From 13c5098f74bf07c433a2e7503758c2ad1ef35c38 Mon Sep 17 00:00:00 2001 From: SergeyBiryukov Date: Fri, 13 Mar 2020 21:05:02 +0000 Subject: [PATCH] General: Move `maybe_serialize()` to a more appropriate place in the file, before `maybe_unserialize()`. Rename the `$original` parameter of `maybe_unserialize()` to `$data`, for consistency with other serialization functions. See #36416. git-svn-id: https://develop.svn.wordpress.org/trunk@47453 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 63 ++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 6c5184f697..8a91d152bf 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -582,18 +582,44 @@ function get_weekstartend( $mysqlstring, $start_of_week = '' ) { } /** - * Unserialize value only if it was serialized. + * Serialize data, if needed. + * + * @since 2.0.5 + * + * @param string|array|object $data Data that might be serialized. + * @return mixed A scalar data. + */ +function maybe_serialize( $data ) { + if ( is_array( $data ) || is_object( $data ) ) { + return serialize( $data ); + } + + /* + * Double serialization is required for backward compatibility. + * See https://core.trac.wordpress.org/ticket/12930 + * Also the world will end. See WP 3.6.1. + */ + if ( is_serialized( $data, false ) ) { + return serialize( $data ); + } + + return $data; +} + +/** + * Unserialize data only if it was serialized. * * @since 2.0.0 * - * @param string $original Maybe unserialized original, if is needed. + * @param string $data Data that might be unserialized. * @return mixed Unserialized data can be any type. */ -function maybe_unserialize( $original ) { - if ( is_serialized( $original ) ) { // Don't attempt to unserialize data that wasn't serialized going in. - return @unserialize( $original ); +function maybe_unserialize( $data ) { + if ( is_serialized( $data ) ) { // Don't attempt to unserialize data that wasn't serialized going in. + return @unserialize( $data ); } - return $original; + + return $data; } /** @@ -695,31 +721,6 @@ function is_serialized_string( $data ) { } } -/** - * Serialize data, if needed. - * - * @since 2.0.5 - * - * @param string|array|object $data Data that might be serialized. - * @return mixed A scalar data - */ -function maybe_serialize( $data ) { - if ( is_array( $data ) || is_object( $data ) ) { - return serialize( $data ); - } - - /* - * Double serialization is required for backward compatibility. - * See https://core.trac.wordpress.org/ticket/12930 - * Also the world will end. See WP 3.6.1. - */ - if ( is_serialized( $data, false ) ) { - return serialize( $data ); - } - - return $data; -} - /** * Retrieve post title from XMLRPC XML. *