@@ -107,21 +107,21 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function __construct( $args ) { |
| 109 | 109 | |
| 110 | - if ( ! empty( $args['group_field'] ) ) { |
|
| 111 | - $this->group = $args['group_field']; |
|
| 110 | + if ( ! empty( $args[ 'group_field' ] ) ) { |
|
| 111 | + $this->group = $args[ 'group_field' ]; |
|
| 112 | 112 | $this->object_id = $this->group->object_id; |
| 113 | 113 | $this->object_type = $this->group->object_type; |
| 114 | 114 | $this->cmb_id = $this->group->cmb_id; |
| 115 | 115 | } else { |
| 116 | - $this->object_id = isset( $args['object_id'] ) && '_' !== $args['object_id'] ? $args['object_id'] : 0; |
|
| 117 | - $this->object_type = isset( $args['object_type'] ) ? $args['object_type'] : 'post'; |
|
| 116 | + $this->object_id = isset( $args[ 'object_id' ] ) && '_' !== $args[ 'object_id' ] ? $args[ 'object_id' ] : 0; |
|
| 117 | + $this->object_type = isset( $args[ 'object_type' ] ) ? $args[ 'object_type' ] : 'post'; |
|
| 118 | 118 | |
| 119 | - if ( isset( $args['cmb_id'] ) ) { |
|
| 120 | - $this->cmb_id = $args['cmb_id']; |
|
| 119 | + if ( isset( $args[ 'cmb_id' ] ) ) { |
|
| 120 | + $this->cmb_id = $args[ 'cmb_id' ]; |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - $this->args = $this->_set_field_defaults( $args['field_args'] ); |
|
| 124 | + $this->args = $this->_set_field_defaults( $args[ 'field_args' ] ); |
|
| 125 | 125 | |
| 126 | 126 | if ( $this->object_id ) { |
| 127 | 127 | $this->value = $this->get_data(); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @return mixed Value of field argument |
| 137 | 137 | */ |
| 138 | 138 | public function __call( $name, $arguments ) { |
| 139 | - $key = isset( $arguments[0] ) ? $arguments[0] : false; |
|
| 139 | + $key = isset( $arguments[ 0 ] ) ? $arguments[ 0 ] : false; |
|
| 140 | 140 | return $this->args( $name, $key ); |
| 141 | 141 | } |
| 142 | 142 | |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | public function get_data( $field_id = '', $args = array() ) { |
| 209 | 209 | if ( $field_id ) { |
| 210 | - $args['field_id'] = $field_id; |
|
| 210 | + $args[ 'field_id' ] = $field_id; |
|
| 211 | 211 | } else if ( $this->group ) { |
| 212 | - $args['field_id'] = $this->group->id(); |
|
| 212 | + $args[ 'field_id' ] = $this->group->id(); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | $a = $this->data_args( $args ); |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | * |
| 251 | 251 | * @since 2.0.0 |
| 252 | 252 | */ |
| 253 | - $data = apply_filters( "cmb2_override_{$a['field_id']}_meta_value", $data, $this->object_id, $a, $this ); |
|
| 253 | + $data = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_value", $data, $this->object_id, $a, $this ); |
|
| 254 | 254 | |
| 255 | 255 | // If no override, get value normally |
| 256 | 256 | if ( 'cmb2_field_no_override_val' === $data ) { |
| 257 | - $data = 'options-page' === $a['type'] |
|
| 258 | - ? cmb2_options( $a['id'] )->get( $a['field_id'] ) |
|
| 259 | - : get_metadata( $a['type'], $a['id'], $a['field_id'], ( $a['single'] || $a['repeat'] ) ); |
|
| 257 | + $data = 'options-page' === $a[ 'type' ] |
|
| 258 | + ? cmb2_options( $a[ 'id' ] )->get( $a[ 'field_id' ] ) |
|
| 259 | + : get_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], ( $a[ 'single' ] || $a[ 'repeat' ] ) ); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | if ( $this->group ) { |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | public function update_data( $new_value, $single = true ) { |
| 279 | 279 | $a = $this->data_args( array( 'single' => $single ) ); |
| 280 | 280 | |
| 281 | - $a['value'] = $a['repeat'] ? array_values( $new_value ) : $new_value; |
|
| 281 | + $a[ 'value' ] = $a[ 'repeat' ] ? array_values( $new_value ) : $new_value; |
|
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * Filter whether to override saving of meta value. |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * |
| 315 | 315 | * @since 2.0.0 |
| 316 | 316 | */ |
| 317 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_save", $override, $a, $this->args(), $this ); |
|
| 317 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_save", $override, $a, $this->args(), $this ); |
|
| 318 | 318 | |
| 319 | 319 | // If override, return that |
| 320 | 320 | if ( null !== $override ) { |
@@ -322,22 +322,22 @@ discard block |
||
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | // Options page handling (or temp data store) |
| 325 | - if ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
| 326 | - return cmb2_options( $a['id'] )->update( $a['field_id'], $a['value'], false, $a['single'] ); |
|
| 325 | + if ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
| 326 | + return cmb2_options( $a[ 'id' ] )->update( $a[ 'field_id' ], $a[ 'value' ], false, $a[ 'single' ] ); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | // Add metadata if not single |
| 330 | - if ( ! $a['single'] ) { |
|
| 331 | - return add_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'], false ); |
|
| 330 | + if ( ! $a[ 'single' ] ) { |
|
| 331 | + return add_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ], false ); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | // Delete meta if we have an empty array |
| 335 | - if ( is_array( $a['value'] ) && empty( $a['value'] ) ) { |
|
| 336 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $this->value ); |
|
| 335 | + if ( is_array( $a[ 'value' ] ) && empty( $a[ 'value' ] ) ) { |
|
| 336 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $this->value ); |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // Update metadata |
| 340 | - return update_metadata( $a['type'], $a['id'], $a['field_id'], $a['value'] ); |
|
| 340 | + return update_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $a[ 'value' ] ); |
|
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | /** |
@@ -387,19 +387,19 @@ discard block |
||
| 387 | 387 | * @param array $field_args All field arguments |
| 388 | 388 | * @param CMB2_Field object $field This field object |
| 389 | 389 | */ |
| 390 | - $override = apply_filters( "cmb2_override_{$a['field_id']}_meta_remove", $override, $a, $this->args(), $this ); |
|
| 390 | + $override = apply_filters( "cmb2_override_{$a[ 'field_id' ]}_meta_remove", $override, $a, $this->args(), $this ); |
|
| 391 | 391 | |
| 392 | 392 | // If no override, remove as usual |
| 393 | 393 | if ( null !== $override ) { |
| 394 | 394 | return $override; |
| 395 | 395 | } |
| 396 | 396 | // Option page handling |
| 397 | - elseif ( 'options-page' === $a['type'] || empty( $a['id'] ) ) { |
|
| 398 | - return cmb2_options( $a['id'] )->remove( $a['field_id'] ); |
|
| 397 | + elseif ( 'options-page' === $a[ 'type' ] || empty( $a[ 'id' ] ) ) { |
|
| 398 | + return cmb2_options( $a[ 'id' ] )->remove( $a[ 'field_id' ] ); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | // Remove metadata |
| 402 | - return delete_metadata( $a['type'], $a['id'], $a['field_id'], $old ); |
|
| 402 | + return delete_metadata( $a[ 'type' ], $a[ 'id' ], $a[ 'field_id' ], $old ); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | /** |
@@ -870,7 +870,7 @@ discard block |
||
| 870 | 870 | |
| 871 | 871 | foreach ( $conditional_classes as $class => $condition ) { |
| 872 | 872 | if ( $condition ) { |
| 873 | - $classes[] = $class; |
|
| 873 | + $classes[ ] = $class; |
|
| 874 | 874 | } |
| 875 | 875 | } |
| 876 | 876 | |
@@ -879,7 +879,7 @@ discard block |
||
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | if ( $added_classes ) { |
| 882 | - $classes[] = esc_attr( $added_classes ); |
|
| 882 | + $classes[ ] = esc_attr( $added_classes ); |
|
| 883 | 883 | } |
| 884 | 884 | |
| 885 | 885 | /** |
@@ -981,10 +981,10 @@ discard block |
||
| 981 | 981 | public function string( $text_key, $fallback ) { |
| 982 | 982 | // If null, populate with our field strings values. |
| 983 | 983 | if ( null === $this->strings ) { |
| 984 | - $this->strings = (array) $this->args['text']; |
|
| 984 | + $this->strings = (array) $this->args[ 'text' ]; |
|
| 985 | 985 | |
| 986 | - if ( is_callable( $this->args['text_cb'] ) ) { |
|
| 987 | - $strings = call_user_func( $this->args['text_cb'], $this ); |
|
| 986 | + if ( is_callable( $this->args[ 'text_cb' ] ) ) { |
|
| 987 | + $strings = call_user_func( $this->args[ 'text_cb' ], $this ); |
|
| 988 | 988 | |
| 989 | 989 | if ( $strings && is_array( $strings ) ) { |
| 990 | 990 | $this->strings += $strings; |
@@ -1018,10 +1018,10 @@ discard block |
||
| 1018 | 1018 | return $this->field_options; |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | - $this->field_options = (array) $this->args['options']; |
|
| 1021 | + $this->field_options = (array) $this->args[ 'options' ]; |
|
| 1022 | 1022 | |
| 1023 | - if ( is_callable( $this->args['options_cb'] ) ) { |
|
| 1024 | - $options = call_user_func( $this->args['options_cb'], $this ); |
|
| 1023 | + if ( is_callable( $this->args[ 'options_cb' ] ) ) { |
|
| 1024 | + $options = call_user_func( $this->args[ 'options_cb' ], $this ); |
|
| 1025 | 1025 | |
| 1026 | 1026 | if ( $options && is_array( $options ) ) { |
| 1027 | 1027 | $this->field_options += $options; |
@@ -1043,17 +1043,17 @@ discard block |
||
| 1043 | 1043 | * @return mixed Default field value |
| 1044 | 1044 | */ |
| 1045 | 1045 | public function get_default() { |
| 1046 | - if ( null !== $this->args['default'] ) { |
|
| 1047 | - return $this->args['default']; |
|
| 1046 | + if ( null !== $this->args[ 'default' ] ) { |
|
| 1047 | + return $this->args[ 'default' ]; |
|
| 1048 | 1048 | } |
| 1049 | 1049 | |
| 1050 | - $param = is_callable( $this->args['default_cb'] ) ? 'default_cb' : 'default'; |
|
| 1050 | + $param = is_callable( $this->args[ 'default_cb' ] ) ? 'default_cb' : 'default'; |
|
| 1051 | 1051 | $default = $this->get_param_callback_result( $param, false ); |
| 1052 | 1052 | |
| 1053 | 1053 | // Allow a filter override of the default value |
| 1054 | - $this->args['default'] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
| 1054 | + $this->args[ 'default' ] = apply_filters( 'cmb2_default_filter', $default, $this ); |
|
| 1055 | 1055 | |
| 1056 | - return $this->args['default']; |
|
| 1056 | + return $this->args[ 'default' ]; |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | /** |
@@ -1088,17 +1088,17 @@ discard block |
||
| 1088 | 1088 | 'default_cb' => '', |
| 1089 | 1089 | 'select_all_button' => true, |
| 1090 | 1090 | 'multiple' => false, |
| 1091 | - 'repeatable' => isset( $args['type'] ) && 'group' == $args['type'], |
|
| 1091 | + 'repeatable' => isset( $args[ 'type' ] ) && 'group' == $args[ 'type' ], |
|
| 1092 | 1092 | 'inline' => false, |
| 1093 | 1093 | 'on_front' => true, |
| 1094 | 1094 | 'show_names' => true, |
| 1095 | 1095 | 'date_format' => 'm\/d\/Y', |
| 1096 | 1096 | 'time_format' => 'h:i A', |
| 1097 | - 'description' => isset( $args['desc'] ) ? $args['desc'] : '', |
|
| 1098 | - 'preview_size' => 'file' == $args['type'] ? array( 350, 350 ) : array( 50, 50 ), |
|
| 1097 | + 'description' => isset( $args[ 'desc' ] ) ? $args[ 'desc' ] : '', |
|
| 1098 | + 'preview_size' => 'file' == $args[ 'type' ] ? array( 350, 350 ) : array( 50, 50 ), |
|
| 1099 | 1099 | 'render_row_cb' => array( $this, 'render_field_callback' ), |
| 1100 | - 'label_cb' => 'title' != $args['type'] ? array( $this, 'label' ) : '', |
|
| 1101 | - ), $args['id'], $args['type'], $this ); |
|
| 1100 | + 'label_cb' => 'title' != $args[ 'type' ] ? array( $this, 'label' ) : '', |
|
| 1101 | + ), $args[ 'id' ], $args[ 'type' ], $this ); |
|
| 1102 | 1102 | |
| 1103 | 1103 | // Set up blank or default values for empty ones |
| 1104 | 1104 | $args = wp_parse_args( $args, $defaults ); |
@@ -1113,55 +1113,55 @@ discard block |
||
| 1113 | 1113 | $args = apply_filters( 'cmb2_field_arguments_raw', $args, $this ); |
| 1114 | 1114 | |
| 1115 | 1115 | // default param can be passed a callback as well |
| 1116 | - if ( is_callable( $args['default'] ) ) { |
|
| 1117 | - $args['default_cb'] = $args['default']; |
|
| 1118 | - $args['default'] = null; |
|
| 1116 | + if ( is_callable( $args[ 'default' ] ) ) { |
|
| 1117 | + $args[ 'default_cb' ] = $args[ 'default' ]; |
|
| 1118 | + $args[ 'default' ] = null; |
|
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - $args['repeatable'] = $args['repeatable'] && ! $this->repeatable_exception( $args['type'] ); |
|
| 1122 | - $args['inline'] = $args['inline'] || false !== stripos( $args['type'], '_inline' ); |
|
| 1121 | + $args[ 'repeatable' ] = $args[ 'repeatable' ] && ! $this->repeatable_exception( $args[ 'type' ] ); |
|
| 1122 | + $args[ 'inline' ] = $args[ 'inline' ] || false !== stripos( $args[ 'type' ], '_inline' ); |
|
| 1123 | 1123 | |
| 1124 | 1124 | // options param can be passed a callback as well |
| 1125 | - if ( is_callable( $args['options'] ) ) { |
|
| 1126 | - $args['options_cb'] = $args['options']; |
|
| 1127 | - $args['options'] = array(); |
|
| 1125 | + if ( is_callable( $args[ 'options' ] ) ) { |
|
| 1126 | + $args[ 'options_cb' ] = $args[ 'options' ]; |
|
| 1127 | + $args[ 'options' ] = array(); |
|
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | - $args['options'] = 'group' == $args['type'] ? wp_parse_args( $args['options'], array( |
|
| 1130 | + $args[ 'options' ] = 'group' == $args[ 'type' ] ? wp_parse_args( $args[ 'options' ], array( |
|
| 1131 | 1131 | 'add_button' => __( 'Add Group', 'cmb2' ), |
| 1132 | 1132 | 'remove_button' => __( 'Remove Group', 'cmb2' ), |
| 1133 | - ) ) : $args['options']; |
|
| 1133 | + ) ) : $args[ 'options' ]; |
|
| 1134 | 1134 | |
| 1135 | - $args['_id'] = $args['id']; |
|
| 1136 | - $args['_name'] = $args['id']; |
|
| 1135 | + $args[ '_id' ] = $args[ 'id' ]; |
|
| 1136 | + $args[ '_name' ] = $args[ 'id' ]; |
|
| 1137 | 1137 | |
| 1138 | 1138 | if ( $this->group ) { |
| 1139 | 1139 | |
| 1140 | - $args['id'] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args['id']; |
|
| 1141 | - $args['_name'] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args['_name'] . ']'; |
|
| 1140 | + $args[ 'id' ] = $this->group->args( 'id' ) . '_' . $this->group->index . '_' . $args[ 'id' ]; |
|
| 1141 | + $args[ '_name' ] = $this->group->args( 'id' ) . '[' . $this->group->index . '][' . $args[ '_name' ] . ']'; |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | - if ( 'wysiwyg' == $args['type'] ) { |
|
| 1145 | - $args['id'] = strtolower( str_ireplace( '-', '_', $args['id'] ) ); |
|
| 1146 | - $args['options']['textarea_name'] = $args['_name']; |
|
| 1144 | + if ( 'wysiwyg' == $args[ 'type' ] ) { |
|
| 1145 | + $args[ 'id' ] = strtolower( str_ireplace( '-', '_', $args[ 'id' ] ) ); |
|
| 1146 | + $args[ 'options' ][ 'textarea_name' ] = $args[ '_name' ]; |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | $option_types = apply_filters( 'cmb2_all_or_nothing_types', array( 'select', 'radio', 'radio_inline', 'taxonomy_select', 'taxonomy_radio', 'taxonomy_radio_inline' ), $this ); |
| 1150 | 1150 | |
| 1151 | - if ( in_array( $args['type'], $option_types, true ) ) { |
|
| 1151 | + if ( in_array( $args[ 'type' ], $option_types, true ) ) { |
|
| 1152 | 1152 | |
| 1153 | - $args['show_option_none'] = isset( $args['show_option_none'] ) ? $args['show_option_none'] : null; |
|
| 1154 | - $args['show_option_none'] = true === $args['show_option_none'] ? __( 'None', 'cmb2' ) : $args['show_option_none']; |
|
| 1153 | + $args[ 'show_option_none' ] = isset( $args[ 'show_option_none' ] ) ? $args[ 'show_option_none' ] : null; |
|
| 1154 | + $args[ 'show_option_none' ] = true === $args[ 'show_option_none' ] ? __( 'None', 'cmb2' ) : $args[ 'show_option_none' ]; |
|
| 1155 | 1155 | |
| 1156 | - if ( null === $args['show_option_none'] ) { |
|
| 1157 | - $off_by_default = in_array( $args['type'], array( 'select', 'radio', 'radio_inline' ), true ); |
|
| 1158 | - $args['show_option_none'] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
| 1156 | + if ( null === $args[ 'show_option_none' ] ) { |
|
| 1157 | + $off_by_default = in_array( $args[ 'type' ], array( 'select', 'radio', 'radio_inline' ), true ); |
|
| 1158 | + $args[ 'show_option_none' ] = $off_by_default ? false : __( 'None', 'cmb2' ); |
|
| 1159 | 1159 | } |
| 1160 | 1160 | |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | - $args['has_supporting_data'] = in_array( |
|
| 1164 | - $args['type'], |
|
| 1163 | + $args[ 'has_supporting_data' ] = in_array( |
|
| 1164 | + $args[ 'type' ], |
|
| 1165 | 1165 | array( |
| 1166 | 1166 | // CMB2_Sanitize::_save_file_id_value()/CMB2_Sanitize::_get_group_file_value_array() |
| 1167 | 1167 | 'file', |
@@ -1200,10 +1200,10 @@ discard block |
||
| 1200 | 1200 | 'cmb_id' => $this->cmb_id, |
| 1201 | 1201 | ); |
| 1202 | 1202 | |
| 1203 | - if ( isset( $field_args['field_args'] ) ) { |
|
| 1203 | + if ( isset( $field_args[ 'field_args' ] ) ) { |
|
| 1204 | 1204 | $args = wp_parse_args( $field_args, $args ); |
| 1205 | 1205 | } else { |
| 1206 | - $args['field_args'] = wp_parse_args( $field_args, $this->args ); |
|
| 1206 | + $args[ 'field_args' ] = wp_parse_args( $field_args, $this->args ); |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | return new CMB2_Field( $args ); |