1
1
<?php
2
2
/**
3
3
*
4
- * @package WordPress
4
+ * @package WordPress
5
5
* @subpackage JSON API
6
6
*/
7
7
15
15
use WP_User ;
16
16
17
17
class Client implements ClientInterface {
18
- const POST_TYPE = 'oauth2_client ' ;
19
- const CLIENT_SECRET_KEY = '_oauth2_client_secret ' ;
20
- const TYPE_KEY = '_oauth2_client_type ' ;
21
- const REDIRECT_URI_KEY = '_oauth2_redirect_uri ' ;
18
+ const POST_TYPE = 'oauth2_client ' ;
19
+ const CLIENT_SECRET_KEY = '_oauth2_client_secret ' ;
20
+ const TYPE_KEY = '_oauth2_client_type ' ;
21
+ const REDIRECT_URI_KEY = '_oauth2_redirect_uri ' ;
22
22
const AUTH_CODE_KEY_PREFIX = '_oauth2_authcode_ ' ;
23
- const AUTH_CODE_LENGTH = 12 ;
24
- const CLIENT_ID_LENGTH = 12 ;
23
+ const AUTH_CODE_LENGTH = 12 ;
24
+ const CLIENT_ID_LENGTH = 12 ;
25
25
const CLIENT_SECRET_LENGTH = 48 ;
26
- const AUTH_CODE_AGE = 600 ; // 10 * MINUTE_IN_SECONDS
26
+ const AUTH_CODE_AGE = 600 ; // 10 * MINUTE_IN_SECONDS
27
27
28
28
/**
29
29
* @var WP_Post
@@ -72,6 +72,7 @@ public function get_name() {
72
72
* Get the client's description.
73
73
*
74
74
* @param boolean $raw True to get raw database value for editing, false to get rendered value for display.
75
+ *
75
76
* @return string
76
77
*/
77
78
public function get_description ( $ raw = false ) {
@@ -137,6 +138,7 @@ public function get_redirect_uris() {
137
138
* just HTTP with standard ports.
138
139
*
139
140
* @param string $url URL for the callback.
141
+ *
140
142
* @return bool True for a valid callback URL, false otherwise.
141
143
*/
142
144
public static function validate_callback ( $ url ) {
@@ -163,10 +165,11 @@ public static function validate_callback( $url ) {
163
165
/**
164
166
* Check if a redirect URI is valid for the client.
165
167
*
166
- * @todo Implement this properly :)
167
- *
168
168
* @param string $uri Supplied redirect URI to check.
169
+ *
169
170
* @return boolean True if the URI is valid, false otherwise.
171
+ * @todo Implement this properly :)
172
+ *
170
173
*/
171
174
public function check_redirect_uri ( $ uri ) {
172
175
if ( ! $ this ->validate_callback ( $ uri ) ) {
@@ -207,30 +210,12 @@ public function check_redirect_uri( $uri ) {
207
210
* Filter whether a callback is counted as valid. (deprecated).
208
211
* User rest_oauth_check_callback.
209
212
*
210
- * @param boolean $valid True if the callback URL is valid, false otherwise.
211
- * @param string $url Supplied callback URL.
212
- * @param string $registered_uri URI being checked.
213
- * @param Client $client OAuth 2 client object.
214
- */
215
- $ valid = apply_filters_deprecated ( 'rest_oauth.check_callback ' , $ valid , $ uri , $ registered_uri , $ this ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
216
-
217
- /**
218
- * Filter whether a callback is counted as valid.
219
- *
220
- * By default, the URLs must match scheme, host, port, user, pass, and
221
- * path. Query and fragment segments are allowed to be different.
222
- *
223
- * To change this behaviour, filter this value. Note that consumers must
224
- * have a callback registered, even if you relax this restruction. It is
225
- * highly recommended not to change this behaviour, as clients will
226
- * expect the same behaviour across all WP sites.
227
- *
228
- * @param boolean $valid True if the callback URL is valid, false otherwise.
229
- * @param string $url Supplied callback URL.
230
- * @param string $registered_uri URI being checked.
231
- * @param Client $client OAuth 2 client object.
213
+ * @param boolean $valid True if the callback URL is valid, false otherwise.
214
+ * @param string $url Supplied callback URL.
215
+ * @param string $registered_uri URI being checked.
216
+ * @param Client $client OAuth 2 client object.
232
217
*/
233
- $ valid = apply_filters ( 'rest_oauth_check_callback ' , $ valid , $ uri , $ registered_uri , $ this );
218
+ $ valid = apply_filters ( 'rest_oauth.check_callback ' , $ valid , $ uri , $ registered_uri , $ this );
234
219
235
220
if ( $ valid ) {
236
221
// Stop checking, we have a match.
@@ -254,6 +239,7 @@ public function generate_authorization_code( WP_User $user ) {
254
239
* Get data stored for an authorization code.
255
240
*
256
241
* @param string $code Authorization code to fetch.
242
+ *
257
243
* @return Authorization_Code|WP_Error Data if available, error if invalid code.
258
244
*/
259
245
public function get_authorization_code ( $ code ) {
@@ -288,6 +274,7 @@ public function issue_token( WP_User $user, $meta = [] ) {
288
274
* Get a client by ID.
289
275
*
290
276
* @param string $id Client ID.
277
+ *
291
278
* @return static|null Token if ID is found, null otherwise.
292
279
*/
293
280
public static function get_by_id ( $ id ) {
@@ -312,6 +299,7 @@ public static function get_by_id( $id ) {
312
299
* Get a client by post ID.
313
300
*
314
301
* @param int $id Client/post ID.
302
+ *
315
303
* @return static|null Client instance on success, null if invalid/not found.
316
304
*/
317
305
public static function get_by_post_id ( $ id ) {
@@ -327,7 +315,8 @@ public static function get_by_post_id( $id ) {
327
315
* Create a new client.
328
316
*
329
317
* @param array $data {
330
- * }
318
+ * }
319
+ *
331
320
* @return WP_Error|Client Client instance on success, error otherwise.
332
321
*/
333
322
public static function create ( $ data ) {
@@ -417,6 +406,7 @@ public function approve() {
417
406
'post_status ' => 'publish ' ,
418
407
];
419
408
$ result = wp_update_post ( wp_slash ( $ data ), true );
409
+
420
410
return is_wp_error ( $ result ) ? $ result : true ;
421
411
}
422
412
0 commit comments