@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | $output = ''; |
22 | 22 | |
23 | 23 | // if options array and 'url' => false, then hide the url field |
24 | - $input_type = array_key_exists( 'url', $options ) && false === $options['url'] ? 'hidden' : 'text'; |
|
24 | + $input_type = array_key_exists( 'url', $options ) && false === $options[ 'url' ] ? 'hidden' : 'text'; |
|
25 | 25 | |
26 | 26 | $output .= parent::render( array( |
27 | 27 | 'type' => $input_type, |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | if ( $_id_value ) { |
72 | 72 | $image = wp_get_attachment_image( $_id_value, $img_size, null, array( 'class' => 'cmb-file-field-image' ) ); |
73 | 73 | } else { |
74 | - $size = is_array( $img_size ) ? $img_size[0] : 350; |
|
74 | + $size = is_array( $img_size ) ? $img_size[ 0 ] : 350; |
|
75 | 75 | $image = '<img style="max-width: ' . absint( $size ) . 'px; width: 100%; height: auto;" src="' . $meta_value . '" alt="" />'; |
76 | 76 | } |
77 | 77 |
@@ -409,6 +409,7 @@ discard block |
||
409 | 409 | * Add a hidden field to the list of hidden fields to be rendered later |
410 | 410 | * @since 2.0.0 |
411 | 411 | * @param array $field_args Array of field arguments to be passed to CMB2_Field |
412 | + * @param CMB2_Field $field_group |
|
412 | 413 | */ |
413 | 414 | public function add_hidden_field( $field_args, $field_group = null ) { |
414 | 415 | if ( isset( $field_args['field_args'] ) ) { |
@@ -610,7 +611,7 @@ discard block |
||
610 | 611 | /** |
611 | 612 | * Save a repeatable group |
612 | 613 | * @since 1.x.x |
613 | - * @param array $field_group CMB2_Field group field object |
|
614 | + * @param CMB2_Field $field_group CMB2_Field group field object |
|
614 | 615 | * @return mixed Return of CMB2_Field::update_data() |
615 | 616 | */ |
616 | 617 | public function save_group_field( $field_group ) { |
@@ -910,7 +911,7 @@ discard block |
||
910 | 911 | * @param mixed $field_id Field (or group field) ID |
911 | 912 | * @param mixed $field_args Array of field arguments |
912 | 913 | * @param mixed $sub_field_id Sub field ID (if field_group exists) |
913 | - * @param mixed $field_group If a sub-field, will be the parent group CMB2_Field object |
|
914 | + * @param CMB2_Field|null $field_group If a sub-field, will be the parent group CMB2_Field object |
|
914 | 915 | * @return array Array of CMB2_Field arguments |
915 | 916 | */ |
916 | 917 | public function get_field_args( $field_id, $field_args, $sub_field_id, $field_group ) { |
@@ -997,7 +998,7 @@ discard block |
||
997 | 998 | * @since 2.0.0 |
998 | 999 | * @param array $field Metabox field config array |
999 | 1000 | * @param int $position (optional) Position of metabox. 1 for first, etc |
1000 | - * @return mixed Field id or false |
|
1001 | + * @return string Field id or false |
|
1001 | 1002 | */ |
1002 | 1003 | public function add_field( array $field, $position = 0 ) { |
1003 | 1004 | if ( ! is_array( $field ) || ! array_key_exists( 'id', $field ) ) { |
@@ -118,19 +118,19 @@ discard block |
||
118 | 118 | */ |
119 | 119 | public function __construct( $meta_box, $object_id = 0 ) { |
120 | 120 | |
121 | - if ( empty( $meta_box['id'] ) ) { |
|
121 | + if ( empty( $meta_box[ 'id' ] ) ) { |
|
122 | 122 | wp_die( __( 'Metabox configuration is required to have an ID parameter', 'cmb2' ) ); |
123 | 123 | } |
124 | 124 | |
125 | 125 | $this->meta_box = wp_parse_args( $meta_box, $this->mb_defaults ); |
126 | - $this->meta_box['fields'] = array(); |
|
126 | + $this->meta_box[ 'fields' ] = array(); |
|
127 | 127 | |
128 | 128 | $this->object_id( $object_id ); |
129 | 129 | $this->mb_object_type(); |
130 | - $this->cmb_id = $meta_box['id']; |
|
130 | + $this->cmb_id = $meta_box[ 'id' ]; |
|
131 | 131 | |
132 | - if ( ! empty( $meta_box['fields'] ) && is_array( $meta_box['fields'] ) ) { |
|
133 | - $this->add_fields( $meta_box['fields'] ); |
|
132 | + if ( ! empty( $meta_box[ 'fields' ] ) && is_array( $meta_box[ 'fields' ] ) ) { |
|
133 | + $this->add_fields( $meta_box[ 'fields' ] ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | CMB2_Boxes::add( $this ); |
@@ -261,22 +261,22 @@ discard block |
||
261 | 261 | * @return mixed CMB2_Field object if successful. |
262 | 262 | */ |
263 | 263 | public function render_field( $field_args ) { |
264 | - $field_args['context'] = $this->prop( 'context' ); |
|
264 | + $field_args[ 'context' ] = $this->prop( 'context' ); |
|
265 | 265 | |
266 | - if ( 'group' == $field_args['type'] ) { |
|
266 | + if ( 'group' == $field_args[ 'type' ] ) { |
|
267 | 267 | |
268 | - if ( ! isset( $field_args['show_names'] ) ) { |
|
269 | - $field_args['show_names'] = $this->prop( 'show_names' ); |
|
268 | + if ( ! isset( $field_args[ 'show_names' ] ) ) { |
|
269 | + $field_args[ 'show_names' ] = $this->prop( 'show_names' ); |
|
270 | 270 | } |
271 | 271 | $field = $this->render_group( $field_args ); |
272 | 272 | |
273 | - } elseif ( 'hidden' == $field_args['type'] && $this->get_field( $field_args )->should_show() ) { |
|
273 | + } elseif ( 'hidden' == $field_args[ 'type' ] && $this->get_field( $field_args )->should_show() ) { |
|
274 | 274 | // Save rendering for after the metabox |
275 | 275 | $field = $this->add_hidden_field( $field_args ); |
276 | 276 | |
277 | 277 | } else { |
278 | 278 | |
279 | - $field_args['show_names'] = $this->prop( 'show_names' ); |
|
279 | + $field_args[ 'show_names' ] = $this->prop( 'show_names' ); |
|
280 | 280 | |
281 | 281 | // Render default fields |
282 | 282 | $field = $this->get_field( $field_args )->render_field(); |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public function render_group( $args ) { |
294 | 294 | |
295 | - if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) { |
|
295 | + if ( ! isset( $args[ 'id' ], $args[ 'fields' ] ) || ! is_array( $args[ 'fields' ] ) ) { |
|
296 | 296 | return; |
297 | 297 | } |
298 | 298 | |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * |
326 | 326 | * @param string $id The group_id of the current group. |
327 | 327 | */ |
328 | - $more_attributes = apply_filters( "cmb2_additional_group_attributes", '', $field_group->args, $args['id'] ); |
|
328 | + $more_attributes = apply_filters( "cmb2_additional_group_attributes", '', $field_group->args, $args[ 'id' ] ); |
|
329 | 329 | |
330 | 330 | $field_group->peform_param_callback( 'before_group' ); |
331 | 331 | |
@@ -389,15 +389,15 @@ discard block |
||
389 | 389 | <div class="inside cmb-td cmb-nested cmb-field-list">'; |
390 | 390 | // Loop and render repeatable group fields |
391 | 391 | foreach ( array_values( $field_group->args( 'fields' ) ) as $field_args ) { |
392 | - if ( 'hidden' == $field_args['type'] ) { |
|
392 | + if ( 'hidden' == $field_args[ 'type' ] ) { |
|
393 | 393 | |
394 | 394 | // Save rendering for after the metabox |
395 | 395 | $this->add_hidden_field( $field_args, $field_group ); |
396 | 396 | |
397 | 397 | } else { |
398 | 398 | |
399 | - $field_args['show_names'] = $field_group->args( 'show_names' ); |
|
400 | - $field_args['context'] = $field_group->args( 'context' ); |
|
399 | + $field_args[ 'show_names' ] = $field_group->args( 'show_names' ); |
|
400 | + $field_args[ 'context' ] = $field_group->args( 'context' ); |
|
401 | 401 | |
402 | 402 | $field = $this->get_field( $field_args, $field_group )->render_field(); |
403 | 403 | } |
@@ -425,14 +425,14 @@ discard block |
||
425 | 425 | * @param array $field_args Array of field arguments to be passed to CMB2_Field |
426 | 426 | */ |
427 | 427 | public function add_hidden_field( $field_args, $field_group = null ) { |
428 | - if ( isset( $field_args['field_args'] ) ) { |
|
428 | + if ( isset( $field_args[ 'field_args' ] ) ) { |
|
429 | 429 | // For back-compatibility. |
430 | 430 | $field = new CMB2_Field( $field_args ); |
431 | 431 | } else { |
432 | 432 | $field = $this->get_new_field( $field_args, $field_group ); |
433 | 433 | } |
434 | 434 | |
435 | - $this->hidden_fields[] = new CMB2_Types( $field ); |
|
435 | + $this->hidden_fields[ ] = new CMB2_Types( $field ); |
|
436 | 436 | |
437 | 437 | return $field; |
438 | 438 | } |
@@ -529,11 +529,11 @@ discard block |
||
529 | 529 | */ |
530 | 530 | public function process_field( $field_args ) { |
531 | 531 | |
532 | - switch ( $field_args['type'] ) { |
|
532 | + switch ( $field_args[ 'type' ] ) { |
|
533 | 533 | |
534 | 534 | case 'group': |
535 | 535 | if ( $this->save_group( $field_args ) ) { |
536 | - $this->updated[] = $field_args['id']; |
|
536 | + $this->updated[ ] = $field_args[ 'id' ]; |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | break; |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | $field = $this->get_new_field( $field_args ); |
548 | 548 | |
549 | 549 | if ( $field->save_field_from_data( $this->data_to_save ) ) { |
550 | - $this->updated[] = $field->id(); |
|
550 | + $this->updated[ ] = $field->id(); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | break; |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | * @return mixed Return of CMB2_Field::update_data() |
615 | 615 | */ |
616 | 616 | public function save_group( $args ) { |
617 | - if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) { |
|
617 | + if ( ! isset( $args[ 'id' ], $args[ 'fields' ] ) || ! is_array( $args[ 'fields' ] ) ) { |
|
618 | 618 | return; |
619 | 619 | } |
620 | 620 | |
@@ -662,16 +662,16 @@ discard block |
||
662 | 662 | $_new_val = array(); |
663 | 663 | foreach ( $new_val as $group_index => $grouped_data ) { |
664 | 664 | // Add the supporting data to the $saved array stack |
665 | - $saved[ $field_group->index ][ $grouped_data['supporting_field_id'] ][] = $grouped_data['supporting_field_value']; |
|
665 | + $saved[ $field_group->index ][ $grouped_data[ 'supporting_field_id' ] ][ ] = $grouped_data[ 'supporting_field_value' ]; |
|
666 | 666 | // Reset var to the actual value |
667 | - $_new_val[ $group_index ] = $grouped_data['value']; |
|
667 | + $_new_val[ $group_index ] = $grouped_data[ 'value' ]; |
|
668 | 668 | } |
669 | 669 | $new_val = $_new_val; |
670 | 670 | } else { |
671 | 671 | // Add the supporting data to the $saved array stack |
672 | - $saved[ $field_group->index ][ $new_val['supporting_field_id'] ] = $new_val['supporting_field_value']; |
|
672 | + $saved[ $field_group->index ][ $new_val[ 'supporting_field_id' ] ] = $new_val[ 'supporting_field_value' ]; |
|
673 | 673 | // Reset var to the actual value |
674 | - $new_val = $new_val['value']; |
|
674 | + $new_val = $new_val[ 'value' ]; |
|
675 | 675 | } |
676 | 676 | } |
677 | 677 | |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | $is_removed = ( empty( $new_val ) && ! empty( $old_val ) ); |
685 | 685 | // Compare values and add to `$updated` array |
686 | 686 | if ( $is_updated || $is_removed ) { |
687 | - $this->updated[] = $base_id . '::' . $field_group->index . '::' . $sub_id; |
|
687 | + $this->updated[ ] = $base_id . '::' . $field_group->index . '::' . $sub_id; |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | // Add to `$saved` array |
@@ -719,22 +719,22 @@ discard block |
||
719 | 719 | // Try to get our object ID from the global space |
720 | 720 | switch ( $this->object_type() ) { |
721 | 721 | case 'user': |
722 | - $object_id = isset( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : $object_id; |
|
723 | - $object_id = ! $object_id && 'user-new.php' != $pagenow && isset( $GLOBALS['user_ID'] ) ? $GLOBALS['user_ID'] : $object_id; |
|
722 | + $object_id = isset( $_REQUEST[ 'user_id' ] ) ? $_REQUEST[ 'user_id' ] : $object_id; |
|
723 | + $object_id = ! $object_id && 'user-new.php' != $pagenow && isset( $GLOBALS[ 'user_ID' ] ) ? $GLOBALS[ 'user_ID' ] : $object_id; |
|
724 | 724 | break; |
725 | 725 | |
726 | 726 | case 'comment': |
727 | - $object_id = isset( $_REQUEST['c'] ) ? $_REQUEST['c'] : $object_id; |
|
728 | - $object_id = ! $object_id && isset( $GLOBALS['comments']->comment_ID ) ? $GLOBALS['comments']->comment_ID : $object_id; |
|
727 | + $object_id = isset( $_REQUEST[ 'c' ] ) ? $_REQUEST[ 'c' ] : $object_id; |
|
728 | + $object_id = ! $object_id && isset( $GLOBALS[ 'comments' ]->comment_ID ) ? $GLOBALS[ 'comments' ]->comment_ID : $object_id; |
|
729 | 729 | break; |
730 | 730 | |
731 | 731 | case 'term': |
732 | - $object_id = isset( $_REQUEST['tag_ID'] ) ? $_REQUEST['tag_ID'] : $object_id; |
|
732 | + $object_id = isset( $_REQUEST[ 'tag_ID' ] ) ? $_REQUEST[ 'tag_ID' ] : $object_id; |
|
733 | 733 | break; |
734 | 734 | |
735 | 735 | default: |
736 | - $object_id = isset( $GLOBALS['post']->ID ) ? $GLOBALS['post']->ID : $object_id; |
|
737 | - $object_id = isset( $_REQUEST['post'] ) ? $_REQUEST['post'] : $object_id; |
|
736 | + $object_id = isset( $GLOBALS[ 'post' ]->ID ) ? $GLOBALS[ 'post' ]->ID : $object_id; |
|
737 | + $object_id = isset( $_REQUEST[ 'post' ] ) ? $_REQUEST[ 'post' ] : $object_id; |
|
738 | 738 | break; |
739 | 739 | } |
740 | 740 | |
@@ -810,7 +810,7 @@ discard block |
||
810 | 810 | * @return boolean True/False |
811 | 811 | */ |
812 | 812 | public function is_options_page_mb() { |
813 | - return ( isset( $this->meta_box['show_on']['key'] ) && 'options-page' === $this->meta_box['show_on']['key'] || array_key_exists( 'options-page', $this->meta_box['show_on'] ) ); |
|
813 | + return ( isset( $this->meta_box[ 'show_on' ][ 'key' ] ) && 'options-page' === $this->meta_box[ 'show_on' ][ 'key' ] || array_key_exists( 'options-page', $this->meta_box[ 'show_on' ] ) ); |
|
814 | 814 | } |
815 | 815 | |
816 | 816 | /** |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | return $field; |
898 | 898 | } |
899 | 899 | |
900 | - $field_id = is_string( $field ) ? $field : $field['id']; |
|
900 | + $field_id = is_string( $field ) ? $field : $field[ 'id' ]; |
|
901 | 901 | |
902 | 902 | $parent_field_id = ! empty( $field_group ) ? $field_group->id() : ''; |
903 | 903 | $ids = $this->get_field_ids( $field_id, $parent_field_id, true ); |
@@ -933,16 +933,16 @@ discard block |
||
933 | 933 | if ( $field_group && ( $sub_field_id || 0 === $sub_field_id ) ) { |
934 | 934 | |
935 | 935 | // Update the fields array w/ any modified properties inherited from the group field |
936 | - $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] = $field_args; |
|
936 | + $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] = $field_args; |
|
937 | 937 | |
938 | 938 | return $this->get_default_args( $field_args, $field_group ); |
939 | 939 | } |
940 | 940 | |
941 | 941 | if ( is_array( $field_args ) ) { |
942 | - $this->meta_box['fields'][ $field_id ] = array_merge( $field_args, $this->meta_box['fields'][ $field_id ] ); |
|
942 | + $this->meta_box[ 'fields' ][ $field_id ] = array_merge( $field_args, $this->meta_box[ 'fields' ][ $field_id ] ); |
|
943 | 943 | } |
944 | 944 | |
945 | - return $this->get_default_args( $this->meta_box['fields'][ $field_id ] ); |
|
945 | + return $this->get_default_args( $this->meta_box[ 'fields' ][ $field_id ] ); |
|
946 | 946 | } |
947 | 947 | |
948 | 948 | /** |
@@ -992,8 +992,8 @@ discard block |
||
992 | 992 | |
993 | 993 | $sub_fields = false; |
994 | 994 | if ( array_key_exists( 'fields', $field ) ) { |
995 | - $sub_fields = $field['fields']; |
|
996 | - unset( $field['fields'] ); |
|
995 | + $sub_fields = $field[ 'fields' ]; |
|
996 | + unset( $field[ 'fields' ] ); |
|
997 | 997 | } |
998 | 998 | |
999 | 999 | $field_id = $parent_field_id |
@@ -1018,18 +1018,18 @@ discard block |
||
1018 | 1018 | return false; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | - if ( 'oembed' === $field['type'] ) { |
|
1021 | + if ( 'oembed' === $field[ 'type' ] ) { |
|
1022 | 1022 | // Initiate oembed Ajax hooks |
1023 | 1023 | cmb2_ajax(); |
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | $this->_add_field_to_array( |
1027 | 1027 | $field, |
1028 | - $this->meta_box['fields'], |
|
1028 | + $this->meta_box[ 'fields' ], |
|
1029 | 1029 | $position |
1030 | 1030 | ); |
1031 | 1031 | |
1032 | - return $field['id']; |
|
1032 | + return $field[ 'id' ]; |
|
1033 | 1033 | } |
1034 | 1034 | |
1035 | 1035 | /** |
@@ -1041,27 +1041,27 @@ discard block |
||
1041 | 1041 | * @return mixed Array of parent/field ids or false |
1042 | 1042 | */ |
1043 | 1043 | public function add_group_field( $parent_field_id, array $field, $position = 0 ) { |
1044 | - if ( ! array_key_exists( $parent_field_id, $this->meta_box['fields'] ) ) { |
|
1044 | + if ( ! array_key_exists( $parent_field_id, $this->meta_box[ 'fields' ] ) ) { |
|
1045 | 1045 | return false; |
1046 | 1046 | } |
1047 | 1047 | |
1048 | - $parent_field = $this->meta_box['fields'][ $parent_field_id ]; |
|
1048 | + $parent_field = $this->meta_box[ 'fields' ][ $parent_field_id ]; |
|
1049 | 1049 | |
1050 | - if ( 'group' !== $parent_field['type'] ) { |
|
1050 | + if ( 'group' !== $parent_field[ 'type' ] ) { |
|
1051 | 1051 | return false; |
1052 | 1052 | } |
1053 | 1053 | |
1054 | - if ( ! isset( $parent_field['fields'] ) ) { |
|
1055 | - $this->meta_box['fields'][ $parent_field_id ]['fields'] = array(); |
|
1054 | + if ( ! isset( $parent_field[ 'fields' ] ) ) { |
|
1055 | + $this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ] = array(); |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | 1058 | $this->_add_field_to_array( |
1059 | 1059 | $field, |
1060 | - $this->meta_box['fields'][ $parent_field_id ]['fields'], |
|
1060 | + $this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ], |
|
1061 | 1061 | $position |
1062 | 1062 | ); |
1063 | 1063 | |
1064 | - return array( $parent_field_id, $field['id'] ); |
|
1064 | + return array( $parent_field_id, $field[ 'id' ] ); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | 1067 | /** |
@@ -1073,9 +1073,9 @@ discard block |
||
1073 | 1073 | */ |
1074 | 1074 | protected function _add_field_to_array( $field, &$fields, $position = 0 ) { |
1075 | 1075 | if ( $position ) { |
1076 | - cmb2_utils()->array_insert( $fields, array( $field['id'] => $field ), $position ); |
|
1076 | + cmb2_utils()->array_insert( $fields, array( $field[ 'id' ] => $field ), $position ); |
|
1077 | 1077 | } else { |
1078 | - $fields[ $field['id'] ] = $field; |
|
1078 | + $fields[ $field[ 'id' ] ] = $field; |
|
1079 | 1079 | } |
1080 | 1080 | } |
1081 | 1081 | |
@@ -1098,15 +1098,15 @@ discard block |
||
1098 | 1098 | unset( $this->fields[ implode( '', $ids ) ] ); |
1099 | 1099 | |
1100 | 1100 | if ( ! $sub_field_id ) { |
1101 | - unset( $this->meta_box['fields'][ $field_id ] ); |
|
1101 | + unset( $this->meta_box[ 'fields' ][ $field_id ] ); |
|
1102 | 1102 | return true; |
1103 | 1103 | } |
1104 | 1104 | |
1105 | - if ( isset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ) ) { |
|
1106 | - unset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ); |
|
1105 | + if ( isset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] ) ) { |
|
1106 | + unset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] ); |
|
1107 | 1107 | } |
1108 | - if ( isset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ) ) { |
|
1109 | - unset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ); |
|
1108 | + if ( isset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] ) ) { |
|
1109 | + unset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] ); |
|
1110 | 1110 | } |
1111 | 1111 | return true; |
1112 | 1112 | } |
@@ -1130,11 +1130,11 @@ discard block |
||
1130 | 1130 | list( $field_id, $sub_field_id ) = $ids; |
1131 | 1131 | |
1132 | 1132 | if ( ! $sub_field_id ) { |
1133 | - $this->meta_box['fields'][ $field_id ][ $property ] = $value; |
|
1133 | + $this->meta_box[ 'fields' ][ $field_id ][ $property ] = $value; |
|
1134 | 1134 | return $field_id; |
1135 | 1135 | } |
1136 | 1136 | |
1137 | - $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ][ $property ] = $value; |
|
1137 | + $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ][ $property ] = $value; |
|
1138 | 1138 | return $field_id; |
1139 | 1139 | } |
1140 | 1140 | |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | public function get_field_ids( $field_id, $parent_field_id = '' ) { |
1149 | 1149 | $sub_field_id = $parent_field_id ? $field_id : ''; |
1150 | 1150 | $field_id = $parent_field_id ? $parent_field_id : $field_id; |
1151 | - $fields =& $this->meta_box['fields']; |
|
1151 | + $fields = & $this->meta_box[ 'fields' ]; |
|
1152 | 1152 | |
1153 | 1153 | if ( ! array_key_exists( $field_id, $fields ) ) { |
1154 | 1154 | $field_id = $this->search_old_school_array( $field_id, $fields ); |
@@ -1162,12 +1162,12 @@ discard block |
||
1162 | 1162 | return array( $field_id, $sub_field_id ); |
1163 | 1163 | } |
1164 | 1164 | |
1165 | - if ( 'group' !== $fields[ $field_id ]['type'] ) { |
|
1165 | + if ( 'group' !== $fields[ $field_id ][ 'type' ] ) { |
|
1166 | 1166 | return false; |
1167 | 1167 | } |
1168 | 1168 | |
1169 | - if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ]['fields'] ) ) { |
|
1170 | - $sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ]['fields'] ); |
|
1169 | + if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ][ 'fields' ] ) ) { |
|
1170 | + $sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ][ 'fields' ] ); |
|
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | return false === $sub_field_id ? false : array( $field_id, $sub_field_id ); |
@@ -735,7 +735,7 @@ discard block |
||
735 | 735 | * Return a formatted timestamp for a field |
736 | 736 | * @since 2.0.0 |
737 | 737 | * @param string $format Either date_format or time_format |
738 | - * @param string $meta_value Optional meta value to check |
|
738 | + * @param integer $meta_value Optional meta value to check |
|
739 | 739 | * @return string Formatted date |
740 | 740 | */ |
741 | 741 | public function get_timestamp_format( $format = 'date_format', $meta_value = 0 ) { |
@@ -1007,7 +1007,7 @@ discard block |
||
1007 | 1007 | * Retrieve options args. Calls options_cb if it exists. |
1008 | 1008 | * @since 2.0.0 |
1009 | 1009 | * @param string $key Specific option to retrieve |
1010 | - * @return array Array of options |
|
1010 | + * @return string Array of options |
|
1011 | 1011 | */ |
1012 | 1012 | public function options( $key = '' ) { |
1013 | 1013 | if ( ! empty( $this->field_options ) ) { |
@@ -107,21 +107,21 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function __construct( $args ) { |
109 | 109 | |
110 | - if ( ! empty( $args['group_field'] ) ) { |
|
111 | - $this->group = $args['group_field']; |
|
110 | + if ( ! empty( $args[ 'group_field' ] ) ) { |
|
111 | + $this->group = $args[ 'group_field' ]; |
|
112 | 112 | $this->object_id = $this->group->object_id; |
113 | 113 | $this->object_type = $this->group->object_type; |
114 | 114 | $this->cmb_id = $this->group->cmb_id; |
115 | 115 | } else { |
116 | - $this->object_id = isset( $args['object_id'] ) && '_' !== $args['object_id'] ? $args['object_id'] : 0; |
|
117 | - $this->object_type = isset( $args['object_type'] ) ? $args['object_type'] : 'post'; |
|
116 | + $this->object_id = isset( $args[ 'object_id' ] ) && '_' !== $args[ 'object_id' ] ? $args[ 'object_id' ] : 0; |
|
117 | + $this->object_type = isset( $args[ 'object_type' ] ) ? $args[ 'object_type' ] : 'post'; |
|
118 | 118 | |
119 | - if ( isset( $args['cmb_id'] ) ) { |
|
120 | - $this->cmb_id = $args['cmb_id']; |
|
119 | + if ( isset( $args[ 'cmb_id' ] ) ) { |
|
120 | + $this->cmb_id = $args[ 'cmb_id' ]; |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - $this->args = $this->_set_field_defaults( $args['field_args'] ); |
|
124 | + $this->args = $this->_set_field_defaults( $args[ 'field_args' ] ); |
|
125 | 125 | |
126 | 126 | if ( $this->object_id ) { |
127 | 127 | $this->value = $this->get_data(); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @return mixed Value of field argument |
137 | 137 | */ |
138 | 138 | public function __call( $name, $arguments ) { |
139 | - $key = isset( $arguments[0] ) ? $arguments[0] : false; |
|
139 | + $key = isset( $arguments[ 0 ] ) ? $arguments[ 0 ] : false; |
|
140 | 140 | return $this->args( $name, $key ); |
141 | 141 | } |
142 | 142 | |
@@ -207,9 +207,9 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public function get_data( $field_id = '', $args = array() ) { |
209 | 209 | if ( $field_id ) { |
210 | - $args['field_id'] = $field_id; |
|
210 | + $args[ 'field_id' ] = $field_id; |
|
211 | 211 | } else if ( $this->group ) { |
212 | - $args['field_id'] = $this->group->id(); |
|
212 | + $args[ 'field_id' ] = $this->group->id(); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | $a = $this->data_args( $args ); |
@@ -250,13 +250,13 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @since 2.0.0 |
252 | 252 | */ |
253 | - $data = apply_filters( "cmb2_override_{$a['field_id']}_meta_value", $data, $this->object_id, $a, $this ); |
|
253 | + $data = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_value", $data, $this->object_id, $a, $this ); |
|
254 | 254 | |
255 | 255 | // If no override, get value normally |
256 | 256 | if ( 'cmb2_field_no_override_val' === $data ) { |
257 | - $data = 'options-page' === $a['type'] |
|
258 | - ? cmb2_options( $a['id'] )->get( $a['field_id'] ) |
|
259 | - : get_metadata( $a['type'], $a['id'], $a['field_id'], ( $a['single'] || $a['repeat'] ) ); |
|
257 | + $data = 'options-page' === $a[ 'type' ] |
|
258 | + ? cmb2_options( $a[ 'id' ] )->get( $a[ 'field_id' ] ) |
|
259 | + : get_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], ( $a[ 'single' ] || $a[ 'repeat' ] ) ); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | if ( $this->group ) { |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | public function update_data( $new_value, $single = true ) { |
279 | 279 | $a = $this->data_args( array( 'single' => $single ) ); |
280 | 280 | |
281 | - $a['value'] = $a['repeat'] ? array_values( $new_value ) : $new_value; |
|
281 | + $a[ 'value' ] = $a[ 'repeat' ] ? array_values( $new_value ) : $new_value; |
|
282 | 282 | |
283 | 283 | /** |
284 | 284 | * Filter whether to override saving of meta value. |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | * |
315 | 315 | * @since 2.0.0 |
316 | 316 | */ |
317 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_save", $override, $a, $this->args(), $this ); |
|
317 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_save", $override, $a, $this->args(), $this ); |
|
318 | 318 | |
319 | 319 | // If override, return that |
320 | 320 | if ( null !== $override ) { |
@@ -322,22 +322,22 @@ discard block |
||
322 | 322 | } |
323 | 323 | |
324 | 324 | // Options page handling (or temp data store) |
325 | - if ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
326 | - return cmb2_options( $a['id'] )->update( $a['field_id'], $a['value'], false, $a['single'] ); |
|
325 | + if ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
326 | + return cmb2_options( $a[ 'id' ] )->update( $a[ 'field_id' ], $a[ 'value' ], false, $a[ 'single' ] ); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Add metadata if not single |
330 | - if ( ! $a['single'] ) { |
|
331 | - return add_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'], false ); |
|
330 | + if ( ! $a[ 'single' ] ) { |
|
331 | + return add_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ], false ); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | // Delete meta if we have an empty array |
335 | - if ( is_array( $a['value'] ) && empty( $a['value'] ) ) { |
|
336 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $this->value ); |
|
335 | + if ( is_array( $a[ 'value' ] ) && empty( $a[ 'value' ] ) ) { |
|
336 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $this->value ); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // Update metadata |
340 | - return update_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'] ); |
|
340 | + return update_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ] ); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
@@ -387,19 +387,19 @@ discard block |
||
387 | 387 | * @param array $field_args All field arguments |
388 | 388 | * @param CMB2_Field object $field This field object |
389 | 389 | */ |
390 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_remove", $override, $a, $this->args(), $this ); |
|
390 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_remove", $override, $a, $this->args(), $this ); |
|
391 | 391 | |
392 | 392 | // If no override, remove as usual |
393 | 393 | if ( null !== $override ) { |
394 | 394 | return $override; |
395 | 395 | } |
396 | 396 | // Option page handling |
397 | - elseif ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
398 | - return cmb2_options( $a['id'] )->remove( $a['field_id'] ); |
|
397 | + elseif ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
398 | + return cmb2_options( $a[ 'id' ] )->remove( $a[ 'field_id' ] ); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | // Remove metadata |
402 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $old ); |
|
402 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $old ); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -870,7 +870,7 @@ discard block |
||
870 | 870 | |
871 | 871 | foreach ( $conditional_classes as $class => $condition ) { |
872 | 872 | if ( $condition ) { |
873 | - $classes[] = $class; |
|
873 | + $classes[ ] = $class; |
|
874 | 874 | } |
875 | 875 | } |
876 | 876 | |
@@ -879,7 +879,7 @@ discard block |
||
879 | 879 | } |
880 | 880 | |
881 | 881 | if ( $added_classes ) { |
882 | - $classes[] = esc_attr( $added_classes ); |
|
882 | + $classes[ ] = esc_attr( $added_classes ); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
@@ -981,10 +981,10 @@ discard block |
||
981 | 981 | public function string( $text_key, $fallback ) { |
982 | 982 | // If null, populate with our field strings values. |
983 | 983 | if ( null === $this->strings ) { |
984 | - $this->strings = (array) $this->args['text']; |
|
984 | + $this->strings = (array) $this->args[ 'text' ]; |
|
985 | 985 | |
986 | - if ( is_callable( $this->args['text_cb'] ) ) { |
|
987 | - $strings = call_user_func( $this->args['text_cb'], $this ); |
|
986 | + if ( is_callable( $this->args[ 'text_cb' ] ) ) { |
|
987 | + $strings = call_user_func( $this->args[ 'text_cb' ], $this ); |
|
988 | 988 | |
989 | 989 | if ( $strings && is_array( $strings ) ) { |
990 | 990 | $this->strings += $strings; |
@@ -1018,10 +1018,10 @@ discard block |
||
1018 | 1018 | return $this->field_options; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | - $this->field_options = (array) $this->args['options']; |
|
1021 | + $this->field_options = (array) $this->args[ 'options' ]; |
|
1022 | 1022 | |
1023 | - if ( is_callable( $this->args['options_cb'] ) ) { |
|
1024 | - $options = call_user_func( $this->args['options_cb'], $this ); |
|
1023 | + if ( is_callable( $this->args[ 'options_cb' ] ) ) { |
|
1024 | + $options = call_user_func( $this->args[ 'options_cb' ], $this ); |
|
1025 | 1025 | |
1026 | 1026 | if ( $options && is_array( $options ) ) { |
1027 | 1027 | $this->field_options += $options; |
@@ -1043,17 +1043,17 @@ discard block |
||
1043 | 1043 | * @return mixed Default field value |
1044 | 1044 | */ |
1045 | 1045 | public function get_default() { |
1046 | - if ( null !== $this->args['default'] ) { |
|
1047 | - return $this->args['default']; |
|
1046 | + if ( null !== $this->args[ 'default' ] ) { |
|
1047 | + return $this->args[ 'default' ]; |
|
1048 | 1048 | } |
1049 | 1049 | |
1050 | - $param = is_callable( $this->args['default_cb'] ) ? 'default_cb' : 'default'; |
|
1050 | + $param = is_callable( $this->args[ 'default_cb' ] ) ? 'default_cb' : 'default'; |
|
1051 | 1051 | $default = $this->get_param_callback_result( $param, false ); |
1052 | 1052 | |
1053 | 1053 | // Allow a filter override of the default value |
1054 | - $this->args['default'] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
1054 | + $this->args[ 'default' ] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
1055 | 1055 | |
1056 | - return $this->args['default']; |
|
1056 | + return $this->args[ 'default' ]; |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | /** |
@@ -1080,68 +1080,68 @@ discard block |
||
1080 | 1080 | 'default_cb' => '', |
1081 | 1081 | 'select_all_button' => true, |
1082 | 1082 | 'multiple' => false, |
1083 | - 'repeatable' => isset( $args['type'] ) && 'group' == $args['type'], |
|
1083 | + 'repeatable' => isset( $args[ 'type' ] ) && 'group' == $args[ 'type' ], |
|
1084 | 1084 | 'inline' => false, |
1085 | 1085 | 'on_front' => true, |
1086 | 1086 | 'show_names' => true, |
1087 | 1087 | 'date_format' => 'm\/d\/Y', |
1088 | 1088 | 'time_format' => 'h:i A', |
1089 | - 'description' => isset( $args['desc'] ) ? $args['desc'] : '', |
|
1090 | - 'preview_size' => 'file' == $args['type'] ? array( 350, 350 ) : array( 50, 50 ), |
|
1089 | + 'description' => isset( $args[ 'desc' ] ) ? $args[ 'desc' ] : '', |
|
1090 | + 'preview_size' => 'file' == $args[ 'type' ] ? array( 350, 350 ) : array( 50, 50 ), |
|
1091 | 1091 | 'render_row_cb' => array( $this, 'render_field_callback' ), |
1092 | - 'label_cb' => 'title' != $args['type'] ? array( $this, 'label' ) : '', |
|
1092 | + 'label_cb' => 'title' != $args[ 'type' ] ? array( $this, 'label' ) : '', |
|
1093 | 1093 | ) ); |
1094 | 1094 | |
1095 | 1095 | // default param can be passed a callback as well |
1096 | - if ( is_callable( $args['default'] ) ) { |
|
1097 | - $args['default_cb'] = $args['default']; |
|
1098 | - $args['default'] = null; |
|
1096 | + if ( is_callable( $args[ 'default' ] ) ) { |
|
1097 | + $args[ 'default_cb' ] = $args[ 'default' ]; |
|
1098 | + $args[ 'default' ] = null; |
|
1099 | 1099 | } |
1100 | 1100 | |
1101 | - $args['repeatable'] = $args['repeatable'] && ! $this->repeatable_exception( $args['type'] ); |
|
1102 | - $args['inline'] = $args['inline'] || false !== stripos( $args['type'], '_inline' ); |
|
1101 | + $args[ 'repeatable' ] = $args[ 'repeatable' ] && ! $this->repeatable_exception( $args[ 'type' ] ); |
|
1102 | + $args[ 'inline' ] = $args[ 'inline' ] || false !== stripos( $args[ 'type' ], '_inline' ); |
|
1103 | 1103 | |
1104 | 1104 | // options param can be passed a callback as well |
1105 | - if ( is_callable( $args['options'] ) ) { |
|
1106 | - $args['options_cb'] = $args['options']; |
|
1107 | - $args['options'] = array(); |
|
1105 | + if ( is_callable( $args[ 'options' ] ) ) { |
|
1106 | + $args[ 'options_cb' ] = $args[ 'options' ]; |
|
1107 | + $args[ 'options' ] = array(); |
|
1108 | 1108 | } |
1109 | 1109 | |
1110 | - $args['options'] = 'group' == $args['type'] ? wp_parse_args( $args['options'], array( |
|
1110 | + $args[ 'options' ] = 'group' == $args[ 'type' ] ? wp_parse_args( $args[ 'options' ], array( |
|
1111 | 1111 | 'add_button' => __( 'Add Group', 'cmb2' ), |
1112 | 1112 | 'remove_button' => __( 'Remove Group', 'cmb2' ), |
1113 | - ) ) : $args['options']; |
|
1113 | + ) ) : $args[ 'options' ]; |
|
1114 | 1114 | |
1115 | - $args['_id'] = $args['id']; |
|
1116 | - $args['_name'] = $args['id']; |
|
1115 | + $args[ '_id' ] = $args[ 'id' ]; |
|
1116 | + $args[ '_name' ] = $args[ 'id' ]; |
|
1117 | 1117 | |
1118 | 1118 | if ( $this->group ) { |
1119 | 1119 | |
1120 | - $args['id'] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args['id']; |
|
1121 | - $args['_name'] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args['_name'] . ']'; |
|
1120 | + $args[ 'id' ] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args[ 'id' ]; |
|
1121 | + $args[ '_name' ] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args[ '_name' ] . ']'; |
|
1122 | 1122 | } |
1123 | 1123 | |
1124 | - if ( 'wysiwyg' == $args['type'] ) { |
|
1125 | - $args['id'] = strtolower( str_ireplace( '-', '_', $args['id'] ) ); |
|
1126 | - $args['options']['textarea_name'] = $args['_name']; |
|
1124 | + if ( 'wysiwyg' == $args[ 'type' ] ) { |
|
1125 | + $args[ 'id' ] = strtolower( str_ireplace( '-', '_', $args[ 'id' ] ) ); |
|
1126 | + $args[ 'options' ][ 'textarea_name' ] = $args[ '_name' ]; |
|
1127 | 1127 | } |
1128 | 1128 | |
1129 | 1129 | $option_types = apply_filters( 'cmb2_all_or_nothing_types', array( 'select', 'radio', 'radio_inline', 'taxonomy_select', 'taxonomy_radio', 'taxonomy_radio_inline' ), $this ); |
1130 | 1130 | |
1131 | - if ( in_array( $args['type'], $option_types, true ) ) { |
|
1131 | + if ( in_array( $args[ 'type' ], $option_types, true ) ) { |
|
1132 | 1132 | |
1133 | - $args['show_option_none'] = isset( $args['show_option_none'] ) ? $args['show_option_none'] : null; |
|
1134 | - $args['show_option_none'] = true === $args['show_option_none'] ? __( 'None', 'cmb2' ) : $args['show_option_none']; |
|
1133 | + $args[ 'show_option_none' ] = isset( $args[ 'show_option_none' ] ) ? $args[ 'show_option_none' ] : null; |
|
1134 | + $args[ 'show_option_none' ] = true === $args[ 'show_option_none' ] ? __( 'None', 'cmb2' ) : $args[ 'show_option_none' ]; |
|
1135 | 1135 | |
1136 | - if ( null === $args['show_option_none'] ) { |
|
1137 | - $off_by_default = in_array( $args['type'], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1138 | - $args['show_option_none'] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
1136 | + if ( null === $args[ 'show_option_none' ] ) { |
|
1137 | + $off_by_default = in_array( $args[ 'type' ], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1138 | + $args[ 'show_option_none' ] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | 1141 | } |
1142 | 1142 | |
1143 | - $args['has_supporting_data'] = in_array( |
|
1144 | - $args['type'], |
|
1143 | + $args[ 'has_supporting_data' ] = in_array( |
|
1144 | + $args[ 'type' ], |
|
1145 | 1145 | array( |
1146 | 1146 | // CMB2_Sanitize::_save_file_id_value()/CMB2_Sanitize::_get_group_file_value_array() |
1147 | 1147 | 'file', |
@@ -1173,10 +1173,10 @@ discard block |
||
1173 | 1173 | 'cmb_id' => $this->cmb_id, |
1174 | 1174 | ); |
1175 | 1175 | |
1176 | - if ( isset( $field_args['field_args'] ) ) { |
|
1176 | + if ( isset( $field_args[ 'field_args' ] ) ) { |
|
1177 | 1177 | $args = wp_parse_args( $field_args, $args ); |
1178 | 1178 | } else { |
1179 | - $args['field_args'] = wp_parse_args( $field_args, $this->args ); |
|
1179 | + $args[ 'field_args' ] = wp_parse_args( $field_args, $this->args ); |
|
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | return new CMB2_Field( $args ); |