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/changelog/add-woocommerce-capabilities-sync-test b/projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test new file mode 100644 index 0000000000000..adac15cf82a48 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-woocommerce-capabilities-sync-test @@ -0,0 +1,5 @@ +Significance: patch +Type: other + +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 1270b02d10bf0..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 @@ -39,6 +39,13 @@ public function test_module_is_enabled() { $this->assertTrue( (bool) Modules::get_module( 'woocommerce' ) ); } + public function test_woocommerce_capabilities_are_whitelisted() { + $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();