CMB2 Documentation
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  • Hooks
  • Download Docs
  • Github

Packages

  • CMB2
  • Demo
    • CMB2
  • None
  • Tests
    • CMB2

Classes

  • CMB2
  • CMB2_Ajax
  • CMB2_Base
  • CMB2_Bootstrap_2101
  • CMB2_Boxes
  • CMB2_Display_Checkbox
  • CMB2_Display_Colorpicker
  • CMB2_Display_File
  • CMB2_Display_File_List
  • CMB2_Display_Multicheck
  • CMB2_Display_oEmbed
  • CMB2_Display_Select
  • CMB2_Display_Taxonomy_Multicheck
  • CMB2_Display_Taxonomy_Radio
  • CMB2_Display_Text_Date
  • CMB2_Display_Text_Date_Timezone
  • CMB2_Display_Text_Money
  • CMB2_Display_Text_Time
  • CMB2_Display_Text_Url
  • CMB2_Display_Textarea
  • CMB2_Display_Textarea_Code
  • CMB2_Field
  • CMB2_Field_Display
  • CMB2_Hookup
  • CMB2_Hookup_Base
  • CMB2_JS
  • CMB2_Option
  • CMB2_Options
  • CMB2_Options_Hookup
  • CMB2_REST
  • CMB2_REST_Controller
  • CMB2_REST_Controller_Boxes
  • CMB2_REST_Controller_Fields
  • CMB2_Sanitize
  • CMB2_Show_Filters
  • CMB2_Type_Base
  • CMB2_Type_Checkbox
  • CMB2_Type_Colorpicker
  • CMB2_Type_Counter_Base
  • CMB2_Type_File
  • CMB2_Type_File_Base
  • CMB2_Type_File_List
  • CMB2_Type_Multi_Base
  • CMB2_Type_Multicheck
  • CMB2_Type_Oembed
  • CMB2_Type_Picker_Base
  • CMB2_Type_Radio
  • CMB2_Type_Select
  • CMB2_Type_Select_Timezone
  • CMB2_Type_Taxonomy_Base
  • CMB2_Type_Taxonomy_Multicheck
  • CMB2_Type_Taxonomy_Multicheck_Hierarchical
  • CMB2_Type_Taxonomy_Radio
  • CMB2_Type_Taxonomy_Radio_Hierarchical
  • CMB2_Type_Taxonomy_Select
  • CMB2_Type_Taxonomy_Select_Hierarchical
  • CMB2_Type_Text
  • CMB2_Type_Text_Date
  • CMB2_Type_Text_Datetime_Timestamp
  • CMB2_Type_Text_Datetime_Timestamp_Timezone
  • CMB2_Type_Text_Time
  • CMB2_Type_Textarea
  • CMB2_Type_Textarea_Code
  • CMB2_Type_Title
  • CMB2_Type_Wysiwyg
  • CMB2_Types
  • CMB2_Utils
  • Test_CMB2_Utils_WIN

Functions

  • _tests_cmb2_manually_load_plugin
  • cmb2_ajax
  • cmb2_autoload_classes
  • cmb2_bootstrap
  • cmb2_dir
  • cmb2_do_oembed
  • cmb2_get_field
  • cmb2_get_field_value
  • cmb2_get_metabox
  • cmb2_get_metabox_form
  • cmb2_get_metabox_sanitized_values
  • cmb2_get_oembed
  • cmb2_get_option
  • cmb2_metabox_form
  • cmb2_options
  • cmb2_print_metabox_form
  • cmb2_update_option
  • cmb2_utils
  • date_create_from_format
  • date_timestamp_get
  • new_cmb2_box

Hooks

  • Hook Reference

Class CMB2_Base

CMB2 Base - Base object functionality.

Direct known subclasses

CMB2, CMB2_Field

Indirect known subclasses

Test_CMB2_Object

Abstract
Package: CMB2
Category: WordPress_Plugin
License: GPL-2.0+
Author: CMB2 team
Link: https://cmb2.io
Located at includes/CMB2_Base.php

Methods summary

public
# __construct( array $args = array() )

Get started

Get started

Parameters

$args
Object properties array.

Since

2.2.3
public integer
# object_id( integer $object_id = 0 )

Returns the object ID

Returns the object ID

Parameters

$object_id
Object ID.

Returns

integer
Object ID

Since

2.2.3
public string
# object_type( string $object_type = '' )

Returns the object type

Returns the object type

Parameters

$object_type
Object Type.

Returns

string
Object type

Since

2.2.3
public string
# current_object_type( )

Get the object type for the current page, based on the $pagenow global.

Get the object type for the current page, based on the $pagenow global.

Returns

string
Page object type name.

Since

2.2.2
public mixed
# set_prop( string $property, mixed $value )

Set object property.

Set object property.

Parameters

$property
Metabox config property to retrieve.
$value
Value to set if no value found.

Returns

mixed
Metabox config property value or false.

Since

2.2.2
public mixed
# prop( string $property, mixed $fallback = null )

Get object property and optionally set a fallback

Get object property and optionally set a fallback

Parameters

$property
Metabox config property to retrieve.
$fallback
Fallback value to set if no value found.

Returns

mixed
Metabox config property value or false

Since

2.0.0
protected array
# get_default_args( array $field_args, CMB2_Field $field_group = null )

Get default field arguments specific to this CMB2 object.

Get default field arguments specific to this CMB2 object.

Parameters

$field_args
Metabox field config array.
$field_group
(optional) CMB2_Field object (group parent).

Returns

array
Array of field arguments.

Since

2.2.0
protected CMB2_Field
# get_new_field( array $field_args, CMB2_Field $field_group = null )

