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_REST_Controller

Creates CMB2 objects/fields endpoint for WordPres REST API. Allows access to fields registered to a specific post type and more.

WP_REST_Controller
Extended by CMB2_REST_Controller

Direct known subclasses

CMB2_REST_Controller_Boxes

Indirect known subclasses

CMB2_REST_Controller_Fields

Abstract
Package: CMB2
Category: WordPress_Plugin
License: GPL-2.0+
Author: CMB2 team
Since: 2.2.3
Link: https://cmb2.io
Todo: Add better documentation.
Todo: Research proper schema.
Located at includes/rest-api/CMB2_REST_Controller.php

Methods summary

public
# __construct( WP_REST_Server $wp_rest_server )

Constructor

Constructor

Since

2.2.3
public
# maybe_hook_callback_and_apply_filters( string $filter, boolean $default_access )

A wrapper for apply_filters which checks for box/field properties to hook to the filter.

A wrapper for apply_filters which checks for box/field properties to hook to the filter.

Checks if a CMB object callback property exists, and if it does, hook it to the permissions filter.

Parameters

$filter
The name of the filter to apply.
$default_access
The default access for this request.

Since

2.2.3
public boolean
# maybe_hook_registered_callback( string $filter, boolean $default_val )

Checks if the CMB2 box has any registered callback parameters for the given filter.

Checks if the CMB2 box has any registered callback parameters for the given filter.

The registered handlers will have a property 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

$filter
The filter name.
$default_val
The default filter value.

Returns

boolean
The possibly-modified filter value (if the '*_cb' param is non-callable).

Since

2.2.3
public
# maybe_unhook_registered_callback( string $filter )

Unhooks any CMB2 box registered callback parameters for the given filter.

Unhooks any CMB2 box registered callback parameters for the given filter.

Parameters

$filter
The filter name.

Since

2.2.3
public array
# prepare_item( mixed $data )

Prepare a CMB2 object for serialization

Prepare a CMB2 object for serialization

Parameters

$data

Returns

array
$data

Since

2.2.3
public mixed
# get_cb_results( mixed $cb )

Output buffers a callback and returns the results.

Output buffers a callback and returns the results.

Parameters

$cb
Callable function/method.

Returns

mixed
Results of output buffer after calling function/method.

Since

2.2.3
public WP_REST_Response
# prepare_item_for_response( mixed $data, WP_REST_Request $request = null )

Prepare the CMB2 item for the REST response.

Prepare the CMB2 item for the REST response.

Parameters

$data
$item WordPress representation of the item.
$request
Request object.

Returns

WP_REST_Response
$response

Since

2.2.3

Overrides

WP_REST_Controller::prepare_item_for_response
protected
# initiate_rest_read_box( WP_REST_Request $request, string $request_type )

Initiates the request property and the rest_box property if box is readable.

Initiates the request property and the rest_box property if box is readable.

Parameters

$request
Request object.
$request_type
A description of the type of request being made.

Since

2.2.3
protected
# initiate_rest_edit_box( WP_REST_Request $request, string $request_type )

Initiates the request property and the rest_box property if box is writeable.

Initiates the request property and the rest_box property if box is writeable.

Parameters

$request
Request object.
$request_type
A description of the type of request being made.

Since

2.2.3
protected
# initiate_rest_box( WP_REST_Request $request, string $request_type )

Initiates the request property and the rest_box property.

Initiates the request property and the rest_box property.

Parameters

$request
Request object.
$request_type
A description of the type of request being made.

Since

2.2.3
public
# initiate_request( WP_REST_Request $request, string $request_type )

Initiates the request property and sets up the initial static properties.

Initiates the request property and sets up the initial static properties.

Parameters

$request
Request object.
$request_type
A description of the type of request being made.

Since

2.2.3
public static string
# get_intial_request_type( )

Useful when getting _embed-ed items

Useful when getting _embed-ed items

Returns

string
Initial requested type.

Since

2.2.3
public static string
# get_intial_route( )

Useful when getting _embed-ed items

Useful when getting _embed-ed items

Returns

string
Initial requested route.

Since

2.2.3
public array
# get_item_schema( )

Get CMB2 fields schema, conforming to JSON Schema

Get CMB2 fields schema, conforming to JSON Schema

Returns

array

Since

2.2.3

Overrides

WP_REST_Controller::get_item_schema
abstract protected array
# prepare_links( mixed $object )

Return an array of contextual links for endpoint/object

Return an array of contextual links for endpoint/object

Parameters

$object
Object to build links from.

Returns

array
Array of links

Since

2.2.3

Link

http://v2.wp-api.org/extending/linking/
http://www.iana.org/assignments/link-relations/link-relations.xhtml
public string
# get_query_string( )

Get whitelisted query strings from URL for appending to link URLS.

Get whitelisted query strings from URL for appending to link URLS.

Returns

string
URL query stringl

Since

2.2.3

Methods inherited from WP_REST_Controller

add_additional_fields_schema(), add_additional_fields_to_object(), create_item(), create_item_permissions_check(), delete_item(), delete_item_permissions_check(), filter_response_by_context(), get_additional_fields(), get_collection_params(), get_context_param(), get_endpoint_args_for_item_schema(), get_item(), get_item_permissions_check(), get_items(), get_items_permissions_check(), get_object_type(), get_post(), get_public_item_schema(), prepare_item_for_database(), prepare_response_for_collection(), register_routes(), update_additional_fields_for_object(), update_item(), update_item_permissions_check()

Properties summary

protected string $namespace

The namespace of this controller's route.

The namespace of this controller's route.

# CMB2_REST::NAME_SPACE
protected string $rest_base

The base of this controller's route.

The base of this controller's route.

#
public WP_REST_Request $request

The current request object

The current request object

Since

2.2.3
#
public WP_REST_Server $server

The current server object

The current server object

Since

2.2.3
#
public mixed $object_id

Box object id

Box object id

Since

2.2.3
# null
public string $object_type

Box object type

Box object type

Since

2.2.3
# ''
protected CMB2_REST $rest_box

CMB2 Instance

CMB2 Instance

#
protected CMB2_Field $field

CMB2_Field Instance

CMB2_Field Instance

#
protected static string $route

The initial route

The initial route

Since

2.2.3
# ''
protected static string $request_type

Defines which endpoint the initial request is.

Defines which endpoint the initial request is.

Since

2.2.3
# ''
CMB2 Documentation API documentation generated by ApiGen