|
@@ 726-758 (lines=33) @@
|
| 723 |
|
return 1; // The number of actions enqueued |
| 724 |
|
} |
| 725 |
|
|
| 726 |
|
private function maybe_sync_constants() { |
| 727 |
|
if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) { |
| 728 |
|
return; |
| 729 |
|
} |
| 730 |
|
|
| 731 |
|
$constants = $this->get_all_constants(); |
| 732 |
|
if ( empty( $constants ) ) { |
| 733 |
|
return; |
| 734 |
|
} |
| 735 |
|
|
| 736 |
|
set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time ); |
| 737 |
|
$constants_checksums = get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() ); |
| 738 |
|
// only send the constants that have changed |
| 739 |
|
foreach ( $constants as $name => $value ) { |
| 740 |
|
$checksum = $this->get_check_sum( $value ); |
| 741 |
|
|
| 742 |
|
// explicitly not using Identical comparison as get_option returns a string |
| 743 |
|
if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) ) { |
| 744 |
|
/** |
| 745 |
|
* Tells the client to sync a constant to the server |
| 746 |
|
* |
| 747 |
|
* @since 4.2.0 |
| 748 |
|
* |
| 749 |
|
* @param string The name of the constant |
| 750 |
|
* @param mixed The value of the constant |
| 751 |
|
*/ |
| 752 |
|
do_action( 'jetpack_sync_constant', $name, $value ); |
| 753 |
|
$constants_checksums[ $name ] = $checksum; |
| 754 |
|
} |
| 755 |
|
} |
| 756 |
|
|
| 757 |
|
update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums ); |
| 758 |
|
} |
| 759 |
|
// public so that we don't have to store an option for each constant |
| 760 |
|
function get_all_constants() { |
| 761 |
|
return array_combine( |
|
@@ 789-821 (lines=33) @@
|
| 786 |
|
$this->maybe_sync_callables(); |
| 787 |
|
} |
| 788 |
|
|
| 789 |
|
private function maybe_sync_callables() { |
| 790 |
|
if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) { |
| 791 |
|
return; |
| 792 |
|
} |
| 793 |
|
|
| 794 |
|
$callables = $this->get_all_callables(); |
| 795 |
|
if ( empty( $callables ) ) { |
| 796 |
|
return; |
| 797 |
|
} |
| 798 |
|
|
| 799 |
|
set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time ); |
| 800 |
|
|
| 801 |
|
$callable_checksums = get_option( self::CALLABLES_CHECKSUM_OPTION_NAME , array() ); |
| 802 |
|
|
| 803 |
|
// only send the callables that have changed |
| 804 |
|
foreach ( $callables as $name => $value ) { |
| 805 |
|
$checksum = $this->get_check_sum( $value ); |
| 806 |
|
// explicitly not using Identical comparison as get_option returns a string |
| 807 |
|
if ( ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ) ) { |
| 808 |
|
/** |
| 809 |
|
* Tells the client to sync a callable (aka function) to the server |
| 810 |
|
* |
| 811 |
|
* @since 4.2.0 |
| 812 |
|
* |
| 813 |
|
* @param string The name of the callable |
| 814 |
|
* @param mixed The value of the callable |
| 815 |
|
*/ |
| 816 |
|
do_action( 'jetpack_sync_callable', $name, $value ); |
| 817 |
|
$callable_checksums[ $name ] = $checksum; |
| 818 |
|
} |
| 819 |
|
} |
| 820 |
|
update_option( self::CALLABLES_CHECKSUM_OPTION_NAME , $callable_checksums ); |
| 821 |
|
} |
| 822 |
|
|
| 823 |
|
private function still_valid_checksum( $sums_to_check, $name, $new_sum ) { |
| 824 |
|
if ( isset( $sums_to_check[ $name ] ) && $sums_to_check[ $name ] === $new_sum ) { |