@@ -1,19 +1,19 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * CMB2 field objects |
|
4 | - * |
|
5 | - * @since 1.1.0 |
|
6 | - * |
|
7 | - * @category WordPress_Plugin |
|
8 | - * @package CMB2 |
|
9 | - * @author WebDevStudios |
|
10 | - * @license GPL-2.0+ |
|
11 | - * @link http://webdevstudios.com |
|
12 | - * |
|
13 | - * @method string _id() |
|
14 | - * @method string type() |
|
15 | - * @method mixed fields() |
|
16 | - */ |
|
3 | + * CMB2 field objects |
|
4 | + * |
|
5 | + * @since 1.1.0 |
|
6 | + * |
|
7 | + * @category WordPress_Plugin |
|
8 | + * @package CMB2 |
|
9 | + * @author WebDevStudios |
|
10 | + * @license GPL-2.0+ |
|
11 | + * @link http://webdevstudios.com |
|
12 | + * |
|
13 | + * @method string _id() |
|
14 | + * @method string type() |
|
15 | + * @method mixed fields() |
|
16 | + */ |
|
17 | 17 | class CMB2_Field { |
18 | 18 | |
19 | 19 | /** |
@@ -93,16 +93,16 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function __construct( $args ) { |
95 | 95 | |
96 | - if ( ! empty( $args['group_field'] ) ) { |
|
97 | - $this->group = $args['group_field']; |
|
96 | + if ( ! empty( $args[ 'group_field' ] ) ) { |
|
97 | + $this->group = $args[ 'group_field' ]; |
|
98 | 98 | $this->object_id = $this->group->object_id; |
99 | 99 | $this->object_type = $this->group->object_type; |
100 | 100 | } else { |
101 | - $this->object_id = isset( $args['object_id'] ) && '_' !== $args['object_id'] ? $args['object_id'] : 0; |
|
102 | - $this->object_type = isset( $args['object_type'] ) ? $args['object_type'] : 'post'; |
|
101 | + $this->object_id = isset( $args[ 'object_id' ] ) && '_' !== $args[ 'object_id' ] ? $args[ 'object_id' ] : 0; |
|
102 | + $this->object_type = isset( $args[ 'object_type' ] ) ? $args[ 'object_type' ] : 'post'; |
|
103 | 103 | } |
104 | 104 | |
105 | - $this->args = $this->_set_field_defaults( $args['field_args'] ); |
|
105 | + $this->args = $this->_set_field_defaults( $args[ 'field_args' ] ); |
|
106 | 106 | |
107 | 107 | if ( $this->object_id ) { |
108 | 108 | $this->value = $this->get_data(); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @return mixed Value of field argument |
118 | 118 | */ |
119 | 119 | public function __call( $name, $arguments ) { |
120 | - $key = isset( $arguments[0] ) ? $arguments[0] : false; |
|
120 | + $key = isset( $arguments[ 0 ] ) ? $arguments[ 0 ] : false; |
|
121 | 121 | return $this->args( $name, $key ); |
122 | 122 | } |
123 | 123 | |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function get_data( $field_id = '', $args = array() ) { |
190 | 190 | if ( $field_id ) { |
191 | - $args['field_id'] = $field_id; |
|
191 | + $args[ 'field_id' ] = $field_id; |
|
192 | 192 | } else if ( $this->group ) { |
193 | - $args['field_id'] = $this->group->id(); |
|
193 | + $args[ 'field_id' ] = $this->group->id(); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | $a = $this->data_args( $args ); |
@@ -231,13 +231,13 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @since 2.0.0 |
233 | 233 | */ |
234 | - $data = apply_filters( "cmb2_override_{$a['field_id']}_meta_value", $data, $this->object_id, $a, $this ); |
|
234 | + $data = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_value", $data, $this->object_id, $a, $this ); |
|
235 | 235 | |
236 | 236 | // If no override, get value normally |
237 | 237 | if ( 'cmb2_field_no_override_val' === $data ) { |
238 | - $data = 'options-page' === $a['type'] |
|
239 | - ? cmb2_options( $a['id'] )->get( $a['field_id'] ) |
|
240 | - : get_metadata( $a['type'], $a['id'], $a['field_id'], ( $a['single'] || $a['repeat'] ) ); |
|
238 | + $data = 'options-page' === $a[ 'type' ] |
|
239 | + ? cmb2_options( $a[ 'id' ] )->get( $a[ 'field_id' ] ) |
|
240 | + : get_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], ( $a[ 'single' ] || $a[ 'repeat' ] ) ); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | if ( $this->group ) { |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | public function update_data( $new_value, $single = true ) { |
260 | 260 | $a = $this->data_args( array( 'single' => $single ) ); |
261 | 261 | |
262 | - $a['value'] = $a['repeat'] ? array_values( $new_value ) : $new_value; |
|
262 | + $a[ 'value' ] = $a[ 'repeat' ] ? array_values( $new_value ) : $new_value; |
|
263 | 263 | |
264 | 264 | /** |
265 | 265 | * Filter whether to override saving of meta value. |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @since 2.0.0 |
297 | 297 | */ |
298 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_save", $override, $a, $this->args(), $this ); |
|
298 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_save", $override, $a, $this->args(), $this ); |
|
299 | 299 | |
300 | 300 | // If override, return that |
301 | 301 | if ( null !== $override ) { |
@@ -303,22 +303,22 @@ discard block |
||
303 | 303 | } |
304 | 304 | |
305 | 305 | // Options page handling (or temp data store) |
306 | - if ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
307 | - return cmb2_options( $a['id'] )->update( $a['field_id'], $a['value'], false, $a['single'] ); |
|
306 | + if ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
307 | + return cmb2_options( $a[ 'id' ] )->update( $a[ 'field_id' ], $a[ 'value' ], false, $a[ 'single' ] ); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // Add metadata if not single |
311 | - if ( ! $a['single'] ) { |
|
312 | - return add_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'], false ); |
|
311 | + if ( ! $a[ 'single' ] ) { |
|
312 | + return add_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ], false ); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | // Delete meta if we have an empty array |
316 | - if ( is_array( $a['value'] ) && empty( $a['value'] ) ) { |
|
317 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $this->value ); |
|
316 | + if ( is_array( $a[ 'value' ] ) && empty( $a[ 'value' ] ) ) { |
|
317 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $this->value ); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | // Update metadata |
321 | - return update_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'] ); |
|
321 | + return update_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ] ); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -368,19 +368,19 @@ discard block |
||
368 | 368 | * @param array $field_args All field arguments |
369 | 369 | * @param CMB2_Field object $field This field object |
370 | 370 | */ |
371 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_remove", $override, $a, $this->args(), $this ); |
|
371 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_remove", $override, $a, $this->args(), $this ); |
|
372 | 372 | |
373 | 373 | // If no override, remove as usual |
374 | 374 | if ( null !== $override ) { |
375 | 375 | return $override; |
376 | 376 | } |
377 | 377 | // Option page handling |
378 | - elseif ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
379 | - return cmb2_options( $a['id'] )->remove( $a['field_id'] ); |
|
378 | + elseif ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
379 | + return cmb2_options( $a[ 'id' ] )->remove( $a[ 'field_id' ] ); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | // Remove metadata |
383 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $old ); |
|
383 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $old ); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | |
852 | 852 | foreach ( $conditional_classes as $class => $condition ) { |
853 | 853 | if ( $condition ) { |
854 | - $classes[] = $class; |
|
854 | + $classes[ ] = $class; |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | } |
861 | 861 | |
862 | 862 | if ( $added_classes ) { |
863 | - $classes[] = esc_attr( $added_classes ); |
|
863 | + $classes[ ] = esc_attr( $added_classes ); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | /** |
@@ -965,10 +965,10 @@ discard block |
||
965 | 965 | return $this->field_options; |
966 | 966 | } |
967 | 967 | |
968 | - $this->field_options = (array) $this->args['options']; |
|
968 | + $this->field_options = (array) $this->args[ 'options' ]; |
|
969 | 969 | |
970 | - if ( is_callable( $this->args['options_cb'] ) ) { |
|
971 | - $options = call_user_func( $this->args['options_cb'], $this ); |
|
970 | + if ( is_callable( $this->args[ 'options_cb' ] ) ) { |
|
971 | + $options = call_user_func( $this->args[ 'options_cb' ], $this ); |
|
972 | 972 | |
973 | 973 | if ( $options && is_array( $options ) ) { |
974 | 974 | $this->field_options += $options; |
@@ -990,17 +990,17 @@ discard block |
||
990 | 990 | * @return mixed Default field value |
991 | 991 | */ |
992 | 992 | public function get_default() { |
993 | - if ( null !== $this->args['default'] ) { |
|
994 | - return $this->args['default']; |
|
993 | + if ( null !== $this->args[ 'default' ] ) { |
|
994 | + return $this->args[ 'default' ]; |
|
995 | 995 | } |
996 | 996 | |
997 | - $param = is_callable( $this->args['default_cb'] ) ? 'default_cb' : 'default'; |
|
997 | + $param = is_callable( $this->args[ 'default_cb' ] ) ? 'default_cb' : 'default'; |
|
998 | 998 | $default = $this->get_param_callback_result( $param, false ); |
999 | 999 | |
1000 | 1000 | // Allow a filter override of the default value |
1001 | - $this->args['default'] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
1001 | + $this->args[ 'default' ] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
1002 | 1002 | |
1003 | - return $this->args['default']; |
|
1003 | + return $this->args[ 'default' ]; |
|
1004 | 1004 | } |
1005 | 1005 | |
1006 | 1006 | /** |
@@ -1025,68 +1025,68 @@ discard block |
||
1025 | 1025 | 'default_cb' => '', |
1026 | 1026 | 'select_all_button' => true, |
1027 | 1027 | 'multiple' => false, |
1028 | - 'repeatable' => isset( $args['type'] ) && 'group' == $args['type'], |
|
1028 | + 'repeatable' => isset( $args[ 'type' ] ) && 'group' == $args[ 'type' ], |
|
1029 | 1029 | 'inline' => false, |
1030 | 1030 | 'on_front' => true, |
1031 | 1031 | 'show_names' => true, |
1032 | 1032 | 'date_format' => 'm\/d\/Y', |
1033 | 1033 | 'time_format' => 'h:i A', |
1034 | - 'description' => isset( $args['desc'] ) ? $args['desc'] : '', |
|
1035 | - 'preview_size' => 'file' == $args['type'] ? array( 350, 350 ) : array( 50, 50 ), |
|
1034 | + 'description' => isset( $args[ 'desc' ] ) ? $args[ 'desc' ] : '', |
|
1035 | + 'preview_size' => 'file' == $args[ 'type' ] ? array( 350, 350 ) : array( 50, 50 ), |
|
1036 | 1036 | 'render_row_cb' => array( $this, 'render_field_callback' ), |
1037 | - 'label_cb' => 'title' != $args['type'] ? array( $this, 'label' ) : '', |
|
1037 | + 'label_cb' => 'title' != $args[ 'type' ] ? array( $this, 'label' ) : '', |
|
1038 | 1038 | ) ); |
1039 | 1039 | |
1040 | 1040 | // default param can be passed a callback as well |
1041 | - if ( is_callable( $args['default'] ) ) { |
|
1042 | - $args['default_cb'] = $args['default']; |
|
1043 | - $args['default'] = null; |
|
1041 | + if ( is_callable( $args[ 'default' ] ) ) { |
|
1042 | + $args[ 'default_cb' ] = $args[ 'default' ]; |
|
1043 | + $args[ 'default' ] = null; |
|
1044 | 1044 | } |
1045 | 1045 | |
1046 | - $args['repeatable'] = $args['repeatable'] && ! $this->repeatable_exception( $args['type'] ); |
|
1047 | - $args['inline'] = $args['inline'] || false !== stripos( $args['type'], '_inline' ); |
|
1046 | + $args[ 'repeatable' ] = $args[ 'repeatable' ] && ! $this->repeatable_exception( $args[ 'type' ] ); |
|
1047 | + $args[ 'inline' ] = $args[ 'inline' ] || false !== stripos( $args[ 'type' ], '_inline' ); |
|
1048 | 1048 | |
1049 | 1049 | // options param can be passed a callback as well |
1050 | - if ( is_callable( $args['options'] ) ) { |
|
1051 | - $args['options_cb'] = $args['options']; |
|
1052 | - $args['options'] = array(); |
|
1050 | + if ( is_callable( $args[ 'options' ] ) ) { |
|
1051 | + $args[ 'options_cb' ] = $args[ 'options' ]; |
|
1052 | + $args[ 'options' ] = array(); |
|
1053 | 1053 | } |
1054 | 1054 | |
1055 | - $args['options'] = 'group' == $args['type'] ? wp_parse_args( $args['options'], array( |
|
1055 | + $args[ 'options' ] = 'group' == $args[ 'type' ] ? wp_parse_args( $args[ 'options' ], array( |
|
1056 | 1056 | 'add_button' => __( 'Add Group', 'cmb2' ), |
1057 | 1057 | 'remove_button' => __( 'Remove Group', 'cmb2' ), |
1058 | - ) ) : $args['options']; |
|
1058 | + ) ) : $args[ 'options' ]; |
|
1059 | 1059 | |
1060 | - $args['_id'] = $args['id']; |
|
1061 | - $args['_name'] = $args['id']; |
|
1060 | + $args[ '_id' ] = $args[ 'id' ]; |
|
1061 | + $args[ '_name' ] = $args[ 'id' ]; |
|
1062 | 1062 | |
1063 | 1063 | if ( $this->group ) { |
1064 | 1064 | |
1065 | - $args['id'] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args['id']; |
|
1066 | - $args['_name'] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args['_name'] . ']'; |
|
1065 | + $args[ 'id' ] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args[ 'id' ]; |
|
1066 | + $args[ '_name' ] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args[ '_name' ] . ']'; |
|
1067 | 1067 | } |
1068 | 1068 | |
1069 | - if ( 'wysiwyg' == $args['type'] ) { |
|
1070 | - $args['id'] = strtolower( str_ireplace( '-', '_', $args['id'] ) ); |
|
1071 | - $args['options']['textarea_name'] = $args['_name']; |
|
1069 | + if ( 'wysiwyg' == $args[ 'type' ] ) { |
|
1070 | + $args[ 'id' ] = strtolower( str_ireplace( '-', '_', $args[ 'id' ] ) ); |
|
1071 | + $args[ 'options' ][ 'textarea_name' ] = $args[ '_name' ]; |
|
1072 | 1072 | } |
1073 | 1073 | |
1074 | 1074 | $option_types = apply_filters( 'cmb2_all_or_nothing_types', array( 'select', 'radio', 'radio_inline', 'taxonomy_select', 'taxonomy_radio', 'taxonomy_radio_inline' ), $this ); |
1075 | 1075 | |
1076 | - if ( in_array( $args['type'], $option_types, true ) ) { |
|
1076 | + if ( in_array( $args[ 'type' ], $option_types, true ) ) { |
|
1077 | 1077 | |
1078 | - $args['show_option_none'] = isset( $args['show_option_none'] ) ? $args['show_option_none'] : null; |
|
1079 | - $args['show_option_none'] = true === $args['show_option_none'] ? __( 'None', 'cmb2' ) : $args['show_option_none']; |
|
1078 | + $args[ 'show_option_none' ] = isset( $args[ 'show_option_none' ] ) ? $args[ 'show_option_none' ] : null; |
|
1079 | + $args[ 'show_option_none' ] = true === $args[ 'show_option_none' ] ? __( 'None', 'cmb2' ) : $args[ 'show_option_none' ]; |
|
1080 | 1080 | |
1081 | - if ( null === $args['show_option_none'] ) { |
|
1082 | - $off_by_default = in_array( $args['type'], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1083 | - $args['show_option_none'] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
1081 | + if ( null === $args[ 'show_option_none' ] ) { |
|
1082 | + $off_by_default = in_array( $args[ 'type' ], array( 'select', 'radio', 'radio_inline' ), true ); |
|
1083 | + $args[ 'show_option_none' ] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
1084 | 1084 | } |
1085 | 1085 | |
1086 | 1086 | } |
1087 | 1087 | |
1088 | - $args['has_supporting_data'] = in_array( |
|
1089 | - $args['type'], |
|
1088 | + $args[ 'has_supporting_data' ] = in_array( |
|
1089 | + $args[ 'type' ], |
|
1090 | 1090 | array( |
1091 | 1091 | // CMB2_Sanitize::_save_file_id_value()/CMB2_Sanitize::_get_group_file_value_array() |
1092 | 1092 | 'file', |
@@ -1105,7 +1105,7 @@ discard block |
||
1105 | 1105 | * @param array $attrs Array of attributes to update |
1106 | 1106 | */ |
1107 | 1107 | public function maybe_set_attributes( $attrs = array() ) { |
1108 | - return wp_parse_args( $this->args['attributes'], $attrs ); |
|
1108 | + return wp_parse_args( $this->args[ 'attributes' ], $attrs ); |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | } |
@@ -197,8 +197,8 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function concat_items( $args = array() ) { |
199 | 199 | |
200 | - $method = isset( $args['method'] ) ? $args['method'] : 'select_option'; |
|
201 | - unset( $args['method'] ); |
|
200 | + $method = isset( $args[ 'method' ] ) ? $args[ 'method' ] : 'select_option'; |
|
201 | + unset( $args[ 'method' ] ); |
|
202 | 202 | |
203 | 203 | $value = $this->field->escaped_value() |
204 | 204 | ? $this->field->escaped_value() |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | // Clone args & modify for just this item |
217 | 217 | $a = $args; |
218 | 218 | |
219 | - $a['value'] = $opt_value; |
|
220 | - $a['label'] = $opt_label; |
|
219 | + $a[ 'value' ] = $opt_value; |
|
220 | + $a[ 'label' ] = $opt_label; |
|
221 | 221 | |
222 | 222 | // Check if this option is the value of the input |
223 | 223 | if ( $value == $opt_value ) { |
224 | - $a['checked'] = 'checked'; |
|
224 | + $a[ 'checked' ] = 'checked'; |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | $concatenated_items .= $this->$method( $a, $i++ ); |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @return string Generated option element html |
238 | 238 | */ |
239 | 239 | public function select_option( $args = array() ) { |
240 | - return sprintf( "\t" . '<option value="%s" %s>%s</option>', $args['value'], selected( isset( $args['checked'] ) && $args['checked'], true, false ), $args['label'] ) . "\n"; |
|
240 | + return sprintf( "\t" . '<option value="%s" %s>%s</option>', $args[ 'value' ], selected( isset( $args[ 'checked' ] ) && $args[ 'checked' ], true, false ), $args[ 'label' ] ) . "\n"; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | 'label' => '', |
258 | 258 | ) ); |
259 | 259 | |
260 | - return sprintf( "\t" . '<li><input%s/> <label for="%s">%s</label></li>' . "\n", $this->concat_attrs( $a, array( 'label' ) ), $a['id'], $a['label'] ); |
|
260 | + return sprintf( "\t" . '<li><input%s/> <label for="%s">%s</label></li>' . "\n", $this->concat_attrs( $a, array( 'label' ) ), $a[ 'id' ], $a[ 'label' ] ); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | */ |
270 | 270 | public function list_input_checkbox( $args, $i ) { |
271 | 271 | $saved_value = $this->field->escaped_value(); |
272 | - if ( is_array( $saved_value ) && in_array( $args['value'], $saved_value ) ) { |
|
273 | - $args['checked'] = 'checked'; |
|
272 | + if ( is_array( $saved_value ) && in_array( $args[ 'value' ], $saved_value ) ) { |
|
273 | + $args[ 'checked' ] = 'checked'; |
|
274 | 274 | } |
275 | - $args['type'] = 'checkbox'; |
|
275 | + $args[ 'type' ] = 'checkbox'; |
|
276 | 276 | return $this->list_input( $args, $i ); |
277 | 277 | } |
278 | 278 | |
@@ -423,11 +423,11 @@ discard block |
||
423 | 423 | 'js_dependencies' => array(), |
424 | 424 | ) ); |
425 | 425 | |
426 | - if ( ! empty( $a['js_dependencies'] ) ) { |
|
427 | - CMB2_JS::add_dependencies( $a['js_dependencies'] ); |
|
426 | + if ( ! empty( $a[ 'js_dependencies' ] ) ) { |
|
427 | + CMB2_JS::add_dependencies( $a[ 'js_dependencies' ] ); |
|
428 | 428 | } |
429 | 429 | |
430 | - return sprintf( '<input%s/>%s', $this->concat_attrs( $a, array( 'desc', 'js_dependencies' ) ), $a['desc'] ); |
|
430 | + return sprintf( '<input%s/>%s', $this->concat_attrs( $a, array( 'desc', 'js_dependencies' ) ), $a[ 'desc' ] ); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | 'value' => $this->field->escaped_value( 'esc_textarea' ), |
447 | 447 | 'desc' => $this->_desc( true ), |
448 | 448 | ) ); |
449 | - return sprintf( '<textarea%s>%s</textarea>%s', $this->concat_attrs( $a, array( 'desc', 'value' ) ), $a['value'], $a['desc'] ); |
|
449 | + return sprintf( '<textarea%s>%s</textarea>%s', $this->concat_attrs( $a, array( 'desc', 'value' ) ), $a[ 'value' ], $a[ 'desc' ] ); |
|
450 | 450 | } |
451 | 451 | |
452 | 452 | /** |
@@ -497,8 +497,8 @@ discard block |
||
497 | 497 | 'options' => $this->field->options(), |
498 | 498 | ) ); |
499 | 499 | |
500 | - wp_editor( $a['value'], $a['id'], $a['options'] ); |
|
501 | - echo $a['desc']; |
|
500 | + wp_editor( $a[ 'value' ], $a[ 'id' ], $a[ 'options' ] ); |
|
501 | + echo $a[ 'desc' ]; |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | public function text_date( $args = array() ) { |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | 'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker' ), |
510 | 510 | ) ); |
511 | 511 | |
512 | - if ( false === strpos( $args['class'], 'timepicker' ) ) { |
|
512 | + if ( false === strpos( $args[ 'class' ], 'timepicker' ) ) { |
|
513 | 513 | $this->parse_picker_options( 'date' ); |
514 | 514 | } |
515 | 515 | |
@@ -541,34 +541,34 @@ discard block |
||
541 | 541 | 'timepicker' => array(), |
542 | 542 | ) ); |
543 | 543 | |
544 | - if ( empty( $args['value'] ) ) { |
|
545 | - $args['value'] = $this->field->escaped_value(); |
|
544 | + if ( empty( $args[ 'value' ] ) ) { |
|
545 | + $args[ 'value' ] = $this->field->escaped_value(); |
|
546 | 546 | // This will be used if there is a select_timezone set for this field |
547 | 547 | $tz_offset = $this->field->field_timezone_offset(); |
548 | 548 | if ( ! empty( $tz_offset ) ) { |
549 | - $args['value'] -= $tz_offset; |
|
549 | + $args[ 'value' ] -= $tz_offset; |
|
550 | 550 | } |
551 | 551 | } |
552 | 552 | |
553 | - $has_good_value = ! empty( $args['value'] ) && ! is_array( $args['value'] ); |
|
553 | + $has_good_value = ! empty( $args[ 'value' ] ) && ! is_array( $args[ 'value' ] ); |
|
554 | 554 | |
555 | - $date_args = wp_parse_args( $args['datepicker'], array( |
|
555 | + $date_args = wp_parse_args( $args[ 'datepicker' ], array( |
|
556 | 556 | 'class' => 'cmb2-text-small cmb2-datepicker', |
557 | 557 | 'name' => $this->_name( '[date]' ), |
558 | 558 | 'id' => $this->_id( '_date' ), |
559 | - 'value' => $has_good_value ? $this->field->get_timestamp_format( 'date_format', $args['value'] ) : '', |
|
559 | + 'value' => $has_good_value ? $this->field->get_timestamp_format( 'date_format', $args[ 'value' ] ) : '', |
|
560 | 560 | 'desc' => '', |
561 | 561 | ) ); |
562 | 562 | |
563 | 563 | // Let's get the date-format, and set it up as a data attr for the field. |
564 | 564 | $date_args = $this->parse_picker_options( 'date', $date_args ); |
565 | 565 | |
566 | - $time_args = wp_parse_args( $args['timepicker'], array( |
|
566 | + $time_args = wp_parse_args( $args[ 'timepicker' ], array( |
|
567 | 567 | 'class' => 'cmb2-timepicker text-time', |
568 | 568 | 'name' => $this->_name( '[time]' ), |
569 | 569 | 'id' => $this->_id( '_time' ), |
570 | - 'value' => $has_good_value ? $this->field->get_timestamp_format( 'time_format', $args['value'] ) : '', |
|
571 | - 'desc' => $args['desc'], |
|
570 | + 'value' => $has_good_value ? $this->field->get_timestamp_format( 'time_format', $args[ 'value' ] ) : '', |
|
571 | + 'desc' => $args[ 'desc' ], |
|
572 | 572 | 'js_dependencies' => array( 'jquery-ui-core', 'jquery-ui-datepicker', 'jquery-ui-datetimepicker' ), |
573 | 573 | ) ); |
574 | 574 | |
@@ -586,12 +586,12 @@ discard block |
||
586 | 586 | 'select_timezone' => array(), |
587 | 587 | ) ); |
588 | 588 | |
589 | - $args['value'] = $this->field->escaped_value(); |
|
590 | - if ( is_array( $args['value'] ) ) { |
|
591 | - $args['value'] = ''; |
|
589 | + $args[ 'value' ] = $this->field->escaped_value(); |
|
590 | + if ( is_array( $args[ 'value' ] ) ) { |
|
591 | + $args[ 'value' ] = ''; |
|
592 | 592 | } |
593 | 593 | |
594 | - $datetime = maybe_unserialize( $args['value'] ); |
|
594 | + $datetime = maybe_unserialize( $args[ 'value' ] ); |
|
595 | 595 | $value = $tzstring = ''; |
596 | 596 | |
597 | 597 | if ( $datetime && $datetime instanceof DateTime ) { |
@@ -600,24 +600,24 @@ discard block |
||
600 | 600 | $value = $datetime->getTimestamp(); |
601 | 601 | } |
602 | 602 | |
603 | - $timestamp_args = wp_parse_args( $args['text_datetime_timestamp'], array( |
|
603 | + $timestamp_args = wp_parse_args( $args[ 'text_datetime_timestamp' ], array( |
|
604 | 604 | 'desc' => '', |
605 | 605 | 'value' => $value, |
606 | 606 | ) ); |
607 | 607 | |
608 | - $timezone_args = wp_parse_args( $args['select_timezone'], array( |
|
608 | + $timezone_args = wp_parse_args( $args[ 'select_timezone' ], array( |
|
609 | 609 | 'class' => 'cmb2_select cmb2-select-timezone', |
610 | 610 | 'name' => $this->_name( '[timezone]' ), |
611 | 611 | 'id' => $this->_id( '_timezone' ), |
612 | 612 | 'options' => wp_timezone_choice( $tzstring ), |
613 | - 'desc' => $args['desc'], |
|
613 | + 'desc' => $args[ 'desc' ], |
|
614 | 614 | ) ); |
615 | 615 | |
616 | 616 | return $this->text_datetime_timestamp( $timestamp_args ) . "\n" . $this->select( $timezone_args ); |
617 | 617 | } |
618 | 618 | |
619 | 619 | public function select_timezone() { |
620 | - $this->field->args['default'] = $this->field->get_default() |
|
620 | + $this->field->args[ 'default' ] = $this->field->get_default() |
|
621 | 621 | ? $this->field->get_default() |
622 | 622 | : cmb2_utils()->timezone_string(); |
623 | 623 | |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | 'desc' => $this->_desc( true ), |
660 | 660 | ) ); |
661 | 661 | |
662 | - return sprintf( '<%1$s class="%2$s">%3$s</%1$s>%4$s', $a['tag'], $a['class'], $a['name'], $a['desc'] ); |
|
662 | + return sprintf( '<%1$s class="%2$s">%3$s</%1$s>%4$s', $a[ 'tag' ], $a[ 'class' ], $a[ 'name' ], $a[ 'desc' ] ); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | public function select( $args = array() ) { |
@@ -672,17 +672,17 @@ discard block |
||
672 | 672 | ) ); |
673 | 673 | |
674 | 674 | $attrs = $this->concat_attrs( $a, array( 'desc', 'options' ) ); |
675 | - return sprintf( '<select%s>%s</select>%s', $attrs, $a['options'], $a['desc'] ); |
|
675 | + return sprintf( '<select%s>%s</select>%s', $attrs, $a[ 'options' ], $a[ 'desc' ] ); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | public function taxonomy_select() { |
679 | 679 | |
680 | 680 | $names = $this->get_object_terms(); |
681 | - $saved_term = is_wp_error( $names ) || empty( $names ) ? $this->field->get_default() : $names[key( $names )]->slug; |
|
681 | + $saved_term = is_wp_error( $names ) || empty( $names ) ? $this->field->get_default() : $names[ key( $names ) ]->slug; |
|
682 | 682 | $terms = get_terms( $this->field->args( 'taxonomy' ), 'hide_empty=0' ); |
683 | 683 | $options = ''; |
684 | 684 | |
685 | - $option_none = $this->field->args( 'show_option_none' ); |
|
685 | + $option_none = $this->field->args( 'show_option_none' ); |
|
686 | 686 | if ( ! empty( $option_none ) ) { |
687 | 687 | $option_none_value = apply_filters( 'cmb2_taxonomy_select_default_value', '' ); |
688 | 688 | $option_none_value = apply_filters( "cmb2_taxonomy_select_{$this->_id()}_default_value", $option_none_value ); |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | 'desc' => $this->_desc( true ), |
713 | 713 | ) ); |
714 | 714 | |
715 | - return sprintf( '<ul class="%s">%s</ul>%s', $a['class'], $a['options'], $a['desc'] ); |
|
715 | + return sprintf( '<ul class="%s">%s</ul>%s', $a[ 'class' ], $a[ 'options' ], $a[ 'desc' ] ); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | public function radio_inline() { |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | : $is_checked; |
748 | 748 | |
749 | 749 | if ( $is_checked ) { |
750 | - $defaults['checked'] = 'checked'; |
|
750 | + $defaults[ 'checked' ] = 'checked'; |
|
751 | 751 | } |
752 | 752 | |
753 | 753 | $args = $this->parse_args( $args, 'checkbox', $defaults ); |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | |
758 | 758 | public function taxonomy_radio() { |
759 | 759 | $names = $this->get_object_terms(); |
760 | - $saved_term = is_wp_error( $names ) || empty( $names ) ? $this->field->get_default() : $names[key( $names )]->slug; |
|
760 | + $saved_term = is_wp_error( $names ) || empty( $names ) ? $this->field->get_default() : $names[ key( $names ) ]->slug; |
|
761 | 761 | $terms = get_terms( $this->field->args( 'taxonomy' ), 'hide_empty=0' ); |
762 | 762 | $options = ''; |
763 | 763 | $i = 1; |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | if ( ! $terms ) { |
766 | 766 | $options .= sprintf( '<li><label>%s</label></li>', esc_html( $this->_text( 'no_terms_text', __( 'No terms', 'cmb2' ) ) ) ); |
767 | 767 | } else { |
768 | - $option_none = $this->field->args( 'show_option_none' ); |
|
768 | + $option_none = $this->field->args( 'show_option_none' ); |
|
769 | 769 | if ( ! empty( $option_none ) ) { |
770 | 770 | $option_none_value = apply_filters( "cmb2_taxonomy_radio_{$this->_id()}_default_value", apply_filters( 'cmb2_taxonomy_radio_default_value', '' ) ); |
771 | 771 | $args = array( |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | 'label' => $option_none, |
774 | 774 | ); |
775 | 775 | if ( $saved_term == $option_none_value ) { |
776 | - $args['checked'] = 'checked'; |
|
776 | + $args[ 'checked' ] = 'checked'; |
|
777 | 777 | } |
778 | 778 | $options .= $this->list_input( $args, $i ); |
779 | 779 | $i++; |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | ); |
787 | 787 | |
788 | 788 | if ( $saved_term == $term->slug ) { |
789 | - $args['checked'] = 'checked'; |
|
789 | + $args[ 'checked' ] = 'checked'; |
|
790 | 790 | } |
791 | 791 | $options .= $this->list_input( $args, $i ); |
792 | 792 | $i++; |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | ); |
824 | 824 | |
825 | 825 | if ( is_array( $saved_terms ) && in_array( $term->slug, $saved_terms ) ) { |
826 | - $args['checked'] = 'checked'; |
|
826 | + $args[ 'checked' ] = 'checked'; |
|
827 | 827 | } |
828 | 828 | $options .= $this->list_input( $args, $i ); |
829 | 829 | $i++; |
@@ -928,7 +928,7 @@ discard block |
||
928 | 928 | $query_args = $this->field->args( 'query_args' ); |
929 | 929 | |
930 | 930 | // if options array and 'url' => false, then hide the url field |
931 | - $input_type = array_key_exists( 'url', $options ) && false === $options['url'] ? 'hidden' : 'text'; |
|
931 | + $input_type = array_key_exists( 'url', $options ) && false === $options[ 'url' ] ? 'hidden' : 'text'; |
|
932 | 932 | |
933 | 933 | echo $this->input( array( |
934 | 934 | 'type' => $input_type, |
@@ -949,8 +949,8 @@ discard block |
||
949 | 949 | // Reset field args for attachment ID |
950 | 950 | $args = $this->field->args(); |
951 | 951 | // If we're looking at a file in a group, we need to get the non-prefixed id |
952 | - $args['id'] = ( $this->field->group ? $this->field->args( '_id' ) : $cached_id ) . '_id'; |
|
953 | - unset( $args['_id'], $args['_name'] ); |
|
952 | + $args[ 'id' ] = ( $this->field->group ? $this->field->args( '_id' ) : $cached_id ) . '_id'; |
|
953 | + unset( $args[ '_id' ], $args[ '_name' ] ); |
|
954 | 954 | |
955 | 955 | // And get new field object |
956 | 956 | $this->field = new CMB2_Field( array( |
@@ -982,7 +982,7 @@ discard block |
||
982 | 982 | if ( $_id_value ) { |
983 | 983 | $image = wp_get_attachment_image( $_id_value, $img_size, null, array( 'class' => 'cmb-file-field-image' ) ); |
984 | 984 | } else { |
985 | - $size = is_array( $img_size ) ? $img_size[0] : 350; |
|
985 | + $size = is_array( $img_size ) ? $img_size[ 0 ] : 350; |
|
986 | 986 | $image = '<img style="max-width: ' . absint( $size ) . 'px; width: 100%; height: auto;" src="' . $meta_value . '" alt="" />'; |
987 | 987 | } |
988 | 988 | |
@@ -1013,11 +1013,11 @@ discard block |
||
1013 | 1013 | */ |
1014 | 1014 | public function img_status_output( $args ) { |
1015 | 1015 | printf( '<%1$s class="img-status">%2$s<p class="cmb2-remove-wrapper"><a href="#" class="cmb2-remove-file-button"%3$s>%4$s</a></p>%5$s</%1$s>', |
1016 | - $args['tag'], |
|
1017 | - $args['image'], |
|
1018 | - isset( $args['cached_id'] ) ? ' rel="' . $args['cached_id'] . '"' : '', |
|
1016 | + $args[ 'tag' ], |
|
1017 | + $args[ 'image' ], |
|
1018 | + isset( $args[ 'cached_id' ] ) ? ' rel="' . $args[ 'cached_id' ] . '"' : '', |
|
1019 | 1019 | esc_html( $this->_text( 'remove_image_text', __( 'Remove Image', 'cmb2' ) ) ), |
1020 | - isset( $args['id_input'] ) ? $args['id_input'] : '' |
|
1020 | + isset( $args[ 'id_input' ] ) ? $args[ 'id_input' ] : '' |
|
1021 | 1021 | ); |
1022 | 1022 | } |
1023 | 1023 | |
@@ -1029,14 +1029,14 @@ discard block |
||
1029 | 1029 | */ |
1030 | 1030 | public function file_status_output( $args ) { |
1031 | 1031 | printf( '<%1$s class="file-status"><span>%2$s <strong>%3$s</strong></span> (<a href="%4$s" target="_blank" rel="external">%5$s</a> / <a href="#" class="cmb2-remove-file-button"%6$s>%7$s</a>)%8$s</%1$s>', |
1032 | - $args['tag'], |
|
1032 | + $args[ 'tag' ], |
|
1033 | 1033 | esc_html( $this->_text( 'file_text', __( 'File:', 'cmb2' ) ) ), |
1034 | - $this->get_file_name_from_path( $args['value'] ), |
|
1035 | - $args['value'], |
|
1034 | + $this->get_file_name_from_path( $args[ 'value' ] ), |
|
1035 | + $args[ 'value' ], |
|
1036 | 1036 | esc_html( $this->_text( 'file_download_text', __( 'Download', 'cmb2' ) ) ), |
1037 | - isset( $args['cached_id'] ) ? ' rel="' . $args['cached_id'] . '"' : '', |
|
1037 | + isset( $args[ 'cached_id' ] ) ? ' rel="' . $args[ 'cached_id' ] . '"' : '', |
|
1038 | 1038 | esc_html( $this->_text( 'remove_text', __( 'Remove', 'cmb2' ) ) ), |
1039 | - isset( $args['id_input'] ) ? $args['id_input'] : '' |
|
1039 | + isset( $args[ 'id_input' ] ) ? $args[ 'id_input' ] : '' |
|
1040 | 1040 | ); |
1041 | 1041 | } |
1042 | 1042 | |
@@ -1058,8 +1058,8 @@ discard block |
||
1058 | 1058 | if ( $update ) { |
1059 | 1059 | $atts = $this->field->args( 'attributes' ); |
1060 | 1060 | } else { |
1061 | - $atts = isset( $args['attributes'] ) |
|
1062 | - ? $args['attributes'] |
|
1061 | + $atts = isset( $args[ 'attributes' ] ) |
|
1062 | + ? $args[ 'attributes' ] |
|
1063 | 1063 | : $atts; |
1064 | 1064 | } |
1065 | 1065 | |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | if ( $update ) { |
1078 | - $this->field->args['attributes'] = $atts; |
|
1078 | + $this->field->args[ 'attributes' ] = $atts; |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | return array_merge( $args, $atts ); |