diff --git a/composer.lock b/composer.lock index 9135fea78..3c6fd5eb2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "14a762d6a169ff16a90a941283c7a5b1", + "content-hash": "1ae0a828e38ceeea92578f76f35e483a", "packages": [ { "name": "codeinwp/themeisle-sdk", - "version": "3.3.67", + "version": "3.3.71", "source": { "type": "git", "url": "https://github.com/Codeinwp/themeisle-sdk.git", - "reference": "e1dda44811660a65c3da6994349c054a46686d69" + "reference": "cd7acfc0b01b8d5712736aa3721d689591ced991" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/e1dda44811660a65c3da6994349c054a46686d69", - "reference": "e1dda44811660a65c3da6994349c054a46686d69", + "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/cd7acfc0b01b8d5712736aa3721d689591ced991", + "reference": "cd7acfc0b01b8d5712736aa3721d689591ced991", "shasum": "" }, "require-dev": { @@ -43,22 +43,22 @@ ], "support": { "issues": "https://github.com/Codeinwp/themeisle-sdk/issues", - "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.67" + "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.71" }, - "time": "2026-10-13T12:16:34+00:00" + "time": "2026-11-04T20:22:53+00:00" }, { "name": "enshrined/svg-sanitize", - "version": "1.0.0", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/darylldoyle/svg-sanitizer.git", - "reference": "f3300fcd1bbf67d205b52217c75d0f7d6a8c47ff" + "reference": "1976ff93c8d8a234cdd3ff99626bd43ecf11bf49" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/darylldoyle/svg-sanitizer/zipball/f3300fcd1bbf67d205b52217c75d0f7d6a8c47ff", - "reference": "f3300fcd1bbf67d205b52217c75d0f7d6a8c47ff", + "url": "https://api.github.com/repos/darylldoyle/svg-sanitizer/zipball/1976ff93c8d8a234cdd3ff99626bd43ecf11bf49", + "reference": "1976ff93c8d8a234cdd3ff99626bd43ecf11bf49", "shasum": "" }, "require": { @@ -88,9 +88,9 @@ "description": "An SVG sanitizer for PHP", "support": { "issues": "https://github.com/darylldoyle/svg-sanitizer/issues", - "source": "https://github.com/darylldoyle/svg-sanitizer/tree/1.0.0" + "source": "https://github.com/darylldoyle/svg-sanitizer/tree/1.1.1" }, - "time": "2026-09-01T09:35:47+00:00" + "time": "2026-10-20T09:45:10+00:00" }, { "name": "sabberworm/php-css-parser", @@ -977,16 +977,16 @@ }, { "name": "php-stubs/woocommerce-stubs", - "version": "v11.2.0", + "version": "v11.2.1", "source": { "type": "git", "url": "https://github.com/php-stubs/woocommerce-stubs.git", - "reference": "fb590c1c2a26c47aa5da2c6c51a707130e8a389c" + "reference": "8cfdb86cad90da64441317e1bebe5f71a437a074" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/fb590c1c2a26c47aa5da2c6c51a707130e8a389c", - "reference": "fb590c1c2a26c47aa5da2c6c51a707130e8a389c", + "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/8cfdb86cad90da64441317e1bebe5f71a437a074", + "reference": "8cfdb86cad90da64441317e1bebe5f71a437a074", "shasum": "" }, "require": { @@ -1015,9 +1015,9 @@ ], "support": { "issues": "https://github.com/php-stubs/woocommerce-stubs/issues", - "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v11.2.0" + "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v11.2.1" }, - "time": "2026-10-07T19:02:59+00:00" + "time": "2026-10-09T20:26:55+00:00" }, { "name": "php-stubs/wordpress-stubs", diff --git a/inc/class-main.php b/inc/class-main.php index 755643dbf..2edbf5ecb 100644 --- a/inc/class-main.php +++ b/inc/class-main.php @@ -646,7 +646,7 @@ public function add_black_friday_data( $configs ) { $status = apply_filters( 'product_otter_license_status', false ); $is_pro = 'valid' === $status; - $is_expired = 'expired' === $status || 'active-expired' === $status; + $is_expired = in_array( $status, array( 'expired', 'active_expired', 'active-expired' ), true ); $pro_product_slug = defined( 'OTTER_PRO_BASEFILE' ) ? basename( dirname( OTTER_PRO_BASEFILE ) ) : ''; if ( $is_pro ) { diff --git a/inc/class-registration.php b/inc/class-registration.php index 0fa0786fe..970bbac88 100644 --- a/inc/class-registration.php +++ b/inc/class-registration.php @@ -1211,21 +1211,26 @@ public function load_condition_hide_on_styles( $block_content, $block ) { return $block_content; } - add_action( 'wp_footer', array( $this, 'condition_hide_on_style' ) ); + self::condition_hide_on_style(); self::$scripts_loaded['condition_hide_on'] = true; return $block_content; } /** - * Get the styles for Hide on condition. + * Enqueue the styles for Hide on condition. + * + * Enqueued, not echoed, so core can print them in even when enqueued late. * * @static * @since 2.4 * @access public + * @return void */ public static function condition_hide_on_style() { - echo ''; + wp_register_style( 'o-condition-hide', false, array(), OTTER_BLOCKS_VERSION ); + wp_add_inline_style( 'o-condition-hide', '@layer theme, base, components, utilities;@media (max-width:768px){@layer utilities{.o-hide-on-mobile:is(.o-hide-on-mobile,#_){display:none!important}}}@media (min-width:769px) and (max-width:1024px){@layer utilities{.o-hide-on-tablet:is(.o-hide-on-tablet,#_){display:none!important}}}@media (min-width:1025px){@layer utilities{.o-hide-on-desktop:is(.o-hide-on-desktop,#_){display:none!important}}}' ); + wp_enqueue_style( 'o-condition-hide' ); } /** diff --git a/inc/plugins/class-abilities.php b/inc/plugins/class-abilities.php index 1a65bb77e..7eeca6e81 100644 --- a/inc/plugins/class-abilities.php +++ b/inc/plugins/class-abilities.php @@ -201,7 +201,7 @@ public function register_abilities() { 'properties' => array( 'email_to' => array( 'type' => 'string', - 'description' => __( 'Recipient email address. The site admin email is used when empty.', 'otter-blocks' ), + 'description' => __( 'Recipient email addresses, separated by commas. The site admin email is used when empty.', 'otter-blocks' ), ), 'subject' => array( 'type' => 'string' ), 'from_name' => array( 'type' => 'string' ), @@ -919,7 +919,7 @@ private function apply_delivery( $entry, $delivery ) { } if ( '' !== $value && in_array( $key, array( 'email_to', 'cc', 'bcc', 'from_email', 'reply_to' ), true ) ) { - $emails = in_array( $key, array( 'email_to', 'from_email', 'reply_to' ), true ) ? array( $value ) : array_map( 'trim', explode( ',', $value ) ); + $emails = in_array( $key, array( 'from_email', 'reply_to' ), true ) ? array( $value ) : array_map( 'trim', explode( ',', $value ) ); foreach ( $emails as $email ) { if ( ! is_email( $email ) ) { diff --git a/inc/server/class-form-server.php b/inc/server/class-form-server.php index 4595caecf..dce0b6ebb 100644 --- a/inc/server/class-form-server.php +++ b/inc/server/class-form-server.php @@ -489,7 +489,7 @@ public function send_default_email( $form_data ) { foreach ( $form_emails as $form ) { if ( isset( $form['form'] ) && $form['form'] === $option_name && isset( $form['email'] ) && '' !== $form['email'] ) { - $to = sanitize_email( $form['email'] ); + $to = implode( ', ', self::sanitize_recipients( $form['email'] ) ); } } @@ -817,14 +817,15 @@ public static function send_test_email( $form_data ) { try { $email_subject = ( __( 'Test email for Otter Form from ', 'otter-blocks' ) . get_bloginfo( 'name', 'display' ) ); $email_body = Form_Email::instance()->build_test_email( $form_data ); + + $recipients = $form_data->payload_has( 'to' ) ? self::sanitize_recipients( $form_data->get_data_from_payload( 'to' ) ) : array(); // Sent the form date to the admin site as a default behaviour. - $to = sanitize_email( get_option( 'admin_email' ) ); - if ( $form_data->payload_has( 'to' ) && '' !== $form_data->get_data_from_payload( 'to' ) ) { - $to = sanitize_email( $form_data->get_data_from_payload( 'to' ) ); + if ( empty( $recipients ) ) { + $recipients = array( sanitize_email( get_option( 'admin_email' ) ) ); } - $headers = array( 'Content-Type: text/html; charset=UTF-8', 'From: ' . get_bloginfo( 'name', 'display' ) . '<' . $to . '>' ); + $headers = array( 'Content-Type: text/html; charset=UTF-8', 'From: ' . get_bloginfo( 'name', 'display' ) . '<' . $recipients[0] . '>' ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_mail_wp_mail - $res->set_success( wp_mail( $to, $email_subject, $email_body, $headers ) ); + $res->set_success( wp_mail( implode( ', ', $recipients ), $email_subject, $email_body, $headers ) ); } catch ( Exception $e ) { $res->set_code( Form_Data_Response::ERROR_RUNTIME_ERROR ); $res->add_reason( $e->getMessage() ); @@ -1170,6 +1171,18 @@ public function build_email_error_content( $content ) { return $content; } + /** + * Sanitize a comma-separated list of email addresses, dropping the invalid ones. + * + * @param string $recipients Comma-separated email addresses. + * @return list + */ + private static function sanitize_recipients( $recipients ) { + $emails = array_map( 'sanitize_email', explode( ',', $recipients ) ); + + return array_values( array_filter( $emails, 'is_email' ) ); + } + /** * Get the first email from the input's form. * diff --git a/inc/server/class-otter-openai-backend.php b/inc/server/class-otter-openai-backend.php index d19f5a0ce..cf7acb17a 100644 --- a/inc/server/class-otter-openai-backend.php +++ b/inc/server/class-otter-openai-backend.php @@ -68,7 +68,7 @@ public function generate( array $payload ) { * @param string $model Default model ID. * @param array $payload The filtered OpenAI-format payload. */ - $model = (string) apply_filters( 'otter_ai_block_generation_model', 'gpt-5-mini', $payload ); + $model = (string) apply_filters( 'otter_ai_block_generation_model', 'gpt-5.6-terra', $payload ); } if ( is_string( $model ) && '' !== $model ) { diff --git a/inc/server/class-prompt-server.php b/inc/server/class-prompt-server.php index 84388801c..5f0404318 100644 --- a/inc/server/class-prompt-server.php +++ b/inc/server/class-prompt-server.php @@ -141,7 +141,7 @@ public function save_api_key( $request ) { ), 'body' => wp_json_encode( array( - 'model' => 'gpt-3.5-turbo', + 'model' => 'gpt-6-luna', 'messages' => array( array( 'role' => 'system', diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c1ba7b1a4..642bc2a93 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -426,12 +426,6 @@ parameters: count: 1 path: inc/class-registration.php - - - rawMessage: 'Method ThemeIsle\GutenbergBlocks\Registration::condition_hide_on_style() has no return type specified.' - identifier: missingType.return - count: 1 - path: inc/class-registration.php - - rawMessage: 'Method ThemeIsle\GutenbergBlocks\Registration::enqueue_assets() has no return type specified.' identifier: missingType.return diff --git a/plugins/blocks-animation/composer.lock b/plugins/blocks-animation/composer.lock index d3d0a6a52..77697de49 100644 --- a/plugins/blocks-animation/composer.lock +++ b/plugins/blocks-animation/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "codeinwp/themeisle-sdk", - "version": "3.3.67", + "version": "3.3.71", "source": { "type": "git", "url": "https://github.com/Codeinwp/themeisle-sdk.git", - "reference": "e1dda44811660a65c3da6994349c054a46686d69" + "reference": "cd7acfc0b01b8d5712736aa3721d689591ced991" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/e1dda44811660a65c3da6994349c054a46686d69", - "reference": "e1dda44811660a65c3da6994349c054a46686d69", + "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/cd7acfc0b01b8d5712736aa3721d689591ced991", + "reference": "cd7acfc0b01b8d5712736aa3721d689591ced991", "shasum": "" }, "require-dev": { @@ -43,9 +43,9 @@ ], "support": { "issues": "https://github.com/Codeinwp/themeisle-sdk/issues", - "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.67" + "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.71" }, - "time": "2026-10-13T12:16:34+00:00" + "time": "2026-11-04T20:22:53+00:00" } ], "packages-dev": [], diff --git a/plugins/blocks-css/composer.lock b/plugins/blocks-css/composer.lock index 22d6489f1..d3431034b 100644 --- a/plugins/blocks-css/composer.lock +++ b/plugins/blocks-css/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "codeinwp/themeisle-sdk", - "version": "3.3.67", + "version": "3.3.71", "source": { "type": "git", "url": "https://github.com/Codeinwp/themeisle-sdk.git", - "reference": "e1dda44811660a65c3da6994349c054a46686d69" + "reference": "cd7acfc0b01b8d5712736aa3721d689591ced991" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/e1dda44811660a65c3da6994349c054a46686d69", - "reference": "e1dda44811660a65c3da6994349c054a46686d69", + "url": "https://api.github.com/repos/Codeinwp/themeisle-sdk/zipball/cd7acfc0b01b8d5712736aa3721d689591ced991", + "reference": "cd7acfc0b01b8d5712736aa3721d689591ced991", "shasum": "" }, "require-dev": { @@ -43,9 +43,9 @@ ], "support": { "issues": "https://github.com/Codeinwp/themeisle-sdk/issues", - "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.67" + "source": "https://github.com/Codeinwp/themeisle-sdk/tree/v3.3.71" }, - "time": "2026-10-13T12:16:34+00:00" + "time": "2026-11-04T20:22:53+00:00" } ], "packages-dev": [], diff --git a/src/blocks/blocks/accordion/group/block.json b/src/blocks/blocks/accordion/group/block.json index 13b76f6af..7445119d5 100644 --- a/src/blocks/blocks/accordion/group/block.json +++ b/src/blocks/blocks/accordion/group/block.json @@ -51,7 +51,7 @@ "type": "number" }, "letterSpacing": { - "type": "string" + "type": ["number", "string"] }, "padding": { "type": "object" diff --git a/src/blocks/blocks/form/inspector.js b/src/blocks/blocks/form/inspector.js index faed5afe7..2c7414fa3 100644 --- a/src/blocks/blocks/form/inspector.js +++ b/src/blocks/blocks/form/inspector.js @@ -113,7 +113,7 @@ const FormOptions = ({ formOptions, setFormOption, attributes, setAttributes }) setFormOption({ emailTo }) } help={ __( 'Default is site administrator.', 'otter-blocks' ) } diff --git a/src/blocks/plugins/data/index.js b/src/blocks/plugins/data/index.js index aa4ad74e1..d0ff9f579 100644 --- a/src/blocks/plugins/data/index.js +++ b/src/blocks/plugins/data/index.js @@ -8,7 +8,10 @@ import hash from 'object-hash'; */ import apiFetch from '@wordpress/api-fetch'; -import { registerStore } from '@wordpress/data'; +import { + registerStore, + select +} from '@wordpress/data'; /** * Internal dependencies @@ -16,7 +19,7 @@ import { registerStore } from '@wordpress/data'; import { getQueryStringFromObject } from '../../helpers/helper-functions.js'; const DEFAULT_STATE = { - showOnboarding: Boolean( window.themeisleGutenberg.showOnboarding ) && 'false' !== window.localStorage?.getItem( 'o-show-onboarding' ), + showOnboarding: Boolean( window.themeisleGutenberg.showOnboarding ) && 'false' !== window.localStorage?.getItem( 'o-show-onboarding' ) && false !== select( 'core/preferences' )?.get( 'themeisle/otter-blocks', 'show-welcome-guide' ), viewType: 'Desktop', visiblePopover: 'themeisle-blocks/dynamic-value', dynamicData: {}, diff --git a/src/blocks/plugins/html-edit/attributes.js b/src/blocks/plugins/html-edit/attributes.js index 15c121ebd..fa521f257 100644 --- a/src/blocks/plugins/html-edit/attributes.js +++ b/src/blocks/plugins/html-edit/attributes.js @@ -52,6 +52,16 @@ export const HTML_FIELDS = { } }; +/** + * Markup that `save` generates from no attribute, by block name. An HTML edit + * inside it cannot be kept, so it is restored from `save`. + * + * @type {Object} + */ +export const GENERATED_MARKUP = { + 'themeisle-blocks/countdown': ':scope > .otter-countdown__container' +}; + /** * Parse markup into an inert fragment. * @@ -263,3 +273,34 @@ export const syncDuplicateValues = ( attributes, blockType, html ) => { return synced ? template.innerHTML : null; }; + +/** + * Replace the generated markup in an edited block with the markup `save` + * regenerates, so an HTML edit inside it matches `save` again. + * + * @param {string} name The block name. + * @param {string} html The edited block markup. + * @param {string} savedHTML The markup `save` generates for the block attributes. + * @return {string|null} The restored markup, or null when the generated markup was not edited. + */ +export const restoreGeneratedMarkup = ( name, html, savedHTML ) => { + const selector = GENERATED_MARKUP[ name ]; + + if ( ! selector || 'string' !== typeof html ) { + return null; + } + + const template = document.createElement( 'template' ); + template.innerHTML = html; + + const edited = template.content.firstElementChild?.querySelector( selector ); + const generated = toFragment( savedHTML ).firstElementChild?.querySelector( selector ); + + if ( ! edited || ! generated || edited.isEqualNode( generated ) ) { + return null; + } + + edited.replaceWith( generated ); + + return template.innerHTML; +}; diff --git a/src/blocks/plugins/html-edit/index.js b/src/blocks/plugins/html-edit/index.js index 0bef920ff..afc2ef017 100644 --- a/src/blocks/plugins/html-edit/index.js +++ b/src/blocks/plugins/html-edit/index.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { getBlockType, validateBlock } from '@wordpress/blocks'; +import { getBlockType, getSaveContent, validateBlock } from '@wordpress/blocks'; import { dispatch, select, subscribe } from '@wordpress/data'; @@ -11,8 +11,10 @@ import { addFilter } from '@wordpress/hooks'; * Internal dependencies */ import { + GENERATED_MARKUP, HTML_FIELDS, getAttributesFromHTML, + restoreGeneratedMarkup, syncDuplicateValues } from './attributes.js'; @@ -28,7 +30,20 @@ addFilter( 'blocks.getBlockAttributes', 'themeisle-gutenberg/html-edit-attribute let lastChecked = null; -// An HTML edit of one copy of a duplicated value leaves the block invalid; sync the other copies. +/** + * Sync the stale copies of duplicated values and restore the generated markup in an edited block. + * + * @param {{name: string, attributes: Record, originalContent: string}} block The block. + * @return {string} The repaired markup. + */ +const repairMarkup = ( block ) => { + const blockType = getBlockType( block.name ); + const synced = syncDuplicateValues( block.attributes, blockType, block.originalContent ) ?? block.originalContent; + + return restoreGeneratedMarkup( block.name, synced, getSaveContent( blockType, block.attributes ) ) ?? synced; +}; + +// An HTML edit of one copy of a duplicated value, or of generated markup, leaves the block invalid; repair it. subscribe( () => { const blockEditor = select( 'core/block-editor' ); const block = blockEditor?.getSelectedBlock(); @@ -36,7 +51,7 @@ subscribe( () => { if ( ! block || block.isValid || - ! HTML_FIELDS[ block.name ] || + ( ! HTML_FIELDS[ block.name ] && ! GENERATED_MARKUP[ block.name ]) || lastChecked === block.originalContent || 'html' !== blockEditor.getBlockMode( block.clientId ) ) { @@ -45,14 +60,17 @@ subscribe( () => { lastChecked = block.originalContent; - const synced = syncDuplicateValues( block.attributes, getBlockType( block.name ), block.originalContent ); + const repaired = repairMarkup( block ); - if ( ! synced || ! validateBlock({ ...block, originalContent: synced })[0]) { + if ( repaired === block.originalContent || ! validateBlock({ ...block, originalContent: repaired })[0]) { return; } + // The same edit can come back after the repair and must be repaired again. + lastChecked = null; + dispatch( 'core/block-editor' ).updateBlock( block.clientId, { - originalContent: synced, + originalContent: repaired, isValid: true, validationIssues: [] }); diff --git a/src/blocks/plugins/welcome-guide/index.js b/src/blocks/plugins/welcome-guide/index.js index 7b69bd664..d9383acd5 100644 --- a/src/blocks/plugins/welcome-guide/index.js +++ b/src/blocks/plugins/welcome-guide/index.js @@ -55,6 +55,7 @@ const WelcomeGuide = () => { const { createNotice } = useDispatch( 'core/notices' ); const { showOnboarding } = useDispatch( 'themeisle-gutenberg/data' ); + const { set: setPreference } = useDispatch( 'core/preferences' ); useEffect( () => { if ( '' === email && undefined !== currentUser ) { @@ -66,6 +67,7 @@ const WelcomeGuide = () => { showOnboarding( false ); localStorage?.setItem( 'o-show-onboarding', 'false' ); + setPreference( 'themeisle/otter-blocks', 'show-welcome-guide', false ); if ( canTrack ) { updateOption( 'otter_blocks_logger_flag', 'yes' ); diff --git a/src/blocks/test/e2e/blocks/accordion.spec.js b/src/blocks/test/e2e/blocks/accordion.spec.js index 1331a5c49..fb333dd4f 100644 --- a/src/blocks/test/e2e/blocks/accordion.spec.js +++ b/src/blocks/test/e2e/blocks/accordion.spec.js @@ -6,7 +6,7 @@ import { test, expect } from '@wordpress/e2e-test-utils-playwright'; /** * Internal dependencies */ -import { expectBlockByName, insertBlockBySlash, publishAndViewPost } from '../helpers/editor'; +import { expectBlockByName, getBlockByName, insertBlockBySlash, publishAndViewPost, waitForEditorReady } from '../helpers/editor'; test.describe( 'Accordion Block', () => { test.beforeEach( async({ admin }) => { @@ -80,4 +80,22 @@ test.describe( 'Accordion Block', () => { await expect( page.getByRole( 'paragraph' ).filter({ hasText: 'This is a placeholder tab content. It is important to have the necessary informa' }) ).toBeHidden(); }); + + test( 'keeps letter spacing after the post is reopened', async({ editor, page }) => { + await editor.insertBlock({ + name: 'themeisle-blocks/accordion', + attributes: { letterSpacing: 3 } + }); + + await editor.publishPost(); + + await page.reload(); + await waitForEditorReady( page ); + + // The saved post is parsed asynchronously after the editor boots. + await expect.poll( async() => { + const block = await getBlockByName( editor, 'themeisle-blocks/accordion' ); + return block?.attributes.letterSpacing; + }).toBe( 3 ); + }); }); diff --git a/src/blocks/test/e2e/blocks/block-conditions.spec.js b/src/blocks/test/e2e/blocks/block-conditions.spec.js index f5b57cdff..3e7bb55b3 100644 --- a/src/blocks/test/e2e/blocks/block-conditions.spec.js +++ b/src/blocks/test/e2e/blocks/block-conditions.spec.js @@ -111,4 +111,31 @@ test.describe( 'Block Conditions', () => { await page.goto( `/?p=${postId}` ); await expect( page.getByText( 'Members only content' ) ).toBeHidden(); }); + + test( 'screen size hide styles load in the head', async({ editor, page }) => { + await waitForEditorReady( page ); + + await editor.insertBlock({ + name: 'core/paragraph', + attributes: { + content: 'Hidden on mobile', + otterConditions: [ + [ + { + type: 'screenSize', + screen_sizes: [ 'mobile' ] + } + ] + ] + } + }); + + await publishAndViewPost({ editor, page }); + + // Hidden from the first paint, not after the body parses. + await expect( page.locator( 'head style#o-condition-hide-inline-css' ) ).toHaveCount( 1 ); + + await page.setViewportSize({ width: 375, height: 700 }); + await expect( page.getByText( 'Hidden on mobile' ) ).toBeHidden(); + }); }); diff --git a/src/blocks/test/e2e/blocks/block-html-mode.spec.js b/src/blocks/test/e2e/blocks/block-html-mode.spec.js index d15b3000c..41fa9fff7 100644 --- a/src/blocks/test/e2e/blocks/block-html-mode.spec.js +++ b/src/blocks/test/e2e/blocks/block-html-mode.spec.js @@ -4,8 +4,8 @@ import { test, expect } from '@wordpress/e2e-test-utils-playwright'; /** - * Blocks whose visible content is stored in comment attributes: the edited - * markup is read back into them, so the block stays valid. + * Blocks whose edited markup is read back into comment attributes, or restored + * from `save` for generated markup, so the block stays valid. */ const EDITABLE = [ { @@ -14,6 +14,20 @@ const EDITABLE = [ edits: [[ 'data-date="2026-10-01T10:00:00"', 'data-date="2026-12-25T10:00:00"' ]], expected: { date: '2026-12-25T10:00:00' } }, + { + title: 'generated label', + target: 'themeisle-blocks/countdown', + block: { name: 'themeisle-blocks/countdown', attributes: { date: '2026-10-01T10:00:00' }}, + edits: [[ '>Day<', '>Days<' ]], + expected: { date: '2026-10-01T10:00:00' } + }, + { + title: 'date and generated label', + target: 'themeisle-blocks/countdown', + block: { name: 'themeisle-blocks/countdown', attributes: { date: '2026-10-01T10:00:00' }}, + edits: [[ 'data-date="2026-10-01T10:00:00"', 'data-date="2026-12-25T10:00:00"' ], [ '>Day<', '>Days<' ]], + expected: { date: '2026-12-25T10:00:00' } + }, { target: 'themeisle-blocks/progress-bar', block: { name: 'themeisle-blocks/progress-bar' }, @@ -278,6 +292,41 @@ test.describe( 'Edit as HTML mode', () => { }); } + test( 'themeisle-blocks/countdown stays valid when the same generated label edit is repeated', async({ editor, page }) => { + await editor.insertBlock({ name: 'themeisle-blocks/countdown', attributes: { date: '2026-10-01T10:00:00' }}); + await selectBlockByName( page, 'themeisle-blocks/countdown' ); + + const textarea = editor.canvas.locator( '.block-editor-block-list__block-html-textarea' ); + + for ( let attempt = 0; 2 > attempt; attempt++ ) { + await editor.clickBlockOptionsMenuItem( 'Edit as HTML' ); + await expect( textarea ).toHaveValue( />DayDay<', '>Days<' ) ); + await textarea.blur(); + + await expect.poll( () => page.evaluate( () => window.wp.data.select( 'core/block-editor' ).getSelectedBlock().isValid ) ).toBe( true ); + + await editor.clickBlockOptionsMenuItem( 'Edit visually' ); + } + }); + + test( 'themeisle-blocks/countdown stays valid when the edited HTML is blurred again', async({ editor, page }) => { + await editor.insertBlock({ name: 'themeisle-blocks/countdown', attributes: { date: '2026-10-01T10:00:00' }}); + await selectBlockByName( page, 'themeisle-blocks/countdown' ); + await editor.clickBlockOptionsMenuItem( 'Edit as HTML' ); + + const textarea = editor.canvas.locator( '.block-editor-block-list__block-html-textarea' ); + const isValid = () => page.evaluate( () => window.wp.data.select( 'core/block-editor' ).getSelectedBlock().isValid ); + + await textarea.fill( ( await textarea.inputValue() ).replace( '>Day<', '>Days<' ) ); + await textarea.blur(); + await expect.poll( isValid ).toBe( true ); + + await textarea.focus(); + await textarea.blur(); + await expect.poll( isValid ).toBe( true ); + }); + for ( const { target, block } of WITHOUT_HTML_MODE ) { test( `${ target } does not offer Edit as HTML`, async({ editor, page }) => { await editor.insertBlock( block ); diff --git a/src/blocks/test/unit/html-edit-attributes.test.js b/src/blocks/test/unit/html-edit-attributes.test.js index fff557386..45eb423a1 100644 --- a/src/blocks/test/unit/html-edit-attributes.test.js +++ b/src/blocks/test/unit/html-edit-attributes.test.js @@ -1,7 +1,7 @@ import { registerBlockType } from '@wordpress/blocks'; import { applyFilters } from '@wordpress/hooks'; -import { getAttributesFromHTML, syncDuplicateValues } from '../../plugins/html-edit/attributes'; +import { getAttributesFromHTML, restoreGeneratedMarkup, syncDuplicateValues } from '../../plugins/html-edit/attributes'; import '../../plugins/html-edit/index'; // The real registry pulls an ESM-only dependency that this Jest setup does not transform. @@ -33,6 +33,8 @@ const formInput = blockType( 'form-input', { label: { type: 'string' }, placehol const countdownHTML = ( date ) => `
`; +const countdownDisplayHTML = ( date, label ) => `
0
${ label }
`; + const progressHTML = ({ title = 'Skill', percent = 50, number = '50%' } = {}) => `
${ title }
${ number }
`; const circleHTML = ( title, percentage ) => `
${ title }
`; @@ -155,6 +157,28 @@ describe( 'syncDuplicateValues', () => { }); }); +describe( 'restoreGeneratedMarkup', () => { + const countdown = 'themeisle-blocks/countdown'; + + it( 'restores an edited Countdown label from the saved markup', () => { + expect( restoreGeneratedMarkup( countdown, countdownDisplayHTML( '2026-10-01T10:00:00', 'Days' ), countdownDisplayHTML( '2026-10-01T10:00:00', 'Day' ) ) ) + .toBe( countdownDisplayHTML( '2026-10-01T10:00:00', 'Day' ) ); + }); + + it( 'restores only the generated markup, not the wrapper', () => { + expect( restoreGeneratedMarkup( countdown, countdownDisplayHTML( '2026-12-25T10:00:00', 'Days' ), countdownDisplayHTML( '2026-10-01T10:00:00', 'Day' ) ) ) + .toBe( countdownDisplayHTML( '2026-12-25T10:00:00', 'Day' ) ); + }); + + it( 'returns null when the generated markup was not edited', () => { + const html = countdownDisplayHTML( '2026-10-01T10:00:00', 'Day' ); + + expect( restoreGeneratedMarkup( countdown, html, html ) ).toBeNull(); + expect( restoreGeneratedMarkup( countdown, countdownHTML( '2026-10-01T10:00:00' ).replace( '
', '' ), html ) ).toBeNull(); + expect( restoreGeneratedMarkup( 'themeisle-blocks/progress-bar', progressHTML({ title: 'Design' }), progressHTML() ) ).toBeNull(); + }); +}); + describe( 'blocks.getBlockAttributes filter', () => { const attributes = { id: 'c1', date: '2026-10-01T10:00:00' }; const editedHTML = countdownHTML( '2026-12-25T10:00:00' ); diff --git a/src/blocks/test/unit/onboarding-visibility.test.js b/src/blocks/test/unit/onboarding-visibility.test.js new file mode 100644 index 000000000..ae77dea48 --- /dev/null +++ b/src/blocks/test/unit/onboarding-visibility.test.js @@ -0,0 +1,68 @@ +/** + * @param {Object} options + * @param {boolean} options.serverFlag Value of themeisleGutenberg.showOnboarding. + * @param {string|null} options.storage Stored 'o-show-onboarding' value. + * @param {boolean|undefined} options.preference Saved 'show-welcome-guide' user preference. + * @return {boolean} Initial onboarding visibility of the data store. + */ +const loadInitialVisibility = ({ serverFlag = true, storage = null, preference = undefined } = {}) => { + jest.resetModules(); + + /** @type {{ reducer: ( state: ( Object|undefined ), action: { type: string } ) => Object, selectors: { isOnboardingVisible: ( state: Object ) => boolean } }|undefined} */ + let storeConfig; + + jest.doMock( 'object-hash', () => jest.fn() ); + jest.doMock( '@wordpress/api-fetch', () => jest.fn(), { virtual: true } ); + jest.doMock( '../../helpers/helper-functions.js', () => ({ + getQueryStringFromObject: jest.fn() + }) ); + + jest.doMock( '@wordpress/data', () => ({ + registerStore: jest.fn( ( name, config ) => { + storeConfig = config; + }), + select: jest.fn( store => { + if ( 'core/preferences' === store ) { + return { + get: ( scope, name ) => ( 'themeisle/otter-blocks' === scope && 'show-welcome-guide' === name ? preference : undefined ) + }; + } + + return undefined; + }) + }), { virtual: true } ); + + window.themeisleGutenberg = { showOnboarding: serverFlag }; + window.localStorage.clear(); + + if ( null !== storage ) { + window.localStorage.setItem( 'o-show-onboarding', storage ); + } + + require( '../../plugins/data' ); + + return storeConfig.selectors.isOnboardingVisible( storeConfig.reducer( undefined, { type: '@@INIT' }) ); +}; + +describe( 'Welcome guide visibility', () => { + afterEach( () => { + window.localStorage.clear(); + delete window.themeisleGutenberg; + }); + + it( 'shows the guide when nothing has dismissed it', () => { + expect( loadInitialVisibility() ).toBe( true ); + }); + + it( 'hides the guide when the user dismissed it in another browser', () => { + expect( loadInitialVisibility({ preference: false }) ).toBe( false ); + }); + + it( 'hides the guide when this browser stored the dismissal', () => { + expect( loadInitialVisibility({ storage: 'false' }) ).toBe( false ); + }); + + it( 'hides the guide when the server disables onboarding', () => { + expect( loadInitialVisibility({ serverFlag: false }) ).toBe( false ); + }); +}); diff --git a/src/blocks/test/unit/welcome-guide-dismiss.test.js b/src/blocks/test/unit/welcome-guide-dismiss.test.js new file mode 100644 index 000000000..c8fee9620 --- /dev/null +++ b/src/blocks/test/unit/welcome-guide-dismiss.test.js @@ -0,0 +1,105 @@ +/** + * @return {{ onFinish: ( target?: Event ) => void, setPreference: jest.Mock }} Guide's finish handler and the preference setter. + */ +const renderWelcomeGuide = () => { + jest.resetModules(); + + /** @type {import('react').FunctionComponent|undefined} */ + let Render; + + /** @type {{ onFinish: ( target?: Event ) => void }|undefined} */ + let guideProps; + + const setPreference = jest.fn(); + + jest.doMock( '@wordpress/i18n', () => ({ + __: text => text + }), { virtual: true } ); + + jest.doMock( '@wordpress/components', () => ({ + CheckboxControl: () => null, + ExternalLink: () => null, + TextControl: () => null, + Guide: props => { + guideProps = props; + return null; + } + }), { virtual: true } ); + + jest.doMock( '@wordpress/plugins', () => ({ + registerPlugin: ( name, settings ) => { + Render = settings.render; + } + }), { virtual: true } ); + + const stores = { + 'core': { + getCurrentUser: () => ({ id: 1 }), + getUser: () => undefined, + getSite: () => undefined + }, + 'core/editor': {}, + 'core/edit-post': { + isFeatureActive: () => false + }, + 'themeisle-gutenberg/data': { + isOnboardingVisible: () => true + } + }; + + const dispatchers = { + 'core/notices': { createNotice: jest.fn() }, + 'core/preferences': { set: setPreference }, + 'themeisle-gutenberg/data': { showOnboarding: jest.fn() } + }; + + jest.doMock( '@wordpress/data', () => ({ + select: store => stores[ store ], + useSelect: mapSelect => mapSelect( store => stores[ store ]), + useDispatch: store => dispatchers[ store ] + }), { virtual: true } ); + + jest.doMock( '../../helpers/use-settings.js', () => () => [ jest.fn(), jest.fn(), 'loaded' ]); + jest.doMock( '../../helpers/helper-functions.js', () => ({ + setUtm: jest.fn() + }) ); + + window.themeisleGutenberg = { isBlockEditor: true }; + + require( '../../plugins/welcome-guide' ); + + // Same React instance as the module under test, which loaded after resetModules(). + const { act, createElement } = require( 'react' ); + const { createRoot } = require( 'react-dom/client' ); + const root = createRoot( document.createElement( 'div' ) ); + + act( () => { + root.render( createElement( Render ) ); + }); + + return { onFinish: guideProps.onFinish, setPreference }; +}; + +describe( 'Welcome guide dismissal', () => { + beforeAll( () => { + global.IS_REACT_ACT_ENVIRONMENT = true; + }); + + afterAll( () => { + delete global.IS_REACT_ACT_ENVIRONMENT; + }); + + afterEach( () => { + window.localStorage.clear(); + delete window.themeisleGutenberg; + }); + + it( 'saves the dismissal as a user preference when the guide is closed', () => { + const { onFinish, setPreference } = renderWelcomeGuide(); + + onFinish(); + + expect( setPreference ).toHaveBeenCalledWith( 'themeisle/otter-blocks', 'show-welcome-guide', false ); + expect( window.localStorage.getItem( 'o-show-onboarding' ) ).toBe( 'false' ); + }); +}); diff --git a/tests/test-abilities.php b/tests/test-abilities.php new file mode 100644 index 000000000..a348061b0 --- /dev/null +++ b/tests/test-abilities.php @@ -0,0 +1,79 @@ +user->create( array( 'role' => 'administrator' ) ) ); + $this->post_id = self::factory()->post->create( + array( 'post_content' => '' ) + ); + } + + /** + * Reset the current user. + */ + public function tear_down(): void { + wp_set_current_user( 0 ); + + parent::tear_down(); + } + + /** + * A comma-separated recipient list is accepted for `email_to`. + */ + public function test_update_form_accepts_comma_separated_email_to(): void { + $result = $this->update_email_to( 'first@example.org, second@example.org' ); + + $this->assertIsArray( $result ); + $this->assertSame( 'first@example.org, second@example.org', $result['delivery']['email_to'] ); + } + + /** + * A recipient list containing an invalid address is rejected. + */ + public function test_update_form_rejects_email_to_list_with_invalid_address(): void { + $result = $this->update_email_to( 'first@example.org, not-an-email' ); + + $this->assertWPError( $result ); + $this->assertSame( 'otter_invalid_email', $result->get_error_code() ); + } + + /** + * Run a dry-run `otter/update-form` that sets the form recipient. + * + * @param string $email_to The recipient value. + * @return array|WP_Error + */ + private function update_email_to( string $email_to ) { + return Abilities::instance()->update_form( + array( + 'form_id' => 'contact_form', + 'post_id' => $this->post_id, + 'dry_run' => true, + 'delivery' => array( 'email_to' => $email_to ), + ) + ); + } +} diff --git a/tests/test-block-conditions.php b/tests/test-block-conditions.php index e36146696..6f2beb2bb 100644 --- a/tests/test-block-conditions.php +++ b/tests/test-block-conditions.php @@ -85,6 +85,9 @@ public function tear_down() wp_delete_user( $this->user_id, true ); wp_delete_post( $this->post_id, true ); wp_delete_term( $this->category_id, 'category' ); + wp_dequeue_style( 'o-condition-hide' ); + wp_deregister_style( 'o-condition-hide' ); + Registration::$scripts_loaded['condition_hide_on'] = false; parent::tear_down(); } @@ -631,4 +634,29 @@ public function test_load_condition_hide_on_styles() { // Make sure styles are loaded. $this->assertEquals( Registration::$scripts_loaded['condition_hide_on'], true ); } + + public function test_screen_size_condition_enqueues_hide_styles_for_head(): void { + $block = array( + 'blockName' => 'core/paragraph', + 'attrs' => array( + 'otterConditions' => array( + array( + array( + 'type' => 'screenSize', + 'screen_sizes' => array( 'mobile' ), + ), + ), + ), + ), + ); + + ( new Registration() )->load_condition_hide_on_styles( '

Hello!

', $block ); + + $this->assertTrue( wp_style_is( 'o-condition-hide' ) ); + + $head_styles = get_echo( 'wp_print_styles', array( 'o-condition-hide' ) ); + + $this->assertMatchesRegularExpression( '/id=["\']o-condition-hide-inline-css["\']/', $head_styles ); + $this->assertStringContainsString( '.o-hide-on-mobile:is(.o-hide-on-mobile,#_){display:none!important}', $head_styles ); + } } diff --git a/tests/test-form-server.php b/tests/test-form-server.php index a06386cc1..0e21ccf71 100644 --- a/tests/test-form-server.php +++ b/tests/test-form-server.php @@ -365,6 +365,87 @@ public function test_send_test_email_without_recipient_uses_site_admin_email(): $this->assertStringNotContainsString( 'network-admin@example.org', $this->mail_requests[0]['message'] ); } + /** + * Form recipient lists and the `to` value the notification must be sent with. + * + * @return array + */ + public function recipient_list_provider(): array { + return array( + 'comma separated' => array( 'first@example.org,second@example.org', 'first@example.org, second@example.org' ), + 'comma and space' => array( 'first@example.org, second@example.org', 'first@example.org, second@example.org' ), + 'invalid entry dropped' => array( 'first@example.org, not-an-email', 'first@example.org' ), + 'only invalid entries' => array( 'not-an-email, also-not-an-email', 'site-admin@example.org' ), + ); + } + + /** + * The notification goes to every valid address in a comma-separated recipient list. + * + * @dataProvider recipient_list_provider + * + * @param string $recipients The form's configured recipients. + * @param string $expected_to The expected `to` value. + */ + public function test_frontend_submission_sends_to_every_listed_recipient( string $recipients, string $expected_to ): void { + $this->mock_mail(); + $this->use_distinct_network_admin_email(); + update_option( 'themeisle_blocks_form_emails', array( $this->get_form_option( array( 'email' => $recipients ) ) ) ); + + $response = $this->form_server->frontend( $this->get_frontend_request() ); + + $this->assertTrue( $response->get_data()['success'] ); + $this->assertCount( 1, $this->mail_requests ); + $this->assertSame( $expected_to, $this->mail_requests[0]['to'] ); + } + + /** + * The test email goes to every valid listed address and is sent from the first one only. + */ + public function test_send_test_email_sends_to_every_listed_recipient(): void { + $this->mock_mail(); + + $request = new WP_REST_Request( 'POST', '/otter/v1/form/editor' ); + $request->set_body( + wp_json_encode( + array( + 'handler' => 'testEmail', + 'payload' => array( 'to' => 'first@example.org, not-an-email, second@example.org' ), + ) + ) + ); + + Form_Server::send_test_email( new Form_Data_Request( $request ) ); + + $this->assertCount( 1, $this->mail_requests ); + $this->assertSame( 'first@example.org, second@example.org', $this->mail_requests[0]['to'] ); + $this->assertContains( 'From: ' . get_bloginfo( 'name', 'display' ) . '', $this->mail_requests[0]['headers'] ); + } + + /** + * A test email whose recipients are all invalid goes to, and is sent from, the current site's admin. + */ + public function test_send_test_email_with_only_invalid_recipients_uses_site_admin_email(): void { + $this->mock_mail(); + $this->use_distinct_network_admin_email(); + + $request = new WP_REST_Request( 'POST', '/otter/v1/form/editor' ); + $request->set_body( + wp_json_encode( + array( + 'handler' => 'testEmail', + 'payload' => array( 'to' => 'not-an-email, also-not-an-email' ), + ) + ) + ); + + Form_Server::send_test_email( new Form_Data_Request( $request ) ); + + $this->assertCount( 1, $this->mail_requests ); + $this->assertSame( 'site-admin@example.org', $this->mail_requests[0]['to'] ); + $this->assertContains( 'From: ' . get_bloginfo( 'name', 'display' ) . '', $this->mail_requests[0]['headers'] ); + } + /** * Ensure a configured Reply-To address overrides the submitter email fallback. */