From 380cc5d7d6a6f371cf7b5fd493c46f0b87921215 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Fri, 16 Dec 2016 05:46:35 +0000 Subject: [PATCH] REST API: Do not include the `password` argument when getting media items Currently, `attachment` is the only post type exposed via the REST API that does not support password protection, but it's possible for other post types to remove password support. Props jnylen0. Merges [39595] to the 4.7 branch. Fixes #38977. Built from https://develop.svn.wordpress.org/branches/4.7@39610 git-svn-id: http://core.svn.wordpress.org/branches/4.7@39550 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-posts-controller.php | 18 +++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 872a6607cb..40955b3c1d 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -77,18 +77,22 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { 'schema' => array( $this, 'get_public_item_schema' ), ) ); + $schema = $this->get_item_schema(); + $get_item_args = array( + 'context' => $this->get_context_param( array( 'default' => 'view' ) ), + ); + if ( isset( $schema['properties']['password'] ) ) { + $get_item_args['password'] = array( + 'description' => __( 'The password for the post if it is password protected.' ), + 'type' => 'string', + ); + } register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P[\d]+)', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), 'permission_callback' => array( $this, 'get_item_permissions_check' ), - 'args' => array( - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), - 'password' => array( - 'description' => __( 'The password for the post if it is password protected.' ), - 'type' => 'string', - ), - ), + 'args' => $get_item_args, ), array( 'methods' => WP_REST_Server::EDITABLE, diff --git a/wp-includes/version.php b/wp-includes/version.php index 44fd014bae..b79490b669 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7.1-alpha-39609'; +$wp_version = '4.7.1-alpha-39610'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.