maybe_serialize( string|array|object $data )
Serialize data, if needed.
Description Description
Parameters Parameters
- $data
-
(string|array|object) (Required) Data that might be serialized.
Return Return
(mixed) A scalar data
Source Source
File: wp-includes/functions.php
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; }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
2.0.5 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Basic Examples
Expand full source codeCollapse full source code
Basic Examples
‘Hello World!’, ‘foo’ => ‘bar’ );
echo maybe_serialize( $data );
// a:2:{i:1;s:12:”Hello World!”;s:3:”foo”;s:3:”bar”;}
// A serialized string will be serialized again.
$data = ‘a:2:{i:1;s:12:”Hello World!”;s:3:”foo”;s:3:”bar”;}’;
echo maybe_serialize( $data );
// s:50:”a:2:{i:1;s:12:”Hello World!”;s:3:”foo”;s:3:”bar”;}”;
?>