Completed
Pull Request — trunk (#582)
by Juliette
71:21 queued 56:23
created
includes/CMB2.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -118,19 +118,19 @@  discard block
 block discarded – undo
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,16 +261,16 @@  discard block
 block discarded – undo
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( array(
276 276
 				'field_args'  => $field_args,
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 
281 281
 		} else {
282 282
 
283
-			$field_args['show_names'] = $this->prop( 'show_names' );
283
+			$field_args[ 'show_names' ] = $this->prop( 'show_names' );
284 284
 
285 285
 			// Render default fields
286 286
 			$field = $this->get_field( $field_args )->render_field();
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	 */
297 297
 	public function render_group( $args ) {
298 298
 
299
-		if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) {
299
+		if ( ! isset( $args[ 'id' ], $args[ 'fields' ] ) || ! is_array( $args[ 'fields' ] ) ) {
300 300
 			return;
301 301
 		}
302 302
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 		 *
330 330
 		 * @param string $id The group_id of the current group.
331 331
 		 */
332
-		$more_attributes = apply_filters( "cmb2_additional_group_attributes", '', $field_group->args, $args['id'] );
332
+		$more_attributes = apply_filters( "cmb2_additional_group_attributes", '', $field_group->args, $args[ 'id' ] );
333 333
 
334 334
 		$field_group->peform_param_callback( 'before_group' );
335 335
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 			<div class="inside cmb-td cmb-nested cmb-field-list">';
394 394
 				// Loop and render repeatable group fields
395 395
 				foreach ( array_values( $field_group->args( 'fields' ) ) as $field_args ) {
396
-					if ( 'hidden' == $field_args['type'] ) {
396
+					if ( 'hidden' == $field_args[ 'type' ] ) {
397 397
 
398 398
 						// Save rendering for after the metabox
399 399
 						$this->add_hidden_field( array(
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
 
404 404
 					} else {
405 405
 
406
-						$field_args['show_names'] = $field_group->args( 'show_names' );
407
-						$field_args['context']    = $field_group->args( 'context' );
406
+						$field_args[ 'show_names' ] = $field_group->args( 'show_names' );
407
+						$field_args[ 'context' ]    = $field_group->args( 'context' );
408 408
 
409 409
 						$field = $this->get_field( $field_args, $field_group )->render_field();
410 410
 					}
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 	 */
434 434
 	public function add_hidden_field( $args ) {
435 435
 		$field = new CMB2_Field( $args );
436
-		$this->hidden_fields[] = new CMB2_Types( $field );
436
+		$this->hidden_fields[ ] = new CMB2_Types( $field );
437 437
 
438 438
 		return $field;
439 439
 	}
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 	 */
573 573
 	public function process_field( $field_args ) {
574 574
 
575
-		switch ( $field_args['type'] ) {
575
+		switch ( $field_args[ 'type' ] ) {
576 576
 
577 577
 			case 'group':
578 578
 				$this->save_group( $field_args );
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 				) );
593 593
 
594 594
 				if ( $field->save_field_from_data( $this->data_to_save ) ) {
595
-					$this->updated[] = $field->id();
595
+					$this->updated[ ] = $field->id();
596 596
 				}
597 597
 
598 598
 				break;
@@ -605,11 +605,11 @@  discard block
 block discarded – undo
605 605
 	 */
606 606
 	public function save_group( $args ) {
607 607
 
608
-		if ( ! isset( $args['id'], $args['fields'], $this->data_to_save[ $args['id'] ] ) || ! is_array( $args['fields'] ) ) {
608
+		if ( ! isset( $args[ 'id' ], $args[ 'fields' ], $this->data_to_save[ $args[ 'id' ] ] ) || ! is_array( $args[ 'fields' ] ) ) {
609 609
 			return;
610 610
 		}
611 611
 
612
-		$field_group        = new CMB2_Field( array(
612
+		$field_group = new CMB2_Field( array(
613 613
 			'field_args'  => $args,
614 614
 			'object_type' => $this->object_type(),
615 615
 			'object_id'   => $this->object_id(),
@@ -644,16 +644,16 @@  discard block
 block discarded – undo
644 644
 						$_new_val = array();
645 645
 						foreach ( $new_val as $group_index => $grouped_data ) {
646 646
 							// Add the supporting data to the $saved array stack
647
-							$saved[ $field_group->index ][ $grouped_data['supporting_field_id'] ][] = $grouped_data['supporting_field_value'];
647
+							$saved[ $field_group->index ][ $grouped_data[ 'supporting_field_id' ] ][ ] = $grouped_data[ 'supporting_field_value' ];
648 648
 							// Reset var to the actual value
649
-							$_new_val[ $group_index ] = $grouped_data['value'];
649
+							$_new_val[ $group_index ] = $grouped_data[ 'value' ];
650 650
 						}
651 651
 						$new_val = $_new_val;
652 652
 					} else {
653 653
 						// Add the supporting data to the $saved array stack
654
-						$saved[ $field_group->index ][ $new_val['supporting_field_id'] ] = $new_val['supporting_field_value'];
654
+						$saved[ $field_group->index ][ $new_val[ 'supporting_field_id' ] ] = $new_val[ 'supporting_field_value' ];
655 655
 						// Reset var to the actual value
656
-						$new_val = $new_val['value'];
656
+						$new_val = $new_val[ 'value' ];
657 657
 					}
658 658
 				}
659 659
 
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 				$is_removed = ( empty( $new_val ) && ! empty( $old_val ) );
667 667
 				// Compare values and add to `$updated` array
668 668
 				if ( $is_updated || $is_removed ) {
669
-					$this->updated[] = $base_id . '::' . $field_group->index . '::' . $sub_id;
669
+					$this->updated[ ] = $base_id . '::' . $field_group->index . '::' . $sub_id;
670 670
 				}
671 671
 
672 672
 				// Add to `$saved` array
@@ -701,22 +701,22 @@  discard block
 block discarded – undo
701 701
 		// Try to get our object ID from the global space
702 702
 		switch ( $this->object_type() ) {
703 703
 			case 'user':
704
-				$object_id = isset( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : $object_id;
705
-				$object_id = ! $object_id && 'user-new.php' != $pagenow && isset( $GLOBALS['user_ID'] ) ? $GLOBALS['user_ID'] : $object_id;
704
+				$object_id = isset( $_REQUEST[ 'user_id' ] ) ? $_REQUEST[ 'user_id' ] : $object_id;
705
+				$object_id = ! $object_id && 'user-new.php' != $pagenow && isset( $GLOBALS[ 'user_ID' ] ) ? $GLOBALS[ 'user_ID' ] : $object_id;
706 706
 				break;
707 707
 
708 708
 			case 'comment':
709
-				$object_id = isset( $_REQUEST['c'] ) ? $_REQUEST['c'] : $object_id;
710
-				$object_id = ! $object_id && isset( $GLOBALS['comments']->comment_ID ) ? $GLOBALS['comments']->comment_ID : $object_id;
709
+				$object_id = isset( $_REQUEST[ 'c' ] ) ? $_REQUEST[ 'c' ] : $object_id;
710
+				$object_id = ! $object_id && isset( $GLOBALS[ 'comments' ]->comment_ID ) ? $GLOBALS[ 'comments' ]->comment_ID : $object_id;
711 711
 				break;
712 712
 
713 713
 			case 'term':
714
-				$object_id = isset( $_REQUEST['tag_ID'] ) ? $_REQUEST['tag_ID'] : $object_id;
714
+				$object_id = isset( $_REQUEST[ 'tag_ID' ] ) ? $_REQUEST[ 'tag_ID' ] : $object_id;
715 715
 				break;
716 716
 
717 717
 			default:
718
-				$object_id = isset( $GLOBALS['post']->ID ) ? $GLOBALS['post']->ID : $object_id;
719
-				$object_id = isset( $_REQUEST['post'] ) ? $_REQUEST['post'] : $object_id;
718
+				$object_id = isset( $GLOBALS[ 'post' ]->ID ) ? $GLOBALS[ 'post' ]->ID : $object_id;
719
+				$object_id = isset( $_REQUEST[ 'post' ] ) ? $_REQUEST[ 'post' ] : $object_id;
720 720
 				break;
721 721
 		}
722 722
 
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 	 * @return boolean True/False
789 789
 	 */
790 790
 	public function is_options_page_mb() {
791
-		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'] ) );
791
+		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' ] ) );
792 792
 	}
793 793
 
794 794
 	/**
@@ -854,7 +854,7 @@  discard block
 block discarded – undo
854 854
 			return $field;
855 855
 		}
856 856
 
857
-		$field_id = is_string( $field ) ? $field : $field['id'];
857
+		$field_id = is_string( $field ) ? $field : $field[ 'id' ];
858 858
 
859 859
 		$parent_field_id = ! empty( $field_group ) ? $field_group->id() : '';
860 860
 		$ids = $this->get_field_ids( $field_id, $parent_field_id, true );
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
 		if ( $field_group && ( $sub_field_id || 0 === $sub_field_id ) ) {
891 891
 
892 892
 			// Update the fields array w/ any modified properties inherited from the group field
893
-			$this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] = $field_args;
893
+			$this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] = $field_args;
894 894
 
895 895
 			return array(
896 896
 				'field_args'  => $field_args,
@@ -900,11 +900,11 @@  discard block
 block discarded – undo
900 900
 		}
901 901
 
902 902
 		if ( is_array( $field_args ) ) {
903
-			$this->meta_box['fields'][ $field_id ] = array_merge( $field_args, $this->meta_box['fields'][ $field_id ] );
903
+			$this->meta_box[ 'fields' ][ $field_id ] = array_merge( $field_args, $this->meta_box[ 'fields' ][ $field_id ] );
904 904
 		}
905 905
 
906 906
 		return array(
907
-			'field_args'  => $this->meta_box['fields'][ $field_id ],
907
+			'field_args'  => $this->meta_box[ 'fields' ][ $field_id ],
908 908
 			'object_type' => $this->object_type(),
909 909
 			'object_id'   => $this->object_id(),
910 910
 		);
@@ -921,8 +921,8 @@  discard block
 block discarded – undo
921 921
 
922 922
 			$sub_fields = false;
923 923
 			if ( array_key_exists( 'fields', $field ) ) {
924
-				$sub_fields = $field['fields'];
925
-				unset( $field['fields'] );
924
+				$sub_fields = $field[ 'fields' ];
925
+				unset( $field[ 'fields' ] );
926 926
 			}
927 927
 
928 928
 			$field_id = $parent_field_id
@@ -947,18 +947,18 @@  discard block
 block discarded – undo
947 947
 			return false;
948 948
 		}
949 949
 
950
-		if ( 'oembed' === $field['type'] ) {
950
+		if ( 'oembed' === $field[ 'type' ] ) {
951 951
 			// Initiate oembed Ajax hooks
952 952
 			cmb2_ajax();
953 953
 		}
954 954
 
955 955
 		$this->_add_field_to_array(
956 956
 			$field,
957
-			$this->meta_box['fields'],
957
+			$this->meta_box[ 'fields' ],
958 958
 			$position
959 959
 		);
960 960
 
961
-		return $field['id'];
961
+		return $field[ 'id' ];
962 962
 	}
963 963
 
964 964
 	/**
@@ -970,27 +970,27 @@  discard block
 block discarded – undo
970 970
 	 * @return mixed                   Array of parent/field ids or false
971 971
 	 */
972 972
 	public function add_group_field( $parent_field_id, array $field, $position = 0 ) {
973
-		if ( ! array_key_exists( $parent_field_id, $this->meta_box['fields'] ) ) {
973
+		if ( ! array_key_exists( $parent_field_id, $this->meta_box[ 'fields' ] ) ) {
974 974
 			return false;
975 975
 		}
976 976
 
977
-		$parent_field = $this->meta_box['fields'][ $parent_field_id ];
977
+		$parent_field = $this->meta_box[ 'fields' ][ $parent_field_id ];
978 978
 
979
-		if ( 'group' !== $parent_field['type'] ) {
979
+		if ( 'group' !== $parent_field[ 'type' ] ) {
980 980
 			return false;
981 981
 		}
982 982
 
983
-		if ( ! isset( $parent_field['fields'] ) ) {
984
-			$this->meta_box['fields'][ $parent_field_id ]['fields'] = array();
983
+		if ( ! isset( $parent_field[ 'fields' ] ) ) {
984
+			$this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ] = array();
985 985
 		}
986 986
 
987 987
 		$this->_add_field_to_array(
988 988
 			$field,
989
-			$this->meta_box['fields'][ $parent_field_id ]['fields'],
989
+			$this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ],
990 990
 			$position
991 991
 		);
992 992
 
993
-		return array( $parent_field_id, $field['id'] );
993
+		return array( $parent_field_id, $field[ 'id' ] );
994 994
 	}
995 995
 
996 996
 	/**
@@ -1002,9 +1002,9 @@  discard block
 block discarded – undo
1002 1002
 	 */
1003 1003
 	protected function _add_field_to_array( $field, &$fields, $position = 0 ) {
1004 1004
 		if ( $position ) {
1005
-			cmb2_utils()->array_insert( $fields, array( $field['id'] => $field ), $position );
1005
+			cmb2_utils()->array_insert( $fields, array( $field[ 'id' ] => $field ), $position );
1006 1006
 		} else {
1007
-			$fields[ $field['id'] ] = $field;
1007
+			$fields[ $field[ 'id' ] ] = $field;
1008 1008
 		}
1009 1009
 	}
1010 1010
 
@@ -1027,15 +1027,15 @@  discard block
 block discarded – undo
1027 1027
 		unset( $this->fields[ implode( '', $ids ) ] );
1028 1028
 
1029 1029
 		if ( ! $sub_field_id ) {
1030
-			unset( $this->meta_box['fields'][ $field_id ] );
1030
+			unset( $this->meta_box[ 'fields' ][ $field_id ] );
1031 1031
 			return true;
1032 1032
 		}
1033 1033
 
1034
-		if ( isset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ) ) {
1035
-			unset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] );
1034
+		if ( isset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] ) ) {
1035
+			unset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] );
1036 1036
 		}
1037
-		if ( isset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ) ) {
1038
-			unset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] );
1037
+		if ( isset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] ) ) {
1038
+			unset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] );
1039 1039
 		}
1040 1040
 		return true;
1041 1041
 	}
@@ -1059,11 +1059,11 @@  discard block
 block discarded – undo
1059 1059
 		list( $field_id, $sub_field_id ) = $ids;
1060 1060
 
1061 1061
 		if ( ! $sub_field_id ) {
1062
-			$this->meta_box['fields'][ $field_id ][ $property ] = $value;
1062
+			$this->meta_box[ 'fields' ][ $field_id ][ $property ] = $value;
1063 1063
 			return $field_id;
1064 1064
 		}
1065 1065
 
1066
-		$this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ][ $property ] = $value;
1066
+		$this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ][ $property ] = $value;
1067 1067
 		return $field_id;
