← All changes
|
json-endpoints/class.wpcom-json-api-site-user-endpoint.php
+13
-8
12.5.2
→
16.3-a.1
View file →
| @@ -1,6 +1,10 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 4 | + exit( 0 ); | |
| 5 | +} | |
| 6 | + | |
| 3 | 7 | new WPCOM_JSON_API_Site_User_Endpoint( |
| 4 | 8 | array( |
| 5 | 9 | 'description' => 'Get details of a user of a site by ID.', |
| 6 | 10 | 'group' => '__do_not_document', // 'users' |
| @@ -24,9 +28,9 @@ | ||
| 24 | 28 | "email": false, |
| 25 | 29 | "name": "binarysmash", |
| 26 | 30 | "URL": "http:\/\/binarysmash.wordpress.com", |
| 27 | 31 | "avatar_URL": "http:\/\/0.gravatar.com\/avatar\/a178ebb1731d432338e6bb0158720fcc?s=96&d=identicon&r=G", |
| 28 | - "profile_URL": "http:\/\/en.gravatar.com\/binarysmash", | |
| 32 | + "profile_URL": "http:\/\/gravatar.com\/binarysmash", | |
| 29 | 33 | "roles": [ "administrator" ] |
| 30 | 34 | }', |
| 31 | 35 | ) |
| 32 | 36 | ); |
| @@ -55,9 +59,9 @@ | ||
| 55 | 59 | "email": false, |
| 56 | 60 | "name": "binarysmash", |
| 57 | 61 | "URL": "http:\/\/binarysmash.wordpress.com", |
| 58 | 62 | "avatar_URL": "http:\/\/0.gravatar.com\/avatar\/a178ebb1731d432338e6bb0158720fcc?s=96&d=identicon&r=G", |
| 59 | - "profile_URL": "http:\/\/en.gravatar.com\/binarysmash", | |
| 63 | + "profile_URL": "http:\/\/gravatar.com\/binarysmash", | |
| 60 | 64 | "roles": [ "administrator" ] |
| 61 | 65 | }', |
| 62 | 66 | ) |
| 63 | 67 | ); |
| @@ -96,9 +100,9 @@ | ||
| 96 | 100 | "email": false, |
| 97 | 101 | "name": "binarysmash", |
| 98 | 102 | "URL": "http:\/\/binarysmash.wordpress.com", |
| 99 | 103 | "avatar_URL": "http:\/\/0.gravatar.com\/avatar\/a178ebb1731d432338e6bb0158720fcc?s=96&d=identicon&r=G", |
| 100 | - "profile_URL": "http:\/\/en.gravatar.com\/binarysmash", | |
| 104 | + "profile_URL": "http:\/\/gravatar.com\/binarysmash", | |
| 101 | 105 | "roles": [ "administrator" ] |
| 102 | 106 | }', |
| 103 | 107 | ) |
| 104 | 108 | ); |
| @@ -106,8 +110,10 @@ | ||
| 106 | 110 | /** |
| 107 | 111 | * Site user endpoint class. |
| 108 | 112 | * |
| 109 | 113 | * /sites/%s/users/%d -> $blog_id, $user_id |
| 114 | + * | |
| 115 | + * @phan-constructor-used-for-side-effects | |
| 110 | 116 | */ |
| 111 | 117 | class WPCOM_JSON_API_Site_User_Endpoint extends WPCOM_JSON_API_Endpoint { |
| 112 | 118 | |
| 113 | 119 | /** |
| @@ -143,14 +149,14 @@ | ||
| 143 | 149 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ) ); |
| 144 | 150 | if ( is_wp_error( $blog_id ) ) { |
| 145 | 151 | return $blog_id; |
| 146 | 152 | } |
| 147 | - if ( ! current_user_can_for_blog( $blog_id, 'list_users' ) ) { | |
| 153 | + if ( ! current_user_can_for_site( $blog_id, 'list_users' ) ) { | |
| 148 | 154 | return new WP_Error( 'unauthorized', 'User cannot view users for specified site', 403 ); |
| 149 | 155 | } |
| 150 | 156 | |
| 151 | 157 | // Get the user by ID or login |
| 152 | - $get_by = false !== strpos( $path, '/users/login:' ) ? 'login' : 'id'; | |
| 158 | + $get_by = str_contains( $path, '/users/login:' ) ? 'login' : 'id'; | |
| 153 | 159 | $user = get_user_by( $get_by, $user_id ); |
| 154 | 160 | |
| 155 | 161 | if ( ! $user ) { |
| 156 | 162 | return new WP_Error( 'unknown_user', 'Unknown user', 404 ); |
| @@ -162,9 +168,9 @@ | ||
| 162 | 168 | |
| 163 | 169 | if ( 'GET' === $this->api->method ) { |
| 164 | 170 | return $this->get_user( $user->ID ); |
| 165 | 171 | } elseif ( 'POST' === $this->api->method ) { |
| 166 | - if ( ! current_user_can_for_blog( $blog_id, 'promote_users' ) ) { | |
| 172 | + if ( ! current_user_can_for_site( $blog_id, 'promote_users' ) ) { | |
| 167 | 173 | return new WP_Error( 'unauthorized_no_promote_cap', 'User cannot promote users for specified site', 403 ); |
| 168 | 174 | } |
| 169 | 175 | return $this->update_user( $user_id, $blog_id ); |
| 170 | 176 | } else { |
| @@ -210,9 +216,9 @@ | ||
| 210 | 216 | return new WP_Error( 'unauthorized', 'You cannot change your own role', 403 ); |
| 211 | 217 | } |
| 212 | 218 | |
| 213 | 219 | if ( $is_wpcom && $user_id !== get_current_user_id() && (int) $user_id === wpcom_get_blog_owner( $blog_id ) ) { |
| 214 | - return new WP_Error( 'unauthorized_edit_owner', 'Current user can not edit blog owner', 403 ); | |
| 220 | + return new WP_Error( 'unauthorized_edit_owner', 'Current user cannot edit blog owner', 403 ); | |
| 215 | 221 | } |
| 216 | 222 | |
| 217 | 223 | if ( ! $is_wpcom ) { |
| 218 | 224 | foreach ( $input as $key => $value ) { |
| @@ -262,6 +268,5 @@ | ||
| 262 | 268 | return $result; |
| 263 | 269 | } |
| 264 | 270 | return $this->get_user( $user_id ); |
| 265 | 271 | } |
| 266 | - | |
| 267 | 272 | } |