Class CMB2
The main CMB2 object for storing box data/properties.
- CMB2_Base
- CMB2
Direct known subclasses
Methods summary
public
|
|
public
|
|
public
|
#
render_form_open( integer $object_id = 0, string $object_type = '' )
Outputs the opening form markup and runs corresponding hooks: 'cmb2_before_form' and "cmb2_before_{$object_type}form{$this->cmb_id}" |
public
string
|
|
public
|
#
render_form_close( integer $object_id = 0, string $object_type = '' )
Outputs the closing form markup and runs corresponding hooks: 'cmb2_after_form' and "cmb2_after_{$object_type}form{$this->cmb_id}" |
public
mixed
|
|
public
|
|
public
|
#
render_group_callback( array $field_args,
The default callback to render a group of fields. |
public
string
|
#
group_wrap_attributes(
Get the group wrap attributes, which are passed through a filter. |
public
|
|
public
mixed
|
#
get_sanitized_values( array $data_to_sanitize )
Returns array of sanitized field values (without saving them) |
public
|
#
save_fields( integer $object_id = 0, string $object_type = '', array $data_to_save = array() )
Loops through and saves field data |
public
|
|
public
|
|
public
|
|
public
|
#
after_save( )
Fires the "cmb2_save_{$object_type}fields" and "cmb2_save{$object_type}fields{$cmb_id}" action hooks. |
public
mixed
|
|
public
mixed
|
|
public
integer|string
|
|
public
string
|
|
public
array
|
|
public
boolean
|
#
is_box_type( string|array $object_types = array(), array $fallback = array() )
Check if given object_type(s) matches any of the registered object types or taxonomies for this box. |
public
|
|
protected
array
|
#
deinit_options_mb( array $types )
If object-page initiation failed, remove traces options page setup. |
public
boolean
|
|
public
boolean
|
|
public
boolean
|
|
public
string|array
|
|
public
string
|
|
public
string
|
|
public
mixed
|
|
public
mixed
|
|
public
|
#
get_field( string|array|
Get a field object |
public
array
|
#
get_field_args( mixed $field_id, mixed $field_args, mixed $sub_field_id,
Handles determining which type of arguments to pass to CMB2_Field |
protected
array
|
#
get_default_args( array $field_args,
Get default field arguments specific to this CMB2 object. |
protected
|
#
add_fields( array $fields, mixed $parent_field_id = null )
When fields are added in the old-school way, intitate them as they should be |
public
string|false
|
|
public
mixed
|
#
add_group_field( string $parent_field_id, array $field, integer $position = 0 )
Add a field to a group |
protected
|
|
protected
array
|
#
define_field_column( array $field )
Defines a field's column if requesting to be show in admin columns. |
protected
|
#
_add_field_to_array( array $field, array & $fields, integer $position = 0 )
Add a field array to a fields array in desired position |
public
boolean
|
|
public
mixed
|
#
update_field_property( string $field_id, string $property, mixed $value, string $parent_field_id = '' )
Update or add a property to a field |
public
mixed
|
#
get_field_ids( string $field_id, string $parent_field_id = '' )
Check if field ids match a field and return the index/field id |
public
mixed
|
#
search_old_school_array( string $field_id, array $fields )
When using the old array filter, it is unlikely field array indexes will be the field id. |
public
mixed
|
#
do_callback( callable $cb, mixed $additional_params = null )
Handles metabox property callbacks, and passes this $cmb object as property. |
public
|
|
public
string
|
|
public
boolean
|
|
public
boolean
|
#
is_alternate_context_box( )
Whether this box is an "alternate context" box. This means the box has a 'context' property defined as: 'form_top', 'before_permalink', 'after_title', or 'after_editor'. |
public
mixed
|
Methods inherited from CMB2_Base
__call()
,
deprecated_param()
,
get_new_field()
,
get_param_callback_result()
,
maybe_callback()
,
maybe_hook()
,
maybe_hook_parameter()
,
peform_param_callback()
,
should_show()
,
unset_param_callback_cache()
Constants summary
Constants inherited from CMB2_Base
Properties summary
protected
string
|
$properties_name
The object properties name. |
#
'meta_box'
|
protected
array
|
$meta_box
Metabox Config array |
#
array()
|
protected
string
|
$mb_object_type
Type of object registered for metabox. (e.g., post, user, or comment) |
#
null
|
protected
array
|
$updated
List of fields that are changed/updated on save |
#
array()
|
protected
array
|
$mb_defaults
Metabox Defaults |
#
array(
'id' => '',
'title' => '',
// Post type slug, or 'user', 'term', 'comment', or 'options-page'.
'object_types' => array(),
/**
* The context within the screen where the boxes should display. Available contexts vary
* from screen to screen. Post edit screen contexts include 'normal', 'side', and 'advanced'.
*
* For placement in locations outside of a metabox, other options include:
* 'form_top', 'before_permalink', 'after_title', 'after_editor'
*
* Comments screen contexts include 'normal' and 'side'. Default is 'normal'.
*/
'context' => 'normal',
'priority' => 'high', // Or 10 for options pages.
'show_names' => true, // Show field names on the left.
'show_on_cb' => null, // Callback to determine if metabox should display.
'show_on' => array(), // Post IDs or page templates to display this metabox. overrides 'show_on_cb'.
'cmb_styles' => true, // Include CMB2 stylesheet.
'enqueue_js' => true, // Include CMB2 JS.
'fields' => array(),
/**
* Handles hooking CMB2 forms/metaboxes into the post/attachement/user/options-page screens
* and handles hooking in and saving those fields.
*/
'hookup' => true,
'save_fields' => true, // Will not save during hookup if false.
'closed' => false, // Default metabox to being closed.
'taxonomies' => array(),
'new_user_section' => 'add-new-user', // or 'add-existing-user'.
'new_term_section' => true,
'show_in_rest' => false,
'classes' => null, // Optionally add classes to the CMB2 wrapper.
'classes_cb' => '', // Optionally add classes to the CMB2 wrapper (via a callback).
/*
* The following parameter is for post alternate-context metaboxes only.
*
* To output the fields 'naked' (without a postbox wrapper/style), then
* add a `'remove_box_wrap' => true` to your metabox registration array.
*/
'remove_box_wrap' => false,
/*
* The following parameter is any additional arguments passed as $callback_args
* to add_meta_box, if/when applicable.
*
* CMB2 does not use these arguments in the add_meta_box callback, however, these args
* are parsed for certain special properties, like determining Gutenberg/block-editor
* compatibility.
*
* Examples:
*
* - Make sure default editor is used as metabox is not compatible with block editor
* [ '__block_editor_compatible_meta_box' => false/true ]
*
* - Or declare this box exists for backwards compatibility
* [ '__back_compat_meta_box' => false ]
*
* More: https://wordpress.org/gutenberg/handbook/extensibility/meta-box/
*/
'mb_callback_args' => null,
/*
* The following parameters are for options-page metaboxes,
* and several are passed along to add_menu_page()/add_submenu_page()
*/
// 'menu_title' => null, // Falls back to 'title' (above). Do not define here so we can set a fallback.
'message_cb' => '', // Optionally define the options-save message (via a callback).
'option_key' => '', // The actual option key and admin menu page slug.
'parent_slug' => '', // Used as first param in add_submenu_page().
'capability' => 'manage_options', // Cap required to view options-page.
'icon_url' => '', // Menu icon. Only applicable if 'parent_slug' is left empty.
'position' => null, // Menu position. Only applicable if 'parent_slug' is left empty.
'admin_menu_hook' => 'admin_menu', // Alternately 'network_admin_menu' to add network-level options page.
'display_cb' => false, // Override the options-page form output (CMB2_Hookup::options_page_output()).
'save_button' => '', // The text for the options-page save button. Defaults to 'Save'.
'disable_settings_errors' => false, // On settings pages (not options-general.php sub-pages), allows disabling.
'tab_group' => '', // Tab-group identifier, enables options page tab navigation.
// 'tab_title' => null, // Falls back to 'title' (above). Do not define here so we can set a fallback.
// 'autoload' => true, // Defaults to true, the options-page option will be autloaded.
)
|
protected
array
|
$fields
Metabox field objects |
#
array()
|
protected
string
|
$generated_nonce
Array of key => value data for saving. Likely $_POST data. |
#
''
|
protected
boolean
|
$has_columns
Whether there are fields to be shown in columns. Set in CMB2::add_field(). |
#
false
|
protected
array
|
$tax_metaboxes_to_remove
If taxonomy field is requesting to remove_default, we store the taxonomy here. |
#
array()
|
Properties inherited from CMB2_Base
$callback_results
,
$cmb_id
,
$data_to_save
,
$object_id
,
$object_type
Magic properties inherited from CMB2_Base
$args
,
$cmb_id
,
$meta_box
,
$object_id
,
$object_type
,
$properties