Skip to content

Commit

Permalink
More clarity in error message codes, and fix leftover write/edit typo
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Sep 8, 2016
1 parent 9538858 commit 9f46758
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions includes/CMB2_REST_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ protected function initiate_rest_read_box( $request, $request_type ) {
$this->initiate_rest_box( $request, $request_type );

if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_read ) {
$this->rest_box = new WP_Error( 'cmb2_rest_error', __( 'This box does not have read permissions.', 'cmb2' ), array( 'status' => 403 ) );
$this->rest_box = new WP_Error( 'cmb2_rest_no_read_error', __( 'This box does not have read permissions.', 'cmb2' ), array( 'status' => 403 ) );
}
}

Expand All @@ -299,11 +299,11 @@ protected function initiate_rest_read_box( $request, $request_type ) {
*
* @return void
*/
protected function initiate_rest_write_box( $request, $request_type ) {
protected function initiate_rest_edit_box( $request, $request_type ) {
$this->initiate_rest_box( $request, $request_type );

if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_write ) {
$this->rest_box = new WP_Error( 'cmb2_rest_error', __( 'This box does not have write permissions.', 'cmb2' ), array( 'status' => 403 ) );
if ( ! is_wp_error( $this->rest_box ) && ! $this->rest_box->rest_edit ) {
$this->rest_box = new WP_Error( 'cmb2_rest_no_write_error', __( 'This box does not have write permissions.', 'cmb2' ), array( 'status' => 403 ) );
}
}

Expand Down
6 changes: 3 additions & 3 deletions includes/CMB2_REST_Controller_Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function modify_field_value( $activity, $field ) {
}

if ( ! $field ) {
return new WP_Error( 'cmb2_rest_error', __( 'No field found by that id.', 'cmb2' ), array( 'status' => 403 ) );
return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array( 'status' => 403 ) );
}

$field->args["value_{$activity}"] = (bool) 'deleted' === $activity
Expand Down Expand Up @@ -195,10 +195,10 @@ public function modify_field_value( $activity, $field ) {
* @return array|WP_Error
*/
public function get_rest_field( $field_id ) {
$field = $field_id instanceof CMB2_Field ? $field_id : $this->rest_box->field_can_read( $field_id, true );
$field = $this->rest_box->field_can_read( $field_id, true );

if ( ! $field ) {
return new WP_Error( 'cmb2_rest_error', __( 'No field found by that id.', 'cmb2' ), array( 'status' => 403 ) );
return new WP_Error( 'cmb2_rest_no_field_by_id_error', __( 'No field found by that id.', 'cmb2' ), array( 'status' => 403 ) );
}

$field_data = $this->prepare_field_data( $field );
Expand Down

0 comments on commit 9f46758

Please sign in to comment.