Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions images/help.svg

This file was deleted.

2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4347,7 +4347,7 @@ parameters:
-
message: '#^Constant PPOM_URL not found\.$#'
identifier: constant.notFound
count: 3
count: 2
path: src/Core/Bootstrap/SdkCompatAndMetadataRegistration.php

-
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 24 additions & 12 deletions src/Core/Bootstrap/SdkCompatAndMetadataRegistration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<array{icon: string, text: string, url: string}>}
*/
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/',
),
),
);
}
);
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/specs/support-hub.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
79 changes: 79 additions & 0 deletions tests/unit/test-support-hub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* Tests for the metadata PPOM hands to the Themeisle SDK Support Hub.
*
* @package ppom-pro
*/

namespace PPOM_Pro {
if ( ! function_exists( __NAMESPACE__ . '\get_license_status' ) ) {
/**
* Stands in for PPOM Pro's stored license lookup, which the unit suite does not load.
*
* @param bool $check_expiration Unused.
*
* @return string
*/
function get_license_status( $check_expiration = false ) {
return (string) get_option( 'ppom_test_pro_license_status', 'not_active' );
}
}
}

namespace {
/**
* Support Hub opt-in tests.
*/
class Test_Support_Hub extends WP_UnitTestCase {

/**
* The filter returns the keys PPOM opts into, and nothing else.
*/
public function test_metadata_has_the_agreed_keys() {
$data = apply_filters( 'woocommerce_product_addon_support_hub_metadata', array() );

$this->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() ) );
}
}
}
Loading