@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $cmb = CMB2_Boxes::get( $meta_box ); |
179 | 179 | } else { |
180 | 180 | // See if we already have an instance of this metabox |
181 | - $cmb = CMB2_Boxes::get( $meta_box['id'] ); |
|
181 | + $cmb = CMB2_Boxes::get( $meta_box[ 'id' ] ); |
|
182 | 182 | // If not, we'll initate a new metabox |
183 | 183 | $cmb = $cmb ? $cmb : new CMB2( $meta_box, $object_id ); |
184 | 184 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | ) ); |
255 | 255 | |
256 | 256 | // Set object type explicitly (rather than trying to guess from context) |
257 | - $cmb->object_type( $args['object_type'] ); |
|
257 | + $cmb->object_type( $args[ 'object_type' ] ); |
|
258 | 258 | |
259 | 259 | // Save the metabox if it's been submitted |
260 | 260 | // check permissions |
@@ -262,32 +262,32 @@ discard block |
||
262 | 262 | if ( |
263 | 263 | $cmb->prop( 'save_fields' ) |
264 | 264 | // check nonce |
265 | - && isset( $_POST['submit-cmb'], $_POST['object_id'], $_POST[ $cmb->nonce() ] ) |
|
265 | + && isset( $_POST[ 'submit-cmb' ], $_POST[ 'object_id' ], $_POST[ $cmb->nonce() ] ) |
|
266 | 266 | && wp_verify_nonce( $_POST[ $cmb->nonce() ], $cmb->nonce() ) |
267 | - && $object_id && $_POST['object_id'] == $object_id |
|
267 | + && $object_id && $_POST[ 'object_id' ] == $object_id |
|
268 | 268 | ) { |
269 | 269 | $cmb->save_fields( $object_id, $cmb->object_type(), $_POST ); |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Enqueue JS/CSS |
273 | - if ( $args['cmb_styles'] ) { |
|
273 | + if ( $args[ 'cmb_styles' ] ) { |
|
274 | 274 | CMB2_hookup::enqueue_cmb_css(); |
275 | 275 | } |
276 | 276 | |
277 | - if ( $args['enqueue_js'] ) { |
|
277 | + if ( $args[ 'enqueue_js' ] ) { |
|
278 | 278 | CMB2_hookup::enqueue_cmb_js(); |
279 | 279 | } |
280 | 280 | |
281 | - $form_format = apply_filters( 'cmb2_get_metabox_form_format', $args['form_format'], $object_id, $cmb ); |
|
281 | + $form_format = apply_filters( 'cmb2_get_metabox_form_format', $args[ 'form_format' ], $object_id, $cmb ); |
|
282 | 282 | |
283 | 283 | $format_parts = explode( '%3$s', $form_format ); |
284 | 284 | |
285 | 285 | // Show cmb form |
286 | - printf( $format_parts[0], $cmb->cmb_id, $object_id ); |
|
286 | + printf( $format_parts[ 0 ], $cmb->cmb_id, $object_id ); |
|
287 | 287 | $cmb->show_form(); |
288 | 288 | |
289 | - if ( isset( $format_parts[1] ) && $format_parts[1] ) { |
|
290 | - printf( str_ireplace( '%4$s', '%1$s', $format_parts[1] ), $args['save_button'] ); |
|
289 | + if ( isset( $format_parts[ 1 ] ) && $format_parts[ 1 ] ) { |
|
290 | + printf( str_ireplace( '%4$s', '%1$s', $format_parts[ 1 ] ), $args[ 'save_button' ] ); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | } |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | * @param array $args Optional arguments array |
301 | 301 | */ |
302 | 302 | function cmb2_metabox_form( $meta_box, $object_id = 0, $args = array() ) { |
303 | - if ( ! isset( $args['echo'] ) || $args['echo'] ) { |
|
303 | + if ( ! isset( $args[ 'echo' ] ) || $args[ 'echo' ] ) { |
|
304 | 304 | cmb2_print_metabox_form( $meta_box, $object_id, $args ); |
305 | 305 | } else { |
306 | 306 | return cmb2_get_metabox_form( $meta_box, $object_id, $args ); |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | |
323 | 323 | $schedule_format = str_replace( |
324 | 324 | array( 'M', 'Y', 'm', 'd', 'H', 'i', 'a' ), |
325 | - array('%b', '%Y', '%m', '%d', '%H', '%M', '%p' ), |
|
325 | + array( '%b', '%Y', '%m', '%d', '%H', '%M', '%p' ), |
|
326 | 326 | $date_format |
327 | 327 | ); |
328 | 328 | |
@@ -339,14 +339,14 @@ discard block |
||
339 | 339 | * 4 or 2 characters, as needed |
340 | 340 | */ |
341 | 341 | '%04d-%02d-%02d %02d:%02d:%02d', |
342 | - $parsed_time['tm_year'] + 1900, // This will be "111", so we need to add 1900. |
|
343 | - $parsed_time['tm_mon'] + 1, // This will be the month minus one, so we add one. |
|
344 | - $parsed_time['tm_mday'], |
|
345 | - $parsed_time['tm_hour'], |
|
346 | - $parsed_time['tm_min'], |
|
347 | - $parsed_time['tm_sec'] |
|
342 | + $parsed_time[ 'tm_year' ] + 1900, // This will be "111", so we need to add 1900. |
|
343 | + $parsed_time[ 'tm_mon' ] + 1, // This will be the month minus one, so we add one. |
|
344 | + $parsed_time[ 'tm_mday' ], |
|
345 | + $parsed_time[ 'tm_hour' ], |
|
346 | + $parsed_time[ 'tm_min' ], |
|
347 | + $parsed_time[ 'tm_sec' ] |
|
348 | 348 | ); |
349 | 349 | |
350 | - return new DateTime($ymd); |
|
350 | + return new DateTime( $ymd ); |
|
351 | 351 | } |
352 | 352 | } |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Bootstraps the CMB2 process |
|
4 | - * |
|
5 | - * @category WordPress_Plugin |
|
6 | - * @package CMB2 |
|
7 | - * @author WebDevStudios |
|
8 | - * @license GPL-2.0+ |
|
9 | - * @link http://webdevstudios.com |
|
10 | - */ |
|
3 | + * Bootstraps the CMB2 process |
|
4 | + * |
|
5 | + * @category WordPress_Plugin |
|
6 | + * @package CMB2 |
|
7 | + * @author WebDevStudios |
|
8 | + * @license GPL-2.0+ |
|
9 | + * @link http://webdevstudios.com |
|
10 | + */ |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * Function to encapsulate the CMB2 bootstrap process. |
@@ -74,7 +74,7 @@ |
||
74 | 74 | * Retrieve all CMB2 instances that have the specified property set. |
75 | 75 | * @since 2.2.0 |
76 | 76 | * @param string $property Property name. |
77 | - * @param mixed $ignore The value to ignore. |
|
77 | + * @param boolean $ignore The value to ignore. |
|
78 | 78 | * @return CMB2[] Array of matching cmb2 instances. |
79 | 79 | */ |
80 | 80 | public static function get_by_property( $property, $ignore = null ) { |
@@ -54,7 +54,7 @@ |
||
54 | 54 | return; |
55 | 55 | } |
56 | 56 | |
57 | - self::$hooks_completed[] = $key; |
|
57 | + self::$hooks_completed[ ] = $key; |
|
58 | 58 | add_filter( $action, $hook, $priority, $accepted_args ); |
59 | 59 | } |
60 | 60 |
@@ -117,16 +117,16 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function __construct( $args ) { |
119 | 119 | |
120 | - if ( ! empty( $args['group_field'] ) ) { |
|
121 | - $this->group = $args['group_field']; |
|
120 | + if ( ! empty( $args[ 'group_field' ] ) ) { |
|
121 | + $this->group = $args[ 'group_field' ]; |
|
122 | 122 | $this->object_id = $this->group->object_id; |
123 | 123 | $this->object_type = $this->group->object_type; |
124 | 124 | } else { |
125 | - $this->object_id = isset( $args['object_id'] ) && '_' !== $args['object_id'] ? $args['object_id'] : 0; |
|
126 | - $this->object_type = isset( $args['object_type'] ) ? $args['object_type'] : 'post'; |
|
125 | + $this->object_id = isset( $args[ 'object_id' ] ) && '_' !== $args[ 'object_id' ] ? $args[ 'object_id' ] : 0; |
|
126 | + $this->object_type = isset( $args[ 'object_type' ] ) ? $args[ 'object_type' ] : 'post'; |
|
127 | 127 | } |
128 | 128 | |
129 | - $this->args = $this->_set_field_defaults( $args['field_args'] ); |
|
129 | + $this->args = $this->_set_field_defaults( $args[ 'field_args' ] ); |
|
130 | 130 | |
131 | 131 | if ( $this->object_id ) { |
132 | 132 | $this->value = $this->get_data(); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * @return mixed Value of field argument |
142 | 142 | */ |
143 | 143 | public function __call( $name, $arguments ) { |
144 | - $key = isset( $arguments[0] ) ? $arguments[0] : false; |
|
144 | + $key = isset( $arguments[ 0 ] ) ? $arguments[ 0 ] : false; |
|
145 | 145 | return $this->args( $name, $key ); |
146 | 146 | } |
147 | 147 | |
@@ -212,9 +212,9 @@ discard block |
||
212 | 212 | */ |
213 | 213 | public function get_data( $field_id = '', $args = array() ) { |
214 | 214 | if ( $field_id ) { |
215 | - $args['field_id'] = $field_id; |
|
215 | + $args[ 'field_id' ] = $field_id; |
|
216 | 216 | } else if ( $this->group ) { |
217 | - $args['field_id'] = $this->group->id(); |
|
217 | + $args[ 'field_id' ] = $this->group->id(); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | $a = $this->data_args( $args ); |
@@ -255,13 +255,13 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @since 2.0.0 |
257 | 257 | */ |
258 | - $data = apply_filters( "cmb2_override_{$a['field_id']}_meta_value", $data, $this->object_id, $a, $this ); |
|
258 | + $data = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_value", $data, $this->object_id, $a, $this ); |
|
259 | 259 | |
260 | 260 | // If no override, get value normally |
261 | 261 | if ( 'cmb2_field_no_override_val' === $data ) { |
262 | - $data = 'options-page' === $a['type'] |
|
263 | - ? cmb2_options( $a['id'] )->get( $a['field_id'] ) |
|
264 | - : get_metadata( $a['type'], $a['id'], $a['field_id'], ( $a['single'] || $a['repeat'] ) ); |
|
262 | + $data = 'options-page' === $a[ 'type' ] |
|
263 | + ? cmb2_options( $a[ 'id' ] )->get( $a[ 'field_id' ] ) |
|
264 | + : get_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], ( $a[ 'single' ] || $a[ 'repeat' ] ) ); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | if ( $this->group ) { |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | public function update_data( $new_value, $single = true ) { |
284 | 284 | $a = $this->data_args( array( 'single' => $single ) ); |
285 | 285 | |
286 | - $a['value'] = $a['repeat'] ? array_values( $new_value ) : $new_value; |
|
286 | + $a[ 'value' ] = $a[ 'repeat' ] ? array_values( $new_value ) : $new_value; |
|
287 | 287 | |
288 | 288 | /** |
289 | 289 | * Filter whether to override saving of meta value. |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * |
320 | 320 | * @since 2.0.0 |
321 | 321 | */ |
322 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_save", $override, $a, $this->args(), $this ); |
|
322 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_save", $override, $a, $this->args(), $this ); |
|
323 | 323 | |
324 | 324 | // If override, return that |
325 | 325 | if ( null !== $override ) { |
@@ -327,22 +327,22 @@ discard block |
||
327 | 327 | } |
328 | 328 | |
329 | 329 | // Options page handling (or temp data store) |
330 | - if ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
331 | - return cmb2_options( $a['id'] )->update( $a['field_id'], $a['value'], false, $a['single'] ); |
|
330 | + if ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
331 | + return cmb2_options( $a[ 'id' ] )->update( $a[ 'field_id' ], $a[ 'value' ], false, $a[ 'single' ] ); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | // Add metadata if not single |
335 | - if ( ! $a['single'] ) { |
|
336 | - return add_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'], false ); |
|
335 | + if ( ! $a[ 'single' ] ) { |
|
336 | + return add_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ], false ); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Delete meta if we have an empty array |
340 | - if ( is_array( $a['value'] ) && empty( $a['value'] ) ) { |
|
341 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $this->value ); |
|
340 | + if ( is_array( $a[ 'value' ] ) && empty( $a[ 'value' ] ) ) { |
|
341 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $this->value ); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | // Update metadata |
345 | - return update_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'] ); |
|
345 | + return update_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ] ); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -392,19 +392,19 @@ discard block |
||
392 | 392 | * @param array $field_args All field arguments |
393 | 393 | * @param CMB2_Field object $field This field object |
394 | 394 | */ |
395 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_remove", $override, $a, $this->args(), $this ); |
|
395 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_remove", $override, $a, $this->args(), $this ); |
|
396 | 396 | |
397 | 397 | // If no override, remove as usual |
398 | 398 | if ( null !== $override ) { |
399 | 399 | return $override; |
400 | 400 | } |
401 | 401 | // Option page handling |
402 | - elseif ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
403 | - return cmb2_options( $a['id'] )->remove( $a['field_id'] ); |
|
402 | + elseif ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
403 | + return cmb2_options( $a[ 'id' ] )->remove( $a[ 'field_id' ] ); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | // Remove metadata |
407 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $old ); |
|
407 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $old ); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | /** |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | |
877 | 877 | foreach ( $conditional_classes as $class => $condition ) { |
878 | 878 | if ( $condition ) { |
879 | - $classes[] = $class; |
|
879 | + $classes[ ] = $class; |
|
880 | 880 | } |
881 | 881 | } |
882 | 882 | |
@@ -885,7 +885,7 @@ discard block |
||
885 | 885 | } |
886 | 886 | |
887 | 887 | if ( $added_classes ) { |
888 | - $classes[] = esc_attr( $added_classes ); |
|
888 | + $classes[ ] = esc_attr( $added_classes ); |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | /** |
@@ -990,10 +990,10 @@ discard block |
||
990 | 990 | return $this->field_options; |
991 | 991 | } |
992 | 992 | |
993 | - $this->field_options = (array) $this->args['options']; |
|
993 | + $this->field_options = (array) $this->args[ 'options' ]; |
|
994 | 994 | |
995 | - if ( is_callable( $this->args['options_cb'] ) ) { |
|
996 | - $options = call_user_func( $this->args['options_cb'], $this ); |
|
995 | + if ( is_callable( $this->args[ 'options_cb' ] ) ) { |
|
996 | + $options = call_user_func( $this->args[ 'options_cb' ], $this ); |
|
997 | 997 | |
998 | 998 | if ( $options && is_array( $options ) ) { |
999 | 999 | $this->field_options += $options; |
@@ -1014,7 +1014,7 @@ discard block |
||
1014 | 1014 | */ |
1015 | 1015 | public function add_js_dependencies( $dependencies = array() ) { |
1016 | 1016 | foreach ( (array) $dependencies as $dependency ) { |
1017 | - $this->args['js_dependencies'][ $dependency ] = $dependency; |
|
1017 | + $this->args[ 'js_dependencies' ][ $dependency ] = $dependency; |
|
1018 | 1018 | } |
1019 | 1019 | |
1020 | 1020 | CMB2_JS::add_dependencies( $dependencies ); |
@@ -1041,66 +1041,66 @@ discard block |
||
1041 | 1041 | 'default' => null, |
1042 | 1042 | 'select_all_button' => true, |
1043 | 1043 | 'multiple' => false, |
1044 | - 'repeatable' => isset( $args['type'] ) && 'group' == $args['type'], |
|
1044 | + 'repeatable' => isset( $args[ 'type' ] ) && 'group' == $args[ 'type' ], |
|
1045 | 1045 | 'inline' => false, |
1046 | 1046 | 'on_front' => true, |
1047 | 1047 | 'show_names' => true, |
1048 | 1048 | 'date_format' => 'm\/d\/Y', |
1049 | 1049 | 'time_format' => 'h:i A', |
1050 | - 'description' => isset( $args['desc'] ) ? $args['desc'] : '', |
|
1051 | - 'preview_size' => 'file' == $args['type'] ? array( 350, 350 ) : array( 50, 50 ), |
|
1050 | + 'description' => isset( $args[ 'desc' ] ) ? $args[ 'desc' ] : '', |
|
1051 | + 'preview_size' => 'file' == $args[ 'type' ] ? array( 350, 350 ) : array( 50, 50 ), |
|
1052 | 1052 | 'render_row_cb' => array( $this, 'render_field_callback' ), |
1053 | - 'label_cb' => 'title' != $args['type'] ? array( $this, 'label' ) : '', |
|
1053 | + 'label_cb' => 'title' != $args[ 'type' ] ? array( $this, 'label' ) : '', |
|
1054 | 1054 | 'show_in_rest' => null, |
1055 | 1055 | 'js_dependencies' => array(), |
1056 | 1056 | ) ); |
1057 | 1057 | |
1058 | 1058 | // Allow a filter override of the default value |
1059 | - $args['default'] = apply_filters( 'cmb2_default_filter', $args['default'], $this ); |
|
1060 | - $args['repeatable'] = $args['repeatable'] && ! $this->repeatable_exception( $args['type'] ); |
|
1061 | - $args['inline'] = $args['inline'] || false !== stripos( $args['type'], '_inline' ); |
|
1059 | + $args[ 'default' ] = apply_filters( 'cmb2_default_filter', $args[ 'default' ], $this ); |
|
1060 | + $args[ 'repeatable' ] = $args[ 'repeatable' ] && ! $this->repeatable_exception( $args[ 'type' ] ); |
|
1061 | + $args[ 'inline' ] = $args[ 'inline' ] || false !== stripos( $args[ 'type' ], '_inline' ); |
|
1062 | 1062 | |
1063 | 1063 | // options param can be passed a callback as well |
1064 | - if ( is_callable( $args['options'] ) ) { |
|
1065 | - $args['options_cb'] = $args['options']; |
|
1066 | - $args['options'] = array(); |
|
1064 | + if ( is_callable( $args[ 'options' ] ) ) { |
|
1065 | + $args[ 'options_cb' ] = $args[ 'options' ]; |
|
1066 | + $args[ 'options' ] = array(); |
|
1067 | 1067 | } |
1068 | 1068 | |
1069 | - $args['options'] = 'group' == $args['type'] ? wp_parse_args( $args['options'], array( |
|
1069 | + $args[ 'options' ] = 'group' == $args[ 'type' ] ? wp_parse_args( $args[ 'options' ], array( |
|
1070 | 1070 | 'add_button' => __( 'Add Group', 'cmb2' ), |
1071 | 1071 | 'remove_button' => __( 'Remove Group', 'cmb2' ), |
1072 | - ) ) : $args['options']; |
|
1072 | + ) ) : $args[ 'options' ]; |
|
1073 | 1073 | |
1074 | - $args['_id'] = $args['id']; |
|
1075 | - $args['_name'] = $args['id']; |
|
1074 | + $args[ '_id' ] = $args[ 'id' ]; |
|
1075 | + $args[ '_name' ] = $args[ 'id' ]; |
|
1076 | 1076 | |
1077 | 1077 | if ( $this->group ) { |
1078 | 1078 | |
1079 | - $args['id'] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args['id']; |
|
1080 | - $args['_name'] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args['_name'] . ']'; |
|
1079 | + $args[ 'id' ] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args[ 'id' ]; |
|
1080 | + $args[ '_name' ] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args[ '_name' ] . ']'; |
|
1081 | 1081 | } |
1082 | 1082 | |
1083 | - if ( 'wysiwyg' == $args['type'] ) { |
|
1084 | - $args['id'] = strtolower( str_ireplace( '-', '_', $args['id'] ) ); |
|
1085 | - $args['options']['textarea_name'] = $args['_name']; |
|
1083 | + if ( 'wysiwyg' == $args[ 'type' ] ) { |
|
1084 | + $args[ 'id' ] = strtolower( str_ireplace( '-', '_', $args[ 'id' ] ) ); |
|
1085 | + $args[ 'options' ][ 'textarea_name' ] = $args[ '_name' ]; |
|
1086 | 1086 | } |
1087 | 1087 | |
1088 | 1088 | $option_types = apply_filters( 'cmb2_all_or_nothing_types', array( 'select', 'radio', 'radio_inline', 'taxonomy_select', 'taxonomy_radio', 'taxonomy_radio_inline' ), $this ); |
1089 | 1089 | |
1090 | - if ( in_array( $args['type'], $option_types, true ) ) { |
|
1090 | + if ( in_array( $args[ 'type' ], $option_types, true ) ) { |
|
1091 | 1091 | |
1092 | - $args['show_option_none'] = isset( $args['show_option_none'] ) ? $args['show_option_none'] : null; |
|
1093 | - $args['show_option_none'] = true === $args['show_option_none'] ? __( 'None', 'cmb2' ) : $args['show_option_none']; |
|
1092 | + $args[ 'show_option_none' ] = isset( $args[ 'show_option_none' ] ) ? $args[ 'show_option_none' ] : null; |
|
1093 | + $args[ 'show_option_none' ] = true === $args[ 'show_option_none' ] ? __( 'None', 'cmb2' ) : $args[ 'show_option_none' ]; |
|
1094 | 1094 | |
1095 | - if ( null === $args['show_option_none'] ) { |
|
1096 | - $off_by_default = in_array( $args['type'], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1097 | - $args['show_option_none'] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
1095 | + if ( null === $args[ 'show_option_none' ] ) { |
|
1096 | + $off_by_default = in_array( $args[ 'type' ], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1097 | + $args[ 'show_option_none' ] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | } |
1101 | 1101 | |
1102 | - $args['has_supporting_data'] = in_array( |
|
1103 | - $args['type'], |
|
1102 | + $args[ 'has_supporting_data' ] = in_array( |
|
1103 | + $args[ 'type' ], |
|
1104 | 1104 | array( |
1105 | 1105 | // See CMB2_Sanitize::_save_utc_value() |
1106 | 1106 | 'file', |
@@ -1119,7 +1119,7 @@ discard block |
||
1119 | 1119 | * @param array $attrs Array of attributes to update |
1120 | 1120 | */ |
1121 | 1121 | public function maybe_set_attributes( $attrs = array() ) { |
1122 | - return wp_parse_args( $this->args['attributes'], $attrs ); |
|
1122 | + return wp_parse_args( $this->args[ 'attributes' ], $attrs ); |
|
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | /** |
153 | 153 | * Handler for updating custom field data. |
154 | 154 | * @since 2.2.0 |
155 | - * @param mixed $value The value of the field |
|
155 | + * @param mixed $values The value of the field |
|
156 | 156 | * @param object $object The object from the response |
157 | 157 | * @param string $field_id Name of field |
158 | 158 | * @return bool|int |
@@ -233,6 +233,9 @@ discard block |
||
233 | 233 | return $protected; |
234 | 234 | } |
235 | 235 | |
236 | + /** |
|
237 | + * @param string $field_id |
|
238 | + */ |
|
236 | 239 | public function field_can_update( $field_id ) { |
237 | 240 | |
238 | 241 | $field = $this->cmb->get_field( $field_id ); |
@@ -88,14 +88,14 @@ discard block |
||
88 | 88 | |
89 | 89 | protected function prepare_read_write_fields() { |
90 | 90 | foreach ( $this->cmb->prop( 'fields' ) as $field ) { |
91 | - $show_in_rest = isset( $field['show_in_rest'] ) ? $field['show_in_rest'] : null; |
|
91 | + $show_in_rest = isset( $field[ 'show_in_rest' ] ) ? $field[ 'show_in_rest' ] : null; |
|
92 | 92 | |
93 | 93 | if ( false === $show_in_rest ) { |
94 | 94 | continue; |
95 | 95 | } |
96 | 96 | |
97 | - $this->maybe_add_read_field( $field['id'], $show_in_rest ); |
|
98 | - $this->maybe_add_write_field( $field['id'], $show_in_rest ); |
|
97 | + $this->maybe_add_read_field( $field[ 'id' ], $show_in_rest ); |
|
98 | + $this->maybe_add_write_field( $field[ 'id' ], $show_in_rest ); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | : in_array( $show_in_rest, array( 'read_and_write', 'read_only' ), true ); |
106 | 106 | |
107 | 107 | if ( $can_read ) { |
108 | - self::$read_fields[ $this->cmb->cmb_id ][] = $field_id; |
|
108 | + self::$read_fields[ $this->cmb->cmb_id ][ ] = $field_id; |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | : in_array( $show_in_rest, array( 'read_and_write', 'write_only' ), true ); |
116 | 116 | |
117 | 117 | if ( $can_update ) { |
118 | - self::$write_fields[ $this->cmb->cmb_id ][] = $field_id; |
|
118 | + self::$write_fields[ $this->cmb->cmb_id ][ ] = $field_id; |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public static function get_restable_field_values( $object, $field_id, $request ) { |
131 | 131 | $values = array(); |
132 | - if ( ! isset( $object['id'] ) ) { |
|
132 | + if ( ! isset( $object[ 'id' ] ) ) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | foreach ( self::$read_fields as $cmb_id => $fields ) { |
137 | 137 | foreach ( $fields as $field_id ) { |
138 | 138 | $field = self::$boxes[ $cmb_id ]->get_field( $field_id ); |
139 | - $field->object_id = $object['id']; |
|
139 | + $field->object_id = $object[ 'id' ]; |
|
140 | 140 | |
141 | 141 | if ( isset( $object->type ) ) { |
142 | 142 | $field->object_type = $object->type; |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | return; |
168 | 168 | } |
169 | 169 | |
170 | - $object_id = $data['object_id']; |
|
171 | - $object_type = $data['object_type']; |
|
170 | + $object_id = $data[ 'object_id' ]; |
|
171 | + $object_type = $data[ 'object_type' ]; |
|
172 | 172 | $updated = array(); |
173 | 173 | |
174 | 174 | foreach ( self::$write_fields as $cmb_id => $fields ) { |
@@ -252,8 +252,8 @@ discard block |
||
252 | 252 | } elseif ( isset( $object->comment_ID ) ) { |
253 | 253 | $object_id = intval( $object->comment_ID ); |
254 | 254 | $object_type = 'comment'; |
255 | - } elseif ( is_array( $object ) && isset( $object['term_id'] ) ) { |
|
256 | - $object_id = intval( $object['term_id'] ); |
|
255 | + } elseif ( is_array( $object ) && isset( $object[ 'term_id' ] ) ) { |
|
256 | + $object_id = intval( $object[ 'term_id' ] ); |
|
257 | 257 | $object_type = 'term'; |
258 | 258 | } elseif ( isset( $object->term_id ) ) { |
259 | 259 | $object_id = intval( $object->term_id ); |
@@ -384,7 +384,6 @@ discard block |
||
384 | 384 | * |
385 | 385 | * @since 2.2.0 |
386 | 386 | * |
387 | - * @param mixed $data |
|
388 | 387 | * @return array $data |
389 | 388 | */ |
390 | 389 | public function prepare_item( $post ) { |
@@ -397,7 +396,7 @@ discard block |
||
397 | 396 | * @since 2.2.0 |
398 | 397 | * |
399 | 398 | * @param mixed $cb Callable function/method. |
400 | - * @return mixed Results of output buffer after calling function/method. |
|
399 | + * @return string Results of output buffer after calling function/method. |
|
401 | 400 | */ |
402 | 401 | public function get_cb_results( $cb ) { |
403 | 402 | $args = func_get_args(); |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | |
67 | 67 | $boxes_data = $cmb->meta_box; |
68 | 68 | |
69 | - if ( isset( $_REQUEST['rendered'] ) ) { |
|
70 | - $boxes_data['form_open'] = $this->get_cb_results( array( $cmb, 'render_form_open' ) ); |
|
71 | - $boxes_data['form_close'] = $this->get_cb_results( array( $cmb, 'render_form_close' ) ); |
|
69 | + if ( isset( $_REQUEST[ 'rendered' ] ) ) { |
|
70 | + $boxes_data[ 'form_open' ] = $this->get_cb_results( array( $cmb, 'render_form_open' ) ); |
|
71 | + $boxes_data[ 'form_close' ] = $this->get_cb_results( array( $cmb, 'render_form_close' ) ); |
|
72 | 72 | |
73 | 73 | global $wp_scripts, $wp_styles; |
74 | 74 | $before_css = $wp_styles->queue; |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | |
77 | 77 | CMB2_JS::enqueue(); |
78 | 78 | |
79 | - $boxes_data['js_dependencies'] = array_values( array_diff( $wp_scripts->queue, $before_js ) ); |
|
80 | - $boxes_data['css_dependencies'] = array_values( array_diff( $wp_styles->queue, $before_css ) ); |
|
79 | + $boxes_data[ 'js_dependencies' ] = array_values( array_diff( $wp_scripts->queue, $before_js ) ); |
|
80 | + $boxes_data[ 'css_dependencies' ] = array_values( array_diff( $wp_styles->queue, $before_css ) ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // TODO: look into 'embed' parameter. |
84 | 84 | // http://demo.wp-api.org/wp-json/wp/v2/posts?_embed |
85 | - unset( $boxes_data['fields'] ); |
|
85 | + unset( $boxes_data[ 'fields' ] ); |
|
86 | 86 | // Handle callable properties. |
87 | - unset( $boxes_data['show_on_cb'] ); |
|
87 | + unset( $boxes_data[ 'show_on_cb' ] ); |
|
88 | 88 | |
89 | 89 | $base = CMB2_REST::BASE . '/boxes/' . $cmb->cmb_id; |
90 | 90 | $boxbase = $base . '/' . $cmb->cmb_id; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | ), |
103 | 103 | ) ); |
104 | 104 | |
105 | - $boxes_data['_links'] = $response->get_links(); |
|
105 | + $boxes_data[ '_links' ] = $response->get_links(); |
|
106 | 106 | |
107 | 107 | return $boxes_data; |
108 | 108 | } |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | ), |
155 | 155 | ) ); |
156 | 156 | |
157 | - $field_data['_links'] = $response->get_links(); |
|
157 | + $field_data[ '_links' ] = $response->get_links(); |
|
158 | 158 | |
159 | 159 | return $field_data; |
160 | 160 | } |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | |
170 | 170 | // TODO: Use request get object |
171 | 171 | // Run this first so the js_dependencies arg is populated. |
172 | - $rendered = isset( $_REQUEST['rendered'] ) && ( $cb = $field->maybe_callback( 'render_row_cb' ) ) |
|
172 | + $rendered = isset( $_REQUEST[ 'rendered' ] ) && ( $cb = $field->maybe_callback( 'render_row_cb' ) ) |
|
173 | 173 | // Ok, callback is good, let's run it. |
174 | 174 | ? $this->get_cb_results( $cb, $field->args(), $field ) |
175 | 175 | : false; |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
201 | - if ( isset( $_REQUEST['rendered'] ) ) { |
|
202 | - $field_data['rendered'] = $rendered; |
|
201 | + if ( isset( $_REQUEST[ 'rendered' ] ) ) { |
|
202 | + $field_data[ 'rendered' ] = $rendered; |
|
203 | 203 | } |
204 | 204 | |
205 | - $field_data['value'] = $field->get_data(); |
|
205 | + $field_data[ 'value' ] = $field->get_data(); |
|
206 | 206 | |
207 | 207 | return $field_data; |
208 | 208 | } |
@@ -262,12 +262,12 @@ discard block |
||
262 | 262 | public function initiate_request( $request ) { |
263 | 263 | $this->request = $request; |
264 | 264 | |
265 | - if ( isset( $_REQUEST['object_id'] ) ) { |
|
266 | - $this->object_id = absint( $_REQUEST['object_id'] ); |
|
265 | + if ( isset( $_REQUEST[ 'object_id' ] ) ) { |
|
266 | + $this->object_id = absint( $_REQUEST[ 'object_id' ] ); |
|
267 | 267 | } |
268 | 268 | |
269 | - if ( isset( $_REQUEST['object_type'] ) ) { |
|
270 | - $this->object_type = absint( $_REQUEST['object_type'] ); |
|
269 | + if ( isset( $_REQUEST[ 'object_type' ] ) ) { |
|
270 | + $this->object_type = absint( $_REQUEST[ 'object_type' ] ); |
|
271 | 271 | } |
272 | 272 | } |
273 | 273 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | */ |
283 | 283 | public function prepare_item_for_response( $data, $request ) { |
284 | 284 | |
285 | - $context = ! empty( $this->request['context'] ) ? $this->request['context'] : 'view'; |
|
285 | + $context = ! empty( $this->request[ 'context' ] ) ? $this->request[ 'context' ] : 'view'; |
|
286 | 286 | $data = $this->filter_response_by_context( $data, $context ); |
287 | 287 | |
288 | 288 | /** |
@@ -59,12 +59,12 @@ discard block |
||
59 | 59 | if ( $cmb_id && ( $cmb = cmb2_get_metabox( $cmb_id, $this->object_id, $this->object_type ) ) ) { |
60 | 60 | $fields = array(); |
61 | 61 | foreach ( $cmb->prop( 'fields', array() ) as $field ) { |
62 | - $field = $this->get_rest_field( $cmb, $field['id'] ); |
|
62 | + $field = $this->get_rest_field( $cmb, $field[ 'id' ] ); |
|
63 | 63 | |
64 | 64 | if ( ! is_wp_error( $field ) ) { |
65 | - $fields[ $field['id'] ] = $field; |
|
65 | + $fields[ $field[ 'id' ] ] = $field; |
|
66 | 66 | } else { |
67 | - $fields[ $field['id'] ] = array( 'error' => $field->get_error_message() ); |
|
67 | + $fields[ $field[ 'id' ] ] = array( 'error' => $field->get_error_message() ); |
|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | public function get_field( $request ) { |
86 | 86 | $this->initiate_request( $request ); |
87 | 87 | |
88 | - $cmb = cmb2_get_metabox( $this->request->get_param( 'cmb_id' ), $this->object_id, $this->object_type ); |
|
88 | + $cmb = cmb2_get_metabox( $this->request->get_param( 'cmb_id' ), $this->object_id, $this->object_type ); |
|
89 | 89 | |
90 | 90 | if ( ! $cmb ) { |
91 | 91 | return $this->prepare_item( array( 'error' => __( 'No box found by that id.', 'cmb2' ) ) ); |