Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
10 changes: 5 additions & 5 deletions 10 lib/endpoints/class-wp-rest-comments-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
*/
public function register_routes() {

$query_params = $this->get_collection_params();
register_rest_route( 'wp/v2', '/comments', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $query_params,
'args' => $this->get_collection_params(),
),
array(
'methods' => WP_REST_Server::CREATABLE,
Expand All @@ -34,8 +33,10 @@ public function register_routes() {
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'args' => array(
'context' => array(
'default' => 'view',
'context' => array(
'default' => 'view',
'type' => 'string',
'enum' => array( 'embed', 'view', 'edit' ),
),
),
),
Expand Down Expand Up @@ -904,7 +905,6 @@ public function get_collection_params() {
$query_params = parent::get_collection_params();

$query_params['context']['default'] = 'view';
$query_params['context']['enum'] = array( 'embed', 'view', 'edit' );

$query_params['author_email'] = array(
'default' => null,
Expand Down
15 changes: 14 additions & 1 deletion 15 lib/endpoints/class-wp-rest-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function get_public_item_schema() {
* @return array
*/
public function get_collection_params() {
return array(
$params = array(
'context' => array(
'description' => 'Scope under which the request is made; determines fields present in response.',
'type' => 'string',
Expand All @@ -241,6 +241,19 @@ public function get_collection_params() {
'sanitize_callback' => 'sanitize_text_field',
),
);
$schema = $this->get_item_schema();
$contexts = array();
if ( ! empty( $schema['properties'] ) ) {
foreach ( $schema['properties'] as $key => $attributes ) {
if ( ! empty( $attributes['context'] ) ) {
$contexts = array_merge( $contexts, $attributes['context'] );
}
}
}
if ( ! empty( $contexts ) ) {
$params['context']['enum'] = array_unique( $contexts );
}
return $params;
}

/**
Expand Down
25 changes: 18 additions & 7 deletions 25 lib/endpoints/class-wp-rest-meta-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public function register_routes() {
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => array(
'context' => array(
'default' => 'view',
),
),
'args' => $this->get_collection_params(),
),
array(
'methods' => WP_REST_Server::CREATABLE,
Expand All @@ -61,8 +57,10 @@ public function register_routes() {
'callback' => array( $this, 'get_item' ),
'permission_callback' => array( $this, 'get_item_permissions_check' ),
'args' => array(
'context' => array(
'default' => 'view',
'context' => array(
'default' => 'edit',
'type' => 'string',
'enum' => array( 'edit' ),
),
),
),
Expand Down Expand Up @@ -126,6 +124,19 @@ public function get_item_schema() {
return $schema;
}

/**
* Get the query params for collections
*
* @return array
*/
public function get_collection_params() {
$params = parent::get_collection_params();
$new_params = array();
$new_params['context'] = $params['context'];
$new_params['context']['default'] = 'edit';
return $new_params;
}

/**
* Get the meta ID column for the relevant table.
*
Expand Down
21 changes: 21 additions & 0 deletions 21 lib/endpoints/class-wp-rest-post-statuses-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public function register_routes() {
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
Expand All @@ -19,6 +20,13 @@ public function register_routes() {
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_item' ),
'args' => array(
'context' => array(
'default' => 'view',
'type' => 'string',
'enum' => array( 'view' ),
),
),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
Expand Down Expand Up @@ -160,4 +168,17 @@ public function get_item_schema() {
return $this->add_additional_fields_schema( $schema );
}

/**
* Get the query params for collections
*
* @return array
*/
public function get_collection_params() {
$params = parent::get_collection_params();
$new_params = array();
$new_params['context'] = $params['context'];
$new_params['context']['default'] = 'view';
return $new_params;
}

}
19 changes: 14 additions & 5 deletions 19 lib/endpoints/class-wp-rest-post-types-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ public function register_routes() {
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'args' => array(
'post_type' => array(
'sanitize_callback' => 'sanitize_key',
),
),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
Expand Down Expand Up @@ -138,4 +134,17 @@ public function get_item_schema() {
return $this->add_additional_fields_schema( $schema );
}

/**
* Get the query params for collections
*
* @return array
*/
public function get_collection_params() {
$params = parent::get_collection_params();
$new_params = array();
$new_params['context'] = $params['context'];
$new_params['context']['default'] = 'view';
return $new_params;
}

}
7 changes: 3 additions & 4 deletions 7 lib/endpoints/class-wp-rest-posts-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ public function register_routes() {

$base = $this->get_post_type_base( $this->post_type );

$posts_args = $this->get_collection_params();

register_rest_route( 'wp/v2', '/' . $base, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $posts_args,
'args' => $this->get_collection_params(),
),
array(
'methods' => WP_REST_Server::CREATABLE,
Expand All @@ -41,6 +39,8 @@ public function register_routes() {
'args' => array(
'context' => array(
'default' => 'view',
'type' => 'string',
'enum' => array( 'embed', 'view', 'edit' ),
),
),
),
Expand Down Expand Up @@ -1556,7 +1556,6 @@ public function get_collection_params() {
$params = parent::get_collection_params();

$params['context']['default'] = 'view';
$params['context']['enum'] = array( 'embed', 'view', 'edit' );

if ( post_type_supports( $this->post_type, 'author' ) ) {
$params['author'] = array(
Expand Down
4 changes: 1 addition & 3 deletions 4 lib/endpoints/class-wp-rest-posts-terms-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ public function register_routes() {
$base = $this->posts_controller->get_post_type_base( $this->post_type );
$tax_base = $this->terms_controller->get_taxonomy_base( $this->taxonomy );

$query_params = $this->get_collection_params();
register_rest_route( 'wp/v2', sprintf( '/%s/(?P<post_id>[\d]+)/%s', $base, $tax_base ), array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $query_params,
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
Expand Down Expand Up @@ -290,7 +289,6 @@ public function get_collection_params() {
$query_params = array();

$query_params['context']['default'] = 'view';
$query_params['context']['enum'] = array( 'view' );

$query_params['order'] = array(
'description' => 'Order sort attribute ascending or descending.',
Expand Down
19 changes: 14 additions & 5 deletions 19 lib/endpoints/class-wp-rest-revisions-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ public function register_routes() {
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => array(
'context' => array(
'default' => 'view',
),
),
'args' => $this->get_collection_params(),
),

'schema' => array( $this, 'get_public_item_schema' ),
Expand Down Expand Up @@ -358,4 +354,17 @@ public function get_item_schema() {
return $this->add_additional_fields_schema( $schema );
}

/**
* Get the query params for collections
*
* @return array
*/
public function get_collection_params() {
$params = parent::get_collection_params();
$new_params = array();
$new_params['context'] = $params['context'];
$new_params['context']['default'] = 'view';
return $new_params;
}

}
23 changes: 18 additions & 5 deletions 23 lib/endpoints/class-wp-rest-taxonomies-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ public function register_routes() {
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'args' => array(
'post_type' => array(
'sanitize_callback' => 'sanitize_key',
),
),
'args' => $this->get_collection_params(),
),
'schema' => array( $this, 'get_public_item_schema' ),
) );
Expand Down Expand Up @@ -184,4 +180,21 @@ public function get_item_schema() {
return $this->add_additional_fields_schema( $schema );
}

/**
* Get the query params for collections
*
* @return array
*/
public function get_collection_params() {
$params = parent::get_collection_params();
$new_params = array();
$new_params['context'] = $params['context'];
$new_params['context']['default'] = 'view';
$new_params['post_type'] = array(
'description' => 'Limit results to taxonomies associated with a specific post type.',
'type' => 'string',
);
return $new_params;
}

}
4 changes: 1 addition & 3 deletions 4 lib/endpoints/class-wp-rest-terms-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ public function __construct( $taxonomy ) {
public function register_routes() {

$base = $this->get_taxonomy_base( $this->taxonomy );
$query_params = $this->get_collection_params();
register_rest_route( 'wp/v2', '/' . $base, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'permission_callback' => array( $this, 'get_items_permissions_check' ),
'args' => $query_params,
'args' => $this->get_collection_params(),
),
array(
'methods' => WP_REST_Server::CREATABLE,
Expand Down Expand Up @@ -586,7 +585,6 @@ public function get_collection_params() {
$query_params = parent::get_collection_params();

$query_params['context']['default'] = 'view';
$query_params['context']['enum'] = array( 'embed', 'view' );

$query_params['order'] = array(
'description' => 'Order sort attribute ascending or descending.',
Expand Down
4 changes: 1 addition & 3 deletions 4 lib/endpoints/class-wp-rest-users-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
*/
public function register_routes() {

$query_params = $this->get_collection_params();
register_rest_route( 'wp/v2', '/users', array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_items' ),
'args' => $query_params,
'args' => $this->get_collection_params(),
),
array(
'methods' => WP_REST_Server::CREATABLE,
Expand Down Expand Up @@ -772,7 +771,6 @@ public function get_collection_params() {
$query_params = parent::get_collection_params();

$params['context']['default'] = 'view';
$params['context']['enum'] = array( 'embed', 'view', 'edit' );

$query_params['order'] = array(
'default' => 'asc',
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.