Completed
Pull Request — trunk (#755)
by Rami
05:45
created
includes/CMB2.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -113,19 +113,19 @@  discard block
 block discarded – undo
113 113
 	 */
114 114
 	public function __construct( $config, $object_id = 0 ) {
115 115
 
116
-		if ( empty( $config['id'] ) ) {
116
+		if ( empty( $config[ 'id' ] ) ) {
117 117
 			wp_die( esc_html__( 'Metabox configuration is required to have an ID parameter.', 'cmb2' ) );
118 118
 		}
119 119
 
120 120
 		$this->meta_box = wp_parse_args( $config, $this->mb_defaults );
121
-		$this->meta_box['fields'] = array();
121
+		$this->meta_box[ 'fields' ] = array();
122 122
 
123 123
 		$this->object_id( $object_id );
124 124
 		$this->mb_object_type();
125
-		$this->cmb_id = $config['id'];
125
+		$this->cmb_id = $config[ 'id' ];
126 126
 
127
-		if ( ! empty( $config['fields'] ) && is_array( $config['fields'] ) ) {
128
-			$this->add_fields( $config['fields'] );
127
+		if ( ! empty( $config[ 'fields' ] ) && is_array( $config[ 'fields' ] ) ) {
128
+			$this->add_fields( $config[ 'fields' ] );
129 129
 		}
130 130
 
131 131
 		CMB2_Boxes::add( $this );
@@ -294,22 +294,22 @@  discard block
 block discarded – undo
294 294
 	 * @return mixed CMB2_Field object if successful.
295 295
 	 */
296 296
 	public function render_field( $field_args ) {
297
-		$field_args['context'] = $this->prop( 'context' );
297
+		$field_args[ 'context' ] = $this->prop( 'context' );
298 298
 
299
-		if ( 'group' == $field_args['type'] ) {
299
+		if ( 'group' == $field_args[ 'type' ] ) {
300 300
 
301
-			if ( ! isset( $field_args['show_names'] ) ) {
302
-				$field_args['show_names'] = $this->prop( 'show_names' );
301
+			if ( ! isset( $field_args[ 'show_names' ] ) ) {
302
+				$field_args[ 'show_names' ] = $this->prop( 'show_names' );
303 303
 			}
304 304
 			$field = $this->render_group( $field_args );
305 305
 
306
-		} elseif ( 'hidden' == $field_args['type'] && $this->get_field( $field_args )->should_show() ) {
306
+		} elseif ( 'hidden' == $field_args[ 'type' ] && $this->get_field( $field_args )->should_show() ) {
307 307
 			// Save rendering for after the metabox
308 308
 			$field = $this->add_hidden_field( $field_args );
309 309
 
310 310
 		} else {
311 311
 
312
-			$field_args['show_names'] = $this->prop( 'show_names' );
312
+			$field_args[ 'show_names' ] = $this->prop( 'show_names' );
313 313
 
314 314
 			// Render default fields
315 315
 			$field = $this->get_field( $field_args )->render_field();
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 	 */
326 326
 	public function render_group( $args ) {
327 327
 
328
-		if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) {
328
+		if ( ! isset( $args[ 'id' ], $args[ 'fields' ] ) || ! is_array( $args[ 'fields' ] ) ) {
329 329
 			return;
330 330
 		}
331 331
 
@@ -435,15 +435,15 @@  discard block
 block discarded – undo
435 435
 			<div class="inside cmb-td cmb-nested cmb-field-list">';
436 436
 				// Loop and render repeatable group fields
437 437
 				foreach ( array_values( $field_group->args( 'fields' ) ) as $field_args ) {
438
-					if ( 'hidden' == $field_args['type'] ) {
438
+					if ( 'hidden' == $field_args[ 'type' ] ) {
439 439
 
440 440
 						// Save rendering for after the metabox
441 441
 						$this->add_hidden_field( $field_args, $field_group );
442 442
 
443 443
 					} else {
444 444
 
445
-						$field_args['show_names'] = $field_group->args( 'show_names' );
446
-						$field_args['context']    = $field_group->args( 'context' );
445
+						$field_args[ 'show_names' ] = $field_group->args( 'show_names' );
446
+						$field_args[ 'context' ]    = $field_group->args( 'context' );
447 447
 
448 448
 						$field = $this->get_field( $field_args, $field_group )->render_field();
449 449
 					}
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 	 * @param array  $field_args Array of field arguments to be passed to CMB2_Field
472 472
 	 */
473 473
 	public function add_hidden_field( $field_args, $field_group = null ) {
474
-		if ( isset( $field_args['field_args'] ) ) {
474
+		if ( isset( $field_args[ 'field_args' ] ) ) {
475 475
 			// For back-compatibility.
476 476
 			$field = new CMB2_Field( $field_args );
477 477
 		} else {
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 			$type->iterator = $field_group->index;
485 485
 		}
486 486
 
487
-		$this->hidden_fields[] = $type;
487
+		$this->hidden_fields[ ] = $type;
488 488
 
489 489
 		return $field;
490 490
 	}
@@ -581,11 +581,11 @@  discard block
 block discarded – undo
581 581
 	 */
582 582
 	public function process_field( $field_args ) {
583 583
 
584
-		switch ( $field_args['type'] ) {
584
+		switch ( $field_args[ 'type' ] ) {
585 585
 
586 586
 			case 'group':
587 587
 				if ( $this->save_group( $field_args ) ) {
588
-					$this->updated[] = $field_args['id'];
588
+					$this->updated[ ] = $field_args[ 'id' ];
589 589
 				}
590 590
 
591 591
 				break;
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 				$field = $this->get_new_field( $field_args );
600 600
 
601 601
 				if ( $field->save_field_from_data( $this->data_to_save ) ) {
602
-					$this->updated[] = $field->id();
602
+					$this->updated[ ] = $field->id();
603 603
 				}
604 604
 
605 605
 				break;
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
 	 * @return mixed        Return of CMB2_Field::update_data()
667 667
 	 */
668 668
 	public function save_group( $args ) {
669
-		if ( ! isset( $args['id'], $args['fields'] ) || ! is_array( $args['fields'] ) ) {
669
+		if ( ! isset( $args[ 'id' ], $args[ 'fields' ] ) || ! is_array( $args[ 'fields' ] ) ) {
670 670
 			return;
671 671
 		}
672 672
 
@@ -714,16 +714,16 @@  discard block
 block discarded – undo
714 714
 						$_new_val = array();
715 715
 						foreach ( $new_val as $group_index => $grouped_data ) {
716 716
 							// Add the supporting data to the $saved array stack
717
-							$saved[ $field_group->index ][ $grouped_data['supporting_field_id'] ][] = $grouped_data['supporting_field_value'];
717
+							$saved[ $field_group->index ][ $grouped_data[ 'supporting_field_id' ] ][ ] = $grouped_data[ 'supporting_field_value' ];
718 718
 							// Reset var to the actual value
719
-							$_new_val[ $group_index ] = $grouped_data['value'];
719
+							$_new_val[ $group_index ] = $grouped_data[ 'value' ];
720 720
 						}
721 721
 						$new_val = $_new_val;
722 722
 					} else {
723 723
 						// Add the supporting data to the $saved array stack
724
-						$saved[ $field_group->index ][ $new_val['supporting_field_id'] ] = $new_val['supporting_field_value'];
724
+						$saved[ $field_group->index ][ $new_val[ 'supporting_field_id' ] ] = $new_val[ 'supporting_field_value' ];
725 725
 						// Reset var to the actual value
726
-						$new_val = $new_val['value'];
726
+						$new_val = $new_val[ 'value' ];
727 727
 					}
728 728
 				}
729 729
 
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
 
738 738
 				// Compare values and add to `$updated` array
739 739
 				if ( $is_updated || $is_removed ) {
740
-					$this->updated[] = $base_id . '::' . $field_group->index . '::' . $sub_id;
740
+					$this->updated[ ] = $base_id . '::' . $field_group->index . '::' . $sub_id;
741 741
 				}
742 742
 
743 743
 				// Add to `$saved` array
@@ -774,22 +774,22 @@  discard block
 block discarded – undo
774 774
 		// Try to get our object ID from the global space
775 775
 		switch ( $this->object_type() ) {
776 776
 			case 'user':
777
-				$object_id = isset( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : $object_id;
778
-				$object_id = ! $object_id && 'user-new.php' != $screen->parent_file && isset( $GLOBALS['user_ID'] ) ? $GLOBALS['user_ID'] : $object_id;
777
+				$object_id = isset( $_REQUEST[ 'user_id' ] ) ? $_REQUEST[ 'user_id' ] : $object_id;
778
+				$object_id = ! $object_id && 'user-new.php' != $screen->parent_file && isset( $GLOBALS[ 'user_ID' ] ) ? $GLOBALS[ 'user_ID' ] : $object_id;
779 779
 				break;
780 780
 
781 781
 			case 'comment':
782
-				$object_id = isset( $_REQUEST['c'] ) ? $_REQUEST['c'] : $object_id;
783
-				$object_id = ! $object_id && isset( $GLOBALS['comments']->comment_ID ) ? $GLOBALS['comments']->comment_ID : $object_id;
782
+				$object_id = isset( $_REQUEST[ 'c' ] ) ? $_REQUEST[ 'c' ] : $object_id;
783
+				$object_id = ! $object_id && isset( $GLOBALS[ 'comments' ]->comment_ID ) ? $GLOBALS[ 'comments' ]->comment_ID : $object_id;
784 784
 				break;
785 785
 
786 786
 			case 'term':
787
-				$object_id = isset( $_REQUEST['tag_ID'] ) ? $_REQUEST['tag_ID'] : $object_id;
787
+				$object_id = isset( $_REQUEST[ 'tag_ID' ] ) ? $_REQUEST[ 'tag_ID' ] : $object_id;
788 788
 				break;
789 789
 
790 790
 			default:
791
-				$object_id = isset( $GLOBALS['post']->ID ) ? $GLOBALS['post']->ID : $object_id;
792
-				$object_id = isset( $_REQUEST['post'] ) ? $_REQUEST['post'] : $object_id;
791
+				$object_id = isset( $GLOBALS[ 'post' ]->ID ) ? $GLOBALS[ 'post' ]->ID : $object_id;
792
+				$object_id = isset( $_REQUEST[ 'post' ] ) ? $_REQUEST[ 'post' ] : $object_id;
793 793
 				break;
794 794
 		}
795 795
 
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
 	 * @return boolean True/False
866 866
 	 */
867 867
 	public function is_options_page_mb() {
868
-		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'] ) );
868
+		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' ] ) );
869 869
 	}
870 870
 
871 871
 	/**
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
 			return $field;
953 953
 		}
954 954
 
955
-		$field_id = is_string( $field ) ? $field : $field['id'];
955
+		$field_id = is_string( $field ) ? $field : $field[ 'id' ];
956 956
 
957 957
 		$parent_field_id = ! empty( $field_group ) ? $field_group->id() : '';
958 958
 		$ids = $this->get_field_ids( $field_id, $parent_field_id, true );
@@ -988,16 +988,16 @@  discard block
 block discarded – undo
988 988
 		if ( $field_group && ( $sub_field_id || 0 === $sub_field_id ) ) {
989 989
 
990 990
 			// Update the fields array w/ any modified properties inherited from the group field
991
-			$this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] = $field_args;
991
+			$this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] = $field_args;
992 992
 
993 993
 			return $this->get_default_args( $field_args, $field_group );
994 994
 		}
995 995
 
996 996
 		if ( is_array( $field_args ) ) {
997
-			$this->meta_box['fields'][ $field_id ] = array_merge( $field_args, $this->meta_box['fields'][ $field_id ] );
997
+			$this->meta_box[ 'fields' ][ $field_id ] = array_merge( $field_args, $this->meta_box[ 'fields' ][ $field_id ] );
998 998
 		}
999 999
 
1000
-		return $this->get_default_args( $this->meta_box['fields'][ $field_id ] );
1000
+		return $this->get_default_args( $this->meta_box[ 'fields' ][ $field_id ] );
1001 1001
 	}
1002 1002
 
1003 1003
 	/**
@@ -1047,8 +1047,8 @@  discard block
 block discarded – undo
1047 1047
 
1048 1048
 			$sub_fields = false;
1049 1049
 			if ( array_key_exists( 'fields', $field ) ) {
1050
-				$sub_fields = $field['fields'];
1051
-				unset( $field['fields'] );
1050
+				$sub_fields = $field[ 'fields' ];
1051
+				unset( $field[ 'fields' ] );
1052 1052
 			}
1053 1053
 
1054 1054
 			$field_id = $parent_field_id
@@ -1073,26 +1073,26 @@  discard block
 block discarded – undo
1073 1073
 			return false;
1074 1074
 		}
1075 1075
 
1076
-		if ( 'oembed' === $field['type'] ) {
1076
+		if ( 'oembed' === $field[ 'type' ] ) {
1077 1077
 			// Initiate oembed Ajax hooks
1078 1078
 			cmb2_ajax();
1079 1079
 		}
1080 1080
 
1081
-		if ( isset( $field['column'] ) && false !== $field['column'] ) {
1081
+		if ( isset( $field[ 'column' ] ) && false !== $field[ 'column' ] ) {
1082 1082
 			$field = $this->define_field_column( $field );
1083 1083
 		}
1084 1084
 
1085
-		if ( isset( $field['taxonomy'] ) && ! empty( $field['remove_default'] ) ) {
1086
-			$this->tax_metaboxes_to_remove[ $field['taxonomy'] ] = $field['taxonomy'];
1085
+		if ( isset( $field[ 'taxonomy' ] ) && ! empty( $field[ 'remove_default' ] ) ) {
1086
+			$this->tax_metaboxes_to_remove[ $field[ 'taxonomy' ] ] = $field[ 'taxonomy' ];
1087 1087
 		}
1088 1088
 
1089 1089
 		$this->_add_field_to_array(
1090 1090
 			$field,
1091
-			$this->meta_box['fields'],
1091
+			$this->meta_box[ 'fields' ],
1092 1092
 			$position
1093 1093
 		);
1094 1094
 
1095
-		return $field['id'];
1095
+		return $field[ 'id' ];
1096 1096
 	}
1097 1097
 
1098 1098
 	/**
@@ -1104,10 +1104,10 @@  discard block
 block discarded – undo
1104 1104
 	protected function define_field_column( array $field ) {
1105 1105
 		$this->has_columns = true;
1106 1106
 
1107
-		$column = is_array( $field['column'] ) ? $field['column'] : array();
1107
+		$column = is_array( $field[ 'column' ] ) ? $field[ 'column' ] : array();
1108 1108
 
1109
-		$field['column'] = wp_parse_args( $column, array(
1110
-			'name'     => isset( $field['name'] ) ? $field['name'] : '',
1109
+		$field[ 'column' ] = wp_parse_args( $column, array(
1110
+			'name'     => isset( $field[ 'name' ] ) ? $field[ 'name' ] : '',
1111 1111
 			'position' => false,
1112 1112
 		) );
1113 1113
 
@@ -1123,27 +1123,27 @@  discard block
 block discarded – undo
1123 1123
 	 * @return mixed                   Array of parent/field ids or false
1124 1124
 	 */
1125 1125
 	public function add_group_field( $parent_field_id, array $field, $position = 0 ) {
1126
-		if ( ! array_key_exists( $parent_field_id, $this->meta_box['fields'] ) ) {
1126
+		if ( ! array_key_exists( $parent_field_id, $this->meta_box[ 'fields' ] ) ) {
1127 1127
 			return false;
1128 1128
 		}
1129 1129
 
1130
-		$parent_field = $this->meta_box['fields'][ $parent_field_id ];
1130
+		$parent_field = $this->meta_box[ 'fields' ][ $parent_field_id ];
1131 1131
 
1132
-		if ( 'group' !== $parent_field['type'] ) {
1132
+		if ( 'group' !== $parent_field[ 'type' ] ) {
1133 1133
 			return false;
1134 1134
 		}
1135 1135
 
1136
-		if ( ! isset( $parent_field['fields'] ) ) {
1137
-			$this->meta_box['fields'][ $parent_field_id ]['fields'] = array();
1136
+		if ( ! isset( $parent_field[ 'fields' ] ) ) {
1137
+			$this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ] = array();
1138 1138
 		}
1139 1139
 
1140 1140
 		$this->_add_field_to_array(
1141 1141
 			$field,
1142
-			$this->meta_box['fields'][ $parent_field_id ]['fields'],
1142
+			$this->meta_box[ 'fields' ][ $parent_field_id ][ 'fields' ],
1143 1143
 			$position
1144 1144
 		);
1145 1145
 
1146
-		return array( $parent_field_id, $field['id'] );
1146
+		return array( $parent_field_id, $field[ 'id' ] );
1147 1147
 	}
1148 1148
 
1149 1149
 	/**
@@ -1155,9 +1155,9 @@  discard block
 block discarded – undo
1155 1155
 	 */
1156 1156
 	protected function _add_field_to_array( $field, &$fields, $position = 0 ) {
1157 1157
 		if ( $position ) {
1158
-			CMB2_Utils::array_insert( $fields, array( $field['id'] => $field ), $position );
1158
+			CMB2_Utils::array_insert( $fields, array( $field[ 'id' ] => $field ), $position );
1159 1159
 		} else {
1160
-			$fields[ $field['id'] ] = $field;
1160
+			$fields[ $field[ 'id' ] ] = $field;
1161 1161
 		}
1162 1162
 	}
1163 1163
 
@@ -1180,15 +1180,15 @@  discard block
 block discarded – undo
1180 1180
 		unset( $this->fields[ implode( '', $ids ) ] );
1181 1181
 
1182 1182
 		if ( ! $sub_field_id ) {
1183
-			unset( $this->meta_box['fields'][ $field_id ] );
1183
+			unset( $this->meta_box[ 'fields' ][ $field_id ] );
1184 1184
 			return true;
1185 1185
 		}
1186 1186
 
1187
-		if ( isset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] ) ) {
1188
-			unset( $this->fields[ $field_id ]->args['fields'][ $sub_field_id ] );
1187
+		if ( isset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] ) ) {
1188
+			unset( $this->fields[ $field_id ]->args[ 'fields' ][ $sub_field_id ] );
1189 1189
 		}
1190
-		if ( isset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] ) ) {
1191
-			unset( $this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ] );
1190
+		if ( isset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] ) ) {
1191
+			unset( $this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ] );
1192 1192
 		}
1193 1193
 		return true;
1194 1194
 	}
@@ -1212,11 +1212,11 @@  discard block
 block discarded – undo
1212 1212
 		list( $field_id, $sub_field_id ) = $ids;
1213 1213
 
1214 1214
 		if ( ! $sub_field_id ) {
1215
-			$this->meta_box['fields'][ $field_id ][ $property ] = $value;
1215
+			$this->meta_box[ 'fields' ][ $field_id ][ $property ] = $value;
1216 1216
 			return $field_id;
1217 1217
 		}
1218 1218
 
1219
-		$this->meta_box['fields'][ $field_id ]['fields'][ $sub_field_id ][ $property ] = $value;
1219
+		$this->meta_box[ 'fields' ][ $field_id ][ 'fields' ][ $sub_field_id ][ $property ] = $value;
1220 1220
 		return $field_id;
1221 1221
 	}
1222 1222
 
@@ -1230,7 +1230,7 @@  discard block
 block discarded – undo
1230 1230
 	public function get_field_ids( $field_id, $parent_field_id = '' ) {
1231 1231
 		$sub_field_id = $parent_field_id ? $field_id : '';
1232 1232
 		$field_id     = $parent_field_id ? $parent_field_id : $field_id;
1233
-		$fields       =& $this->meta_box['fields'];
1233
+		$fields       = & $this->meta_box[ 'fields' ];
1234 1234
 
1235 1235
 		if ( ! array_key_exists( $field_id, $fields ) ) {
1236 1236
 			$field_id = $this->search_old_school_array( $field_id, $fields );
@@ -1244,12 +1244,12 @@  discard block
 block discarded – undo
1244 1244
 			return array( $field_id, $sub_field_id );
1245 1245
 		}
1246 1246
 
1247
-		if ( 'group' !== $fields[ $field_id ]['type'] ) {
1247
+		if ( 'group' !== $fields[ $field_id ][ 'type' ] ) {
1248 1248
 			return false;
1249 1249
 		}
1250 1250
 
1251
-		if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ]['fields'] ) ) {
1252
-			$sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ]['fields'] );
1251
+		if ( ! array_key_exists( $sub_field_id, $fields[ $field_id ][ 'fields' ] ) ) {
1252
+			$sub_field_id = $this->search_old_school_array( $sub_field_id, $fields[ $field_id ][ 'fields' ] );
1253 1253
 		}
1254 1254
 
1255 1255
 		return false === $sub_field_id ? false : array( $field_id, $sub_field_id );
Please login to merge, or discard this patch.