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