Skip to content
This repository was archived by the owner on Sep 24, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/endpoints/class-wp-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ abstract class WP_REST_Controller {
*/
protected $rest_base;

/**
* The resource's singular label
*
* @var string
*/

/**
* Register the routes for the objects of the controller.
*/
Expand Down
18 changes: 8 additions & 10 deletions lib/endpoints/class-wp-rest-post-statuses-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
public function __construct() {
$this->namespace = 'wp/v2';
$this->rest_base = 'statuses';
$this->singular_label = __( 'Status' );
$this->plural_label = __( 'Statuses' );
}

/**
Expand Down Expand Up @@ -67,7 +65,7 @@ public function get_items( $request ) {
public function get_item( $request ) {
$obj = get_post_status_object( $request['status'] );
if ( empty( $obj ) ) {
return new WP_Error( 'rest_status_invalid', sprintf( __( 'Invalid %s.' ), $this->singular_label ), array( 'status' => 404 ) );
return new WP_Error( 'rest_status_invalid', __( 'Invalid resource.' ), array( 'status' => 404 ) );
}
$data = $this->prepare_item_for_response( $obj, $request );
return rest_ensure_response( $data );
Expand All @@ -82,7 +80,7 @@ public function get_item( $request ) {
*/
public function prepare_item_for_response( $status, $request ) {
if ( ( false === $status->public && ! is_user_logged_in() ) || ( true === $status->internal && is_user_logged_in() ) ) {
return new WP_Error( 'rest_cannot_read_status', sprintf( __( 'Cannot view %s.' ), $this->singular_label ), array( 'status' => rest_authorization_required_code() ) );
return new WP_Error( 'rest_cannot_read_status', __( 'Cannot view resource.' ), array( 'status' => rest_authorization_required_code() ) );
}

$data = array(
Expand Down Expand Up @@ -133,27 +131,27 @@ public function get_item_schema() {
'type' => 'object',
'properties' => array(
'name' => array(
'description' => sprintf( __( 'The title for the %s.' ), $this->singular_label ),
'description' => __( 'The title for the resource.' ),
'type' => 'string',
'context' => array( 'view' ),
),
'private' => array(
'description' => sprintf( __( 'Whether posts with this %s should be private.' ), $this->singular_label ),
'description' => __( 'Whether posts with this resource should be private.' ),
'type' => 'boolean',
'context' => array( 'view' ),
),
'protected' => array(
'description' => sprintf( __( 'Whether posts with this %s should be protected.' ), $this->singular_label ),
'description' => __( 'Whether posts with this resource should be protected.' ),
'type' => 'boolean',
'context' => array( 'view' ),
),
'public' => array(
'description' => sprintf( __( 'Whether posts of this %s should be shown in the front end of the site.' ), $this->singular_label ),
'description' => __( 'Whether posts of this resource should be shown in the front end of the site.' ),
'type' => 'boolean',
'context' => array( 'view' ),
),
'queryable' => array(
'description' => sprintf( __( 'Whether posts with this %s should be publicly-queryable.' ), $this->singular_label ),
'description' => __( 'Whether posts with this resource should be publicly-queryable.' ),
'type' => 'boolean',
'context' => array( 'view' ),
),
Expand All @@ -163,7 +161,7 @@ public function get_item_schema() {
'context' => array( 'view' ),
),
'slug' => array(
'description' => sprintf( __( 'An alphanumeric identifier for the %s.' ), $this->singular_label ),
'description' => __( 'An alphanumeric identifier for the resource.' ),
'type' => 'string',
'context' => array( 'view' ),
),
Expand Down
18 changes: 8 additions & 10 deletions lib/endpoints/class-wp-rest-post-types-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
public function __construct() {
$this->namespace = 'wp/v2';
$this->rest_base = 'types';
$this->singular_label = __( 'Type' );
$this->plural_label = __( 'Types' );
}

/**
Expand Down Expand Up @@ -62,13 +60,13 @@ public function get_items( $request ) {
public function get_item( $request ) {
$obj = get_post_type_object( $request['type'] );
if ( empty( $obj ) ) {
return new WP_Error( 'rest_type_invalid', sprintf( __( 'Invalid %s.' ), $this->singular_label ), array( 'status' => 404 ) );
return new WP_Error( 'rest_type_invalid', __( 'Invalid resource.' ), array( 'status' => 404 ) );
}
if ( empty( $obj->show_in_rest ) ) {
return new WP_Error( 'rest_cannot_read_type', sprintf( __( 'Cannot view %s.' ), $this->singular_label ), array( 'status' => rest_authorization_required_code() ) );
return new WP_Error( 'rest_cannot_read_type', __( 'Cannot view resource.' ), array( 'status' => rest_authorization_required_code() ) );
}
if ( 'edit' === $request['context'] && ! current_user_can( $obj->cap->edit_posts ) ) {
return new WP_Error( 'rest_forbidden_context', sprintf( __( 'Sorry, you are not allowed to manage this %s.' ), $this->singular_label ), array( 'status' => rest_authorization_required_code() ) );
return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to manage this resource.' ), array( 'status' => rest_authorization_required_code() ) );
}
$data = $this->prepare_item_for_response( $obj, $request );
return rest_ensure_response( $data );
Expand Down Expand Up @@ -130,27 +128,27 @@ public function get_item_schema() {
'type' => 'object',
'properties' => array(
'description' => array(
'description' => sprintf( __( 'A human-readable description of the %s.' ), $this->singular_label ),
'description' => __( 'A human-readable description of the resource.' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'hierarchical' => array(
'description' => sprintf( __( 'Whether or not the %s should have children.' ), $this->singular_label ),
'description' => __( 'Whether or not the resource should have children.' ),
'type' => 'boolean',
'context' => array( 'view', 'edit' ),
),
'labels' => array(
'description' => sprintf( __( 'Human-readable labels for the %s for various contexts.' ), $this->singular_label ),
'description' => __( 'Human-readable labels for the resource for various contexts.' ),
'type' => 'object',
'context' => array( 'edit' ),
),
'name' => array(
'description' => sprintf( __( 'The title for the %s.' ), $this->singular_label ),
'description' => __( 'The title for the resource.' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'slug' => array(
'description' => sprintf( __( 'An alphanumeric identifier for the %s.' ), $this->singular_label ),
'description' => __( 'An alphanumeric identifier for the resource.' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
Expand Down
20 changes: 9 additions & 11 deletions lib/endpoints/class-wp-rest-taxonomies-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
public function __construct() {
$this->namespace = 'wp/v2';
$this->rest_base = 'taxonomies';
$this->singular_label = __( 'Taxonomy' );
$this->plural_label = __( 'Taxonomies' );
}

/**
Expand Down Expand Up @@ -75,7 +73,7 @@ public function get_item_permissions_check( $request ) {
return false;
}
if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->manage_terms ) ) {
return new WP_Error( 'rest_forbidden_context', sprintf( __( 'Sorry, you are not allowed to manage this %s.' ), $this->singular_label ), array( 'status' => rest_authorization_required_code() ) );
return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to manage this resource.' ), array( 'status' => rest_authorization_required_code() ) );
}
}

Expand All @@ -91,7 +89,7 @@ public function get_item_permissions_check( $request ) {
public function get_item( $request ) {
$tax_obj = get_taxonomy( $request['taxonomy'] );
if ( empty( $tax_obj ) ) {
return new WP_Error( 'rest_taxonomy_invalid', sprintf( __( 'Invalid %s.' ), $this->singular_label ), array( 'status' => 404 ) );
return new WP_Error( 'rest_taxonomy_invalid', __( 'Invalid resource.' ), array( 'status' => 404 ) );
}
$data = $this->prepare_item_for_response( $tax_obj, $request );
return rest_ensure_response( $data );
Expand Down Expand Up @@ -157,27 +155,27 @@ public function get_item_schema() {
'type' => 'object',
'properties' => array(
'description' => array(
'description' => sprintf( __( 'A human-readable description of the %s.' ), $this->singular_label ),
'description' => __( 'A human-readable description of the resource.' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'hierarchical' => array(
'description' => sprintf( __( 'Whether or not the %s should have children.' ), $this->singular_label ),
'description' => __( 'Whether or not the resource should have children.' ),
'type' => 'boolean',
'context' => array( 'view', 'edit' ),
),
'labels' => array(
'description' => sprintf( __( 'Human-readable labels for the %s for various contexts.' ), $this->singular_label ),
'description' => __( 'Human-readable labels for the resource for various contexts.' ),
'type' => 'object',
'context' => array( 'edit' ),
),
'name' => array(
'description' => sprintf( __( 'The title for the %s.' ), $this->singular_label ),
'description' => __( 'The title for the resource.' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'slug' => array(
'description' => sprintf( __( 'An alphanumeric identifier for the %s.' ), $this->singular_label ),
'description' => __( 'An alphanumeric identifier for the resource.' ),
'type' => 'string',
'context' => array( 'view', 'edit' ),
),
Expand All @@ -187,7 +185,7 @@ public function get_item_schema() {
'context' => array( 'edit' ),
),
'types' => array(
'description' => sprintf( __( 'Types associated with %s.' ), $this->singular_label ),
'description' => __( 'Types associated with resource.' ),
'type' => 'array',
'context' => array( 'view', 'edit' ),
),
Expand All @@ -205,7 +203,7 @@ public function get_collection_params() {
$new_params = array();
$new_params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
$new_params['type'] = array(
'description' => sprintf( __( 'Limit results to %s associated with a specific post type.' ), $this->plural_label ),
'description' => __( 'Limit results to resources associated with a specific post type.' ),
'type' => 'string',
);
return $new_params;
Expand Down
Loading