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_Field

CMB2 field objects

CMB2_Base
Extended by CMB2_Field
Package: CMB2
Category: WordPress_Plugin
License: GPL-2.0+
Author: CMB2 team
Since: 1.1.0
Link: https://cmb2.io
Located at includes/CMB2_Field.php

Methods summary

public
# __construct( array $args )

Constructs our field object

Constructs our field object

Parameters

$args
Field arguments.

Since

1.1.0

Overrides

CMB2_Base::__construct
public mixed
# __call( string $name, array $arguments )

Non-existent methods fallback to checking for field arguments of the same name

Non-existent methods fallback to checking for field arguments of the same name

Parameters

$name
Method name.
$arguments
Array of passed-in arguments.

Returns

mixed
Value of field argument

Throws

Exception
Invalid method exception.

Since

1.1.0

Overrides

CMB2_Base::__call
public string
# id( boolean $raw = false )

Retrieves the field id

Retrieves the field id

Parameters

$raw
Whether to retrieve pre-modidifed id.

Returns

string
Field id

Since

1.1.0
public mixed
# args( string $key = '', string $_key = '' )

Get a field argument

Get a field argument

Parameters

$key
Argument to check.
$_key
Sub argument to check.

Returns

mixed
Argument value or false if non-existent

Since

1.1.0
public mixed
# _data( string $var, string $key = '' )

Retrieve a portion of a field property

Retrieve a portion of a field property

Parameters

$var
Field property to check.
$key
Field property array key to check.

Returns

mixed
Queried property value or false

Since

1.1.0
public mixed
# value( string $key = '' )

Get Field's value

Get Field's value

Parameters

$key
If value is an array, is used to get array key->value.

Returns

mixed
Field value or false if non-existent

Since

1.1.0
public mixed
# get_data( string $field_id = '', array $args = array() )

Retrieves metadata/option data

Retrieves metadata/option data

Parameters

$field_id
Meta key/Option array key.
$args
Override arguments.

Returns

mixed
Meta/Option value

Since

1.0.1
public mixed
# update_data( mixed $new_value, boolean $single = true )

Updates metadata/option data.

Updates metadata/option data.

Parameters

$new_value
Value to update data with.
$single
Whether data is an array (add_metadata).

Returns

mixed

Since

1.0.1
public mixed
# remove_data( string $old = '' )

Removes/updates metadata/option data.

Removes/updates metadata/option data.

Parameters

$old
Old value.

Returns

mixed

Since

1.0.1
public array
# data_args( array $args = array() )

Data variables for get/set data methods

Data variables for get/set data methods

Parameters

$args
Override arguments.

Returns

array
Updated arguments

Since

1.1.0
public mixed
# sanitization_cb( mixed $meta_value )

Checks if field has a registered sanitization callback

Checks if field has a registered sanitization callback

Parameters

$meta_value
Meta value.

Returns

mixed
Possibly sanitized meta value

Since

1.0.1
public array|integer|boolean
# save_field_from_data( array $data_to_save )

Process $_POST data to save this field's value

Process $_POST data to save this field's value

Parameters

$data_to_save
$_POST data to check.

Returns

array|integer|boolean
Result of save, false on failure

Since

2.0.3
public array|integer|boolean
# save_field( array $meta_value )

Sanitize/store a value to this field

Sanitize/store a value to this field

Parameters

$meta_value
Desired value to sanitize/store.

Returns

array|integer|boolean
Result of save. false on failure

Since

2.0.0
public boolean
# escaping_exception( )

Determine if current type is exempt from escaping

Determine if current type is exempt from escaping

Returns

boolean
True if exempt

Since

1.1.0
public boolean
# repeatable_exception( string $type )

Determine if current type cannot be repeatable

Determine if current type cannot be repeatable

Parameters

$type
Field type to check.

Returns

boolean
True if type cannot be repeatable

Since

1.1.0
public boolean
# has_args_method( string $type )

Determine if current type has its own defaults field-arguments method.

Determine if current type has its own defaults field-arguments method.

Parameters

$type
Field type to check.

Returns

boolean
True if has own method.

Since

2.2.6
public mixed
# escaped_value( callable|string $func = 'esc_attr', mixed $meta_value = '' )

Escape the value before output. Defaults to 'esc_attr()'

Escape the value before output. Defaults to 'esc_attr()'

Parameters

$func
Escaping function (if not esc_attr()).
$meta_value
Meta value.

Returns

mixed
Final value.

Since

1.0.1
public mixed
# val_or_default( mixed $meta_value )

Return non-empty value or field default if value IS empty

