diff options
Diffstat (limited to 'plugins/jetpack/sync')
12 files changed, 703 insertions, 226 deletions
diff --git a/plugins/jetpack/sync/class.jetpack-sync-defaults.php b/plugins/jetpack/sync/class.jetpack-sync-defaults.php index 2f267ec9..8e24178a 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-defaults.php +++ b/plugins/jetpack/sync/class.jetpack-sync-defaults.php @@ -195,6 +195,39 @@ class Jetpack_Sync_Defaults { 'roles' => array( 'Jetpack_Sync_Functions', 'roles' ), ); + + static $default_post_type_attributes = array( + 'name' => '', + 'label' => '', + 'labels' => array(), + 'description' => '', + 'public' => false, + 'hierarchical' => false, + 'exclude_from_search' => true, + 'publicly_queryable' => null, + 'show_ui' => false, + 'show_in_menu' => null, + 'show_in_nav_menus' => null, + 'show_in_admin_bar' => false, + 'menu_position' => null, + 'menu_icon' => null, + 'supports' => array(), + 'capability_type' => 'post', + 'capabilities' => array(), + 'cap' => array(), + 'map_meta_cap' => true, + 'taxonomies' => array(), + 'has_archive' => false, + 'rewrite' => true, + 'query_var' => true, + 'can_export' => true, + 'delete_with_user' => null, + 'show_in_rest' => false, + 'rest_base' => false, + '_builtin' => false, + '_edit_link' => 'post.php?post=%d', + ); + public static function get_callable_whitelist() { /** * Filter the list of callables that are manageable via the JSON API. @@ -226,6 +259,13 @@ class Jetpack_Sync_Defaults { 'wpephpcompat_jobs', 'wprss_feed_item', 'wp_automatic', + 'jp_sitemap_master', + 'jp_sitemap', + 'jp_sitemap_index', + 'jp_img_sitemap', + 'jp_img_sitemap_index', + 'jp_vid_sitemap', + 'jp_vid_sitemap_index', ); static $default_post_checksum_columns = array( @@ -335,6 +375,19 @@ class Jetpack_Sync_Defaults { 'hc_foreign_user_id' ); + public static function get_comment_meta_whitelist() { + /** + * Filter the list of comment meta data that are manageable via the JSON API. + * + * @module sync + * + * @since 5.7.0 + * + * @param array The default list of comment meta data keys. + */ + return apply_filters( 'jetpack_sync_comment_meta_whitelist', self::$comment_meta_whitelist ); + } + // TODO: move this to server? - these are theme support values // that should be synced as jetpack_current_theme_supports_foo option values static $default_theme_support_whitelist = array( diff --git a/plugins/jetpack/sync/class.jetpack-sync-functions.php b/plugins/jetpack/sync/class.jetpack-sync-functions.php index 89a70642..8fbe3dc9 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-functions.php +++ b/plugins/jetpack/sync/class.jetpack-sync-functions.php @@ -66,7 +66,37 @@ class Jetpack_Sync_Functions { public static function get_post_types() { global $wp_post_types; - return $wp_post_types; + $post_types_without_callbacks = array(); + foreach ( $wp_post_types as $post_type_name => $post_type ) { + $sanitized_post_type = self::sanitize_post_type( $post_type ); + if ( ! empty( $sanitized_post_type ) ) { + $post_types_without_callbacks[ $post_type_name ] = $sanitized_post_type; + } else { + error_log( 'Jetpack: Encountered a recusive post_type:' . $post_type_name ); + } + } + return $post_types_without_callbacks; + } + + public static function sanitize_post_type( $post_type ) { + // Lets clone the post type object instead of modifing the global one. + $sanitized_post_type = array(); + foreach ( Jetpack_Sync_Defaults::$default_post_type_attributes as $attribute_key => $default_value ) { + if ( isset( $post_type->{ $attribute_key } ) ) { + $sanitized_post_type[ $attribute_key ] = $post_type->{ $attribute_key }; + } + } + return (object) $sanitized_post_type; + } + + public static function expand_synced_post_type( $sanitized_post_type, $post_type ) { + $post_type = sanitize_key( $post_type ); + $post_type_object = new WP_Post_Type( $post_type, $sanitized_post_type ); + $post_type_object->add_supports(); + $post_type_object->add_rewrite_rules(); + $post_type_object->add_hooks(); + $post_type_object->register_taxonomies(); + return (object) $post_type_object; } public static function get_post_type_features() { diff --git a/plugins/jetpack/sync/class.jetpack-sync-listener.php b/plugins/jetpack/sync/class.jetpack-sync-listener.php index dedad442..832340a4 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-listener.php +++ b/plugins/jetpack/sync/class.jetpack-sync-listener.php @@ -144,6 +144,8 @@ class Jetpack_Sync_Listener { * * @since 4.2.0 * + * @module sync + * * @param array The action parameters */ $args = apply_filters( "jetpack_sync_before_enqueue_$action_name", $args ); @@ -172,6 +174,15 @@ class Jetpack_Sync_Listener { } /** + * Add an action hook to execute when anything on the whitelist gets sent to the queue to sync. + * + * @module sync + * + * @since 5.9.0 + */ + do_action( 'jetpack_sync_action_before_enqueue' ); + + /** * Modify or reject the data within an action before it is enqueued locally. * * @since 4.2.0 @@ -256,13 +267,33 @@ class Jetpack_Sync_Listener { 'is_xmlrpc' => defined( 'XMLRPC_REQUEST' ) ? XMLRPC_REQUEST : false, 'is_wp_rest' => defined( 'REST_REQUEST' ) ? REST_REQUEST : false, 'is_ajax' => defined( 'DOING_AJAX' ) ? DOING_AJAX : false, - 'ip' => isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null, 'is_wp_admin' => is_admin(), ); + if ( $this->should_send_user_data_with_actor( $current_filter ) ) { + require_once( JETPACK__PLUGIN_DIR . 'modules/protect/shared-functions.php' ); + $actor['ip'] = jetpack_protect_get_ip(); + $actor['user_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'unknown'; + } + return $actor; } + function should_send_user_data_with_actor( $current_filter ) { + $should_send = in_array( $current_filter, array( 'wp_login', 'wp_logout', 'jetpack_valid_failed_login_attempt' ) ); + /** + * Allow or deny sending actor's user data ( IP and UA ) during a sync event + * + * @since 5.8.0 + * + * @module sync + * + * @param bool True if we should send user data + * @param string The current filter that is performing the sync action + */ + return apply_filters( 'jetpack_sync_actor_user_data', $should_send, $current_filter ); + } + function set_defaults() { $this->sync_queue = new Jetpack_Sync_Queue( 'sync' ); $this->full_sync_queue = new Jetpack_Sync_Queue( 'full_sync' ); diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-plugins.php b/plugins/jetpack/sync/class.jetpack-sync-module-plugins.php index e72425d6..a7b75209 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-plugins.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-plugins.php @@ -16,10 +16,13 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module { add_action( 'activated_plugin', $callable, 10, 2 ); add_action( 'deactivated_plugin', $callable, 10, 2 ); add_action( 'delete_plugin', array( $this, 'delete_plugin') ); - add_action( 'upgrader_process_complete', array( $this, 'check_upgrader' ), 10, 2 ); - add_action( 'jetpack_installed_plugin', $callable, 10, 2 ); + add_action( 'upgrader_process_complete', array( $this, 'on_upgrader_completion' ), 10, 2 ); + add_action( 'jetpack_plugin_installed', $callable, 10, 1 ); + add_action( 'jetpack_plugin_update_failed', $callable, 10, 4 ); + add_action( 'jetpack_plugins_updated', $callable, 10, 2 ); add_action( 'admin_action_update', array( $this, 'check_plugin_edit') ); add_action( 'jetpack_edited_plugin', $callable, 10, 2 ); + add_action( 'wp_ajax_edit-theme-plugin-file', array( $this, 'plugin_edit_ajax' ), 0 ); } public function init_before_send() { @@ -28,34 +31,115 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module { //Note that we don't simply 'expand_plugin_data' on the 'delete_plugin' action here because the plugin file is deleted when that action finishes } - public function check_upgrader( $upgrader, $details) { + public function on_upgrader_completion( $upgrader, $details ) { + if ( ! isset( $details['type'] ) ) { + return; + } + if ( 'plugin' != $details['type'] ) { + return; + } - if ( ! isset( $details['type'] ) || - 'plugin' !== $details['type'] || - is_wp_error( $upgrader->skin->result ) || - ! method_exists( $upgrader, 'plugin_info' ) - ) { + if ( ! isset( $details['action'] ) ) { return; } - if ( 'install' === $details['action'] ) { - $plugin_path = $upgrader->plugin_info(); - $plugins = get_plugins(); - $plugin_info = $plugins[ $plugin_path ]; + $plugins = ( isset( $details['plugins'] ) ? $details['plugins'] : null ); + if ( empty( $plugins ) ) { + $plugins = ( isset( $details['plugin'] ) ? array( $details['plugin'] ) : null ); + } + + // for plugin installer + if ( empty( $plugins ) && method_exists( $upgrader, 'plugin_info' ) ) { + $plugins = array( $upgrader->plugin_info() ); + } + if ( empty( $plugins ) ) { + return; // We shouldn't be here + } + + switch ( $details['action'] ) { + case 'update': + $state = array( + 'is_autoupdate' => Jetpack_Constants::is_true( 'JETPACK_PLUGIN_AUTOUPDATE' ), + ); + $errors = $this->get_errors( $upgrader->skin ); + if ( $errors ) { + foreach ( $plugins as $slug ) { + /** + * Sync that a plugin update failed + * + * @since 5.8.0 + * + * @module sync + * + * @param string $plugin , Plugin slug + * @param string Error code + * @param string Error message + */ + do_action( 'jetpack_plugin_update_failed', $this->get_plugin_info( $slug ), $errors['code'], $errors['message'], $state ); + } + + return; + } + /** + * Sync that a plugin update + * + * @since 5.8.0 + * + * @module sync + * + * @param array () $plugin, Plugin Data + */ + do_action( 'jetpack_plugins_updated', array_map( array( $this, 'get_plugin_info' ), $plugins ), $state ); + break; + case 'install': + + } + + if ( 'install' === $details['action'] ) { /** * Signals to the sync listener that a plugin was installed and a sync action * reflecting the installation and the plugin info should be sent * - * @since 4.9.0 + * @since 5.8.0 + * + * @module sync * - * @param string $plugin_path Path of plugin installed - * @param mixed $plugin_info Array of info describing plugin installed + * @param array () $plugin, Plugin Data */ - do_action( 'jetpack_installed_plugin', $plugin_path, $plugin_info ); + do_action( 'jetpack_plugin_installed', array_map( array( $this, 'get_plugin_info' ), $plugins ) ); + + return; } } + private function get_plugin_info( $slug ) { + $plugins = get_plugins(); + return isset( $plugins[ $slug ] ) ? array_merge( array( 'slug' => $slug), $plugins[ $slug ] ): array( 'slug' => $slug ); + } + + private function get_errors( $skin ) { + $errors = method_exists( $skin, 'get_errors' ) ? $skin->get_errors() : null; + if ( is_wp_error( $errors ) ) { + $error_code = $errors->get_error_code(); + if ( ! empty( $error_code ) ) { + return array( 'code' => $error_code, 'message' => $errors->get_error_message() ); + } + } + + if ( isset( $skin->result ) ) { + $errors = $skin->result; + if ( is_wp_error( $errors ) ) { + return array( 'code' => $errors->get_error_code(), 'message' => $errors->get_error_message() ); + } + + if ( false == $skin->result ) { + return array( 'code' => 'unknown', 'message' => __( 'Unknown Plugin Update Failure', 'jetpack' ) ); + } + } + return false; + } + public function check_plugin_edit() { $screen = get_current_screen(); if ( 'plugin-editor' !== $screen->base || @@ -82,6 +166,64 @@ class Jetpack_Sync_Module_Plugins extends Jetpack_Sync_Module { do_action( 'jetpack_edited_plugin', $plugin, $plugins[ $plugin ] ); } + public function plugin_edit_ajax() { + // this validation is based on wp_edit_theme_plugin_file() + $args = wp_unslash( $_POST ); + if ( empty( $args['file'] ) ) { + return; + } + + $file = $args['file']; + if ( 0 !== validate_file( $file ) ) { + return; + } + + if ( ! isset( $args['newcontent'] ) ) { + return; + } + + if ( ! isset( $args['nonce'] ) ) { + return; + } + + if ( empty( $args['plugin'] ) ) { + return; + } + + $plugin = $args['plugin']; + if ( ! current_user_can( 'edit_plugins' ) ) { + return; + } + + if ( ! wp_verify_nonce( $args['nonce'], 'edit-plugin_' . $file ) ) { + return; + } + $plugins = get_plugins(); + if ( ! array_key_exists( $plugin, $plugins ) ) { + return; + } + + if ( 0 !== validate_file( $file, get_plugin_files( $plugin ) ) ) { + return; + } + + $real_file = WP_PLUGIN_DIR . '/' . $file; + + if ( ! is_writeable( $real_file ) ) { + return; + } + + $file_pointer = fopen( $real_file, 'w+' ); + if ( false === $file_pointer ) { + return; + } + + /** + * This action is documented already in this file + */ + do_action( 'jetpack_edited_plugin', $plugin, $plugins[ $plugin ] ); + } + public function delete_plugin( $plugin_path ) { $full_plugin_path = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $plugin_path; diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-posts.php b/plugins/jetpack/sync/class.jetpack-sync-module-posts.php index f7cc2bff..7effbdc7 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-posts.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-posts.php @@ -5,10 +5,12 @@ require_once dirname( __FILE__ ) . '/class.jetpack-sync-settings.php'; class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { private $just_published = array(); - private $just_trashed = array(); + private $previous_status = array(); private $action_handler; private $import_end = false; + const DEFAULT_PREVIOUS_STATE = 'new'; + public function name() { return 'posts'; } @@ -33,13 +35,13 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { $priority = version_compare( $wp_version, '4.7-alpha', '<' ) ? 0 : 11; add_action( 'wp_insert_post', array( $this, 'wp_insert_post' ), $priority, 3 ); + add_action( 'jetpack_sync_save_post', $callable, 10, 4 ); add_action( 'deleted_post', $callable, 10 ); add_action( 'jetpack_published_post', $callable, 10, 2 ); - add_action( 'jetpack_trashed_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' ) ); + add_filter( 'jetpack_sync_before_enqueue_jetpack_sync_save_post', array( $this, 'filter_blacklisted_post_types' ) ); // listen for meta changes $this->init_listeners_for_meta_type( 'post', $callable ); @@ -121,7 +123,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { } public function init_before_send() { - add_filter( 'jetpack_sync_before_send_wp_insert_post', array( $this, 'expand_wp_insert_post' ) ); + add_filter( 'jetpack_sync_before_send_jetpack_sync_save_post', array( $this, 'expand_jetpack_sync_save_post' ) ); // full sync add_filter( 'jetpack_sync_before_send_jetpack_full_sync_posts', array( $this, 'expand_post_ids' ) ); @@ -164,14 +166,9 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { * * @return array */ - function expand_wp_insert_post( $args ) { - $post_id = $args[0]; - $post = $args[1]; - $update = $args[2]; - $is_auto_save = isset( $args[3] ) ? $args[3] : false; //See https://github.com/Automattic/jetpack/issues/7372 - $just_published = isset( $args[4] ) ? $args[4] : false; //Preventative in light of above issue - - return array( $post_id, $this->filter_post_content_and_add_links( $post ), $update, $is_auto_save, $just_published ); + function expand_jetpack_sync_save_post( $args ) { + list( $post_id, $post, $update, $previous_state ) = $args; + return array( $post_id, $this->filter_post_content_and_add_links( $post ), $update, $previous_state ); } function filter_blacklisted_post_types( $args ) { @@ -199,9 +196,11 @@ 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' ) ); + $post = get_post( intval( $post_id ) ); + if( $post->post_type ) { + return ! in_array( $post->post_type, Jetpack_Sync_Settings::get_setting( 'post_types_blacklist' ) ); + } + return false; } function remove_embed() { @@ -320,12 +319,10 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { public function save_published( $new_status, $old_status, $post ) { if ( 'publish' === $new_status && 'publish' !== $old_status ) { - $this->just_published[] = $post->ID; + $this->just_published[ $post->ID ] = true; } - if ( 'trash' === $new_status && 'trash' !== $old_status ) { - $this->just_trashed[] = $post->ID; - } + $this->previous_status[ $post->ID ] = $old_status; } public function wp_insert_post( $post_ID, $post = null, $update = null ) { @@ -333,30 +330,43 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { return; } - if ( Jetpack_Constants::get_constant( 'DOING_AUTOSAVE' ) ) { - $is_auto_save = true; - } else { - $is_auto_save = false; - } - - if ( ! in_array( $post_ID, $this->just_published ) ) { - $just_published = false; - } else { - $just_published = true; - } - // workaround for https://github.com/woocommerce/woocommerce/issues/18007 if ( $post && 'shop_order' === $post->post_type ) { $post = get_post( $post_ID ); } - call_user_func( $this->action_handler, $post_ID, $post, $update, $is_auto_save, $just_published ); + $previous_status = isset( $this->previous_status[ $post_ID ] ) ? + $this->previous_status[ $post_ID ] : + self::DEFAULT_PREVIOUS_STATE; + + $just_published = isset( $this->just_published[ $post_ID ] ) ? + $this->just_published[ $post_ID ] : + false; + + $state = array( + 'is_auto_save' => (bool) Jetpack_Constants::get_constant( 'DOING_AUTOSAVE' ), + 'previous_status' => $previous_status, + 'just_published' => $just_published + ); + /** + * Filter that is used to add to the post flags ( meta data ) when a post gets published + * + * @since 5.8.0 + * + * @param int $post_ID the post ID + * @param mixed $post WP_POST object + * @param bool $update Whether this is an existing post being updated or not. + * @param mixed $state state + * + * @module sync + */ + do_action( 'jetpack_sync_save_post', $post_ID, $post, $update, $state ); + unset( $this->previous_status[ $post_ID ] ); $this->send_published( $post_ID, $post ); - $this->send_trashed( $post_ID, $post ); } public function send_published( $post_ID, $post ) { - if ( ! in_array( $post_ID, $this->just_published ) ) { + if ( ! isset( $this->just_published[ $post_ID ] ) ) { return; } @@ -399,29 +409,7 @@ class Jetpack_Sync_Module_Posts extends Jetpack_Sync_Module { * @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 send_trashed( $post_ID, $post ) { - if ( ! in_array( $post_ID, $this->just_trashed ) ) { - 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; - } - - /** - * Action that gets synced when a post type gets trashed. - * - * @since 4.9.0 - * - * @param int $post_ID - */ - do_action( 'jetpack_trashed_post', $post_ID, $post->post_type ); - - $this->just_trashed = array_diff( $this->just_trashed, array( $post_ID ) ); + unset( $this->just_published[ $post_ID ] ); } public function expand_post_ids( $args ) { diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-protect.php b/plugins/jetpack/sync/class.jetpack-sync-module-protect.php index d81d3591..1385dd00 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-protect.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-protect.php @@ -14,10 +14,10 @@ class Jetpack_Sync_Module_Protect extends Jetpack_Sync_Module { add_action( 'jetpack_valid_failed_login_attempt', $callback ); } - function maybe_log_failed_login_attempt( $ip ) { + function maybe_log_failed_login_attempt( $failed_attempt ) { $protect = Jetpack_Protect_Module::instance(); if ( $protect->has_login_ability() ) { - do_action( 'jetpack_valid_failed_login_attempt', $ip ); + do_action( 'jetpack_valid_failed_login_attempt', $failed_attempt ); } } } diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-themes.php b/plugins/jetpack/sync/class.jetpack-sync-module-themes.php index f4e4d6e1..50ece939 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-themes.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-themes.php @@ -15,6 +15,7 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module { add_action( 'jetpack_deleted_theme', $callable, 10, 2 ); add_filter( 'wp_redirect', array( $this, 'detect_theme_edit' ) ); add_action( 'jetpack_edited_theme', $callable, 10, 2 ); + add_action( 'wp_ajax_edit-theme-plugin-file', array( $this, 'theme_edit_ajax' ), 0 ); add_action( 'update_site_option_allowedthemes', array( $this, 'sync_network_allowed_themes_change' ), 10, 4 ); add_action( 'jetpack_network_disabled_themes', $callable, 10, 2 ); add_action( 'jetpack_network_enabled_themes', $callable, 10, 2 ); @@ -39,6 +40,7 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module { $widget = array( 'name' => $widget_object->name, 'id' => $widget_object->id, + 'title' => isset( $new_instance['title'] ) ? $new_instance['title'] : '', ); /** * Trigger action to alert $callable sync listener that a widget was edited @@ -142,6 +144,111 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module { return $redirect_url; } + public function theme_edit_ajax() { + $args = wp_unslash( $_POST ); + + if ( empty( $args['theme'] ) ) { + return; + } + + if ( empty( $args['file'] ) ) { + return; + } + $file = $args['file']; + if ( 0 !== validate_file( $file ) ) { + return; + } + + if ( ! isset( $args['newcontent'] ) ) { + return; + } + + if ( ! isset( $args['nonce'] ) ) { + return; + } + + $stylesheet = $args['theme']; + if ( 0 !== validate_file( $stylesheet ) ) { + return; + } + + if ( ! current_user_can( 'edit_themes' ) ) { + return; + } + + $theme = wp_get_theme( $stylesheet ); + if ( ! $theme->exists() ) { + return; + } + + $real_file = $theme->get_stylesheet_directory() . '/' . $file; + if ( ! wp_verify_nonce( $args['nonce'], 'edit-theme_' . $real_file . $stylesheet ) ) { + return; + } + + if ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) { + return; + } + + $editable_extensions = wp_get_theme_file_editable_extensions( $theme ); + + $allowed_files = array(); + foreach ( $editable_extensions as $type ) { + switch ( $type ) { + case 'php': + $allowed_files = array_merge( $allowed_files, $theme->get_files( 'php', -1 ) ); + break; + case 'css': + $style_files = $theme->get_files( 'css', -1 ); + $allowed_files['style.css'] = $style_files['style.css']; + $allowed_files = array_merge( $allowed_files, $style_files ); + break; + default: + $allowed_files = array_merge( $allowed_files, $theme->get_files( $type, -1 ) ); + break; + } + } + + if ( 0 !== validate_file( $real_file, $allowed_files ) ) { + return; + } + + // Ensure file is real. + if ( ! is_file( $real_file ) ) { + return; + } + + // Ensure file extension is allowed. + $extension = null; + if ( preg_match( '/\.([^.]+)$/', $real_file, $matches ) ) { + $extension = strtolower( $matches[1] ); + if ( ! in_array( $extension, $editable_extensions, true ) ) { + return; + } + } + + if ( ! is_writeable( $real_file ) ) { + return; + } + + $file_pointer = fopen( $real_file, 'w+' ); + if ( false === $file_pointer ) { + return; + } + + $theme_data = array( + 'name' => $theme->get('Name'), + 'version' => $theme->get('Version'), + 'uri' => $theme->get( 'ThemeURI' ), + ); + + /** + * This action is documented already in this file + */ + do_action( 'jetpack_edited_theme', $stylesheet, $theme_data ); + + } + public function detect_theme_deletion() { $delete_theme_call = $this->get_delete_theme_call(); if ( empty( $delete_theme_call ) ) { @@ -461,4 +568,4 @@ class Jetpack_Sync_Module_Themes extends Jetpack_Sync_Module { private function is_theme_switch() { return did_action( 'after_switch_theme' ); } -}
\ No newline at end of file +} diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-updates.php b/plugins/jetpack/sync/class.jetpack-sync-module-updates.php index 73e49907..2db14ee5 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-updates.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-updates.php @@ -34,7 +34,7 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module { if ( is_multisite() ) { - add_action( 'update_site_option_wpmu_upgrade_site', array ( $this, 'update_core_network_event' ), 10, 3 ); + add_filter( 'pre_update_site_option_wpmu_upgrade_site', array ( $this, 'update_core_network_event' ), 10, 2 ); add_action( 'jetpack_sync_core_update_network', $callable, 10, 3 ); } @@ -55,7 +55,7 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module { add_filter( 'jetpack_sync_before_send_jetpack_update_themes_change', array( $this, 'expand_themes' ) ); } - public function update_core_network_event( $option, $wp_db_version, $old_wp_db_version ) { + public function update_core_network_event( $wp_db_version, $old_wp_db_version ) { global $wp_version; /** * Sync event for when core wp network updates to a new db version @@ -68,6 +68,7 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module { * */ do_action( 'jetpack_sync_core_update_network', $wp_db_version, $old_wp_db_version, $wp_version ); + return $wp_db_version; } public function update_core( $new_wp_version ) { @@ -111,26 +112,73 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module { } - public function get_update_checksum( $value ) { - // Create an new array so we don't modify the object passed in. - $a_value = (array) $value; - // ignore `last_checked` - unset( $a_value['last_checked'] ); - unset( $a_value['checked'] ); - unset( $a_value['version_checked'] ); - if ( empty( $a_value['updates'] ) ) { - unset( $a_value['updates'] ); - } - if ( empty( $a_value ) ) { + public function get_update_checksum( $update, $transient ) { + $updates = array(); + $no_updated = array(); + switch ( $transient ) { + case 'update_plugins': + if ( ! empty( $update->response ) ) { + foreach ( $update->response as $plugin_slug => $response ) { + if ( ! empty( $plugin_slug ) && isset( $response->new_version ) ) { + $updates[] = array( $plugin_slug => $response->new_version ); + } + } + } + if ( ! empty( $update->no_update ) ) { + $no_updated = array_keys( $update->no_update ); + } + + if ( ! isset( $no_updated[ 'jetpack/jetpack.php' ] ) && isset( $updates[ 'jetpack/jetpack.php' ] ) ) { + return false; + } + + break; + case 'update_themes': + if ( ! empty( $update->response ) ) { + foreach ( $update->response as $theme_slug => $response ) { + if ( ! empty( $theme_slug ) && isset( $response['new_version'] ) ) { + $updates[] = array( $theme_slug => $response['new_version'] ); + } + } + } + + if ( ! empty( $update->checked ) ) { + $no_updated = $update->checked; + } + + break; + case 'update_core': + if ( ! empty( $update->updates ) ) { + foreach ( $update->updates as $response ) { + if( ! empty( $response->response ) && $response->response === 'latest' ) { + continue; + } + if ( ! empty( $response->response ) && isset( $response->packages->full ) ) { + $updates[] = array( $response->response => $response->packages->full ); + } + } + } + + if ( ! empty( $update->version_checked ) ) { + $no_updated = $update->version_checked; + } + + if ( empty( $updates ) ) { + return false; + } + break; + + } + if ( empty( $updates ) && empty( $no_updated ) ) { return false; } - return $this->get_check_sum( $a_value ); + return $this->get_check_sum( array( $no_updated, $updates ) ); } public function validate_update_change( $value, $expiration, $transient ) { - $new_checksum = $this->get_update_checksum( $value ); + $new_checksum = $this->get_update_checksum( $value, $transient ); if ( false === $new_checksum ) { return; } @@ -144,7 +192,6 @@ class Jetpack_Sync_Module_Updates extends Jetpack_Sync_Module { $checksums[ $transient ] = $new_checksum; update_option( self::UPDATES_CHECKSUM_OPTION_NAME, $checksums ); - // possible $transient value are update_plugins, update_themes, update_core do_action( "jetpack_{$transient}_change", $value ); } diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-users.php b/plugins/jetpack/sync/class.jetpack-sync-module-users.php index a3f000e3..005a9fd4 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-users.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-users.php @@ -3,6 +3,8 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { const MAX_INITIAL_SYNC_USERS = 100; + protected $flags = array(); + function name() { return 'users'; } @@ -17,18 +19,20 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { } public function init_listeners( $callable ) { + // users - add_action( 'user_register', array( $this, 'save_user_handler' ) ); + add_action( 'user_register', array( $this, 'user_register_handler' ) ); add_action( 'profile_update', array( $this, 'save_user_handler' ), 10, 2 ); - add_action( 'add_user_to_blog', array( $this, 'save_user_handler' ) ); + + add_action( 'add_user_to_blog', array( $this, 'add_user_to_blog_handler' ) ); add_action( 'jetpack_sync_add_user', $callable, 10, 2 ); + add_action( 'jetpack_sync_add_user', array( $this, 'clear_flags' ), 11 ); + add_action( 'jetpack_sync_register_user', $callable, 10, 2 ); - add_action( 'jetpack_sync_save_user', $callable ); + add_action( 'jetpack_sync_register_user', array( $this, 'clear_flags' ), 11 ); - //Edit user info, see https://github.com/WordPress/WordPress/blob/c05f1dc805bddcc0e76fd90c4aaf2d9ea76dc0fb/wp-admin/user-edit.php#L126 - add_action( 'personal_options_update', array( $this, 'edited_user_handler' ) ); - add_action( 'edit_user_profile_update', array( $this, 'edited_user_handler' ) ); - add_action( 'jetpack_user_edited', $callable ); + add_action( 'jetpack_sync_save_user', $callable, 10, 2 ); + add_action( 'jetpack_sync_save_user', array( $this, 'clear_flags' ), 11 ); add_action( 'jetpack_sync_user_locale', $callable, 10, 2 ); add_action( 'jetpack_sync_user_locale_delete', $callable, 10, 1 ); @@ -52,6 +56,11 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { add_action( 'wp_login', $callable, 10, 2 ); add_action( 'wp_logout', $callable, 10, 0 ); add_action( 'wp_masterbar_logout', $callable, 10, 0 ); + + // Add on init + add_filter( 'jetpack_sync_before_enqueue_jetpack_sync_add_user', array( $this, 'expand_action' ) ); + add_filter( 'jetpack_sync_before_enqueue_jetpack_sync_register_user', array( $this, 'expand_action' ) ); + add_filter( 'jetpack_sync_before_enqueue_jetpack_sync_save_user', array( $this, 'expand_action' ) ); } public function init_full_sync_listeners( $callable ) { @@ -59,9 +68,8 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { } public function init_before_send() { - add_filter( 'jetpack_sync_before_send_jetpack_sync_add_user', array( $this, 'expand_user' ) ); - add_filter( 'jetpack_sync_before_send_jetpack_sync_register_user', array( $this, 'expand_user' ) ); - add_filter( 'jetpack_sync_before_send_jetpack_sync_save_user', array( $this, 'expand_user' ), 10, 2 ); + + add_filter( 'jetpack_sync_before_send_wp_login', array( $this, 'expand_login_username' ), 10, 1 ); add_filter( 'jetpack_sync_before_send_wp_logout', array( $this, 'expand_logout_username' ), 10, 2 ); @@ -69,14 +77,8 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { add_filter( 'jetpack_sync_before_send_jetpack_full_sync_users', array( $this, 'expand_users' ) ); } - public function sanitize_user_and_expand( $user ) { - $user = $this->get_user( $user ); - $user = $this->add_to_user( $user ); - return $this->sanitize_user( $user ); - } - private function get_user( $user ) { - if ( $user && ! is_object( $user ) && is_numeric( $user ) ) { + if ( is_numeric( $user ) ) { $user = get_user_by( 'id', $user ); } if ( $user instanceof WP_User ) { @@ -93,17 +95,15 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { if ( is_object( $user ) && is_object( $user->data ) ) { unset( $user->data->user_pass ); } - if ( $user ) { - $user->allcaps = $this->get_real_user_capabilities( $user ); - } return $user; } - public function add_to_user( $user ) { + public function expand_user( $user ) { if ( ! is_object( $user ) ) { return null; } $user->allowed_mime_types = get_allowed_mime_types( $user ); + $user->allcaps = $this->get_real_user_capabilities( $user ); if ( function_exists( 'get_user_locale' ) ) { @@ -129,11 +129,18 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { return $user_capabilities; } - public function expand_user( $args ) { - list( $user ) = $args; + public function sanitize_user_and_expand( $user ) { + $user = $this->get_user( $user ); + $user = $this->expand_user( $user ); + return $this->sanitize_user( $user ); + } + public function expand_action( $args ) { + // the first argument is always the user + list( $user ) = $args; if ( $user ) { - return array( $this->add_to_user( $user ) ); + $args[0] = $this->sanitize_user_and_expand( $user ); + return $args; } return false; @@ -149,7 +156,7 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { public function expand_logout_username( $args, $user_id ) { $user = get_userdata( $user_id ); $user = $this->sanitize_user( $user ); - + $login = ''; if ( is_object( $user ) && is_object( $user->data ) ) { $login = $user->data->user_login; @@ -176,24 +183,52 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { do_action( 'jetpack_deleted_user', $deleted_user_id, $reassigned_user_id, $is_multisite ); } - public function edited_user_handler( $user_id ) { + function user_register_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; + } + + if ( Jetpack_Constants::is_true( 'JETPACK_INVITE_ACCEPTED' ) ) { + $this->add_flags( $user_id, array( 'invitation_accepted' => true ) ); + } /** - * Fires when a user is edited on a site + * Fires when a new user is registered on a site * - * @since 5.4.0 + * @since 4.9.0 + * + * @param object The WP_User object + */ + do_action( 'jetpack_sync_register_user', $user_id, $this->get_flags( $user_id ) ); + + } + + function add_user_to_blog_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; + } + + if ( Jetpack_Constants::is_true( 'JETPACK_INVITE_ACCEPTED' ) ) { + $this->add_flags( $user_id, array( 'invitation_accepted' => true ) ); + } + /** + * Fires when a user is added on a site * - * @param int $user_id - ID of the edited user + * @since 4.9.0 + * + * @param object The WP_User object */ - do_action( 'jetpack_user_edited', $user_id ); + do_action( 'jetpack_sync_add_user', $user_id, $this->get_flags( $user_id ) ); } - + 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; } - $user = $this->sanitize_user( get_user_by( 'id', $user_id ) ); + $user = get_user_by( 'id', $user_id ); // Older versions of WP don't pass the old_user_data in ->data if ( isset( $old_user_data->data ) ) { @@ -201,38 +236,8 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { } else { $old_user = $old_user_data; } - - if ( $old_user !== null ) { - unset( $old_user->user_pass ); - if ( serialize( $old_user ) === serialize( $user->data ) ) { - return; - } - } - - if ( 'user_register' === current_filter() ) { - /** - * Fires when a new user is registered on a site - * - * @since 4.9.0 - * - * @param object The WP_User object - */ - do_action( 'jetpack_sync_register_user', $user ); - - return; - } - /* MU Sites add users instead of register them to sites */ - if ( 'add_user_to_blog' === current_filter() ) { - /** - * Fires when a new user is added to a site. (WordPress Multisite) - * - * @since 4.9.0 - * - * @param object The WP_User object - */ - do_action( 'jetpack_sync_add_user', $user ); - - return; + if ( $old_user !== null && $user->user_pass !== $old_user->user_pass ) { + $this->flags[ $user_id ]['password_changed'] = true; } /** @@ -241,79 +246,60 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { * @since 4.2.0 * * @param object The WP_User object + * @param array state - New since 5.8.0 */ - do_action( 'jetpack_sync_save_user', $user ); + do_action( 'jetpack_sync_save_user', $user_id, $this->get_flags( $user_id ) ); } function save_user_role_handler( $user_id, $role, $old_roles = null ) { + $this->add_flags( $user_id, array( 'role_changed' => true, 'previous_role' => $old_roles ) ); + //The jetpack_sync_register_user payload is identical to jetpack_sync_save_user, don't send both if ( $this->is_create_user() || $this->is_add_user_to_blog() ) { return; } - - $user = $this->sanitize_user( get_user_by( 'id', $user_id ) ); /** - * Fires when the client needs to sync an updated user - * - * @since 4.2.0 - * - * @param object The WP_User object + * This action is documented already in this file */ - do_action( 'jetpack_sync_save_user', $user ); + do_action( 'jetpack_sync_save_user', $user_id, $this->get_flags( $user_id ) ); + } + + function get_flags( $user_id ) { + if ( isset( $this->flags[ $user_id ] ) ) { + return $this->flags[ $user_id ]; + } + return array(); + } + + function clear_flags( $user_id ) { + if ( isset( $this->flags[ $user_id ] ) ) { + unset( $this->flags[ $user_id ] ); + } + } + + function add_flags( $user_id, $flags ) { + $this->flags[ $user_id ] = wp_parse_args( $flags, $this->get_flags( $user_id ) ); } 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->add_flags( $user_id, array( 'locale_changed' => true ) ); } - $this->save_user_cap_handler( $meta_id, $user_id, $meta_key, $value ); - } - function save_user_cap_handler( $meta_id, $user_id, $meta_key, $capabilities ) { - //The jetpack_sync_register_user payload is identical to jetpack_sync_save_user, don't send both - if ( $this->is_create_user() || $this->is_add_user_to_blog() ) { - return; + $user = get_user_by( 'id', $user_id ); + if ( $meta_key === $user->cap_key ) { + $this->add_flags( $user_id, array( 'capabilities_changed' => true ) ); } - // 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' - && - preg_match( '/capabilities|user_level/', $meta_key ) - && - ! is_user_member_of_blog( $user_id, get_current_blog_id() ) - ) { + if ( $this->is_create_user() || $this->is_add_user_to_blog() || $this->is_delete_user() ) { return; } - $user = get_user_by( 'id', $user_id ); - if ( $meta_key === $user->cap_key ) { + if ( isset( $this->flags[ $user_id ] ) ) { /** - * Fires when the client needs to sync an updated user - * - * @since 4.2.0 - * - * @param object The Sanitized WP_User object + * This action is documented already in this file */ - do_action( 'jetpack_sync_save_user', $this->sanitize_user( $user ) ); + do_action( 'jetpack_sync_save_user', $user_id, $this->get_flags( $user_id ) ); } } @@ -400,6 +386,10 @@ class Jetpack_Sync_Module_Users extends Jetpack_Sync_Module { return Jetpack::is_function_in_backtrace( 'add_user_to_blog' ); } + private function is_delete_user() { + return Jetpack::is_function_in_backtrace( array( 'wp_delete_user' , 'remove_user_from_blog' ) ); + } + private function is_create_user() { $functions = array( 'add_new_user_to_blog', // Used to suppress jetpack_sync_save_user in save_user_cap_handler when user registered on multi site diff --git a/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php b/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php index 9604a518..6a048c38 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php +++ b/plugins/jetpack/sync/class.jetpack-sync-module-woocommerce.php @@ -194,43 +194,110 @@ class Jetpack_Sync_Module_WooCommerce extends Jetpack_Sync_Module { private static $wc_post_meta_whitelist = array( //woocommerce products - '_stock_status', + // https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-product-data-store-cpt.php#L21 '_visibility', - 'total_sales', - '_downloadable', - '_virtual', + '_sku', + '_price', '_regular_price', '_sale_price', + '_sale_price_dates_from', + '_sale_price_dates_to', + 'total_sales', '_tax_status', '_tax_class', - '_featured', - '_price', - '_stock', - '_backorders', '_manage_stock', + '_backorders', + '_sold_individually', + '_weight', + '_length', + '_width', + '_height', + '_upsell_ids', + '_crosssell_ids', + '_purchase_note', + '_default_attributes', + '_product_attributes', + '_virtual', + '_downloadable', + '_download_limit', + '_download_expiry', + '_featured', + '_downloadable_files', + '_wc_rating_count', + '_wc_average_rating', + '_wc_review_count', + '_variation_description', + '_thumbnail_id', + '_file_paths', + '_product_image_gallery', + '_product_version', + '_wp_old_slug', //woocommerce orders + // https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L27 + '_customer_user', + '_order_key', '_order_currency', - '_prices_include_tax', - '_created_via', - '_billing_country', + '_billing_first_name', + '_billing_last_name', + '_billing_company', + '_billing_address_1', + '_billing_address_2', '_billing_city', '_billing_state', '_billing_postcode', - '_shipping_country', + '_billing_country', + '_billing_email', + '_billing_phone', + '_shipping_first_name', + '_shipping_last_name', + '_shipping_company', + '_shipping_address_1', + '_shipping_address_2', '_shipping_city', '_shipping_state', '_shipping_postcode', - '_payment_method', - '_payment_method_title', - '_order_shipping', + '_shipping_country', + '_completed_date', + '_paid_date', '_cart_discount', '_cart_discount_tax', - '_order_tax', + '_order_shipping', '_order_shipping_tax', + '_order_tax', '_order_total', - '_download_permissions_granted', + '_payment_method', + '_payment_method_title', + '_transaction_id', + '_customer_ip_address', + '_customer_user_agent', + '_created_via', + '_order_version', + '_prices_include_tax', + '_date_completed', + '_date_paid', + '_payment_tokens', + '_billing_address_index', + '_shipping_address_index', '_recorded_sales', + '_recorded_coupon_usage_counts', + // https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L539 + '_download_permissions_granted', + // https://github.com/woocommerce/woocommerce/blob/8ed6e7436ff87c2153ed30edd83c1ab8abbdd3e9/includes/data-stores/class-wc-order-data-store-cpt.php#L594 '_order_stock_reduced', + + //woocommerce order refunds + // https://github.com/woocommerce/woocommerce/blob/b8a2815ae546c836467008739e7ff5150cb08e93/includes/data-stores/class-wc-order-refund-data-store-cpt.php#L20 + '_order_currency', + '_refund_amount', + '_refunded_by', + '_refund_reason', + '_order_shipping', + '_order_shipping_tax', + '_order_tax', + '_order_total', + '_order_version', + '_prices_include_tax', + '_payment_tokens', ); } diff --git a/plugins/jetpack/sync/class.jetpack-sync-sender.php b/plugins/jetpack/sync/class.jetpack-sync-sender.php index fa80a3af..47ed3f0b 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-sender.php +++ b/plugins/jetpack/sync/class.jetpack-sync-sender.php @@ -25,6 +25,7 @@ class Jetpack_Sync_Sender { private $sync_queue; private $full_sync_queue; private $codec; + private $old_user; // singleton functions private static $instance; @@ -44,11 +45,32 @@ class Jetpack_Sync_Sender { } private function init() { + add_action( 'jetpack_sync_before_send_queue_sync', array( $this, 'maybe_set_user_from_token' ), 1 ); + add_action( 'jetpack_sync_before_send_queue_sync', array( $this, 'maybe_clear_user_from_token' ), 20 ); foreach ( Jetpack_Sync_Modules::get_modules() as $module ) { $module->init_before_send(); } } + public function maybe_set_user_from_token( ) { + $jetpack = Jetpack::init(); + $verified_user = $jetpack->verify_xml_rpc_signature(); + if ( Jetpack_Constants::is_true( 'XMLRPC_REQUEST' ) && + ! is_wp_error( $verified_user ) + && $verified_user + ) { + $old_user = wp_get_current_user(); + $this->old_user = isset( $old_user->ID ) ? $old_user->ID : 0; + wp_set_current_user( $verified_user['user_id'] ); + } + } + + public function maybe_clear_user_from_token() { + if ( isset( $this->old_user ) ) { + wp_set_current_user( $this->old_user ); + } + } + public function get_next_sync_time( $queue_name ) { return (double) get_option( self::NEXT_SYNC_TIME_OPTION_NAME . '_' . $queue_name, 0 ); } diff --git a/plugins/jetpack/sync/class.jetpack-sync-settings.php b/plugins/jetpack/sync/class.jetpack-sync-settings.php index 4b69fb5c..3f0a1fee 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-settings.php +++ b/plugins/jetpack/sync/class.jetpack-sync-settings.php @@ -73,7 +73,7 @@ class Jetpack_Sync_Settings { $default_array_value = Jetpack_Sync_Defaults::get_post_meta_whitelist(); break; case 'comment_meta_whitelist': - $default_array_value = Jetpack_Sync_Defaults::$comment_meta_whitelist; + $default_array_value = Jetpack_Sync_Defaults::get_comment_meta_whitelist(); break; } |