Make WordPress Core


Ignore:
Timestamp:
03/13/2020 09:05:02 PM (7 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r47430 r47453  
    583583
    584584/**
    585  * Unserialize value only if it was serialized.
     585 * Serialize data, if needed.
     586 *
     587 * @since 2.0.5
     588 *
     589 * @param string|array|object $data Data that might be serialized.
     590 * @return mixed A scalar data.
     591 */
     592function maybe_serialize( $data ) {
     593        if ( is_array( $data ) || is_object( $data ) ) {
     594                return serialize( $data );
     595        }
     596
     597        /*
     598         * Double serialization is required for backward compatibility.
     599         * See https://core.trac.wordpress.org/ticket/12930
     600         * Also the world will end. See WP 3.6.1.
     601         */
     602        if ( is_serialized( $data, false ) ) {
     603                return serialize( $data );
     604        }
     605
     606        return $data;
     607}
     608
     609/**
     610 * Unserialize data only if it was serialized.
    586611 *
    587612 * @since 2.0.0
    588613 *
    589  * @param string $original Maybe unserialized original, if is needed.
     614 * @param string $data Data that might be unserialized.
    590615 * @return mixed Unserialized data can be any type.
    591616 */
    592 function maybe_unserialize( $original ) {
    593         if ( is_serialized( $original ) ) { // Don't attempt to unserialize data that wasn't serialized going in.
    594                 return @unserialize( $original );
    595         }
    596         return $original;
     617function maybe_unserialize( $data ) {
     618        if ( is_serialized( $data ) ) { // Don't attempt to unserialize data that wasn't serialized going in.
     619                return @unserialize( $data );
     620        }
     621
     622        return $data;
    597623}
    598624
    … …  
    694720                return true;
    695721        }
    696 }
    697 
    698 /**
    699  * Serialize data, if needed.
    700  *
    701  * @since 2.0.5
    702  *
    703  * @param string|array|object $data Data that might be serialized.
    704  * @return mixed A scalar data
    705  */
    706 function maybe_serialize( $data ) {
    707         if ( is_array( $data ) || is_object( $data ) ) {
    708                 return serialize( $data );
    709         }
    710 
    711         /*
    712          * Double serialization is required for backward compatibility.
    713          * See https://core.trac.wordpress.org/ticket/12930
    714          * Also the world will end. See WP 3.6.1.
    715          */
    716         if ( is_serialized( $data, false ) ) {
    717                 return serialize( $data );
    718         }
    719 
    720         return $data;
    721722}
    722723
Note: See TracChangeset for help on using the changeset viewer.