From 38a805d24a890dea4b5e90851693afb4e2041c9e Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Sun, 16 Apr 2017 04:35:35 -0400 Subject: Update jetpack 4.8.2 --- .../jetpack/sync/class.jetpack-sync-actions.php | 27 ++++- .../jetpack/sync/class.jetpack-sync-defaults.php | 72 ++++++++++++- .../jetpack/sync/class.jetpack-sync-functions.php | 3 + .../jetpack/sync/class.jetpack-sync-listener.php | 56 +++++++++-- .../sync/class.jetpack-sync-module-callables.php | 8 +- .../sync/class.jetpack-sync-module-constants.php | 13 +-- .../sync/class.jetpack-sync-module-options.php | 3 +- .../sync/class.jetpack-sync-module-posts.php | 112 +++++++++++---------- .../sync/class.jetpack-sync-module-users.php | 52 ++++++++-- .../sync/class.jetpack-sync-module-woocommerce.php | 112 +++++++++++++++++++++ .../class.jetpack-sync-module-wp-super-cache.php | 79 +++++++++++++++ .../jetpack/sync/class.jetpack-sync-modules.php | 12 ++- .../jetpack/sync/class.jetpack-sync-settings.php | 2 +- .../sync/class.jetpack-sync-wp-replicastore.php | 12 +++ .../sync/interface.jetpack-sync-replicastore.php | 6 ++ 15 files changed, 477 insertions(+), 92 deletions(-) create mode 100644 plugins/jetpack/sync/class.jetpack-sync-module-wp-super-cache.php (limited to 'plugins/jetpack/sync') diff --git a/plugins/jetpack/sync/class.jetpack-sync-actions.php b/plugins/jetpack/sync/class.jetpack-sync-actions.php index 193c4bdb..43f45cdc 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-actions.php +++ b/plugins/jetpack/sync/class.jetpack-sync-actions.php @@ -282,9 +282,10 @@ class Jetpack_Sync_Actions { } static function initialize_woocommerce() { - if ( class_exists( 'WooCommerce' ) ) { - add_filter( 'jetpack_sync_modules', array( 'Jetpack_Sync_Actions', 'add_woocommerce_sync_module' ) ); + if ( false === class_exists( 'WooCommerce' ) ) { + return; } + add_filter( 'jetpack_sync_modules', array( 'Jetpack_Sync_Actions', 'add_woocommerce_sync_module' ) ); } static function add_woocommerce_sync_module( $sync_modules ) { @@ -293,6 +294,19 @@ class Jetpack_Sync_Actions { return $sync_modules; } + static function initialize_wp_super_cache() { + if ( false === function_exists( 'wp_cache_is_enabled' ) ) { + return; + } + add_filter( 'jetpack_sync_modules', array( 'Jetpack_Sync_Actions', 'add_wp_super_cache_sync_module' ) ); + } + + static function add_wp_super_cache_sync_module( $sync_modules ) { + require_once dirname( __FILE__ ) . '/class.jetpack-sync-module-wp-super-cache.php'; + $sync_modules[] = 'Jetpack_Sync_Module_WP_Super_Cache'; + return $sync_modules; + } + static function sanitize_filtered_sync_cron_schedule( $schedule ) { $schedule = sanitize_key( $schedule ); $schedules = wp_get_schedules(); @@ -417,14 +431,19 @@ class Jetpack_Sync_Actions { } } +// Check for WooCommerce support +add_action( 'plugins_loaded', array( 'Jetpack_Sync_Actions', 'initialize_woocommerce' ), 5 ); + +// Check for WP Super Cache +add_action( 'plugins_loaded', array( 'Jetpack_Sync_Actions', 'initialize_wp_super_cache' ), 5 ); + /* * Init after plugins loaded and before the `init` action. This helps with issues where plugins init * with a high priority or sites that use alternate cron. */ add_action( 'plugins_loaded', array( 'Jetpack_Sync_Actions', 'init' ), 90 ); -// Check for WooCommerce support -add_action( 'plugins_loaded', array( 'Jetpack_Sync_Actions', 'initialize_woocommerce' ), 5 ); + // We need to define this here so that it's hooked before `updating_jetpack_version` is called add_action( 'updating_jetpack_version', array( 'Jetpack_Sync_Actions', 'do_initial_sync' ), 10, 2 ); diff --git a/plugins/jetpack/sync/class.jetpack-sync-defaults.php b/plugins/jetpack/sync/class.jetpack-sync-defaults.php index c7b42125..a2987a99 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-defaults.php +++ b/plugins/jetpack/sync/class.jetpack-sync-defaults.php @@ -5,6 +5,7 @@ require_once( JETPACK__PLUGIN_DIR . 'modules/sso/class.jetpack-sso-helpers.php' * Just some defaults that we share with the server */ class Jetpack_Sync_Defaults { + static $default_options_whitelist = array( 'stylesheet', 'blogname', @@ -111,6 +112,21 @@ class Jetpack_Sync_Defaults { 'jetpack_api_cache_enabled', ); + public static function get_options_whitelist() { + /** This filter is already documented in json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php */ + $options_whitelist = apply_filters( 'jetpack_options_whitelist', self::$default_options_whitelist ); + /** + * Filter the list of WordPress options that are manageable via the JSON API. + * + * @module sync + * + * @since 4.8 + * + * @param array The default list of options. + */ + return apply_filters( 'jetpack_sync_options_whitelist', $options_whitelist ); + } + static $default_constants_whitelist = array( 'EMPTY_TRASH_DAYS', 'WP_POST_REVISIONS', @@ -128,9 +144,22 @@ class Jetpack_Sync_Defaults { 'DISABLE_WP_CRON', 'ALTERNATE_WP_CRON', 'WP_CRON_LOCK_TIMEOUT', - 'PHP_VERSION' + 'PHP_VERSION', ); + public static function get_constants_whitelist() { + /** + * Filter the list of PHP constants that are manageable via the JSON API. + * + * @module sync + * + * @since 4.8 + * + * @param array The default list of constants options. + */ + return apply_filters( 'jetpack_sync_constants_whitelist', self::$default_constants_whitelist ); + } + static $default_callable_whitelist = array( 'wp_max_upload_size' => 'wp_max_upload_size', 'is_main_network' => array( 'Jetpack', 'is_multi_network' ), @@ -161,6 +190,19 @@ class Jetpack_Sync_Defaults { 'site_icon_url' => array( 'Jetpack_Sync_Functions', 'site_icon_url' ), ); + public static function get_callable_whitelist() { + /** + * Filter the list of callables that are manageable via the JSON API. + * + * @module sync + * + * @since 4.8 + * + * @param array The default list of callables. + */ + return apply_filters( 'jetpack_sync_callable_whitelist', self::$default_callable_whitelist ); + } + static $blacklisted_post_types = array( 'ai1ec_event', 'snitch', @@ -171,6 +213,8 @@ class Jetpack_Sync_Defaults { 'idx_page', 'postman_sent_mail', 'rssmi_feed_item', + 'rssap-feed', + 'wp_automatic', ); static $default_post_checksum_columns = array( @@ -207,6 +251,19 @@ class Jetpack_Sync_Defaults { 'network_enable_administration_menus' => array( 'Jetpack', 'network_enable_administration_menus' ), ); + public static function get_multisite_callable_whitelist() { + /** + * Filter the list of multisite callables that are manageable via the JSON API. + * + * @module sync + * + * @since 4.8 + * + * @param array The default list of multisite callables. + */ + return apply_filters( 'jetpack_sync_multisite_callable_whitelist', self::$default_multisite_callable_whitelist ); + } + static $post_meta_whitelist = array( '_feedback_akismet_values', '_feedback_email', @@ -247,6 +304,19 @@ class Jetpack_Sync_Defaults { 'advanced_seo_description', // Jetpack_SEO_Posts::DESCRIPTION_META_KEY ); + public static function get_post_meta_whitelist() { + /** + * Filter the list of post meta data that are manageable via the JSON API. + * + * @module sync + * + * @since 4.8 + * + * @param array The default list of meta data keys. + */ + return apply_filters( 'jetpack_sync_post_meta_whitelist', self::$post_meta_whitelist ); + } + static $comment_meta_whitelist = array( 'hc_avatar', 'hc_post_as', diff --git a/plugins/jetpack/sync/class.jetpack-sync-functions.php b/plugins/jetpack/sync/class.jetpack-sync-functions.php index 905d187e..596af357 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-functions.php +++ b/plugins/jetpack/sync/class.jetpack-sync-functions.php @@ -88,6 +88,9 @@ class Jetpack_Sync_Functions { if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) { return 'wpe'; } + if ( defined( 'VIP_GO_ENV' ) && false !== VIP_GO_ENV ) { + return 'vip-go'; + } return 'unknown'; } diff --git a/plugins/jetpack/sync/class.jetpack-sync-listener.php b/plugins/jetpack/sync/class.jetpack-sync-listener.php index 508f5b55..4ff5b291 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-listener.php +++ b/plugins/jetpack/sync/class.jetpack-sync-listener.php @@ -197,13 +197,34 @@ class Jetpack_Sync_Listener { ignore_user_abort( true ); } - $queue->add( array( - $current_filter, - $args, - get_current_user_id(), - microtime( true ), - Jetpack_Sync_Settings::is_importing() - ) ); + if ( + 'sync' === $queue->id || + in_array( + $current_filter, + array( + 'jetpack_full_sync_start', + 'jetpack_full_sync_end', + 'jetpack_full_sync_cancel' + ) + ) + ) { + $queue->add( array( + $current_filter, + $args, + get_current_user_id(), + microtime( true ), + Jetpack_Sync_Settings::is_importing(), + $this->get_actor(), + ) ); + } else { + $queue->add( array( + $current_filter, + $args, + get_current_user_id(), + microtime( true ), + Jetpack_Sync_Settings::is_importing() + ) ); + } // since we've added some items, let's try to load the sender so we can send them as quickly as possible if ( ! Jetpack_Sync_Actions::$sender ) { @@ -213,6 +234,27 @@ class Jetpack_Sync_Listener { } } } + function get_actor() { + $current_user = wp_get_current_user(); + $actor = array(); + if ( $current_user ) { + $actor[ 'display_name' ] = $current_user->display_name; + $actor[ 'user_email' ] = $current_user->user_email; + } + + if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { + $actor[ 'ip' ] = $_SERVER['REMOTE_ADDR']; + } + + $actor['is_cron'] = defined( 'DOING_CRON' ) ? DOING_CRON : false; + $actor['is_wp_admin'] = is_admin(); + $actor['is_rest'] = defined( 'REST_API_REQUEST' ) ? REST_API_REQUEST : false; + $actor['is_xmlrpc'] = defined( 'XMLRPC_REQUEST' ) ? XMLRPC_REQUEST : false; + $actor['is_wp_rest'] = defined( 'REST_REQUEST' ) ? REST_REQUEST : false; + $actor['is_ajax'] = defined( 'DOING_AJAX' ) ? DOING_AJAX : false; + + return $actor; + } function set_defaults() { $this->sync_queue = new Jetpack_Sync_Queue( 'sync' ); diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-callables.php b/plugins/jetpack/sync/class.jetpack-sync-module-callables.php index 90d9c1fd..b0565213 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-callables.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-callables.php @@ -14,9 +14,9 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module { public function set_defaults() { if ( is_multisite() ) { - $this->callable_whitelist = array_merge( Jetpack_Sync_Defaults::$default_callable_whitelist, Jetpack_Sync_Defaults::$default_multisite_callable_whitelist ); + $this->callable_whitelist = array_merge( Jetpack_Sync_Defaults::get_callable_whitelist(), Jetpack_Sync_Defaults::get_multisite_callable_whitelist() ); } else { - $this->callable_whitelist = Jetpack_Sync_Defaults::$default_callable_whitelist; + $this->callable_whitelist = Jetpack_Sync_Defaults::get_callable_whitelist(); } } @@ -77,8 +77,8 @@ class Jetpack_Sync_Module_Callables extends Jetpack_Sync_Module { $current_user_id = get_current_user_id(); wp_set_current_user( Jetpack_Options::get_option( 'master_user' ) ); $callables = array_combine( - array_keys( $this->callable_whitelist ), - array_map( array( $this, 'get_callable' ), array_values( $this->callable_whitelist ) ) + array_keys( $this->get_callable_whitelist() ), + array_map( array( $this, 'get_callable' ), array_values( $this->get_callable_whitelist() ) ) ); wp_set_current_user( $current_user_id ); diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-constants.php b/plugins/jetpack/sync/class.jetpack-sync-module-constants.php index c473f19f..ae9ca127 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-constants.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-constants.php @@ -10,12 +10,6 @@ class Jetpack_Sync_Module_Constants extends Jetpack_Sync_Module { return 'constants'; } - private $constants_whitelist; - - public function set_defaults() { - $this->constants_whitelist = Jetpack_Sync_Defaults::$default_constants_whitelist; - } - public function init_listeners( $callable ) { add_action( 'jetpack_sync_constant', $callable, 10, 2 ); } @@ -41,7 +35,7 @@ class Jetpack_Sync_Module_Constants extends Jetpack_Sync_Module { } function get_constants_whitelist() { - return $this->constants_whitelist; + return Jetpack_Sync_Defaults::get_constants_whitelist(); } function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { @@ -103,9 +97,10 @@ class Jetpack_Sync_Module_Constants extends Jetpack_Sync_Module { // public so that we don't have to store an option for each constant function get_all_constants() { + $constants_whitelist = $this->get_constants_whitelist(); return array_combine( - $this->constants_whitelist, - array_map( array( $this, 'get_constant' ), $this->constants_whitelist ) + $constants_whitelist, + array_map( array( $this, 'get_constant' ), $constants_whitelist ) ); } diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-options.php b/plugins/jetpack/sync/class.jetpack-sync-module-options.php index eeede489..12fe91a3 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-options.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-options.php @@ -85,8 +85,7 @@ class Jetpack_Sync_Module_Options extends Jetpack_Sync_Module { } function update_options_whitelist() { - /** This filter is already documented in json-endpoints/jetpack/class.wpcom-json-api-get-option-endpoint.php */ - $this->options_whitelist = apply_filters( 'jetpack_options_whitelist', Jetpack_Sync_Defaults::$default_options_whitelist ); + $this->options_whitelist = Jetpack_Sync_Defaults::get_options_whitelist(); } function set_options_whitelist( $options ) { diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-posts.php b/plugins/jetpack/sync/class.jetpack-sync-module-posts.php index be31c761..3c31bbf7 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-posts.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-posts.php @@ -5,6 +5,7 @@ require_once dirname( __FILE__ ) . '/class.jetpack-sync-settings.php'; class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { private $just_published = array(); + private $action_handler; public function name() { return 'posts'; @@ -22,10 +23,15 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { } public function init_listeners( $callable ) { - add_action( 'wp_insert_post', $callable, 10, 3 ); - add_action( 'wp_insert_post', array( $this, 'send_published'), 11, 3 ); + $this->action_handler = $callable; + + // Core < 4.7 doesn't deal with nested wp_insert_post calls very well + global $wp_version; + $priority = version_compare( $wp_version, '4.7-alpha', '<' ) ? 0 : 11; + + add_action( 'wp_insert_post', array( $this, 'wp_insert_post' ), $priority, 3 ); + add_action( 'deleted_post', $callable, 10 ); - add_action( 'jetpack_publicize_post', $callable ); add_action( 'jetpack_published_post', $callable, 10, 2 ); add_action( 'transition_post_status', array( $this, 'save_published' ), 10, 3 ); add_filter( 'jetpack_sync_before_enqueue_wp_insert_post', array( $this, 'filter_blacklisted_post_types' ) ); @@ -66,7 +72,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { // config is a list of post IDs to sync if ( is_array( $config ) ) { - $where_sql .= ' AND ID IN (' . implode( ',', array_map( 'intval', $config ) ) . ')'; + $where_sql .= ' AND ID IN (' . implode( ',', array_map( 'intval', $config ) ) . ')'; } return $where_sql; @@ -78,8 +84,11 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { /** * Process content before send + * + * @param array $args wp_insert_post arguments + * + * @return array */ - function expand_wp_insert_post( $args ) { return array( $args[0], $this->filter_post_content_and_add_links( $args[1] ), $args[2] ); } @@ -110,6 +119,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { function is_post_type_allowed( $post_id ) { $post = get_post( $post_id ); + return ! in_array( $post->post_type, Jetpack_Sync_Settings::get_setting( 'post_types_blacklist' ) ); } @@ -138,13 +148,13 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { // return non existant post $post_type = get_post_type_object( $post->post_type ); - if ( empty( $post_type) || ! is_object( $post_type ) ) { + if ( empty( $post_type ) || ! is_object( $post_type ) ) { $non_existant_post = new stdClass(); $non_existant_post->ID = $post->ID; $non_existant_post->post_modified = $post->post_modified; $non_existant_post->post_modified_gmt = $post->post_modified_gmt; $non_existant_post->post_status = 'jetpack_sync_non_registered_post_type'; - + return $non_existant_post; } /** @@ -179,9 +189,8 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { } /** This filter is already documented in core. wp-includes/post-template.php */ - if ( Jetpack_Sync_Settings::get_setting( 'render_filtered_content' ) && $post_type->public ) { + if ( Jetpack_Sync_Settings::get_setting( 'render_filtered_content' ) && $post_type->public ) { global $shortcode_tags; - $shortcodes_and_callbacks_to_remove = array(); /** * Filter prevents some shortcodes from expanding. * @@ -192,22 +201,25 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { * * @param array of shortcode tags to remove. */ - $shortcodes_to_remove = apply_filters( 'jetpack_sync_do_not_expand_shortcodes', array( 'gallery', 'slideshow' ) ); + $shortcodes_to_remove = apply_filters( 'jetpack_sync_do_not_expand_shortcodes', array( + 'gallery', + 'slideshow' + ) ); $removed_shortcode_callbacks = array(); foreach ( $shortcodes_to_remove as $shortcode ) { - if ( isset ( $shortcode_tags[ $shortcode ] ) ) { - $removed_shortcode_callbacks[ $shortcode ] = $shortcode_tags[ $shortcode ]; + if ( isset ( $shortcode_tags[ $shortcode ] ) ) { + $removed_shortcode_callbacks[ $shortcode ] = $shortcode_tags[ $shortcode ]; } } - array_map( 'remove_shortcode' , array_keys( $removed_shortcode_callbacks ) ); + array_map( 'remove_shortcode', array_keys( $removed_shortcode_callbacks ) ); - $post->post_content_filtered = apply_filters( 'the_content', $post->post_content ); - $post->post_excerpt_filtered = apply_filters( 'the_excerpt', $post->post_excerpt ); + $post->post_content_filtered = apply_filters( 'the_content', $post->post_content ); + $post->post_excerpt_filtered = apply_filters( 'the_excerpt', $post->post_excerpt ); foreach ( $removed_shortcode_callbacks as $shortcode => $callback ) { - add_shortcode( $shortcode, $callback ); - } + add_shortcode( $shortcode, $callback ); + } } $this->add_embed(); @@ -219,8 +231,8 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { } } - $post->permalink = get_permalink( $post->ID ); - $post->shortlink = wp_get_shortlink( $post->ID ); + $post->permalink = get_permalink( $post->ID ); + $post->shortlink = wp_get_shortlink( $post->ID ); return $post; } @@ -231,44 +243,42 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { } } - public function send_published( $post_ID, $post, $update ) { + public function wp_insert_post( $post_ID, $post, $update ) { + call_user_func( $this->action_handler, $post_ID, $post, $update ); + $this->send_published( $post_ID, $post ); + } + + public function send_published( $post_ID, $post ) { + if ( ! in_array( $post_ID, $this->just_published ) ) { + return; + } + // Post revisions cause race conditions where this send_published add the action before the actual post gets synced if ( wp_is_post_autosave( $post ) || wp_is_post_revision( $post ) ) { return; } - if ( ! empty( $this->just_published ) && in_array( $post_ID, $this->just_published ) ) { - $published = array_reverse( array_unique( $this->just_published ) ); - - // Pre 4.7 WP does not have run though send_published for every save_published call - // So lets clear out any just_published that we recorded - foreach ( $published as $just_published_post_ID ) { - if ( $post_ID !== $just_published_post_ID ) { - $post = get_post( $just_published_post_ID ); - } + /** + * Filter that is used to add to the post flags ( meta data ) when a post gets published + * + * @since 4.4.0 + * + * @param mixed array post flags that are added to the post + * @param mixed $post WP_POST object + */ + $flags = apply_filters( 'jetpack_published_post_flags', array(), $post ); - /** - * Filter that is used to add to the post flags ( meta data ) when a post gets published - * - * @since 4.4.0 - * - * @param mixed array post flags that are added to the post - * @param mixed $post WP_POST object - */ - $flags = apply_filters( 'jetpack_published_post_flags', array(), $post ); - - /** - * Action that gets synced when a post type gets published. - * - * @since 4.4.0 - * - * @param int post_id - * @param mixed array post flags that are added to the post - */ - do_action( 'jetpack_published_post', $just_published_post_ID, $flags ); - } - $this->just_published = array(); - } + /** + * Action that gets synced when a post type gets published. + * + * @since 4.4.0 + * + * @param int $post_ID + * @param mixed array $flags post flags that are added to the post + */ + do_action( 'jetpack_published_post', $post_ID, $flags ); + + $this->just_published = array_diff( $this->just_published, array( $post_ID ) ); } public function expand_post_ids( $args ) { diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-users.php b/plugins/jetpack/sync/class.jetpack-sync-module-users.php index 2df50af5..e488a579 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-users.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-users.php @@ -2,7 +2,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { const MAX_INITIAL_SYNC_USERS = 100; - + function name() { return 'users'; } @@ -22,6 +22,8 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { add_action( 'profile_update', array( $this, 'save_user_handler' ), 10, 2 ); add_action( 'add_user_to_blog', array( $this, 'save_user_handler' ) ); add_action( 'jetpack_sync_save_user', $callable, 10, 2 ); + add_action( 'jetpack_sync_user_locale', $callable, 10, 2 ); + add_action( 'jetpack_sync_user_locale_delete', $callable, 10, 1 ); add_action( 'deleted_user', $callable, 10, 2 ); add_action( 'remove_user_from_blog', $callable, 10, 2 ); @@ -32,14 +34,15 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { add_action( 'remove_user_role', array( $this, 'save_user_role_handler' ), 10, 2 ); // user capabilities - add_action( 'added_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 ); - add_action( 'updated_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 ); - add_action( 'deleted_user_meta', array( $this, 'save_user_cap_handler' ), 10, 4 ); + add_action( 'added_user_meta', array( $this, 'maybe_save_user_meta' ), 10, 4 ); + add_action( 'updated_user_meta', array( $this, 'maybe_save_user_meta' ), 10, 4 ); + add_action( 'deleted_user_meta', array( $this, 'maybe_save_user_meta' ), 10, 4 ); // user authentication add_action( 'wp_login', $callable, 10, 2 ); add_action( 'wp_login_failed', $callable, 10, 2 ); add_action( 'wp_logout', $callable, 10, 0 ); + add_action( 'wp_masterbar_logout', $callable, 10, 0 ); } public function init_full_sync_listeners( $callable ) { @@ -75,6 +78,13 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { public function add_to_user( $user ) { $user->allowed_mime_types = get_allowed_mime_types( $user ); + if ( function_exists( 'get_user_locale' ) ) { + + // Only set the user locale if it is different from the site local + if ( get_locale() !== get_user_locale( $user->ID ) ) { + $user->locale = get_user_locale( $user->ID ); + } + } return $user; } @@ -82,7 +92,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { list( $user ) = $args; if ( $user ) { - return array( $this->add_to_user( $user ) ); + return array( $this->add_to_user( $user ) ); } return false; @@ -107,7 +117,6 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { } function save_user_handler( $user_id, $old_user_data = null ) { - // ensure we only sync users who are members of the current blog if ( ! is_user_member_of_blog( $user_id, get_current_blog_id() ) ) { return; @@ -151,8 +160,33 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { do_action( 'jetpack_sync_save_user', $user ); } - function save_user_cap_handler( $meta_id, $user_id, $meta_key, $capabilities ) { + function maybe_save_user_meta( $meta_id, $user_id, $meta_key, $value ) { + if ( $meta_key === 'locale' ) { + if ( current_filter() === 'deleted_user_meta' ) { + /** + * Allow listeners to listen for user local delete changes + * + * @since 4.8.0 + * + * @param int $user_id - The ID of the user whos locale is being deleted + */ + do_action( 'jetpack_sync_user_locale_delete', $user_id ); + } else { + /** + * Allow listeners to listen for user local changes + * + * @since 4.8.0 + * + * @param int $user_id - The ID of the user whos locale is being changed + * @param int $value - The value of the new locale + */ + do_action( 'jetpack_sync_user_locale', $user_id, $value ); + } + } + $this->save_user_cap_handler( $meta_id, $user_id, $meta_key, $value ); + } + function save_user_cap_handler( $meta_id, $user_id, $meta_key, $capabilities ) { // if a user is currently being removed as a member of this blog, we don't fire the event if ( current_filter() === 'deleted_user_meta' && @@ -185,7 +219,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { global $wpdb; $query = "SELECT count(*) FROM $wpdb->usermeta"; - + if ( $where_sql = $this->get_where_sql( $config ) ) { $query .= ' WHERE ' . $where_sql; } @@ -199,7 +233,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { global $wpdb; $query = "meta_key = '{$wpdb->prefix}capabilities'"; - + // config is a list of user IDs to sync if ( is_array( $config ) ) { $query .= ' AND user_id IN (' . implode( ',', array_map( 'intval', $config ) ) . ')'; diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php b/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php index 228ee4ea..263d55a9 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php @@ -42,6 +42,11 @@ class Jetpack_Sync_Module_WooCommerce extends Jetpack_Sync_Module { // order item meta $this->init_listeners_for_meta_type( 'order_item', $callable ); + + // options, constants and post meta whitelists + add_filter( 'jetpack_sync_options_whitelist', array( $this, 'add_woocommerce_options_whitelist' ), 10 ); + add_filter( 'jetpack_sync_constants_whitelist', array( $this, 'add_woocommerce_constants_whitelist' ), 10 ); + add_filter( 'jetpack_sync_post_meta_whitelist', array( $this, 'add_woocommerce_post_meta_whitelist' ), 10 ); } public function init_full_sync_listeners( $callable ) { @@ -113,4 +118,111 @@ class Jetpack_Sync_Module_WooCommerce extends Jetpack_Sync_Module { private function get_where_sql( $config ) { return '1=1'; } + + public function add_woocommerce_options_whitelist( $list ) { + return array_merge( $list, self::$wc_options_whitelist ); + } + + public function add_woocommerce_constants_whitelist( $list ) { + return array_merge( $list, self::$wc_constants_whitelist ); + } + + public function add_woocommerce_post_meta_whitelist( $list ) { + return array_merge( $list, self::$wc_post_meta_whitelist ); + } + + private static $wc_options_whitelist = array( + 'woocommerce_currency', + 'woocommerce_db_version', + 'woocommerce_weight_unit', + 'woocommerce_version', + 'woocommerce_unforce_ssl_checkout', + 'woocommerce_tax_total_display', + 'woocommerce_tax_round_at_subtotal', + 'woocommerce_tax_display_shop', + 'woocommerce_tax_display_cart', + 'woocommerce_prices_include_tax', + 'woocommerce_price_thousand_sep', + 'woocommerce_price_num_decimals', + 'woocommerce_price_decimal_sep', + 'woocommerce_notify_low_stock', + 'woocommerce_notify_low_stock_amount', + 'woocommerce_notify_no_stock', + 'woocommerce_notify_no_stock_amount', + 'woocommerce_manage_stock', + 'woocommerce_force_ssl_checkout', + 'woocommerce_hide_out_of_stock_items', + 'woocommerce_file_download_method', + 'woocommerce_enable_signup_and_login_from_checkout', + 'woocommerce_enable_shipping_calc', + 'woocommerce_enable_review_rating', + 'woocommerce_enable_guest_checkout', + 'woocommerce_enable_coupons', + 'woocommerce_enable_checkout_login_reminder', + 'woocommerce_enable_ajax_add_to_cart', + 'woocommerce_dimension_unit', + 'woocommerce_default_country', + 'woocommerce_default_customer_address', + 'woocommerce_currency_pos', + 'woocommerce_api_enabled', + 'woocommerce_allow_tracking', + ); + + private static $wc_constants_whitelist = array( + //woocommerce options + 'WC_PLUGIN_FILE', + 'WC_ABSPATH', + 'WC_PLUGIN_BASENAME', + 'WC_VERSION', + 'WOOCOMMERCE_VERSION', + 'WC_ROUNDING_PRECISION', + 'WC_DISCOUNT_ROUNDING_MODE', + 'WC_TAX_ROUNDING_MODE', + 'WC_DELIMITER', + 'WC_LOG_DIR', + 'WC_SESSION_CACHE_GROUP', + 'WC_TEMPLATE_DEBUG_MODE', + ); + + private static $wc_post_meta_whitelist = array( + //woocommerce products + '_stock_status', + '_visibility', + 'total_sales', + '_downloadable', + '_virtual', + '_regular_price', + '_sale_price', + '_tax_status', + '_tax_class', + '_featured', + '_price', + '_stock', + '_backorders', + '_manage_stock', + + //woocommerce orders + '_order_currency', + '_prices_include_tax', + '_created_via', + '_billing_country', + '_billing_city', + '_billing_state', + '_billing_postcode', + '_shipping_country', + '_shipping_city', + '_shipping_state', + '_shipping_postcode', + '_payment_method', + '_payment_method_title', + '_order_shipping', + '_cart_discount', + '_cart_discount_tax', + '_order_tax', + '_order_shipping_tax', + '_order_total', + '_download_permissions_granted', + '_recorded_sales', + '_order_stock_reduced', + ); } diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-wp-super-cache.php b/plugins/jetpack/sync/class.jetpack-sync-module-wp-super-cache.php new file mode 100644 index 00000000..f1c9fc80 --- /dev/null +++ b/plugins/jetpack/sync/class.jetpack-sync-module-wp-super-cache.php @@ -0,0 +1,79 @@ + array( 'Jetpack_Sync_Module_WP_Super_Cache', 'get_wp_super_cache_globals' ), + ); + + public function name() { + return 'wp-super-cache'; + } + + public static function get_wp_super_cache_globals() { + global $wp_cache_mod_rewrite; + global $cache_enabled; + global $super_cache_enabled; + global $ossdlcdn; + global $cache_rebuild_files; + global $wp_cache_mobile; + global $wp_super_cache_late_init; + global $wp_cache_anon_only; + global $wp_cache_not_logged_in; + global $wp_cache_clear_on_post_edit; + global $wp_cache_mobile_enabled; + global $wp_super_cache_debug; + global $cache_max_time; + global $wp_cache_refresh_single_only; + global $wp_cache_mfunc_enabled; + global $wp_supercache_304; + global $wp_cache_no_cache_for_get; + global $wp_cache_mutex_disabled; + global $cache_jetpack; + global $cache_domain_mapping; + + return array( + 'wp_cache_mod_rewrite' => $wp_cache_mod_rewrite, + 'cache_enabled' => $cache_enabled, + 'super_cache_enabled' => $super_cache_enabled, + 'ossdlcdn' => $ossdlcdn, + 'cache_rebuild_files' => $cache_rebuild_files, + 'wp_cache_mobile' => $wp_cache_mobile, + 'wp_super_cache_late_init' => $wp_super_cache_late_init, + 'wp_cache_anon_only' => $wp_cache_anon_only, + 'wp_cache_not_logged_in' => $wp_cache_not_logged_in, + 'wp_cache_clear_on_post_edit' => $wp_cache_clear_on_post_edit, + 'wp_cache_mobile_enabled' => $wp_cache_mobile_enabled, + 'wp_super_cache_debug' => $wp_super_cache_debug, + 'cache_max_time' => $cache_max_time, + 'wp_cache_refresh_single_only' => $wp_cache_refresh_single_only, + 'wp_cache_mfunc_enabled' => $wp_cache_mfunc_enabled, + 'wp_supercache_304' => $wp_supercache_304, + 'wp_cache_no_cache_for_get' => $wp_cache_no_cache_for_get, + 'wp_cache_mutex_disabled' => $wp_cache_mutex_disabled, + 'cache_jetpack' => $cache_jetpack, + 'cache_domain_mapping' => $cache_domain_mapping, + ); + } + + public function add_wp_super_cache_constants_whitelist( $list ) { + return array_merge( $list, self::$wp_super_cache_constants ); + } + + public function add_wp_super_cache_callable_whitelist( $list ) { + return array_merge( $list, self::$wp_super_cache_callables ); + } +} \ No newline at end of file diff --git a/plugins/jetpack/sync/class.jetpack-sync-modules.php b/plugins/jetpack/sync/class.jetpack-sync-modules.php index c269319e..7c5fff4e 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-modules.php +++ b/plugins/jetpack/sync/class.jetpack-sync-modules.php @@ -80,16 +80,20 @@ class Jetpack_Sync_Modules { */ $modules = apply_filters( 'jetpack_sync_modules', self::$default_sync_modules ); - return array_map( array( 'Jetpack_Sync_Modules', 'initialize_module' ), $modules ); + $modules = array_map( array( 'Jetpack_Sync_Modules', 'load_module' ), $modules ); + + return array_map( array( 'Jetpack_Sync_Modules', 'set_module_defaults' ), $modules ); + } + + static function load_module( $module_name ) { + return new $module_name; } - static function initialize_module( $module_name ) { - $module = new $module_name; + static function set_module_defaults( $module ) { $module->set_defaults(); if ( method_exists( $module, 'set_late_default' ) ) { add_action( 'init', array( $module, 'set_late_default' ), 90 ); } - return $module; } diff --git a/plugins/jetpack/sync/class.jetpack-sync-settings.php b/plugins/jetpack/sync/class.jetpack-sync-settings.php index 6713cc9d..4b69fb5c 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-settings.php +++ b/plugins/jetpack/sync/class.jetpack-sync-settings.php @@ -70,7 +70,7 @@ class Jetpack_Sync_Settings { $default_array_value = Jetpack_Sync_Defaults::$blacklisted_post_types; break; case 'post_meta_whitelist': - $default_array_value = Jetpack_Sync_Defaults::$post_meta_whitelist; + $default_array_value = Jetpack_Sync_Defaults::get_post_meta_whitelist(); break; case 'comment_meta_whitelist': $default_array_value = Jetpack_Sync_Defaults::$comment_meta_whitelist; diff --git a/plugins/jetpack/sync/class.jetpack-sync-wp-replicastore.php b/plugins/jetpack/sync/class.jetpack-sync-wp-replicastore.php index fbd39e87..dc91be55 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-wp-replicastore.php +++ b/plugins/jetpack/sync/class.jetpack-sync-wp-replicastore.php @@ -584,6 +584,18 @@ class Jetpack_Sync_WP_Replicastore implements iJetpack_Sync_Replicastore { $this->invalid_call(); } + public function upsert_user_locale( $user_id, $local ) { + $this->invalid_call(); + } + + public function delete_user_locale( $user_id ) { + $this->invalid_call(); + } + + public function get_user_locale( $user_id ) { + return jetpack_get_user_locale( $user_id ); + } + public function get_allowed_mime_types( $user_id ) { } diff --git a/plugins/jetpack/sync/interface.jetpack-sync-replicastore.php b/plugins/jetpack/sync/interface.jetpack-sync-replicastore.php index 636abc4f..4aeda78c 100644 --- a/plugins/jetpack/sync/interface.jetpack-sync-replicastore.php +++ b/plugins/jetpack/sync/interface.jetpack-sync-replicastore.php @@ -120,6 +120,12 @@ interface iJetpack_Sync_Replicastore { public function delete_user( $user_id ); + public function upsert_user_locale( $user_id, $locale ); + + public function delete_user_locale( $user_id ); + + public function get_user_locale( $user_id ); + public function get_allowed_mime_types( $user_id ); -- cgit v1.2.3-18-g5258