PHP Class RW_Meta_Box

Author: Rilwis
Author: Co-Authors @see https://github.com/rilwis/meta-box
Mostrar archivo Open project: rilwis/meta-box Class Usage Examples

Public Properties

Property Type Description
$fields Fields information
$meta_box Meta box information
$saved Used to prevent duplicated calls like revisions, manual hook to wp_insert_post, etc.

Public Methods

Method Description
__construct ( array $meta_box ) Create meta box based on given data
add_meta_boxes ( ) Add meta box for multiple post types
enqueue ( ) Enqueue common scripts and styles.
hide ( array $hidden, object $screen ) : array Hide meta box if it's set 'default_hidden'
is_edit_screen ( WP_Screen $screen = null ) : boolean Check if we're on the right edit screen.
is_saved ( ) : boolean Check if meta box is saved before.
normalize ( array $meta_box ) : array Normalize parameters for meta box
normalize_fields ( array $fields ) : array Normalize an array of fields
save_post ( integer $post_id ) Save data from meta box
show ( ) Callback function to show fields in meta box

Protected Methods

Method Description
global_hooks ( ) Add global hooks.
is_shown ( ) : boolean Conditional check for whether initializing meta box.
object_hooks ( ) Specific hooks for meta box object. Default is 'post'.
validate ( ) : boolean Validate form when submit. Check: - If this function is called to prevent duplicated calls like revisions, manual hook to wp_insert_post, etc.

Method Details

__construct() public method

Create meta box based on given data
public __construct ( array $meta_box )
$meta_box array Meta box definition

add_meta_boxes() public method

Add meta box for multiple post types
public add_meta_boxes ( )

enqueue() public method

Enqueue common scripts and styles.
public enqueue ( )

global_hooks() protected method

Add global hooks.
protected global_hooks ( )

hide() public method

Hide meta box if it's set 'default_hidden'
public hide ( array $hidden, object $screen ) : array
$hidden array Array of default hidden meta boxes
$screen object Current screen information
return array

is_edit_screen() public method

Check if we're on the right edit screen.
public is_edit_screen ( WP_Screen $screen = null ) : boolean
$screen WP_Screen Screen object. Optional. Use current screen object by default.
return boolean

is_saved() public method

This helps saving empty value in meta fields (text, check box, etc.) and set the correct default values.
public is_saved ( ) : boolean
return boolean

is_shown() protected method

- 1st filter applies to all meta boxes - 2nd filter applies to only current meta box
protected is_shown ( ) : boolean
return boolean

normalize() public static method

Normalize parameters for meta box
public static normalize ( array $meta_box ) : array
$meta_box array Meta box definition
return array $meta_box Normalized meta box

normalize_fields() public static method

Normalize an array of fields
public static normalize_fields ( array $fields ) : array
$fields array Array of fields
return array $fields Normalized fields

object_hooks() protected method

This should be extended in sub-classes to support meta fields for terms, user, settings pages, etc.
protected object_hooks ( )

save_post() public method

Save data from meta box
public save_post ( integer $post_id )
$post_id integer Post ID

show() public method

Callback function to show fields in meta box
public show ( )

validate() protected method

- Autosave - If form is submitted properly
protected validate ( ) : boolean
return boolean

Property Details

$fields public_oe property

Fields information
public $fields

$meta_box public_oe property

Meta box information
public $meta_box

$saved public_oe property

Used to prevent duplicated calls like revisions, manual hook to wp_insert_post, etc.
public $saved