Ticket #48885: patch.4.diff
File patch.4.diff, 3.4 KB (added by , 5 years ago) |
---|
-
src/wp-includes/option.php
1908 1908 array( 1909 1909 'show_in_rest' => array( 1910 1910 'name' => 'title', 1911 'public' => true, 1911 1912 ), 1912 1913 'type' => 'string', 1913 1914 'description' => __( 'Site title.' ), … … 1920 1921 array( 1921 1922 'show_in_rest' => array( 1922 1923 'name' => 'description', 1924 'public' => true, 1923 1925 ), 1924 1926 'type' => 'string', 1925 1927 'description' => __( 'Site tagline.' ), -
src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
1 1 <?php 2 /**2 /** 3 3 * REST API: WP_REST_Settings_Controller class 4 4 * 5 5 * @package WordPress … … 55 55 ) 56 56 ); 57 57 58 register_rest_route( 59 $this->namespace, 60 '/' . $this->rest_base . '/public', 61 array( 62 array( 63 'methods' => WP_REST_Server::READABLE, 64 'callback' => array( $this, 'get_public_item' ), 65 'args' => array(), 66 'permission_callback' => array( $this, 'get_public_item_permissions_check' ), 67 ), 68 array( 69 'methods' => WP_REST_Server::EDITABLE, 70 'callback' => array( $this, 'update_public_item' ), 71 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), 72 'permission_callback' => array( $this, 'get_item_permissions_check' ), 73 ), 74 'schema' => array( $this, 'get_public_item_schema' ), 75 ) 76 ); 77 58 78 } 59 79 60 80 /** … … 70 90 } 71 91 72 92 /** 93 * Checks if a given request has access to read and manage settings. 94 * 95 * @since ? 96 * 97 * @param WP_REST_Request $request Full details about the request. 98 * @return bool True if the request has read access for the item, otherwise false. 99 */ 100 public function get_public_item_permissions_check( $request ) { 101 return true; 102 return current_user_can( 'edit_posts' ); 103 } 104 105 /** 73 106 * Retrieves the settings. 74 107 * 75 108 * @since 4.7.0 … … 262 295 $rest_options[ $rest_args['name'] ] = $rest_args; 263 296 } 264 297 265 return $rest_options;298 return apply_filters( 'get_registered_options', $rest_options ); 266 299 } 267 300 268 301 /** … … 345 378 346 379 return $schema; 347 380 } 381 382 public function filter_public_registered_options( $rest_options ){ 383 $filtered_rest_options = array(); 384 foreach ( $rest_options as $name => $args ) { 385 if ( empty( $args['public'] ) ) { 386 continue; 387 } 388 389 $filtered_rest_options[ $args['name'] ] = $args; 390 } 391 return $filtered_rest_options; 392 } 393 394 public function get_public_item( $request ) { 395 add_filter( 'get_registered_options', array( $this, 'filter_public_registered_options' ) ); 396 return $this->get_item( $request ); 397 remove_filter( 'get_registered_options', array( $this, 'filter_public_registered_options' ) ); 398 } 399 400 public function update_public_item( $request ) { 401 add_filter( 'get_registered_options', array( $this, 'filter_public_registered_options' ) ); 402 return $this->update_item( $request ); 403 remove_filter( 'get_registered_options', array( $this, 'filter_public_registered_options' ) ); 404 } 405 348 406 }