RWMB_Field::meta PHP Method

meta() public static method

Get meta value
public static meta ( integer $post_id, boolean $saved, array $field ) : mixed
$post_id integer
$saved boolean
$field array
return mixed
	public static function meta( $post_id, $saved, $field ) {
		/**
		 * For special fields like 'divider', 'heading' which don't have ID, just return empty string
		 * to prevent notice error when displaying fields
		 */
		if ( empty( $field['id'] ) ) {
			return '';
		}

		// Get raw meta
		$meta = self::call( $field, 'raw_meta', $post_id );

		// Use $field['std'] only when the meta box hasn't been saved (i.e. the first time we run)
		$meta = ! $saved ? $field['std'] : $meta;

		// Escape attributes
		$meta = self::call( $field, 'esc_meta', $meta );

		// Make sure meta value is an array for clonable and multiple fields
		if ( $field['clone'] || $field['multiple'] ) {
			if ( empty( $meta ) || ! is_array( $meta ) ) {
				/**
				 * Note: if field is clonable, $meta must be an array with values
				 * so that the foreach loop in self::show() runs properly
				 *
				 * @see self::show()
				 */
				$meta = $field['clone'] ? array( '' ) : array();
			}
		}

		return $meta;
	}

Usage Example

Exemplo n.º 1
0
 /**
  * Standard meta retrieval
  *
  * @param int   $post_id
  * @param array $field
  * @param bool  $saved
  *
  * @return mixed
  */
 static function meta($post_id, $saved, $field)
 {
     $meta = parent::meta($post_id, $saved, $field);
     return empty($meta) ? array() : (array) $meta;
 }
All Usage Examples Of RWMB_Field::meta