WordPress at Your Fingertips

maybe_unserialize() WP 1.0

Unserialize value only if it was serialized.

1 time — 0.000047 sec (very fast) | 50000 times — 1.21 sec (fast) | PHP 7.1.2, WP 4.7.4

No Hooks.

Return

Mixed. Unserialized data can be any type.

Usage

maybe_unserialize( $data );
$data(string) (required)
Data that might be unserialized.

Changelog

Since 2.0.0 Introduced.

Code of maybe_unserialize() WP 5.8.1

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

serialize

Helper Functions

No comments
    Log In