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