11<?php
22/**
33 *
4- * @package WordPress
4+ * @package WordPress
55 * @subpackage JSON API
66 */
77
1515use WP_User ;
1616
1717class 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 ' ;
2222 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 ;
2525 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
2727
2828 /**
2929 * @var WP_Post
@@ -72,6 +72,7 @@ public function get_name() {
7272 * Get the client's description.
7373 *
7474 * @param boolean $raw True to get raw database value for editing, false to get rendered value for display.
75+ *
7576 * @return string
7677 */
7778 public function get_description ( $ raw = false ) {
@@ -137,6 +138,7 @@ public function get_redirect_uris() {
137138 * just HTTP with standard ports.
138139 *
139140 * @param string $url URL for the callback.
141+ *
140142 * @return bool True for a valid callback URL, false otherwise.
141143 */
142144 public static function validate_callback ( $ url ) {
@@ -163,10 +165,11 @@ public static function validate_callback( $url ) {
163165 /**
164166 * Check if a redirect URI is valid for the client.
165167 *
166- * @todo Implement this properly :)
167- *
168168 * @param string $uri Supplied redirect URI to check.
169+ *
169170 * @return boolean True if the URI is valid, false otherwise.
171+ * @todo Implement this properly :)
172+ *
170173 */
171174 public function check_redirect_uri ( $ uri ) {
172175 if ( ! $ this ->validate_callback ( $ uri ) ) {
@@ -207,30 +210,12 @@ public function check_redirect_uri( $uri ) {
207210 * Filter whether a callback is counted as valid. (deprecated).
208211 * User rest_oauth_check_callback.
209212 *
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.
232217 */
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 );
234219
235220 if ( $ valid ) {
236221 // Stop checking, we have a match.
@@ -254,6 +239,7 @@ public function generate_authorization_code( WP_User $user ) {
254239 * Get data stored for an authorization code.
255240 *
256241 * @param string $code Authorization code to fetch.
242+ *
257243 * @return Authorization_Code|WP_Error Data if available, error if invalid code.
258244 */
259245 public function get_authorization_code ( $ code ) {
@@ -288,6 +274,7 @@ public function issue_token( WP_User $user, $meta = [] ) {
288274 * Get a client by ID.
289275 *
290276 * @param string $id Client ID.
277+ *
291278 * @return static|null Token if ID is found, null otherwise.
292279 */
293280 public static function get_by_id ( $ id ) {
@@ -312,6 +299,7 @@ public static function get_by_id( $id ) {
312299 * Get a client by post ID.
313300 *
314301 * @param int $id Client/post ID.
302+ *
315303 * @return static|null Client instance on success, null if invalid/not found.
316304 */
317305 public static function get_by_post_id ( $ id ) {
@@ -327,7 +315,8 @@ public static function get_by_post_id( $id ) {
327315 * Create a new client.
328316 *
329317 * @param array $data {
330- * }
318+ * }
319+ *
331320 * @return WP_Error|Client Client instance on success, error otherwise.
332321 */
333322 public static function create ( $ data ) {
@@ -417,6 +406,7 @@ public function approve() {
417406 'post_status ' => 'publish ' ,
418407 ];
419408 $ result = wp_update_post ( wp_slash ( $ data ), true );
409+
420410 return is_wp_error ( $ result ) ? $ result : true ;
421411 }
422412
0 commit comments