Return non-empty value or field default if value IS empty

Parameters

$meta_value
Field value.

Returns

mixed
Field value, or default value

Since

2.0.0
public string
# field_timezone_offset( )

Offset a time value based on timezone

Offset a time value based on timezone

Returns

string
Offset time string

Since

1.0.0
public string
# field_timezone( )

Return timezone string

Return timezone string

Returns

string
Timezone string

Since

1.0.0
public string
# format_timestamp( integer $meta_value, string $format = 'date_format' )

Format the timestamp field value based on the field date/time format arg

Format the timestamp field value based on the field date/time format arg

Parameters

$meta_value
Timestamp.
$format
Either date_format or time_format.

Returns

string
Formatted date

Since

2.0.0
public string
# get_timestamp_format( string $format = 'date_format', string|integer $meta_value = 0 )

Return a formatted timestamp for a field

Return a formatted timestamp for a field

Parameters

$format
Either date_format or time_format.
$meta_value
Optional meta value to check.

Returns

string
Formatted date

Since

2.0.0
public mixed
# get_timestamp_from_value( string $value )

Get timestamp from text date

Get timestamp from text date

Parameters

$value
Date value.

Returns

mixed
Unix timestamp representing the date.

Since

2.2.0
public
# render_field( )

Get field render callback and Render the field row

Get field render callback and Render the field row

Since

1.0.0
public
# render_field_callback( )

Default field render callback

Default field render callback

Since

2.1.1
public string
# label( )

The default label_cb callback (if not a title field)

The default label_cb callback (if not a title field)

Returns

string
Label html markup.

Since

2.1.1
public string
# row_classes( )

Defines the classes for the current CMB2 field row

Defines the classes for the current CMB2 field row

Returns

string
Space concatenated list of classes

Since

2.0.0
public
# render_column( )

Get field display callback and render the display value in the column.

Get field display callback and render the display value in the column.

Since

2.2.2
public
# get_rest_value( )

The method to fetch the value for this field for the REST API.

The method to fetch the value for this field for the REST API.

Since

2.5.0
public CMB2_Field|boolean
# get_supporting_field( )

Get a field object for a supporting field. (e.g. file field)

Get a field object for a supporting field. (e.g. file field)

Returns

CMB2_Field|boolean
Supporting field object, if supported.

Since

2.7.0
public
# display_value_callback( )

Default callback to outputs field value in a display format.

Default callback to outputs field value in a display format.

Since

2.2.2
public string
# replace_hash( string $value )

