WordPress at a glance

maybe_serialize() WP 1.0

Serialize data, if needed.

No Hooks.

Return

Mixed. A scalar data

Usage

maybe_serialize( $data );
$data(string/array/object) (required)
Data that might be serialized.

Code of maybe_serialize: wp-includes/functions.php VER 5.0.1

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

Related Functions

From tag: serialize

More from category: Helper Functions

No comments
    Hello, !     Log In . Register