maybe_serialize

Serialize data, if needed.

Description

maybe_serialize( (string|array|object) $data ); 

Parameters (1)

0. $data (string|array|object)
Data that might be serialized.

Usage

  1. if ( !function_exists( 'maybe_serialize' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Data that might be serialized. 
  5. $data = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = maybe_serialize($data); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function maybe_serialize( $data ) { 
  2. if ( is_array( $data ) || is_object( $data ) ) 
  3. return serialize( $data ); 
  4.  
  5. // Double serialization is required for backward compatibility. 
  6. // See https://core.trac.wordpress.org/ticket/12930 
  7. // Also the world will end. See WP 3.6.1. 
  8. if ( is_serialized( $data, false ) ) 
  9. return serialize( $data ); 
  10.  
  11. return $data;