Make WordPress Core


Ignore:
Timestamp:
10/08/2018 10:44:05 PM (6 years ago)
Author:
danielbachhuber
Message:

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.

Props timothyblynjacobs.
Fixes #45014.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r43490 r43682  
    17691769        if ( 'attachment' !== $this->post_type && current_user_can( $post_type->cap->publish_posts ) ) {
    17701770            $rels[] = 'https://api.w.org/action-publish';
     1771        }
     1772
     1773        if ( current_user_can( 'unfiltered_html' ) ) {
     1774            $rels[] = 'https://api.w.org/action-unfiltered-html';
    17711775        }
    17721776
     
    21802184        }
    21812185
     2186        $links[] = array(
     2187            'rel'          => 'https://api.w.org/action-unfiltered-html',
     2188            'title'        => __( 'The current user can post unfiltered HTML markup and JavaScript.' ),
     2189            'href'         => $href,
     2190            'targetSchema' => array(
     2191                'type'        => 'object',
     2192                'properties'  => array(
     2193                    'content' => array(
     2194                        'raw' => array(
     2195                            'type' => 'string',
     2196                        ),
     2197                    ),
     2198                ),
     2199            ),
     2200        );
     2201
    21822202        if ( 'post' === $this->post_type ) {
    21832203            $links[] = array(
Note: See TracChangeset for help on using the changeset viewer.