Skip to content

Commit

Permalink
Jetpack Sync: Ensure 'jetpack_sync_callable_whitelist' filter is resp…
Browse files Browse the repository at this point in the history
…ected when added late (#37370)

* Jetpack Sync: Ensure 'jetpack_sync_callable_whitelist' filter is respected when added late
  • Loading branch information
fgiannar authored May 14, 2024
1 parent 4424768 commit 491451f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Jetpack Sync: Ensure 'jetpack_sync_callable_whitelist' filter is respected when added late
2 changes: 1 addition & 1 deletion projects/packages/sync/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '2.16.1';
const PACKAGE_VERSION = '2.16.2-alpha';

const PACKAGE_SLUG = 'sync';

Expand Down
22 changes: 22 additions & 0 deletions projects/packages/sync/src/modules/class-callables.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ public function set_defaults() {
$this->force_send_callables_on_next_tick = false; // Resets here as well mostly for tests.
}

/**
* Set module defaults at a later time.
* Reset the callable whitelist if needed to account for plugins adding the 'jetpack_sync_callable_whitelist'
* and 'jetpack_sync_multisite_callable_whitelist' filters late.
*
* @see Automattic\Jetpack\Sync\Modules::set_module_defaults
* @access public
*/
public function set_late_default() {
if ( is_multisite() ) {
$late_callables = array_merge(
apply_filters( 'jetpack_sync_callable_whitelist', array() ),
apply_filters( 'jetpack_sync_multisite_callable_whitelist', array() )
);
} else {
$late_callables = apply_filters( 'jetpack_sync_callable_whitelist', array() );
}
if ( ! empty( $late_callables ) && is_array( $late_callables ) ) {
$this->callable_whitelist = array_merge( $this->callable_whitelist, $late_callables );
}
}

/**
* Initialize callables action listeners.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: other
Comment: Updated Sync related unit tests


2 changes: 1 addition & 1 deletion projects/plugins/jetpack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"platform": {
"ext-intl": "0.0.0"
},
"autoloader-suffix": "f11009ded9fc4592b6a05b61ce272b3c_jetpackⓥ13_5_a_1",
"autoloader-suffix": "f11009ded9fc4592b6a05b61ce272b3c_jetpackⓥ13_5_a_2",
"allow-plugins": {
"automattic/jetpack-autoloader": true,
"automattic/jetpack-composer-plugin": true
Expand Down
4 changes: 2 additions & 2 deletions projects/plugins/jetpack/jetpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://jetpack.com
* Description: Security, performance, and marketing tools made by WordPress experts. Jetpack keeps your site protected so you can focus on more important things.
* Author: Automattic
* Version: 13.5-a.1
* Version: 13.5-a.2
* Author URI: https://jetpack.com
* License: GPL2+
* Text Domain: jetpack
Expand Down Expand Up @@ -34,7 +34,7 @@

define( 'JETPACK__MINIMUM_WP_VERSION', '6.4' );
define( 'JETPACK__MINIMUM_PHP_VERSION', '7.0' );
define( 'JETPACK__VERSION', '13.5-a.1' );
define( 'JETPACK__VERSION', '13.5-a.2' );

/**
* Constant used to fetch the connection owner token
Expand Down
2 changes: 1 addition & 1 deletion projects/plugins/jetpack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Jetpack",
"version": "13.5.0-a.1",
"version": "13.5.0-a.2",
"private": true,
"description": "[Jetpack](https://jetpack.com/) is a WordPress plugin that supercharges your self-hosted WordPress site with the awesome cloud power of [WordPress.com](https://wordpress.com).",
"homepage": "https://jetpack.com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,26 @@ public function test_white_listed_callable_sync_on_next_tick() {
$this->assertNotEquals( $initial_value, $new_value );
}

/**
* Tests that calling set_late_default works as expected.
*
* Return null
*/
public function test_sync_callable_set_late_default() {
$this->callable_module->set_callable_whitelist( array() );

add_filter( 'jetpack_sync_callable_whitelist', array( $this, 'filter_sync_callable_whitelist' ) );

$this->callable_module->set_late_default();

remove_filter( 'jetpack_sync_callable_whitelist', array( $this, 'filter_sync_callable_whitelist' ) );

$this->sender->do_sync();

$synced_value = $this->server_replica_storage->get_callable( 'jetpack_foo' );
$this->assertEquals( jetpack_foo_is_callable(), $synced_value );
}

/**
* Tests that updating the theme should result in the no callabled transient being set.
*
Expand Down Expand Up @@ -976,6 +996,18 @@ public function add_www_subdomain_to_siteurl( $url ) {
return "{$parsed_url['scheme']}://www.{$parsed_url['host']}";
}

/**
* Filters the sync callable whitelist.
*
* @param array $whitelist The sync callable whitelist.
* @return array
*/
public function filter_sync_callable_whitelist( $whitelist ) {
$whitelist['jetpack_foo'] = 'jetpack_foo_is_callable';

return $whitelist;
}

/**
* Test "taxonomies_objects_do_not_have_meta_box_callback".
*/
Expand Down

0 comments on commit 491451f

Please sign in to comment.