|
@@ -49,8 +49,8 @@ discard block |
|
|
block discarded – undo |
|
49
|
49
|
) ); |
|
50
|
50
|
|
|
51
|
51
|
$delete_args = $args; |
|
52
|
|
- $delete_args['object_id']['required'] = true; |
|
53
|
|
- $delete_args['object_type']['required'] = true; |
|
|
52
|
+ $delete_args[ 'object_id' ][ 'required' ] = true; |
|
|
53
|
+ $delete_args[ 'object_type' ][ 'required' ] = true; |
|
54
|
54
|
|
|
55
|
55
|
// Returns specific field data. |
|
56
|
56
|
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<cmb_id>[\w-]+)/fields/(?P<field_id>[\w-]+)', array( |
|
@@ -94,11 +94,11 @@ discard block |
|
|
block discarded – undo |
|
94
|
94
|
|
|
95
|
95
|
$fields = array(); |
|
96
|
96
|
foreach ( $this->rest_box->cmb->prop( 'fields', array() ) as $field ) { |
|
97
|
|
- $field_id = $field['id']; |
|
|
97
|
+ $field_id = $field[ 'id' ]; |
|
98
|
98
|
$rest_field = $this->get_rest_field( $field_id ); |
|
99
|
99
|
|
|
100
|
100
|
if ( ! is_wp_error( $rest_field ) ) { |
|
101
|
|
- $fields[ $field_id ] = $this->server->response_to_data( $rest_field, isset( $this->request['_embed'] ) ); |
|
|
101
|
+ $fields[ $field_id ] = $this->server->response_to_data( $rest_field, isset( $this->request[ '_embed' ] ) ); |
|
102
|
102
|
} else { |
|
103
|
103
|
$fields[ $field_id ] = array( 'error' => $rest_field->get_error_message() ); |
|
104
|
104
|
} |
|
@@ -142,7 +142,7 @@ discard block |
|
|
block discarded – undo |
|
142
|
142
|
public function update_field_value( $request ) { |
|
143
|
143
|
$this->initiate_rest_read_box( $request, 'field_value_update' ); |
|
144
|
144
|
|
|
145
|
|
- if ( ! $this->request['value'] ) { |
|
|
145
|
+ if ( ! $this->request[ 'value' ] ) { |
|
146
|
146
|
return new WP_Error( 'cmb2_rest_update_field_error', __( 'CMB2 Field value cannot be updated without the value parameter specified.', 'cmb2' ), array( 'status' => 400 ) ); |
|
147
|
147
|
} |
|
148
|
148
|
|
|
@@ -178,7 +178,7 @@ discard block |
|
|
block discarded – undo |
|
178
|
178
|
*/ |
|
179
|
179
|
public function modify_field_value( $activity, $field ) { |
|
180
|
180
|
|
|
181
|
|
- if ( ! $this->request['object_id'] || ! $this->request['object_type'] ) { |
|
|
181
|
+ if ( ! $this->request[ 'object_id' ] || ! $this->request[ 'object_type' ] ) { |
|
182
|
182
|
return new WP_Error( 'cmb2_rest_modify_field_value_error', __( 'CMB2 Field value cannot be modified without the object_id and object_type parameters specified.', 'cmb2' ), array( 'status' => 400 ) ); |
|
183
|
183
|
} |
|
184
|
184
|
|
|
@@ -190,13 +190,13 @@ discard block |
|
|
block discarded – undo |
|
190
|
190
|
return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array( 'status' => 403 ) ); |
|
191
|
191
|
} |
|
192
|
192
|
|
|
193
|
|
- $field->args["value_{$activity}"] = (bool) 'deleted' === $activity |
|
|
193
|
+ $field->args[ "value_{$activity}" ] = (bool) 'deleted' === $activity |
|
194
|
194
|
? $field->remove_data() |
|
195
|
|
- : $field->save_field( $this->request['value'] ); |
|
|
195
|
+ : $field->save_field( $this->request[ 'value' ] ); |
|
196
|
196
|
|
|
197
|
197
|
// If options page, save the $activity options |
|
198
|
|
- if ( 'options-page' == $this->request['object_type'] ) { |
|
199
|
|
- $field->args["value_{$activity}"] = cmb2_options( $this->request['object_id'] )->set(); |
|
|
198
|
+ if ( 'options-page' == $this->request[ 'object_type' ] ) { |
|
|
199
|
+ $field->args[ "value_{$activity}" ] = cmb2_options( $this->request[ 'object_id' ] )->set(); |
|
200
|
200
|
} |
|
201
|
201
|
|
|
202
|
202
|
$field_data = $this->get_rest_field( $field ); |
|
@@ -265,13 +265,13 @@ discard block |
|
|
block discarded – undo |
|
265
|
265
|
$value = $field->options(); |
|
266
|
266
|
} elseif ( in_array( $key, CMB2_Field::$callable_fields, true ) ) { |
|
267
|
267
|
|
|
268
|
|
- if ( isset( $this->request['_rendered'] ) ) { |
|
|
268
|
+ if ( isset( $this->request[ '_rendered' ] ) ) { |
|
269
|
269
|
$value = $key === 'render_row_cb' ? $rendered : $field->get_param_callback_result( $key ); |
|
270
|
270
|
} elseif ( is_array( $value ) ) { |
|
271
|
271
|
// We need to rewrite callbacks as string as they will cause |
|
272
|
272
|
// JSON recursion errors. |
|
273
|
|
- $class = is_string( $value[0] ) ? $value[0] : get_class( $value[0] ); |
|
274
|
|
- $value = $class . '::' . $value[1]; |
|
|
273
|
+ $class = is_string( $value[ 0 ] ) ? $value[ 0 ] : get_class( $value[ 0 ] ); |
|
|
274
|
+ $value = $class . '::' . $value[ 1 ]; |
|
275
|
275
|
} |
|
276
|
276
|
} |
|
277
|
277
|
|
|
@@ -284,8 +284,8 @@ discard block |
|
|
block discarded – undo |
|
284
|
284
|
} |
|
285
|
285
|
} |
|
286
|
286
|
|
|
287
|
|
- if ( $this->request['object_id'] && $this->request['object_type'] ) { |
|
288
|
|
- $field_data['value'] = $field->get_data(); |
|
|
287
|
+ if ( $this->request[ 'object_id' ] && $this->request[ 'object_type' ] ) { |
|
|
288
|
+ $field_data[ 'value' ] = $field->get_data(); |
|
289
|
289
|
} |
|
290
|
290
|
|
|
291
|
291
|
return $field_data; |
|
@@ -318,7 +318,7 @@ discard block |
|
|
block discarded – undo |
|
318
|
318
|
|
|
319
|
319
|
// Don't embed boxes when looking at boxes route. |
|
320
|
320
|
if ( '/cmb2/v1/boxes' !== CMB2_REST_Controller::get_intial_route() ) { |
|
321
|
|
- $links['up']['embeddable'] = true; |
|
|
321
|
+ $links[ 'up' ][ 'embeddable' ] = true; |
|
322
|
322
|
} |
|
323
|
323
|
|
|
324
|
324
|
return $links; |