@@ -408,6 +408,7 @@ discard block |
||
408 | 408 | * Add a hidden field to the list of hidden fields to be rendered later |
409 | 409 | * @since 2.0.0 |
410 | 410 | * @param array $field_args Array of field arguments to be passed to CMB2_Field |
411 | + * @param CMB2_Field $field_group |
|
411 | 412 | */ |
412 | 413 | public function add_hidden_field( $field_args, $field_group = null ) { |
413 | 414 | if ( isset( $field_args['field_args'] ) ) { |
@@ -851,7 +852,7 @@ discard block |
||
851 | 852 | * @param mixed $field_id Field (or group field) ID |
852 | 853 | * @param mixed $field_args Array of field arguments |
853 | 854 | * @param mixed $sub_field_id Sub field ID (if field_group exists) |
854 | - * @param mixed $field_group If a sub-field, will be the parent group CMB2_Field object |
|
855 | + * @param CMB2_Field|null $field_group If a sub-field, will be the parent group CMB2_Field object |
|
855 | 856 | * @return array Array of CMB2_Field arguments |
856 | 857 | */ |
857 | 858 | public function get_field_args( $field_id, $field_args, $sub_field_id, $field_group ) { |
@@ -938,7 +939,7 @@ discard block |
||
938 | 939 | * @since 2.0.0 |
939 | 940 | * @param array $field Metabox field config array |
940 | 941 | * @param int $position (optional) Position of metabox. 1 for first, etc |
941 | - * @return mixed Field id or false |
|
942 | + * @return string Field id or false |
|
942 | 943 | */ |
943 | 944 | public function add_field( array $field, $position = 0 ) { |
944 | 945 | 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 | |
@@ -374,15 +374,15 @@ discard block |
||
374 | 374 | <div class="inside cmb-td cmb-nested cmb-field-list">'; |
375 | 375 | // Loop and render repeatable group fields |
376 | 376 | foreach ( array_values( $field_group->args( 'fields' ) ) as $field_args ) { |
377 | - if ( 'hidden' == $field_args['type'] ) { |
|
377 | + if ( 'hidden' == $field_args[ 'type' ] ) { |
|
378 | 378 | |
379 | 379 | // Save rendering for after the metabox |
380 | 380 | $this->add_hidden_field( $field_args, $field_group ); |
381 | 381 | |
382 | 382 | } else { |
383 | 383 | |
384 | - $field_args['show_names'] = $field_group->args( 'show_names' ); |
|
385 | - $field_args['context'] = $field_group->args( 'context' ); |
|
384 | + $field_args[ 'show_names' ] = $field_group->args( 'show_names' ); |
|
385 | + $field_args[ 'context' ] = $field_group->args( 'context' ); |
|
386 | 386 | |
387 | 387 | $field = $this->get_field( $field_args, $field_group )->render_field(); |
388 | 388 | } |
@@ -410,14 +410,14 @@ discard block |
||
410 | 410 | * @param array $field_args Array of field arguments to be passed to CMB2_Field |
411 | 411 | */ |
412 | 412 | public function add_hidden_field( $field_args, $field_group = null ) { |
413 | - if ( isset( $field_args['field_args'] ) ) { |
|
413 | + if ( isset( $field_args[ 'field_args' ] ) ) { |
|
414 | 414 | // For back-compatibility. |
415 | 415 | $field = new CMB2_Field( $field_args ); |
416 | 416 | } else { |
417 | 417 | $field = $this->get_new_field( $field_args, $field_group ); |
418 | 418 | } |
419 | 419 | |
420 | - $this->hidden_fields[] = new CMB2_Types( $field ); |
|
420 | + $this->hidden_fields[ ] = new CMB2_Types( $field ); |
|
421 | 421 | |
422 | 422 | return $field; |
423 | 423 | } |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | */ |
557 | 557 | public function process_field( $field_args ) { |
558 | 558 | |
559 | - switch ( $field_args['type'] ) { |
|
559 | + switch ( $field_args[ 'type' ] ) { |
|
560 | 560 | |
561 | 561 | case 'group': |
562 | 562 | $this->save_group( $field_args ); |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | $field = $this->get_new_field( $field_args ); |
572 | 572 | |
573 | 573 | if ( $field->save_field_from_data( $this->data_to_save ) ) { |
574 | - $this->updated[] = $field->id(); |
|
574 | + $this->updated[ ] = $field->id(); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | break; |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | */ |
585 | 585 | public function save_group( $args ) { |
586 | 586 | |
587 | - if ( ! isset( $args['id'], $args['fields'], $this->data_to_save[ $args['id'] ] ) || ! is_array( $args['fields'] ) ) { |
|
587 | + if ( ! isset( $args[ 'id' ], $args[ 'fields' ], $this->data_to_save[ $args[ 'id' ] ] ) || ! is_array( $args[ 'fields' ] ) ) { |
|
588 | 588 | return; |
589 | 589 | } |
590 | 590 | |
@@ -617,16 +617,16 @@ discard block |
||
617 | 617 | $_new_val = array(); |
618 | 618 | foreach ( $new_val as $group_index => $grouped_data ) { |
619 | 619 | // Add the supporting data to the $saved array stack |
620 | - $saved[ $field_group->index ][ $grouped_data['supporting_field_id'] ][] = $grouped_data['supporting_field_value']; |
|
620 | + $saved[ $field_group->index ][ $grouped_data[ 'supporting_field_id' ] ][ ] = $grouped_data[ 'supporting_field_value' ]; |
|
621 | 621 | // Reset var to the actual value |
622 | - $_new_val[ $group_index ] = $grouped_data['value']; |
|
622 | + $_new_val[ $group_index ] = $grouped_data[ 'value' ]; |
|
623 | 623 | } |
624 | 624 | $new_val = $_new_val; |
625 | 625 | } else { |
626 | 626 | // Add the supporting data to the $saved array stack |
627 | - $saved[ $field_group->index ][ $new_val['supporting_field_id'] ] = $new_val['supporting_field_value']; |
|
627 | + $saved[ $field_group->index ][ $new_val[ 'supporting_field_id' ] ] = $new_val[ 'supporting_field_value' ]; |
|
628 | 628 | // Reset var to the actual value |
629 | - $new_val = $new_val['value']; |
|
629 | + $new_val = $new_val[ 'value' ]; |
|
630 | 630 | } |
631 | 631 | } |
632 | 632 | |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | $is_removed = ( empty( $new_val ) && ! empty( $old_val ) ); |
640 | 640 | // Compare values and add to `$updated` array |
641 | 641 | if ( $is_updated || $is_removed ) { |
642 | - $this->updated[] = $base_id . '::' . $field_group->index . '::' . $sub_id; |
|
642 | + $this->updated[ ] = $base_id . '::' . $field_group->index . '::' . $sub_id; |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | // Add to `$saved` array |
@@ -674,22 +674,22 @@ discard block |
||
674 | 674 | // Try to get our object ID from the global space |
675 | 675 | switch ( $this->object_type() ) { |
676 | 676 | case 'user': |
677 | - $object_id = isset( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : $object_id; |
|
678 | - $object_id = ! $object_id && 'user-new.php' != $pagenow && isset( $GLOBALS['user_ID'] ) ? $GLOBALS['user_ID'] : $object_id; |
|
677 | + $object_id = isset( $_REQUEST[ 'user_id' ] ) ? $_REQUEST[ 'user_id' ] : $object_id; |
|
678 | + $object_id = ! $object_id && 'user-new.php' != $pagenow && isset( $GLOBALS[ 'user_ID' ] ) ? $GLOBALS[ 'user_ID' ] : $object_id; |
|
679 | 679 | break; |
680 | 680 | |
681 | 681 | case 'comment': |
682 | - $object_id = isset( $_REQUEST['c'] ) ? $_REQUEST['c'] : $object_id; |
|
683 | - $object_id = ! $object_id && isset( $GLOBALS['comments']->comment_ID ) ? $GLOBALS['comments']->comment_ID : $object_id; |
|
682 | + $object_id = isset( $_REQUEST[ 'c' ] ) ? $_REQUEST[ 'c' ] : $object_id; |
|
683 | + $object_id = ! $object_id && isset( $GLOBALS[ 'comments' ]->comment_ID ) ? $GLOBALS[ 'comments' ]->comment_ID : $object_id; |
|
684 | 684 | break; |
685 | 685 | |
686 | 686 | case 'term': |
687 | - $object_id = isset( $_REQUEST['tag_ID'] ) ? $_REQUEST['tag_ID'] : $object_id; |
|
687 | + $object_id = isset( $_REQUEST[ 'tag_ID' ] ) ? $_REQUEST[ 'tag_ID' ] : $object_id; |
|
688 | 688 | break; |
689 | 689 | |
690 | 690 | default: |
691 | - $object_id = isset( $GLOBALS['post']->ID ) ? $GLOBALS['post']->ID : $object_id; |
|
692 | - $object_id = isset( $_REQUEST['post'] ) ? $_REQUEST['post'] : $object_id; |
|
691 | + $object_id = isset( $GLOBALS[ 'post' ]->ID ) ? $GLOBALS[ 'post' ]->ID : $object_id; |
|
692 | + $object_id = isset( $_REQUEST[ 'post' ] ) ? $_REQUEST[ 'post' ] : $object_id; |
|
693 | 693 | break; |
694 | 694 | } |
695 | 695 | |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | * @return boolean True/False |
762 | 762 | */ |
763 | 763 | public function is_options_page_mb() { |
764 | - 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'] ) ); |
|
764 | + 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' ] ) ); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | /** |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | return $field; |
825 | 825 | } |
826 | 826 | |
827 | - $field_id = is_string( $field ) ? $field : $field['id']; |
|
827 | + $field_id = is_string( $field ) ? $field : $field[ 'id' ]; |
|
828 | 828 | |
829 | 829 | $parent_field_id = ! empty( $field_group ) ? $field_group->id() : ''; |
830 | 830 | $ids = $this->get_field_ids( $field_id, $parent_field_id, true ); |
@@ -860,16 +860,16 @@ discard block |
||
860 | 860 | if ( $field_group && ( $sub_field_id || 0 === $sub_field_id ) ) { |
861 | 861 | |
862 | 862 | // Update the fields array w/ any modified properties inherited from the group field |
863 | - $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] = $field_args; |
|
863 | + $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] = $field_args; |
|
864 | 864 | |
865 | 865 | return $this->get_default_args( $field_args, $field_group ); |
866 | 866 | } |
867 | 867 | |
868 | 868 | if ( is_array( $field_args ) ) { |
869 | - $this->meta_box['fields'][ $field_id ] = array_merge( $field_args, $this->meta_box['fields'][ $field_id ] ); |
|
869 | + $this->meta_box[ 'fields' ][ $field_id ] = array_merge( $field_args, $this->meta_box[ 'fields' ][ $field_id ] ); |
|
870 | 870 | } |
871 | 871 | |
872 | - return $this->get_default_args( $this->meta_box['fields'][ $field_id ] ); |
|
872 | + return $this->get_default_args( $this->meta_box[ 'fields' ][ $field_id ] ); |
|
873 | 873 | } |
874 | 874 | |
875 | 875 | /** |
@@ -919,8 +919,8 @@ discard block |
||
919 | 919 | |
920 | 920 | $sub_fields = false; |
921 | 921 | if ( array_key_exists( 'fields', $field ) ) { |
922 | - $sub_fields = $field['fields']; |
|
923 | - unset( $field['fields'] ); |
|
922 | + $sub_fields = $field[ 'fields' ]; |
|
923 | + unset( $field[ 'fields' ] ); |
|
924 | 924 | } |
925 | 925 | |
926 | 926 | $field_id = $parent_field_id |
@@ -945,18 +945,18 @@ discard block |
||
945 | 945 | return false; |
946 | 946 | } |
947 | 947 | |
948 | - if ( 'oembed' === $field['type'] ) { |
|
948 | + if ( 'oembed' === $field[ 'type' ] ) { |
|
949 | 949 | // Initiate oembed Ajax hooks |
950 | 950 | cmb2_ajax(); |
951 | 951 | } |
952 | 952 | |
953 | 953 | $this->_add_field_to_array( |
954 | 954 | $field, |
955 | - $this->meta_box['fields'], |
|
955 | + $this->meta_box[ 'fields' ], |
|
956 | 956 | $position |
957 | 957 | ); |
958 | 958 | |
959 | - return $field['id']; |
|
959 | + return $field[ 'id' ]; |
|
960 | 960 | } |
961 | 961 | |
962 | 962 | /** |
@@ -968,27 +968,27 @@ discard block |
||
968 | 968 | * @return mixed Array of parent/field ids or false |
969 | 969 | */ |
970 | 970 | public function add_group_field( $parent_field_id, array $field, $position = 0 ) { |
971 | - if ( ! array_key_exists( $parent_field_id, $this->meta_box['fields'] ) ) { |
|
971 | + if ( ! array_key_exists( $parent_field_id, $this->meta_box[ 'fields' ] ) ) { |
|
972 | 972 | return false; |
973 | 973 | } |
974 | 974 | |
975 | - $parent_field = $this->meta_box['fields'][ $parent_field_id ]; |
|
975 | + $parent_field = $this->meta_box[ 'fields' ][ $parent_field_id ]; |
|
976 | 976 | |
977 | - if ( 'group' !== $parent_field['type'] ) { |
|
977 | + if ( 'group' !== $parent_field[ 'type' ] ) { |
|
978 | 978 | return false; |
979 | 979 | } |
980 | 980 | |
981 | - if ( ! isset( $parent_field['fields'] ) ) { |
|
982 | - $this->meta_box['fields'][ $parent_field_id ]['fields'] = array(); |
|
981 | + if ( ! isset( $parent_field[ 'fields' ] ) ) { |
|
982 | + $this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ] = array(); |
|
983 | 983 | } |
984 | 984 | |
985 | 985 | $this->_add_field_to_array( |
986 | 986 | $field, |
987 | - $this->meta_box['fields'][ $parent_field_id ]['fields'], |
|
987 | + $this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ], |
|
988 | 988 | $position |
989 | 989 | ); |
990 | 990 | |
991 | - return array( $parent_field_id, $field['id'] ); |
|
991 | + return array( $parent_field_id, $field[ 'id' ] ); |
|
992 | 992 | } |
993 | 993 | |
994 | 994 | /** |
@@ -1000,9 +1000,9 @@ discard block |
||
1000 | 1000 | */ |
1001 | 1001 | protected function _add_field_to_array( $field, &$fields, $position = 0 ) { |
1002 | 1002 | if ( $position ) { |
1003 | - cmb2_utils()->array_insert( $fields, array( $field['id'] => $field ), $position ); |
|
1003 | + cmb2_utils()->array_insert( $fields, array( $field[ 'id' ] => $field ), $position ); |
|
1004 | 1004 | } else { |
1005 | - $fields[ $field['id'] ] = $field; |
|
1005 | + $fields[ $field[ 'id' ] ] = $field; |
|
1006 | 1006 | } |
1007 | 1007 | } |
1008 | 1008 | |
@@ -1025,15 +1025,15 @@ discard block |
||
1025 | 1025 | unset( $this->fields[ implode( '', $ids ) ] ); |
1026 | 1026 | |
1027 | 1027 | if ( ! $sub_field_id ) { |
1028 | - unset( $this->meta_box['fields'][ $field_id ] ); |
|
1028 | + unset( $this->meta_box[ 'fields' ][ $field_id ] ); |
|
1029 | 1029 | return true; |
1030 | 1030 | } |
1031 | 1031 | |
1032 | - if ( isset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ) ) { |
|
1033 | - unset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ); |
|
1032 | + if ( isset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] ) ) { |
|
1033 | + unset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] ); |
|
1034 | 1034 | } |
1035 | - if ( isset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ) ) { |
|
1036 | - unset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ); |
|
1035 | + if ( isset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] ) ) { |
|
1036 | + unset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] ); |
|
1037 | 1037 | } |
1038 | 1038 | return true; |
1039 | 1039 | } |
@@ -1057,11 +1057,11 @@ discard block |
||
1057 | 1057 | list( $field_id, $sub_field_id ) = $ids; |
1058 | 1058 | |
1059 | 1059 | if ( ! $sub_field_id ) { |
1060 | - $this->meta_box['fields'][ $field_id ][ $property ] = $value; |
|
1060 | + $this->meta_box[ 'fields' ][ $field_id ][ $property ] = $value; |
|
1061 | 1061 | return $field_id; |
1062 | 1062 | } |
1063 | 1063 | |
1064 | - $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ][ $property ] = $value; |
|
1064 | + $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ][ $property ] = $value; |
|
1065 | 1065 | return $field_id; |
1066 | 1066 | } |
1067 | 1067 | |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | public function get_field_ids( $field_id, $parent_field_id = '' ) { |
1076 | 1076 | $sub_field_id = $parent_field_id ? $field_id : ''; |
1077 | 1077 | $field_id = $parent_field_id ? $parent_field_id : $field_id; |
1078 | - $fields =& $this->meta_box['fields']; |
|
1078 | + $fields = & $this->meta_box[ 'fields' ]; |
|
1079 | 1079 | |
1080 | 1080 | if ( ! array_key_exists( $field_id, $fields ) ) { |
1081 | 1081 | $field_id = $this->search_old_school_array( $field_id, $fields ); |
@@ -1089,12 +1089,12 @@ discard block |
||
1089 | 1089 | return array( $field_id, $sub_field_id ); |
1090 | 1090 | } |
1091 | 1091 | |
1092 | - if ( 'group' !== $fields[ $field_id ]['type'] ) { |
|
1092 | + if ( 'group' !== $fields[ $field_id ][ 'type' ] ) { |
|
1093 | 1093 | return false; |
1094 | 1094 | } |
1095 | 1095 | |
1096 | - if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ]['fields'] ) ) { |
|
1097 | - $sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ]['fields'] ); |
|
1096 | + if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ][ 'fields' ] ) ) { |
|
1097 | + $sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ][ 'fields' ] ); |
|
1098 | 1098 | } |
1099 | 1099 | |
1100 | 1100 | return false === $sub_field_id ? false : array( $field_id, $sub_field_id ); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | global $wp_locale; |
174 | 174 | |
175 | - $search = array( $wp_locale->number_format['thousands_sep'], $wp_locale->number_format['decimal_point'] ); |
|
175 | + $search = array( $wp_locale->number_format[ 'thousands_sep' ], $wp_locale->number_format[ 'decimal_point' ] ); |
|
176 | 176 | $replace = array( '', '.' ); |
177 | 177 | |
178 | 178 | // for repeatable |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | return $repeat_value; |
216 | 216 | } |
217 | 217 | |
218 | - if ( isset( $this->value['date'], $this->value['time'] ) ) { |
|
219 | - $this->value = $this->field->get_timestamp_from_value( $this->value['date'] . ' ' . $this->value['time'] ); |
|
218 | + if ( isset( $this->value[ 'date' ], $this->value[ 'time' ] ) ) { |
|
219 | + $this->value = $this->field->get_timestamp_from_value( $this->value[ 'date' ] . ' ' . $this->value[ 'time' ] ); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | if ( $tz_offset = $this->field->field_timezone_offset() ) { |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | $tzstring = null; |
255 | 255 | |
256 | 256 | if ( is_array( $this->value ) && array_key_exists( 'timezone', $this->value ) ) { |
257 | - $tzstring = $this->value['timezone']; |
|
257 | + $tzstring = $this->value[ 'timezone' ]; |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | if ( empty( $tzstring ) ) { |
@@ -274,8 +274,8 @@ discard block |
||
274 | 274 | $tzstring = false !== $tzstring ? $tzstring : timezone_name_from_abbr( '', 0, 0 ); |
275 | 275 | } |
276 | 276 | |
277 | - $full_format = $this->field->args['date_format'] . ' ' . $this->field->args['time_format']; |
|
278 | - $full_date = $this->value['date'] . ' ' . $this->value['time']; |
|
277 | + $full_format = $this->field->args[ 'date_format' ] . ' ' . $this->field->args[ 'time_format' ]; |
|
278 | + $full_date = $this->value[ 'date' ] . ' ' . $this->value[ 'time' ]; |
|
279 | 279 | |
280 | 280 | try { |
281 | 281 | |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | } else { |
299 | 299 | // Save the utc timestamp supporting field |
300 | 300 | if ( $repeat ) { |
301 | - $utc_values[ $utc_key ][] = $utc_stamp; |
|
301 | + $utc_values[ $utc_key ][ ] = $utc_stamp; |
|
302 | 302 | } else { |
303 | 303 | $this->_save_utc_value( $utc_key, $utc_stamp ); |
304 | 304 | } |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | if ( $this->value ) { |
434 | 434 | $val = $this->$method( true ); |
435 | 435 | if ( ! empty( $val ) ) { |
436 | - $new_value[] = $val; |
|
436 | + $new_value[ ] = $val; |
|
437 | 437 | } |
438 | 438 | } |
439 | 439 | } |
@@ -100,21 +100,21 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function __construct( $args ) { |
102 | 102 | |
103 | - if ( ! empty( $args['group_field'] ) ) { |
|
104 | - $this->group = $args['group_field']; |
|
103 | + if ( ! empty( $args[ 'group_field' ] ) ) { |
|
104 | + $this->group = $args[ 'group_field' ]; |
|
105 | 105 | $this->object_id = $this->group->object_id; |
106 | 106 | $this->object_type = $this->group->object_type; |
107 | 107 | $this->cmb_id = $this->group->cmb_id; |
108 | 108 | } else { |
109 | - $this->object_id = isset( $args['object_id'] ) && '_' !== $args['object_id'] ? $args['object_id'] : 0; |
|
110 | - $this->object_type = isset( $args['object_type'] ) ? $args['object_type'] : 'post'; |
|
109 | + $this->object_id = isset( $args[ 'object_id' ] ) && '_' !== $args[ 'object_id' ] ? $args[ 'object_id' ] : 0; |
|
110 | + $this->object_type = isset( $args[ 'object_type' ] ) ? $args[ 'object_type' ] : 'post'; |
|
111 | 111 | |
112 | - if ( isset( $args['cmb_id'] ) ) { |
|
113 | - $this->cmb_id = $args['cmb_id']; |
|
112 | + if ( isset( $args[ 'cmb_id' ] ) ) { |
|
113 | + $this->cmb_id = $args[ 'cmb_id' ]; |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | - $this->args = $this->_set_field_defaults( $args['field_args'] ); |
|
117 | + $this->args = $this->_set_field_defaults( $args[ 'field_args' ] ); |
|
118 | 118 | |
119 | 119 | if ( $this->object_id ) { |
120 | 120 | $this->value = $this->get_data(); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @return mixed Value of field argument |
130 | 130 | */ |
131 | 131 | public function __call( $name, $arguments ) { |
132 | - $key = isset( $arguments[0] ) ? $arguments[0] : false; |
|
132 | + $key = isset( $arguments[ 0 ] ) ? $arguments[ 0 ] : false; |
|
133 | 133 | return $this->args( $name, $key ); |
134 | 134 | } |
135 | 135 | |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function get_data( $field_id = '', $args = array() ) { |
202 | 202 | if ( $field_id ) { |
203 | - $args['field_id'] = $field_id; |
|
203 | + $args[ 'field_id' ] = $field_id; |
|
204 | 204 | } else if ( $this->group ) { |
205 | - $args['field_id'] = $this->group->id(); |
|
205 | + $args[ 'field_id' ] = $this->group->id(); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | $a = $this->data_args( $args ); |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @since 2.0.0 |
245 | 245 | */ |
246 | - $data = apply_filters( "cmb2_override_{$a['field_id']}_meta_value", $data, $this->object_id, $a, $this ); |
|
246 | + $data = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_value", $data, $this->object_id, $a, $this ); |
|
247 | 247 | |
248 | 248 | // If no override, get value normally |
249 | 249 | if ( 'cmb2_field_no_override_val' === $data ) { |
250 | - $data = 'options-page' === $a['type'] |
|
251 | - ? cmb2_options( $a['id'] )->get( $a['field_id'] ) |
|
252 | - : get_metadata( $a['type'], $a['id'], $a['field_id'], ( $a['single'] || $a['repeat'] ) ); |
|
250 | + $data = 'options-page' === $a[ 'type' ] |
|
251 | + ? cmb2_options( $a[ 'id' ] )->get( $a[ 'field_id' ] ) |
|
252 | + : get_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], ( $a[ 'single' ] || $a[ 'repeat' ] ) ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | if ( $this->group ) { |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | public function update_data( $new_value, $single = true ) { |
272 | 272 | $a = $this->data_args( array( 'single' => $single ) ); |
273 | 273 | |
274 | - $a['value'] = $a['repeat'] ? array_values( $new_value ) : $new_value; |
|
274 | + $a[ 'value' ] = $a[ 'repeat' ] ? array_values( $new_value ) : $new_value; |
|
275 | 275 | |
276 | 276 | /** |
277 | 277 | * Filter whether to override saving of meta value. |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | * |
308 | 308 | * @since 2.0.0 |
309 | 309 | */ |
310 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_save", $override, $a, $this->args(), $this ); |
|
310 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_save", $override, $a, $this->args(), $this ); |
|
311 | 311 | |
312 | 312 | // If override, return that |
313 | 313 | if ( null !== $override ) { |
@@ -315,22 +315,22 @@ discard block |
||
315 | 315 | } |
316 | 316 | |
317 | 317 | // Options page handling (or temp data store) |
318 | - if ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
319 | - return cmb2_options( $a['id'] )->update( $a['field_id'], $a['value'], false, $a['single'] ); |
|
318 | + if ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
319 | + return cmb2_options( $a[ 'id' ] )->update( $a[ 'field_id' ], $a[ 'value' ], false, $a[ 'single' ] ); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // Add metadata if not single |
323 | - if ( ! $a['single'] ) { |
|
324 | - return add_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'], false ); |
|
323 | + if ( ! $a[ 'single' ] ) { |
|
324 | + return add_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ], false ); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | // Delete meta if we have an empty array |
328 | - if ( is_array( $a['value'] ) && empty( $a['value'] ) ) { |
|
329 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $this->value ); |
|
328 | + if ( is_array( $a[ 'value' ] ) && empty( $a[ 'value' ] ) ) { |
|
329 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $this->value ); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | // Update metadata |
333 | - return update_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'] ); |
|
333 | + return update_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ] ); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -380,19 +380,19 @@ discard block |
||
380 | 380 | * @param array $field_args All field arguments |
381 | 381 | * @param CMB2_Field object $field This field object |
382 | 382 | */ |
383 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_remove", $override, $a, $this->args(), $this ); |
|
383 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_remove", $override, $a, $this->args(), $this ); |
|
384 | 384 | |
385 | 385 | // If no override, remove as usual |
386 | 386 | if ( null !== $override ) { |
387 | 387 | return $override; |
388 | 388 | } |
389 | 389 | // Option page handling |
390 | - elseif ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
391 | - return cmb2_options( $a['id'] )->remove( $a['field_id'] ); |
|
390 | + elseif ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
391 | + return cmb2_options( $a[ 'id' ] )->remove( $a[ 'field_id' ] ); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | // Remove metadata |
395 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $old ); |
|
395 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $old ); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -863,7 +863,7 @@ discard block |
||
863 | 863 | |
864 | 864 | foreach ( $conditional_classes as $class => $condition ) { |
865 | 865 | if ( $condition ) { |
866 | - $classes[] = $class; |
|
866 | + $classes[ ] = $class; |
|
867 | 867 | } |
868 | 868 | } |
869 | 869 | |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | } |
873 | 873 | |
874 | 874 | if ( $added_classes ) { |
875 | - $classes[] = esc_attr( $added_classes ); |
|
875 | + $classes[ ] = esc_attr( $added_classes ); |
|
876 | 876 | } |
877 | 877 | |
878 | 878 | /** |
@@ -977,10 +977,10 @@ discard block |
||
977 | 977 | return $this->field_options; |
978 | 978 | } |
979 | 979 | |
980 | - $this->field_options = (array) $this->args['options']; |
|
980 | + $this->field_options = (array) $this->args[ 'options' ]; |
|
981 | 981 | |
982 | - if ( is_callable( $this->args['options_cb'] ) ) { |
|
983 | - $options = call_user_func( $this->args['options_cb'], $this ); |
|
982 | + if ( is_callable( $this->args[ 'options_cb' ] ) ) { |
|
983 | + $options = call_user_func( $this->args[ 'options_cb' ], $this ); |
|
984 | 984 | |
985 | 985 | if ( $options && is_array( $options ) ) { |
986 | 986 | $this->field_options += $options; |
@@ -1002,17 +1002,17 @@ discard block |
||
1002 | 1002 | * @return mixed Default field value |
1003 | 1003 | */ |
1004 | 1004 | public function get_default() { |
1005 | - if ( null !== $this->args['default'] ) { |
|
1006 | - return $this->args['default']; |
|
1005 | + if ( null !== $this->args[ 'default' ] ) { |
|
1006 | + return $this->args[ 'default' ]; |
|
1007 | 1007 | } |
1008 | 1008 | |
1009 | - $param = is_callable( $this->args['default_cb'] ) ? 'default_cb' : 'default'; |
|
1009 | + $param = is_callable( $this->args[ 'default_cb' ] ) ? 'default_cb' : 'default'; |
|
1010 | 1010 | $default = $this->get_param_callback_result( $param, false ); |
1011 | 1011 | |
1012 | 1012 | // Allow a filter override of the default value |
1013 | - $this->args['default'] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
1013 | + $this->args[ 'default' ] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
1014 | 1014 | |
1015 | - return $this->args['default']; |
|
1015 | + return $this->args[ 'default' ]; |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | /** |
@@ -1037,68 +1037,68 @@ discard block |
||
1037 | 1037 | 'default_cb' => '', |
1038 | 1038 | 'select_all_button' => true, |
1039 | 1039 | 'multiple' => false, |
1040 | - 'repeatable' => isset( $args['type'] ) && 'group' == $args['type'], |
|
1040 | + 'repeatable' => isset( $args[ 'type' ] ) && 'group' == $args[ 'type' ], |
|
1041 | 1041 | 'inline' => false, |
1042 | 1042 | 'on_front' => true, |
1043 | 1043 | 'show_names' => true, |
1044 | 1044 | 'date_format' => 'm\/d\/Y', |
1045 | 1045 | 'time_format' => 'h:i A', |
1046 | - 'description' => isset( $args['desc'] ) ? $args['desc'] : '', |
|
1047 | - 'preview_size' => 'file' == $args['type'] ? array( 350, 350 ) : array( 50, 50 ), |
|
1046 | + 'description' => isset( $args[ 'desc' ] ) ? $args[ 'desc' ] : '', |
|
1047 | + 'preview_size' => 'file' == $args[ 'type' ] ? array( 350, 350 ) : array( 50, 50 ), |
|
1048 | 1048 | 'render_row_cb' => array( $this, 'render_field_callback' ), |
1049 | - 'label_cb' => 'title' != $args['type'] ? array( $this, 'label' ) : '', |
|
1049 | + 'label_cb' => 'title' != $args[ 'type' ] ? array( $this, 'label' ) : '', |
|
1050 | 1050 | ) ); |
1051 | 1051 | |
1052 | 1052 | // default param can be passed a callback as well |
1053 | - if ( is_callable( $args['default'] ) ) { |
|
1054 | - $args['default_cb'] = $args['default']; |
|
1055 | - $args['default'] = null; |
|
1053 | + if ( is_callable( $args[ 'default' ] ) ) { |
|
1054 | + $args[ 'default_cb' ] = $args[ 'default' ]; |
|
1055 | + $args[ 'default' ] = null; |
|
1056 | 1056 | } |
1057 | 1057 | |
1058 | - $args['repeatable'] = $args['repeatable'] && ! $this->repeatable_exception( $args['type'] ); |
|
1059 | - $args['inline'] = $args['inline'] || false !== stripos( $args['type'], '_inline' ); |
|
1058 | + $args[ 'repeatable' ] = $args[ 'repeatable' ] && ! $this->repeatable_exception( $args[ 'type' ] ); |
|
1059 | + $args[ 'inline' ] = $args[ 'inline' ] || false !== stripos( $args[ 'type' ], '_inline' ); |
|
1060 | 1060 | |
1061 | 1061 | // options param can be passed a callback as well |
1062 | - if ( is_callable( $args['options'] ) ) { |
|
1063 | - $args['options_cb'] = $args['options']; |
|
1064 | - $args['options'] = array(); |
|
1062 | + if ( is_callable( $args[ 'options' ] ) ) { |
|
1063 | + $args[ 'options_cb' ] = $args[ 'options' ]; |
|
1064 | + $args[ 'options' ] = array(); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $args['options'] = 'group' == $args['type'] ? wp_parse_args( $args['options'], array( |
|
1067 | + $args[ 'options' ] = 'group' == $args[ 'type' ] ? wp_parse_args( $args[ 'options' ], array( |
|
1068 | 1068 | 'add_button' => __( 'Add Group', 'cmb2' ), |
1069 | 1069 | 'remove_button' => __( 'Remove Group', 'cmb2' ), |
1070 | - ) ) : $args['options']; |
|
1070 | + ) ) : $args[ 'options' ]; |
|
1071 | 1071 | |
1072 | - $args['_id'] = $args['id']; |
|
1073 | - $args['_name'] = $args['id']; |
|
1072 | + $args[ '_id' ] = $args[ 'id' ]; |
|
1073 | + $args[ '_name' ] = $args[ 'id' ]; |
|
1074 | 1074 | |
1075 | 1075 | if ( $this->group ) { |
1076 | 1076 | |
1077 | - $args['id'] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args['id']; |
|
1078 | - $args['_name'] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args['_name'] . ']'; |
|
1077 | + $args[ 'id' ] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args[ 'id' ]; |
|
1078 | + $args[ '_name' ] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args[ '_name' ] . ']'; |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | - if ( 'wysiwyg' == $args['type'] ) { |
|
1082 | - $args['id'] = strtolower( str_ireplace( '-', '_', $args['id'] ) ); |
|
1083 | - $args['options']['textarea_name'] = $args['_name']; |
|
1081 | + if ( 'wysiwyg' == $args[ 'type' ] ) { |
|
1082 | + $args[ 'id' ] = strtolower( str_ireplace( '-', '_', $args[ 'id' ] ) ); |
|
1083 | + $args[ 'options' ][ 'textarea_name' ] = $args[ '_name' ]; |
|
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | $option_types = apply_filters( 'cmb2_all_or_nothing_types', array( 'select', 'radio', 'radio_inline', 'taxonomy_select', 'taxonomy_radio', 'taxonomy_radio_inline' ), $this ); |
1087 | 1087 | |
1088 | - if ( in_array( $args['type'], $option_types, true ) ) { |
|
1088 | + if ( in_array( $args[ 'type' ], $option_types, true ) ) { |
|
1089 | 1089 | |
1090 | - $args['show_option_none'] = isset( $args['show_option_none'] ) ? $args['show_option_none'] : null; |
|
1091 | - $args['show_option_none'] = true === $args['show_option_none'] ? __( 'None', 'cmb2' ) : $args['show_option_none']; |
|
1090 | + $args[ 'show_option_none' ] = isset( $args[ 'show_option_none' ] ) ? $args[ 'show_option_none' ] : null; |
|
1091 | + $args[ 'show_option_none' ] = true === $args[ 'show_option_none' ] ? __( 'None', 'cmb2' ) : $args[ 'show_option_none' ]; |
|
1092 | 1092 | |
1093 | - if ( null === $args['show_option_none'] ) { |
|
1094 | - $off_by_default = in_array( $args['type'], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1095 | - $args['show_option_none'] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
1093 | + if ( null === $args[ 'show_option_none' ] ) { |
|
1094 | + $off_by_default = in_array( $args[ 'type' ], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1095 | + $args[ 'show_option_none' ] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | } |
1099 | 1099 | |
1100 | - $args['has_supporting_data'] = in_array( |
|
1101 | - $args['type'], |
|
1100 | + $args[ 'has_supporting_data' ] = in_array( |
|
1101 | + $args[ 'type' ], |
|
1102 | 1102 | array( |
1103 | 1103 | // CMB2_Sanitize::_save_file_id_value()/CMB2_Sanitize::_get_group_file_value_array() |
1104 | 1104 | 'file', |
@@ -1130,10 +1130,10 @@ discard block |
||
1130 | 1130 | 'cmb_id' => $this->cmb_id, |
1131 | 1131 | ); |
1132 | 1132 | |
1133 | - if ( isset( $field_args['field_args'] ) ) { |
|
1133 | + if ( isset( $field_args[ 'field_args' ] ) ) { |
|
1134 | 1134 | $args = wp_parse_args( $field_args, $args ); |
1135 | 1135 | } else { |
1136 | - $args['field_args'] = wp_parse_args( $field_args, $this->args ); |
|
1136 | + $args[ 'field_args' ] = wp_parse_args( $field_args, $this->args ); |
|
1137 | 1137 | } |
1138 | 1138 | |
1139 | 1139 | return new CMB2_Field( $args ); |
@@ -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 |