Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r41760 r42343  
    4646    public function register_routes() {
    4747
    48         register_rest_route( $this->namespace, '/' . $this->rest_base, array(
    49             array(
    50                 'methods'             => WP_REST_Server::READABLE,
    51                 'callback'            => array( $this, 'get_items' ),
    52                 'permission_callback' => array( $this, 'get_items_permissions_check' ),
    53                 'args'                => $this->get_collection_params(),
    54             ),
    55             array(
    56                 'methods'             => WP_REST_Server::CREATABLE,
    57                 'callback'            => array( $this, 'create_item' ),
    58                 'permission_callback' => array( $this, 'create_item_permissions_check' ),
    59                 'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
    60             ),
    61             'schema' => array( $this, 'get_public_item_schema' ),
    62         ) );
    63 
    64         register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
    65             'args' => array(
    66                 'id' => array(
    67                     'description' => __( 'Unique identifier for the user.' ),
    68                     'type'        => 'integer',
    69                 ),
    70             ),
    71             array(
    72                 'methods'             => WP_REST_Server::READABLE,
    73                 'callback'            => array( $this, 'get_item' ),
    74                 'permission_callback' => array( $this, 'get_item_permissions_check' ),
    75                 'args'                => array(
    76                     'context' => $this->get_context_param( array( 'default' => 'view' ) ),
    77                 ),
    78             ),
    79             array(
    80                 'methods'             => WP_REST_Server::EDITABLE,
    81                 'callback'            => array( $this, 'update_item' ),
    82                 'permission_callback' => array( $this, 'update_item_permissions_check' ),
    83                 'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
    84             ),
    85             array(
    86                 'methods'             => WP_REST_Server::DELETABLE,
    87                 'callback'            => array( $this, 'delete_item' ),
    88                 'permission_callback' => array( $this, 'delete_item_permissions_check' ),
    89                 'args'                => array(
    90                     'force'    => array(
    91                         'type'        => 'boolean',
    92                         'default'     => false,
    93                         'description' => __( 'Required to be true, as users do not support trashing.' ),
     48        register_rest_route(
     49            $this->namespace, '/' . $this->rest_base, array(
     50                array(
     51                    'methods'             => WP_REST_Server::READABLE,
     52                    'callback'            => array( $this, 'get_items' ),
     53                    'permission_callback' => array( $this, 'get_items_permissions_check' ),
     54                    'args'                => $this->get_collection_params(),
     55                ),
     56                array(
     57                    'methods'             => WP_REST_Server::CREATABLE,
     58                    'callback'            => array( $this, 'create_item' ),
     59                    'permission_callback' => array( $this, 'create_item_permissions_check' ),
     60                    'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
     61                ),
     62                'schema' => array( $this, 'get_public_item_schema' ),
     63            )
     64        );
     65
     66        register_rest_route(
     67            $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
     68                'args'   => array(
     69                    'id' => array(
     70                        'description' => __( 'Unique identifier for the user.' ),
     71                        'type'        => 'integer',
    9472                    ),
    95                     'reassign' => array(
    96                         'type'        => 'integer',
    97                         'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ),
    98                         'required'    => true,
    99                         'sanitize_callback' => array( $this, 'check_reassign' ),
     73                ),
     74                array(
     75                    'methods'             => WP_REST_Server::READABLE,
     76                    'callback'            => array( $this, 'get_item' ),
     77                    'permission_callback' => array( $this, 'get_item_permissions_check' ),
     78                    'args'                => array(
     79                        'context' => $this->get_context_param( array( 'default' => 'view' ) ),
    10080                    ),
    10181                ),
    102             ),
    103             'schema' => array( $this, 'get_public_item_schema' ),
    104         ) );
    105 
    106         register_rest_route( $this->namespace, '/' . $this->rest_base . '/me', array(
    107             array(
    108                 'methods'             => WP_REST_Server::READABLE,
    109                 'callback'            => array( $this, 'get_current_item' ),
    110                 'args'                => array(
    111                     'context' => $this->get_context_param( array( 'default' => 'view' ) ),
    112                 ),
    113             ),
    114             array(
    115                 'methods'             => WP_REST_Server::EDITABLE,
    116                 'callback'            => array( $this, 'update_current_item' ),
    117                 'permission_callback' => array( $this, 'update_current_item_permissions_check' ),
    118                 'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
    119             ),
    120             array(
    121                 'methods'             => WP_REST_Server::DELETABLE,
    122                 'callback'            => array( $this, 'delete_current_item' ),
    123                 'permission_callback' => array( $this, 'delete_current_item_permissions_check' ),
    124                 'args'                => array(
    125                     'force'    => array(
    126                         'type'        => 'boolean',
    127                         'default'     => false,
    128                         'description' => __( 'Required to be true, as users do not support trashing.' ),
     82                array(
     83                    'methods'             => WP_REST_Server::EDITABLE,
     84                    'callback'            => array( $this, 'update_item' ),
     85                    'permission_callback' => array( $this, 'update_item_permissions_check' ),
     86                    'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
     87                ),
     88                array(
     89                    'methods'             => WP_REST_Server::DELETABLE,
     90                    'callback'            => array( $this, 'delete_item' ),
     91                    'permission_callback' => array( $this, 'delete_item_permissions_check' ),
     92                    'args'                => array(
     93                        'force'    => array(
     94                            'type'        => 'boolean',
     95                            'default'     => false,
     96                            'description' => __( 'Required to be true, as users do not support trashing.' ),
     97                        ),
     98                        'reassign' => array(
     99                            'type'              => 'integer',
     100                            'description'       => __( 'Reassign the deleted user\'s posts and links to this user ID.' ),
     101                            'required'          => true,
     102                            'sanitize_callback' => array( $this, 'check_reassign' ),
     103                        ),
    129104                    ),
    130                     'reassign' => array(
    131                         'type'        => 'integer',
    132                         'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ),
    133                         'required'    => true,
    134                         'sanitize_callback' => array( $this, 'check_reassign' ),
     105                ),
     106                'schema' => array( $this, 'get_public_item_schema' ),
     107            )
     108        );
     109
     110        register_rest_route(
     111            $this->namespace, '/' . $this->rest_base . '/me', array(
     112                array(
     113                    'methods'  => WP_REST_Server::READABLE,
     114                    'callback' => array( $this, 'get_current_item' ),
     115                    'args'     => array(
     116                        'context' => $this->get_context_param( array( 'default' => 'view' ) ),
    135117                    ),
    136118                ),
    137             ),
    138             'schema' => array( $this, 'get_public_item_schema' ),
    139         ));
     119                array(
     120                    'methods'             => WP_REST_Server::EDITABLE,
     121                    'callback'            => array( $this, 'update_current_item' ),
     122                    'permission_callback' => array( $this, 'update_current_item_permissions_check' ),
     123                    'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
     124                ),
     125                array(
     126                    'methods'             => WP_REST_Server::DELETABLE,
     127                    'callback'            => array( $this, 'delete_current_item' ),
     128                    'permission_callback' => array( $this, 'delete_current_item_permissions_check' ),
     129                    'args'                => array(
     130                        'force'    => array(
     131                            'type'        => 'boolean',
     132                            'default'     => false,
     133                            'description' => __( 'Required to be true, as users do not support trashing.' ),
     134                        ),
     135                        'reassign' => array(
     136                            'type'              => 'integer',
     137                            'description'       => __( 'Reassign the deleted user\'s posts and links to this user ID.' ),
     138                            'required'          => true,
     139                            'sanitize_callback' => array( $this, 'check_reassign' ),
     140                        ),
     141                    ),
     142                ),
     143                'schema' => array( $this, 'get_public_item_schema' ),
     144            )
     145        );
    140146    }
    141147
     
    234240            $prepared_args['offset'] = $request['offset'];
    235241        } else {
    236             $prepared_args['offset']  = ( $request['page'] - 1 ) * $prepared_args['number'];
     242            $prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
    237243        }
    238244
    239245        if ( isset( $registered['orderby'] ) ) {
    240             $orderby_possibles = array(
     246            $orderby_possibles        = array(
    241247                'id'              => 'ID',
    242248                'include'         => 'include',
     
    275281
    276282        foreach ( $query->results as $user ) {
    277             $data = $this->prepare_item_for_response( $user, $request );
     283            $data    = $this->prepare_item_for_response( $user, $request );
    278284            $users[] = $this->prepare_response_for_collection( $data );
    279285        }
     
    392398        }
    393399
    394         $user = $this->prepare_item_for_response( $user, $request );
     400        $user     = $this->prepare_item_for_response( $user, $request );
    395401        $response = rest_ensure_response( $user );
    396402
     
    416422        $response = $this->prepare_item_for_response( $user, $request );
    417423        $response = rest_ensure_response( $response );
    418 
    419424
    420425        return $response;
     
    494499            }
    495500
    496             $result= add_user_to_blog( get_site()->id, $user_id, '' );
     501            $result = add_user_to_blog( get_site()->id, $user_id, '' );
    497502            if ( is_wp_error( $result ) ) {
    498503                return $result;
     
    531536        }
    532537
    533         $user = get_user_by( 'id', $user_id );
     538        $user          = get_user_by( 'id', $user_id );
    534539        $fields_update = $this->update_additional_fields_for_object( $user, $request );
    535540
     
    654659        }
    655660
    656         $user = get_user_by( 'id', $user_id );
     661        $user          = get_user_by( 'id', $user_id );
    657662        $fields_update = $this->update_additional_fields_for_object( $user, $request );
    658663
     
    766771
    767772        $response = new WP_REST_Response();
    768         $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
     773        $response->set_data(
     774            array(
     775                'deleted'  => true,
     776                'previous' => $previous->get_data(),
     777            )
     778        );
    769779
    770780        /**
     
    929939    protected function prepare_links( $user ) {
    930940        $links = array(
    931             'self' => array(
     941            'self'       => array(
    932942                'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $user->ID ) ),
    933943            ),
     
    11151125        }
    11161126
    1117         if ( false !== strpos( $password, "\\" ) ) {
     1127        if ( false !== strpos( $password, '\\' ) ) {
    11181128            return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot contain the "\\" character.' ), array( 'status' => 400 ) );
    11191129        }
     
    11351145            'type'       => 'object',
    11361146            'properties' => array(
    1137                 'id'          => array(
     1147                'id'                 => array(
    11381148                    'description' => __( 'Unique identifier for the user.' ),
    11391149                    'type'        => 'integer',
     
    11411151                    'readonly'    => true,
    11421152                ),
    1143                 'username'    => array(
     1153                'username'           => array(
    11441154                    'description' => __( 'Login name for the user.' ),
    11451155                    'type'        => 'string',
     
    11501160                    ),
    11511161                ),
    1152                 'name'        => array(
     1162                'name'               => array(
    11531163                    'description' => __( 'Display name for the user.' ),
    11541164                    'type'        => 'string',
     
    11581168                    ),
    11591169                ),
    1160                 'first_name'  => array(
     1170                'first_name'         => array(
    11611171                    'description' => __( 'First name for the user.' ),
    11621172                    'type'        => 'string',
     
    11661176                    ),
    11671177                ),
    1168                 'last_name'   => array(
     1178                'last_name'          => array(
    11691179                    'description' => __( 'Last name for the user.' ),
    11701180                    'type'        => 'string',
     
    11741184                    ),
    11751185                ),
    1176                 'email'       => array(
     1186                'email'              => array(
    11771187                    'description' => __( 'The email address for the user.' ),
    11781188                    'type'        => 'string',
     
    11811191                    'required'    => true,
    11821192                ),
    1183                 'url'         => array(
     1193                'url'                => array(
    11841194                    'description' => __( 'URL of the user.' ),
    11851195                    'type'        => 'string',
     
    11871197                    'context'     => array( 'embed', 'view', 'edit' ),
    11881198                ),
    1189                 'description' => array(
     1199                'description'        => array(
    11901200                    'description' => __( 'Description of the user.' ),
    11911201                    'type'        => 'string',
    11921202                    'context'     => array( 'embed', 'view', 'edit' ),
    11931203                ),
    1194                 'link'        => array(
     1204                'link'               => array(
    11951205                    'description' => __( 'Author URL of the user.' ),
    11961206                    'type'        => 'string',
     
    11991209                    'readonly'    => true,
    12001210                ),
    1201                 'locale'    => array(
     1211                'locale'             => array(
    12021212                    'description' => __( 'Locale for the user.' ),
    12031213                    'type'        => 'string',
     
    12051215                    'context'     => array( 'edit' ),
    12061216                ),
    1207                 'nickname'    => array(
     1217                'nickname'           => array(
    12081218                    'description' => __( 'The nickname for the user.' ),
    12091219                    'type'        => 'string',
     
    12131223                    ),
    12141224                ),
    1215                 'slug'        => array(
     1225                'slug'               => array(
    12161226                    'description' => __( 'An alphanumeric identifier for the user.' ),
    12171227                    'type'        => 'string',
     
    12211231                    ),
    12221232                ),
    1223                 'registered_date' => array(
     1233                'registered_date'    => array(
    12241234                    'description' => __( 'Registration date for the user.' ),
    12251235                    'type'        => 'string',
     
    12281238                    'readonly'    => true,
    12291239                ),
    1230                 'roles'           => array(
     1240                'roles'              => array(
    12311241                    'description' => __( 'Roles assigned to the user.' ),
    12321242                    'type'        => 'array',
    12331243                    'items'       => array(
    1234                         'type'    => 'string',
     1244                        'type' => 'string',
    12351245                    ),
    12361246                    'context'     => array( 'edit' ),
    12371247                ),
    1238                 'password'        => array(
     1248                'password'           => array(
    12391249                    'description' => __( 'Password for the user (never included).' ),
    12401250                    'type'        => 'string',
     
    12451255                    ),
    12461256                ),
    1247                 'capabilities'    => array(
     1257                'capabilities'       => array(
    12481258                    'description' => __( 'All capabilities assigned to the user.' ),
    12491259                    'type'        => 'object',
     
    12751285            }
    12761286
    1277             $schema['properties']['avatar_urls']  = array(
     1287            $schema['properties']['avatar_urls'] = array(
    12781288                'description' => __( 'Avatar URLs for the user.' ),
    12791289                'type'        => 'object',
     
    13021312
    13031313        $query_params['exclude'] = array(
    1304             'description'        => __( 'Ensure result set excludes specific IDs.' ),
    1305             'type'               => 'array',
    1306             'items'              => array(
    1307                 'type'           => 'integer',
     1314            'description' => __( 'Ensure result set excludes specific IDs.' ),
     1315            'type'        => 'array',
     1316            'items'       => array(
     1317                'type' => 'integer',
    13081318            ),
    1309             'default'            => array(),
     1319            'default'     => array(),
    13101320        );
    13111321
    13121322        $query_params['include'] = array(
    1313             'description'        => __( 'Limit result set to specific IDs.' ),
    1314             'type'               => 'array',
    1315             'items'              => array(
    1316                 'type'           => 'integer',
     1323            'description' => __( 'Limit result set to specific IDs.' ),
     1324            'type'        => 'array',
     1325            'items'       => array(
     1326                'type' => 'integer',
    13171327            ),
    1318             'default'            => array(),
     1328            'default'     => array(),
    13191329        );
    13201330
    13211331        $query_params['offset'] = array(
    1322             'description'        => __( 'Offset the result set by a specific number of items.' ),
    1323             'type'               => 'integer',
     1332            'description' => __( 'Offset the result set by a specific number of items.' ),
     1333            'type'        => 'integer',
    13241334        );
    13251335
    13261336        $query_params['order'] = array(
    1327             'default'            => 'asc',
    1328             'description'        => __( 'Order sort attribute ascending or descending.' ),
    1329             'enum'               => array( 'asc', 'desc' ),
    1330             'type'               => 'string',
     1337            'default'     => 'asc',
     1338            'description' => __( 'Order sort attribute ascending or descending.' ),
     1339            'enum'        => array( 'asc', 'desc' ),
     1340            'type'        => 'string',
    13311341        );
    13321342
    13331343        $query_params['orderby'] = array(
    1334             'default'            => 'name',
    1335             'description'        => __( 'Sort collection by object attribute.' ),
    1336             'enum'               => array(
     1344            'default'     => 'name',
     1345            'description' => __( 'Sort collection by object attribute.' ),
     1346            'enum'        => array(
    13371347                'id',
    13381348                'include',
     
    13441354                'url',
    13451355            ),
    1346             'type'               => 'string',
     1356            'type'        => 'string',
    13471357        );
    13481358
    1349         $query_params['slug']    = array(
    1350             'description'        => __( 'Limit result set to users with one or more specific slugs.' ),
    1351             'type'               => 'array',
    1352             'items'              => array(
    1353                 'type'               => 'string',
     1359        $query_params['slug'] = array(
     1360            'description' => __( 'Limit result set to users with one or more specific slugs.' ),
     1361            'type'        => 'array',
     1362            'items'       => array(
     1363                'type' => 'string',
    13541364            ),
    13551365        );
    13561366
    1357         $query_params['roles']   = array(
    1358             'description'        => __( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ),
    1359             'type'               => 'array',
    1360             'items'              => array(
    1361                 'type'           => 'string',
     1367        $query_params['roles'] = array(
     1368            'description' => __( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ),
     1369            'type'        => 'array',
     1370            'items'       => array(
     1371                'type' => 'string',
    13621372            ),
    13631373        );
Note: See TracChangeset for help on using the changeset viewer.