Completed
Pull Request — trunk (#582)
by Juliette
05:24
created
includes/CMB2.php 1 patch
Spacing   +64 added lines, -64 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,22 +261,22 @@  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( $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
 block discarded – undo
292 292
 	 */
293 293
 	public function render_group( $args ) {
294 294
 
295
-		if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) {
295
+		if ( ! isset( $args[ 'id' ], $args[ 'fields' ] ) || ! is_array( $args[ 'fields' ] ) ) {
296 296
 			return;
297 297
 		}
298 298
 
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 		 *
326 326
 		 * @param string $id The group_id of the current group.
327 327
 		 */
328
-		$more_attributes = apply_filters( "cmb2_additional_group_attributes", '', $field_group->args, $args['id'] );
328
+		$more_attributes = apply_filters( "cmb2_additional_group_attributes", '', $field_group->args, $args[ 'id' ] );
329 329
 
330 330
 		$field_group->peform_param_callback( 'before_group' );
331 331
 
@@ -389,15 +389,15 @@  discard block
 block discarded – undo
389 389
 			<div class="inside cmb-td cmb-nested cmb-field-list">';
390 390
 				// Loop and render repeatable group fields
391 391
 				foreach ( array_values( $field_group->args( 'fields' ) ) as $field_args ) {
392
-					if ( 'hidden' == $field_args['type'] ) {
392
+					if ( 'hidden' == $field_args[ 'type' ] ) {
393 393
 
394 394
 						// Save rendering for after the metabox
395 395
 						$this->add_hidden_field( $field_args, $field_group );
396 396
 
397 397
 					} else {
398 398
 
399
-						$field_args['show_names'] = $field_group->args( 'show_names' );
400
-						$field_args['context']    = $field_group->args( 'context' );
399
+						$field_args[ 'show_names' ] = $field_group->args( 'show_names' );
400
+						$field_args[ 'context' ]    = $field_group->args( 'context' );
401 401
 
402 402
 						$field = $this->get_field( $field_args, $field_group )->render_field();
403 403
 					}
@@ -425,14 +425,14 @@  discard block
 block discarded – undo
425 425
 	 * @param array  $field_args Array of field arguments to be passed to CMB2_Field
426 426
 	 */
427 427
 	public function add_hidden_field( $field_args, $field_group = null ) {
428
-		if ( isset( $field_args['field_args'] ) ) {
428
+		if ( isset( $field_args[ 'field_args' ] ) ) {
429 429
 			// For back-compatibility.
430 430
 			$field = new CMB2_Field( $field_args );
431 431
 		} else {
432 432
 			$field = $this->get_new_field( $field_args, $field_group );
433 433
 		}
434 434
 
435
-		$this->hidden_fields[] = new CMB2_Types( $field );
435
+		$this->hidden_fields[ ] = new CMB2_Types( $field );
436 436
 
437 437
 		return $field;
438 438
 	}
@@ -529,11 +529,11 @@  discard block
 block discarded – undo
529 529
 	 */
530 530
 	public function process_field( $field_args ) {
531 531
 
532
-		switch ( $field_args['type'] ) {
532
+		switch ( $field_args[ 'type' ] ) {
533 533
 
534 534
 			case 'group':
535 535
 				if ( $this->save_group( $field_args ) ) {
536
-					$this->updated[] = $field_args['id'];
536
+					$this->updated[ ] = $field_args[ 'id' ];
537 537
 				}
538 538
 
539 539
 				break;
@@ -547,7 +547,7 @@  discard block
 block discarded – undo
547 547
 				$field = $this->get_new_field( $field_args );
548 548
 
549 549
 				if ( $field->save_field_from_data( $this->data_to_save ) ) {
550
-					$this->updated[] = $field->id();
550
+					$this->updated[ ] = $field->id();
551 551
 				}
552 552
 
553 553
 				break;
@@ -614,7 +614,7 @@  discard block
 block discarded – undo
614 614
 	 * @return mixed        Return of CMB2_Field::update_data()
615 615
 	 */
616 616
 	public function save_group( $args ) {
617
-		if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) {
617
+		if ( ! isset( $args[ 'id' ], $args[ 'fields' ] ) || ! is_array( $args[ 'fields' ] ) ) {
618 618
 			return;
619 619
 		}
620 620
 
@@ -662,16 +662,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
719 719
 		// Try to get our object ID from the global space
720 720
 		switch ( $this->object_type() ) {
721 721
 			case 'user':
722
-				$object_id = isset( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : $object_id;
723
-				$object_id = ! $object_id && 'user-new.php' != $pagenow && isset( $GLOBALS['user_ID'] ) ? $GLOBALS['user_ID'] : $object_id;
722
+				$object_id = isset( $_REQUEST[ 'user_id' ] ) ? $_REQUEST[ 'user_id' ] : $object_id;
723
+				$object_id = ! $object_id && 'user-new.php' != $pagenow && isset( $GLOBALS[ 'user_ID' ] ) ? $GLOBALS[ 'user_ID' ] : $object_id;
724 724
 				break;
725 725
 
726 726
 			case 'comment':
727
-				$object_id = isset( $_REQUEST['c'] ) ? $_REQUEST['c'] : $object_id;
728
-				$object_id = ! $object_id && isset( $GLOBALS['comments']->comment_ID ) ? $GLOBALS['comments']->comment_ID : $object_id;
727
+				$object_id = isset( $_REQUEST[ 'c' ] ) ? $_REQUEST[ 'c' ] : $object_id;
728
+				$object_id = ! $object_id && isset( $GLOBALS[ 'comments' ]->comment_ID ) ? $GLOBALS[ 'comments' ]->comment_ID : $object_id;
729 729
 				break;
730 730
 
731 731
 			case 'term':
732
-				$object_id = isset( $_REQUEST['tag_ID'] ) ? $_REQUEST['tag_ID'] : $object_id;
732
+				$object_id = isset( $_REQUEST[ 'tag_ID' ] ) ? $_REQUEST[ 'tag_ID' ] : $object_id;
733 733
 				break;
734 734
 
735 735
 			default:
736
-				$object_id = isset( $GLOBALS['post']->ID ) ? $GLOBALS['post']->ID : $object_id;
737
-				$object_id = isset( $_REQUEST['post'] ) ? $_REQUEST['post'] : $object_id;
736
+				$object_id = isset( $GLOBALS[ 'post' ]->ID ) ? $GLOBALS[ 'post' ]->ID : $object_id;
737
+				$object_id = isset( $_REQUEST[ 'post' ] ) ? $_REQUEST[ 'post' ] : $object_id;
738 738
 				break;
739 739
 		}
740 740
 
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 	 * @return boolean True/False
811 811
 	 */
812 812
 	public function is_options_page_mb() {
813
-		return ( isset( $this->meta_box['show_on']['key'] ) && 'options-page' === $this->meta_box['show_on']['key'] || array_key_exists( 'options-page', $this->meta_box['show_on'] ) );
813
+		return ( isset( $this->meta_box[ 'show_on' ][ 'key' ] ) && 'options-page' === $this->meta_box[ 'show_on' ][ 'key' ] || array_key_exists( 'options-page', $this->meta_box[ 'show_on' ] ) );
814 814
 	}
815 815
 
816 816
 	/**
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 			return $field;
898 898
 		}
899 899
 
900
-		$field_id = is_string( $field ) ? $field : $field['id'];
900
+		$field_id = is_string( $field ) ? $field : $field[ 'id' ];
901 901
 
902 902
 		$parent_field_id = ! empty( $field_group ) ? $field_group->id() : '';
903 903
 		$ids = $this->get_field_ids( $field_id, $parent_field_id, true );
@@ -933,16 +933,16 @@  discard block
 block discarded – undo
933 933
 		if ( $field_group && ( $sub_field_id || 0 === $sub_field_id ) ) {
934 934
 
935 935
 			// Update the fields array w/ any modified properties inherited from the group field
936
-			$this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] = $field_args;
936
+			$this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] = $field_args;
937 937
 
938 938
 			return $this->get_default_args( $field_args, $field_group );
939 939
 		}
940 940
 
941 941
 		if ( is_array( $field_args ) ) {
942
-			$this->meta_box['fields'][ $field_id ] = array_merge( $field_args, $this->meta_box['fields'][ $field_id ] );
942
+			$this->meta_box[ 'fields' ][ $field_id ] = array_merge( $field_args, $this->meta_box[ 'fields' ][ $field_id ] );
943 943
 		}
944 944
 
945
-		return $this->get_default_args( $this->meta_box['fields'][ $field_id ] );
945
+		return $this->get_default_args( $this->meta_box[ 'fields' ][ $field_id ] );
946 946
 	}
947 947
 
948 948
 	/**
@@ -992,8 +992,8 @@  discard block
 block discarded – undo
992 992
 
993 993
 			$sub_fields = false;
994 994
 			if ( array_key_exists( 'fields', $field ) ) {
995
-				$sub_fields = $field['fields'];
996
-				unset( $field['fields'] );
995
+				$sub_fields = $field[ 'fields' ];
996
+				unset( $field[ 'fields' ] );
997 997
 			}
998 998
 
999 999
 			$field_id = $parent_field_id
@@ -1018,18 +1018,18 @@  discard block
 block discarded – undo
1018 1018
 			return false;
1019 1019
 		}
1020 1020
 
1021
-		if ( 'oembed' === $field['type'] ) {
1021
+		if ( 'oembed' === $field[ 'type' ] ) {
1022 1022
 			// Initiate oembed Ajax hooks
1023 1023
 			cmb2_ajax();
1024 1024
 		}
1025 1025
 
1026 1026
 		$this->_add_field_to_array(
1027 1027
 			$field,
1028
-			$this->meta_box['fields'],
1028
+			$this->meta_box[ 'fields' ],
1029 1029
 			$position
1030 1030
 		);
1031 1031
 
1032
-		return $field['id'];
1032
+		return $field[ 'id' ];
1033 1033
 	}
1034 1034
 
1035 1035
 	/**
@@ -1041,27 +1041,27 @@  discard block
 block discarded – undo
1041 1041
 	 * @return mixed                   Array of parent/field ids or false
1042 1042
 	 */
1043 1043
 	public function add_group_field( $parent_field_id, array $field, $position = 0 ) {
1044
-		if ( ! array_key_exists( $parent_field_id, $this->meta_box['fields'] ) ) {
1044
+		if ( ! array_key_exists( $parent_field_id, $this->meta_box[ 'fields' ] ) ) {
1045 1045
 			return false;
1046 1046
 		}
1047 1047
 
1048
-		$parent_field = $this->meta_box['fields'][ $parent_field_id ];
1048
+		$parent_field = $this->meta_box[ 'fields' ][ $parent_field_id ];
1049 1049
 
1050
-		if ( 'group' !== $parent_field['type'] ) {
1050
+		if ( 'group' !== $parent_field[ 'type' ] ) {
1051 1051
 			return false;
1052 1052
 		}
1053 1053
 
1054
-		if ( ! isset( $parent_field['fields'] ) ) {
1055
-			$this->meta_box['fields'][ $parent_field_id ]['fields'] = array();
1054
+		if ( ! isset( $parent_field[ 'fields' ] ) ) {
1055
+			$this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ] = array();
1056 1056
 		}
1057 1057
 
1058 1058
 		$this->_add_field_to_array(
1059 1059
 			$field,
1060
-			$this->meta_box['fields'][ $parent_field_id ]['fields'],
1060
+			$this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ],
1061 1061
 			$position
1062 1062
 		);
1063 1063
 
1064
-		return array( $parent_field_id, $field['id'] );
1064
+		return array( $parent_field_id, $field[ 'id' ] );
1065 1065
 	}
1066 1066
 
1067 1067
 	/**
@@ -1073,9 +1073,9 @@  discard block
 block discarded – undo
1073 1073
 	 */
1074 1074
 	protected function _add_field_to_array( $field, &$fields, $position = 0 ) {
1075 1075
 		if ( $position ) {
1076
-			cmb2_utils()->array_insert( $fields, array( $field['id'] => $field ), $position );
1076
+			cmb2_utils()->array_insert( $fields, array( $field[ 'id' ] => $field ), $position );
1077 1077
 		} else {
1078
-			$fields[ $field['id'] ] = $field;
1078
+			$fields[ $field[ 'id' ] ] = $field;
1079 1079
 		}
1080 1080
 	}
1081 1081
 
@@ -1098,15 +1098,15 @@  discard block
 block discarded – undo
1098 1098
 		unset( $this->fields[ implode( '', $ids ) ] );
1099 1099
 
1100 1100
 		if ( ! $sub_field_id ) {
1101
-			unset( $this->meta_box['fields'][ $field_id ] );
1101
+			unset( $this->meta_box[ 'fields' ][ $field_id ] );
1102 1102
 			return true;
1103 1103
 		}
1104 1104
 
1105
-		if ( isset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ) ) {
1106
-			unset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] );
1105
+		if ( isset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] ) ) {
1106
+			unset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] );
1107 1107
 		}
1108
-		if ( isset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ) ) {
1109
-			unset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] );
1108
+		if ( isset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] ) ) {
1109
+			unset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] );
1110 1110
 		}
