@@ -122,21 +122,21 @@ discard block |
||
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'], $args ); |
|
139 | + $this->args = $this->_set_field_defaults( $args[ 'field_args' ], $args ); |
|
140 | 140 | |
141 | 141 | if ( $this->object_id ) { |
142 | 142 | $this->value = $this->get_data(); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | return call_user_func_array( array( $this, 'get_string' ), $arguments ); |
157 | 157 | } |
158 | 158 | |
159 | - $key = isset( $arguments[0] ) ? $arguments[0] : false; |
|
159 | + $key = isset( $arguments[ 0 ] ) ? $arguments[ 0 ] : false; |
|
160 | 160 | return $this->args( $name, $key ); |
161 | 161 | } |
162 | 162 | |
@@ -232,9 +232,9 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | /** |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | |
898 | 898 | foreach ( $conditional_classes as $class => $condition ) { |
899 | 899 | if ( $condition ) { |
900 | - $classes[] = $class; |
|
900 | + $classes[ ] = $class; |
|
901 | 901 | } |
902 | 902 | } |
903 | 903 | |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | } |
909 | 909 | |
910 | 910 | if ( $added_classes ) { |
911 | - $classes[] = esc_attr( $added_classes ); |
|
911 | + $classes[ ] = esc_attr( $added_classes ); |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | /** |
@@ -1011,10 +1011,10 @@ discard block |
||
1011 | 1011 | public function get_string( $text_key, $fallback ) { |
1012 | 1012 | // If null, populate with our field strings values. |
1013 | 1013 | if ( null === $this->strings ) { |
1014 | - $this->strings = (array) $this->args['text']; |
|
1014 | + $this->strings = (array) $this->args[ 'text' ]; |
|
1015 | 1015 | |
1016 | - if ( is_callable( $this->args['text_cb'] ) ) { |
|
1017 | - $strings = call_user_func( $this->args['text_cb'], $this ); |
|
1016 | + if ( is_callable( $this->args[ 'text_cb' ] ) ) { |
|
1017 | + $strings = call_user_func( $this->args[ 'text_cb' ], $this ); |
|
1018 | 1018 | |
1019 | 1019 | if ( $strings && is_array( $strings ) ) { |
1020 | 1020 | $this->strings += $strings; |
@@ -1049,10 +1049,10 @@ discard block |
||
1049 | 1049 | return $this->field_options; |
1050 | 1050 | } |
1051 | 1051 | |
1052 | - $this->field_options = (array) $this->args['options']; |
|
1052 | + $this->field_options = (array) $this->args[ 'options' ]; |
|
1053 | 1053 | |
1054 | - if ( is_callable( $this->args['options_cb'] ) ) { |
|
1055 | - $options = call_user_func( $this->args['options_cb'], $this ); |
|
1054 | + if ( is_callable( $this->args[ 'options_cb' ] ) ) { |
|
1055 | + $options = call_user_func( $this->args[ 'options_cb' ], $this ); |
|
1056 | 1056 | |
1057 | 1057 | if ( $options && is_array( $options ) ) { |
1058 | 1058 | $this->field_options = $options + $this->field_options; |
@@ -1074,7 +1074,7 @@ discard block |
||
1074 | 1074 | */ |
1075 | 1075 | public function add_js_dependencies( $dependencies = array() ) { |
1076 | 1076 | foreach ( (array) $dependencies as $dependency ) { |
1077 | - $this->args['js_dependencies'][ $dependency ] = $dependency; |
|
1077 | + $this->args[ 'js_dependencies' ][ $dependency ] = $dependency; |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | CMB2_JS::add_dependencies( $dependencies ); |
@@ -1088,17 +1088,17 @@ discard block |
||
1088 | 1088 | * @return mixed Default field value |
1089 | 1089 | */ |
1090 | 1090 | public function get_default() { |
1091 | - if ( null !== $this->args['default'] ) { |
|
1092 | - return $this->args['default']; |
|
1091 | + if ( null !== $this->args[ 'default' ] ) { |
|
1092 | + return $this->args[ 'default' ]; |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | - $param = is_callable( $this->args['default_cb'] ) ? 'default_cb' : 'default'; |
|
1095 | + $param = is_callable( $this->args[ 'default_cb' ] ) ? 'default_cb' : 'default'; |
|
1096 | 1096 | $default = $this->get_param_callback_result( $param ); |
1097 | 1097 | |
1098 | 1098 | // Allow a filter override of the default value |
1099 | - $this->args['default'] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
1099 | + $this->args[ 'default' ] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
1100 | 1100 | |
1101 | - return $this->args['default']; |
|
1101 | + return $this->args[ 'default' ]; |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | /** |
@@ -1129,18 +1129,18 @@ discard block |
||
1129 | 1129 | 'classes_cb' => '', |
1130 | 1130 | 'select_all_button' => true, |
1131 | 1131 | 'multiple' => false, |
1132 | - 'repeatable' => isset( $args['type'] ) && 'group' == $args['type'], |
|
1132 | + 'repeatable' => isset( $args[ 'type' ] ) && 'group' == $args[ 'type' ], |
|
1133 | 1133 | 'inline' => false, |
1134 | 1134 | 'on_front' => true, |
1135 | 1135 | 'show_names' => true, |
1136 | 1136 | 'save_field' => true, // Will not save if false |
1137 | 1137 | 'date_format' => 'm\/d\/Y', |
1138 | 1138 | 'time_format' => 'h:i A', |
1139 | - 'description' => isset( $args['desc'] ) ? $args['desc'] : '', |
|
1140 | - 'preview_size' => 'file' == $args['type'] ? array( 350, 350 ) : array( 50, 50 ), |
|
1139 | + 'description' => isset( $args[ 'desc' ] ) ? $args[ 'desc' ] : '', |
|
1140 | + 'preview_size' => 'file' == $args[ 'type' ] ? array( 350, 350 ) : array( 50, 50 ), |
|
1141 | 1141 | 'render_row_cb' => array( $this, 'render_field_callback' ), |
1142 | 1142 | 'display_cb' => array( $this, 'display_value_callback' ), |
1143 | - 'label_cb' => 'title' != $args['type'] ? array( $this, 'label' ) : '', |
|
1143 | + 'label_cb' => 'title' != $args[ 'type' ] ? array( $this, 'label' ) : '', |
|
1144 | 1144 | 'column' => false, |
1145 | 1145 | 'js_dependencies' => array(), |
1146 | 1146 | 'show_in_rest' => null, |
@@ -1155,43 +1155,43 @@ discard block |
||
1155 | 1155 | */ |
1156 | 1156 | $args = $this->convert_deprecated_params( $args ); |
1157 | 1157 | |
1158 | - $args['repeatable'] = $args['repeatable'] && ! $this->repeatable_exception( $args['type'] ); |
|
1159 | - $args['inline'] = $args['inline'] || false !== stripos( $args['type'], '_inline' ); |
|
1158 | + $args[ 'repeatable' ] = $args[ 'repeatable' ] && ! $this->repeatable_exception( $args[ 'type' ] ); |
|
1159 | + $args[ 'inline' ] = $args[ 'inline' ] || false !== stripos( $args[ 'type' ], '_inline' ); |
|
1160 | 1160 | |
1161 | - $args['options'] = 'group' == $args['type'] ? wp_parse_args( $args['options'], array( |
|
1161 | + $args[ 'options' ] = 'group' == $args[ 'type' ] ? wp_parse_args( $args[ 'options' ], array( |
|
1162 | 1162 | 'add_button' => esc_html__( 'Add Group', 'cmb2' ), |
1163 | 1163 | 'remove_button' => esc_html__( 'Remove Group', 'cmb2' ), |
1164 | - ) ) : $args['options']; |
|
1164 | + ) ) : $args[ 'options' ]; |
|
1165 | 1165 | |
1166 | - $args['_id'] = $args['id']; |
|
1167 | - $args['_name'] = $args['id']; |
|
1166 | + $args[ '_id' ] = $args[ 'id' ]; |
|
1167 | + $args[ '_name' ] = $args[ 'id' ]; |
|
1168 | 1168 | |
1169 | 1169 | if ( $this->group ) { |
1170 | 1170 | |
1171 | - $args['id'] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args['id']; |
|
1172 | - $args['_name'] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args['_name'] . ']'; |
|
1171 | + $args[ 'id' ] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args[ 'id' ]; |
|
1172 | + $args[ '_name' ] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args[ '_name' ] . ']'; |
|
1173 | 1173 | } |
1174 | 1174 | |
1175 | - if ( 'wysiwyg' == $args['type'] ) { |
|
1176 | - $args['id'] = strtolower( str_ireplace( '-', '_', $args['id'] ) ); |
|
1177 | - $args['options']['textarea_name'] = $args['_name']; |
|
1175 | + if ( 'wysiwyg' == $args[ 'type' ] ) { |
|
1176 | + $args[ 'id' ] = strtolower( str_ireplace( '-', '_', $args[ 'id' ] ) ); |
|
1177 | + $args[ 'options' ][ 'textarea_name' ] = $args[ '_name' ]; |
|
1178 | 1178 | } |
1179 | 1179 | |
1180 | 1180 | $option_types = apply_filters( 'cmb2_all_or_nothing_types', array( 'select', 'radio', 'radio_inline', 'taxonomy_select', 'taxonomy_radio', 'taxonomy_radio_inline' ), $this ); |
1181 | 1181 | |
1182 | - if ( in_array( $args['type'], $option_types, true ) ) { |
|
1182 | + if ( in_array( $args[ 'type' ], $option_types, true ) ) { |
|
1183 | 1183 | |
1184 | - $args['show_option_none'] = isset( $args['show_option_none'] ) ? $args['show_option_none'] : null; |
|
1185 | - $args['show_option_none'] = true === $args['show_option_none'] ? esc_html__( 'None', 'cmb2' ) : $args['show_option_none']; |
|
1184 | + $args[ 'show_option_none' ] = isset( $args[ 'show_option_none' ] ) ? $args[ 'show_option_none' ] : null; |
|
1185 | + $args[ 'show_option_none' ] = true === $args[ 'show_option_none' ] ? esc_html__( 'None', 'cmb2' ) : $args[ 'show_option_none' ]; |
|
1186 | 1186 | |
1187 | - if ( null === $args['show_option_none'] ) { |
|
1188 | - $off_by_default = in_array( $args['type'], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1189 | - $args['show_option_none'] = $off_by_default ? false : esc_html__( 'None', 'cmb2' ); |
|
1187 | + if ( null === $args[ 'show_option_none' ] ) { |
|
1188 | + $off_by_default = in_array( $args[ 'type' ], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1189 | + $args[ 'show_option_none' ] = $off_by_default ? false : esc_html__( 'None', 'cmb2' ); |
|
1190 | 1190 | } |
1191 | 1191 | } |
1192 | 1192 | |
1193 | - $args['has_supporting_data'] = in_array( |
|
1194 | - $args['type'], |
|
1193 | + $args[ 'has_supporting_data' ] = in_array( |
|
1194 | + $args[ 'type' ], |
|
1195 | 1195 | array( |
1196 | 1196 | // CMB2_Sanitize::_save_file_id_value()/CMB2_Sanitize::_get_group_file_value_array() |
1197 | 1197 | 'file', |
@@ -1215,10 +1215,10 @@ discard block |
||
1215 | 1215 | protected function get_default_args( $field_args, $field_group = null ) { |
1216 | 1216 | $args = parent::get_default_args( array(), $this->group ); |
1217 | 1217 | |
1218 | - if ( isset( $field_args['field_args'] ) ) { |
|
1218 | + if ( isset( $field_args[ 'field_args' ] ) ) { |
|
1219 | 1219 | $args = wp_parse_args( $field_args, $args ); |
1220 | 1220 | } else { |
1221 | - $args['field_args'] = wp_parse_args( $field_args, $this->args ); |
|
1221 | + $args[ 'field_args' ] = wp_parse_args( $field_args, $this->args ); |
|
1222 | 1222 | } |
1223 | 1223 | |
1224 | 1224 | return $args; |
@@ -1262,41 +1262,41 @@ discard block |
||
1262 | 1262 | */ |
1263 | 1263 | protected function convert_deprecated_params( $args ) { |
1264 | 1264 | |
1265 | - if ( isset( $args['row_classes'] ) ) { |
|
1265 | + if ( isset( $args[ 'row_classes' ] ) ) { |
|
1266 | 1266 | |
1267 | 1267 | // We'll let this one be. |
1268 | 1268 | // $this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_PARAM, 'row_classes', 'classes' ); |
1269 | 1269 | // row_classes param could be a callback. This is definitely deprecated. |
1270 | - if ( is_callable( $args['row_classes'] ) ) { |
|
1270 | + if ( is_callable( $args[ 'row_classes' ] ) ) { |
|
1271 | 1271 | |
1272 | 1272 | $this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'row_classes', 'classes_cb' ); |
1273 | 1273 | |
1274 | - $args['classes_cb'] = $args['row_classes']; |
|
1275 | - $args['classes'] = null; |
|
1274 | + $args[ 'classes_cb' ] = $args[ 'row_classes' ]; |
|
1275 | + $args[ 'classes' ] = null; |
|
1276 | 1276 | } else { |
1277 | 1277 | |
1278 | - $args['classes'] = $args['row_classes']; |
|
1278 | + $args[ 'classes' ] = $args[ 'row_classes' ]; |
|
1279 | 1279 | } |
1280 | 1280 | |
1281 | - unset( $args['row_classes'] ); |
|
1281 | + unset( $args[ 'row_classes' ] ); |
|
1282 | 1282 | } |
1283 | 1283 | |
1284 | 1284 | // default param can be passed a callback as well |
1285 | - if ( is_callable( $args['default'] ) ) { |
|
1285 | + if ( is_callable( $args[ 'default' ] ) ) { |
|
1286 | 1286 | |
1287 | 1287 | $this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'default', 'default_cb' ); |
1288 | 1288 | |
1289 | - $args['default_cb'] = $args['default']; |
|
1290 | - $args['default'] = null; |
|
1289 | + $args[ 'default_cb' ] = $args[ 'default' ]; |
|
1290 | + $args[ 'default' ] = null; |
|
1291 | 1291 | } |
1292 | 1292 | |
1293 | 1293 | // options param can be passed a callback as well |
1294 | - if ( is_callable( $args['options'] ) ) { |
|
1294 | + if ( is_callable( $args[ 'options' ] ) ) { |
|
1295 | 1295 | |
1296 | 1296 | $this->deprecated_param( __CLASS__ . '::__construct()', '2.2.3', self::DEPRECATED_CB_PARAM, 'options', 'options_cb' ); |
1297 | 1297 | |
1298 | - $args['options_cb'] = $args['options']; |
|
1299 | - $args['options'] = array(); |
|
1298 | + $args[ 'options_cb' ] = $args[ 'options' ]; |
|
1299 | + $args[ 'options' ] = array(); |
|
1300 | 1300 | } |
1301 | 1301 | |
1302 | 1302 | return $args; |