* @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_constants' ); } /** * Sync the constants if we're supposed to. * * @access public */ public function maybe_sync_constants() { if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) { return; } set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Defaults::$default_sync_constants_wait_time ); $constants = $this->get_all_constants(); if ( empty( $constants ) ) { return; } $constants_checksums = (array) get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() ); foreach ( $constants as $name => $value ) { $checksum = $this->get_check_sum( $value ); // Explicitly not using Identical comparison as get_option returns a string. if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) && ! is_null( $value ) ) { /** * Tells the client to sync a constant to the server * * @param string The name of the constant * @param mixed The value of the constant * * @since 4.2.0 */ do_action( 'jetpack_sync_constant', $name, $value ); $constants_checksums[ $name ] = $checksum; } else { $constants_checksums[ $name ] = $checksum; } } update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums ); } /** * Retrieve all constants as per the current constants whitelist. * Public so that we don't have to store an option for each constant. * * @access public * * @return array All constants. */ public function get_all_constants() { $constants_whitelist = $this->get_constants_whitelist(); return array_combine( $constants_whitelist, array_map( array( $this, 'get_constant' ), $constants_whitelist ) ); } /** * Retrieve the value of a constant. * Used as a wrapper to standartize access to constants. * * @access private * * @param string $constant Constant name. * * @return mixed Return value of the constant. */ private function get_constant( $constant ) { return ( defined( $constant ) ) ? constant( $constant ) : null; } /** * Expand the constants 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_constants( $args ) { if ( $args[0] ) { $constants = $this->get_all_constants(); $constants_checksums = array(); foreach ( $constants as $name => $value ) { $constants_checksums[ $name ] = $this->get_check_sum( $value ); } update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums ); return $constants; } return $args; } /** * 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 count( $this->get_constants_whitelist() ); } }