Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync: check schema is available or not #8143

Merged
merged 3 commits into from
Nov 10, 2017
Merged
Changes from 1 commit
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
47 changes: 29 additions & 18 deletions sync/class.jetpack-sync-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ public static function get_taxonomies() {
$sanitized_taxonomy = self::sanitize_taxonomy( $taxonomy );
if ( ! empty( $sanitized_taxonomy ) ) {
$wp_taxonomies_without_callbacks[ $taxonomy_name ] = $sanitized_taxonomy;
} else {
} else {
error_log( 'Jetpack: Encountered a recusive taxonomy:' . $taxonomy_name );
}
}

return $wp_taxonomies_without_callbacks;
}

public static function get_shortcodes() {
global $shortcode_tags;

return array_keys( $shortcode_tags );
}

Expand All @@ -47,19 +49,23 @@ public static function sanitize_taxonomy( $taxonomy ) {
}
// Remove any meta_box_cb if they are not the default wp ones.
if ( isset( $cloned_taxonomy->meta_box_cb ) &&
! in_array( $cloned_taxonomy->meta_box_cb, array( 'post_tags_meta_box', 'post_categories_meta_box' ) ) ) {
! in_array( $cloned_taxonomy->meta_box_cb, array( 'post_tags_meta_box', 'post_categories_meta_box' ) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you meant to clarify the if statement here, it might be best to move the first check on its own line as well:

if (
    isset( $cloned_taxonomy->meta_box_cb )
    && ! in_array( $cloned_taxonomy->meta_box_cb, array( 'post_tags_meta_box', 'post_categories_meta_box' ) )
) {

) {
$cloned_taxonomy->meta_box_cb = null;
}
// Remove update call back
if ( isset( $cloned_taxonomy->update_count_callback ) &&
! is_null( $cloned_taxonomy->update_count_callback ) ) {
! is_null( $cloned_taxonomy->update_count_callback )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

) {
$cloned_taxonomy->update_count_callback = null;
}
// Remove rest_controller_class if it something other then the default.
if ( isset( $cloned_taxonomy->rest_controller_class ) &&
'WP_REST_Terms_Controller' !== $cloned_taxonomy->rest_controller_class ) {
if ( isset( $cloned_taxonomy->rest_controller_class ) &&
'WP_REST_Terms_Controller' !== $cloned_taxonomy->rest_controller_class
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

) {
$cloned_taxonomy->rest_controller_class = null;
}

return $cloned_taxonomy;
}

Expand Down Expand Up @@ -91,6 +97,7 @@ public static function get_hosting_provider() {
if ( defined( 'VIP_GO_ENV' ) && false !== VIP_GO_ENV ) {
return 'vip-go';
}

return 'unknown';
}

Expand Down Expand Up @@ -130,7 +137,7 @@ public static function file_system_write_access() {
require_once( ABSPATH . 'wp-admin/includes/template.php' );

$filesystem_method = get_filesystem_method();
if ( 'direct' === $filesystem_method ) {
if ( 'direct' === $filesystem_method ) {
return true;
}

Expand Down Expand Up @@ -160,8 +167,8 @@ public static function get_raw_or_filtered_url( $url_type ) {
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 );
$url = self::get_raw_url( $url_type );
$url = set_url_scheme( $url, $scheme );
} else {
$url = self::normalize_www_in_url( $url_type, $url_function );
}
Expand Down Expand Up @@ -203,26 +210,26 @@ public static function get_protocol_normalized_url( $callable, $new_value ) {
$option_key = self::HTTPS_CHECK_OPTION_PREFIX . $callable;

$parsed_url = wp_parse_url( $new_value );
if ( ! $parsed_url ) {
if ( empty ( $parsed_url['scheme'] ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't just return here if there's no schema set for the URL. To avoid warnings let's instead check against empty down there where we first try to access the scheme key.

return $new_value;
}

$scheme = $parsed_url['scheme'];
$scheme_history = get_option( $option_key, array() );
$scheme = $parsed_url['scheme'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we need to see if the key exists, and I'd prefer to use array_key_exists here instead of empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zinigor
If I use
if ( array_key_exists ( 'scheme' , $parsed_url) ) {
$scheme = $parsed_url['scheme'];
} else {
$scheme = '';
}
This is fine .

$scheme_history = get_option( $option_key, array() );
$scheme_history[] = $scheme;

// Limit length to self::HTTPS_CHECK_HISTORY
$scheme_history = array_slice( $scheme_history, ( self::HTTPS_CHECK_HISTORY * -1 ) );
$scheme_history = array_slice( $scheme_history, ( self::HTTPS_CHECK_HISTORY * - 1 ) );

update_option( $option_key, $scheme_history );

$forced_scheme = in_array( 'https', $scheme_history ) ? 'https' : 'http';
$forced_scheme = in_array( 'https', $scheme_history ) ? 'https' : 'http';

return set_url_scheme( $new_value, $forced_scheme );
}

public static function get_raw_url( $option_name ) {
$value = null;
$value = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid unnecessary changes like this. It's OK to remove spaces that shouldn't be there in related code, but these edits make the PR harder to review. Thanks!

$constant = ( 'home' == $option_name )
? 'WP_HOME'
: 'WP_SITEURL';
Expand All @@ -248,13 +255,13 @@ public static function normalize_www_in_url( $option, $url_function ) {
return $url;
}

if ( $url[ 'host' ] === "www.{$option_url[ 'host' ]}" ) {
if ( $url['host'] === "www.{$option_url[ 'host' ]}" ) {
// remove www if not present in option URL
$url[ 'host' ] = $option_url[ 'host' ];
$url['host'] = $option_url['host'];
}
if ( $option_url[ 'host' ] === "www.{$url[ 'host' ]}" ) {
if ( $option_url['host'] === "www.{$url[ 'host' ]}" ) {
// add www if present in option URL
$url[ 'host' ] = $option_url[ 'host' ];
$url['host'] = $option_url['host'];
}

$normalized_url = "{$url['scheme']}://{$url['host']}";
Expand Down Expand Up @@ -293,13 +300,16 @@ public static function get_plugins_action_links( $plugin_file_singular = null )
if ( is_null( $plugin_file_singular ) ) {
return $plugins_action_links;
}

return ( isset( $plugins_action_links[ $plugin_file_singular ] ) ? $plugins_action_links[ $plugin_file_singular ] : null );
}

return array();
}

public static function wp_version() {
global $wp_version;

return $wp_version;
}

Expand All @@ -313,6 +323,7 @@ public static function site_icon_url() {

public static function roles() {
$wp_roles = wp_roles();

return $wp_roles->roles;
}

Expand Down