From 9fcd0510efa8857d2c5e03d727aaf305c63abf89 Mon Sep 17 00:00:00 2001 From: Eric Binnion Date: Tue, 17 Oct 2017 11:11:40 -0500 Subject: [PATCH 1/2] Sync: Fix issue with syncing raw URLs for multisites --- sync/class.jetpack-sync-functions.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sync/class.jetpack-sync-functions.php b/sync/class.jetpack-sync-functions.php index 3532c4aeb198..a45f8d9f56f6 100644 --- a/sync/class.jetpack-sync-functions.php +++ b/sync/class.jetpack-sync-functions.php @@ -81,10 +81,10 @@ public static function get_hosting_provider() { } if ( defined( 'MM_BASE_DIR' ) ) { return 'bh'; - } + } if ( defined( 'IS_PRESSABLE' ) ) { return 'pressable'; - } + } if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) { return 'wpe'; } @@ -225,7 +225,9 @@ public static function get_raw_url( $option_name ) { ? 'WP_HOME' : 'WP_SITEURL'; - if ( Jetpack_Constants::is_defined( $constant ) ) { + // Since we disregard the constant for multisites in ms-default-filters.php, + // let's also use the db value if this is a multisite. + if ( ! is_multisite() && Jetpack_Constants::is_defined( $constant ) ) { $value = Jetpack_Constants::get_constant( $constant ); } else { // Let's get the option from the database so that we can bypass filters. This will help From d90d1f20504bd77b0dee6524443e6ddc1305f5d5 Mon Sep 17 00:00:00 2001 From: Eric Binnion Date: Tue, 17 Oct 2017 11:56:13 -0500 Subject: [PATCH 2/2] Sync: Fix failing test after updating multisite logic --- .../test_class.jetpack-sync-callables.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/php/sync/test_class.jetpack-sync-callables.php b/tests/php/sync/test_class.jetpack-sync-callables.php index dfbdb83f4345..a1ca07f564f9 100644 --- a/tests/php/sync/test_class.jetpack-sync-callables.php +++ b/tests/php/sync/test_class.jetpack-sync-callables.php @@ -146,7 +146,7 @@ function test_sync_always_sync_changes_to_modules_right_away() { Jetpack::update_active_modules( array( 'stats' ) ); $this->sender->do_sync(); - + $synced_value = $this->server_replica_storage->get_callable( 'active_modules' ); $this->assertEquals( array( 'stats' ), $synced_value ); @@ -394,7 +394,7 @@ function test_get_protocol_normalized_url_cleared_on_reset_data() { } function test_subdomain_switching_to_www_does_not_cause_sync() { - // a lot of sites accept www.domain.com or just domain.com, and we want to prevent lots of + // a lot of sites accept www.domain.com or just domain.com, and we want to prevent lots of // switching back and forth, so we force the domain to be the one in the siteurl option $this->setSyncClientDefaults(); delete_transient( Jetpack_Sync_Module_Callables::CALLABLES_AWAIT_TRANSIENT_NAME ); @@ -429,7 +429,7 @@ function test_only_syncs_if_is_admin_and_not_cron() { $this->sender->do_sync(); $this->assertEquals( null, $this->server_replica_storage->get_callable( 'site_url' ) ); - + Jetpack_Sync_Settings::set_doing_cron( false ); $this->sender->do_sync(); $this->assertEquals( site_url(), $this->server_replica_storage->get_callable( 'site_url' ) ); @@ -481,7 +481,7 @@ function test_calling_taxonomies_do_not_modify_global() { } function test_sanitize_sync_taxonomies_method() { - + $sanitized = Jetpack_Sync_Functions::sanitize_taxonomy( (object) array( 'meta_box_cb' => 'post_tags_meta_box' ) ); $this->assertEquals( $sanitized->meta_box_cb, 'post_tags_meta_box' ); @@ -513,8 +513,13 @@ function test_get_raw_url_by_constant_bypasses_filters() { add_filter( 'option_home', array( $this, '__return_filtered_url' ) ); add_filter( 'option_siteurl', array( $this, '__return_filtered_url' ) ); - $this->assertEquals( 'http://constanturl.com', Jetpack_Sync_Functions::get_raw_url( 'home' ) ); - $this->assertEquals( 'http://constanturl.com', Jetpack_Sync_Functions::get_raw_url( 'siteurl' ) ); + if ( is_multisite() ) { + $this->assertTrue( $this->__return_filtered_url() !== Jetpack_Sync_Functions::get_raw_url( 'home' ) ); + $this->assertTrue( $this->__return_filtered_url() !== Jetpack_Sync_Functions::get_raw_url( 'siteurl' ) ); + } else { + $this->assertEquals( 'http://constanturl.com', Jetpack_Sync_Functions::get_raw_url( 'home' ) ); + $this->assertEquals( 'http://constanturl.com', Jetpack_Sync_Functions::get_raw_url( 'siteurl' ) ); + } remove_filter( 'option_home', array( $this, '__return_filtered_url' ) ); remove_filter( 'option_siteurl', array( $this, '__return_filtered_url' ) ); @@ -601,7 +606,7 @@ function test_plugin_action_links_get_synced() { function __return_filtered_url() { return 'http://filteredurl.com'; } - + function add_www_subdomain_to_siteurl( $url ) { $parsed_url = parse_url( $url );