Get a new field object specific to this CMB2 object.

Get a new field object specific to this CMB2 object.

Parameters

$field_args
Metabox field config array.
$field_group
(optional) CMB2_Field object (group parent).

Returns

CMB2_Field
CMB2_Field object

Since

2.2.0
public boolean
# should_show( )

Determine whether this cmb object should show, based on the 'show_on_cb' callback.

Determine whether this cmb object should show, based on the 'show_on_cb' callback.

Returns

boolean
Whether this cmb should be shown.

Since

2.0.9
public
# peform_param_callback( string $param )

Displays the results of the param callbacks.

Displays the results of the param callbacks.

Parameters

$param
Field parameter.

Since

2.0.0
public mixed
# get_param_callback_result( string $param )

Store results of the param callbacks for continual access

Store results of the param callbacks for continual access

Parameters

$param
Field parameter.

Returns

mixed
Results of param/param callback

Since

2.0.0
public CMB2_Base
# unset_param_callback_cache( string $param )

Unset the cached results of the param callback.

Unset the cached results of the param callback.

Parameters

$param
Field parameter.

Returns

CMB2_Base

Since

2.2.6
protected mixed
# do_callback( callable $cb, mixed $additional_params = null )

Handles the parameter callbacks, and passes this object as parameter.

Handles the parameter callbacks, and passes this object as parameter.

Parameters

$cb
The callback method/function/closure.
$additional_params
Any additoinal parameters which should be passed to the callback.

Returns

mixed
Return of the callback function.

Since

2.2.3
public mixed
# maybe_callback( string $cb )

Checks if field has a callback value

Checks if field has a callback value

Parameters

$cb
Callback string.

Returns

mixed
NULL, false for NO validation, or $cb string if it exists.

Since

1.0.1
public null|boolean
# maybe_hook_parameter( string $hook_name, boolean $val = null, string $hook_function = 'add_filter' )

Checks if this object has parameter corresponding to the given filter which is callable. If so, it registers the callback, and if not, converts the maybe-modified $val to a boolean for return.

Checks if this object has parameter corresponding to the given filter which is callable. If so, it registers the callback, and if not, converts the maybe-modified $val to a boolean for return.

The registered handlers will have a parameter name which matches the filter, except: - The 'cmb2_api' prefix will be removed - A '_cb' suffix will be added (to stay inline with other '*_cb' parameters).

Parameters

$hook_name
The hook name.
$val
The default value.
$hook_function
The hook function. Default: 'add_filter'.

Returns

null|boolean
Null if hook is registered, or bool for value.

Since

2.2.3
public static null|boolean
# maybe_hook( boolean $val, string $hook_name, string $hook_function )

Checks if given value is callable, and registers the callback. If is non-callable, converts the $val to a boolean for return.

Checks if given value is callable, and registers the callback. If is non-callable, converts the $val to a boolean for return.

Parameters

$val
The default value.
$hook_name
The hook name.
$hook_function
The hook function.

Returns

null|boolean
Null if hook is registered, or bool for value.

Since

2.2.3
protected
# deprecated_param( string $function, string $version, string $message = null )

Mark a param as deprecated and inform when it has been used.

Mark a param as deprecated and inform when it has been used.

There is a default WordPress hook deprecated_argument_run that will be called that can be used to get the backtrace up to what file and function used the deprecated argument.

The current behavior is to trigger a user error if WP_DEBUG is true.

Parameters

$function
The function that was called.
$version
The version of CMB2 that deprecated the argument used.
$message

Optional. A message regarding the change, or numeric key to generate message from additional arguments. Default null.

Since

2.2.3
public mixed
# __get( string $field )

Magic getter for our object.

Magic getter for our object.

Parameters

$field
Requested property.

Returns

mixed

Throws

Exception
Throws an exception if the field is invalid.
public mixed
# __call( string $method, array $args )

Allows overloading the object with methods... Whooaaa oooh it's magic, y'knoooow.

Allows overloading the object with methods... Whooaaa oooh it's magic, y'knoooow.

Parameters

$method
Non-existent method.
$args
All arguments passed to the method.

Returns

mixed

Throws

Exception
Invalid method exception.

Since

1.0.0

Constants summary

integer DEPRECATED_PARAM

The deprecated_param method deprecated param message signature.

The deprecated_param method deprecated param message signature.

# 1
integer DEPRECATED_CB_PARAM

The deprecated_param method deprecated callback param message signature.

The deprecated_param method deprecated callback param message signature.

# 2

Properties summary

protected string $cmb_id

Current CMB2 instance ID

Current CMB2 instance ID

Since

2.2.3
# ''
protected string $properties_name

The object properties name.

The object properties name.

Since

2.2.3
# 'meta_box'
protected mixed $object_id

Object ID

Object ID

Since

2.2.3
# 0
protected string $object_type

Type of object being handled. (e.g., post, user, comment, or term)

Type of object being handled. (e.g., post, user, comment, or term)

Since

2.2.3
# ''
public array $data_to_save

Array of key => value data for saving. Likely $_POST data.

Array of key => value data for saving. Likely $_POST data.

Since

2.2.3
# array()
protected array $callback_results

Array of field param callback results

Array of field param callback results

Since

2.0.0
# array()

Magic properties

public read-only $args

The objects array of properties/arguments.

public read-only $meta_box

The objects array of properties/arguments.

public read-only $properties

The objects array of properties/arguments.

public read-only $cmb_id

Current CMB2 instance ID

public read-only $object_id

Object ID

public read-only $object_type

Type of object being handled. (e.g., post, user, comment, or term)

CMB2 Documentation API documentation generated by ApiGen