Skip to content

Commit 1824c78

Browse files
committed
Sync: Factor out logic to get raw URL; Do not set scheme
1 parent bfd6b46 commit 1824c78

1 file changed

Lines changed: 18 additions & 26 deletions

File tree

sync/class.jetpack-sync-functions.php

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,28 @@ public static function file_system_write_access() {
144144
return false;
145145
}
146146

147-
public static function home_url() {
147+
/**
148+
* Helper function that is used when getting home or siteurl values. Decides
149+
* whether to get the raw or filtered value.
150+
*
151+
* @return string
152+
*/
153+
public static function get_raw_or_filtered_url( $url_type, $url_function) {
148154
if (
149155
! Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) ||
150156
Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
151157
) {
152-
$home_url = self::get_raw_url( 'home' );
158+
$url = self::get_raw_url( $url_type );
153159
} else {
154-
$home_url = self::normalize_www_in_url( 'home', 'home_url' );
160+
$url = self::normalize_www_in_url( $url_type, $url_function );
161+
$url = self::get_protocol_normalized_url( $url_function, $url );
155162
}
156163

157-
$home_url = self::get_protocol_normalized_url( 'home_url', $home_url );
164+
return $url;
165+
}
166+
167+
public static function home_url() {
168+
$url = self::get_raw_or_filtered_url( 'home', 'home_url' );
158169

159170
/**
160171
* Allows overriding of the home_url value that is synced back to WordPress.com.
@@ -163,20 +174,11 @@ public static function home_url() {
163174
*
164175
* @param string $home_url
165176
*/
166-
return esc_url_raw( apply_filters( 'jetpack_sync_home_url', $home_url ) );
177+
return esc_url_raw( apply_filters( 'jetpack_sync_home_url', $url ) );
167178
}
168179

169180
public static function site_url() {
170-
if (
171-
! Jetpack_Constants::is_defined( 'JETPACK_SYNC_USE_RAW_URL' ) ||
172-
Jetpack_Constants::get_constant( 'JETPACK_SYNC_USE_RAW_URL' )
173-
) {
174-
$site_url = self::get_raw_url( 'siteurl' );
175-
} else {
176-
$site_url = self::normalize_www_in_url( 'siteurl', 'site_url' );
177-
}
178-
179-
$site_url = self::get_protocol_normalized_url( 'site_url', $site_url );
181+
$url = self::get_raw_or_filtered_url( 'siteurl', 'site_url' );
180182

181183
/**
182184
* Allows overriding of the site_url value that is synced back to WordPress.com.
@@ -185,7 +187,7 @@ public static function site_url() {
185187
*
186188
* @param string $site_url
187189
*/
188-
return esc_url_raw( apply_filters( 'jetpack_sync_site_url', $site_url ) );
190+
return esc_url_raw( apply_filters( 'jetpack_sync_site_url', $url ) );
189191
}
190192

191193
public static function main_network_site_url() {
@@ -215,8 +217,6 @@ public static function get_protocol_normalized_url( $callable, $new_value ) {
215217
}
216218

217219
public static function get_raw_url( $option_name ) {
218-
global $wpdb;
219-
220220
$value = null;
221221
if ( 'home' == $option_name && Jetpack_Constants::is_defined( 'WP_HOME' ) ) {
222222
$value = Jetpack_Constants::get_constant( 'WP_HOME' );
@@ -228,14 +228,6 @@ public static function get_raw_url( $option_name ) {
228228
$value = Jetpack_Options::get_raw_option( $option_name );
229229
}
230230

231-
if ( is_ssl() ) {
232-
$scheme = 'https';
233-
} else {
234-
$scheme = parse_url( $value, PHP_URL_SCHEME );
235-
}
236-
237-
$value = set_url_scheme( $value, $scheme );
238-
239231
return $value;
240232
}
241233

0 commit comments

Comments
 (0)