maybe_serialize( string|array|object $data )

Serialize data, if needed.


Parameters

$data

(string|array|object) (Required) Data that might be serialized.


Return

(mixed) A scalar data


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;
}


Changelog

Changelog
Version Description
WP-2.0.5 Introduced.