WordPress at a glance

maybe_unserialize() WP 1.0

Unserialize value only if it was serialized.

1 time = 0.000047s = very fast | 50000 times = 1.21s = 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.5.1

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

From tag: serialize

More from category: Helper Functions

No comments
    Log In . Register