Make WordPress Core

Changeset 51278


Ignore:
Timestamp:
06/30/2021 12:33:43 PM (5 years ago)
Author:
SergeyBiryukov
Message:

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

See #53399.

Location:
trunk/src/wp-includes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r51021 r51278  
    119119 *                                          by object type.
    120120 *
    121  * @param string|array $object_type Object(s) the field is being registered
    122  *                                  to, "post"|"term"|"comment" etc.
     121 * @param string|array $object_type Object(s) the field is being registered to,
     122 *                                  "post"|"term"|"comment" etc.
    123123 * @param string       $attribute   The attribute name.
    124124 * @param array        $args {
     
    136136 */
    137137function register_rest_field( $object_type, $attribute, $args = array() ) {
     138        global $wp_rest_additional_fields;
     139
    138140        $defaults = array(
    139141                'get_callback'    => null,
     
    143145
    144146        $args = wp_parse_args( $args, $defaults );
    145 
    146         global $wp_rest_additional_fields;
    147147
    148148        $object_types = (array) $object_type;
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php

    r49108 r51278  
    104104         * @since 5.0.0
    105105         *
     106         * @global WP_Post $post Global post object.
     107         *
    106108         * @param WP_REST_Request $request Request.
    107109         * @return true|WP_Error True if the request has read access, WP_Error object otherwise.
     
    112114                $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0;
    113115
    114                 if ( 0 < $post_id ) {
     116                if ( $post_id > 0 ) {
    115117                        $post = get_post( $post_id );
    116118
     
    144146         * @since 5.0.0
    145147         *
     148         * @global WP_Post $post Global post object.
     149         *
    146150         * @param WP_REST_Request $request Full details about the request.
    147151         * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
     
    152156                $post_id = isset( $request['post_id'] ) ? (int) $request['post_id'] : 0;
    153157
    154                 if ( 0 < $post_id ) {
     158                if ( $post_id > 0 ) {
    155159                        $post = get_post( $post_id );
    156160
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php

    r50952 r51278  
    505505         * @since 4.7.0
    506506         *
     507         * @global array $wp_rest_additional_fields Holds registered fields, organized by object type.
     508         *
    507509         * @param string $object_type Optional. The object type.
    508          * @return array Registered additional fields (if any), empty array if none or if the object type could
    509          *               not be inferred.
     510         * @return array Registered additional fields (if any), empty array if none or if the object type
     511         *               could not be inferred.
    510512         */
    511513        protected function get_additional_fields( $object_type = null ) {
     514                global $wp_rest_additional_fields;
    512515
    513516                if ( ! $object_type ) {
     
    518521                        return array();
    519522                }
    520 
    521                 global $wp_rest_additional_fields;
    522523
    523524                if ( ! $wp_rest_additional_fields || ! isset( $wp_rest_additional_fields[ $object_type ] ) ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php

    r49955 r51278  
    266266         * @since 5.5.0
    267267         *
     268         * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
     269         *
    268270         * @param WP_REST_Request $request Full details about the request.
    269271         * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
    270272         */
    271273        public function create_item( $request ) {
     274                global $wp_filesystem;
     275
    272276                require_once ABSPATH . 'wp-admin/includes/file.php';
    273277                require_once ABSPATH . 'wp-admin/includes/plugin.php';
     
    330334
    331335                if ( is_null( $result ) ) {
    332                         global $wp_filesystem;
    333336                        // Pass through the error from WP_Filesystem if one was raised.
    334                         if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
    335                                 return new WP_Error( 'unable_to_connect_to_filesystem', $wp_filesystem->errors->get_error_message(), array( 'status' => 500 ) );
    336                         }
    337 
    338                         return new WP_Error( 'unable_to_connect_to_filesystem', __( 'Unable to connect to the filesystem. Please confirm your credentials.' ), array( 'status' => 500 ) );
     337                        if ( $wp_filesystem instanceof WP_Filesystem_Base
     338                                && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors()
     339                        ) {
     340                                return new WP_Error(
     341                                        'unable_to_connect_to_filesystem',
     342                                        $wp_filesystem->errors->get_error_message(),
     343                                        array( 'status' => 500 )
     344                                );
     345                        }
     346
     347                        return new WP_Error(
     348                                'unable_to_connect_to_filesystem',
     349                                __( 'Unable to connect to the filesystem. Please confirm your credentials.' ),
     350                                array( 'status' => 500 )
     351                        );
    339352                }
    340353
     
    342355
    343356                if ( ! $file ) {
    344                         return new WP_Error( 'unable_to_determine_installed_plugin', __( 'Unable to determine what plugin was installed.' ), array( 'status' => 500 ) );
     357                        return new WP_Error(
     358                                'unable_to_determine_installed_plugin',
     359                                __( 'Unable to determine what plugin was installed.' ),
     360                                array( 'status' => 500 )
     361                        );
    345362                }
    346363
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

    r51000 r51278  
    11741174         * @since 4.7.0
    11751175         *
     1176         * @global WP_Roles $wp_roles WordPress role management object.
     1177         *
    11761178         * @param int   $user_id User ID.
    11771179         * @param array $roles   New user roles.
Note: See TracChangeset for help on using the changeset viewer.