@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -if ( ! class_exists( 'CMB2_Bootstrap_270', false ) ) { |
|
7 | +if ( ! class_exists('CMB2_Bootstrap_270', false)) { |
|
8 | 8 | |
9 | 9 | class CMB2_Bootstrap_270 { |
10 | 10 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @return CMB2_Bootstrap_270 Single instance object |
40 | 40 | */ |
41 | 41 | public static function initiate() { |
42 | - if ( null === self::$single_instance ) { |
|
42 | + if (null === self::$single_instance) { |
|
43 | 43 | self::$single_instance = new self(); |
44 | 44 | } |
45 | 45 | return self::$single_instance; |
@@ -59,15 +59,15 @@ discard block |
||
59 | 59 | * A constant you can use to check if CMB2 is loaded |
60 | 60 | * for your plugins/themes with CMB2 dependency |
61 | 61 | */ |
62 | - if ( ! defined( 'CMB2_LOADED' ) ) { |
|
63 | - define( 'CMB2_LOADED', self::PRIORITY ); |
|
62 | + if ( ! defined('CMB2_LOADED')) { |
|
63 | + define('CMB2_LOADED', self::PRIORITY); |
|
64 | 64 | } |
65 | 65 | |
66 | - if ( ! function_exists( 'add_action' ) ) { |
|
66 | + if ( ! function_exists('add_action')) { |
|
67 | 67 | // We are running outside of the context of WordPress. |
68 | 68 | return; |
69 | 69 | } |
70 | - add_action( 'init', array( $this, 'include_cmb' ), self::PRIORITY ); |
|
70 | + add_action('init', array($this, 'include_cmb'), self::PRIORITY); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | * @since 2.0.0 |
78 | 78 | */ |
79 | 79 | public function include_cmb() { |
80 | - if ( class_exists( 'CMB2', false ) ) { |
|
80 | + if (class_exists('CMB2', false)) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | - if ( ! defined( 'CMB2_VERSION' ) ) { |
|
85 | - define( 'CMB2_VERSION', self::VERSION ); |
|
84 | + if ( ! defined('CMB2_VERSION')) { |
|
85 | + define('CMB2_VERSION', self::VERSION); |
|
86 | 86 | } |
87 | 87 | |
88 | - if ( ! defined( 'CMB2_DIR' ) ) { |
|
89 | - define( 'CMB2_DIR', trailingslashit( dirname( __FILE__ ) ) ); |
|
88 | + if ( ! defined('CMB2_DIR')) { |
|
89 | + define('CMB2_DIR', trailingslashit(dirname(__FILE__))); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | $this->l10ni18n(); |
@@ -97,10 +97,10 @@ discard block |
||
97 | 97 | require_once CMB2_DIR . 'includes/helper-functions.php'; |
98 | 98 | |
99 | 99 | // Now kick off the class autoloader. |
100 | - spl_autoload_register( 'cmb2_autoload_classes' ); |
|
100 | + spl_autoload_register('cmb2_autoload_classes'); |
|
101 | 101 | |
102 | 102 | // Kick the whole thing off. |
103 | - require_once( cmb2_dir( 'bootstrap.php' ) ); |
|
103 | + require_once(cmb2_dir('bootstrap.php')); |
|
104 | 104 | cmb2_bootstrap(); |
105 | 105 | } |
106 | 106 | |
@@ -111,20 +111,20 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public function l10ni18n() { |
113 | 113 | |
114 | - $loaded = load_plugin_textdomain( 'cmb2', false, '/languages/' ); |
|
114 | + $loaded = load_plugin_textdomain('cmb2', false, '/languages/'); |
|
115 | 115 | |
116 | - if ( ! $loaded ) { |
|
117 | - $loaded = load_muplugin_textdomain( 'cmb2', '/languages/' ); |
|
116 | + if ( ! $loaded) { |
|
117 | + $loaded = load_muplugin_textdomain('cmb2', '/languages/'); |
|
118 | 118 | } |
119 | 119 | |
120 | - if ( ! $loaded ) { |
|
121 | - $loaded = load_theme_textdomain( 'cmb2', get_stylesheet_directory() . '/languages/' ); |
|
120 | + if ( ! $loaded) { |
|
121 | + $loaded = load_theme_textdomain('cmb2', get_stylesheet_directory() . '/languages/'); |
|
122 | 122 | } |
123 | 123 | |
124 | - if ( ! $loaded ) { |
|
125 | - $locale = apply_filters( 'plugin_locale', function_exists( 'determine_locale' ) ? determine_locale() : get_locale(), 'cmb2' ); |
|
126 | - $mofile = dirname( __FILE__ ) . '/languages/cmb2-' . $locale . '.mo'; |
|
127 | - load_textdomain( 'cmb2', $mofile ); |
|
124 | + if ( ! $loaded) { |
|
125 | + $locale = apply_filters('plugin_locale', function_exists('determine_locale') ? determine_locale() : get_locale(), 'cmb2'); |
|
126 | + $mofile = dirname(__FILE__) . '/languages/cmb2-' . $locale . '.mo'; |
|
127 | + load_textdomain('cmb2', $mofile); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | } |
@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @since 2.2.3 |
37 | 37 | */ |
38 | - public function __construct( WP_REST_Server $wp_rest_server ) { |
|
38 | + public function __construct(WP_REST_Server $wp_rest_server) { |
|
39 | 39 | $this->namespace_base = $this->namespace . '/' . $this->rest_base; |
40 | - parent::__construct( $wp_rest_server ); |
|
40 | + parent::__construct($wp_rest_server); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | public function register_routes() { |
49 | 49 | $args = array( |
50 | 50 | '_embed' => array( |
51 | - 'description' => __( 'Includes the registered fields for the box in the response.', 'cmb2' ), |
|
51 | + 'description' => __('Includes the registered fields for the box in the response.', 'cmb2'), |
|
52 | 52 | ), |
53 | 53 | ); |
54 | 54 | |
@@ -58,30 +58,30 @@ discard block |
||
58 | 58 | // $args['context']['default'] = 'view'; |
59 | 59 | // $args['context']['enum'] = array( 'view', 'embed' ); |
60 | 60 | // Returns all boxes data. |
61 | - register_rest_route( $this->namespace, '/' . $this->rest_base, array( |
|
61 | + register_rest_route($this->namespace, '/' . $this->rest_base, array( |
|
62 | 62 | array( |
63 | 63 | 'methods' => WP_REST_Server::READABLE, |
64 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
65 | - 'callback' => array( $this, 'get_items' ), |
|
64 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
65 | + 'callback' => array($this, 'get_items'), |
|
66 | 66 | 'args' => $args, |
67 | 67 | ), |
68 | - 'schema' => array( $this, 'get_item_schema' ), |
|
69 | - ) ); |
|
68 | + 'schema' => array($this, 'get_item_schema'), |
|
69 | + )); |
|
70 | 70 | |
71 | 71 | $args['_rendered'] = array( |
72 | - 'description' => __( 'Includes the fully rendered attributes, \'form_open\', \'form_close\', as well as the enqueued \'js_dependencies\' script handles, and \'css_dependencies\' stylesheet handles.', 'cmb2' ), |
|
72 | + 'description' => __('Includes the fully rendered attributes, \'form_open\', \'form_close\', as well as the enqueued \'js_dependencies\' script handles, and \'css_dependencies\' stylesheet handles.', 'cmb2'), |
|
73 | 73 | ); |
74 | 74 | |
75 | 75 | // Returns specific box's data. |
76 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)', array( |
|
76 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)', array( |
|
77 | 77 | array( |
78 | 78 | 'methods' => WP_REST_Server::READABLE, |
79 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
80 | - 'callback' => array( $this, 'get_item' ), |
|
79 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
80 | + 'callback' => array($this, 'get_item'), |
|
81 | 81 | 'args' => $args, |
82 | 82 | ), |
83 | - 'schema' => array( $this, 'get_item_schema' ), |
|
84 | - ) ); |
|
83 | + 'schema' => array($this, 'get_item_schema'), |
|
84 | + )); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | * @param WP_REST_Request $request Full data about the request. |
93 | 93 | * @return WP_Error|boolean |
94 | 94 | */ |
95 | - public function get_items_permissions_check( $request ) { |
|
96 | - $this->initiate_request( $request, __FUNCTION__ ); |
|
95 | + public function get_items_permissions_check($request) { |
|
96 | + $this->initiate_request($request, __FUNCTION__); |
|
97 | 97 | |
98 | 98 | /** |
99 | 99 | * By default, no special permissions needed. |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param bool $can_access Whether this CMB2 endpoint can be accessed. |
104 | 104 | * @param object $controller This CMB2_REST_Controller object. |
105 | 105 | */ |
106 | - return apply_filters( 'cmb2_api_get_boxes_permissions_check', true, $this ); |
|
106 | + return apply_filters('cmb2_api_get_boxes_permissions_check', true, $this); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -114,34 +114,34 @@ discard block |
||
114 | 114 | * @param WP_REST_Request $request Full data about the request. |
115 | 115 | * @return WP_Error|WP_REST_Response |
116 | 116 | */ |
117 | - public function get_items( $request ) { |
|
118 | - $this->initiate_request( $request, 'boxes_read' ); |
|
117 | + public function get_items($request) { |
|
118 | + $this->initiate_request($request, 'boxes_read'); |
|
119 | 119 | |
120 | 120 | $boxes = CMB2_REST::get_all(); |
121 | - if ( empty( $boxes ) ) { |
|
122 | - return new WP_Error( 'cmb2_rest_no_boxes', __( 'No boxes found.', 'cmb2' ), array( |
|
121 | + if (empty($boxes)) { |
|
122 | + return new WP_Error('cmb2_rest_no_boxes', __('No boxes found.', 'cmb2'), array( |
|
123 | 123 | 'status' => 403, |
124 | - ) ); |
|
124 | + )); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | $boxes_data = array(); |
128 | 128 | |
129 | 129 | // Loop and prepare boxes data. |
130 | - foreach ( $boxes as $this->rest_box ) { |
|
130 | + foreach ($boxes as $this->rest_box) { |
|
131 | 131 | if ( |
132 | 132 | // Make sure this box can be read |
133 | 133 | $this->rest_box->rest_read |
134 | 134 | // And make sure current user can view this box. |
135 | - && $this->get_item_permissions_check_filter( $this->request ) |
|
135 | + && $this->get_item_permissions_check_filter($this->request) |
|
136 | 136 | ) { |
137 | 137 | $boxes_data[] = $this->server->response_to_data( |
138 | 138 | $this->get_rest_box(), |
139 | - isset( $this->request['_embed'] ) |
|
139 | + isset($this->request['_embed']) |
|
140 | 140 | ); |
141 | 141 | } |
142 | 142 | } |
143 | 143 | |
144 | - return $this->prepare_item( $boxes_data ); |
|
144 | + return $this->prepare_item($boxes_data); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @param WP_REST_Request $request Full details about the request. |
154 | 154 | * @return WP_Error|boolean |
155 | 155 | */ |
156 | - public function get_item_permissions_check( $request ) { |
|
157 | - $this->initiate_rest_read_box( $request, 'box_read' ); |
|
156 | + public function get_item_permissions_check($request) { |
|
157 | + $this->initiate_rest_read_box($request, 'box_read'); |
|
158 | 158 | |
159 | 159 | return $this->get_item_permissions_check_filter(); |
160 | 160 | } |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param bool $can_access Whether the current request has access to view the box by default. |
169 | 169 | * @return WP_Error|boolean |
170 | 170 | */ |
171 | - public function get_item_permissions_check_filter( $can_access = true ) { |
|
171 | + public function get_item_permissions_check_filter($can_access = true) { |
|
172 | 172 | /** |
173 | 173 | * By default, no special permissions needed. |
174 | 174 | * |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @param bool $can_access Whether this CMB2 endpoint can be accessed. |
178 | 178 | * @param object $controller This CMB2_REST_Controller object. |
179 | 179 | */ |
180 | - return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_box_permissions_check', $can_access ); |
|
180 | + return $this->maybe_hook_callback_and_apply_filters('cmb2_api_get_box_permissions_check', $can_access); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -188,14 +188,14 @@ discard block |
||
188 | 188 | * @param WP_REST_Request $request Full data about the request. |
189 | 189 | * @return WP_Error|WP_REST_Response |
190 | 190 | */ |
191 | - public function get_item( $request ) { |
|
192 | - $this->initiate_rest_read_box( $request, 'box_read' ); |
|
191 | + public function get_item($request) { |
|
192 | + $this->initiate_rest_read_box($request, 'box_read'); |
|
193 | 193 | |
194 | - if ( is_wp_error( $this->rest_box ) ) { |
|
194 | + if (is_wp_error($this->rest_box)) { |
|
195 | 195 | return $this->rest_box; |
196 | 196 | } |
197 | 197 | |
198 | - return $this->prepare_item( $this->get_rest_box() ); |
|
198 | + return $this->prepare_item($this->get_rest_box()); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | |
211 | 211 | $boxes_data = $cmb->meta_box; |
212 | 212 | |
213 | - if ( isset( $this->request['_rendered'] ) && $this->namespace_base !== ltrim( CMB2_REST_Controller::get_intial_route(), '/' ) ) { |
|
214 | - $boxes_data['form_open'] = $this->get_cb_results( array( $cmb, 'render_form_open' ) ); |
|
215 | - $boxes_data['form_close'] = $this->get_cb_results( array( $cmb, 'render_form_close' ) ); |
|
213 | + if (isset($this->request['_rendered']) && $this->namespace_base !== ltrim(CMB2_REST_Controller::get_intial_route(), '/')) { |
|
214 | + $boxes_data['form_open'] = $this->get_cb_results(array($cmb, 'render_form_open')); |
|
215 | + $boxes_data['form_close'] = $this->get_cb_results(array($cmb, 'render_form_close')); |
|
216 | 216 | |
217 | 217 | global $wp_scripts, $wp_styles; |
218 | 218 | $before_css = $wp_styles->queue; |
@@ -220,19 +220,19 @@ discard block |
||
220 | 220 | |
221 | 221 | CMB2_JS::enqueue(); |
222 | 222 | |
223 | - $boxes_data['js_dependencies'] = array_values( array_diff( $wp_scripts->queue, $before_js ) ); |
|
224 | - $boxes_data['css_dependencies'] = array_values( array_diff( $wp_styles->queue, $before_css ) ); |
|
223 | + $boxes_data['js_dependencies'] = array_values(array_diff($wp_scripts->queue, $before_js)); |
|
224 | + $boxes_data['css_dependencies'] = array_values(array_diff($wp_styles->queue, $before_css)); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | // TODO: look into 'embed' parameter. |
228 | 228 | // http://demo.wp-api.org/wp-json/wp/v2/posts?_embed |
229 | - unset( $boxes_data['fields'] ); |
|
229 | + unset($boxes_data['fields']); |
|
230 | 230 | // Handle callable properties. |
231 | - unset( $boxes_data['show_on_cb'] ); |
|
231 | + unset($boxes_data['show_on_cb']); |
|
232 | 232 | |
233 | - $response = rest_ensure_response( $boxes_data ); |
|
233 | + $response = rest_ensure_response($boxes_data); |
|
234 | 234 | |
235 | - $response->add_links( $this->prepare_links( $cmb ) ); |
|
235 | + $response->add_links($this->prepare_links($cmb)); |
|
236 | 236 | |
237 | 237 | return $response; |
238 | 238 | } |
@@ -246,22 +246,22 @@ discard block |
||
246 | 246 | * |
247 | 247 | * @return array Array of links |
248 | 248 | */ |
249 | - protected function prepare_links( $cmb ) { |
|
249 | + protected function prepare_links($cmb) { |
|
250 | 250 | $boxbase = $this->namespace_base . '/' . $cmb->cmb_id; |
251 | 251 | $query_string = $this->get_query_string(); |
252 | 252 | |
253 | 253 | return array( |
254 | 254 | // Standard Link Relations -- http://v2.wp-api.org/extending/linking/ |
255 | 255 | 'self' => array( |
256 | - 'href' => rest_url( $boxbase . $query_string ), |
|
256 | + 'href' => rest_url($boxbase . $query_string), |
|
257 | 257 | ), |
258 | 258 | 'collection' => array( |
259 | - 'href' => rest_url( $this->namespace_base . $query_string ), |
|
259 | + 'href' => rest_url($this->namespace_base . $query_string), |
|
260 | 260 | ), |
261 | 261 | // Custom Link Relations -- http://v2.wp-api.org/extending/linking/ |
262 | 262 | // TODO URL should document relationship. |
263 | 263 | 'https://cmb2.io/fields' => array( |
264 | - 'href' => rest_url( trailingslashit( $boxbase ) . 'fields' . $query_string ), |
|
264 | + 'href' => rest_url(trailingslashit($boxbase) . 'fields' . $query_string), |
|
265 | 265 | 'embeddable' => true, |
266 | 266 | ), |
267 | 267 | ); |
@@ -24,57 +24,57 @@ discard block |
||
24 | 24 | public function register_routes() { |
25 | 25 | $args = array( |
26 | 26 | '_embed' => array( |
27 | - 'description' => __( 'Includes the box object which the fields are registered to in the response.', 'cmb2' ), |
|
27 | + 'description' => __('Includes the box object which the fields are registered to in the response.', 'cmb2'), |
|
28 | 28 | ), |
29 | 29 | '_rendered' => array( |
30 | - 'description' => __( 'When the \'_rendered\' argument is passed, the renderable field attributes will be returned fully rendered. By default, the names of the callback handers for the renderable attributes will be returned.', 'cmb2' ), |
|
30 | + 'description' => __('When the \'_rendered\' argument is passed, the renderable field attributes will be returned fully rendered. By default, the names of the callback handers for the renderable attributes will be returned.', 'cmb2'), |
|
31 | 31 | ), |
32 | 32 | 'object_id' => array( |
33 | - 'description' => __( 'To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2' ), |
|
33 | + 'description' => __('To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2'), |
|
34 | 34 | ), |
35 | 35 | 'object_type' => array( |
36 | - 'description' => __( 'To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2' ), |
|
36 | + 'description' => __('To view or modify the field\'s value, the \'object_id\' and \'object_type\' arguments are required.', 'cmb2'), |
|
37 | 37 | ), |
38 | 38 | ); |
39 | 39 | |
40 | 40 | // Returns specific box's fields. |
41 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/', array( |
|
41 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/', array( |
|
42 | 42 | array( |
43 | 43 | 'methods' => WP_REST_Server::READABLE, |
44 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
45 | - 'callback' => array( $this, 'get_items' ), |
|
44 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
45 | + 'callback' => array($this, 'get_items'), |
|
46 | 46 | 'args' => $args, |
47 | 47 | ), |
48 | - 'schema' => array( $this, 'get_item_schema' ), |
|
49 | - ) ); |
|
48 | + 'schema' => array($this, 'get_item_schema'), |
|
49 | + )); |
|
50 | 50 | |
51 | 51 | $delete_args = $args; |
52 | 52 | $delete_args['object_id']['required'] = true; |
53 | 53 | $delete_args['object_type']['required'] = true; |
54 | 54 | |
55 | 55 | // Returns specific field data. |
56 | - register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/(?P<field_id>[\w-]+)', array( |
|
56 | + register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/(?P<field_id>[\w-]+)', array( |
|
57 | 57 | array( |
58 | 58 | 'methods' => WP_REST_Server::READABLE, |
59 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
60 | - 'callback' => array( $this, 'get_item' ), |
|
59 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
60 | + 'callback' => array($this, 'get_item'), |
|
61 | 61 | 'args' => $args, |
62 | 62 | ), |
63 | 63 | array( |
64 | 64 | 'methods' => WP_REST_Server::EDITABLE, |
65 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
66 | - 'callback' => array( $this, 'update_item' ), |
|
67 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
65 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
66 | + 'callback' => array($this, 'update_item'), |
|
67 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
68 | 68 | 'args' => $args, |
69 | 69 | ), |
70 | 70 | array( |
71 | 71 | 'methods' => WP_REST_Server::DELETABLE, |
72 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
73 | - 'callback' => array( $this, 'delete_item' ), |
|
72 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
73 | + 'callback' => array($this, 'delete_item'), |
|
74 | 74 | 'args' => $delete_args, |
75 | 75 | ), |
76 | - 'schema' => array( $this, 'get_item_schema' ), |
|
77 | - ) ); |
|
76 | + 'schema' => array($this, 'get_item_schema'), |
|
77 | + )); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @param WP_REST_Request $request Full data about the request. |
87 | 87 | * @return WP_Error|boolean |
88 | 88 | */ |
89 | - public function get_items_permissions_check( $request ) { |
|
90 | - $this->initiate_rest_read_box( $request, 'fields_read' ); |
|
89 | + public function get_items_permissions_check($request) { |
|
90 | + $this->initiate_rest_read_box($request, 'fields_read'); |
|
91 | 91 | $can_access = true; |
92 | 92 | |
93 | 93 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @param bool $can_access Whether this CMB2 endpoint can be accessed. |
99 | 99 | * @param object $controller This CMB2_REST_Controller object. |
100 | 100 | */ |
101 | - return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_fields_permissions_check', $can_access ); |
|
101 | + return $this->maybe_hook_callback_and_apply_filters('cmb2_api_get_fields_permissions_check', $can_access); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -109,31 +109,31 @@ discard block |
||
109 | 109 | * @param WP_REST_Request $request Full data about the request. |
110 | 110 | * @return WP_Error|WP_REST_Response |
111 | 111 | */ |
112 | - public function get_items( $request ) { |
|
113 | - if ( ! $this->rest_box ) { |
|
114 | - $this->initiate_rest_read_box( $request, 'fields_read' ); |
|
112 | + public function get_items($request) { |
|
113 | + if ( ! $this->rest_box) { |
|
114 | + $this->initiate_rest_read_box($request, 'fields_read'); |
|
115 | 115 | } |
116 | 116 | |
117 | - if ( is_wp_error( $this->rest_box ) ) { |
|
117 | + if (is_wp_error($this->rest_box)) { |
|
118 | 118 | return $this->rest_box; |
119 | 119 | } |
120 | 120 | |
121 | 121 | $fields = array(); |
122 | - foreach ( $this->rest_box->cmb->prop( 'fields', array() ) as $field ) { |
|
122 | + foreach ($this->rest_box->cmb->prop('fields', array()) as $field) { |
|
123 | 123 | |
124 | 124 | // Make sure this field can be read. |
125 | - $this->field = $this->rest_box->field_can_read( $field['id'], true ); |
|
125 | + $this->field = $this->rest_box->field_can_read($field['id'], true); |
|
126 | 126 | |
127 | 127 | // And make sure current user can view this box. |
128 | - if ( $this->field && $this->get_item_permissions_check_filter() ) { |
|
129 | - $fields[ $field['id'] ] = $this->server->response_to_data( |
|
128 | + if ($this->field && $this->get_item_permissions_check_filter()) { |
|
129 | + $fields[$field['id']] = $this->server->response_to_data( |
|
130 | 130 | $this->prepare_field_response(), |
131 | - isset( $this->request['_embed'] ) |
|
131 | + isset($this->request['_embed']) |
|
132 | 132 | ); |
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | - return $this->prepare_item( $fields ); |
|
136 | + return $this->prepare_item($fields); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | * @param WP_REST_Request $request Full details about the request. |
146 | 146 | * @return WP_Error|boolean |
147 | 147 | */ |
148 | - public function get_item_permissions_check( $request ) { |
|
149 | - $this->initiate_rest_read_box( $request, 'field_read' ); |
|
150 | - if ( ! is_wp_error( $this->rest_box ) ) { |
|
151 | - $this->field = $this->rest_box->field_can_read( $this->request->get_param( 'field_id' ), true ); |
|
148 | + public function get_item_permissions_check($request) { |
|
149 | + $this->initiate_rest_read_box($request, 'field_read'); |
|
150 | + if ( ! is_wp_error($this->rest_box)) { |
|
151 | + $this->field = $this->rest_box->field_can_read($this->request->get_param('field_id'), true); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | return $this->get_item_permissions_check_filter(); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @param bool $can_access Whether the current request has access to view the field by default. |
164 | 164 | * @return WP_Error|boolean |
165 | 165 | */ |
166 | - public function get_item_permissions_check_filter( $can_access = true ) { |
|
166 | + public function get_item_permissions_check_filter($can_access = true) { |
|
167 | 167 | /** |
168 | 168 | * By default, no special permissions needed. |
169 | 169 | * |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | * @param bool $can_access Whether this CMB2 endpoint can be accessed. |
173 | 173 | * @param object $controller This CMB2_REST_Controller object. |
174 | 174 | */ |
175 | - return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_get_field_permissions_check', $can_access ); |
|
175 | + return $this->maybe_hook_callback_and_apply_filters('cmb2_api_get_field_permissions_check', $can_access); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | * @param WP_REST_Request $request Full data about the request. |
184 | 184 | * @return WP_Error|WP_REST_Response |
185 | 185 | */ |
186 | - public function get_item( $request ) { |
|
187 | - $this->initiate_rest_read_box( $request, 'field_read' ); |
|
186 | + public function get_item($request) { |
|
187 | + $this->initiate_rest_read_box($request, 'field_read'); |
|
188 | 188 | |
189 | - if ( is_wp_error( $this->rest_box ) ) { |
|
189 | + if (is_wp_error($this->rest_box)) { |
|
190 | 190 | return $this->rest_box; |
191 | 191 | } |
192 | 192 | |
193 | - return $this->prepare_read_field( $this->request->get_param( 'field_id' ) ); |
|
193 | + return $this->prepare_read_field($this->request->get_param('field_id')); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | * @param WP_REST_Request $request Full details about the request. |
203 | 203 | * @return WP_Error|boolean |
204 | 204 | */ |
205 | - public function update_item_permissions_check( $request ) { |
|
206 | - $this->initiate_rest_read_box( $request, 'field_value_update' ); |
|
207 | - if ( ! is_wp_error( $this->rest_box ) ) { |
|
208 | - $this->field = $this->rest_box->field_can_edit( $this->request->get_param( 'field_id' ), true ); |
|
205 | + public function update_item_permissions_check($request) { |
|
206 | + $this->initiate_rest_read_box($request, 'field_value_update'); |
|
207 | + if ( ! is_wp_error($this->rest_box)) { |
|
208 | + $this->field = $this->rest_box->field_can_edit($this->request->get_param('field_id'), true); |
|
209 | 209 | } |
210 | 210 | |
211 | - $can_update = current_user_can( 'edit_others_posts' ); |
|
211 | + $can_update = current_user_can('edit_others_posts'); |
|
212 | 212 | |
213 | 213 | /** |
214 | 214 | * By default, 'edit_others_posts' is required capability. |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | * @param bool $can_update Whether this CMB2 endpoint can be accessed. |
219 | 219 | * @param object $controller This CMB2_REST_Controller object. |
220 | 220 | */ |
221 | - return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_update_field_value_permissions_check', $can_update ); |
|
221 | + return $this->maybe_hook_callback_and_apply_filters('cmb2_api_update_field_value_permissions_check', $can_update); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -229,16 +229,16 @@ discard block |
||
229 | 229 | * @param WP_REST_Request $request Full data about the request. |
230 | 230 | * @return WP_Error|WP_REST_Response |
231 | 231 | */ |
232 | - public function update_item( $request ) { |
|
233 | - $this->initiate_rest_read_box( $request, 'field_value_update' ); |
|
232 | + public function update_item($request) { |
|
233 | + $this->initiate_rest_read_box($request, 'field_value_update'); |
|
234 | 234 | |
235 | - if ( ! $this->request['value'] ) { |
|
236 | - return new WP_Error( 'cmb2_rest_update_field_error', __( 'CMB2 Field value cannot be updated without the value parameter specified.', 'cmb2' ), array( |
|
235 | + if ( ! $this->request['value']) { |
|
236 | + return new WP_Error('cmb2_rest_update_field_error', __('CMB2 Field value cannot be updated without the value parameter specified.', 'cmb2'), array( |
|
237 | 237 | 'status' => 400, |
238 | - ) ); |
|
238 | + )); |
|
239 | 239 | } |
240 | 240 | |
241 | - return $this->modify_field_value( 'updated' ); |
|
241 | + return $this->modify_field_value('updated'); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | * @param WP_REST_Request $request Full details about the request. |
251 | 251 | * @return WP_Error|boolean |
252 | 252 | */ |
253 | - public function delete_item_permissions_check( $request ) { |
|
254 | - $this->initiate_rest_read_box( $request, 'field_value_delete' ); |
|
255 | - if ( ! is_wp_error( $this->rest_box ) ) { |
|
256 | - $this->field = $this->rest_box->field_can_edit( $this->request->get_param( 'field_id' ), true ); |
|
253 | + public function delete_item_permissions_check($request) { |
|
254 | + $this->initiate_rest_read_box($request, 'field_value_delete'); |
|
255 | + if ( ! is_wp_error($this->rest_box)) { |
|
256 | + $this->field = $this->rest_box->field_can_edit($this->request->get_param('field_id'), true); |
|
257 | 257 | } |
258 | 258 | |
259 | - $can_delete = current_user_can( 'delete_others_posts' ); |
|
259 | + $can_delete = current_user_can('delete_others_posts'); |
|
260 | 260 | |
261 | 261 | /** |
262 | 262 | * By default, 'delete_others_posts' is required capability. |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | * @param bool $can_delete Whether this CMB2 endpoint can be accessed. |
267 | 267 | * @param object $controller This CMB2_REST_Controller object. |
268 | 268 | */ |
269 | - return $this->maybe_hook_callback_and_apply_filters( 'cmb2_api_delete_field_value_permissions_check', $can_delete ); |
|
269 | + return $this->maybe_hook_callback_and_apply_filters('cmb2_api_delete_field_value_permissions_check', $can_delete); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -277,10 +277,10 @@ discard block |
||
277 | 277 | * @param WP_REST_Request $request Full data about the request. |
278 | 278 | * @return WP_Error|WP_REST_Response |
279 | 279 | */ |
280 | - public function delete_item( $request ) { |
|
281 | - $this->initiate_rest_read_box( $request, 'field_value_delete' ); |
|
280 | + public function delete_item($request) { |
|
281 | + $this->initiate_rest_read_box($request, 'field_value_delete'); |
|
282 | 282 | |
283 | - return $this->modify_field_value( 'deleted' ); |
|
283 | + return $this->modify_field_value('deleted'); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
@@ -291,39 +291,39 @@ discard block |
||
291 | 291 | * @param string $activity The modification activity (updated or deleted). |
292 | 292 | * @return WP_Error|WP_REST_Response |
293 | 293 | */ |
294 | - public function modify_field_value( $activity ) { |
|
294 | + public function modify_field_value($activity) { |
|
295 | 295 | |
296 | - if ( ! $this->request['object_id'] || ! $this->request['object_type'] ) { |
|
297 | - return new WP_Error( 'cmb2_rest_modify_field_value_error', __( 'CMB2 Field value cannot be modified without the object_id and object_type parameters specified.', 'cmb2' ), array( |
|
296 | + if ( ! $this->request['object_id'] || ! $this->request['object_type']) { |
|
297 | + return new WP_Error('cmb2_rest_modify_field_value_error', __('CMB2 Field value cannot be modified without the object_id and object_type parameters specified.', 'cmb2'), array( |
|
298 | 298 | 'status' => 400, |
299 | - ) ); |
|
299 | + )); |
|
300 | 300 | } |
301 | 301 | |
302 | - if ( is_wp_error( $this->rest_box ) ) { |
|
302 | + if (is_wp_error($this->rest_box)) { |
|
303 | 303 | return $this->rest_box; |
304 | 304 | } |
305 | 305 | |
306 | 306 | $this->field = $this->rest_box->field_can_edit( |
307 | - $this->field ? $this->field : $this->request->get_param( 'field_id' ), |
|
307 | + $this->field ? $this->field : $this->request->get_param('field_id'), |
|
308 | 308 | true |
309 | 309 | ); |
310 | 310 | |
311 | - if ( ! $this->field ) { |
|
312 | - return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array( |
|
311 | + if ( ! $this->field) { |
|
312 | + return new WP_Error('cmb2_rest_no_field_by_id_error', __('No field found by that id.', 'cmb2'), array( |
|
313 | 313 | 'status' => 403, |
314 | - ) ); |
|
314 | + )); |
|
315 | 315 | } |
316 | 316 | |
317 | - $this->field->args[ "value_{$activity}" ] = (bool) 'deleted' === $activity |
|
317 | + $this->field->args["value_{$activity}"] = (bool) 'deleted' === $activity |
|
318 | 318 | ? $this->field->remove_data() |
319 | - : $this->field->save_field( $this->request['value'] ); |
|
319 | + : $this->field->save_field($this->request['value']); |
|
320 | 320 | |
321 | 321 | // If options page, save the $activity options |
322 | - if ( 'options-page' == $this->request['object_type'] ) { |
|
323 | - $this->field->args[ "value_{$activity}" ] = cmb2_options( $this->request['object_id'] )->set(); |
|
322 | + if ('options-page' == $this->request['object_type']) { |
|
323 | + $this->field->args["value_{$activity}"] = cmb2_options($this->request['object_id'])->set(); |
|
324 | 324 | } |
325 | 325 | |
326 | - return $this->prepare_read_field( $this->field ); |
|
326 | + return $this->prepare_read_field($this->field); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -334,16 +334,16 @@ discard block |
||
334 | 334 | * @param string\CMB2_Field Field id or Field object. |
335 | 335 | * @return WP_Error|WP_REST_Response |
336 | 336 | */ |
337 | - public function prepare_read_field( $field ) { |
|
338 | - $this->field = $this->rest_box->field_can_read( $field, true ); |
|
337 | + public function prepare_read_field($field) { |
|
338 | + $this->field = $this->rest_box->field_can_read($field, true); |
|
339 | 339 | |
340 | - if ( ! $this->field ) { |
|
341 | - return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array( |
|
340 | + if ( ! $this->field) { |
|
341 | + return new WP_Error('cmb2_rest_no_field_by_id_error', __('No field found by that id.', 'cmb2'), array( |
|
342 | 342 | 'status' => 403, |
343 | - ) ); |
|
343 | + )); |
|
344 | 344 | } |
345 | 345 | |
346 | - return $this->prepare_item( $this->prepare_field_response() ); |
|
346 | + return $this->prepare_item($this->prepare_field_response()); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
@@ -355,10 +355,10 @@ discard block |
||
355 | 355 | * @return array Response array. |
356 | 356 | */ |
357 | 357 | public function prepare_field_response() { |
358 | - $field_data = $this->prepare_field_data( $this->field ); |
|
359 | - $response = rest_ensure_response( $field_data ); |
|
358 | + $field_data = $this->prepare_field_data($this->field); |
|
359 | + $response = rest_ensure_response($field_data); |
|
360 | 360 | |
361 | - $response->add_links( $this->prepare_links( $this->field ) ); |
|
361 | + $response->add_links($this->prepare_links($this->field)); |
|
362 | 362 | |
363 | 363 | return $response; |
364 | 364 | } |
@@ -372,55 +372,55 @@ discard block |
||
372 | 372 | * |
373 | 373 | * @return array Array of field data. |
374 | 374 | */ |
375 | - protected function prepare_field_data( CMB2_Field $field ) { |
|
375 | + protected function prepare_field_data(CMB2_Field $field) { |
|
376 | 376 | $field_data = array(); |
377 | - $params_to_ignore = array( 'show_in_rest', 'options' ); |
|
377 | + $params_to_ignore = array('show_in_rest', 'options'); |
|
378 | 378 | $params_to_rename = array( |
379 | 379 | 'label_cb' => 'label', |
380 | 380 | 'options_cb' => 'options', |
381 | 381 | ); |
382 | 382 | |
383 | 383 | // Run this first so the js_dependencies arg is populated. |
384 | - $rendered = ( $cb = $field->maybe_callback( 'render_row_cb' ) ) |
|
384 | + $rendered = ($cb = $field->maybe_callback('render_row_cb')) |
|
385 | 385 | // Ok, callback is good, let's run it. |
386 | - ? $this->get_cb_results( $cb, $field->args(), $field ) |
|
386 | + ? $this->get_cb_results($cb, $field->args(), $field) |
|
387 | 387 | : false; |
388 | 388 | |
389 | 389 | $field_args = $field->args(); |
390 | 390 | |
391 | - foreach ( $field_args as $key => $value ) { |
|
392 | - if ( in_array( $key, $params_to_ignore, true ) ) { |
|
391 | + foreach ($field_args as $key => $value) { |
|
392 | + if (in_array($key, $params_to_ignore, true)) { |
|
393 | 393 | continue; |
394 | 394 | } |
395 | 395 | |
396 | - if ( 'options_cb' === $key ) { |
|
396 | + if ('options_cb' === $key) { |
|
397 | 397 | $value = $field->options(); |
398 | - } elseif ( in_array( $key, CMB2_Field::$callable_fields, true ) ) { |
|
398 | + } elseif (in_array($key, CMB2_Field::$callable_fields, true)) { |
|
399 | 399 | |
400 | - if ( isset( $this->request['_rendered'] ) ) { |
|
401 | - $value = $key === 'render_row_cb' ? $rendered : $field->get_param_callback_result( $key ); |
|
402 | - } elseif ( is_array( $value ) ) { |
|
400 | + if (isset($this->request['_rendered'])) { |
|
401 | + $value = $key === 'render_row_cb' ? $rendered : $field->get_param_callback_result($key); |
|
402 | + } elseif (is_array($value)) { |
|
403 | 403 | // We need to rewrite callbacks as string as they will cause |
404 | 404 | // JSON recursion errors. |
405 | - $class = is_string( $value[0] ) ? $value[0] : get_class( $value[0] ); |
|
405 | + $class = is_string($value[0]) ? $value[0] : get_class($value[0]); |
|
406 | 406 | $value = $class . '::' . $value[1]; |
407 | 407 | } |
408 | 408 | } |
409 | 409 | |
410 | - $key = isset( $params_to_rename[ $key ] ) ? $params_to_rename[ $key ] : $key; |
|
410 | + $key = isset($params_to_rename[$key]) ? $params_to_rename[$key] : $key; |
|
411 | 411 | |
412 | - if ( empty( $value ) || is_scalar( $value ) || is_array( $value ) ) { |
|
413 | - $field_data[ $key ] = $value; |
|
412 | + if (empty($value) || is_scalar($value) || is_array($value)) { |
|
413 | + $field_data[$key] = $value; |
|
414 | 414 | } else { |
415 | - $field_data[ $key ] = sprintf( __( 'Value Error for %s', 'cmb2' ), $key ); |
|
415 | + $field_data[$key] = sprintf(__('Value Error for %s', 'cmb2'), $key); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | |
419 | - if ( $field->args( 'has_supporting_data' ) ) { |
|
420 | - $field_data = $this->get_supporting_data( $field_data, $field ); |
|
419 | + if ($field->args('has_supporting_data')) { |
|
420 | + $field_data = $this->get_supporting_data($field_data, $field); |
|
421 | 421 | } |
422 | 422 | |
423 | - if ( $this->request['object_id'] && $this->request['object_type'] ) { |
|
423 | + if ($this->request['object_id'] && $this->request['object_type']) { |
|
424 | 424 | $field_data['value'] = $field->get_rest_value(); |
425 | 425 | } |
426 | 426 | |
@@ -437,18 +437,18 @@ discard block |
||
437 | 437 | * |
438 | 438 | * @return array Array of field data. |
439 | 439 | */ |
440 | - public function get_supporting_data( $field_data, $field ) { |
|
440 | + public function get_supporting_data($field_data, $field) { |
|
441 | 441 | |
442 | 442 | // Reset placement of this property. |
443 | - unset( $field_data['has_supporting_data'] ); |
|
443 | + unset($field_data['has_supporting_data']); |
|
444 | 444 | $field_data['has_supporting_data'] = true; |
445 | 445 | |
446 | 446 | $field = $field->get_supporting_field(); |
447 | 447 | $field_data['supporting_data'] = array( |
448 | - 'id' => $field->_id( '', false ), |
|
448 | + 'id' => $field->_id('', false), |
|
449 | 449 | ); |
450 | 450 | |
451 | - if ( $this->request['object_id'] && $this->request['object_type'] ) { |
|
451 | + if ($this->request['object_id'] && $this->request['object_type']) { |
|
452 | 452 | $field_data['supporting_data']['value'] = $field->get_rest_value(); |
453 | 453 | } |
454 | 454 | |
@@ -464,20 +464,20 @@ discard block |
||
464 | 464 | * |
465 | 465 | * @return array Array of links |
466 | 466 | */ |
467 | - protected function prepare_links( $field ) { |
|
467 | + protected function prepare_links($field) { |
|
468 | 468 | $boxbase = $this->namespace_base . '/' . $this->rest_box->cmb->cmb_id; |
469 | 469 | $query_string = $this->get_query_string(); |
470 | 470 | |
471 | 471 | $links = array( |
472 | 472 | 'self' => array( |
473 | - 'href' => rest_url( trailingslashit( $boxbase ) . 'fields/' . $field->_id( '', false ) . $query_string ), |
|
473 | + 'href' => rest_url(trailingslashit($boxbase) . 'fields/' . $field->_id('', false) . $query_string), |
|
474 | 474 | ), |
475 | 475 | 'collection' => array( |
476 | - 'href' => rest_url( trailingslashit( $boxbase ) . 'fields' . $query_string ), |
|
476 | + 'href' => rest_url(trailingslashit($boxbase) . 'fields' . $query_string), |
|
477 | 477 | ), |
478 | 478 | 'up' => array( |
479 | 479 | 'embeddable' => true, |
480 | - 'href' => rest_url( $boxbase . $query_string ), |
|
480 | + 'href' => rest_url($boxbase . $query_string), |
|
481 | 481 | ), |
482 | 482 | ); |
483 | 483 | |
@@ -498,14 +498,14 @@ discard block |
||
498 | 498 | * |
499 | 499 | * @return bool The possibly-modified filter value (if the _cb param is a non-callable). |
500 | 500 | */ |
501 | - public function maybe_hook_registered_callback( $filter, $default_val ) { |
|
502 | - $default_val = parent::maybe_hook_registered_callback( $filter, $default_val ); |
|
501 | + public function maybe_hook_registered_callback($filter, $default_val) { |
|
502 | + $default_val = parent::maybe_hook_registered_callback($filter, $default_val); |
|
503 | 503 | |
504 | - if ( $this->field ) { |
|
504 | + if ($this->field) { |
|
505 | 505 | |
506 | 506 | // Hook field specific filter callbacks. |
507 | - $val = $this->field->maybe_hook_parameter( $filter, $default_val ); |
|
508 | - if ( null !== $val ) { |
|
507 | + $val = $this->field->maybe_hook_parameter($filter, $default_val); |
|
508 | + if (null !== $val) { |
|
509 | 509 | $default_val = $val; |
510 | 510 | } |
511 | 511 | } |
@@ -522,12 +522,12 @@ discard block |
||
522 | 522 | * |
523 | 523 | * @return void |
524 | 524 | */ |
525 | - public function maybe_unhook_registered_callback( $filter ) { |
|
526 | - parent::maybe_unhook_registered_callback( $filter ); |
|
525 | + public function maybe_unhook_registered_callback($filter) { |
|
526 | + parent::maybe_unhook_registered_callback($filter); |
|
527 | 527 | |
528 | - if ( $this->field ) { |
|
528 | + if ($this->field) { |
|
529 | 529 | // Unhook field specific filter callbacks. |
530 | - $this->field->maybe_hook_parameter( $filter, null, 'remove_filter' ); |
|
530 | + $this->field->maybe_hook_parameter($filter, null, 'remove_filter'); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! class_exists( 'WP_REST_Controller' ) ) { |
|
2 | +if ( ! class_exists('WP_REST_Controller')) { |
|
3 | 3 | // Shim the WP_REST_Controller class if wp-api plugin not installed, & not in core. |
4 | - require_once cmb2_dir( 'includes/shim/WP_REST_Controller.php' ); |
|
4 | + require_once cmb2_dir('includes/shim/WP_REST_Controller.php'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @since 2.2.3 |
104 | 104 | */ |
105 | - public function __construct( WP_REST_Server $wp_rest_server ) { |
|
105 | + public function __construct(WP_REST_Server $wp_rest_server) { |
|
106 | 106 | $this->server = $wp_rest_server; |
107 | 107 | } |
108 | 108 | |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return void |
121 | 121 | */ |
122 | - public function maybe_hook_callback_and_apply_filters( $filter, $default_access ) { |
|
123 | - if ( ! $this->rest_box && $this->request->get_param( 'cmb_id' ) ) { |
|
124 | - $this->rest_box = CMB2_REST::get_rest_box( $this->request->get_param( 'cmb_id' ) ); |
|
122 | + public function maybe_hook_callback_and_apply_filters($filter, $default_access) { |
|
123 | + if ( ! $this->rest_box && $this->request->get_param('cmb_id')) { |
|
124 | + $this->rest_box = CMB2_REST::get_rest_box($this->request->get_param('cmb_id')); |
|
125 | 125 | } |
126 | 126 | |
127 | - $default_access = $this->maybe_hook_registered_callback( $filter, $default_access ); |
|
127 | + $default_access = $this->maybe_hook_registered_callback($filter, $default_access); |
|
128 | 128 | |
129 | 129 | /** |
130 | 130 | * Apply the permissions check filter. |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | * @param bool $default_access Whether this CMB2 endpoint can be accessed. |
135 | 135 | * @param object $controller This CMB2_REST_Controller object. |
136 | 136 | */ |
137 | - $default_access = apply_filters( $filter, $default_access, $this ); |
|
137 | + $default_access = apply_filters($filter, $default_access, $this); |
|
138 | 138 | |
139 | - $this->maybe_unhook_registered_callback( $filter ); |
|
139 | + $this->maybe_unhook_registered_callback($filter); |
|
140 | 140 | |
141 | 141 | return $default_access; |
142 | 142 | } |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return bool The possibly-modified filter value (if the '*_cb' param is non-callable). |
157 | 157 | */ |
158 | - public function maybe_hook_registered_callback( $filter, $default_val ) { |
|
159 | - if ( ! $this->rest_box || is_wp_error( $this->rest_box ) ) { |
|
158 | + public function maybe_hook_registered_callback($filter, $default_val) { |
|
159 | + if ( ! $this->rest_box || is_wp_error($this->rest_box)) { |
|
160 | 160 | return $default_val; |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Hook box specific filter callbacks. |
164 | - $val = $this->rest_box->cmb->maybe_hook_parameter( $filter, $default_val ); |
|
165 | - if ( null !== $val ) { |
|
164 | + $val = $this->rest_box->cmb->maybe_hook_parameter($filter, $default_val); |
|
165 | + if (null !== $val) { |
|
166 | 166 | $default_val = $val; |
167 | 167 | } |
168 | 168 | |
@@ -178,13 +178,13 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return void |
180 | 180 | */ |
181 | - public function maybe_unhook_registered_callback( $filter ) { |
|
182 | - if ( ! $this->rest_box || is_wp_error( $this->rest_box ) ) { |
|
181 | + public function maybe_unhook_registered_callback($filter) { |
|
182 | + if ( ! $this->rest_box || is_wp_error($this->rest_box)) { |
|
183 | 183 | return; |
184 | 184 | } |
185 | 185 | |
186 | 186 | // Unhook box specific filter callbacks. |
187 | - $this->rest_box->cmb->maybe_hook_parameter( $filter, null, 'remove_filter' ); |
|
187 | + $this->rest_box->cmb->maybe_hook_parameter($filter, null, 'remove_filter'); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | * @param mixed $data |
196 | 196 | * @return array $data |
197 | 197 | */ |
198 | - public function prepare_item( $data ) { |
|
199 | - return $this->prepare_item_for_response( $data, $this->request ); |
|
198 | + public function prepare_item($data) { |
|
199 | + return $this->prepare_item_for_response($data, $this->request); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -207,11 +207,11 @@ discard block |
||
207 | 207 | * @param mixed $cb Callable function/method. |
208 | 208 | * @return mixed Results of output buffer after calling function/method. |
209 | 209 | */ |
210 | - public function get_cb_results( $cb ) { |
|
210 | + public function get_cb_results($cb) { |
|
211 | 211 | $args = func_get_args(); |
212 | - array_shift( $args ); // ignore $cb |
|
212 | + array_shift($args); // ignore $cb |
|
213 | 213 | ob_start(); |
214 | - call_user_func_array( $cb, $args ); |
|
214 | + call_user_func_array($cb, $args); |
|
215 | 215 | |
216 | 216 | return ob_get_clean(); |
217 | 217 | } |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | * @param WP_REST_Request $request Request object. |
226 | 226 | * @return WP_REST_Response $response |
227 | 227 | */ |
228 | - public function prepare_item_for_response( $data, $request = null ) { |
|
229 | - $data = $this->filter_response_by_context( $data, $this->request['context'] ); |
|
228 | + public function prepare_item_for_response($data, $request = null) { |
|
229 | + $data = $this->filter_response_by_context($data, $this->request['context']); |
|
230 | 230 | |
231 | 231 | /** |
232 | 232 | * Filter the prepared CMB2 item response. |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @param object $request The WP_REST_Request object |
238 | 238 | * @param object $cmb2_endpoints This endpoints object |
239 | 239 | */ |
240 | - return apply_filters( 'cmb2_rest_prepare', rest_ensure_response( $data ), $this->request, $this ); |
|
240 | + return apply_filters('cmb2_rest_prepare', rest_ensure_response($data), $this->request, $this); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @return void |
252 | 252 | */ |
253 | - protected function initiate_rest_read_box( $request, $request_type ) { |
|
254 | - $this->initiate_rest_box( $request, $request_type ); |
|
253 | + protected function initiate_rest_read_box($request, $request_type) { |
|
254 | + $this->initiate_rest_box($request, $request_type); |
|
255 | 255 | |
256 | - if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_read ) { |
|
257 | - $this->rest_box = new WP_Error( 'cmb2_rest_no_read_error', __( 'This box does not have read permissions.', 'cmb2' ), array( |
|
256 | + if ( ! is_wp_error($this->rest_box) && ! $this->rest_box->rest_read) { |
|
257 | + $this->rest_box = new WP_Error('cmb2_rest_no_read_error', __('This box does not have read permissions.', 'cmb2'), array( |
|
258 | 258 | 'status' => 403, |
259 | - ) ); |
|
259 | + )); |
|
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
@@ -270,13 +270,13 @@ discard block |
||
270 | 270 | * |
271 | 271 | * @return void |
272 | 272 | */ |
273 | - protected function initiate_rest_edit_box( $request, $request_type ) { |
|
274 | - $this->initiate_rest_box( $request, $request_type ); |
|
273 | + protected function initiate_rest_edit_box($request, $request_type) { |
|
274 | + $this->initiate_rest_box($request, $request_type); |
|
275 | 275 | |
276 | - if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_edit ) { |
|
277 | - $this->rest_box = new WP_Error( 'cmb2_rest_no_write_error', __( 'This box does not have write permissions.', 'cmb2' ), array( |
|
276 | + if ( ! is_wp_error($this->rest_box) && ! $this->rest_box->rest_edit) { |
|
277 | + $this->rest_box = new WP_Error('cmb2_rest_no_write_error', __('This box does not have write permissions.', 'cmb2'), array( |
|
278 | 278 | 'status' => 403, |
279 | - ) ); |
|
279 | + )); |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
@@ -290,25 +290,25 @@ discard block |
||
290 | 290 | * |
291 | 291 | * @return void |
292 | 292 | */ |
293 | - protected function initiate_rest_box( $request, $request_type ) { |
|
294 | - $this->initiate_request( $request, $request_type ); |
|
293 | + protected function initiate_rest_box($request, $request_type) { |
|
294 | + $this->initiate_request($request, $request_type); |
|
295 | 295 | |
296 | - $this->rest_box = CMB2_REST::get_rest_box( $this->request->get_param( 'cmb_id' ) ); |
|
296 | + $this->rest_box = CMB2_REST::get_rest_box($this->request->get_param('cmb_id')); |
|
297 | 297 | |
298 | - if ( ! $this->rest_box ) { |
|
298 | + if ( ! $this->rest_box) { |
|
299 | 299 | |
300 | - $this->rest_box = new WP_Error( 'cmb2_rest_box_not_found_error', __( 'No box found by that id. A box needs to be registered with the "show_in_rest" parameter configured.', 'cmb2' ), array( |
|
300 | + $this->rest_box = new WP_Error('cmb2_rest_box_not_found_error', __('No box found by that id. A box needs to be registered with the "show_in_rest" parameter configured.', 'cmb2'), array( |
|
301 | 301 | 'status' => 403, |
302 | - ) ); |
|
302 | + )); |
|
303 | 303 | |
304 | 304 | } else { |
305 | 305 | |
306 | - if ( isset( $this->request['object_id'] ) ) { |
|
307 | - $this->rest_box->cmb->object_id( sanitize_text_field( $this->request['object_id'] ) ); |
|
306 | + if (isset($this->request['object_id'])) { |
|
307 | + $this->rest_box->cmb->object_id(sanitize_text_field($this->request['object_id'])); |
|
308 | 308 | } |
309 | 309 | |
310 | - if ( isset( $this->request['object_type'] ) ) { |
|
311 | - $this->rest_box->cmb->object_type( sanitize_text_field( $this->request['object_type'] ) ); |
|
310 | + if (isset($this->request['object_type'])) { |
|
311 | + $this->rest_box->cmb->object_type(sanitize_text_field($this->request['object_type'])); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | } |
@@ -323,18 +323,18 @@ discard block |
||
323 | 323 | * |
324 | 324 | * @return void |
325 | 325 | */ |
326 | - public function initiate_request( $request, $request_type ) { |
|
326 | + public function initiate_request($request, $request_type) { |
|
327 | 327 | $this->request = $request; |
328 | 328 | |
329 | - if ( ! isset( $this->request['context'] ) || empty( $this->request['context'] ) ) { |
|
329 | + if ( ! isset($this->request['context']) || empty($this->request['context'])) { |
|
330 | 330 | $this->request['context'] = 'view'; |
331 | 331 | } |
332 | 332 | |
333 | - if ( ! self::$request_type ) { |
|
333 | + if ( ! self::$request_type) { |
|
334 | 334 | self::$request_type = $request_type; |
335 | 335 | } |
336 | 336 | |
337 | - if ( ! self::$route ) { |
|
337 | + if ( ! self::$route) { |
|
338 | 338 | self::$route = $this->request->get_route(); |
339 | 339 | } |
340 | 340 | } |
@@ -375,21 +375,21 @@ discard block |
||
375 | 375 | 'type' => 'object', |
376 | 376 | 'properties' => array( |
377 | 377 | 'description' => array( |
378 | - 'description' => __( 'A human-readable description of the object.', 'cmb2' ), |
|
378 | + 'description' => __('A human-readable description of the object.', 'cmb2'), |
|
379 | 379 | 'type' => 'string', |
380 | 380 | 'context' => array( |
381 | 381 | 'view', |
382 | 382 | ), |
383 | 383 | ), |
384 | 384 | 'name' => array( |
385 | - 'description' => __( 'The id for the object.', 'cmb2' ), |
|
385 | + 'description' => __('The id for the object.', 'cmb2'), |
|
386 | 386 | 'type' => 'integer', |
387 | 387 | 'context' => array( |
388 | 388 | 'view', |
389 | 389 | ), |
390 | 390 | ), |
391 | 391 | 'name' => array( |
392 | - 'description' => __( 'The title for the object.', 'cmb2' ), |
|
392 | + 'description' => __('The title for the object.', 'cmb2'), |
|
393 | 393 | 'type' => 'string', |
394 | 394 | 'context' => array( |
395 | 395 | 'view', |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | ), |
399 | 399 | ); |
400 | 400 | |
401 | - return $this->add_additional_fields_schema( $schema ); |
|
401 | + return $this->add_additional_fields_schema($schema); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * |
414 | 414 | * @return array Array of links |
415 | 415 | */ |
416 | - abstract protected function prepare_links( $object ); |
|
416 | + abstract protected function prepare_links($object); |
|
417 | 417 | |
418 | 418 | /** |
419 | 419 | * Get whitelisted query strings from URL for appending to link URLS. |
@@ -432,11 +432,11 @@ discard block |
||
432 | 432 | |
433 | 433 | $query_string = ''; |
434 | 434 | |
435 | - foreach ( $defaults as $key => $value ) { |
|
436 | - if ( isset( $this->request[ $key ] ) ) { |
|
435 | + foreach ($defaults as $key => $value) { |
|
436 | + if (isset($this->request[$key])) { |
|
437 | 437 | $query_string .= $query_string ? '&' : '?'; |
438 | 438 | $query_string .= $key; |
439 | - if ( $value = sanitize_text_field( $this->request[ $key ] ) ) { |
|
439 | + if ($value = sanitize_text_field($this->request[$key])) { |
|
440 | 440 | $query_string .= '=' . $value; |
441 | 441 | } |
442 | 442 | } |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | * |
97 | 97 | * @return CMB2_Hookup_Base $hookup The hookup object. |
98 | 98 | */ |
99 | - public static function maybe_init_and_hookup( CMB2 $cmb ) { |
|
100 | - if ( $cmb->prop( 'show_in_rest' ) && function_exists( 'rest_get_server' ) ) { |
|
99 | + public static function maybe_init_and_hookup(CMB2 $cmb) { |
|
100 | + if ($cmb->prop('show_in_rest') && function_exists('rest_get_server')) { |
|
101 | 101 | |
102 | - $hookup = new self( $cmb ); |
|
102 | + $hookup = new self($cmb); |
|
103 | 103 | |
104 | 104 | return $hookup->universal_hooks(); |
105 | 105 | } |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @param CMB2 $cmb The CMB2 object to be registered for the API. |
116 | 116 | */ |
117 | - public function __construct( CMB2 $cmb ) { |
|
117 | + public function __construct(CMB2 $cmb) { |
|
118 | 118 | $this->cmb = $cmb; |
119 | - self::$boxes[ $cmb->cmb_id ] = $this; |
|
119 | + self::$boxes[$cmb->cmb_id] = $this; |
|
120 | 120 | |
121 | - $show_value = $this->cmb->prop( 'show_in_rest' ); |
|
121 | + $show_value = $this->cmb->prop('show_in_rest'); |
|
122 | 122 | |
123 | - $this->rest_read = self::is_readable( $show_value ); |
|
124 | - $this->rest_edit = self::is_editable( $show_value ); |
|
123 | + $this->rest_read = self::is_readable($show_value); |
|
124 | + $this->rest_edit = self::is_editable($show_value); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function universal_hooks() { |
135 | 135 | // hook up the CMB rest endpoint classes |
136 | - $this->once( 'rest_api_init', array( __CLASS__, 'init_routes' ), 0 ); |
|
136 | + $this->once('rest_api_init', array(__CLASS__, 'init_routes'), 0); |
|
137 | 137 | |
138 | - if ( function_exists( 'register_rest_field' ) ) { |
|
139 | - $this->once( 'rest_api_init', array( __CLASS__, 'register_cmb2_fields' ), 50 ); |
|
138 | + if (function_exists('register_rest_field')) { |
|
139 | + $this->once('rest_api_init', array(__CLASS__, 'register_cmb2_fields'), 50); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | $this->declare_read_edit_fields(); |
143 | 143 | |
144 | - add_filter( 'is_protected_meta', array( $this, 'is_protected_meta' ), 10, 3 ); |
|
144 | + add_filter('is_protected_meta', array($this, 'is_protected_meta'), 10, 3); |
|
145 | 145 | |
146 | 146 | return $this; |
147 | 147 | } |
@@ -156,10 +156,10 @@ discard block |
||
156 | 156 | public static function init_routes() { |
157 | 157 | $wp_rest_server = rest_get_server(); |
158 | 158 | |
159 | - $boxes_controller = new CMB2_REST_Controller_Boxes( $wp_rest_server ); |
|
159 | + $boxes_controller = new CMB2_REST_Controller_Boxes($wp_rest_server); |
|
160 | 160 | $boxes_controller->register_routes(); |
161 | 161 | |
162 | - $fields_controller = new CMB2_REST_Controller_Fields( $wp_rest_server ); |
|
162 | + $fields_controller = new CMB2_REST_Controller_Fields($wp_rest_server); |
|
163 | 163 | $fields_controller->register_routes(); |
164 | 164 | } |
165 | 165 | |
@@ -173,60 +173,60 @@ discard block |
||
173 | 173 | public static function register_cmb2_fields() { |
174 | 174 | $alltypes = $taxonomies = array(); |
175 | 175 | |
176 | - foreach ( self::$boxes as $cmb_id => $rest_box ) { |
|
176 | + foreach (self::$boxes as $cmb_id => $rest_box) { |
|
177 | 177 | |
178 | 178 | // Hook box specific filter callbacks. |
179 | - $callback = $rest_box->cmb->prop( 'register_rest_field_cb' ); |
|
180 | - if ( is_callable( $callback ) ) { |
|
181 | - call_user_func( $callback, $rest_box ); |
|
179 | + $callback = $rest_box->cmb->prop('register_rest_field_cb'); |
|
180 | + if (is_callable($callback)) { |
|
181 | + call_user_func($callback, $rest_box); |
|
182 | 182 | continue; |
183 | 183 | } |
184 | 184 | |
185 | - $types = array_flip( $rest_box->cmb->box_types( array( 'post' ) ) ); |
|
185 | + $types = array_flip($rest_box->cmb->box_types(array('post'))); |
|
186 | 186 | |
187 | - if ( isset( $types['user'] ) ) { |
|
188 | - unset( $types['user'] ); |
|
189 | - self::$type_boxes['user'][ $cmb_id ] = $cmb_id; |
|
187 | + if (isset($types['user'])) { |
|
188 | + unset($types['user']); |
|
189 | + self::$type_boxes['user'][$cmb_id] = $cmb_id; |
|
190 | 190 | } |
191 | 191 | |
192 | - if ( isset( $types['comment'] ) ) { |
|
193 | - unset( $types['comment'] ); |
|
194 | - self::$type_boxes['comment'][ $cmb_id ] = $cmb_id; |
|
192 | + if (isset($types['comment'])) { |
|
193 | + unset($types['comment']); |
|
194 | + self::$type_boxes['comment'][$cmb_id] = $cmb_id; |
|
195 | 195 | } |
196 | 196 | |
197 | - if ( isset( $types['term'] ) ) { |
|
198 | - unset( $types['term'] ); |
|
197 | + if (isset($types['term'])) { |
|
198 | + unset($types['term']); |
|
199 | 199 | |
200 | 200 | $taxonomies = array_merge( |
201 | 201 | $taxonomies, |
202 | - CMB2_Utils::ensure_array( $rest_box->cmb->prop( 'taxonomies' ) ) |
|
202 | + CMB2_Utils::ensure_array($rest_box->cmb->prop('taxonomies')) |
|
203 | 203 | ); |
204 | 204 | |
205 | - self::$type_boxes['term'][ $cmb_id ] = $cmb_id; |
|
205 | + self::$type_boxes['term'][$cmb_id] = $cmb_id; |
|
206 | 206 | } |
207 | 207 | |
208 | - if ( ! empty( $types ) ) { |
|
209 | - $alltypes = array_merge( $alltypes, array_flip( $types ) ); |
|
210 | - self::$type_boxes['post'][ $cmb_id ] = $cmb_id; |
|
208 | + if ( ! empty($types)) { |
|
209 | + $alltypes = array_merge($alltypes, array_flip($types)); |
|
210 | + self::$type_boxes['post'][$cmb_id] = $cmb_id; |
|
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
214 | - $alltypes = array_unique( $alltypes ); |
|
214 | + $alltypes = array_unique($alltypes); |
|
215 | 215 | |
216 | - if ( ! empty( $alltypes ) ) { |
|
217 | - self::register_rest_field( $alltypes, 'post' ); |
|
216 | + if ( ! empty($alltypes)) { |
|
217 | + self::register_rest_field($alltypes, 'post'); |
|
218 | 218 | } |
219 | 219 | |
220 | - if ( ! empty( self::$type_boxes['user'] ) ) { |
|
221 | - self::register_rest_field( 'user', 'user' ); |
|
220 | + if ( ! empty(self::$type_boxes['user'])) { |
|
221 | + self::register_rest_field('user', 'user'); |
|
222 | 222 | } |
223 | 223 | |
224 | - if ( ! empty( self::$type_boxes['comment'] ) ) { |
|
225 | - self::register_rest_field( 'comment', 'comment' ); |
|
224 | + if ( ! empty(self::$type_boxes['comment'])) { |
|
225 | + self::register_rest_field('comment', 'comment'); |
|
226 | 226 | } |
227 | 227 | |
228 | - if ( ! empty( self::$type_boxes['term'] ) ) { |
|
229 | - self::register_rest_field( $taxonomies, 'term' ); |
|
228 | + if ( ! empty(self::$type_boxes['term'])) { |
|
229 | + self::register_rest_field($taxonomies, 'term'); |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 | |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @return void |
243 | 243 | */ |
244 | - protected static function register_rest_field( $object_types, $object_type ) { |
|
245 | - register_rest_field( $object_types, 'cmb2', array( |
|
246 | - 'get_callback' => array( __CLASS__, "get_{$object_type}_rest_values" ), |
|
247 | - 'update_callback' => array( __CLASS__, "update_{$object_type}_rest_values" ), |
|
244 | + protected static function register_rest_field($object_types, $object_type) { |
|
245 | + register_rest_field($object_types, 'cmb2', array( |
|
246 | + 'get_callback' => array(__CLASS__, "get_{$object_type}_rest_values"), |
|
247 | + 'update_callback' => array(__CLASS__, "update_{$object_type}_rest_values"), |
|
248 | 248 | 'schema' => null, // @todo add schema |
249 | - ) ); |
|
249 | + )); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -257,18 +257,18 @@ discard block |
||
257 | 257 | * @return void |
258 | 258 | */ |
259 | 259 | protected function declare_read_edit_fields() { |
260 | - foreach ( $this->cmb->prop( 'fields' ) as $field ) { |
|
261 | - $show_in_rest = isset( $field['show_in_rest'] ) ? $field['show_in_rest'] : null; |
|
260 | + foreach ($this->cmb->prop('fields') as $field) { |
|
261 | + $show_in_rest = isset($field['show_in_rest']) ? $field['show_in_rest'] : null; |
|
262 | 262 | |
263 | - if ( false === $show_in_rest ) { |
|
263 | + if (false === $show_in_rest) { |
|
264 | 264 | continue; |
265 | 265 | } |
266 | 266 | |
267 | - if ( $this->can_read( $show_in_rest ) ) { |
|
267 | + if ($this->can_read($show_in_rest)) { |
|
268 | 268 | $this->read_fields[] = $field['id']; |
269 | 269 | } |
270 | 270 | |
271 | - if ( $this->can_edit( $show_in_rest ) ) { |
|
271 | + if ($this->can_edit($show_in_rest)) { |
|
272 | 272 | $this->edit_fields[] = $field['id']; |
273 | 273 | } |
274 | 274 | } |
@@ -284,14 +284,14 @@ discard block |
||
284 | 284 | * |
285 | 285 | * @return bool Whether field is readable. |
286 | 286 | */ |
287 | - protected function can_read( $show_in_rest ) { |
|
287 | + protected function can_read($show_in_rest) { |
|
288 | 288 | // if 'null', then use default box value. |
289 | - if ( null === $show_in_rest ) { |
|
289 | + if (null === $show_in_rest) { |
|
290 | 290 | return $this->rest_read; |
291 | 291 | } |
292 | 292 | |
293 | 293 | // Else check if the value represents readable. |
294 | - return self::is_readable( $show_in_rest ); |
|
294 | + return self::is_readable($show_in_rest); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -304,14 +304,14 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return bool Whether field is editable. |
306 | 306 | */ |
307 | - protected function can_edit( $show_in_rest ) { |
|
307 | + protected function can_edit($show_in_rest) { |
|
308 | 308 | // if 'null', then use default box value. |
309 | - if ( null === $show_in_rest ) { |
|
309 | + if (null === $show_in_rest) { |
|
310 | 310 | return $this->rest_edit; |
311 | 311 | } |
312 | 312 | |
313 | 313 | // Else check if the value represents editable. |
314 | - return self::is_editable( $show_in_rest ); |
|
314 | + return self::is_editable($show_in_rest); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | * |
327 | 327 | * @return mixed |
328 | 328 | */ |
329 | - public static function get_post_rest_values( $object, $field_name, $request, $object_type ) { |
|
330 | - if ( 'cmb2' === $field_name ) { |
|
331 | - return self::get_rest_values( $object, $request, $object_type, 'post' ); |
|
329 | + public static function get_post_rest_values($object, $field_name, $request, $object_type) { |
|
330 | + if ('cmb2' === $field_name) { |
|
331 | + return self::get_rest_values($object, $request, $object_type, 'post'); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
@@ -344,9 +344,9 @@ discard block |
||
344 | 344 | * |
345 | 345 | * @return mixed |
346 | 346 | */ |
347 | - public static function get_user_rest_values( $object, $field_name, $request, $object_type ) { |
|
348 | - if ( 'cmb2' === $field_name ) { |
|
349 | - return self::get_rest_values( $object, $request, $object_type, 'user' ); |
|
347 | + public static function get_user_rest_values($object, $field_name, $request, $object_type) { |
|
348 | + if ('cmb2' === $field_name) { |
|
349 | + return self::get_rest_values($object, $request, $object_type, 'user'); |
|
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
@@ -362,9 +362,9 @@ discard block |
||
362 | 362 | * |
363 | 363 | * @return mixed |
364 | 364 | */ |
365 | - public static function get_comment_rest_values( $object, $field_name, $request, $object_type ) { |
|
366 | - if ( 'cmb2' === $field_name ) { |
|
367 | - return self::get_rest_values( $object, $request, $object_type, 'comment' ); |
|
365 | + public static function get_comment_rest_values($object, $field_name, $request, $object_type) { |
|
366 | + if ('cmb2' === $field_name) { |
|
367 | + return self::get_rest_values($object, $request, $object_type, 'comment'); |
|
368 | 368 | } |
369 | 369 | } |
370 | 370 | |
@@ -380,9 +380,9 @@ discard block |
||
380 | 380 | * |
381 | 381 | * @return mixed |
382 | 382 | */ |
383 | - public static function get_term_rest_values( $object, $field_name, $request, $object_type ) { |
|
384 | - if ( 'cmb2' === $field_name ) { |
|
385 | - return self::get_rest_values( $object, $request, $object_type, 'term' ); |
|
383 | + public static function get_term_rest_values($object, $field_name, $request, $object_type) { |
|
384 | + if ('cmb2' === $field_name) { |
|
385 | + return self::get_rest_values($object, $request, $object_type, 'term'); |
|
386 | 386 | } |
387 | 387 | } |
388 | 388 | |
@@ -398,27 +398,27 @@ discard block |
||
398 | 398 | * |
399 | 399 | * @return mixed |
400 | 400 | */ |
401 | - protected static function get_rest_values( $object, $request, $object_type, $main_object_type = 'post' ) { |
|
402 | - if ( ! isset( $object['id'] ) ) { |
|
401 | + protected static function get_rest_values($object, $request, $object_type, $main_object_type = 'post') { |
|
402 | + if ( ! isset($object['id'])) { |
|
403 | 403 | return; |
404 | 404 | } |
405 | 405 | |
406 | 406 | $values = array(); |
407 | 407 | |
408 | - if ( ! empty( self::$type_boxes[ $main_object_type ] ) ) { |
|
409 | - foreach ( self::$type_boxes[ $main_object_type ] as $cmb_id ) { |
|
410 | - $rest_box = self::$boxes[ $cmb_id ]; |
|
408 | + if ( ! empty(self::$type_boxes[$main_object_type])) { |
|
409 | + foreach (self::$type_boxes[$main_object_type] as $cmb_id) { |
|
410 | + $rest_box = self::$boxes[$cmb_id]; |
|
411 | 411 | |
412 | - if ( ! $rest_box->cmb->is_box_type( $object_type ) ) { |
|
412 | + if ( ! $rest_box->cmb->is_box_type($object_type)) { |
|
413 | 413 | continue; |
414 | 414 | } |
415 | 415 | |
416 | - $result = self::get_box_rest_values( $rest_box, $object['id'], $main_object_type ); |
|
417 | - if ( ! empty( $result ) ) { |
|
418 | - if ( empty( $values[ $cmb_id ] ) ) { |
|
419 | - $values[ $cmb_id ] = $result; |
|
416 | + $result = self::get_box_rest_values($rest_box, $object['id'], $main_object_type); |
|
417 | + if ( ! empty($result)) { |
|
418 | + if (empty($values[$cmb_id])) { |
|
419 | + $values[$cmb_id] = $result; |
|
420 | 420 | } else { |
421 | - $values[ $cmb_id ] = array_merge( $values[ $cmb_id ], $result ); |
|
421 | + $values[$cmb_id] = array_merge($values[$cmb_id], $result); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | } |
@@ -438,23 +438,23 @@ discard block |
||
438 | 438 | * |
439 | 439 | * @return array Array of box rest values. |
440 | 440 | */ |
441 | - public static function get_box_rest_values( $rest_box, $object_id = 0, $main_object_type = 'post' ) { |
|
441 | + public static function get_box_rest_values($rest_box, $object_id = 0, $main_object_type = 'post') { |
|
442 | 442 | |
443 | - $rest_box->cmb->object_id( $object_id ); |
|
444 | - $rest_box->cmb->object_type( $main_object_type ); |
|
443 | + $rest_box->cmb->object_id($object_id); |
|
444 | + $rest_box->cmb->object_type($main_object_type); |
|
445 | 445 | |
446 | 446 | $values = array(); |
447 | 447 | |
448 | - foreach ( $rest_box->read_fields as $field_id ) { |
|
449 | - $field = $rest_box->cmb->get_field( $field_id ); |
|
450 | - $field->object_id( $object_id ); |
|
451 | - $field->object_type( $main_object_type ); |
|
448 | + foreach ($rest_box->read_fields as $field_id) { |
|
449 | + $field = $rest_box->cmb->get_field($field_id); |
|
450 | + $field->object_id($object_id); |
|
451 | + $field->object_type($main_object_type); |
|
452 | 452 | |
453 | - $values[ $field->id( true ) ] = $field->get_rest_value(); |
|
453 | + $values[$field->id(true)] = $field->get_rest_value(); |
|
454 | 454 | |
455 | - if ( $field->args( 'has_supporting_data' ) ) { |
|
455 | + if ($field->args('has_supporting_data')) { |
|
456 | 456 | $field = $field->get_supporting_field(); |
457 | - $values[ $field->id( true ) ] = $field->get_rest_value(); |
|
457 | + $values[$field->id(true)] = $field->get_rest_value(); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
@@ -474,9 +474,9 @@ discard block |
||
474 | 474 | * |
475 | 475 | * @return bool|int |
476 | 476 | */ |
477 | - public static function update_post_rest_values( $values, $object, $field_name, $request, $object_type ) { |
|
478 | - if ( 'cmb2' === $field_name ) { |
|
479 | - return self::update_rest_values( $values, $object, $request, $object_type, 'post' ); |
|
477 | + public static function update_post_rest_values($values, $object, $field_name, $request, $object_type) { |
|
478 | + if ('cmb2' === $field_name) { |
|
479 | + return self::update_rest_values($values, $object, $request, $object_type, 'post'); |
|
480 | 480 | } |
481 | 481 | } |
482 | 482 | |
@@ -493,9 +493,9 @@ discard block |
||
493 | 493 | * |
494 | 494 | * @return bool|int |
495 | 495 | */ |
496 | - public static function update_user_rest_values( $values, $object, $field_name, $request, $object_type ) { |
|
497 | - if ( 'cmb2' === $field_name ) { |
|
498 | - return self::update_rest_values( $values, $object, $request, $object_type, 'user' ); |
|
496 | + public static function update_user_rest_values($values, $object, $field_name, $request, $object_type) { |
|
497 | + if ('cmb2' === $field_name) { |
|
498 | + return self::update_rest_values($values, $object, $request, $object_type, 'user'); |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | |
@@ -512,9 +512,9 @@ discard block |
||
512 | 512 | * |
513 | 513 | * @return bool|int |
514 | 514 | */ |
515 | - public static function update_comment_rest_values( $values, $object, $field_name, $request, $object_type ) { |
|
516 | - if ( 'cmb2' === $field_name ) { |
|
517 | - return self::update_rest_values( $values, $object, $request, $object_type, 'comment' ); |
|
515 | + public static function update_comment_rest_values($values, $object, $field_name, $request, $object_type) { |
|
516 | + if ('cmb2' === $field_name) { |
|
517 | + return self::update_rest_values($values, $object, $request, $object_type, 'comment'); |
|
518 | 518 | } |
519 | 519 | } |
520 | 520 | |
@@ -531,9 +531,9 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @return bool|int |
533 | 533 | */ |
534 | - public static function update_term_rest_values( $values, $object, $field_name, $request, $object_type ) { |
|
535 | - if ( 'cmb2' === $field_name ) { |
|
536 | - return self::update_rest_values( $values, $object, $request, $object_type, 'term' ); |
|
534 | + public static function update_term_rest_values($values, $object, $field_name, $request, $object_type) { |
|
535 | + if ('cmb2' === $field_name) { |
|
536 | + return self::update_rest_values($values, $object, $request, $object_type, 'term'); |
|
537 | 537 | } |
538 | 538 | } |
539 | 539 | |
@@ -550,24 +550,24 @@ discard block |
||
550 | 550 | * |
551 | 551 | * @return bool|int |
552 | 552 | */ |
553 | - protected static function update_rest_values( $values, $object, $request, $object_type, $main_object_type = 'post' ) { |
|
554 | - if ( empty( $values ) || ! is_array( $values ) ) { |
|
553 | + protected static function update_rest_values($values, $object, $request, $object_type, $main_object_type = 'post') { |
|
554 | + if (empty($values) || ! is_array($values)) { |
|
555 | 555 | return; |
556 | 556 | } |
557 | 557 | |
558 | - $object_id = self::get_object_id( $object, $main_object_type ); |
|
558 | + $object_id = self::get_object_id($object, $main_object_type); |
|
559 | 559 | |
560 | - if ( ! $object_id ) { |
|
560 | + if ( ! $object_id) { |
|
561 | 561 | return; |
562 | 562 | } |
563 | 563 | |
564 | 564 | $updated = array(); |
565 | 565 | |
566 | - if ( ! empty( self::$type_boxes[ $main_object_type ] ) ) { |
|
567 | - foreach ( self::$type_boxes[ $main_object_type ] as $cmb_id ) { |
|
568 | - $result = self::santize_box_rest_values( $values, self::$boxes[ $cmb_id ], $object_id, $main_object_type ); |
|
569 | - if ( ! empty( $result ) ) { |
|
570 | - $updated[ $cmb_id ] = $result; |
|
566 | + if ( ! empty(self::$type_boxes[$main_object_type])) { |
|
567 | + foreach (self::$type_boxes[$main_object_type] as $cmb_id) { |
|
568 | + $result = self::santize_box_rest_values($values, self::$boxes[$cmb_id], $object_id, $main_object_type); |
|
569 | + if ( ! empty($result)) { |
|
570 | + $updated[$cmb_id] = $result; |
|
571 | 571 | } |
572 | 572 | } |
573 | 573 | } |
@@ -587,16 +587,16 @@ discard block |
||
587 | 587 | * |
588 | 588 | * @return mixed|bool Array of updated statuses if successful. |
589 | 589 | */ |
590 | - public static function santize_box_rest_values( $values, $rest_box, $object_id = 0, $main_object_type = 'post' ) { |
|
590 | + public static function santize_box_rest_values($values, $rest_box, $object_id = 0, $main_object_type = 'post') { |
|
591 | 591 | |
592 | - if ( ! array_key_exists( $rest_box->cmb->cmb_id, $values ) ) { |
|
592 | + if ( ! array_key_exists($rest_box->cmb->cmb_id, $values)) { |
|
593 | 593 | return false; |
594 | 594 | } |
595 | 595 | |
596 | - $rest_box->cmb->object_id( $object_id ); |
|
597 | - $rest_box->cmb->object_type( $main_object_type ); |
|
596 | + $rest_box->cmb->object_id($object_id); |
|
597 | + $rest_box->cmb->object_type($main_object_type); |
|
598 | 598 | |
599 | - return $rest_box->sanitize_box_values( $values ); |
|
599 | + return $rest_box->sanitize_box_values($values); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | /** |
@@ -607,13 +607,13 @@ discard block |
||
607 | 607 | * @param array $values Array of values being provided. |
608 | 608 | * @return array Array of updated/sanitized values. |
609 | 609 | */ |
610 | - public function sanitize_box_values( array $values ) { |
|
610 | + public function sanitize_box_values(array $values) { |
|
611 | 611 | $updated = array(); |
612 | 612 | |
613 | 613 | $this->cmb->pre_process(); |
614 | 614 | |
615 | - foreach ( $this->edit_fields as $field_id ) { |
|
616 | - $updated[ $field_id ] = $this->sanitize_field_value( $values, $field_id ); |
|
615 | + foreach ($this->edit_fields as $field_id) { |
|
616 | + $updated[$field_id] = $this->sanitize_field_value($values, $field_id); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | $this->cmb->after_save(); |
@@ -631,25 +631,25 @@ discard block |
||
631 | 631 | * |
632 | 632 | * @return mixed The results of saving/sanitizing a field value. |
633 | 633 | */ |
634 | - protected function sanitize_field_value( array $values, $field_id ) { |
|
635 | - if ( ! array_key_exists( $field_id, $values[ $this->cmb->cmb_id ] ) ) { |
|
634 | + protected function sanitize_field_value(array $values, $field_id) { |
|
635 | + if ( ! array_key_exists($field_id, $values[$this->cmb->cmb_id])) { |
|
636 | 636 | return; |
637 | 637 | } |
638 | 638 | |
639 | - $field = $this->cmb->get_field( $field_id ); |
|
639 | + $field = $this->cmb->get_field($field_id); |
|
640 | 640 | |
641 | - if ( 'title' == $field->type() ) { |
|
641 | + if ('title' == $field->type()) { |
|
642 | 642 | return; |
643 | 643 | } |
644 | 644 | |
645 | - $field->object_id( $this->cmb->object_id() ); |
|
646 | - $field->object_type( $this->cmb->object_type() ); |
|
645 | + $field->object_id($this->cmb->object_id()); |
|
646 | + $field->object_type($this->cmb->object_type()); |
|
647 | 647 | |
648 | - if ( 'group' == $field->type() ) { |
|
649 | - return $this->sanitize_group_value( $values, $field ); |
|
648 | + if ('group' == $field->type()) { |
|
649 | + return $this->sanitize_group_value($values, $field); |
|
650 | 650 | } |
651 | 651 | |
652 | - return $field->save_field( $values[ $this->cmb->cmb_id ][ $field_id ] ); |
|
652 | + return $field->save_field($values[$this->cmb->cmb_id][$field_id]); |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | /** |
@@ -662,15 +662,15 @@ discard block |
||
662 | 662 | * |
663 | 663 | * @return mixed The results of saving/sanitizing the group field value. |
664 | 664 | */ |
665 | - protected function sanitize_group_value( array $values, CMB2_Field $field ) { |
|
665 | + protected function sanitize_group_value(array $values, CMB2_Field $field) { |
|
666 | 666 | $fields = $field->fields(); |
667 | - if ( empty( $fields ) ) { |
|
667 | + if (empty($fields)) { |
|
668 | 668 | return; |
669 | 669 | } |
670 | 670 | |
671 | - $this->cmb->data_to_save[ $field->_id( '', false ) ] = $values[ $this->cmb->cmb_id ][ $field->_id( '', false ) ]; |
|
671 | + $this->cmb->data_to_save[$field->_id('', false)] = $values[$this->cmb->cmb_id][$field->_id('', false)]; |
|
672 | 672 | |
673 | - return $this->cmb->save_group_field( $field ); |
|
673 | + return $this->cmb->save_group_field($field); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | /** |
@@ -682,8 +682,8 @@ discard block |
||
682 | 682 | * @param string $meta_key Meta key. |
683 | 683 | * @param string $meta_type Meta type. |
684 | 684 | */ |
685 | - public function is_protected_meta( $protected, $meta_key, $meta_type ) { |
|
686 | - if ( $this->field_can_edit( $meta_key ) ) { |
|
685 | + public function is_protected_meta($protected, $meta_key, $meta_type) { |
|
686 | + if ($this->field_can_edit($meta_key)) { |
|
687 | 687 | return false; |
688 | 688 | } |
689 | 689 | |
@@ -700,22 +700,22 @@ discard block |
||
700 | 700 | * |
701 | 701 | * @return int The object ID if found. |
702 | 702 | */ |
703 | - public static function get_object_id( $object, $object_type = 'post' ) { |
|
704 | - switch ( $object_type ) { |
|
703 | + public static function get_object_id($object, $object_type = 'post') { |
|
704 | + switch ($object_type) { |
|
705 | 705 | case 'user': |
706 | 706 | case 'post': |
707 | - if ( isset( $object->ID ) ) { |
|
708 | - return intval( $object->ID ); |
|
707 | + if (isset($object->ID)) { |
|
708 | + return intval($object->ID); |
|
709 | 709 | } |
710 | 710 | case 'comment': |
711 | - if ( isset( $object->comment_ID ) ) { |
|
712 | - return intval( $object->comment_ID ); |
|
711 | + if (isset($object->comment_ID)) { |
|
712 | + return intval($object->comment_ID); |
|
713 | 713 | } |
714 | 714 | case 'term': |
715 | - if ( is_array( $object ) && isset( $object['term_id'] ) ) { |
|
716 | - return intval( $object['term_id'] ); |
|
717 | - } elseif ( isset( $object->term_id ) ) { |
|
718 | - return intval( $object->term_id ); |
|
715 | + if (is_array($object) && isset($object['term_id'])) { |
|
716 | + return intval($object['term_id']); |
|
717 | + } elseif (isset($object->term_id)) { |
|
718 | + return intval($object->term_id); |
|
719 | 719 | } |
720 | 720 | } |
721 | 721 | |
@@ -732,8 +732,8 @@ discard block |
||
732 | 732 | * |
733 | 733 | * @return mixed False if field can't be read or true|CMB2_Field object. |
734 | 734 | */ |
735 | - public function field_can_read( $field_id, $return_object = false ) { |
|
736 | - return $this->field_can( 'read_fields', $field_id, $return_object ); |
|
735 | + public function field_can_read($field_id, $return_object = false) { |
|
736 | + return $this->field_can('read_fields', $field_id, $return_object); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | /** |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | * |
747 | 747 | * @return mixed False if field can't be edited or true|CMB2_Field object. |
748 | 748 | */ |
749 | - public function field_can_edit( $field_id, $return_object = false ) { |
|
750 | - return $this->field_can( 'edit_fields', $field_id, $return_object ); |
|
749 | + public function field_can_edit($field_id, $return_object = false) { |
|
750 | + return $this->field_can('edit_fields', $field_id, $return_object); |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | /** |
@@ -761,12 +761,12 @@ discard block |
||
761 | 761 | * |
762 | 762 | * @return mixed False if field can't be read or edited or true|CMB2_Field object. |
763 | 763 | */ |
764 | - protected function field_can( $type = 'read_fields', $field_id, $return_object = false ) { |
|
765 | - if ( ! in_array( $field_id instanceof CMB2_Field ? $field_id->id() : $field_id, $this->{$type}, true ) ) { |
|
764 | + protected function field_can($type = 'read_fields', $field_id, $return_object = false) { |
|
765 | + if ( ! in_array($field_id instanceof CMB2_Field ? $field_id->id() : $field_id, $this->{$type}, true)) { |
|
766 | 766 | return false; |
767 | 767 | } |
768 | 768 | |
769 | - return $return_object ? $this->cmb->get_field( $field_id ) : true; |
|
769 | + return $return_object ? $this->cmb->get_field($field_id) : true; |
|
770 | 770 | } |
771 | 771 | |
772 | 772 | /** |
@@ -778,8 +778,8 @@ discard block |
||
778 | 778 | * |
779 | 779 | * @return CMB2_REST|false The CMB2_REST object or false. |
780 | 780 | */ |
781 | - public static function get_rest_box( $cmb_id ) { |
|
782 | - return isset( self::$boxes[ $cmb_id ] ) ? self::$boxes[ $cmb_id ] : false; |
|
781 | + public static function get_rest_box($cmb_id) { |
|
782 | + return isset(self::$boxes[$cmb_id]) ? self::$boxes[$cmb_id] : false; |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
@@ -789,9 +789,9 @@ discard block |
||
789 | 789 | * |
790 | 790 | * @param string $cmb_id A CMB2 instance id. |
791 | 791 | */ |
792 | - public static function remove( $cmb_id ) { |
|
793 | - if ( array_key_exists( $cmb_id, self::$boxes ) ) { |
|
794 | - unset( self::$boxes[ $cmb_id ] ); |
|
792 | + public static function remove($cmb_id) { |
|
793 | + if (array_key_exists($cmb_id, self::$boxes)) { |
|
794 | + unset(self::$boxes[$cmb_id]); |
|
795 | 795 | } |
796 | 796 | } |
797 | 797 | |
@@ -816,12 +816,12 @@ discard block |
||
816 | 816 | * |
817 | 817 | * @return boolean Whether value is considered readable. |
818 | 818 | */ |
819 | - public static function is_readable( $value ) { |
|
820 | - return ! empty( $value ) && ! in_array( $value, array( |
|
819 | + public static function is_readable($value) { |
|
820 | + return ! empty($value) && ! in_array($value, array( |
|
821 | 821 | WP_REST_Server::CREATABLE, |
822 | 822 | WP_REST_Server::EDITABLE, |
823 | 823 | WP_REST_Server::DELETABLE, |
824 | - ), true ); |
|
824 | + ), true); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | /** |
@@ -835,11 +835,11 @@ discard block |
||
835 | 835 | * |
836 | 836 | * @return boolean Whether value is considered editable. |
837 | 837 | */ |
838 | - public static function is_editable( $value ) { |
|
839 | - return in_array( $value, array( |
|
838 | + public static function is_editable($value) { |
|
839 | + return in_array($value, array( |
|
840 | 840 | WP_REST_Server::EDITABLE, |
841 | 841 | WP_REST_Server::ALLMETHODS, |
842 | - ), true ); |
|
842 | + ), true); |
|
843 | 843 | } |
844 | 844 | |
845 | 845 | /** |
@@ -850,15 +850,15 @@ discard block |
||
850 | 850 | * |
851 | 851 | * @return mixed |
852 | 852 | */ |
853 | - public function __get( $field ) { |
|
854 | - switch ( $field ) { |
|
853 | + public function __get($field) { |
|
854 | + switch ($field) { |
|
855 | 855 | case 'read_fields': |
856 | 856 | case 'edit_fields': |
857 | 857 | case 'rest_read': |
858 | 858 | case 'rest_edit': |
859 | 859 | return $this->{$field}; |
860 | 860 | default: |
861 | - throw new Exception( 'Invalid ' . __CLASS__ . ' property: ' . $field ); |
|
861 | + throw new Exception('Invalid ' . __CLASS__ . ' property: ' . $field); |
|
862 | 862 | } |
863 | 863 | } |
864 | 864 |
@@ -21,17 +21,17 @@ |
||
21 | 21 | |
22 | 22 | public function render() { |
23 | 23 | return $this->rendered( |
24 | - $this->types->radio( array( |
|
24 | + $this->types->radio(array( |
|
25 | 25 | 'options' => $this->get_term_options(), |
26 | - ), 'taxonomy_radio_hierarchical' ) |
|
26 | + ), 'taxonomy_radio_hierarchical') |
|
27 | 27 | ); |
28 | 28 | } |
29 | 29 | |
30 | - protected function list_term_input( $term, $saved_term ) { |
|
31 | - $options = parent::list_term_input( $term, $saved_term ); |
|
32 | - $children = $this->build_children( $term, $saved_term ); |
|
30 | + protected function list_term_input($term, $saved_term) { |
|
31 | + $options = parent::list_term_input($term, $saved_term); |
|
32 | + $children = $this->build_children($term, $saved_term); |
|
33 | 33 | |
34 | - if ( ! empty( $children ) ) { |
|
34 | + if ( ! empty($children)) { |
|
35 | 35 | $options .= $children; |
36 | 36 | } |
37 | 37 |
@@ -18,26 +18,26 @@ |
||
18 | 18 | * @return string Heading element |
19 | 19 | */ |
20 | 20 | public function render() { |
21 | - $name = $this->field->args( 'name' ); |
|
21 | + $name = $this->field->args('name'); |
|
22 | 22 | $tag = 'span'; |
23 | 23 | |
24 | - if ( ! empty( $name ) ) { |
|
24 | + if ( ! empty($name)) { |
|
25 | 25 | $tag = $this->field->object_type == 'post' ? 'h5' : 'h3'; |
26 | 26 | } |
27 | 27 | |
28 | - $a = $this->parse_args( 'title', array( |
|
28 | + $a = $this->parse_args('title', array( |
|
29 | 29 | 'tag' => $tag, |
30 | - 'class' => empty( $name ) ? 'cmb2-metabox-title-anchor' : 'cmb2-metabox-title', |
|
30 | + 'class' => empty($name) ? 'cmb2-metabox-title-anchor' : 'cmb2-metabox-title', |
|
31 | 31 | 'name' => $name, |
32 | - 'desc' => $this->_desc( true ), |
|
33 | - 'id' => str_replace( '_', '-', sanitize_html_class( $this->field->id() ) ), |
|
34 | - ) ); |
|
32 | + 'desc' => $this->_desc(true), |
|
33 | + 'id' => str_replace('_', '-', sanitize_html_class($this->field->id())), |
|
34 | + )); |
|
35 | 35 | |
36 | 36 | return $this->rendered( |
37 | 37 | sprintf( |
38 | 38 | '<%1$s %2$s>%3$s</%1$s>%4$s', |
39 | 39 | $a['tag'], |
40 | - $this->concat_attrs( $a, array( 'tag', 'name', 'desc' ) ), |
|
40 | + $this->concat_attrs($a, array('tag', 'name', 'desc')), |
|
41 | 41 | $a['name'], |
42 | 42 | $a['desc'] |
43 | 43 | ) |
@@ -19,21 +19,21 @@ |
||
19 | 19 | */ |
20 | 20 | public $type = 'checkbox'; |
21 | 21 | |
22 | - public function render( $args = array() ) { |
|
23 | - $classes = false === $this->field->args( 'select_all_button' ) |
|
22 | + public function render($args = array()) { |
|
23 | + $classes = false === $this->field->args('select_all_button') |
|
24 | 24 | ? 'cmb2-checkbox-list no-select-all cmb2-list' |
25 | 25 | : 'cmb2-checkbox-list cmb2-list'; |
26 | 26 | |
27 | - $args = $this->parse_args( $this->type, array( |
|
27 | + $args = $this->parse_args($this->type, array( |
|
28 | 28 | 'class' => $classes, |
29 | - 'options' => $this->concat_items( array( |
|
29 | + 'options' => $this->concat_items(array( |
|
30 | 30 | 'name' => $this->_name() . '[]', |
31 | 31 | 'method' => 'list_input_checkbox', |
32 | - ) ), |
|
33 | - 'desc' => $this->_desc( true ), |
|
34 | - ) ); |
|
32 | + )), |
|
33 | + 'desc' => $this->_desc(true), |
|
34 | + )); |
|
35 | 35 | |
36 | - return $this->rendered( $this->ul( $args ) ); |
|
36 | + return $this->rendered($this->ul($args)); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | } |
@@ -21,18 +21,18 @@ |
||
21 | 21 | |
22 | 22 | public function render() { |
23 | 23 | return $this->rendered( |
24 | - $this->types->radio( array( |
|
24 | + $this->types->radio(array( |
|
25 | 25 | 'class' => $this->get_wrapper_classes(), |
26 | 26 | 'options' => $this->get_term_options(), |
27 | - ), 'taxonomy_multicheck_hierarchical' ) |
|
27 | + ), 'taxonomy_multicheck_hierarchical') |
|
28 | 28 | ); |
29 | 29 | } |
30 | 30 | |
31 | - protected function list_term_input( $term, $saved_terms ) { |
|
32 | - $options = parent::list_term_input( $term, $saved_terms ); |
|
33 | - $children = $this->build_children( $term, $saved_terms ); |
|
31 | + protected function list_term_input($term, $saved_terms) { |
|
32 | + $options = parent::list_term_input($term, $saved_terms); |
|
33 | + $children = $this->build_children($term, $saved_terms); |
|
34 | 34 | |
35 | - if ( ! empty( $children ) ) { |
|
35 | + if ( ! empty($children)) { |
|
36 | 36 | $options .= $children; |
37 | 37 | } |
38 | 38 |