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