Passed
Push — trunk ( 35f7f8...44999f )
by Justin
01:59
created
includes/CMB2_Field.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -122,21 +122,21 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function __construct( $args ) {
124 124
 
125
-		if ( ! empty( $args['group_field'] ) ) {
126
-			$this->group       = $args['group_field'];
125
+		if ( ! empty( $args[ 'group_field' ] ) ) {
126
+			$this->group       = $args[ 'group_field' ];
127 127
 			$this->object_id   = $this->group->object_id;
128 128
 			$this->object_type = $this->group->object_type;
129 129
 			$this->cmb_id      = $this->group->cmb_id;
130 130
 		} else {
131
-			$this->object_id   = isset( $args['object_id'] ) && '_' !== $args['object_id'] ? $args['object_id'] : 0;
132
-			$this->object_type = isset( $args['object_type'] ) ? $args['object_type'] : 'post';
131
+			$this->object_id   = isset( $args[ 'object_id' ] ) && '_' !== $args[ 'object_id' ] ? $args[ 'object_id' ] : 0;
132
+			$this->object_type = isset( $args[ 'object_type' ] ) ? $args[ 'object_type' ] : 'post';
133 133
 
134
-			if ( isset( $args['cmb_id'] ) ) {
135
-				$this->cmb_id = $args['cmb_id'];
134
+			if ( isset( $args[ 'cmb_id' ] ) ) {
135
+				$this->cmb_id = $args[ 'cmb_id' ];
136 136
 			}
137 137
 		}
138 138
 
139
-		$this->args = $this->_set_field_defaults( $args['field_args'] );
139
+		$this->args = $this->_set_field_defaults( $args[ 'field_args' ] );
140 140
 
141 141
 		if ( $this->object_id ) {
142 142
 			$this->value = $this->get_data();
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 			return call_user_func_array( array( $this, 'get_string' ), $arguments );
157 157
 		}
158 158
 
159
-		$key = isset( $arguments[0] ) ? $arguments[0] : '';
159
+		$key = isset( $arguments[ 0 ] ) ? $arguments[ 0 ] : '';
160 160
 		return $this->args( $name, $key );
161 161
 	}
162 162
 
@@ -232,9 +232,9 @@  discard block
 block discarded – undo
232 232
 	 */
233 233
 	public function get_data( $field_id = '', $args = array() ) {
234 234
 		if ( $field_id ) {
235
-			$args['field_id'] = $field_id;
235
+			$args[ 'field_id' ] = $field_id;
236 236
 		} elseif ( $this->group ) {
237
-			$args['field_id'] = $this->group->id();
237
+			$args[ 'field_id' ] = $this->group->id();
238 238
 		}
239 239
 
240 240
 		$a = $this->data_args( $args );
@@ -275,13 +275,13 @@  discard block
 block discarded – undo
275 275
 		 *
276 276
 		 * @since 2.0.0
277 277
 		 */
278
-		$data = apply_filters( "cmb2_override_{$a['field_id']}_meta_value", $data, $this->object_id, $a, $this );
278
+		$data = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_value", $data, $this->object_id, $a, $this );
279 279
 
280 280
 		// If no override, get value normally
281 281
 		if ( 'cmb2_field_no_override_val' === $data ) {
282
-			$data = 'options-page' === $a['type']
283
-				? cmb2_options( $a['id'] )->get( $a['field_id'] )
284
-				: get_metadata( $a['type'], $a['id'], $a['field_id'], ( $a['single'] || $a['repeat'] ) );
282
+			$data = 'options-page' === $a[ 'type' ]
283
+				? cmb2_options( $a[ 'id' ] )->get( $a[ 'field_id' ] )
284
+				: get_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], ( $a[ 'single' ] || $a[ 'repeat' ] ) );
285 285
 		}
286 286
 
287 287
 		if ( $this->group ) {
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 			'single' => $single,
307 307
 		) );
308 308
 
309
-		$a['value'] = $a['repeat'] ? array_values( $new_value ) : $new_value;
309
+		$a[ 'value' ] = $a[ 'repeat' ] ? array_values( $new_value ) : $new_value;
310 310
 
