Make WordPress Core


Ignore:
Timestamp:
12/11/2018 04:12:56 AM (6 years ago)
Author:
jorbin
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.

Merges [43682] to trunk.

Props timothyblynjacobs.

Fixes #45014.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r43584 r43974  
    17801780        if ( 'attachment' !== $this->post_type && current_user_can( $post_type->cap->publish_posts ) ) {
    17811781            $rels[] = 'https://api.w.org/action-publish';
     1782        }
     1783
     1784        if ( current_user_can( 'unfiltered_html' ) ) {
     1785            $rels[] = 'https://api.w.org/action-unfiltered-html';
    17821786        }
    17831787
     
    21912195        }
    21922196
     2197        $links[] = array(
     2198            'rel'          => 'https://api.w.org/action-unfiltered-html',
     2199            'title'        => __( 'The current user can post unfiltered HTML markup and JavaScript.' ),
     2200            'href'         => $href,
     2201            'targetSchema' => array(
     2202                'type'       => 'object',
     2203                'properties' => array(
     2204                    'content' => array(
     2205                        'raw' => array(
     2206                            'type' => 'string',
     2207                        ),
     2208                    ),
     2209                ),
     2210            ),
     2211        );
     2212
    21932213        if ( 'post' === $this->post_type ) {
    21942214            $links[] = array(
Note: See TracChangeset for help on using the changeset viewer.