1111 1111
 		return true;
1112 1112
 	}
@@ -1130,11 +1130,11 @@  discard block
 block discarded – undo
1130 1130
 		list( $field_id, $sub_field_id ) = $ids;
1131 1131
 
1132 1132
 		if ( ! $sub_field_id ) {
1133
-			$this->meta_box['fields'][ $field_id ][ $property ] = $value;
1133
+			$this->meta_box[ 'fields' ][ $field_id ][ $property ] = $value;
1134 1134
 			return $field_id;
1135 1135
 		}
1136 1136
 
1137
-		$this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ][ $property ] = $value;
1137
+		$this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ][ $property ] = $value;
1138 1138
 		return $field_id;
1139 1139
 	}
1140 1140
 
@@ -1148,7 +1148,7 @@  discard block
 block discarded – undo
1148 1148
 	public function get_field_ids( $field_id, $parent_field_id = '' ) {
1149 1149
 		$sub_field_id = $parent_field_id ? $field_id : '';
1150 1150
 		$field_id     = $parent_field_id ? $parent_field_id : $field_id;
1151
-		$fields       =& $this->meta_box['fields'];
1151
+		$fields       = & $this->meta_box[ 'fields' ];
1152 1152
 
1153 1153
 		if ( ! array_key_exists( $field_id, $fields ) ) {
1154 1154
 			$field_id = $this->search_old_school_array( $field_id, $fields );
@@ -1162,12 +1162,12 @@  discard block
 block discarded – undo
1162 1162
 			return array( $field_id, $sub_field_id );
1163 1163
 		}
1164 1164
 
1165
-		if ( 'group' !== $fields[ $field_id ]['type'] ) {
1165
+		if ( 'group' !== $fields[ $field_id ][ 'type' ] ) {
1166 1166
 			return false;
1167 1167
 		}
1168 1168
 
1169
-		if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ]['fields'] ) ) {
1170
-			$sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ]['fields'] );
1169
+		if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ][ 'fields' ] ) ) {
1170
+			$sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ][ 'fields' ] );
1171 1171
 		}
1172 1172
 
1173 1173
 		return false === $sub_field_id ? false : array( $field_id, $sub_field_id );
Please login to merge, or discard this patch.