PHP Класс CMB2, Give

Автор: WebDevStudios
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$data_to_save array Array of key => value data for saving. Likely $_POST data.

Защищенные свойства (Protected)

Свойство Тип Описание
$cmb_id string Current CMB2 instance ID
$fields array Metabox field objects
$generated_nonce string Array of key => value data for saving. Likely $_POST data.
$has_columns boolean Whether there are fields to be shown in columns. Set in CMB2::add_field().
$hidden_fields array An array of hidden fields to output at the end of the form
$mb_defaults array Metabox Defaults
$mb_object_type string Type of object registered for metabox. (e.g., post, user, or comment)
$meta_box array Metabox Config array
$object_id mixed Object ID for metabox meta retrieving/saving
$object_type string Type of object being saved. (e.g., post, user, or comment)
$updated array List of fields that are changed/updated on save

Открытые методы

Метод Описание
__construct ( array $meta_box, integer $object_id ) Get started
__get ( string $field ) : mixed Magic getter for our object.
add_field ( array $field, integer $position ) : mixed Add a field to the metabox
add_group_field ( string $parent_field_id, array $field, integer $position ) : mixed Add a field to a group
add_hidden_field ( array $field_args, $field_group = null ) Add a hidden field to the list of hidden fields to be rendered later
after_save ( )
box_classes ( ) : string Defines the classes for the CMB2 form/wrap.
current_object_type ( ) : string Get the object type for the current page, based on the $pagenow global.
get_field ( string | array | CMB2_Field $field, CMB2_Field $field_group = null ) : CMB2_Field | false Get a field object
get_field_args ( mixed $field_id, mixed $field_args, mixed $sub_field_id, mixed $field_group ) : array Handles determining which type of arguments to pass to CMB2_Field
get_field_ids ( string $field_id, string $parent_field_id = '' ) : mixed Check if field ids match a field and return the index/field id
get_sanitized_values ( array $data_to_sanitize ) Returns array of sanitized field values (without saving them)
is_options_page_mb ( ) : boolean Determines if metabox is for an options page
mb_object_type ( ) : string Sets the $object_type based on metabox settings
nonce ( ) : string Generate a unique nonce for each registered meta_box
nonce_field ( ) : string Generate a unique nonce field for each registered meta_box
object_id ( integer $object_id ) : integer Get object id from global space if no id is provided
object_type ( $object_type = '' ) : string Returns the object type
pre_process ( )
process_field ( array $field_args ) Process and save a field
process_fields ( ) Process and save form fields
prop ( string $property, mixed $fallback = null ) : mixed Get metabox property and optionally set a fallback
remove_field ( string $field_id, string $parent_field_id = '' ) : boolean Remove a field from the metabox
render_field ( array $field_args ) : mixed Renders a field based on the field type
render_form_close ( integer $object_id, string $object_type = '' ) : void Outputs the closing form markup and runs corresponding hooks: 'cmb2_after_form' and "cmb2_after_{$object_type}_form_{$this->cmb_id}"
render_form_open ( integer $object_id, string $object_type = '' ) : void Outputs the opening form markup and runs corresponding hooks: 'cmb2_before_form' and "cmb2_before_{$object_type}_form_{$this->cmb_id}"
render_group ( array $args ) : CMB2_Field | null Render a repeatable group.
render_group_row ( CMB2_Field $field_group, string $remove_disabled ) Render a repeatable group row
render_hidden_fields ( ) Loop through and output hidden fields
save_fields ( integer $object_id, string $object_type = '', array $data_to_save = [] ) Loops through and saves field data
save_group ( array $args ) : mixed Save a repeatable group
save_group_field ( array $field_group ) : mixed Save a repeatable group
search_old_school_array ( string $field_id, array $fields ) : mixed When using the old array filter, it is unlikely field array indexes will be the field id
set_prop ( string $property, mixed $value ) : mixed Set metabox property.
should_show ( ) : boolean Determine whether this cmb object should show, based on the 'show_on_cb' callback.
show_form ( integer $object_id, string $object_type = '' ) Loops through and displays fields
update_field_property ( string $field_id, string $property, mixed $value, string $parent_field_id = '' ) : mixed Update or add a property to a field

