| @@ 92-126 (lines=35) @@ | ||
| 89 | $this->maybe_sync_callables(); |
|
| 90 | } |
|
| 91 | ||
| 92 | public function maybe_sync_callables() { |
|
| 93 | if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) { |
|
| 94 | return; |
|
| 95 | } |
|
| 96 | ||
| 97 | $callables = $this->get_all_callables(); |
|
| 98 | ||
| 99 | if ( empty( $callables ) ) { |
|
| 100 | return; |
|
| 101 | } |
|
| 102 | ||
| 103 | set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time ); |
|
| 104 | ||
| 105 | $callable_checksums = (array) get_option( self::CALLABLES_CHECKSUM_OPTION_NAME , array() ); |
|
| 106 | ||
| 107 | // only send the callables that have changed |
|
| 108 | foreach ( $callables as $name => $value ) { |
|
| 109 | $checksum = $this->get_check_sum( $value ); |
|
| 110 | // explicitly not using Identical comparison as get_option returns a string |
|
| 111 | if ( ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ) && ! is_null( $value ) ) { |
|
| 112 | /** |
|
| 113 | * Tells the client to sync a callable (aka function) to the server |
|
| 114 | * |
|
| 115 | * @since 4.2.0 |
|
| 116 | * |
|
| 117 | * @param string The name of the callable |
|
| 118 | * @param mixed The value of the callable |
|
| 119 | */ |
|
| 120 | do_action( 'jetpack_sync_callable', $name, $value ); |
|
| 121 | $callable_checksums[ $name ] = $checksum; |
|
| 122 | } else { |
|
| 123 | $callable_checksums[ $name ] = $checksum; |
|
| 124 | } |
|
| 125 | } |
|
| 126 | update_option( self::CALLABLES_CHECKSUM_OPTION_NAME , $callable_checksums ); |
|
| 127 | } |
|
| 128 | ||
| 129 | public function expand_callables( $args ) { |
|
| @@ 66-98 (lines=33) @@ | ||
| 63 | return array( 'jetpack_full_sync_constants' ); |
|
| 64 | } |
|
| 65 | ||
| 66 | function maybe_sync_constants() { |
|
| 67 | if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) { |
|
| 68 | return; |
|
| 69 | } |
|
| 70 | ||
| 71 | $constants = $this->get_all_constants(); |
|
| 72 | if ( empty( $constants ) ) { |
|
| 73 | return; |
|
| 74 | } |
|
| 75 | ||
| 76 | set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time ); |
|
| 77 | $constants_checksums = (array) get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() ); |
|
| 78 | ||
| 79 | foreach ( $constants as $name => $value ) { |
|
| 80 | $checksum = $this->get_check_sum( $value ); |
|
| 81 | // explicitly not using Identical comparison as get_option returns a string |
|
| 82 | if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) && ! is_null( $value ) ) { |
|
| 83 | /** |
|
| 84 | * Tells the client to sync a constant to the server |
|
| 85 | * |
|
| 86 | * @since 4.2.0 |
|
| 87 | * |
|
| 88 | * @param string The name of the constant |
|
| 89 | * @param mixed The value of the constant |
|
| 90 | */ |
|
| 91 | do_action( 'jetpack_sync_constant', $name, $value ); |
|
| 92 | $constants_checksums[ $name ] = $checksum; |
|
| 93 | } else { |
|
| 94 | $constants_checksums[ $name ] = $checksum; |
|
| 95 | } |
|
| 96 | } |
|
| 97 | update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums ); |
|
| 98 | } |
|
| 99 | ||
| 100 | // public so that we don't have to store an option for each constant |
|
| 101 | function get_all_constants() { |
|