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
This commit is contained in:
SergeyBiryukov 2020-03-13 21:05:02 +00:00
parent 5ac6156507
commit 13c5098f74
1 changed files with 32 additions and 31 deletions

View File

@ -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.
*