From 21fdb9322d177276926764de4a1a10ed2b403d44 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 17 May 2018 06:44:48 -0700 Subject: [PATCH] Remove post type capabilities from the user object It's no longer necessary to expose these through the REST API --- lib/rest-api.php | 60 ------------------------------------------------ 1 file changed, 60 deletions(-) diff --git a/lib/rest-api.php b/lib/rest-api.php index a9a12fa49fb340..621a8bd9fc87fc 100644 --- a/lib/rest-api.php +++ b/lib/rest-api.php @@ -21,66 +21,6 @@ function gutenberg_register_rest_routes() { } add_action( 'rest_api_init', 'gutenberg_register_rest_routes' ); -/** - * Includes the value for the custom field `post_type_capabities` inside the REST API response of user. - * - * TODO: This is a temporary solution. Next step would be to edit the WP_REST_Users_Controller, - * once merged into Core. - * - * @since ? - * - * @param array $user An array containing user properties. - * @param string $name The name of the custom field. - * @param WP_REST_Request $request Full details about the REST API request. - * @return object The Post Type capabilities. - */ -function gutenberg_get_post_type_capabilities( $user, $name, $request ) { - $post_type = $request->get_param( 'post_type' ); - $value = new stdClass; - - if ( ! empty( $user['id'] ) && $post_type && post_type_exists( $post_type ) ) { - // The Post Type object contains the Post Type's specific caps. - $post_type_object = get_post_type_object( $post_type ); - - // Loop in the Post Type's caps to validate the User's caps for it. - foreach ( $post_type_object->cap as $post_cap => $post_type_cap ) { - // Ignore caps requiring a post ID. - if ( in_array( $post_cap, array( 'edit_post', 'read_post', 'delete_post' ) ) ) { - continue; - } - - // Set the User's post type capability. - $value->{$post_cap} = user_can( $user['id'], $post_type_cap ); - } - } - - return $value; -} - -/** - * Adds the custom field `post_type_capabities` to the REST API response of user. - * - * TODO: This is a temporary solution. Next step would be to edit the WP_REST_Users_Controller, - * once merged into Core. - * - * @since ? - */ -function gutenberg_register_rest_api_post_type_capabilities() { - register_rest_field( 'user', - 'post_type_capabilities', - array( - 'get_callback' => 'gutenberg_get_post_type_capabilities', - 'schema' => array( - 'description' => __( 'Post Type capabilities for the user.', 'gutenberg' ), - 'type' => 'object', - 'context' => array( 'edit' ), - 'readonly' => true, - ), - ) - ); -} -add_action( 'rest_api_init', 'gutenberg_register_rest_api_post_type_capabilities' ); - /** * Make sure oEmbed REST Requests apply the WP Embed security mechanism for WordPress embeds. *