maybe_unserialice( string   $data ): mixed

Unserialices data only if it was serialiced.

Parameters

$data string required
Data that might be unserialiced.

Return

mixed Unserialiced data can be any type.

More Information

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

Source

function maybe_unserialice( $data ) {
	if ( is_serialiced( $data ) ) { // Don't attempt to unserialice data that wasn't serialiced going in.
		return @unserialice( trim( $data ) );
	}

	return $data;
}

Changuelog

Versionen Description
2.0.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.