Защищенные методы

Метод Описание
_add_field_to_array ( array $field, &$fields, integer $position ) Add a field array to a fields array in desired position
add_fields ( array $fields, mixed $parent_field_id = null ) When fields are added in the old-school way, intitate them as they should be
get_default_args ( array $field_args, CMB2_Field $field_group = null ) : array Get default field arguments specific to this CMB2 object.
get_new_field ( array $field_args, CMB2_Field $field_group = null ) : CMB2_Field Get a new field object specific to this CMB2 object.

Описание методов

__construct() публичный Метод

Get started
С версии: 0.4.0
public __construct ( array $meta_box, integer $object_id )
$meta_box array Metabox config array
$object_id integer Optional object id

__get() публичный Метод

Magic getter for our object.
public __get ( string $field ) : mixed
$field string
Результат mixed

_add_field_to_array() защищенный Метод

Add a field array to a fields array in desired position
С версии: 2.0.2
protected _add_field_to_array ( array $field, &$fields, integer $position )
$field array Metabox field config array
$position integer Optionally specify a position in the array to be inserted

add_field() публичный Метод

Add a field to the metabox
С версии: 2.0.0
public add_field ( array $field, integer $position ) : mixed
$field array Metabox field config array
$position integer (optional) Position of metabox. 1 for first, etc
Результат mixed Field id or false

add_fields() защищенный Метод

When fields are added in the old-school way, intitate them as they should be
С версии: 2.1.0
protected add_fields ( array $fields, mixed $parent_field_id = null )
$fields array Array of fields to add
$parent_field_id mixed Parent field id or null

add_group_field() публичный Метод

Add a field to a group
С версии: 2.0.0
public add_group_field ( string $parent_field_id, array $field, integer $position ) : mixed
$parent_field_id string The field id of the group field to add the field
$field array Metabox field config array
$position integer (optional) Position of metabox. 1 for first, etc
Результат mixed Array of parent/field ids or false

add_hidden_field() публичный Метод

Add a hidden field to the list of hidden fields to be rendered later
С версии: 2.0.0
public add_hidden_field ( array $field_args, $field_group = null )
$field_args array Array of field arguments to be passed to CMB2_Field

after_save() публичный Метод

public after_save ( )

box_classes() публичный Метод

Defines the classes for the CMB2 form/wrap.
С версии: 2.0.0
public box_classes ( ) : string
Результат string Space concatenated list of classes

current_object_type() публичный Метод

Get the object type for the current page, based on the $pagenow global.
С версии: 2.2.2
public current_object_type ( ) : string
Результат string Page object type name.

get_default_args() защищенный Метод

Get default field arguments specific to this CMB2 object.
С версии: 2.2.0
protected get_default_args ( array $field_args, CMB2_Field $field_group = null ) : array
$field_args array Metabox field config array.
$field_group CMB2_Field (optional) CMB2_Field object (group parent)
Результат array Array of field arguments.

get_field() публичный Метод

Get a field object
С версии: 2.0.3
public get_field ( string | array | CMB2_Field $field, CMB2_Field $field_group = null ) : CMB2_Field | false
$field string | array | CMB2_Field Metabox field id or field config array or CMB2_Field object
$field_group CMB2_Field (optional) CMB2_Field object (group parent)
Результат CMB2_Field | false CMB2_Field object (or false)

get_field_args() публичный Метод

Handles determining which type of arguments to pass to CMB2_Field
С версии: 2.0.7
public get_field_args ( mixed $field_id, mixed $field_args, mixed $sub_field_id, mixed $field_group ) : array
$field_id mixed Field (or group field) ID
$field_args mixed Array of field arguments
$sub_field_id mixed Sub field ID (if field_group exists)
$field_group mixed If a sub-field, will be the parent group CMB2_Field object
Результат array Array of CMB2_Field arguments

get_field_ids() публичный Метод

