@@ 792-824 (lines=33) @@ | ||
789 | return 1; // The number of actions enqueued |
|
790 | } |
|
791 | ||
792 | private function maybe_sync_constants() { |
|
793 | if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) { |
|
794 | return; |
|
795 | } |
|
796 | ||
797 | $constants = $this->get_all_constants(); |
|
798 | if ( empty( $constants ) ) { |
|
799 | return; |
|
800 | } |
|
801 | ||
802 | set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time ); |
|
803 | $constants_checksums = get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() ); |
|
804 | // only send the constants that have changed |
|
805 | foreach ( $constants as $name => $value ) { |
|
806 | $checksum = $this->get_check_sum( $value ); |
|
807 | ||
808 | // explicitly not using Identical comparison as get_option returns a string |
|
809 | if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) ) { |
|
810 | /** |
|
811 | * Tells the client to sync a constant to the server |
|
812 | * |
|
813 | * @since 4.2.0 |
|
814 | * |
|
815 | * @param string The name of the constant |
|
816 | * @param mixed The value of the constant |
|
817 | */ |
|
818 | do_action( 'jetpack_sync_constant', $name, $value ); |
|
819 | $constants_checksums[ $name ] = $checksum; |
|
820 | } |
|
821 | } |
|
822 | ||
823 | update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums ); |
|
824 | } |
|
825 | // public so that we don't have to store an option for each constant |
|
826 | function get_all_constants() { |
|
827 | return array_combine( |
|
@@ 853-885 (lines=33) @@ | ||
850 | $this->maybe_sync_callables(); |
|
851 | } |
|
852 | ||
853 | private function maybe_sync_callables() { |
|
854 | if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) { |
|
855 | return; |
|
856 | } |
|
857 | ||
858 | $callables = $this->get_all_callables(); |
|
859 | if ( empty( $callables ) ) { |
|
860 | return; |
|
861 | } |
|
862 | ||
863 | set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time ); |
|
864 | ||
865 | $callable_checksums = get_option( self::CALLABLES_CHECKSUM_OPTION_NAME , array() ); |
|
866 | ||
867 | // only send the callables that have changed |
|
868 | foreach ( $callables as $name => $value ) { |
|
869 | $checksum = $this->get_check_sum( $value ); |
|
870 | // explicitly not using Identical comparison as get_option returns a string |
|
871 | if ( ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ) ) { |
|
872 | /** |
|
873 | * Tells the client to sync a callable (aka function) to the server |
|
874 | * |
|
875 | * @since 4.2.0 |
|
876 | * |
|
877 | * @param string The name of the callable |
|
878 | * @param mixed The value of the callable |
|
879 | */ |
|
880 | do_action( 'jetpack_sync_callable', $name, $value ); |
|
881 | $callable_checksums[ $name ] = $checksum; |
|
882 | } |
|
883 | } |
|
884 | update_option( self::CALLABLES_CHECKSUM_OPTION_NAME , $callable_checksums ); |
|
885 | } |
|
886 | ||
887 | private function still_valid_checksum( $sums_to_check, $name, $new_sum ) { |
|
888 | if ( isset( $sums_to_check[ $name ] ) && $sums_to_check[ $name ] === $new_sum ) { |