Replaces a hash key - {#} - with the repeatable index

Replaces a hash key - {#} - with the repeatable index

Parameters

$value
Value to update.

Returns

string
Updated value

Since

1.2.0
public string
# get_string( string $text_key, string $fallback )

Retrieve text parameter from field's text array (if it has one), or use fallback text For back-compatibility, falls back to checking the options array.

Retrieve text parameter from field's text array (if it has one), or use fallback text For back-compatibility, falls back to checking the options array.

Parameters

$text_key
Key in field's text array.
$fallback
Fallback text.

Returns

string
Text

Since

2.2.2
public array|mixed
# options( string $key = '' )

Retrieve options args.

Retrieve options args.

Parameters

$key
Specific option to retrieve.

Returns

array|mixed
Array of options or specific option.

Since

2.0.0
public array
# set_options( )

Generates/sets options args. Calls options_cb if it exists.

Generates/sets options args. Calls options_cb if it exists.

Returns

array
Array of options

Since

2.2.5
public
# add_js_dependencies( array $dependencies = array() )

Store JS dependencies as part of the field args.

Store JS dependencies as part of the field args.

Parameters

$dependencies
Dependies to register for this field.

Since

2.2.0
public
# register_js_data( )

Send field data to JS.

Send field data to JS.

Since

2.2.0
public array
# js_data( )

Get an array of some of the field data to be used in the Javascript.

Get an array of some of the field data to be used in the Javascript.

Returns

array

Since

2.2.4
public string
# hash_id( )

Returns a unique hash representing this field.

Returns a unique hash representing this field.

Returns

string

Since

2.2.4
public string
# group_id( )

Gets the id of the group field if this field is part of a group.

Gets the id of the group field if this field is part of a group.

Returns

string

Since

2.2.4
public mixed
# get_default( )

Get CMB2_Field default value, either from default param or default_cb param.

Get CMB2_Field default value, either from default param or default_cb param.

Returns

mixed
Default field value

Since

0.2.2
public array
# _set_field_defaults( array $args )

Fills in empty field parameters with defaults

Fills in empty field parameters with defaults

Parameters

$args
Field config array.

Returns

array
Modified field config array.

Since

1.1.0
protected array
# set_field_defaults_group( array $args )

Sets default arguments for the group field types.

Sets default arguments for the group field types.

Parameters

$args
Field config array.

Returns

array
Modified field config array.

Since

2.2.6
protected array
# set_field_defaults_wysiwyg( array $args )

Sets default arguments for the wysiwyg field types.

Sets default arguments for the wysiwyg field types.

Parameters

$args
Field config array.

Returns

array
Modified field config array.

Since

2.2.6
protected array
# set_field_defaults_all_or_nothing_types( array $args )

Sets default arguments for the all-or-nothing field types.

Sets default arguments for the all-or-nothing field types.

Parameters

$args
Field config array.

Returns

array
Modified field config array.

Since

2.2.6
protected array
# set_group_sub_field_defaults( array $args )

Sets default arguments for group sub-fields.

Sets default arguments for group sub-fields.

Parameters

$args
Field config array.

Returns

array
Modified field config array.

Since

2.2.6
protected array
# get_default_field_args( array $args )

Gets the default arguments for all fields.

Gets the default arguments for all fields.

Parameters

$args
Field config array.

Returns

array
Field defaults.

Since

2.2.6
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

Overrides

CMB2_Base::get_default_args
public CMB2_Field
# get_field_clone( array $field_args )

Returns a cloned version of this field object, but with modified/overridden field arguments.

Returns a cloned version of this field object, but with modified/overridden field arguments.

Parameters

$field_args

Array of field arguments, or entire array of arguments for CMB2_Field.

Returns

CMB2_Field
The new CMB2_Field instance.

Since

2.2.2
public CMB2|WP_Error
# get_cmb( )

Returns the CMB2 instance this field is registered to.

Returns the CMB2 instance this field is registered to.

Returns

CMB2|WP_Error
If new CMB2_Field is called without cmb_id arg, returns error.

Since

2.2.2
protected array
# convert_deprecated_params( array $args )

Converts deprecated field parameters to the current/proper parameter, and throws a deprecation notice.

Converts deprecated field parameters to the current/proper parameter, and throws a deprecation notice.

Parameters

$args
Metabox field config array.

Returns

array
Modified field config array.

Since

2.2.3

Methods inherited from CMB2_Base

__get(), current_object_type(), deprecated_param(), do_callback(), get_new_field(), get_param_callback_result(), maybe_callback(), maybe_hook(), maybe_hook_parameter(), object_id(), object_type(), peform_param_callback(), prop(), set_prop(), should_show(), unset_param_callback_cache()

Magic methods summary

public string
# _id( )

Returns

string
public string
# type( )

Returns

string
public mixed
# fields( )

Returns

mixed

Constants summary

Constants inherited from CMB2_Base

DEPRECATED_CB_PARAM, DEPRECATED_PARAM

Properties summary

protected string $properties_name

The object properties name.

The object properties name.

Since

2.2.3
# 'args'
public mixed $args

Field arguments

Field arguments

Since

1.1.0
# array()
public mixed $group

Field group object or false (if no group)

Field group object or false (if no group)

Since

1.1.0
# false
public mixed $value

Field meta value

Field meta value

Since

1.1.0
# null
public mixed $escaped_value

Field meta value

Field meta value

Since

1.1.0
# null
public mixed $index

Grouped Field's current numeric index during the save process

Grouped Field's current numeric index during the save process

Since

2.0.0
# 0
protected array $field_options

Array of field options

Array of field options

Since

2.0.0
# array()
protected array $strings

Array of provided field text strings

Array of provided field text strings

Since

2.0.0
#
public string $render_context

The field's render context. In most cases, 'edit', but can be 'display'.

The field's render context. In most cases, 'edit', but can be 'display'.

Since

2.2.2
# 'edit'
public static array $callable_fields

All CMB2_Field callable field arguments. Can be used to determine if a field argument is callable.

All CMB2_Field callable field arguments. Can be used to determine if a field argument is callable.

# array( 'default_cb', 'classes_cb', 'options_cb', 'text_cb', 'label_cb', 'render_row_cb', 'display_cb', 'before_group', 'before_group_row', 'before_row', 'before', 'before_field', 'after_field', 'after', 'after_row', 'after_group_row', 'after_group', )
protected string $hash_id

Represents a unique hash representing this field.

Represents a unique hash representing this field.

Since

2.2.4
# ''

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

CMB2 Documentation API documentation generated by ApiGen