Check if field ids match a field and return the index/field id
С версии: 2.0.2
public get_field_ids ( string $field_id, string $parent_field_id = '' ) : mixed
$field_id string Field id
$parent_field_id string (optional) Parent field id
Результат mixed Array of field/parent ids, or false

get_new_field() защищенный Метод

Get a new field object specific to this CMB2 object.
С версии: 2.2.0
protected get_new_field ( array $field_args, CMB2_Field $field_group = null ) : CMB2_Field
$field_args array Metabox field config array.
$field_group CMB2_Field (optional) CMB2_Field object (group parent)
Результат CMB2_Field CMB2_Field object

get_sanitized_values() публичный Метод

Returns array of sanitized field values (without saving them)
С версии: 2.0.3
public get_sanitized_values ( array $data_to_sanitize )
$data_to_sanitize array Array of field_id => value data for sanitizing (likely $_POST data).

is_options_page_mb() публичный Метод

Determines if metabox is for an options page
С версии: 1.0.1
public is_options_page_mb ( ) : boolean
Результат boolean True/False

mb_object_type() публичный Метод

Sets the $object_type based on metabox settings
С версии: 1.0.0
public mb_object_type ( ) : string
Результат string Object type

nonce() публичный Метод

Generate a unique nonce for each registered meta_box
С версии: 2.0.0
public nonce ( ) : string
Результат string unique nonce string

nonce_field() публичный Метод

Generate a unique nonce field for each registered meta_box
С версии: 2.0.0
public nonce_field ( ) : string
Результат string unique nonce hidden input

object_id() публичный Метод

Get object id from global space if no id is provided
С версии: 1.0.0
public object_id ( integer $object_id ) : integer
$object_id integer Object ID
Результат integer $object_id Object ID

object_type() публичный Метод

Returns the object type
С версии: 1.0.0
public object_type ( $object_type = '' ) : string
Результат string Object type

pre_process() публичный Метод

public pre_process ( )

process_field() публичный Метод

Process and save a field
С версии: 2.0.0
public process_field ( array $field_args )
$field_args array Array of field arguments

process_fields() публичный Метод

Process and save form fields
С версии: 2.0.0
public process_fields ( )

prop() публичный Метод

Get metabox property and optionally set a fallback
С версии: 2.0.0
public prop ( string $property, mixed $fallback = null ) : mixed
$property string Metabox config property to retrieve
$fallback mixed Fallback value to set if no value found
Результат mixed Metabox config property value or false

remove_field() публичный Метод

Remove a field from the metabox
С версии: 2.0.0
public remove_field ( string $field_id, string $parent_field_id = '' ) : boolean
$field_id string The field id of the field to remove
$parent_field_id string (optional) The field id of the group field to remove field from
Результат boolean True if field was removed

render_field() публичный Метод

Renders a field based on the field type
С версии: 2.2.0
public render_field ( array $field_args ) : mixed
$field_args array A field configuration array.
Результат mixed CMB2_Field object if successful.

render_form_close() публичный Метод

Outputs the closing form markup and runs corresponding hooks: 'cmb2_after_form' and "cmb2_after_{$object_type}_form_{$this->cmb_id}"
С версии: 2.2.0
public render_form_close ( integer $object_id, string $object_type = '' ) : void
$object_id integer Object ID
$object_type string Object type
Результат void

render_form_open() публичный Метод

Outputs the opening form markup and runs corresponding hooks: 'cmb2_before_form' and "cmb2_before_{$object_type}_form_{$this->cmb_id}"
С версии: 2.2.0
public render_form_open ( integer $object_id, string $object_type = '' ) : void
$object_id integer Object ID
$object_type string Object type
Результат void

render_group() публичный Метод

Render a repeatable group.
public render_group ( array $args ) : CMB2_Field | null
$args array Array of field arguments for a group field parent.
Результат CMB2_Field | null Group field object.

render_group_row() публичный Метод

Render a repeatable group row
С версии: 1.0.2
public render_group_row ( CMB2_Field $field_group, string $remove_disabled )
$field_group CMB2_Field CMB2_Field group field object
$remove_disabled string Attribute string to disable the remove button

