@@ -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 | ); |
@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | * @param CMB2_Types $types Object for the field type. |
| 41 | 41 | * @param array $args Array of arguments for the type. |
| 42 | 42 | */ |
| 43 | - public function __construct( CMB2_Types $types, $args = array() ) { |
|
| 43 | + public function __construct(CMB2_Types $types, $args = array()) { |
|
| 44 | 44 | $this->types = $types; |
| 45 | - $args['rendered'] = isset( $args['rendered'] ) ? (bool) $args['rendered'] : true; |
|
| 45 | + $args['rendered'] = isset($args['rendered']) ? (bool) $args['rendered'] : true; |
|
| 46 | 46 | $this->args = $args; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | * @param string|CMB2_Type_Base $rendered Rendered output. |
| 62 | 62 | * @return string|CMB2_Type_Base Rendered output or this object. |
| 63 | 63 | */ |
| 64 | - public function rendered( $rendered ) { |
|
| 64 | + public function rendered($rendered) { |
|
| 65 | 65 | $this->field->register_js_data(); |
| 66 | 66 | |
| 67 | - if ( $this->args['rendered'] ) { |
|
| 68 | - return is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered; |
|
| 67 | + if ($this->args['rendered']) { |
|
| 68 | + return is_a($rendered, __CLASS__) ? $rendered->rendered : $rendered; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - $this->rendered = is_a( $rendered, __CLASS__ ) ? $rendered->rendered : $rendered; |
|
| 71 | + $this->rendered = is_a($rendered, __CLASS__) ? $rendered->rendered : $rendered; |
|
| 72 | 72 | |
| 73 | 73 | return $this; |
| 74 | 74 | } |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | * @param array $type_overrides Type override arguments. |
| 93 | 93 | * @return array Parsed and filtered arguments. |
| 94 | 94 | */ |
| 95 | - public function parse_args( $element, $type_defaults, $type_overrides = array() ) { |
|
| 96 | - $args = $this->parse_args_from_overrides( $type_overrides ); |
|
| 95 | + public function parse_args($element, $type_defaults, $type_overrides = array()) { |
|
| 96 | + $args = $this->parse_args_from_overrides($type_overrides); |
|
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | 99 | * Filter attributes for a field type. |
@@ -105,12 +105,12 @@ discard block |
||
| 105 | 105 | * @param array $field The `CMB2_Field` object. |
| 106 | 106 | * @param object $field_type_object This `CMB2_Types` object. |
| 107 | 107 | */ |
| 108 | - $args = apply_filters( "cmb2_{$element}_attributes", $args, $type_defaults, $this->field, $this->types ); |
|
| 108 | + $args = apply_filters("cmb2_{$element}_attributes", $args, $type_defaults, $this->field, $this->types); |
|
| 109 | 109 | |
| 110 | - $args = wp_parse_args( $args, $type_defaults ); |
|
| 110 | + $args = wp_parse_args($args, $type_defaults); |
|
| 111 | 111 | |
| 112 | - if ( ! empty( $args['js_dependencies'] ) ) { |
|
| 113 | - $this->field->add_js_dependencies( $args['js_dependencies'] ); |
|
| 112 | + if ( ! empty($args['js_dependencies'])) { |
|
| 113 | + $this->field->add_js_dependencies($args['js_dependencies']); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | return $args; |
@@ -123,17 +123,17 @@ discard block |
||
| 123 | 123 | * @param array $type_overrides Type override arguments. |
| 124 | 124 | * @return array Parsed arguments |
| 125 | 125 | */ |
| 126 | - protected function parse_args_from_overrides( $type_overrides = array() ) { |
|
| 127 | - $type_overrides = empty( $type_overrides ) ? $this->args : $type_overrides; |
|
| 126 | + protected function parse_args_from_overrides($type_overrides = array()) { |
|
| 127 | + $type_overrides = empty($type_overrides) ? $this->args : $type_overrides; |
|
| 128 | 128 | |
| 129 | - if ( true !== $this->field->args( 'disable_hash_data_attribute' ) ) { |
|
| 129 | + if (true !== $this->field->args('disable_hash_data_attribute')) { |
|
| 130 | 130 | $type_overrides['data-hash'] = $this->field->hash_id(); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $field_overrides = $this->field->args( 'attributes' ); |
|
| 133 | + $field_overrides = $this->field->args('attributes'); |
|
| 134 | 134 | |
| 135 | - return ! empty( $field_overrides ) |
|
| 136 | - ? wp_parse_args( $field_overrides, $type_overrides ) |
|
| 135 | + return ! empty($field_overrides) |
|
| 136 | + ? wp_parse_args($field_overrides, $type_overrides) |
|
| 137 | 137 | : $type_overrides; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -145,16 +145,16 @@ discard block |
||
| 145 | 145 | * @throws Exception Throws an exception if the field is invalid. |
| 146 | 146 | * @return mixed |
| 147 | 147 | */ |
| 148 | - public function __call( $method, $arguments ) { |
|
| 149 | - switch ( $method ) { |
|
| 148 | + public function __call($method, $arguments) { |
|
| 149 | + switch ($method) { |
|
| 150 | 150 | case '_id': |
| 151 | 151 | case '_name': |
| 152 | 152 | case '_desc': |
| 153 | 153 | case '_text': |
| 154 | 154 | case 'concat_attrs': |
| 155 | - return call_user_func_array( array( $this->types, $method ), $arguments ); |
|
| 155 | + return call_user_func_array(array($this->types, $method), $arguments); |
|
| 156 | 156 | default: |
| 157 | - throw new Exception( sprintf( esc_html__( 'Invalid %1$s method: %2$s', 'cmb2' ), __CLASS__, $method ) ); |
|
| 157 | + throw new Exception(sprintf(esc_html__('Invalid %1$s method: %2$s', 'cmb2'), __CLASS__, $method)); |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
@@ -165,12 +165,12 @@ discard block |
||
| 165 | 165 | * @throws Exception Throws an exception if the field is invalid. |
| 166 | 166 | * @return mixed |
| 167 | 167 | */ |
| 168 | - public function __get( $field ) { |
|
| 169 | - switch ( $field ) { |
|
| 168 | + public function __get($field) { |
|
| 169 | + switch ($field) { |
|
| 170 | 170 | case 'field': |
| 171 | 171 | return $this->types->field; |
| 172 | 172 | default: |
| 173 | - throw new Exception( sprintf( esc_html__( 'Invalid %1$s property: %2$s', 'cmb2' ), __CLASS__, $field ) ); |
|
| 173 | + throw new Exception(sprintf(esc_html__('Invalid %1$s property: %2$s', 'cmb2'), __CLASS__, $field)); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |