maybe_unserialize() WordPress Function

The maybe_unserialize() function in WordPress is used to unserialize data that has been serialized by the WordPress Settings API. This function is used to ensure that the data is unserialized correctly before it is used by the WordPress Settings API.

maybe_unserialize( string $data ) #

Unserialize data only if it was serialized.


Parameters

$data

(string)(Required)Data that might be unserialized.


Top ↑

Return

(mixed) Unserialized data can be any type.


Top ↑

More Information

Data might need to be serialized to allow it to be successfully stored and retrieved from a database in a form that PHP can understand.


Top ↑

Source

File: wp-includes/functions.php

function maybe_unserialize( $data ) {
	if ( is_serialized( $data ) ) { // Don't attempt to unserialize data that wasn't serialized going in.
		return @unserialize( trim( $data ) );
	}

	return $data;
}


Top ↑

Changelog

Changelog
VersionDescription
2.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More