sient ] ) && $checksums[ $transient ] === $new_checksum ) { return; } $checksums[ $transient ] = $new_checksum; update_option( self::UPDATES_CHECKSUM_OPTION_NAME, $checksums ); if ( 'update_core' === $transient ) { /** * Trigger a change to core update that we want to sync. * * @since 5.1.0 * * @param array $value Contains info that tells us what needs updating. */ do_action( 'jetpack_update_core_change', $value ); return; } if ( empty( $this->updates ) ) { // Lets add the shutdown method once and only when the updates move from empty to filled with something. add_action( 'shutdown', array( $this, 'sync_last_event' ), 9 ); } if ( ! isset( $this->updates[ $transient ] ) ) { $this->updates[ $transient ] = array(); } $this->updates[ $transient ][] = $value; } /** * Sync the last update only. * * @access public */ public function sync_last_event() { foreach ( $this->updates as $transient => $values ) { $value = end( $values ); // Only send over the last value. /** * Trigger a change to a specific update that we want to sync. * Triggers one of the following actions: * - jetpack_{$transient}_change * - jetpack_update_plugins_change * - jetpack_update_themes_change * * @since 5.1.0 * * @param array $value Contains info that tells us what needs updating. */ do_action( "jetpack_{$transient}_change", $value ); } } /** * Enqueue the updates actions for full sync. * * @access public * * @param array $config Full sync configuration for this sync module. * @param int $max_items_to_enqueue Maximum number of items to enqueue. * @param boolean $state True if full sync has finished enqueueing this module, false otherwise. * @return array Number of actions enqueued, and next module state. */ public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable /** * Tells the client to sync all updates to the server * * @since 4.2.0 * * @param boolean Whether to expand updates (should always be true) */ do_action( 'jetpack_full_sync_updates', true ); // The number of actions enqueued, and next module state (true == done). return array( 1, true ); } /** * Send the updates actions for full sync. * * @access public * * @param array $config Full sync configuration for this sync module. * @param int $send_until The timestamp until the current request can send. * @param array $state This module Full Sync status. * * @return array This module Full Sync status. */ public function send_full_sync_actions( $config, $send_until, $state ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable // we call this instead of do_action when sending immediately. $this->send_action( 'jetpack_full_sync_updates', array( true ) ); // The number of actions enqueued, and next module state (true == done). return array( 'finished' => true ); } /** * Retrieve an estimated number of actions that will be enqueued. * * @access public * * @param array $config Full sync configuration for this sync module. * @return array Number of items yet to be enqueued. */ public function estimate_full_sync_actions( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable return 1; } /** * Retrieve the actions that will be sent for this module during a full sync. * * @access public * * @return array Full sync actions of this module. */ public function get_full_sync_actions() { return array( 'jetpack_full_sync_updates' ); } /** * Retrieve all updates that we're interested in. * * @access public * * @return array All updates. */ public function get_all_updates() { return array( 'core' => get_site_transient( 'update_core' ), 'plugins' => get_site_transient( 'update_plugins' ), 'themes' => get_site_transient( 'update_themes' ), ); } /** * Remove unnecessary keys from synced updates data. * * @access public * * @param array $args Hook arguments. * @return array $args Hook arguments. */ public function filter_update_keys( $args ) { $updates = $args[0]; if ( isset( $updates->no_update ) ) { unset( $updates->no_update ); } return $args; } /** * Filter out upgrader object from the completed upgrader action args. * * @access public * * @param array $args Hook arguments. * @return array $args Filtered hook arguments. */ public function filter_upgrader_process_complete( $args ) { array_shift( $args ); return $args; } /** * Expand the updates within a hook before they are serialized and sent to the server. * * @access public * * @param array $args The hook parameters. * @return array $args The hook parameters. */ public function expand_updates( $args ) { if ( $args[0] ) { return $this->get_all_updates(); } return $args; } /** * Expand the themes within a hook before they are serialized and sent to the server. * * @access public * * @param array $args The hook parameters. * @return array $args The hook parameters. */ public function expand_themes( $args ) { if ( ! isset( $args[0], $args[0]->response ) ) { return $args; } if ( ! is_array( $args[0]->response ) ) { // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error trigger_error( 'Warning: Not an Array as expected but -> ' . wp_json_encode( $args[0]->response ) . ' instead', E_USER_WARNING ); return $args; } foreach ( $args[0]->response as $stylesheet => &$theme_data ) { $theme = wp_get_theme( $stylesheet ); $theme_data['name'] = $theme->name; } return $args; } /** * Perform module cleanup. * Deletes any transients and options that this module uses. * Usually triggered when uninstalling the plugin. * * @access public */ public function reset_data() { delete_option( self::UPDATES_CHECKSUM_OPTION_NAME ); } /** * Return Total number of objects. * * @param array $config Full Sync config. * * @return int total */ public function total( $config ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable return 3; } }