th to the url if the plugin did not provide it. $link_url_scheme = wp_parse_url( $link_url, PHP_URL_SCHEME ); if ( empty( $link_url_scheme ) ) { $link_url = admin_url( $link_url ); } // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $formatted_action_links[ $link_element->nodeValue ] = $link_url; } } } if ( $formatted_action_links ) { $plugins_action_links[ $plugin_file ] = $formatted_action_links; } } // Cache things for a long time. set_transient( 'jetpack_plugin_api_action_links_refresh', time(), DAY_IN_SECONDS ); update_option( 'jetpack_plugin_api_action_links', $plugins_action_links ); } /** * Whether a certain callable should be sent. * * @access public * * @param array $callable_checksums Callable checksums. * @param string $name Name of the callable. * @param string $checksum A checksum of the callable. * @return boolean Whether to send the callable. */ public function should_send_callable( $callable_checksums, $name, $checksum ) { $idc_override_callables = array( 'main_network_site', 'home_url', 'site_url', ); if ( in_array( $name, $idc_override_callables, true ) && \Jetpack_Options::get_option( 'migrate_for_idc' ) ) { return true; } return ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ); } /** * Sync the callables if we're supposed to. * * @access public */ public function maybe_sync_callables() { $callables = $this->get_all_callables(); if ( ! apply_filters( 'jetpack_check_and_send_callables', false ) ) { if ( ! is_admin() ) { // If we're not an admin and we're not doing cron and this isn't WP_CLI, don't sync anything. if ( ! Settings::is_doing_cron() && ! Jetpack_Constants::get_constant( 'WP_CLI' ) ) { return; } // If we're not an admin and we are doing cron, sync the Callables that are always supposed to sync ( See https://github.com/Automattic/jetpack/issues/12924 ). $callables = $this->get_always_sent_callables(); } if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) { if ( $this->force_send_callables_on_next_tick ) { $this->unlock_sync_callable(); } return; } } if ( empty( $callables ) ) { return; } // No need to set the transiant we are trying to remove it anyways. if ( ! $this->force_send_callables_on_next_tick ) { set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Defaults::$default_sync_callables_wait_time ); } $callable_checksums = (array) \Jetpack_Options::get_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, array() ); $has_changed = false; // Only send the callables that have changed. foreach ( $callables as $name => $value ) { $checksum = $this->get_check_sum( $value ); // Explicitly not using Identical comparison as get_option returns a string. if ( ! is_null( $value ) && $this->should_send_callable( $callable_checksums, $name, $checksum ) ) { // Only send callable if the non sorted checksum also does not match. if ( $this->should_send_callable( $callable_checksums, $name, $this->get_check_sum( $value, false ) ) ) { /** * Tells the client to sync a callable (aka function) to the server * * @param string The name of the callable * @param mixed The value of the callable * * @since 4.2.0 */ do_action( 'jetpack_sync_callable', $name, $value ); } $callable_checksums[ $name ] = $checksum; $has_changed = true; } else { $callable_checksums[ $name ] = $checksum; } } if ( $has_changed ) { \Jetpack_Options::update_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callable_checksums ); } if ( $this->force_send_callables_on_next_tick ) { $this->unlock_sync_callable(); } } /** * Get the callables that should always be sent, e.g. on cron. * * @return array Callables that should always be sent */ protected function get_always_sent_callables() { $callables = $this->get_all_callables(); $cron_callables = array(); foreach ( self::ALWAYS_SEND_UPDATES_TO_THESE_OPTIONS as $option_name ) { if ( array_key_exists( $option_name, $callables ) ) { $cron_callables[ $option_name ] = $callables[ $option_name ]; continue; } // Check for the Callable name/key for the option, if different from option name. if ( array_key_exists( $option_name, self::OPTION_NAMES_TO_CALLABLE_NAMES ) ) { $callable_name = self::OPTION_NAMES_TO_CALLABLE_NAMES[ $option_name ]; if ( array_key_exists( $callable_name, $callables ) ) { $cron_callables[ $callable_name ] = $callables[ $callable_name ]; } } } return $cron_callables; } /** * Expand the callables 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_callables( $args ) { if ( $args[0] ) { $callables = $this->get_all_callables(); $callables_checksums = array(); foreach ( $callables as $name => $value ) { $callables_checksums[ $name ] = $this->get_check_sum( $value ); } \Jetpack_Options::update_raw_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callables_checksums ); return $callables; } 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_callable_whitelist() ); } }