From 4724ee2f8cf74c76e688b8783aeb5d429fbc3246 Mon Sep 17 00:00:00 2001 From: Chris Blower Date: Fri, 10 Oct 2025 14:46:20 +0100 Subject: [PATCH 1/3] Sync: Add WooCommerce capabilities to sync whitelist Add `manage_woocommerce` and `view_woocommerce_reports` capabilities to the Jetpack Sync capabilities whitelist. This enables WPCOM to check WooCommerce permissions for connected users, which is needed for AI Abilities and other WooCommerce integrations. - Add `$wc_capabilities_whitelist` array to WooCommerce sync module - Add `add_woocommerce_capabilities_whitelist()` method to filter capabilities --- .../add-manage-woocommerce-capability | 5 ++++ .../sync/src/modules/class-woocommerce.php | 24 +++++++++++++++++++ .../sync/Jetpack_Sync_WooCommerce_Test.php | 8 +++++++ 3 files changed, 37 insertions(+) create mode 100644 projects/packages/sync/changelog/add-manage-woocommerce-capability diff --git a/projects/packages/sync/changelog/add-manage-woocommerce-capability b/projects/packages/sync/changelog/add-manage-woocommerce-capability new file mode 100644 index 0000000000000..aac94793d4eb5 --- /dev/null +++ b/projects/packages/sync/changelog/add-manage-woocommerce-capability @@ -0,0 +1,5 @@ +Significance: patch +Type: added + +Add manage_woocommerce and view_woocommerce_reports capabilities to sync whitelist for WooCommerce integration. + diff --git a/projects/packages/sync/src/modules/class-woocommerce.php b/projects/packages/sync/src/modules/class-woocommerce.php index b09346030134b..2df99ef34e42a 100644 --- a/projects/packages/sync/src/modules/class-woocommerce.php +++ b/projects/packages/sync/src/modules/class-woocommerce.php @@ -127,6 +127,7 @@ public function __construct() { add_filter( 'jetpack_sync_constants_whitelist', array( $this, 'add_woocommerce_constants_whitelist' ), 10 ); add_filter( 'jetpack_sync_post_meta_whitelist', array( $this, 'add_woocommerce_post_meta_whitelist' ), 10 ); add_filter( 'jetpack_sync_comment_meta_whitelist', array( $this, 'add_woocommerce_comment_meta_whitelist' ), 10 ); + add_filter( 'jetpack_sync_capabilities_whitelist', array( $this, 'add_woocommerce_capabilities_whitelist' ), 10 ); add_filter( 'jetpack_sync_before_enqueue_woocommerce_new_order_item', array( $this, 'filter_order_item' ) ); add_filter( 'jetpack_sync_before_enqueue_woocommerce_update_order_item', array( $this, 'filter_order_item' ) ); @@ -393,6 +394,16 @@ public function add_woocommerce_comment_meta_whitelist( $list ) { return array_merge( $list, self::$wc_comment_meta_whitelist ); } + /** + * Add WooCommerce capabilities to the capabilities whitelist. + * + * @param array $list Existing capabilities whitelist. + * @return array Updated capabilities whitelist. + */ + public function add_woocommerce_capabilities_whitelist( $list ) { + return array_merge( $list, self::$wc_capabilities_whitelist ); + } + /** * Adds 'revew' to the list of comment types so Sync will listen for status changes on 'reviews'. * @@ -628,6 +639,19 @@ public function filter_action_scheduler_comments( $can_sync, $comment ) { 'rating', ); + /** + * Whitelist for capabilities we are interested to sync. + * + * @access private + * @static + * + * @var array + */ + private static $wc_capabilities_whitelist = array( + 'manage_woocommerce', + 'view_woocommerce_reports', + ); + /** * Return a list of objects by their type and IDs * diff --git a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php index 1270b02d10bf0..37511cfaecd99 100644 --- a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php +++ b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php @@ -39,6 +39,14 @@ public function test_module_is_enabled() { $this->assertTrue( (bool) Modules::get_module( 'woocommerce' ) ); } + public function test_woocommerce_capabilities_are_whitelisted() { + $woocommerce_module = Modules::get_module( 'woocommerce' ); + $capabilities_whitelist = apply_filters( 'jetpack_sync_capabilities_whitelist', array() ); + + $this->assertContains( 'manage_woocommerce', $capabilities_whitelist ); + $this->assertContains( 'view_woocommerce_reports', $capabilities_whitelist ); + } + /** Incremental sync **/ public function test_orders_are_synced() { $order = $this->createOrderWithItem(); From 1c677dcbf0ef46eb1ff1fd2e3163644a52b89ce6 Mon Sep 17 00:00:00 2001 From: Chris Blower Date: Fri, 10 Oct 2025 16:29:27 +0100 Subject: [PATCH 2/3] fix test; add changelog for test --- .../jetpack/changelog/add-woocommerce-capabilities-sync-test | 5 +++++ .../jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test diff --git a/projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test b/projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test new file mode 100644 index 0000000000000..83a9a711d830c --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test @@ -0,0 +1,5 @@ +Significance: patch +Type: added + +Add test to verify WooCommerce capabilities are synced. + diff --git a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php index 37511cfaecd99..9d8aa190afe48 100644 --- a/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php +++ b/projects/plugins/jetpack/tests/php/sync/Jetpack_Sync_WooCommerce_Test.php @@ -40,7 +40,6 @@ public function test_module_is_enabled() { } public function test_woocommerce_capabilities_are_whitelisted() { - $woocommerce_module = Modules::get_module( 'woocommerce' ); $capabilities_whitelist = apply_filters( 'jetpack_sync_capabilities_whitelist', array() ); $this->assertContains( 'manage_woocommerce', $capabilities_whitelist ); From 2b80ff00500b6563b99ce3d35cdf6df747b7e267 Mon Sep 17 00:00:00 2001 From: Chris Blower Date: Fri, 10 Oct 2025 16:31:27 +0100 Subject: [PATCH 3/3] other --- .../jetpack/changelog/add-woocommerce-capabilities-sync-test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test b/projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test index 83a9a711d830c..adac15cf82a48 100644 --- a/projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test +++ b/projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test @@ -1,5 +1,5 @@ Significance: patch -Type: added +Type: other Add test to verify WooCommerce capabilities are synced.