| @@ 131-170 (lines=40) @@ | ||
| 128 | return ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ); |
|
| 129 | } |
|
| 130 | ||
| 131 | public function maybe_sync_callables() { |
|
| 132 | if ( ! is_admin() || Jetpack_Sync_Settings::is_doing_cron() ) { |
|
| 133 | return; |
|
| 134 | } |
|
| 135 | ||
| 136 | if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) { |
|
| 137 | return; |
|
| 138 | } |
|
| 139 | ||
| 140 | set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time ); |
|
| 141 | ||
| 142 | $callables = $this->get_all_callables(); |
|
| 143 | ||
| 144 | if ( empty( $callables ) ) { |
|
| 145 | return; |
|
| 146 | } |
|
| 147 | ||
| 148 | $callable_checksums = (array) get_option( self::CALLABLES_CHECKSUM_OPTION_NAME, array() ); |
|
| 149 | ||
| 150 | // only send the callables that have changed |
|
| 151 | foreach ( $callables as $name => $value ) { |
|
| 152 | $checksum = $this->get_check_sum( $value ); |
|
| 153 | // explicitly not using Identical comparison as get_option returns a string |
|
| 154 | if ( ! is_null( $value ) && $this->should_send_callable( $callable_checksums, $name, $checksum ) ) { |
|
| 155 | /** |
|
| 156 | * Tells the client to sync a callable (aka function) to the server |
|
| 157 | * |
|
| 158 | * @since 4.2.0 |
|
| 159 | * |
|
| 160 | * @param string The name of the callable |
|
| 161 | * @param mixed The value of the callable |
|
| 162 | */ |
|
| 163 | do_action( 'jetpack_sync_callable', $name, $value ); |
|
| 164 | $callable_checksums[ $name ] = $checksum; |
|
| 165 | } else { |
|
| 166 | $callable_checksums[ $name ] = $checksum; |
|
| 167 | } |
|
| 168 | } |
|
| 169 | update_option( self::CALLABLES_CHECKSUM_OPTION_NAME, $callable_checksums ); |
|
| 170 | } |
|
| 171 | ||
| 172 | public function expand_callables( $args ) { |
|
| 173 | if ( $args[0] ) { |
|
| @@ 63-96 (lines=34) @@ | ||
| 60 | return array( 'jetpack_full_sync_constants' ); |
|
| 61 | } |
|
| 62 | ||
| 63 | function maybe_sync_constants() { |
|
| 64 | if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) { |
|
| 65 | return; |
|
| 66 | } |
|
| 67 | ||
| 68 | set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time ); |
|
| 69 | ||
| 70 | $constants = $this->get_all_constants(); |
|
| 71 | if ( empty( $constants ) ) { |
|
| 72 | return; |
|
| 73 | } |
|
| 74 | ||
| 75 | $constants_checksums = (array) get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() ); |
|
| 76 | ||
| 77 | foreach ( $constants as $name => $value ) { |
|
| 78 | $checksum = $this->get_check_sum( $value ); |
|
| 79 | // explicitly not using Identical comparison as get_option returns a string |
|
| 80 | if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) && ! is_null( $value ) ) { |
|
| 81 | /** |
|
| 82 | * Tells the client to sync a constant to the server |
|
| 83 | * |
|
| 84 | * @since 4.2.0 |
|
| 85 | * |
|
| 86 | * @param string The name of the constant |
|
| 87 | * @param mixed The value of the constant |
|
| 88 | */ |
|
| 89 | do_action( 'jetpack_sync_constant', $name, $value ); |
|
| 90 | $constants_checksums[ $name ] = $checksum; |
|
| 91 | } else { |
|
| 92 | $constants_checksums[ $name ] = $checksum; |
|
| 93 | } |
|
| 94 | } |
|
| 95 | update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums ); |
|
| 96 | } |
|
| 97 | ||
| 98 | // public so that we don't have to store an option for each constant |
|
| 99 | function get_all_constants() { |
|