@@ -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 | |
@@ -30,47 +30,47 @@ discard block |
||
| 30 | 30 | * |
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | - public function char_counter_markup( $val ) { |
|
| 33 | + public function char_counter_markup($val) { |
|
| 34 | 34 | $markup = ''; |
| 35 | 35 | |
| 36 | - if ( ! $this->field->args( 'char_counter' ) ) { |
|
| 36 | + if ( ! $this->field->args('char_counter')) { |
|
| 37 | 37 | return $markup; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - $type = (string) $this->field->args( 'char_counter' ); |
|
| 41 | - $field_id = $this->_id( '', false ); |
|
| 42 | - $char_max = (int) $this->field->prop( 'char_max' ); |
|
| 43 | - if ( $char_max ) { |
|
| 40 | + $type = (string) $this->field->args('char_counter'); |
|
| 41 | + $field_id = $this->_id('', false); |
|
| 42 | + $char_max = (int) $this->field->prop('char_max'); |
|
| 43 | + if ($char_max) { |
|
| 44 | 44 | $char_max = 'data-max="' . $char_max . '"'; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - switch ( $type ) { |
|
| 47 | + switch ($type) { |
|
| 48 | 48 | case 'words': |
| 49 | 49 | $label = $char_max |
| 50 | - ? $this->_text( 'words_left_text', esc_html__( 'Words left', 'cmb2' ) ) |
|
| 51 | - : $this->_text( 'words_text', esc_html__( 'Words', 'cmb2' ) ); |
|
| 50 | + ? $this->_text('words_left_text', esc_html__('Words left', 'cmb2')) |
|
| 51 | + : $this->_text('words_text', esc_html__('Words', 'cmb2')); |
|
| 52 | 52 | break; |
| 53 | 53 | default: |
| 54 | 54 | $type = 'characters'; |
| 55 | 55 | $label = $char_max |
| 56 | - ? $this->_text( 'characters_left_text', esc_html__( 'Characters left', 'cmb2' ) ) |
|
| 57 | - : $this->_text( 'characters_text', esc_html__( 'Characters', 'cmb2' ) ); |
|
| 56 | + ? $this->_text('characters_left_text', esc_html__('Characters left', 'cmb2')) |
|
| 57 | + : $this->_text('characters_text', esc_html__('Characters', 'cmb2')); |
|
| 58 | 58 | break; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $msg = $char_max |
| 62 | - ? sprintf( '<span class="cmb2-char-max-msg">%s</span>', $this->_text( 'characters_truncated_text', esc_html__( 'Your text may be truncated.', 'cmb2' ) ) ) |
|
| 62 | + ? sprintf('<span class="cmb2-char-max-msg">%s</span>', $this->_text('characters_truncated_text', esc_html__('Your text may be truncated.', 'cmb2'))) |
|
| 63 | 63 | : ''; |
| 64 | 64 | |
| 65 | - $length = strlen( $val ); |
|
| 66 | - $width = $length > 1 ? ( 8 * strlen( (string) $length ) ) + 15 : false; |
|
| 65 | + $length = strlen($val); |
|
| 66 | + $width = $length > 1 ? (8 * strlen((string) $length)) + 15 : false; |
|
| 67 | 67 | |
| 68 | 68 | $markup .= '<p class="cmb2-char-counter-wrap">'; |
| 69 | 69 | $markup .= sprintf( |
| 70 | 70 | '<label><span class="cmb2-char-counter-label">%2$s:</span> <input id="%1$s" data-field-id="%3$s" data-counter-type="%4$s" %5$s class="cmb2-char-counter" type="text" value="%6$s" readonly="readonly" style="%7$s"></label>%8$s', |
| 71 | - esc_attr( 'char-counter-' . $field_id ), |
|
| 71 | + esc_attr('char-counter-' . $field_id), |
|
| 72 | 72 | $label, |
| 73 | - esc_attr( $field_id ), |
|
| 73 | + esc_attr($field_id), |
|
| 74 | 74 | $type, |
| 75 | 75 | $char_max, |
| 76 | 76 | $length, |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | $markup .= '</p>'; |
| 81 | 81 | |
| 82 | 82 | // Enqueue the required JS. |
| 83 | - $this->field->add_js_dependencies( array( |
|
| 83 | + $this->field->add_js_dependencies(array( |
|
| 84 | 84 | 'word-count', |
| 85 | 85 | 'wp-util', |
| 86 | 86 | 'cmb2-char-counter', |
| 87 | - ) ); |
|
| 87 | + )); |
|
| 88 | 88 | |
| 89 | 89 | $this->has_counter = true; |
| 90 | 90 | |
@@ -100,16 +100,16 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @return array Potentially modified attributes. |
| 102 | 102 | */ |
| 103 | - public function maybe_update_attributes_for_char_counter( $attributes ) { |
|
| 104 | - $char_counter = $this->char_counter_markup( $attributes['value'] ); |
|
| 103 | + public function maybe_update_attributes_for_char_counter($attributes) { |
|
| 104 | + $char_counter = $this->char_counter_markup($attributes['value']); |
|
| 105 | 105 | |
| 106 | 106 | // Has character counter? |
| 107 | - if ( $char_counter ) { |
|
| 108 | - $attributes['class'] = ! empty( $attributes['class'] ) ? $attributes['class'] . ' cmb2-count-chars' : ' cmb2-count-chars'; |
|
| 107 | + if ($char_counter) { |
|
| 108 | + $attributes['class'] = ! empty($attributes['class']) ? $attributes['class'] . ' cmb2-count-chars' : ' cmb2-count-chars'; |
|
| 109 | 109 | |
| 110 | 110 | // Enforce max chars? |
| 111 | 111 | $max = $this->enforce_max(); |
| 112 | - if ( $max ) { |
|
| 112 | + if ($max) { |
|
| 113 | 113 | $attributes['maxlength'] = $max; |
| 114 | 114 | } |
| 115 | 115 | $attributes['desc'] = $char_counter . $attributes['desc']; |
@@ -126,11 +126,11 @@ discard block |
||
| 126 | 126 | * @return bool Whether to enforce max characters. |
| 127 | 127 | */ |
| 128 | 128 | public function enforce_max() { |
| 129 | - $char_max = (int) $this->field->args( 'char_max' ); |
|
| 129 | + $char_max = (int) $this->field->args('char_max'); |
|
| 130 | 130 | |
| 131 | 131 | // Enforce max chars? |
| 132 | - return ( $this->field->args( 'char_max_enforce' ) && $char_max > 0 |
|
| 133 | - && 'words' !== $this->field->args( 'char_counter' ) ) |
|
| 132 | + return ($this->field->args('char_max_enforce') && $char_max > 0 |
|
| 133 | + && 'words' !== $this->field->args('char_counter')) |
|
| 134 | 134 | ? $char_max |
| 135 | 135 | : false; |
| 136 | 136 | } |
@@ -12,19 +12,19 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class CMB2_Type_Text_Date extends CMB2_Type_Picker_Base { |
| 14 | 14 | |
| 15 | - public function render( $args = array() ) { |
|
| 16 | - $args = $this->parse_args( 'text_date', array( |
|
| 15 | + public function render($args = array()) { |
|
| 16 | + $args = $this->parse_args('text_date', array( |
|
| 17 | 17 | 'class' => 'cmb2-text-small cmb2-datepicker', |
| 18 | 18 | 'value' => $this->field->get_timestamp_format(), |
| 19 | 19 | 'desc' => $this->_desc(), |
| 20 | - 'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker' ), |
|
| 21 | - ) ); |
|
| 20 | + 'js_dependencies' => array('jquery-ui-core', 'jquery-ui-datepicker'), |
|
| 21 | + )); |
|
| 22 | 22 | |
| 23 | - if ( false === strpos( $args['class'], 'timepicker' ) ) { |
|
| 24 | - $this->parse_picker_options( 'date' ); |
|
| 23 | + if (false === strpos($args['class'], 'timepicker')) { |
|
| 24 | + $this->parse_picker_options('date'); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - return parent::render( $args ); |
|
| 27 | + return parent::render($args); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | } |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | * @param array $args Array of arguments for the type. |
| 29 | 29 | * @param mixed $is_checked Whether or not the field is checked, or default value. |
| 30 | 30 | */ |
| 31 | - public function __construct( CMB2_Types $types, $args = array(), $is_checked = null ) { |
|
| 32 | - parent::__construct( $types, $args ); |
|
| 31 | + public function __construct(CMB2_Types $types, $args = array(), $is_checked = null) { |
|
| 32 | + parent::__construct($types, $args); |
|
| 33 | 33 | $this->is_checked = $is_checked; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param array $args Array of arguments for the rendering. |
| 42 | 42 | * @return CMB2_Type_Base|string |
| 43 | 43 | */ |
| 44 | - public function render( $args = array() ) { |
|
| 44 | + public function render($args = array()) { |
|
| 45 | 45 | $defaults = array( |
| 46 | 46 | 'type' => 'checkbox', |
| 47 | 47 | 'class' => 'cmb2-option cmb2-list', |
@@ -52,20 +52,20 @@ discard block |
||
| 52 | 52 | $meta_value = $this->field->escaped_value(); |
| 53 | 53 | |
| 54 | 54 | $is_checked = null === $this->is_checked |
| 55 | - ? ! empty( $meta_value ) |
|
| 55 | + ? ! empty($meta_value) |
|
| 56 | 56 | : $this->is_checked; |
| 57 | 57 | |
| 58 | - if ( $is_checked ) { |
|
| 58 | + if ($is_checked) { |
|
| 59 | 59 | $defaults['checked'] = 'checked'; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $args = $this->parse_args( 'checkbox', $defaults ); |
|
| 62 | + $args = $this->parse_args('checkbox', $defaults); |
|
| 63 | 63 | |
| 64 | 64 | return $this->rendered( |
| 65 | 65 | sprintf( |
| 66 | 66 | '%s <label for="%s">%s</label>', |
| 67 | - parent::render( $args ), |
|
| 68 | - $this->_id( '', false ), |
|
| 67 | + parent::render($args), |
|
| 68 | + $this->_id('', false), |
|
| 69 | 69 | $this->_desc() |
| 70 | 70 | ) |
| 71 | 71 | ); |