diff options
Diffstat (limited to 'plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php')
-rw-r--r-- | plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php b/plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php index cb2954f1..8d8e6173 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php +++ b/plugins/jetpack/sync/class.jetpack-sync-json-deflate-array-codec.php @@ -8,11 +8,11 @@ require_once dirname( __FILE__ ) . '/interface.jetpack-sync-codec.php'; */ class Jetpack_Sync_JSON_Deflate_Array_Codec implements iJetpack_Sync_Codec { const CODEC_NAME = "deflate-json-array"; - + public function name() { return self::CODEC_NAME; } - + public function encode( $object ) { return base64_encode( gzdeflate( $this->json_serialize( $object ) ) ); } @@ -22,11 +22,16 @@ class Jetpack_Sync_JSON_Deflate_Array_Codec implements iJetpack_Sync_Codec { } // @see https://gist.github.com/muhqu/820694 - private function json_serialize( $any ) { + + protected function json_serialize( $any ) { + if ( function_exists( 'jetpack_json_wrap' ) ) { + return wp_json_encode( jetpack_json_wrap( $any ) ); + } + // This prevents fatal error when updating pre 6.0 via the cli command return wp_json_encode( $this->json_wrap( $any ) ); } - private function json_unserialize( $str ) { + protected function json_unserialize( $str ) { return $this->json_unwrap( json_decode( $str, true ) ); } @@ -47,10 +52,10 @@ class Jetpack_Sync_JSON_Deflate_Array_Codec implements iJetpack_Sync_Codec { if ( ( is_array( $v ) || is_object( $v ) ) ) { if ( in_array( $v, $seen_nodes, true ) ) { continue; - } + } $return[ $k ] = $this->json_wrap( $v, $seen_nodes ); } else { - $return[ $k ] = $v; + $return[ $k ] = $v; } } @@ -77,4 +82,4 @@ class Jetpack_Sync_JSON_Deflate_Array_Codec implements iJetpack_Sync_Codec { return $any; } -}
\ No newline at end of file +} |