Docs: Document the globals used in some REST API methods.

See #53399.
Built from https://develop.svn.wordpress.org/trunk@51278


git-svn-id: http://core.svn.wordpress.org/trunk@50887 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-06-30 12:34:56 +00:00
parent ffafbefc36
commit d72eb14abf
6 changed files with 40 additions and 16 deletions

View File

@ -118,8 +118,8 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
* @global array $wp_rest_additional_fields Holds registered fields, organized
* by object type.
*
* @param string|array $object_type Object(s) the field is being registered
* to, "post"|"term"|"comment" etc.
* @param string|array $object_type Object(s) the field is being registered to,
* "post"|"term"|"comment" etc.
* @param string $attribute The attribute name.
* @param array $args {
* Optional. An array of arguments used to handle the registered field.
@ -135,6 +135,8 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
* }
*/
function register_rest_field( $object_type, $attribute, $args = array() ) {
global $wp_rest_additional_fields;
$defaults = array(
'get_callback' => null,
'update_callback' => null,
@ -143,8 +145,6 @@ function register_rest_field( $object_type, $attribute, $args = array() ) {
$args = wp_parse_args( $args, $defaults );
global $wp_rest_additional_fields;
$object_types = (array) $object_type;
foreach ( $object_types as $object_type ) {

View File

@ -103,6 +103,8 @@ class WP_REST_Block_Renderer_Controller extends WP_REST_Controller {
*
* @since 5.0.0
*
* @global WP_Post $post Global post object.
*
* @param WP_REST_Request $request Request.
* @return true|WP_Error True if the request has read access, WP_Error object otherwise.
*/
@ -111,7 +113,7 @@ class WP_REST_Block_Renderer_Controller extends WP_REST_Controller {
$post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0;
if ( 0 < $post_id ) {
if ( $post_id > 0 ) {
$post = get_post( $post_id );
if ( ! $post || ! current_user_can( 'edit_post', $post->ID ) ) {
@ -143,6 +145,8 @@ class WP_REST_Block_Renderer_Controller extends WP_REST_Controller {
*
* @since 5.0.0
*
* @global WP_Post $post Global post object.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
@ -151,7 +155,7 @@ class WP_REST_Block_Renderer_Controller extends WP_REST_Controller {
$post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0;
if ( 0 < $post_id ) {
if ( $post_id > 0 ) {
$post = get_post( $post_id );
// Set up postdata since this will be needed if post_id was set.

View File

@ -504,11 +504,14 @@ abstract class WP_REST_Controller {
*
* @since 4.7.0
*
* @global array $wp_rest_additional_fields Holds registered fields, organized by object type.
*
* @param string $object_type Optional. The object type.
* @return array Registered additional fields (if any), empty array if none or if the object type could
* not be inferred.
* @return array Registered additional fields (if any), empty array if none or if the object type
* could not be inferred.
*/
protected function get_additional_fields( $object_type = null ) {
global $wp_rest_additional_fields;
if ( ! $object_type ) {
$object_type = $this->get_object_type();
@ -518,8 +521,6 @@ abstract class WP_REST_Controller {
return array();
}
global $wp_rest_additional_fields;
if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) {
return array();
}

View File

@ -265,10 +265,14 @@ class WP_REST_Plugins_Controller extends WP_REST_Controller {
*
* @since 5.5.0
*
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
*
* @param WP_REST_Request $request Full details about the request.
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
global $wp_filesystem;
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/plugin.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
@ -329,19 +333,32 @@ class WP_REST_Plugins_Controller extends WP_REST_Controller {
}
if ( is_null( $result ) ) {
global $wp_filesystem;
// Pass through the error from WP_Filesystem if one was raised.
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
return new WP_Error( 'unable_to_connect_to_filesystem', $wp_filesystem->errors->get_error_message(), array( 'status' => 500 ) );
if ( $wp_filesystem instanceof WP_Filesystem_Base
&& is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors()
) {
return new WP_Error(
'unable_to_connect_to_filesystem',
$wp_filesystem->errors->get_error_message(),
array( 'status' => 500 )
);
}
return new WP_Error( 'unable_to_connect_to_filesystem', __( 'Unable to connect to the filesystem. Please confirm your credentials.' ), array( 'status' => 500 ) );
return new WP_Error(
'unable_to_connect_to_filesystem',
__( 'Unable to connect to the filesystem. Please confirm your credentials.' ),
array( 'status' => 500 )
);
}
$file = $upgrader->plugin_info();
if ( ! $file ) {
return new WP_Error( 'unable_to_determine_installed_plugin', __( 'Unable to determine what plugin was installed.' ), array( 'status' => 500 ) );
return new WP_Error(
'unable_to_determine_installed_plugin',
__( 'Unable to determine what plugin was installed.' ),
array( 'status' => 500 )
);
}
if ( 'inactive' !== $request['status'] ) {

View File

@ -1173,6 +1173,8 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
*
* @since 4.7.0
*
* @global WP_Roles $wp_roles WordPress role management object.
*
* @param int $user_id User ID.
* @param array $roles New user roles.
* @return true|WP_Error True if the current user is allowed to make the role change,

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-alpha-51277';
$wp_version = '5.9-alpha-51278';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.