diff --git a/composer.json b/composer.json index a06437e3c..e2bfee152 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,7 @@ }, "minimum-stability": "dev", "require": { - "codeinwp/themeisle-sdk": "^3.3.65", + "codeinwp/themeisle-sdk": "^3.3.70", "tubalmartin/cssmin": "^4.1", "wptt/webfont-loader": "^1.1", "sabberworm/php-css-parser": "^8.4", diff --git a/composer.lock b/composer.lock index 0a27b7e3a..67a965ca1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c01ca8d521c97d9b29fb7fce95c0002f", + "content-hash": "f7d4a66bc361fcc3052821cc86d88804", "packages": [ { "name": "codeinwp/themeisle-sdk", @@ -3143,5 +3143,5 @@ "platform-overrides": { "php": "7.4" }, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.11.0" } diff --git a/otter-blocks.php b/otter-blocks.php index 71cb2b081..e2f405d18 100644 --- a/otter-blocks.php +++ b/otter-blocks.php @@ -90,6 +90,47 @@ function () { } ); +/* + * Opts into the SDK Support Hub: one Help button on Otter's screens and the + * deactivation window. The dashboard and Form Submissions screens already fire + * `themeisle_internal_page`, so no `pages` list is needed. + */ +add_filter( + 'otter_blocks_support_hub_metadata', + function () { + return array( + // The SDK reads this while loading Otter, before Otter Pro's Licenser adds the + // product_otter_license_status filter, so read the stored license directly. + 'is_pro' => defined( 'OTTER_PRO_BASEFILE' ) && class_exists( '\ThemeisleSDK\Modules\Licenser' ) && \ThemeisleSDK\Modules\Licenser::is_valid( OTTER_PRO_BASEFILE ), + 'links' => array( + array( + 'icon' => 'book-alt', + 'text' => __( 'Documentation', 'otter-blocks' ), + 'url' => \ThemeIsle\GutenbergBlocks\Pro::get_docs_url(), + ), + array( + 'icon' => 'groups', + 'text' => __( 'Community Forum', 'otter-blocks' ), + 'url' => 'https://wordpress.org/support/plugin/otter-blocks/', + ), + ), + ); + } +); + +/* + * Otter also fires `themeisle_internal_page` in the block editor, which would put + * the Help button on every post, site and widget editor. Keep it to Otter's screens. + */ +add_filter( + 'otter_blocks_hide_support_hub', + function ( $hide ) { + global $pagenow; + + return $hide || in_array( $pagenow, array( 'post.php', 'post-new.php', 'site-editor.php', 'widgets.php' ), true ); + } +); + add_filter( 'themeisle_sdk_compatibilities/' . basename( OTTER_BLOCKS_PATH ), function ( $compatibilities ) { diff --git a/readme.md b/readme.md index a5832f3c9..89d85c1dc 100644 --- a/readme.md +++ b/readme.md @@ -330,7 +330,7 @@ Sure, Otter is compatible with any WordPress theme. ### Where can I get help? ### -If you encounter any difficulties or if you have questions about Otter, you can create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential. +If you encounter any difficulties or if you have questions about Otter, you can ask our support team from the **Help** button on the Otter dashboard, or create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential. ### What are the Patterns and how can I use them? ### diff --git a/readme.txt b/readme.txt index c8d29109e..b6775c199 100644 --- a/readme.txt +++ b/readme.txt @@ -330,7 +330,7 @@ Sure, Otter is compatible with any WordPress theme. = Where can I get help? = -If you encounter any difficulties or if you have questions about Otter, you can create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential. +If you encounter any difficulties or if you have questions about Otter, you can ask our support team from the **Help** button on the Otter dashboard, or create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential. = What are the Patterns and how can I use them? = diff --git a/src/blocks/test/e2e/blocks/dashboard.spec.js b/src/blocks/test/e2e/blocks/dashboard.spec.js index e10d35b24..b62d72f18 100644 --- a/src/blocks/test/e2e/blocks/dashboard.spec.js +++ b/src/blocks/test/e2e/blocks/dashboard.spec.js @@ -170,4 +170,38 @@ test.describe( 'Dashboard', () => { await countdownCard.getByRole( 'checkbox' ).click(); await expect( countdownCard.getByRole( 'checkbox' ) ).toBeChecked(); }); + + test( 'free sidebar opens the Help panel and keeps the community forum', async({ admin, otterUtils, page }) => { + // Global setup stubs a valid Pro license, which shows Contact Pro Support instead. + await otterUtils.deactivatePro(); + + try { + await admin.visitAdminPage( 'admin.php?page=otter' ); + + const contact = page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Support' }); + + await expect( contact ).toHaveAttribute( 'data-ti-support', 'dashboard' ); + await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Community Forum' }) ).toHaveAttribute( 'href', 'https://wordpress.org/support/plugin/otter-blocks/' ); + + await contact.click(); + + await expect( page.locator( '.ti-support-panel' ) ).toBeVisible(); + } finally { + await otterUtils.activatePro(); + } + }); + + test( 'licensed Pro sidebar keeps Contact Pro Support', async({ page }) => { + await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Pro Support' }) ).toHaveAttribute( 'href', 'https://store.themeisle.com/' ); + await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Support' }) ).toHaveCount( 0 ); + }); + + test( 'Help launcher shows on the dashboard but not in the block editor', async({ admin, page }) => { + await expect( page.locator( '.ti-support-launcher' ) ).toBeVisible(); + + await admin.createNewPost(); + + // The SDK prints this container in admin_footer whenever the hub loads. + await expect( page.locator( '#ti-support-hub' ) ).toHaveCount( 0 ); + }); }); diff --git a/src/dashboard/components/Sidebar.js b/src/dashboard/components/Sidebar.js index 2c94f7f5e..482317428 100644 --- a/src/dashboard/components/Sidebar.js +++ b/src/dashboard/components/Sidebar.js @@ -76,9 +76,7 @@ const Sidebar = ({ setTab }) => { const isProLicenseActive = Boolean( window.otterObj.hasPro ) && 'valid' === window.otterObj?.license?.valid; - - const supportLink = isProLicenseActive ? 'https://store.themeisle.com/' : 'https://wordpress.org/support/plugin/otter-blocks'; - const supportLabel = isProLicenseActive ? __( 'Contact Pro Support', 'otter-blocks' ) : __( 'Support', 'otter-blocks' ); + const forumLink = 'https://wordpress.org/support/plugin/otter-blocks/'; return ( @@ -122,7 +120,15 @@ const Sidebar = ({ title={ __( 'Useful links', 'otter-blocks' ) } > diff --git a/tests/test-support-hub.php b/tests/test-support-hub.php new file mode 100644 index 000000000..65159c621 --- /dev/null +++ b/tests/test-support-hub.php @@ -0,0 +1,94 @@ +assertIsArray( $data ); + $this->assertSame( array( 'is_pro', 'links' ), array_keys( $data ) ); + } + + /** + * The footer links point to Otter's docs and wordpress.org forum. + */ + public function test_links_point_to_otter() { + $links = apply_filters( 'otter_blocks_support_hub_metadata', array() )['links']; + + $this->assertSame( + array( + 'https://docs.themeisle.com/otter-page-builder-blocks-extensions/otter-blocks-documentation', + 'https://wordpress.org/support/plugin/otter-blocks/', + ), + wp_list_pluck( $links, 'url' ) + ); + foreach ( $links as $link ) { + $this->assertNotEmpty( $link['icon'] ); + $this->assertNotEmpty( $link['text'] ); + } + } + + /** + * Messages are tagged as Pro only while the stored Pro license is valid, whatever + * the order in which the SDK loads Otter and Otter Pro. + */ + public function test_is_pro_reads_the_stored_pro_license() { + if ( ! defined( 'OTTER_PRO_BASEFILE' ) ) { + define( 'OTTER_PRO_BASEFILE', dirname( __DIR__ ) . '/plugins/otter-pro/otter-pro.php' ); + } + // The test bootstrap loads Composer before WordPress, so the SDK's load.php skips itself. + $sdk = dirname( __DIR__ ) . '/vendor/codeinwp/themeisle-sdk/src/'; + foreach ( array( 'Loader.php', 'Product.php', 'Common/Abstract_module.php', 'Modules/Licenser.php' ) as $file ) { + require_once $sdk . $file; + } + // No Licenser filter is registered, as when Otter loads before Otter Pro. + remove_all_filters( 'product_otter_license_status' ); + + update_option( 'otter_pro_license_data', (object) array( 'license' => 'expired' ) ); + $this->assertFalse( apply_filters( 'otter_blocks_support_hub_metadata', array() )['is_pro'] ); + + update_option( 'otter_pro_license_data', (object) array( 'license' => 'valid' ) ); + $this->assertTrue( apply_filters( 'otter_blocks_support_hub_metadata', array() )['is_pro'] ); + } + + /** + * The Help button stays off the block editors, which also count as Otter screens, and shows on Otter's own screens. + * + * @dataProvider admin_screens + * + * @param string $pagenow Admin page file. + * @param bool $hidden Whether the Help button is hidden there. + */ + public function test_hub_is_hidden_only_in_block_editors( $pagenow, $hidden ) { + $GLOBALS['pagenow'] = $pagenow; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + + $this->assertSame( $hidden, apply_filters( 'otter_blocks_hide_support_hub', false ) ); + } + + /** + * Admin pages and whether the Help button is hidden on them. + * + * @return array + */ + public function admin_screens() { + return array( + 'post editor' => array( 'post.php', true ), + 'new post' => array( 'post-new.php', true ), + 'site editor' => array( 'site-editor.php', true ), + 'widget editor' => array( 'widgets.php', true ), + 'Otter screen' => array( 'admin.php', false ), + 'post list' => array( 'edit.php', false ), + ); + } +}