1068 1068
 	}
1069 1069
 
@@ -1077,7 +1077,7 @@  discard block
 block discarded – undo
1077 1077
 	public function get_field_ids( $field_id, $parent_field_id = '' ) {
1078 1078
 		$sub_field_id = $parent_field_id ? $field_id : '';
1079 1079
 		$field_id     = $parent_field_id ? $parent_field_id : $field_id;
1080
-		$fields       =& $this->meta_box['fields'];
1080
+		$fields       = & $this->meta_box[ 'fields' ];
1081 1081
 
1082 1082
 		if ( ! array_key_exists( $field_id, $fields ) ) {
1083 1083
 			$field_id = $this->search_old_school_array( $field_id, $fields );
@@ -1091,12 +1091,12 @@  discard block
 block discarded – undo
1091 1091
 			return array( $field_id, $sub_field_id );
1092 1092
 		}
1093 1093
 
1094
-		if ( 'group' !== $fields[ $field_id ]['type'] ) {
1094
+		if ( 'group' !== $fields[ $field_id ][ 'type' ] ) {
1095 1095
 			return false;
1096 1096
 		}
1097 1097
 
1098
-		if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ]['fields'] ) ) {
1099
-			$sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ]['fields'] );
1098
+		if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ][ 'fields' ] ) ) {
1099
+			$sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ][ 'fields' ] );
1100 1100
 		}
1101 1101
 
1102 1102
 		return false === $sub_field_id ? false : array( $field_id, $sub_field_id );
Please login to merge, or discard this patch.