Make WordPress Core


Ignore:
Timestamp:
07/11/2018 06:22:10 AM (8 years ago)
Author:
pento
Message:

REST API: Declare user capabilities using JSON Hyper Schema's "targetSchema".

There are a variety of operations a WordPress user can only perform if they have the correct capabilities. A REST API client should only display UI for one of these operations if the WordPress user can perform the operation.

Rather than requiring REST API clients to calculate whether to display UI based on potentially complicated combinations of user capabilities, targetSchema allows us to expose a single flag to show whether the corresponding UI should be displayed.

This change also includes flags on post objects for the following actions:

  • action-publish: The current user can publish this post.
  • action-sticky: The current user can make this post sticky, and the post type supports sticking.
  • `action-assign-author': The current user can change the author on this post.
  • action-assign-{$taxonomy}: The current user can assign terms from the "$taxonomy" taxonomy to this post.
  • action-create-{$taxonomy}: The current user can create terms int the "$taxonomy" taxonomy.

Props TimothyBlynJacobs, danielbachhuber.
Fixes #44287.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r43087 r43437  
    369369        $data = $this->filter_response_by_context( $data, $context );
    370370
     371        $links = $response->get_links();
     372
    371373        // Wrap the data in a response object.
    372374        $response = rest_ensure_response( $data );
    373 
    374         $response->add_links( $this->prepare_links( $post ) );
     375        $response->add_links( $links );
    375376
    376377        /**
Note: See TracChangeset for help on using the changeset viewer.