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
16 changes: 9 additions & 7 deletions sync/class.jetpack-sync-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down Expand Up @@ -151,20 +151,22 @@ public static function file_system_write_access() {
* @return string
*/
public static function get_raw_or_filtered_url( $url_type ) {
$url_function = ( 'home' == $url_type )
? 'home_url'
: 'site_url';

if (
! Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) ||
Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
) {
$scheme = is_ssl() ? 'https' : 'http';
$url = self::get_raw_url( $url_type );
$url = set_url_scheme( $url, $scheme );
} else {
$url_function = ( 'home' == $url_type )
? 'home_url'
: 'site_url';
$url = self::normalize_www_in_url( $url_type, $url_function );
$url = self::get_protocol_normalized_url( $url_function, $url );
}

return $url;
return self::get_protocol_normalized_url( $url_function, $url );
}

public static function home_url() {
Expand Down
30 changes: 25 additions & 5 deletions tests/php/sync/test_class.jetpack-sync-callables.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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' ) );
Expand Down Expand Up @@ -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' );

Expand Down Expand Up @@ -536,6 +536,26 @@ function test_get_raw_url_returns_with_http_if_is_ssl() {
unset( $_SERVER['HTTPS'] );
}

function test_raw_home_url_is_https_when_is_ssl() {
Jetpack_Constants::set_constant( 'JETPACK_SYNC_USE_RAW_URL', true );

$home_option = get_option( 'home' );

// Test without https first
$this->assertEquals(
$home_option,
Jetpack_Sync_Functions::home_url()
);

// Now, with https
$_SERVER['HTTPS'] = 'on';
$this->assertEquals(
set_url_scheme( $home_option, 'https' ),
Jetpack_Sync_Functions::home_url()
);
unset( $_SERVER['HTTPS'] );
}

function test_user_can_stop_raw_urls() {
add_filter( 'option_home', array( $this, '__return_filtered_url' ) );
add_filter( 'option_siteurl', array( $this, '__return_filtered_url' ) );
Expand Down Expand Up @@ -601,7 +621,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 );

Expand Down