311 311
 		/**
312 312
 		 * Filter whether to override saving of meta value.
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
 		 *
343 343
 		 * @since 2.0.0
344 344
 		 */
345
-		$override = apply_filters( "cmb2_override_{$a['field_id']}_meta_save", $override, $a, $this->args(), $this );
345
+		$override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_save", $override, $a, $this->args(), $this );
346 346
 
347 347
 		// If override, return that
348 348
 		if ( null !== $override ) {
@@ -350,22 +350,22 @@  discard block
 block discarded – undo
350 350
 		}
351 351
 
352 352
 		// Options page handling (or temp data store)
353
-		if ( 'options-page' === $a['type'] || empty( $a['id'] ) ) {
354
-			return cmb2_options( $a['id'] )->update( $a['field_id'], $a['value'], false, $a['single'] );
353
+		if ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) {
354
+			return cmb2_options( $a[ 'id' ] )->update( $a[ 'field_id' ], $a[ 'value' ], false, $a[ 'single' ] );
355 355
 		}
356 356
 
357 357
 		// Add metadata if not single
358
-		if ( ! $a['single'] ) {
359
-			return add_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'], false );
358
+		if ( ! $a[ 'single' ] ) {
359
+			return add_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ], false );
360 360
 		}
361 361
 
362 362
 		// Delete meta if we have an empty array
363
-		if ( is_array( $a['value'] ) && empty( $a['value'] ) ) {
364
-			return delete_metadata( $a['type'], $a['id'], $a['field_id'], $this->value );
363
+		if ( is_array( $a[ 'value' ] ) && empty( $a[ 'value' ] ) ) {
364
+			return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $this->value );
365 365
 		}
366 366
 
367 367
 		// Update metadata
368
-		return update_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'] );
368
+		return update_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ] );
369 369
 	}
370 370
 
371 371
 	/**
@@ -418,19 +418,19 @@  discard block
 block discarded – undo
418 418
 		 * @param array $field_args All field arguments
419 419
 		 * @param CMB2_Field object $field This field object
420 420
 		 */
421
-		$override = apply_filters( "cmb2_override_{$a['field_id']}_meta_remove", $override, $a, $this->args(), $this );
421
+		$override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_remove", $override, $a, $this->args(), $this );
422 422
 
423 423
 		// If no override, remove as usual
424 424
 		if ( null !== $override ) {
425 425
 			return $override;
426 426
 		} // End if().
427 427
 		// Option page handling.
428
-		elseif ( 'options-page' === $a['type'] || empty( $a['id'] ) ) {
429
-			return cmb2_options( $a['id'] )->remove( $a['field_id'] );
428
+		elseif ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) {
429
+			return cmb2_options( $a[ 'id' ] )->remove( $a[ 'field_id' ] );
430 430
 		}
431 431
 
432 432
 		// Remove metadata
433
-		return delete_metadata( $a['type'], $a['id'], $a['field_id'], $old );
433
+		return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $old );
434 434
 	}
435 435
 
436 436
 	/**
@@ -954,7 +954,7 @@  discard block
 block discarded – undo
954 954
 
955 955
 		foreach ( $conditional_classes as $class => $condition ) {
956 956
 			if ( $condition ) {
957
-				$classes[] = $class;
957
+				$classes[ ] = $class;
958 958
 			}
959 959
 		}
960 960
 
@@ -965,7 +965,7 @@  discard block
 block discarded – undo
965 965
 		}
966 966
 
967 967
 		if ( $added_classes ) {
968
-			$classes[] = esc_attr( $added_classes );
968
+			$classes[ ] = esc_attr( $added_classes );
969 969
 		}
970 970
 
971 971
 		/**
@@ -1069,10 +1069,10 @@  discard block
 block discarded – undo
1069 1069
 	public function get_string( $text_key, $fallback ) {
1070 1070
 		// If null, populate with our field strings values.
1071 1071
 		if ( null === $this->strings ) {
1072
-			$this->strings = (array) $this->args['text'];
1072
+			$this->strings = (array) $this->args[ 'text' ];
1073 1073
 
1074
-			if ( is_callable( $this->args['text_cb'] ) ) {
1075
-				$strings = call_user_func( $this->args['text_cb'], $this );
1074
+			if ( is_callable( $this->args[ 'text_cb' ] ) ) {
1075
+				$strings = call_user_func( $this->args[ 'text_cb' ], $this );
1076 1076
 
1077 1077
 				if ( $strings && is_array( $strings ) ) {
1078 1078
 					$this->strings += $strings;
@@ -1118,10 +1118,10 @@  discard block
 block discarded – undo
1118 1118
 	 * @return array Array of options
1119 1119
 	 */