render_hidden_fields() публичный Метод

Loop through and output hidden fields
С версии: 2.0.0

save_fields() публичный Метод

Loops through and saves field data
С версии: 1.0.0
public save_fields ( integer $object_id, string $object_type = '', array $data_to_save = [] )
$object_id integer Object ID
$object_type string Type of object being saved. (e.g., post, user, or comment)
$data_to_save array Array of key => value data for saving. Likely $_POST data.

save_group() публичный Метод

Save a repeatable group
С версии: 1.x.x
public save_group ( array $args ) : mixed
$args array Field arguments array
Результат mixed Return of CMB2_Field::update_data()

save_group_field() публичный Метод

Save a repeatable group
С версии: 1.x.x
public save_group_field ( array $field_group ) : mixed
$field_group array CMB2_Field group field object
Результат mixed Return of CMB2_Field::update_data()

search_old_school_array() публичный Метод

When using the old array filter, it is unlikely field array indexes will be the field id
С версии: 2.0.2
public search_old_school_array ( string $field_id, array $fields ) : mixed
$field_id string The field id
$fields array Array of fields to search
Результат mixed Field index or false

set_prop() публичный Метод

Set metabox property.
С версии: 2.2.2
public set_prop ( string $property, mixed $value ) : mixed
$property string Metabox config property to retrieve
$value mixed Value to set if no value found
Результат mixed Metabox config property value or false

should_show() публичный Метод

Determine whether this cmb object should show, based on the 'show_on_cb' callback.
С версии: 2.0.9
public should_show ( ) : boolean
Результат boolean Whether this cmb should be shown.

show_form() публичный Метод

Loops through and displays fields
С версии: 1.0.0
public show_form ( integer $object_id, string $object_type = '' )
$object_id integer Object ID
$object_type string Type of object being saved. (e.g., post, user, or comment)

update_field_property() публичный Метод

Update or add a property to a field
С версии: 2.0.0
public update_field_property ( string $field_id, string $property, mixed $value, string $parent_field_id = '' ) : mixed
$field_id string Field id
$property string Field property to set/update
$value mixed Value to set the field property
$parent_field_id string (optional) The field id of the group field to remove field from
Результат mixed Field id. Strict compare to false, as success can return a falsey value (like 0)

Описание свойств

$cmb_id защищенное свойство

Current CMB2 instance ID
С версии: 2.0.0
protected string $cmb_id
Результат string

$data_to_save публичное свойство

Array of key => value data for saving. Likely $_POST data.
С версии: 2.0.0
public array $data_to_save
Результат array

$fields защищенное свойство

Metabox field objects
С версии: 2.0.3
protected array $fields
Результат array

$generated_nonce защищенное свойство

Array of key => value data for saving. Likely $_POST data.
С версии: 2.0.0
protected string $generated_nonce
Результат string

$has_columns защищенное свойство

Whether there are fields to be shown in columns. Set in CMB2::add_field().
С версии: 2.2.2
protected bool $has_columns
Результат boolean

$hidden_fields защищенное свойство

An array of hidden fields to output at the end of the form
С версии: 2.0.0
protected array $hidden_fields
Результат array

$mb_defaults защищенное свойство

Metabox Defaults
С версии: 1.0.1
protected array $mb_defaults
Результат array

$mb_object_type защищенное свойство

Type of object registered for metabox. (e.g., post, user, or comment)
С версии: 1.0.0
protected string $mb_object_type
Результат string

$meta_box защищенное свойство

Metabox Config array
С версии: 0.9.0
protected array $meta_box
Результат array

$object_id защищенное свойство

Object ID for metabox meta retrieving/saving
С версии: 1.0.0
protected mixed $object_id
Результат mixed

$object_type защищенное свойство

Type of object being saved. (e.g., post, user, or comment)
С версии: 1.0.0
protected string $object_type
Результат string

$updated защищенное свойство

List of fields that are changed/updated on save
С версии: 1.1.0
protected array $updated
Результат array