From 41fdd64d7a48377aded64a84e42fb3b29780f890 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Fri, 17 Nov 2023 16:58:09 +0000 Subject: [PATCH 01/20] Code improves and PHP 8.0 compat --- admin.php | 2 +- composer.json | 2 +- lib/class-wp-rest-client.php | 14 ++++++++++--- lib/class-wp-rest-oauth1-admin.php | 27 ++++++++++---------------- lib/class-wp-rest-oauth1-listtable.php | 6 ++---- lib/class-wp-rest-oauth1-ui.php | 2 ++ lib/class-wp-rest-oauth1.php | 10 ++++------ oauth-server.php | 20 +++++++++++++++++-- theme/oauth1-authorize.php | 5 +++++ 9 files changed, 54 insertions(+), 34 deletions(-) diff --git a/admin.php b/admin.php index 8d1802d..62e03c3 100644 --- a/admin.php +++ b/admin.php @@ -17,7 +17,7 @@ function rest_oauth1_profile_section( $user ) { global $wpdb; - $results = $wpdb->get_col( "SELECT option_value FROM {$wpdb->options} WHERE option_name LIKE 'oauth1_access_%'", 0 ); + $results = $wpdb->get_col( "SELECT option_value FROM $wpdb->options WHERE option_name LIKE 'oauth1_access_%'", 0 ); $approved = array(); foreach ( $results as $result ) { $row = unserialize( $result ); diff --git a/composer.json b/composer.json index 39cce50..10a6f07 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "authors": [ { "name": "WP-API Team", - "homepage": "http://wp-api.org/" + "homepage": "https://wp-api.org/" } ], "require": {} diff --git a/lib/class-wp-rest-client.php b/lib/class-wp-rest-client.php index bfb7e5e..f072064 100644 --- a/lib/class-wp-rest-client.php +++ b/lib/class-wp-rest-client.php @@ -1,12 +1,20 @@ prepare_items(); - - return; + return null; } } public static function dispatch() { - switch ( self::current_action() ) { - case 'add': - case 'edit': - case 'delete': - return; - - default: - return self::render(); - } + return self::render(); } /** @@ -149,9 +140,9 @@ protected static function validate_parameters( $params ) { if ( empty( $params['callback'] ) ) { return new WP_Error( 'rest_oauth1_missing_description', __( 'Consumer callback is required and must be a valid URL.', 'rest_oauth1' ) ); } - if ( ! empty( $params['callback'] ) ) { - $valid['callback'] = $params['callback']; - } + + $valid['callback'] = $params['callback']; + return $valid; } @@ -232,6 +223,7 @@ public static function render_edit_page() { // Are we editing? $consumer = null; + $regenerate_action = ''; $form_action = self::get_url('action=add'); if ( ! empty( $_REQUEST['id'] ) ) { $id = absint( $_REQUEST['id'] ); @@ -400,13 +392,11 @@ public static function handle_delete() { $client = WP_REST_OAuth1_Client::get( $id ); if ( is_wp_error( $client ) ) { wp_die( $client ); - return; } if ( ! $client->delete() ) { $message = 'Invalid consumer ID'; wp_die( $message ); - return; } wp_safe_redirect( self::get_url( 'deleted=1' ) ); @@ -430,7 +420,10 @@ public static function handle_regenerate() { } $client = WP_REST_OAuth1_Client::get( $id ); - $client->regenerate_secret(); + $result = $client->regenerate_secret(); + if( is_wp_error ($result) ) { + wp_die( $result ); + } wp_safe_redirect( self::get_url( array( 'action' => 'edit', 'id' => $id, 'did_action' => 'regenerate' ) ) ); exit; diff --git a/lib/class-wp-rest-oauth1-listtable.php b/lib/class-wp-rest-oauth1-listtable.php index ea16416..e71e069 100644 --- a/lib/class-wp-rest-oauth1-listtable.php +++ b/lib/class-wp-rest-oauth1-listtable.php @@ -1,7 +1,7 @@ get_pagenum(); $args = array( @@ -37,13 +37,11 @@ public function prepare_items() { * and the value is the description. */ public function get_columns() { - $c = array( + return array( 'cb' => '', 'name' => __( 'Name', 'rest_oauth1' ), 'description' => __( 'Description', 'rest_oauth1' ), ); - - return $c; } public function column_cb( $item ) { diff --git a/lib/class-wp-rest-oauth1-ui.php b/lib/class-wp-rest-oauth1-ui.php index c801b6e..b1093eb 100644 --- a/lib/class-wp-rest-oauth1-ui.php +++ b/lib/class-wp-rest-oauth1-ui.php @@ -115,6 +115,8 @@ public function render_page() { } include $file; + + return null; } /** diff --git a/lib/class-wp-rest-oauth1.php b/lib/class-wp-rest-oauth1.php index 268001f..f94160e 100644 --- a/lib/class-wp-rest-oauth1.php +++ b/lib/class-wp-rest-oauth1.php @@ -277,9 +277,9 @@ public function dispatch( $route ) { /** * Check a token against the database * - * @param string $token Token object + * @param array $token Token object * @param string $consumer_key Consumer ID - * @return array Array of consumer object, user object + * @return array|WP_Error Array of consumer object, user object or WP_Error on error. */ public function check_token( $token, $consumer_key ) { $this->should_attempt = false; @@ -363,12 +363,11 @@ public function generate_request_token( $params ) { } } - $data = array( + return array( 'oauth_token' => self::urlencode_rfc3986($key), 'oauth_token_secret' => self::urlencode_rfc3986($data['secret']), 'oauth_callback_confirmed' => 'true', ); - return $data; } public function set_request_token_callback( $key, $callback ) { @@ -601,11 +600,10 @@ public function generate_access_token( $params ) { $this->remove_request_token( $params['oauth_token'] ); // Return the new token's data - $data = array( + return array( 'oauth_token' => self::urlencode_rfc3986( $key ), 'oauth_token_secret' => self::urlencode_rfc3986( $data['secret'] ), ); - return $data; } /** diff --git a/oauth-server.php b/oauth-server.php index 7180e3c..843250d 100644 --- a/oauth-server.php +++ b/oauth-server.php @@ -181,7 +181,15 @@ function rest_oauth1_load_authorize_page() { function rest_oauth1_activation( $network_wide ) { if ( function_exists( 'is_multisite' ) && is_multisite() && $network_wide ) { - $mu_blogs = wp_get_sites(); + if( function_exists('get_sites')){ + $blogs = get_sites(); + $mu_blogs = array(); + foreach ( $blogs as $mu_blog ) { + $mu_blogs[] = $mu_blog->to_array(); + } + } else { + $mu_blogs = wp_get_sites(); + } foreach ( $mu_blogs as $mu_blog ) { @@ -206,7 +214,15 @@ function rest_oauth1_activation( $network_wide ) { function rest_oauth1_deactivation( $network_wide ) { if ( function_exists( 'is_multisite' ) && is_multisite() && $network_wide ) { - $mu_blogs = wp_get_sites(); + if( function_exists('get_sites')){ + $blogs = get_sites(); + $mu_blogs = array(); + foreach ( $blogs as $mu_blog ) { + $mu_blogs[] = $mu_blog->to_array(); + } + } else { + $mu_blogs = wp_get_sites(); + } foreach ( $mu_blogs as $mu_blog ) { diff --git a/theme/oauth1-authorize.php b/theme/oauth1-authorize.php index 7a51306..a46377d 100644 --- a/theme/oauth1-authorize.php +++ b/theme/oauth1-authorize.php @@ -1,4 +1,9 @@ Date: Mon, 20 Nov 2023 10:06:13 +0000 Subject: [PATCH 02/20] Fix dispatch --- lib/class-wp-rest-oauth1-admin.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-rest-oauth1-admin.php b/lib/class-wp-rest-oauth1-admin.php index b0431c3..e1f6bff 100644 --- a/lib/class-wp-rest-oauth1-admin.php +++ b/lib/class-wp-rest-oauth1-admin.php @@ -80,7 +80,11 @@ public static function load() { } public static function dispatch() { - return self::render(); + if ( in_array( self::current_action(), array( 'add', 'edit', 'delete' ), true ) ) { + return; + } + + return self::render(); } /** From 201229673e504a8935b58dcfb7bb71ea604485da Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Mon, 20 Nov 2023 10:26:23 +0000 Subject: [PATCH 03/20] Remove get_class_caller --- lib/class-wp-rest-client.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/class-wp-rest-client.php b/lib/class-wp-rest-client.php index f072064..0d4c52f 100644 --- a/lib/class-wp-rest-client.php +++ b/lib/class-wp-rest-client.php @@ -127,8 +127,7 @@ public static function get( $id ) { return new WP_Error( 'rest_oauth1_invalid_id', __( 'Client ID is not valid.', 'rest_oauth1' ), array( 'status' => 404 ) ); } - $class = function_exists( 'get_called_class' ) ? get_called_class() : self::get_called_class(); - return new $class( $post ); + return new static( $post ); } /** @@ -139,8 +138,7 @@ public static function get( $id ) { * @return WP_Post|WP_Error */ public static function get_by_key( $key ) { - $class = function_exists( 'get_called_class' ) ? get_called_class() : self::get_called_class(); - $type = call_user_func( array( $class, 'get_type' ) ); + $type = self::get_type(); $query = new WP_Query(); $consumers = $query->query( array( @@ -174,7 +172,7 @@ public static function get_by_key( $key ) { * @type string $description Client description * @type array $meta Metadata for the client (map of key => value) * } - * @return WP_Post|WP_Error + * @return WP_REST_Client|WP_Error */ public static function create( $params ) { $default = array( @@ -194,9 +192,8 @@ public static function create( $params ) { return $ID; } - $class = function_exists( 'get_called_class' ) ? get_called_class() : self::get_called_class(); $meta = $params['meta']; - $meta['type'] = call_user_func( array( $class, 'get_type' ) ); + $meta['type'] = self::get_type(); // Allow types to add their own meta too $meta = self::add_extra_meta( $meta, $params ); @@ -215,7 +212,7 @@ public static function create( $params ) { } $post = get_post( $ID ); - return new $class( $post ); + return new static( $post ); } /** @@ -235,9 +232,11 @@ protected static function add_extra_meta( $meta, $params ) { /** * Shim for get_called_class() for PHP 5.2 * + * @deprecated 0.3.1 * @return string Class name. */ protected static function get_called_class() { + _deprecated_function( __METHOD__, '0.3.1', 'get_called_class()' ); // PHP 5.2 only $backtrace = debug_backtrace(); // [0] WP_REST_Client::get_called_class() From 36053665495f34ee9990ffda7a48de08926ed54f Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Mon, 20 Nov 2023 11:04:19 +0000 Subject: [PATCH 04/20] More type checks --- admin.php | 2 +- lib/class-wp-rest-oauth1-admin.php | 14 +++++++++----- lib/class-wp-rest-oauth1-cli.php | 3 +++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/admin.php b/admin.php index 62e03c3..7e65e7e 100644 --- a/admin.php +++ b/admin.php @@ -17,7 +17,7 @@ function rest_oauth1_profile_section( $user ) { global $wpdb; - $results = $wpdb->get_col( "SELECT option_value FROM $wpdb->options WHERE option_name LIKE 'oauth1_access_%'", 0 ); + $results = $wpdb->get_col( "SELECT option_value FROM $wpdb->options WHERE option_name LIKE 'oauth1_access_%'" ); $approved = array(); foreach ( $results as $result ) { $row = unserialize( $result ); diff --git a/lib/class-wp-rest-oauth1-admin.php b/lib/class-wp-rest-oauth1-admin.php index e1f6bff..9409bce 100644 --- a/lib/class-wp-rest-oauth1-admin.php +++ b/lib/class-wp-rest-oauth1-admin.php @@ -12,7 +12,9 @@ public static function register() { */ include_once dirname( __FILE__ ) . '/class-wp-rest-oauth1-listtable.php'; - $hook = add_users_page( + $class = get_class(); + + $hook = add_users_page( // Page title __( 'Registered OAuth Applications', 'rest_oauth1' ), @@ -26,10 +28,10 @@ public static function register() { self::BASE_SLUG, // Callback - array( get_class(), 'dispatch' ) + array( $class, 'dispatch' ) ); - add_action( 'load-' . $hook, array( get_class(), 'load' ) ); + add_action( 'load-' . $hook, array( $class, 'load' ) ); } /** @@ -76,7 +78,6 @@ public static function load() { $wp_list_table->prepare_items(); return null; } - } public static function dispatch() { @@ -424,8 +425,11 @@ public static function handle_regenerate() { } $client = WP_REST_OAuth1_Client::get( $id ); + if( is_wp_error( $client) ) { + wp_die( $client ); + } $result = $client->regenerate_secret(); - if( is_wp_error ($result) ) { + if( is_wp_error( $result) ) { wp_die( $result ); } diff --git a/lib/class-wp-rest-oauth1-cli.php b/lib/class-wp-rest-oauth1-cli.php index bbe2e10..a9e855d 100644 --- a/lib/class-wp-rest-oauth1-cli.php +++ b/lib/class-wp-rest-oauth1-cli.php @@ -13,6 +13,9 @@ class WP_REST_OAuth1_CLI extends WP_CLI_Command { */ public function add( $_, $args ) { $consumer = WP_REST_OAuth1_Client::create( $args ); + if( is_wp_error( $consumer ) ) { + WP_CLI::Error( $consumer ); + } WP_CLI::line( sprintf( 'ID: %d', $consumer->ID ) ); WP_CLI::line( sprintf( 'Key: %s', $consumer->key ) ); WP_CLI::line( sprintf( 'Secret: %s', $consumer->secret ) ); From 2b6bbd82ce4e27f01003140549039253cdc35688 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Mon, 20 Nov 2023 11:26:46 +0000 Subject: [PATCH 05/20] More code quality changes --- admin.php | 2 +- lib/class-wp-rest-client.php | 46 ++++++++++++++---------------- lib/class-wp-rest-oauth1-admin.php | 18 ++++++------ lib/class-wp-rest-oauth1.php | 13 ++++----- 4 files changed, 36 insertions(+), 43 deletions(-) diff --git a/admin.php b/admin.php index 7e65e7e..9fc993b 100644 --- a/admin.php +++ b/admin.php @@ -26,7 +26,7 @@ function rest_oauth1_profile_section( $user ) { } } - $authenticator = new WP_REST_OAuth1(); + (new WP_REST_OAuth1()); ?> diff --git a/lib/class-wp-rest-client.php b/lib/class-wp-rest-client.php index 0d4c52f..47fb29e 100644 --- a/lib/class-wp-rest-client.php +++ b/lib/class-wp-rest-client.php @@ -104,13 +104,11 @@ public function update( $params ) { return true; } - /** - * Delete a client. - * - * @param string $type Client type. - * @param int $id Client post ID. - * @return bool True if delete, false otherwise. - */ + /** + * Delete a client. + * + * @return bool True if delete, false otherwise. + */ public function delete() { return (bool) wp_delete_post( $this->post->ID, true ); } @@ -130,13 +128,12 @@ public static function get( $id ) { return new static( $post ); } - /** - * Get a client by key. - * - * @param string $type Client type. - * @param string $key Client key. - * @return WP_Post|WP_Error - */ + /** + * Get a client by key. + * + * @param string $key Client key. + * @return WP_Post|WP_Error + */ public static function get_by_key( $key ) { $type = self::get_type(); @@ -163,17 +160,16 @@ public static function get_by_key( $key ) { return $consumers[0]; } - /** - * Create a new client. - * - * @param string $type Client type. - * @param array $params { - * @type string $name Client name - * @type string $description Client description - * @type array $meta Metadata for the client (map of key => value) - * } - * @return WP_REST_Client|WP_Error - */ + /** + * Create a new client. + * + * @param array $params { + * @type string $name Client name + * @type string $description Client description + * @type array $meta Metadata for the client (map of key => value) + * } + * @return WP_REST_Client|WP_Error + */ public static function create( $params ) { $default = array( 'name' => '', diff --git a/lib/class-wp-rest-oauth1-admin.php b/lib/class-wp-rest-oauth1-admin.php index 9409bce..b63f596 100644 --- a/lib/class-wp-rest-oauth1-admin.php +++ b/lib/class-wp-rest-oauth1-admin.php @@ -62,21 +62,19 @@ public static function load() { switch ( self::current_action() ) { case 'add': case 'edit': - return self::render_edit_page(); - + self::render_edit_page(); + break; case 'delete': - return self::handle_delete(); - + self::handle_delete(); + break; case 'regenerate': - return self::handle_regenerate(); - + self::handle_regenerate(); + break; default: global $wp_list_table; $wp_list_table = new WP_REST_OAuth1_ListTable(); - $wp_list_table->prepare_items(); - return null; } } @@ -85,7 +83,7 @@ public static function dispatch() { return; } - return self::render(); + self::render(); } /** @@ -176,7 +174,7 @@ protected static function handle_edit_submit( $consumer ) { } if ( empty( $consumer ) ) { - $authenticator = new WP_REST_OAuth1(); + (new WP_REST_OAuth1()); // Create the consumer $data = array( diff --git a/lib/class-wp-rest-oauth1.php b/lib/class-wp-rest-oauth1.php index f94160e..03018f7 100644 --- a/lib/class-wp-rest-oauth1.php +++ b/lib/class-wp-rest-oauth1.php @@ -160,7 +160,7 @@ public function get_parameters( $require_token = true, $extra = array() ) { * * @link http://tools.ietf.org/html/rfc5849 OAuth 1.0a Specification * - * @param WP_User|null Already authenticated user (will be passed through), or null to perform OAuth authentication + * @param WP_User|null $user Already authenticated user (will be passed through), or null to perform OAuth authentication * @return WP_User|null|WP_Error Authenticated user on success, null if no OAuth data supplied, error otherwise */ public function authenticate( $user ) { @@ -213,7 +213,7 @@ public function authenticate( $user ) { /** * Report authentication errors to the JSON API * - * @param WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not + * @param WP_Error|mixed $value Error from another authentication handler, null if we should handle it, or another value if not * @return WP_Error|boolean|null {@see WP_JSON_Server::check_authentication} */ public function get_authentication_errors( $value ) { @@ -542,8 +542,7 @@ public function get_access_token( $oauth_token ) { /** * Generate a new access token * - * @param string $oauth_consumer_key Consumer key - * @param string $oauth_token Request token key + * @param array $params Request parameters. * @return WP_Error|array OAuth token data on success, error otherwise */ public function generate_access_token( $params ) { @@ -628,8 +627,8 @@ public function revoke_access_token( $key ) { * Verify that the consumer-provided request signature matches our generated signature, this ensures the consumer * has a valid key/secret * - * @param WP_User $user - * @param array $params the request parameters + * @param WP_Post $consumer REST Client. + * @param array $oauth_params the request parameters * @return boolean|WP_Error True on success, error otherwise */ public function check_oauth_signature( $consumer, $oauth_params, $token = null ) { @@ -761,7 +760,7 @@ protected function normalize_parameters( &$key, &$value ) { * valid within 15 minutes of the current time, and a nonce is valid if it * has not been used within the last 15 minutes. * - * @param WP_User $consumer + * @param WP_Post $consumer Post client. * @param int $timestamp the unix timestamp for when the request was made * @param string $nonce a unique (for the given user) 32 alphanumeric string, consumer-generated * @return boolean|WP_Error True on success, error otherwise From e2f2526a649a50a725ea2bd8f20210b176a45601 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 21 Nov 2023 16:16:50 +0000 Subject: [PATCH 06/20] Improve error handling --- lib/class-wp-rest-oauth1.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/class-wp-rest-oauth1.php b/lib/class-wp-rest-oauth1.php index 984b78d..c036f61 100644 --- a/lib/class-wp-rest-oauth1.php +++ b/lib/class-wp-rest-oauth1.php @@ -205,8 +205,8 @@ public function authenticate( $user ) { // Fetch user by token key. $token = $this->get_access_token( $params['oauth_token'] ); - if ( is_wp_error( $token ) ) { - $this->auth_status = $token; + if ( empty( $token ) ) { + $this->auth_status = new WP_Error( 'json_oauth1_invalid_token', __( 'Access token does not exist', 'rest_oauth1' ), array( 'status' => 401 ) );; return null; } From bf29eba7825f66c2c3dae8aed7948a818f77bfbc Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 21 Nov 2023 16:18:56 +0000 Subject: [PATCH 07/20] Fix lint --- lib/class-wp-rest-oauth1.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-rest-oauth1.php b/lib/class-wp-rest-oauth1.php index c036f61..9378b3e 100644 --- a/lib/class-wp-rest-oauth1.php +++ b/lib/class-wp-rest-oauth1.php @@ -206,7 +206,8 @@ public function authenticate( $user ) { // Fetch user by token key. $token = $this->get_access_token( $params['oauth_token'] ); if ( empty( $token ) ) { - $this->auth_status = new WP_Error( 'json_oauth1_invalid_token', __( 'Access token does not exist', 'rest_oauth1' ), array( 'status' => 401 ) );; + $this->auth_status = new WP_Error( 'json_oauth1_invalid_token', __( 'Access token does not exist', 'rest_oauth1' ), array( 'status' => 401 ) ); + return null; } From 92e66a371eaa87a0ec9bb3044157520f4537f8e8 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 21 Nov 2023 17:21:10 +0000 Subject: [PATCH 08/20] Fix another PHP error --- lib/class-wp-rest-oauth1.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-rest-oauth1.php b/lib/class-wp-rest-oauth1.php index 9378b3e..bf6a7ce 100644 --- a/lib/class-wp-rest-oauth1.php +++ b/lib/class-wp-rest-oauth1.php @@ -705,7 +705,7 @@ public function check_oauth_signature( $consumer, $oauth_params, $token = null ) unset( $params['oauth_signature'] ); // normalize parameter key/values. - array_walk_recursive( $params, array( $this, 'normalize_parameters' ) ); + $params = $this->normalize_parameter( $params ); // sort parameters. if ( ! uksort( $params, 'strcmp' ) ) { @@ -779,6 +779,28 @@ public function join_with_equals_sign( $params, $query_params = array(), $key = return $query_params; } + /** + * Normalize each parameter by assuming each parameter may have already been encoded, so attempt to decode, and then + * re-encode according to RFC 3986 + * + * @see rawurlencode() + * @param array $params Parameters to normalize. + */ + protected function normalize_parameter( array $params ) { + $new_params = array(); + foreach ( $params as $key => $value ) { + $new_key = self::urlencode_rfc3986( rawurldecode( $key ) ); + if ( is_array( $value ) ) { + $new_value = $this->normalize_parameter( $value ); + } else { + $new_value = self::urlencode_rfc3986( rawurldecode( $value ) ); + } + $new_params[ $new_key ] = $new_value; + } + + return $new_params; + } + /** * Normalize each parameter by assuming each parameter may have already been encoded, so attempt to decode, and then * re-encode according to RFC 3986 @@ -789,6 +811,7 @@ public function join_with_equals_sign( $params, $query_params = array(), $key = * @param string $value Value, passed by reference. */ protected function normalize_parameters( &$key, &$value ) { + _deprecated_function( __METHOD__, '0.3.1', 'WP_REST_OAuth1::normalize_parameter()' ); $key = self::urlencode_rfc3986( rawurldecode( $key ) ); $value = self::urlencode_rfc3986( rawurldecode( $value ) ); } From fcb586ab31bb3b59b5ecb9b76cd68233639a62cc Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 21 Nov 2023 17:54:16 +0000 Subject: [PATCH 09/20] Revert some of the changes --- lib/class-wp-rest-client.php | 14 ++++++++------ lib/class-wp-rest-oauth1.php | 31 +++++++++++-------------------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/lib/class-wp-rest-client.php b/lib/class-wp-rest-client.php index 2d87cb7..59d9d77 100644 --- a/lib/class-wp-rest-client.php +++ b/lib/class-wp-rest-client.php @@ -134,7 +134,9 @@ public static function get( $id ) { return new WP_Error( 'rest_oauth1_invalid_id', __( 'Client ID is not valid.', 'rest_oauth1' ), array( 'status' => 404 ) ); } - return new static( $post ); + $class = get_called_class(); + + return new $class( $post ); } /** @@ -144,7 +146,7 @@ public static function get( $id ) { * @return WP_Post|WP_Error */ public static function get_by_key( $key ) { - $type = self::get_type(); + $type = call_user_func( array( get_called_class(), 'get_type' ) ); $query = new WP_Query(); $consumers = $query->query( @@ -165,8 +167,7 @@ public static function get_by_key( $key ) { ); if ( empty( $consumers ) || empty( $consumers[0] ) ) { - $code = is_user_logged_in() ? 403 : 401; - return new WP_Error( 'json_consumer_notfound', __( 'Consumer Key is invalid', 'rest_oauth1' ), array( 'status' => $code ) ); + return new WP_Error( 'json_consumer_notfound', __( 'Consumer Key is invalid', 'rest_oauth1' ), array( 'status' => 401 ) ); } return $consumers[0]; @@ -201,7 +202,8 @@ public static function create( $params ) { } $meta = $params['meta']; - $meta['type'] = self::get_type(); + $class = get_called_class(); + $meta['type'] = call_user_func( array( $class, 'get_type' ) ); // Allow types to add their own meta too. $meta = self::add_extra_meta( $meta, $params ); @@ -220,7 +222,7 @@ public static function create( $params ) { } $post = get_post( $id ); - return new static( $post ); + return new $class( $post ); } /** diff --git a/lib/class-wp-rest-oauth1.php b/lib/class-wp-rest-oauth1.php index bf6a7ce..1a0c0cb 100644 --- a/lib/class-wp-rest-oauth1.php +++ b/lib/class-wp-rest-oauth1.php @@ -170,7 +170,7 @@ public function get_parameters( $require_token = true, $extra = array() ) { ), implode( ', ', $errors ) ); - return new WP_Error( 'json_oauth1_missing_parameter', $message, array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_missing_parameter', $message, array( 'status' => 401 ) ); } return $params; @@ -312,7 +312,7 @@ public function check_token( $token, $consumer_key ) { } if ( ! hash_equals( (string) $token['consumer'], (string) $consumer->ID ) ) { - return new WP_Error( 'json_oauth1_consumer_mismatch', __( 'Token is not registered for the given consumer', 'rest_oauth1' ), array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_consumer_mismatch', __( 'Token is not registered for the given consumer', 'rest_oauth1' ), array( 'status' => 401 ) ); } return array( $consumer, new WP_User( $token['user'] ) ); @@ -334,7 +334,7 @@ public function get_request_token( $key ) { // Check expiration. if ( $data['expiration'] < time() ) { $this->remove_request_token( $key ); - return new WP_Error( 'json_oauth1_expired_token', __( 'OAuth request token has expired', 'rest_oauth1' ), array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_expired_token', __( 'OAuth request token has expired', 'rest_oauth1' ), array( 'status' => 401 ) ); } return $data; @@ -601,7 +601,7 @@ public function generate_access_token( $params ) { // Check verification. if ( true !== $token['authorized'] ) { - return new WP_Error( 'json_oauth1_unauthorized_token', __( 'OAuth token has not been authorized', 'rest_oauth1' ), array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_unauthorized_token', __( 'OAuth token has not been authorized', 'rest_oauth1' ), array( 'status' => 401 ) ); } if ( ! hash_equals( (string) $params['oauth_verifier'], (string) $token['verifier'] ) ) { @@ -646,7 +646,7 @@ public function generate_access_token( $params ) { public function revoke_access_token( $key ) { $data = $this->get_access_token( $key ); if ( empty( $data ) ) { - return new WP_Error( 'json_oauth1_invalid_token', __( 'Access token does not exist', 'rest_oauth1' ), array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_invalid_token', __( 'Access token does not exist', 'rest_oauth1' ), array( 'status' => 401 ) ); } delete_option( 'oauth1_access_' . $key ); @@ -687,7 +687,7 @@ public function check_oauth_signature( $consumer, $oauth_params, $token = null ) __( 'Unknown http method: %s', 'rest_oauth1' ), $http_method ), - array( 'status' => $this->get_authorization_required_code() ) + array( 'status' => 401 ) ); } @@ -709,7 +709,7 @@ public function check_oauth_signature( $consumer, $oauth_params, $token = null ) // sort parameters. if ( ! uksort( $params, 'strcmp' ) ) { - return new WP_Error( 'json_oauth1_failed_parameter_sort', __( 'Invalid Signature - failed to sort parameters', 'rest_oauth1' ), array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_failed_parameter_sort', __( 'Invalid Signature - failed to sort parameters', 'rest_oauth1' ), array( 'status' => 401 ) ); } $query_string = $this->create_signature_string( $params ); @@ -732,13 +732,13 @@ public function check_oauth_signature( $consumer, $oauth_params, $token = null ) break; default: - return new WP_Error( 'json_oauth1_invalid_signature_method', __( 'Signature method is invalid', 'rest_oauth1' ), array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_invalid_signature_method', __( 'Signature method is invalid', 'rest_oauth1' ), array( 'status' => 401 ) ); } $signature = base64_encode( hash_hmac( $hash_algorithm, $string_to_sign, $key, true ) ); if ( ! hash_equals( $signature, $consumer_signature ) ) { - return new WP_Error( 'json_oauth1_signature_mismatch', __( 'OAuth signature does not match', 'rest_oauth1' ), array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_signature_mismatch', __( 'OAuth signature does not match', 'rest_oauth1' ), array( 'status' => 401 ) ); } return true; @@ -832,7 +832,7 @@ public function check_oauth_timestamp_and_nonce( $consumer, $timestamp, $nonce ) $valid_window = apply_filters( 'json_oauth1_timestamp_window', 15 * MINUTE_IN_SECONDS ); if ( ( $timestamp < time() - $valid_window ) || ( $timestamp > time() + $valid_window ) ) { - return new WP_Error( 'json_oauth1_invalid_timestamp', __( 'Invalid timestamp', 'rest_oauth1' ), array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_invalid_timestamp', __( 'Invalid timestamp', 'rest_oauth1' ), array( 'status' => 401 ) ); } $used_nonces = $consumer->nonces; @@ -842,7 +842,7 @@ public function check_oauth_timestamp_and_nonce( $consumer, $timestamp, $nonce ) } if ( in_array( $nonce, $used_nonces, true ) ) { - return new WP_Error( 'json_oauth1_nonce_already_used', __( 'Invalid nonce - nonce has already been used', 'rest_oauth1' ), array( 'status' => $this->get_authorization_required_code() ) ); + return new WP_Error( 'json_oauth1_nonce_already_used', __( 'Invalid nonce - nonce has already been used', 'rest_oauth1' ), array( 'status' => 401 ) ); } $used_nonces[ $timestamp ] = $nonce; @@ -874,13 +874,4 @@ public function check_oauth_timestamp_and_nonce( $consumer, $timestamp, $nonce ) protected static function urlencode_rfc3986( $value ) { return str_replace( array( '+', '%7E' ), array( ' ', '~' ), rawurlencode( $value ) ); } - - /** - * Returns a contextual HTTP error code for authorization failure. - * - * @return int 401 if the user is not logged in, 403 if the user is logged in. - */ - protected function get_authorization_required_code() { - return is_user_logged_in() ? 403 : 401; - } } From e7446635ed2563d063e8bbead448aab9dabf1d24 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 21 Nov 2023 18:22:40 +0000 Subject: [PATCH 10/20] Fix error --- lib/class-wp-rest-client.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/class-wp-rest-client.php b/lib/class-wp-rest-client.php index 59d9d77..b7f747a 100644 --- a/lib/class-wp-rest-client.php +++ b/lib/class-wp-rest-client.php @@ -146,7 +146,7 @@ public static function get( $id ) { * @return WP_Post|WP_Error */ public static function get_by_key( $key ) { - $type = call_user_func( array( get_called_class(), 'get_type' ) ); + $type = call_user_func( array( get_called_class(), 'get_type' ) ); $query = new WP_Query(); $consumers = $query->query( @@ -206,7 +206,7 @@ public static function create( $params ) { $meta['type'] = call_user_func( array( $class, 'get_type' ) ); // Allow types to add their own meta too. - $meta = self::add_extra_meta( $meta, $params ); + $meta = call_user_func( array( $class, 'add_extra_meta' ), $meta, $params ); /** * Add extra meta to the consumer on creation. From cb5e0ca54dd2e375e84faab9a370a641871fa253 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 21 Nov 2023 18:24:19 +0000 Subject: [PATCH 11/20] Change type --- lib/class-wp-rest-oauth1-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/class-wp-rest-oauth1-admin.php b/lib/class-wp-rest-oauth1-admin.php index 6e31234..5ac5708 100644 --- a/lib/class-wp-rest-oauth1-admin.php +++ b/lib/class-wp-rest-oauth1-admin.php @@ -347,7 +347,7 @@ public static function render_edit_page() {
-

From 2450b9c848a0172f5b73dca46fbd7c793171f910 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 23 Nov 2023 16:22:14 +0000 Subject: [PATCH 12/20] Ensure that callback is registered --- lib/class-wp-rest-oauth1-admin.php | 2 +- lib/class-wp-rest-oauth1.php | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/class-wp-rest-oauth1-admin.php b/lib/class-wp-rest-oauth1-admin.php index 5ac5708..6e31234 100644 --- a/lib/class-wp-rest-oauth1-admin.php +++ b/lib/class-wp-rest-oauth1-admin.php @@ -347,7 +347,7 @@ public static function render_edit_page() {
-

diff --git a/lib/class-wp-rest-oauth1.php b/lib/class-wp-rest-oauth1.php index 1a0c0cb..1ad8d61 100644 --- a/lib/class-wp-rest-oauth1.php +++ b/lib/class-wp-rest-oauth1.php @@ -364,21 +364,22 @@ public function generate_request_token( $params ) { } // Generate token. - $key = apply_filters( 'json_oauth1_request_token_key', wp_generate_password( self::TOKEN_KEY_LENGTH, false ) ); - $data = array( + $key = apply_filters( 'json_oauth1_request_token_key', wp_generate_password( self::TOKEN_KEY_LENGTH, false ) ); + $callback = ! empty( $params['oauth_callback'] ) ? $params['oauth_callback'] : null; + $data = array( 'key' => $key, 'secret' => wp_generate_password( self::TOKEN_SECRET_LENGTH, false ), 'consumer' => $consumer->ID, 'authorized' => false, 'expiration' => time() + 24 * HOUR_IN_SECONDS, - 'callback' => null, + 'callback' => $callback, 'verifier' => null, 'user' => null, ); - $data = apply_filters( 'json_oauth1_request_token_data', $data ); + $data = apply_filters( 'json_oauth1_request_token_data', $data ); add_option( 'oauth1_request_' . $key, $data, null, 'no' ); - if ( ! empty( $params['oauth_callback'] ) ) { - $error = $this->set_request_token_callback( $key, $params['oauth_callback'] ); + if ( ! empty( $callback ) ) { + $error = $this->set_request_token_callback( $key, $callback ); if ( $error ) { return $error; } From d270e2a254730bc75bdf44d76223bb942b5ea774 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 23 Nov 2023 16:55:48 +0000 Subject: [PATCH 13/20] Ensure that no cache control headers are sent when using oauth1 --- oauth-server.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/oauth-server.php b/oauth-server.php index 91bb052..5753d48 100644 --- a/oauth-server.php +++ b/oauth-server.php @@ -128,6 +128,9 @@ function rest_oauth1_loaded() { $authenticator = new WP_REST_OAuth1(); $response = $authenticator->dispatch( $GLOBALS['wp']->query_vars['rest_oauth1'] ); + nocache_headers(); + header( 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' ); + if ( is_wp_error( $response ) ) { $error_data = $response->get_error_data(); if ( is_array( $error_data ) && isset( $error_data['status'] ) ) { @@ -141,7 +144,6 @@ function rest_oauth1_loaded() { die(); } - header( 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' ); $response = http_build_query( $response, '', '&' ); echo $response; From 43052648ba14133fb93b10482cd68d52497b0a35 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 23 Nov 2023 17:23:44 +0000 Subject: [PATCH 14/20] Improve error message --- lib/class-wp-rest-oauth1-admin.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/class-wp-rest-oauth1-admin.php b/lib/class-wp-rest-oauth1-admin.php index 6e31234..c182a95 100644 --- a/lib/class-wp-rest-oauth1-admin.php +++ b/lib/class-wp-rest-oauth1-admin.php @@ -170,7 +170,7 @@ protected static function validate_parameters( $params ) { /** * Handle submission of the add page - * @param WP_User $consumer Consumer user. + * @param WP_REST_Client $consumer Consumer user. * * @return array|null List of errors. Issues a redirect and exits on success. */ @@ -429,8 +429,12 @@ public static function handle_delete() { } if ( ! $client->delete() ) { - $message = 'Invalid consumer ID'; - wp_die( $message ); + $code = is_user_logged_in() ? 403 : 401; + wp_die( + '

' . __( 'An error has occurred.', 'rest_oauth1' ) . '

' . + '

' . __( 'Invalid consumer ID', 'rest_oauth1' ) . '

', + $code + ); } wp_safe_redirect( self::get_url( 'deleted=1' ) ); From 2d8c468be09548f2beb77efd04ee428a1a141379 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 23 Nov 2023 17:31:00 +0000 Subject: [PATCH 15/20] Fix WP_Error code --- lib/class-wp-rest-oauth1-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/class-wp-rest-oauth1-admin.php b/lib/class-wp-rest-oauth1-admin.php index c182a95..f50fc09 100644 --- a/lib/class-wp-rest-oauth1-admin.php +++ b/lib/class-wp-rest-oauth1-admin.php @@ -159,7 +159,7 @@ protected static function validate_parameters( $params ) { $valid['description'] = wp_filter_post_kses( $params['description'] ); if ( empty( $params['callback'] ) ) { - return new WP_Error( 'rest_oauth1_missing_description', __( 'Consumer callback is required and must be a valid URL.', 'rest_oauth1' ) ); + return new WP_Error( 'rest_oauth1_missing_callback', __( 'Consumer callback is required and must be a valid URL.', 'rest_oauth1' ) ); } $valid['callback'] = $params['callback']; From b0ba4af6d02eadc45d6f1ab59b63a1f1bbe0ad32 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 23 Nov 2023 17:55:27 +0000 Subject: [PATCH 16/20] Code improvements --- admin.php | 5 +++-- lib/class-wp-rest-client.php | 2 +- lib/class-wp-rest-oauth1-admin.php | 2 -- lib/class-wp-rest-oauth1-client.php | 24 ++++++++++++++++++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/admin.php b/admin.php index 3aaedb6..d8be5ff 100644 --- a/admin.php +++ b/admin.php @@ -31,8 +31,6 @@ function rest_oauth1_profile_section( $user ) { } } - ( new WP_REST_OAuth1() ); - ?> @@ -51,6 +49,9 @@ function rest_oauth1_profile_section( $user ) { diff --git a/lib/class-wp-rest-client.php b/lib/class-wp-rest-client.php index b7f747a..cf45614 100644 --- a/lib/class-wp-rest-client.php +++ b/lib/class-wp-rest-client.php @@ -16,7 +16,7 @@ abstract class WP_REST_Client { * * @var WP_Post */ - private $post; + protected $post; /** * Get the client type. diff --git a/lib/class-wp-rest-oauth1-admin.php b/lib/class-wp-rest-oauth1-admin.php index f50fc09..ece6651 100644 --- a/lib/class-wp-rest-oauth1-admin.php +++ b/lib/class-wp-rest-oauth1-admin.php @@ -192,8 +192,6 @@ protected static function handle_edit_submit( $consumer ) { } if ( empty( $consumer ) ) { - ( new WP_REST_OAuth1() ); - // Create the consumer. $data = array( 'name' => $params['name'], diff --git a/lib/class-wp-rest-oauth1-client.php b/lib/class-wp-rest-oauth1-client.php index c6e58cd..41a5203 100644 --- a/lib/class-wp-rest-oauth1-client.php +++ b/lib/class-wp-rest-oauth1-client.php @@ -43,6 +43,30 @@ protected static function get_type() { return 'oauth1'; } + /** + * Delete a client. + * + * @return bool True if delete, false otherwise. + */ + public function delete() { + global $wpdb; + $results = $wpdb->get_results( "SELECT * FROM $wpdb->options WHERE option_name LIKE 'oauth1_access_%'", ARRAY_A ); + $delete_option = array(); + foreach ( $results as $result ) { + $row = unserialize( $result['option_value'] ); + if ( $this->post->ID === $row['consumer'] ) { + $delete_option[] = $result['option_name']; + } + } + + if ( (bool) wp_delete_post( $this->post->ID, true ) ) { + array_map( 'delete_option', $delete_option ); + return true; + } + + return false; + } + /** * Add extra meta to a post. * From 5788cd7217da12649bea0be2694f79cb82b58a70 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Thu, 23 Nov 2023 18:01:13 +0000 Subject: [PATCH 17/20] Fallback to get_called_class --- lib/class-wp-rest-client.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/class-wp-rest-client.php b/lib/class-wp-rest-client.php index cf45614..1617939 100644 --- a/lib/class-wp-rest-client.php +++ b/lib/class-wp-rest-client.php @@ -247,6 +247,10 @@ protected static function add_extra_meta( $meta, $params ) { //phpcs:ignore Vari */ protected static function get_called_class() { _deprecated_function( __METHOD__, '0.3.1', 'get_called_class()' ); + if ( function_exists( 'get_called_class' ) ) { + return get_called_class(); + } + // PHP 5.2 only. $backtrace = debug_backtrace(); // [0] WP_REST_Client::get_called_class() From 2fcb4c78f49751285057307913c3056ca89ba210 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Fri, 24 Nov 2023 09:17:23 +0000 Subject: [PATCH 18/20] Also delete request tokens --- lib/class-wp-rest-oauth1-client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/class-wp-rest-oauth1-client.php b/lib/class-wp-rest-oauth1-client.php index 41a5203..f0c1018 100644 --- a/lib/class-wp-rest-oauth1-client.php +++ b/lib/class-wp-rest-oauth1-client.php @@ -50,7 +50,7 @@ protected static function get_type() { */ public function delete() { global $wpdb; - $results = $wpdb->get_results( "SELECT * FROM $wpdb->options WHERE option_name LIKE 'oauth1_access_%'", ARRAY_A ); + $results = $wpdb->get_results( "SELECT * FROM $wpdb->options WHERE option_name LIKE 'oauth1_access_%' OR option_name LIKE 'oauth1_request_%'", ARRAY_A ); $delete_option = array(); foreach ( $results as $result ) { $row = unserialize( $result['option_value'] ); From 260de8524983706b15d03ce78b6fa61e33a62419 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Fri, 24 Nov 2023 10:04:56 +0000 Subject: [PATCH 19/20] Translate string in WP CLI comment --- lib/class-wp-rest-oauth1-cli.php | 68 +++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 6 deletions(-) diff --git a/lib/class-wp-rest-oauth1-cli.php b/lib/class-wp-rest-oauth1-cli.php index 5c2d620..80a3e5b 100644 --- a/lib/class-wp-rest-oauth1-cli.php +++ b/lib/class-wp-rest-oauth1-cli.php @@ -6,6 +6,8 @@ class WP_REST_OAuth1_CLI extends WP_CLI_Command { /** + * Creates a new OAuth1 Client. + * * ## OPTIONS * * [--name=] @@ -13,14 +15,68 @@ class WP_REST_OAuth1_CLI extends WP_CLI_Command { * * [--description=] * : Consumer description + * + * [--callback=] + * : Consumer callback + */ + public function add( $args, $assoc_args ) { + $consumer = WP_REST_OAuth1_Client::create( $assoc_args ); + if ( is_wp_error( $consumer ) ) { + WP_CLI::error( $consumer ); + } + + WP_CLI::line( + sprintf( + /* translators: %d: client ID **/ + __( 'ID: %d', 'rest_oauth1' ), + $consumer->ID + ) + ); + WP_CLI::line( + sprintf( + /* translators: %d: client key **/ + __( 'Key: %s', 'rest_oauth1' ), + $consumer->key + ) + ); + WP_CLI::line( + sprintf( + /* translators: %d: client secret **/ + __( 'Secret: %s', 'rest_oauth1' ), + $consumer->secret + ) + ); + } + + /** + * Delete a new OAuth1 Client. + * + * ## OPTIONS + * + * + * : Database ID for the client. */ - public function add( $_, $args ) { - $consumer = WP_REST_OAuth1_Client::create( $args ); + public function delete( $args ) { + $consumer = WP_REST_OAuth1_Client::get( $args[0] ); if ( is_wp_error( $consumer ) ) { - WP_CLI::Error( $consumer ); + WP_CLI::error( $consumer ); + } + if ( ! $consumer->delete() ) { + WP_CLI::error( + sprintf( + /* translators: %d: client ID **/ + __( 'Unable to delete client with ID: %d', 'rest_oauth1' ), + $consumer->ID + ) + ); } - WP_CLI::line( sprintf( 'ID: %d', $consumer->ID ) ); - WP_CLI::line( sprintf( 'Key: %s', $consumer->key ) ); - WP_CLI::line( sprintf( 'Secret: %s', $consumer->secret ) ); + + WP_CLI::success( + sprintf( + /* translators: %d: client ID **/ + __( 'Client deleted with ID: %d', 'rest_oauth1' ), + $consumer->ID + ) + ); } } From e1850a1d46fa0c3f592c90eb4a1d5ed54f2ab186 Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Fri, 24 Nov 2023 10:10:13 +0000 Subject: [PATCH 20/20] Update version number --- lib/class-wp-rest-client.php | 4 ++-- lib/class-wp-rest-oauth1-client.php | 2 ++ lib/class-wp-rest-oauth1.php | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/class-wp-rest-client.php b/lib/class-wp-rest-client.php index 1617939..b3459e0 100644 --- a/lib/class-wp-rest-client.php +++ b/lib/class-wp-rest-client.php @@ -242,11 +242,11 @@ protected static function add_extra_meta( $meta, $params ) { //phpcs:ignore Vari /** * Shim for get_called_class() for PHP 5.2 * - * @deprecated 0.3.1 + * @deprecated 0.4.0 * @return string Class name. */ protected static function get_called_class() { - _deprecated_function( __METHOD__, '0.3.1', 'get_called_class()' ); + _deprecated_function( __METHOD__, '0.4.0', 'get_called_class()' ); if ( function_exists( 'get_called_class' ) ) { return get_called_class(); } diff --git a/lib/class-wp-rest-oauth1-client.php b/lib/class-wp-rest-oauth1-client.php index f0c1018..698ed6a 100644 --- a/lib/class-wp-rest-oauth1-client.php +++ b/lib/class-wp-rest-oauth1-client.php @@ -46,6 +46,8 @@ protected static function get_type() { /** * Delete a client. * + * @since 0.4.0 + * * @return bool True if delete, false otherwise. */ public function delete() { diff --git a/lib/class-wp-rest-oauth1.php b/lib/class-wp-rest-oauth1.php index 1ad8d61..1226731 100644 --- a/lib/class-wp-rest-oauth1.php +++ b/lib/class-wp-rest-oauth1.php @@ -784,6 +784,8 @@ public function join_with_equals_sign( $params, $query_params = array(), $key = * Normalize each parameter by assuming each parameter may have already been encoded, so attempt to decode, and then * re-encode according to RFC 3986 * + * @since 0.4.0 + * * @see rawurlencode() * @param array $params Parameters to normalize. */ @@ -812,7 +814,7 @@ protected function normalize_parameter( array $params ) { * @param string $value Value, passed by reference. */ protected function normalize_parameters( &$key, &$value ) { - _deprecated_function( __METHOD__, '0.3.1', 'WP_REST_OAuth1::normalize_parameter()' ); + _deprecated_function( __METHOD__, '0.4.0', 'WP_REST_OAuth1::normalize_parameter()' ); $key = self::urlencode_rfc3986( rawurldecode( $key ) ); $value = self::urlencode_rfc3986( rawurldecode( $value ) ); }
post_title ); ?>