1120 1120
 	public function set_options() {
1121
-		$this->field_options = (array) $this->args['options'];
1121
+		$this->field_options = (array) $this->args[ 'options' ];
1122 1122
 
1123
-		if ( is_callable( $this->args['options_cb'] ) ) {
1124
-			$options = call_user_func( $this->args['options_cb'], $this );
1123
+		if ( is_callable( $this->args[ 'options_cb' ] ) ) {
1124
+			$options = call_user_func( $this->args[ 'options_cb' ], $this );
1125 1125
 
1126 1126
 			if ( $options && is_array( $options ) ) {
1127 1127
 				$this->field_options = $options + $this->field_options;
@@ -1139,7 +1139,7 @@  discard block
 block discarded – undo
1139 1139
 	 */
1140 1140
 	public function add_js_dependencies( $dependencies = array() ) {
1141 1141
 		foreach ( (array) $dependencies as $dependency ) {
1142
-			$this->args['js_dependencies'][ $dependency ] = $dependency;
1142
+			$this->args[ 'js_dependencies' ][ $dependency ] = $dependency;
1143 1143
 		}
1144 1144
 
1145 1145
 		CMB2_JS::add_dependencies( $dependencies );
@@ -1153,17 +1153,17 @@  discard block
 block discarded – undo
1153 1153
 	 * @return mixed  Default field value
1154 1154
 	 */
1155 1155
 	public function get_default() {
1156
-		$default = $this->args['default'];
1156
+		$default = $this->args[ 'default' ];
1157 1157
 
1158 1158
 		if ( null !== $default ) {
1159 1159
 			return apply_filters( 'cmb2_default_filter', $default, $this );
1160 1160
 		}
1161 1161
 
1162
-		$param = is_callable( $this->args['default_cb'] ) ? 'default_cb' : 'default';
1163
-		$default = $this->args['default'] = $this->get_param_callback_result( $param );
1162
+		$param = is_callable( $this->args[ 'default_cb' ] ) ? 'default_cb' : 'default';
1163
+		$default = $this->args[ 'default' ] = $this->get_param_callback_result( $param );
1164 1164
 
1165 1165
 		// Allow a filter override of the default value.
1166
-		return apply_filters( 'cmb2_default_filter', $this->args['default'], $this );
1166
+		return apply_filters( 'cmb2_default_filter', $this->args[ 'default' ], $this );
1167 1167
 	}
1168 1168
 
1169 1169
 	/**
@@ -1188,12 +1188,12 @@  discard block
 block discarded – undo
1188 1188
 		 */
1189 1189
 		$args = $this->convert_deprecated_params( $args );
1190 1190
 
1191
-		$args['repeatable'] = $args['repeatable'] && ! $this->repeatable_exception( $args['type'] );
1192
-		$args['inline']     = $args['inline'] || false !== stripos( $args['type'], '_inline' );
1193
-		$args['_id']        = $args['id'];
1194
-		$args['_name']      = $args['id'];
1191
+		$args[ 'repeatable' ] = $args[ 'repeatable' ] && ! $this->repeatable_exception( $args[ 'type' ] );
1192
+		$args[ 'inline' ]     = $args[ 'inline' ] || false !== stripos( $args[ 'type' ], '_inline' );
1193
+		$args[ '_id' ]        = $args[ 'id' ];
1194
+		$args[ '_name' ]      = $args[ 'id' ];
1195 1195
 
1196
-		if ( $method = $this->has_args_method( $args['type'] ) ) {
1196
+		if ( $method = $this->has_args_method( $args[ 'type' ] ) ) {
1197 1197
 			$args = $this->{$method}( $args );
1198 1198
 		}
1199 1199
 
@@ -1201,8 +1201,8 @@  discard block
 block discarded – undo
1201 1201
 			$args = $this->set_group_sub_field_defaults( $args );
1202 1202
 		}
1203 1203
 
1204
-		$args['has_supporting_data'] = in_array(
1205
-			$args['type'],
1204
+		$args[ 'has_supporting_data' ] = in_array(
1205
+			$args[ 'type' ],
1206 1206
 			array(
1207 1207
 				// CMB2_Sanitize::_save_file_id_value()/CMB2_Sanitize::_get_group_file_value_array()
1208 1208
 				'file',
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
 	 * @return array        Modified field config array.
1225 1225
 	 */
1226 1226
 	protected function set_field_defaults_group( $args ) {
1227
-		$args['options'] = wp_parse_args( $args['options'], array(
1227
+		$args[ 'options' ] = wp_parse_args( $args[ 'options' ], array(
1228 1228
 			'add_button'    => esc_html__( 'Add Group', 'cmb2' ),
1229 1229
 			'remove_button' => esc_html__( 'Remove Group', 'cmb2' ),
1230 1230
 		) );
@@ -1241,8 +1241,8 @@  discard block
 block discarded – undo
1241 1241
 	 * @return array        Modified field config array.
1242 1242
 	 */
1243 1243
 	protected function set_field_defaults_wysiwyg( $args ) {
1244
-		$args['id'] = strtolower( str_ireplace( '-', '_', $args['id'] ) );
1245
-		$args['options']['textarea_name'] = $args['_name'];
1244
+		$args[ 'id' ] = strtolower( str_ireplace( '-', '_', $args[ 'id' ] ) );
1245
+		$args[ 'options' ][ 'textarea_name' ] = $args[ '_name' ];
1246 1246
 
1247 1247
 		return $args;
1248 1248
 	}
@@ -1256,12 +1256,12 @@  discard block
 block discarded – undo
1256 1256
 	 * @return array        Modified field config array.
1257 1257
 	 */
1258 1258
 	protected function set_field_defaults_all_or_nothing_types( $args ) {
1259
-		$args['show_option_none'] = isset( $args['show_option_none'] ) ? $args['show_option_none'] : null;
1260
-		$args['show_option_none'] = true === $args['show_option_none'] ? esc_html__( 'None', 'cmb2' ) : $args['show_option_none'];
1259
+		$args[ 'show_option_none' ] = isset( $args[ 'show_option_none' ] ) ? $args[ 'show_option_none' ] : null;
1260
+		$args[ 'show_option_none' ] = true === $args[ 'show_option_none' ] ? esc_html__( 'None', 'cmb2' ) : $args[ 'show_option_none' ];
1261 1261
 
1262
-		if ( null === $args['show_option_none'] ) {
1263
-			$off_by_default = in_array( $args['type'], array( 'select', 'radio', 'radio_inline' ), true );
1264
-			$args['show_option_none'] = $off_by_default ? false : esc_html__( 'None', 'cmb2' );
1262
+		if ( null === $args[ 'show_option_none' ] ) {
1263
+			$off_by_default = in_array( $args[ 'type' ], array( 'select', 'radio', 'radio_inline' ), true );
1264
+			$args[ 'show_option_none' ] = $off_by_default ? false : esc_html__( 'None', 'cmb2' );
1265 1265
 		}
1266 1266
 
1267 1267
 		return $args;
@@ -1276,8 +1276,8 @@  discard block
 block discarded – undo
1276 1276
 	 * @return array        Modified field config array.
1277 1277
 	 */
1278 1278
 	protected function set_group_sub_field_defaults( $args ) {
1279
-		$args['id']    = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args['id'];
1280
-		$args['_name'] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args['_name'] . ']';
1279
+		$args[ 'id' ]    = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args[ 'id' ];
1280
+		$args[ '_name' ] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args[ '_name' ] . ']';
1281 1281
 
1282 1282
 		return $args;
1283 1283
 	}
@@ -1291,7 +1291,7 @@  discard block
 block discarded – undo
1291 1291
 	 * @return array        Field defaults.
1292 1292
 	 */
1293 1293
 	protected function get_default_field_args( $args ) {
1294
-		$type = isset( $args['type'] ) ? $args['type'] : '';
1294
+		$type = isset( $args[ 'type' ] ) ? $args[ 'type' ] : '';
1295 1295
 
1296 1296
 		return array(
1297 1297
 			'type'              => $type,
@@ -1318,7 +1318,7 @@  discard block
 block discarded – undo
1318 1318
 			'save_field'        => true, // Will not save if false
1319 1319
 			'date_format'       => 'm\/d\/Y',
1320 1320
 			'time_format'       => 'h:i A',
1321
-			'description'       => isset( $args['desc'] ) ? $args['desc'] : '',
1321
+			'description'       => isset( $args[ 'desc' ] ) ? $args[ 'desc' ] : '',
1322 1322
 			'preview_size'      => 'file' === $type ? array( 350, 350 ) : array( 50, 50 ),
1323 1323
 			'render_row_cb'     => array( $this, 'render_field_callback' ),
1324 1324
 			'display_cb'        => array( $this, 'display_value_callback' ),
@@ -1340,10 +1340,10 @@  discard block
 block discarded – undo
1340 1340
 	protected function get_default_args( $field_args, $field_group = null ) {
1341 1341
 		$args = parent::get_default_args( array(), $this->group );
1342 1342
 
1343
-		if ( isset( $field_args['field_args'] ) ) {
1343
+		if ( isset( $field_args[ 'field_args' ] ) ) {
1344 1344
 			$args = wp_parse_args( $field_args, $args );
1345 1345
 		} else {
1346
-			$args['field_args'] = wp_parse_args( $field_args, $this->args );
1346
+			$args[ 'field_args' ] = wp_parse_args( $field_args, $this->args );
1347 1347
 		}
1348 1348
 
1349 1349
 		return $args;
@@ -1387,41 +1387,41 @@  discard block
 block discarded – undo
1387 1387
 	 */
1388 1388
 	protected function convert_deprecated_params( $args ) {
1389 1389
 
1390
-		if ( isset( $args['row_classes'] ) ) {
1390
+		if ( isset( $args[ 'row_classes' ] ) ) {
1391 1391
 
1392 1392
 			// We'll let this one be.
1393 1393
 			// $this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_PARAM, 'row_classes', 'classes' );
1394 1394
 			// row_classes param could be a callback. This is definitely deprecated.
1395
-			if ( is_callable( $args['row_classes'] ) ) {
1395
+			if ( is_callable( $args[ 'row_classes' ] ) ) {
1396 1396
 
1397 1397
 				$this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'row_classes', 'classes_cb' );
1398 1398
 
1399
-				$args['classes_cb'] = $args['row_classes'];
1400
-				$args['classes'] = null;
1399
+				$args[ 'classes_cb' ] = $args[ 'row_classes' ];
1400
+				$args[ 'classes' ] = null;
1401 1401
 			} else {
1402 1402
 
1403
-				$args['classes'] = $args['row_classes'];
1403
+				$args[ 'classes' ] = $args[ 'row_classes' ];
1404 1404
 			}
1405 1405
 
1406
-			unset( $args['row_classes'] );
1406
+			unset( $args[ 'row_classes' ] );
1407 1407
 		}
1408 1408
 
1409 1409
 		// default param can be passed a callback as well
1410
-		if ( is_callable( $args['default'] ) ) {
1410
+		if ( is_callable( $args[ 'default' ] ) ) {
1411 1411
 
1412 1412
 			$this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'default', 'default_cb' );
1413 1413
 
1414
-			$args['default_cb'] = $args['default'];
1415
-			$args['default'] = null;
1414
+			$args[ 'default_cb' ] = $args[ 'default' ];
1415
+			$args[ 'default' ] = null;
1416 1416
 		}
1417 1417
 
1418 1418
 		// options param can be passed a callback as well
1419
-		if ( is_callable( $args['options'] ) ) {
1419
+		if ( is_callable( $args[ 'options' ] ) ) {
1420 1420
 
1421 1421
 			$this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'options', 'options_cb' );
1422 1422
 
1423
-			$args['options_cb'] = $args['options'];
1424
-			$args['options'] = array();
1423
+			$args[ 'options_cb' ] = $args[ 'options' ];
1424
+			$args[ 'options' ] = array();
1425 1425
 		}
1426 1426
 
1427 1427
 		return $args;
Please login to merge, or discard this patch.