如果需要,可以序列化数据。

原型

maybe_serialize( string|array|object $data )

参数

$data (string|array|object) (Required) 可能序列化的数据。

返回值

(mixed)  标量数据

源文件

路径:wp-includes/functions.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<?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;
}

...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/maybe_serialize/