diff --git a/composer.json b/composer.json index e95c6866..bd725d75 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "installer-disable": "true" }, "require": { - "codeinwp/themeisle-sdk": "^3.3.65", + "codeinwp/themeisle-sdk": "^3.3.71", "enshrined/svg-sanitize": "^1.0" }, "autoload": { diff --git a/composer.lock b/composer.lock index c09c7ad1..084b73a0 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": "74fb3f513a7ca4455e98782c544ece6d", + "content-hash": "1c7dbd6e79892d1f66b6511a480f6138", "packages": [ { "name": "codeinwp/themeisle-sdk", diff --git a/images/help.svg b/images/help.svg deleted file mode 100644 index 7eba7a1d..00000000 --- a/images/help.svg +++ /dev/null @@ -1,29 +0,0 @@ - \ No newline at end of file diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 47182cba..4b43177c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4347,7 +4347,7 @@ parameters: - message: '#^Constant PPOM_URL not found\.$#' identifier: constant.notFound - count: 3 + count: 2 path: src/Core/Bootstrap/SdkCompatAndMetadataRegistration.php - diff --git a/readme.txt b/readme.txt index 250aa9fe..35eebc49 100644 --- a/readme.txt +++ b/readme.txt @@ -221,7 +221,7 @@ Interested in PPOM PRO? [Learn more](https://themeisle.com/plugins/ppom-pro/upgr ### Support -Need help? Open a thread on the [Support Forum](https://wordpress.org/support/plugin/woocommerce-product-addon/). +Need help? Ask our support team from the **Help** button on the PPOM screens, or open a thread on the [Support Forum](https://wordpress.org/support/plugin/woocommerce-product-addon/). ### Documentation diff --git a/src/Core/Bootstrap/SdkCompatAndMetadataRegistration.php b/src/Core/Bootstrap/SdkCompatAndMetadataRegistration.php index 51d3c689..38cf93fc 100644 --- a/src/Core/Bootstrap/SdkCompatAndMetadataRegistration.php +++ b/src/Core/Bootstrap/SdkCompatAndMetadataRegistration.php @@ -106,21 +106,33 @@ function () { } ); + /* + * Opts into the SDK Support Hub: one Help button on PPOM's screens and the + * deactivation window. It replaces the float widget. The field groups and + * settings screens already fire `themeisle_internal_page`, so no `pages` list is needed. + */ add_filter( - 'woocommerce_product_addon_float_widget_metadata', + 'woocommerce_product_addon_support_hub_metadata', + /** + * @return array{is_pro: bool, links: list} + */ function () { - $support_link = defined( 'PPOM_PRO_PATH' ) ? tsdk_support_link( PPOM_PRO_PATH . '/ppom.php' ) : false; - return array( - 'logo' => PPOM_URL . '/images/help.svg', - 'nice_name' => 'PPOM', - 'primary_color' => '#313350', - 'pages' => array( 'woocommerce_page_ppom' ), - 'has_upgrade_menu' => ! defined( 'PPOM_PRO_PATH' ), - 'upgrade_link' => tsdk_utmify( tsdk_translate_link( PPOM_UPGRADE_URL ), 'float_widget' ), - 'documentation_link' => 'https://rviv.ly/C1cmSQ', - 'premium_support_link' => $support_link ? tsdk_translate_link( $support_link ) : '', - 'feature_request_link' => tsdk_translate_link( 'https://store.themeisle.com/suggest-a-feature/' ), + // The SDK reads this while loading PPOM, possibly before PPOM Pro's Licenser + // adds the product_ppom_license_status filter, so ask PPOM Pro for the stored license. + 'is_pro' => function_exists( '\PPOM_Pro\get_license_status' ) && 'valid' === \PPOM_Pro\get_license_status( false ), + 'links' => array( + array( + 'icon' => 'book-alt', + 'text' => __( 'Documentation', 'woocommerce-product-addon' ), + 'url' => 'https://docs.themeisle.com/collection/1695-product-option-manager', + ), + array( + 'icon' => 'groups', + 'text' => __( 'Community Forum', 'woocommerce-product-addon' ), + 'url' => 'https://wordpress.org/support/plugin/woocommerce-product-addon/', + ), + ), ); } ); diff --git a/tests/e2e/specs/support-hub.spec.js b/tests/e2e/specs/support-hub.spec.js new file mode 100644 index 00000000..e53db6b2 --- /dev/null +++ b/tests/e2e/specs/support-hub.spec.js @@ -0,0 +1,18 @@ +/** + * WordPress dependencies + */ +import { test, expect } from "@wordpress/e2e-test-utils-playwright"; + +test.describe("Support Hub", () => { + test("Help launcher shows on the PPOM Fields screen only", async ({ + admin, + page, + }) => { + await admin.visitAdminPage("admin.php?page=ppom"); + await expect(page.locator(".ti-support-launcher")).toBeVisible(); + + await admin.visitAdminPage("edit.php"); + // The SDK prints this container in admin_footer whenever the hub loads on a screen. + await expect(page.locator("#ti-support-hub")).toHaveCount(0); + }); +}); diff --git a/tests/unit/test-support-hub.php b/tests/unit/test-support-hub.php new file mode 100644 index 00000000..1db184dd --- /dev/null +++ b/tests/unit/test-support-hub.php @@ -0,0 +1,79 @@ +assertIsArray( $data ); + $this->assertSame( array( 'is_pro', 'links' ), array_keys( $data ) ); + } + + /** + * The footer links point to PPOM's docs and wordpress.org forum. + */ + public function test_links_point_to_ppom() { + $links = apply_filters( 'woocommerce_product_addon_support_hub_metadata', array() )['links']; + + $this->assertSame( + array( + 'https://docs.themeisle.com/collection/1695-product-option-manager', + 'https://wordpress.org/support/plugin/woocommerce-product-addon/', + ), + 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 PPOM Pro license is valid, + * even when the license status filter is not registered yet. + */ + public function test_is_pro_reads_the_stored_pro_license() { + remove_all_filters( 'product_ppom_license_status' ); + + update_option( 'ppom_test_pro_license_status', 'expired' ); + $this->assertFalse( apply_filters( 'woocommerce_product_addon_support_hub_metadata', array() )['is_pro'] ); + + update_option( 'ppom_test_pro_license_status', 'valid' ); + $this->assertTrue( apply_filters( 'woocommerce_product_addon_support_hub_metadata', array() )['is_pro'] ); + } + + /** + * The float widget is no longer registered: the Help button replaces it. + */ + public function test_float_widget_is_not_registered() { + $this->assertSame( array(), apply_filters( 'woocommerce_product_addon_float_widget_metadata', array() ) ); + } + } +}