From c19856e322c30b62f1f8f77d86da42db8ab32efd Mon Sep 17 00:00:00 2001 From: Umangvaghela Date: Fri, 10 Nov 2017 11:38:33 +0530 Subject: [PATCH 1/3] check schema is available or not --- sync/class.jetpack-sync-functions.php | 47 +++++++++++++++++---------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/sync/class.jetpack-sync-functions.php b/sync/class.jetpack-sync-functions.php index 1ef3f11e7bd6b..1f1b5c8cad0c3 100644 --- a/sync/class.jetpack-sync-functions.php +++ b/sync/class.jetpack-sync-functions.php @@ -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 ); } @@ -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' ) ) + ) { $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 ) + ) { $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 + ) { $cloned_taxonomy->rest_controller_class = null; } + return $cloned_taxonomy; } @@ -91,6 +97,7 @@ public static function get_hosting_provider() { if ( defined( 'VIP_GO_ENV' ) && false !== VIP_GO_ENV ) { return 'vip-go'; } + return 'unknown'; } @@ -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; } @@ -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 ); } @@ -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'] ) ) { return $new_value; } - $scheme = $parsed_url['scheme']; - $scheme_history = get_option( $option_key, array() ); + $scheme = $parsed_url['scheme']; + $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; $constant = ( 'home' == $option_name ) ? 'WP_HOME' : 'WP_SITEURL'; @@ -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']}"; @@ -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; } @@ -313,6 +323,7 @@ public static function site_icon_url() { public static function roles() { $wp_roles = wp_roles(); + return $wp_roles->roles; } From caa3e43e7e585d3d3b66ca05c06b1e5270b5b5a5 Mon Sep 17 00:00:00 2001 From: Umangvaghela Date: Fri, 10 Nov 2017 15:02:01 +0530 Subject: [PATCH 2/3] add changes which is suggested by owner --- sync/class.jetpack-sync-functions.php | 52 ++++++++++++--------------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/sync/class.jetpack-sync-functions.php b/sync/class.jetpack-sync-functions.php index 1f1b5c8cad0c3..94d902ec23d7a 100644 --- a/sync/class.jetpack-sync-functions.php +++ b/sync/class.jetpack-sync-functions.php @@ -21,17 +21,15 @@ 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 ); } @@ -49,23 +47,19 @@ 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' ) ) ) { $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 ) ) { $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 ) { $cloned_taxonomy->rest_controller_class = null; } - return $cloned_taxonomy; } @@ -97,7 +91,6 @@ public static function get_hosting_provider() { if ( defined( 'VIP_GO_ENV' ) && false !== VIP_GO_ENV ) { return 'vip-go'; } - return 'unknown'; } @@ -137,7 +130,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; } @@ -167,8 +160,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 ); } @@ -210,26 +203,29 @@ 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 ( empty ( $parsed_url['scheme'] ) ) { + if ( ! $parsed_url ) { return $new_value; } - - $scheme = $parsed_url['scheme']; - $scheme_history = get_option( $option_key, array() ); + if( array_key_exists ( 'scheme' , $parsed_url) ) { + $scheme = $parsed_url['scheme']; + } else { + $scheme = ''; + } + $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; $constant = ( 'home' == $option_name ) ? 'WP_HOME' : 'WP_SITEURL'; @@ -255,13 +251,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']}"; @@ -300,16 +296,13 @@ 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; } @@ -323,7 +316,6 @@ public static function site_icon_url() { public static function roles() { $wp_roles = wp_roles(); - return $wp_roles->roles; } From a7422d21926d1b28c97840a118be0394d4ab624f Mon Sep 17 00:00:00 2001 From: Umangvaghela Date: Fri, 10 Nov 2017 17:42:29 +0530 Subject: [PATCH 3/3] add changes --- sync/class.jetpack-sync-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sync/class.jetpack-sync-functions.php b/sync/class.jetpack-sync-functions.php index 94d902ec23d7a..89a70642b3c73 100644 --- a/sync/class.jetpack-sync-functions.php +++ b/sync/class.jetpack-sync-functions.php @@ -206,7 +206,7 @@ public static function get_protocol_normalized_url( $callable, $new_value ) { if ( ! $parsed_url ) { return $new_value; } - if( array_key_exists ( 'scheme' , $parsed_url) ) { + if ( array_key_exists ( 'scheme' , $parsed_url ) ) { $scheme = $parsed_url['scheme']; } else { $scheme = '';