From e945a217587fa18b198e2ffec2ac846201d11256 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Tue, 11 Dec 2018 04:13:23 +0000 Subject: [PATCH] REST API: Declare unfiltered_html capability in links. Because user capabilities can be modified at runtime, the REST API needs to expose them in some evaluated but declarative manner for clients to interpret. JSON Hyper Schema targetSchema provides an appropriate paradigm for doing so. Merges [43682] to trunk. Props timothyblynjacobs. Fixes #45014. Built from https://develop.svn.wordpress.org/trunk@43974 git-svn-id: http://core.svn.wordpress.org/trunk@43806 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-posts-controller.php | 20 +++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) 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 472115e121..bff977e40c 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 @@ -1781,6 +1781,10 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $rels[] = 'https://api.w.org/action-publish'; } + if ( current_user_can( 'unfiltered_html' ) ) { + $rels[] = 'https://api.w.org/action-unfiltered-html'; + } + if ( 'post' === $post_type->name ) { if ( current_user_can( $post_type->cap->edit_others_posts ) && current_user_can( $post_type->cap->publish_posts ) ) { $rels[] = 'https://api.w.org/action-sticky'; @@ -2190,6 +2194,22 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { ); } + $links[] = array( + 'rel' => 'https://api.w.org/action-unfiltered-html', + 'title' => __( 'The current user can post unfiltered HTML markup and JavaScript.' ), + 'href' => $href, + 'targetSchema' => array( + 'type' => 'object', + 'properties' => array( + 'content' => array( + 'raw' => array( + 'type' => 'string', + ), + ), + ), + ), + ); + if ( 'post' === $this->post_type ) { $links[] = array( 'rel' => 'https://api.w.org/action-sticky', diff --git a/wp-includes/version.php b/wp-includes/version.php index 807054b506..64cad9ee52 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-43973'; +$wp_version = '5.1-alpha-43974'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.