@@ -1,46 +1,46 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * @category WordPress_Plugin |
|
4 | - * @package CMB2 |
|
5 | - * @author WebDevStudios |
|
6 | - * @license GPL-2.0+ |
|
7 | - * @link http://webdevstudios.com |
|
8 | - * |
|
9 | - * Plugin Name: CMB2 |
|
10 | - * Plugin URI: https://github.com/WebDevStudios/CMB2 |
|
11 | - * Description: CMB2 will create metaboxes and forms with custom fields that will blow your mind. |
|
12 | - * Author: WebDevStudios |
|
13 | - * Author URI: http://webdevstudios.com |
|
14 | - * Contributors: WebDevStudios (@webdevstudios / webdevstudios.com) |
|
15 | - * Justin Sternberg (@jtsternberg / dsgnwrks.pro) |
|
16 | - * Jared Atchison (@jaredatch / jaredatchison.com) |
|
17 | - * Bill Erickson (@billerickson / billerickson.net) |
|
18 | - * Andrew Norcross (@norcross / andrewnorcross.com) |
|
19 | - * |
|
20 | - * Version: 2.1.2 |
|
21 | - * |
|
22 | - * Text Domain: cmb2 |
|
23 | - * Domain Path: languages |
|
24 | - * |
|
25 | - * |
|
26 | - * Released under the GPL license |
|
27 | - * http://www.opensource.org/licenses/gpl-license.php |
|
28 | - * |
|
29 | - * This is an add-on for WordPress |
|
30 | - * http://wordpress.org/ |
|
31 | - * |
|
32 | - * ********************************************************************** |
|
33 | - * This program is free software; you can redistribute it and/or modify |
|
34 | - * it under the terms of the GNU General Public License as published by |
|
35 | - * the Free Software Foundation; either version 2 of the License, or |
|
36 | - * (at your option) any later version. |
|
37 | - * |
|
38 | - * This program is distributed in the hope that it will be useful, |
|
39 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
40 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
41 | - * GNU General Public License for more details. |
|
42 | - * ********************************************************************** |
|
43 | - */ |
|
3 | + * @category WordPress_Plugin |
|
4 | + * @package CMB2 |
|
5 | + * @author WebDevStudios |
|
6 | + * @license GPL-2.0+ |
|
7 | + * @link http://webdevstudios.com |
|
8 | + * |
|
9 | + * Plugin Name: CMB2 |
|
10 | + * Plugin URI: https://github.com/WebDevStudios/CMB2 |
|
11 | + * Description: CMB2 will create metaboxes and forms with custom fields that will blow your mind. |
|
12 | + * Author: WebDevStudios |
|
13 | + * Author URI: http://webdevstudios.com |
|
14 | + * Contributors: WebDevStudios (@webdevstudios / webdevstudios.com) |
|
15 | + * Justin Sternberg (@jtsternberg / dsgnwrks.pro) |
|
16 | + * Jared Atchison (@jaredatch / jaredatchison.com) |
|
17 | + * Bill Erickson (@billerickson / billerickson.net) |
|
18 | + * Andrew Norcross (@norcross / andrewnorcross.com) |
|
19 | + * |
|
20 | + * Version: 2.1.2 |
|
21 | + * |
|
22 | + * Text Domain: cmb2 |
|
23 | + * Domain Path: languages |
|
24 | + * |
|
25 | + * |
|
26 | + * Released under the GPL license |
|
27 | + * http://www.opensource.org/licenses/gpl-license.php |
|
28 | + * |
|
29 | + * This is an add-on for WordPress |
|
30 | + * http://wordpress.org/ |
|
31 | + * |
|
32 | + * ********************************************************************** |
|
33 | + * This program is free software; you can redistribute it and/or modify |
|
34 | + * it under the terms of the GNU General Public License as published by |
|
35 | + * the Free Software Foundation; either version 2 of the License, or |
|
36 | + * (at your option) any later version. |
|
37 | + * |
|
38 | + * This program is distributed in the hope that it will be useful, |
|
39 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
40 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
41 | + * GNU General Public License for more details. |
|
42 | + * ********************************************************************** |
|
43 | + */ |
|
44 | 44 | |
45 | 45 | /************************************************************************ |
46 | 46 | You should not edit the code below |
@@ -121,19 +121,19 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function __construct( $meta_box, $object_id = 0 ) { |
123 | 123 | |
124 | - if ( empty( $meta_box['id'] ) ) { |
|
124 | + if ( empty( $meta_box[ 'id' ] ) ) { |
|
125 | 125 | wp_die( __( 'Metabox configuration is required to have an ID parameter', 'cmb2' ) ); |
126 | 126 | } |
127 | 127 | |
128 | 128 | $this->meta_box = wp_parse_args( $meta_box, $this->mb_defaults ); |
129 | - $this->meta_box['fields'] = array(); |
|
129 | + $this->meta_box[ 'fields' ] = array(); |
|
130 | 130 | |
131 | 131 | $this->object_id( $object_id ); |
132 | 132 | $this->mb_object_type(); |
133 | - $this->cmb_id = $meta_box['id']; |
|
133 | + $this->cmb_id = $meta_box[ 'id' ]; |
|
134 | 134 | |
135 | - if ( ! empty( $meta_box['fields'] ) && is_array( $meta_box['fields'] ) ) { |
|
136 | - $this->add_fields( $meta_box['fields'] ); |
|
135 | + if ( ! empty( $meta_box[ 'fields' ] ) && is_array( $meta_box[ 'fields' ] ) ) { |
|
136 | + $this->add_fields( $meta_box[ 'fields' ] ); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | CMB2_Boxes::add( $this ); |
@@ -264,16 +264,16 @@ discard block |
||
264 | 264 | * @return mixed CMB2_Field object if successful. |
265 | 265 | */ |
266 | 266 | public function render_field( $field_args ) { |
267 | - $field_args['context'] = $this->prop( 'context' ); |
|
267 | + $field_args[ 'context' ] = $this->prop( 'context' ); |
|
268 | 268 | |
269 | - if ( 'group' == $field_args['type'] ) { |
|
269 | + if ( 'group' == $field_args[ 'type' ] ) { |
|
270 | 270 | |
271 | - if ( ! isset( $field_args['show_names'] ) ) { |
|
272 | - $field_args['show_names'] = $this->prop( 'show_names' ); |
|
271 | + if ( ! isset( $field_args[ 'show_names' ] ) ) { |
|
272 | + $field_args[ 'show_names' ] = $this->prop( 'show_names' ); |
|
273 | 273 | } |
274 | 274 | $field = $this->render_group( $field_args ); |
275 | 275 | |
276 | - } elseif ( 'hidden' == $field_args['type'] && $this->get_field( $field_args )->should_show() ) { |
|
276 | + } elseif ( 'hidden' == $field_args[ 'type' ] && $this->get_field( $field_args )->should_show() ) { |
|
277 | 277 | // Save rendering for after the metabox |
278 | 278 | $field = $this->add_hidden_field( array( |
279 | 279 | 'field_args' => $field_args, |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | |
284 | 284 | } else { |
285 | 285 | |
286 | - $field_args['show_names'] = $this->prop( 'show_names' ); |
|
286 | + $field_args[ 'show_names' ] = $this->prop( 'show_names' ); |
|
287 | 287 | |
288 | 288 | // Render default fields |
289 | 289 | $field = $this->get_field( $field_args )->render_field(); |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | */ |
300 | 300 | public function render_group( $args ) { |
301 | 301 | |
302 | - if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) { |
|
302 | + if ( ! isset( $args[ 'id' ], $args[ 'fields' ] ) || ! is_array( $args[ 'fields' ] ) ) { |
|
303 | 303 | return; |
304 | 304 | } |
305 | 305 | |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | <div class="inside cmb-td cmb-nested cmb-field-list">'; |
382 | 382 | // Loop and render repeatable group fields |
383 | 383 | foreach ( array_values( $field_group->args( 'fields' ) ) as $field_args ) { |
384 | - if ( 'hidden' == $field_args['type'] ) { |
|
384 | + if ( 'hidden' == $field_args[ 'type' ] ) { |
|
385 | 385 | |
386 | 386 | // Save rendering for after the metabox |
387 | 387 | $this->add_hidden_field( array( |
@@ -391,8 +391,8 @@ discard block |
||
391 | 391 | |
392 | 392 | } else { |
393 | 393 | |
394 | - $field_args['show_names'] = $field_group->args( 'show_names' ); |
|
395 | - $field_args['context'] = $field_group->args( 'context' ); |
|
394 | + $field_args[ 'show_names' ] = $field_group->args( 'show_names' ); |
|
395 | + $field_args[ 'context' ] = $field_group->args( 'context' ); |
|
396 | 396 | |
397 | 397 | $field = $this->get_field( $field_args, $field_group )->render_field(); |
398 | 398 | } |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | */ |
422 | 422 | public function add_hidden_field( $args ) { |
423 | 423 | $field = new CMB2_Field( $args ); |
424 | - $this->hidden_fields[] = new CMB2_Types( $field ); |
|
424 | + $this->hidden_fields[ ] = new CMB2_Types( $field ); |
|
425 | 425 | |
426 | 426 | return $field; |
427 | 427 | } |
@@ -518,11 +518,11 @@ discard block |
||
518 | 518 | */ |
519 | 519 | public function process_field( $field_args ) { |
520 | 520 | |
521 | - switch ( $field_args['type'] ) { |
|
521 | + switch ( $field_args[ 'type' ] ) { |
|
522 | 522 | |
523 | 523 | case 'group': |
524 | 524 | if ( $this->save_group( $field_args ) ) { |
525 | - $this->updated[] = $field_args['id']; |
|
525 | + $this->updated[ ] = $field_args[ 'id' ]; |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | break; |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | ) ); |
542 | 542 | |
543 | 543 | if ( $field->save_field_from_data( $this->data_to_save ) ) { |
544 | - $this->updated[] = $field->id(); |
|
544 | + $this->updated[ ] = $field->id(); |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | break; |
@@ -608,7 +608,7 @@ discard block |
||
608 | 608 | * @return mixed Return of CMB2_Field::update_data() |
609 | 609 | */ |
610 | 610 | public function save_group( $args ) { |
611 | - if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) { |
|
611 | + if ( ! isset( $args[ 'id' ], $args[ 'fields' ] ) || ! is_array( $args[ 'fields' ] ) ) { |
|
612 | 612 | return; |
613 | 613 | } |
614 | 614 | |
@@ -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 | |
@@ -806,7 +806,7 @@ discard block |
||
806 | 806 | * @return boolean True/False |
807 | 807 | */ |
808 | 808 | public function is_options_page_mb() { |
809 | - 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'] ) ); |
|
809 | + 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' ] ) ); |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | /** |
@@ -872,7 +872,7 @@ discard block |
||
872 | 872 | return $field; |
873 | 873 | } |
874 | 874 | |
875 | - $field_id = is_string( $field ) ? $field : $field['id']; |
|
875 | + $field_id = is_string( $field ) ? $field : $field[ 'id' ]; |
|
876 | 876 | |
877 | 877 | $parent_field_id = ! empty( $field_group ) ? $field_group->id() : ''; |
878 | 878 | $ids = $this->get_field_ids( $field_id, $parent_field_id, true ); |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | if ( $field_group && ( $sub_field_id || 0 === $sub_field_id ) ) { |
909 | 909 | |
910 | 910 | // Update the fields array w/ any modified properties inherited from the group field |
911 | - $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] = $field_args; |
|
911 | + $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] = $field_args; |
|
912 | 912 | |
913 | 913 | return array( |
914 | 914 | 'field_args' => $field_args, |
@@ -918,11 +918,11 @@ discard block |
||
918 | 918 | } |
919 | 919 | |
920 | 920 | if ( is_array( $field_args ) ) { |
921 | - $this->meta_box['fields'][ $field_id ] = array_merge( $field_args, $this->meta_box['fields'][ $field_id ] ); |
|
921 | + $this->meta_box[ 'fields' ][ $field_id ] = array_merge( $field_args, $this->meta_box[ 'fields' ][ $field_id ] ); |
|
922 | 922 | } |
923 | 923 | |
924 | 924 | return array( |
925 | - 'field_args' => $this->meta_box['fields'][ $field_id ], |
|
925 | + 'field_args' => $this->meta_box[ 'fields' ][ $field_id ], |
|
926 | 926 | 'object_type' => $this->object_type(), |
927 | 927 | 'object_id' => $this->object_id(), |
928 | 928 | ); |
@@ -939,8 +939,8 @@ discard block |
||
939 | 939 | |
940 | 940 | $sub_fields = false; |
941 | 941 | if ( array_key_exists( 'fields', $field ) ) { |
942 | - $sub_fields = $field['fields']; |
|
943 | - unset( $field['fields'] ); |
|
942 | + $sub_fields = $field[ 'fields' ]; |
|
943 | + unset( $field[ 'fields' ] ); |
|
944 | 944 | } |
945 | 945 | |
946 | 946 | $field_id = $parent_field_id |
@@ -967,11 +967,11 @@ discard block |
||
967 | 967 | |
968 | 968 | $this->_add_field_to_array( |
969 | 969 | $field, |
970 | - $this->meta_box['fields'], |
|
970 | + $this->meta_box[ 'fields' ], |
|
971 | 971 | $position |
972 | 972 | ); |
973 | 973 | |
974 | - return $field['id']; |
|
974 | + return $field[ 'id' ]; |
|
975 | 975 | } |
976 | 976 | |
977 | 977 | /** |
@@ -983,27 +983,27 @@ discard block |
||
983 | 983 | * @return mixed Array of parent/field ids or false |
984 | 984 | */ |
985 | 985 | public function add_group_field( $parent_field_id, array $field, $position = 0 ) { |
986 | - if ( ! array_key_exists( $parent_field_id, $this->meta_box['fields'] ) ) { |
|
986 | + if ( ! array_key_exists( $parent_field_id, $this->meta_box[ 'fields' ] ) ) { |
|
987 | 987 | return false; |
988 | 988 | } |
989 | 989 | |
990 | - $parent_field = $this->meta_box['fields'][ $parent_field_id ]; |
|
990 | + $parent_field = $this->meta_box[ 'fields' ][ $parent_field_id ]; |
|
991 | 991 | |
992 | - if ( 'group' !== $parent_field['type'] ) { |
|
992 | + if ( 'group' !== $parent_field[ 'type' ] ) { |
|
993 | 993 | return false; |
994 | 994 | } |
995 | 995 | |
996 | - if ( ! isset( $parent_field['fields'] ) ) { |
|
997 | - $this->meta_box['fields'][ $parent_field_id ]['fields'] = array(); |
|
996 | + if ( ! isset( $parent_field[ 'fields' ] ) ) { |
|
997 | + $this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ] = array(); |
|
998 | 998 | } |
999 | 999 | |
1000 | 1000 | $this->_add_field_to_array( |
1001 | 1001 | $field, |
1002 | - $this->meta_box['fields'][ $parent_field_id ]['fields'], |
|
1002 | + $this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ], |
|
1003 | 1003 | $position |
1004 | 1004 | ); |
1005 | 1005 | |
1006 | - return array( $parent_field_id, $field['id'] ); |
|
1006 | + return array( $parent_field_id, $field[ 'id' ] ); |
|
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | /** |
@@ -1015,9 +1015,9 @@ discard block |
||
1015 | 1015 | */ |
1016 | 1016 | protected function _add_field_to_array( $field, &$fields, $position = 0 ) { |
1017 | 1017 | if ( $position ) { |
1018 | - cmb2_utils()->array_insert( $fields, array( $field['id'] => $field ), $position ); |
|
1018 | + cmb2_utils()->array_insert( $fields, array( $field[ 'id' ] => $field ), $position ); |
|
1019 | 1019 | } else { |
1020 | - $fields[ $field['id'] ] = $field; |
|
1020 | + $fields[ $field[ 'id' ] ] = $field; |
|
1021 | 1021 | } |
1022 | 1022 | } |
1023 | 1023 | |
@@ -1040,12 +1040,12 @@ discard block |
||
1040 | 1040 | unset( $this->fields[ implode( '', $ids ) ] ); |
1041 | 1041 | |
1042 | 1042 | if ( ! $sub_field_id ) { |
1043 | - unset( $this->meta_box['fields'][ $field_id ] ); |
|
1043 | + unset( $this->meta_box[ 'fields' ][ $field_id ] ); |
|
1044 | 1044 | return true; |
1045 | 1045 | } |
1046 | 1046 | |
1047 | - unset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ); |
|
1048 | - unset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ); |
|
1047 | + unset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] ); |
|
1048 | + unset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] ); |
|
1049 | 1049 | return true; |
1050 | 1050 | } |
1051 | 1051 | |
@@ -1068,11 +1068,11 @@ discard block |
||
1068 | 1068 | list( $field_id, $sub_field_id ) = $ids; |
1069 | 1069 | |
1070 | 1070 | if ( ! $sub_field_id ) { |
1071 | - $this->meta_box['fields'][ $field_id ][ $property ] = $value; |
|
1071 | + $this->meta_box[ 'fields' ][ $field_id ][ $property ] = $value; |
|
1072 | 1072 | return $field_id; |
1073 | 1073 | } |
1074 | 1074 | |
1075 | - $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ][ $property ] = $value; |
|
1075 | + $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ][ $property ] = $value; |
|
1076 | 1076 | return $field_id; |
1077 | 1077 | } |
1078 | 1078 | |
@@ -1086,7 +1086,7 @@ discard block |
||
1086 | 1086 | public function get_field_ids( $field_id, $parent_field_id = '' ) { |
1087 | 1087 | $sub_field_id = $parent_field_id ? $field_id : ''; |
1088 | 1088 | $field_id = $parent_field_id ? $parent_field_id : $field_id; |
1089 | - $fields =& $this->meta_box['fields']; |
|
1089 | + $fields = & $this->meta_box[ 'fields' ]; |
|
1090 | 1090 | |
1091 | 1091 | if ( ! array_key_exists( $field_id, $fields ) ) { |
1092 | 1092 | $field_id = $this->search_old_school_array( $field_id, $fields ); |
@@ -1100,12 +1100,12 @@ discard block |
||
1100 | 1100 | return array( $field_id, $sub_field_id ); |
1101 | 1101 | } |
1102 | 1102 | |
1103 | - if ( 'group' !== $fields[ $field_id ]['type'] ) { |
|
1103 | + if ( 'group' !== $fields[ $field_id ][ 'type' ] ) { |
|
1104 | 1104 | return false; |
1105 | 1105 | } |
1106 | 1106 | |
1107 | - if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ]['fields'] ) ) { |
|
1108 | - $sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ]['fields'] ); |
|
1107 | + if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ][ 'fields' ] ) ) { |
|
1108 | + $sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ][ 'fields' ] ); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | return false === $sub_field_id ? false : array( $field_id, $sub_field_id ); |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | /** |
621 | 621 | * Save a repeatable group |
622 | 622 | * @since 1.x.x |
623 | - * @param array $field_group CMB2_Field group field object |
|
623 | + * @param CMB2_Field $field_group CMB2_Field group field object |
|
624 | 624 | * @return mixed Return of CMB2_Field::update_data() |
625 | 625 | */ |
626 | 626 | public function save_group_field( $field_group ) { |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | * @param mixed $field_id Field (or group field) ID |
911 | 911 | * @param mixed $field_args Array of field arguments |
912 | 912 | * @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 |
|
913 | + * @param CMB2_Field|null $field_group If a sub-field, will be the parent group CMB2_Field object |
|
914 | 914 | * @return array Array of CMB2_Field arguments |
915 | 915 | */ |
916 | 916 | public function get_field_args( $field_id, $field_args, $sub_field_id, $field_group ) { |
@@ -969,7 +969,7 @@ discard block |
||
969 | 969 | * @since 2.0.0 |
970 | 970 | * @param array $field Metabox field config array |
971 | 971 | * @param int $position (optional) Position of metabox. 1 for first, etc |
972 | - * @return mixed Field id or false |
|
972 | + * @return string Field id or false |
|
973 | 973 | */ |
974 | 974 | public function add_field( array $field, $position = 0 ) { |
975 | 975 | if ( ! is_array( $field ) || ! array_key_exists( 'id', $field ) ) { |
@@ -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 ); |
@@ -120,18 +120,18 @@ discard block |
||
120 | 120 | |
121 | 121 | protected function declare_read_write_fields() { |
122 | 122 | foreach ( $this->cmb->prop( 'fields' ) as $field ) { |
123 | - $show_in_rest = isset( $field['show_in_rest'] ) ? $field['show_in_rest'] : null; |
|
123 | + $show_in_rest = isset( $field[ 'show_in_rest' ] ) ? $field[ 'show_in_rest' ] : null; |
|
124 | 124 | |
125 | 125 | if ( false === $show_in_rest ) { |
126 | 126 | continue; |
127 | 127 | } |
128 | 128 | |
129 | 129 | if ( $this->can_read( $show_in_rest ) ) { |
130 | - $this->read_fields[] = $field['id']; |
|
130 | + $this->read_fields[ ] = $field[ 'id' ]; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | if ( $this->can_write( $show_in_rest ) ) { |
134 | - $this->write_fields[] = $field['id']; |
|
134 | + $this->write_fields[ ] = $field[ 'id' ]; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | } |
@@ -159,14 +159,14 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public static function get_restable_field_values( $object, $field_id, $request ) { |
161 | 161 | $values = array(); |
162 | - if ( ! isset( $object['id'] ) ) { |
|
162 | + if ( ! isset( $object[ 'id' ] ) ) { |
|
163 | 163 | return; |
164 | 164 | } |
165 | 165 | |
166 | 166 | foreach ( self::$boxes as $cmb_id => $rest_box ) { |
167 | 167 | foreach ( $rest_box->read_fields as $field_id ) { |
168 | 168 | $field = $rest_box->cmb->get_field( $field_id ); |
169 | - $field->object_id = $object['id']; |
|
169 | + $field->object_id = $object[ 'id' ]; |
|
170 | 170 | |
171 | 171 | // TODO: test other object types (users, comments, etc) |
172 | 172 | if ( isset( $object->type ) ) { |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | continue; |
206 | 206 | } |
207 | 207 | |
208 | - $rest_box->cmb->object_id( $data['object_id'] ); |
|
209 | - $rest_box->cmb->object_type( $data['object_type'] ); |
|
208 | + $rest_box->cmb->object_id( $data[ 'object_id' ] ); |
|
209 | + $rest_box->cmb->object_type( $data[ 'object_type' ] ); |
|
210 | 210 | |
211 | 211 | // TODO: Test since refactor. |
212 | 212 | $updated[ $cmb_id ] = $rest_box->sanitize_box_values( $values ); |
@@ -304,8 +304,8 @@ discard block |
||
304 | 304 | } elseif ( isset( $object->comment_ID ) ) { |
305 | 305 | $object_id = intval( $object->comment_ID ); |
306 | 306 | $object_type = 'comment'; |
307 | - } elseif ( is_array( $object ) && isset( $object['term_id'] ) ) { |
|
308 | - $object_id = intval( $object['term_id'] ); |
|
307 | + } elseif ( is_array( $object ) && isset( $object[ 'term_id' ] ) ) { |
|
308 | + $object_id = intval( $object[ 'term_id' ] ); |
|
309 | 309 | $object_type = 'term'; |
310 | 310 | } elseif ( isset( $object->term_id ) ) { |
311 | 311 | $object_id = intval( $object->term_id ); |
@@ -94,7 +94,6 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @since 2.2.0 |
96 | 96 | * |
97 | - * @param mixed $data |
|
98 | 97 | * @return array $data |
99 | 98 | */ |
100 | 99 | public function prepare_item( $post ) { |
@@ -107,7 +106,7 @@ discard block |
||
107 | 106 | * @since 2.2.0 |
108 | 107 | * |
109 | 108 | * @param mixed $cb Callable function/method. |
110 | - * @return mixed Results of output buffer after calling function/method. |
|
109 | + * @return string Results of output buffer after calling function/method. |
|
111 | 110 | */ |
112 | 111 | public function get_cb_results( $cb ) { |
113 | 112 | $args = func_get_args(); |
@@ -142,6 +141,9 @@ discard block |
||
142 | 141 | return apply_filters( 'cmb2_rest_prepare', rest_ensure_response( $data ), $this->request, $this ); |
143 | 142 | } |
144 | 143 | |
144 | + /** |
|
145 | + * @param string $request_type |
|
146 | + */ |
|
145 | 147 | protected function initiate_rest_read_box( $request, $request_type ) { |
146 | 148 | $this->initiate_rest_box( $request, $request_type ); |
147 | 149 |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return array $data |
129 | 129 | */ |
130 | 130 | public function prepare_item_for_response( $data, $request = null ) { |
131 | - $data = $this->filter_response_by_context( $data, $this->request['context'] ); |
|
131 | + $data = $this->filter_response_by_context( $data, $this->request[ 'context' ] ); |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * Filter the prepared CMB2 item response. |
@@ -170,16 +170,16 @@ discard block |
||
170 | 170 | |
171 | 171 | public function initiate_request( $request, $request_type ) { |
172 | 172 | $this->request = $request; |
173 | - $this->request['context'] = isset( $this->request['context'] ) && ! empty( $this->request['context'] ) |
|
174 | - ? $this->request['context'] |
|
173 | + $this->request[ 'context' ] = isset( $this->request[ 'context' ] ) && ! empty( $this->request[ 'context' ] ) |
|
174 | + ? $this->request[ 'context' ] |
|
175 | 175 | : 'view'; |
176 | 176 | |
177 | - if ( isset( $_REQUEST['object_id'] ) ) { |
|
178 | - $this->object_id = absint( $_REQUEST['object_id'] ); |
|
177 | + if ( isset( $_REQUEST[ 'object_id' ] ) ) { |
|
178 | + $this->object_id = absint( $_REQUEST[ 'object_id' ] ); |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( isset( $_REQUEST['object_type'] ) ) { |
|
182 | - $this->object_type = absint( $_REQUEST['object_type'] ); |
|
181 | + if ( isset( $_REQUEST[ 'object_type' ] ) ) { |
|
182 | + $this->object_type = absint( $_REQUEST[ 'object_type' ] ); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | self::$request_type = self::$request_type ? self::$request_type : $request_type; |
@@ -100,7 +100,6 @@ |
||
100 | 100 | * |
101 | 101 | * @since 2.2.0 |
102 | 102 | * |
103 | - * @param CMB2 $cmb |
|
104 | 103 | * @return array |
105 | 104 | */ |
106 | 105 | public function get_rest_box() { |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | foreach ( CMB2_REST::$boxes as $this->rest_box ) { |
71 | 71 | if ( $this->rest_box->rest_read ) { |
72 | 72 | $rest_box = $this->get_rest_box(); |
73 | - $boxes_data[ $this->rest_box->cmb->cmb_id ] = $this->server->response_to_data( $rest_box, isset( $_GET['_embed'] ) ); |
|
73 | + $boxes_data[ $this->rest_box->cmb->cmb_id ] = $this->server->response_to_data( $rest_box, isset( $_GET[ '_embed' ] ) ); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -110,9 +110,9 @@ discard block |
||
110 | 110 | |
111 | 111 | $boxes_data = $cmb->meta_box; |
112 | 112 | |
113 | - if ( isset( $_REQUEST['_rendered'] ) && '/cmb2/v1/boxes' !== CMB2_REST_Controller::get_intial_route() ) { |
|
114 | - $boxes_data['form_open'] = $this->get_cb_results( array( $cmb, 'render_form_open' ) ); |
|
115 | - $boxes_data['form_close'] = $this->get_cb_results( array( $cmb, 'render_form_close' ) ); |
|
113 | + if ( isset( $_REQUEST[ '_rendered' ] ) && '/cmb2/v1/boxes' !== CMB2_REST_Controller::get_intial_route() ) { |
|
114 | + $boxes_data[ 'form_open' ] = $this->get_cb_results( array( $cmb, 'render_form_open' ) ); |
|
115 | + $boxes_data[ 'form_close' ] = $this->get_cb_results( array( $cmb, 'render_form_close' ) ); |
|
116 | 116 | |
117 | 117 | global $wp_scripts, $wp_styles; |
118 | 118 | $before_css = $wp_styles->queue; |
@@ -120,15 +120,15 @@ discard block |
||
120 | 120 | |
121 | 121 | CMB2_JS::enqueue(); |
122 | 122 | |
123 | - $boxes_data['js_dependencies'] = array_values( array_diff( $wp_scripts->queue, $before_js ) ); |
|
124 | - $boxes_data['css_dependencies'] = array_values( array_diff( $wp_styles->queue, $before_css ) ); |
|
123 | + $boxes_data[ 'js_dependencies' ] = array_values( array_diff( $wp_scripts->queue, $before_js ) ); |
|
124 | + $boxes_data[ 'css_dependencies' ] = array_values( array_diff( $wp_styles->queue, $before_css ) ); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | // TODO: look into 'embed' parameter. |
128 | 128 | // http://demo.wp-api.org/wp-json/wp/v2/posts?_embed |
129 | - unset( $boxes_data['fields'] ); |
|
129 | + unset( $boxes_data[ 'fields' ] ); |
|
130 | 130 | // Handle callable properties. |
131 | - unset( $boxes_data['show_on_cb'] ); |
|
131 | + unset( $boxes_data[ 'show_on_cb' ] ); |
|
132 | 132 | |
133 | 133 | $response = rest_ensure_response( $boxes_data ); |
134 | 134 |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | |
68 | 68 | $fields = array(); |
69 | 69 | foreach ( $this->rest_box->cmb->prop( 'fields', array() ) as $field ) { |
70 | - $field_id = $field['id']; |
|
70 | + $field_id = $field[ 'id' ]; |
|
71 | 71 | $rest_field = $this->get_rest_field( $field_id ); |
72 | 72 | |
73 | 73 | if ( ! is_wp_error( $rest_field ) ) { |
74 | - $fields[ $field_id ] = $this->server->response_to_data( $rest_field, isset( $_GET['_embed'] ) ); |
|
74 | + $fields[ $field_id ] = $this->server->response_to_data( $rest_field, isset( $_GET[ '_embed' ] ) ); |
|
75 | 75 | } else { |
76 | 76 | $fields[ $field_id ] = array( 'error' => $rest_field->get_error_message() ); |
77 | 77 | } |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - if ( isset( $_REQUEST['_rendered'] ) ) { |
|
169 | - $field_data['rendered'] = $rendered; |
|
168 | + if ( isset( $_REQUEST[ '_rendered' ] ) ) { |
|
169 | + $field_data[ 'rendered' ] = $rendered; |
|
170 | 170 | } |
171 | 171 | |
172 | - $field_data['value'] = $field->get_data(); |
|
172 | + $field_data[ 'value' ] = $field->get_data(); |
|
173 | 173 | |
174 | 174 | return $field_data; |
175 | 175 | } |
@@ -190,14 +190,14 @@ discard block |
||
190 | 190 | ); |
191 | 191 | |
192 | 192 | // TODO ? |
193 | - error_log( '$this->request[context]: '. print_r( $this->request['context'], true ) ); |
|
194 | - error_log( 'CMB2_REST_Controller::get_intial_route(): '. print_r( CMB2_REST_Controller::get_intial_route(), true ) ); |
|
195 | - error_log( '$match: '. print_r( 'box_read' === CMB2_REST_Controller::get_intial_request_type(), true ) ); |
|
193 | + error_log( '$this->request[context]: ' . print_r( $this->request[ 'context' ], true ) ); |
|
194 | + error_log( 'CMB2_REST_Controller::get_intial_route(): ' . print_r( CMB2_REST_Controller::get_intial_route(), true ) ); |
|
195 | + error_log( '$match: ' . print_r( 'box_read' === CMB2_REST_Controller::get_intial_request_type(), true ) ); |
|
196 | 196 | |
197 | 197 | |
198 | 198 | // Don't embed boxes when looking at boxes route. |
199 | 199 | if ( '/cmb2/v1/boxes' !== CMB2_REST_Controller::get_intial_route() ) { |
200 | - $links['up']['embeddable'] = true; |
|
200 | + $links[ 'up' ][ 'embeddable' ] = true; |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return $links; |