| @@ -20,9 +20,8 @@ | ||
| 20 | 20 | */ |
| 21 | 21 | public static function init() { |
| 22 | 22 | add_filter( 'jetpack_xmlrpc_unauthenticated_methods', array( __CLASS__, 'xmlrpc_methods' ) ); |
| 23 | 23 | add_filter( 'jetpack_xmlrpc_test_connection_response', array( __CLASS__, 'test_connection' ) ); |
| 24 | - add_filter( 'jetpack_remote_xmlrpc_provision_response', array( __CLASS__, 'remote_provision_response' ), 10, 2 ); | |
| 25 | 24 | add_action( 'jetpack_xmlrpc_server_event', array( __CLASS__, 'jetpack_xmlrpc_server_event' ), 10, 4 ); |
| 26 | 25 | add_action( 'jetpack_remote_connect_end', array( __CLASS__, 'remote_connect_end' ) ); |
| 27 | 26 | add_filter( 'jetpack_xmlrpc_remote_register_redirect_uri', array( __CLASS__, 'remote_register_redirect_uri' ) ); |
| 28 | 27 | } |
| @@ -44,8 +43,10 @@ | ||
| 44 | 43 | |
| 45 | 44 | /** |
| 46 | 45 | * Returns what features are available. Uses the slug of the module files. |
| 47 | 46 | * |
| 47 | + * @deprecated 13.9 | |
| 48 | + * @see Jetpack_Core_Json_Api_Endpoints::get_features_available() | |
| 48 | 49 | * @return array |
| 49 | 50 | */ |
| 50 | 51 | public static function features_available() { |
| 51 | 52 | $raw_modules = Jetpack::get_available_modules(); |
| @@ -59,8 +60,10 @@ | ||
| 59 | 60 | |
| 60 | 61 | /** |
| 61 | 62 | * Returns what features are enabled. Uses the slug of the modules files. |
| 62 | 63 | * |
| 64 | + * @deprecated 13.9 | |
| 65 | + * @see Jetpack_Core_Json_Api_Endpoints::get_features_enabled() | |
| 63 | 66 | * @return array |
| 64 | 67 | */ |
| 65 | 68 | public static function features_enabled() { |
| 66 | 69 | $raw_modules = Jetpack::get_active_modules(); |
| @@ -112,9 +115,9 @@ | ||
| 112 | 115 | $verify_api_user_args = $args[1]; |
| 113 | 116 | |
| 114 | 117 | $method = (string) $json_api_args[0]; |
| 115 | 118 | $url = (string) $json_api_args[1]; |
| 116 | - $post_body = $json_api_args[2] === null ? null : (string) $json_api_args[2]; | |
| 119 | + $post_body = is_scalar( $json_api_args[2] ) ? (string) $json_api_args[2] : null; | |
| 117 | 120 | $user_details = (array) $json_api_args[4]; |
| 118 | 121 | $locale = (string) $json_api_args[5]; |
| 119 | 122 | |
| 120 | 123 | if ( ! $verify_api_user_args ) { |
| @@ -133,29 +136,8 @@ | ||
| 133 | 136 | return false; |
| 134 | 137 | } |
| 135 | 138 | } |
| 136 | 139 | |
| 137 | - if ( 'en' !== $locale ) { | |
| 138 | - // .org mo files are named slightly different from .com, and all we have is this the locale -- try to guess them. | |
| 139 | - $new_locale = $locale; | |
| 140 | - if ( str_contains( $locale, '-' ) ) { | |
| 141 | - $locale_pieces = explode( '-', $locale ); | |
| 142 | - $new_locale = $locale_pieces[0]; | |
| 143 | - $new_locale .= ( ! empty( $locale_pieces[1] ) ) ? '_' . strtoupper( $locale_pieces[1] ) : ''; | |
| 144 | - } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found | |
| 145 | - // .com might pass 'fr' because thats what our language files are named as, where core seems | |
| 146 | - // to do fr_FR - so try that if we don't think we can load the file. | |
| 147 | - if ( ! file_exists( WP_LANG_DIR . '/' . $locale . '.mo' ) ) { | |
| 148 | - $new_locale = $locale . '_' . strtoupper( $locale ); | |
| 149 | - } | |
| 150 | - } | |
| 151 | - | |
| 152 | - if ( file_exists( WP_LANG_DIR . '/' . $new_locale . '.mo' ) ) { | |
| 153 | - unload_textdomain( 'default' ); | |
| 154 | - load_textdomain( 'default', WP_LANG_DIR . '/' . $new_locale . '.mo' ); | |
| 155 | - } | |
| 156 | - } | |
| 157 | - | |
| 158 | 140 | $old_user = wp_get_current_user(); |
| 159 | 141 | wp_set_current_user( $user_id ); |
| 160 | 142 | |
| 161 | 143 | if ( $user_id ) { |
| @@ -161,9 +143,9 @@ | ||
| 161 | 143 | if ( $user_id ) { |
| 162 | 144 | $token_key = false; |
| 163 | 145 | } else { |
| 164 | 146 | $verified = ( new Connection_Manager() )->verify_xml_rpc_signature(); |
| 165 | - $token_key = $verified['token_key']; | |
| 147 | + $token_key = $verified['token_key'] ?? false; | |
| 166 | 148 | } |
| 167 | 149 | |
| 168 | 150 | $token = ( new Tokens() )->get_access_token( $user_id, $token_key ); |
| 169 | 151 | if ( ! $token || is_wp_error( $token ) ) { |
| @@ -172,14 +154,14 @@ | ||
| 172 | 154 | |
| 173 | 155 | define( 'REST_API_REQUEST', true ); |
| 174 | 156 | define( 'WPCOM_JSON_API__BASE', 'public-api.wordpress.com/rest/v1' ); |
| 175 | 157 | |
| 176 | - // needed? | |
| 177 | - require_once ABSPATH . 'wp-admin/includes/admin.php'; | |
| 178 | - | |
| 179 | 158 | require_once JETPACK__PLUGIN_DIR . 'class.json-api.php'; |
| 180 | 159 | $api = WPCOM_JSON_API::init( $method, $url, $post_body ); |
| 181 | 160 | $api->token_details['user'] = $user_details; |
| 161 | + | |
| 162 | + $api->init_locale( $locale ); | |
| 163 | + | |
| 182 | 164 | require_once JETPACK__PLUGIN_DIR . 'class.json-api-endpoints.php'; |
| 183 | 165 | |
| 184 | 166 | $display_errors = ini_set( 'display_errors', 0 ); // phpcs:ignore WordPress.PHP.IniSet |
| 185 | 167 | ob_start(); |
| @@ -189,14 +171,14 @@ | ||
| 189 | 171 | |
| 190 | 172 | $nonce = wp_generate_password( 10, false ); |
| 191 | 173 | $hmac = hash_hmac( 'md5', $nonce . $output, $token->secret ); |
| 192 | 174 | |
| 193 | - wp_set_current_user( isset( $old_user->ID ) ? $old_user->ID : 0 ); | |
| 175 | + wp_set_current_user( $old_user->ID ?? 0 ); | |
| 194 | 176 | |
| 195 | 177 | return array( |
| 196 | 178 | (string) $output, |
| 197 | 179 | (string) $nonce, |
| 198 | - (string) $hmac, | |
| 180 | + $hmac, | |
| 199 | 181 | ); |
| 200 | 182 | } |
| 201 | 183 | |
| 202 | 184 | /** |
| @@ -205,15 +187,14 @@ | ||
| 205 | 187 | * @param array $response The response. |
| 206 | 188 | * @param array $request An array containing at minimum a nonce key and a local_username key. |
| 207 | 189 | * |
| 208 | 190 | * @since 9.8.0 |
| 191 | + * @deprecated since 13.9 | |
| 192 | + * | |
| 209 | 193 | * @return array |
| 210 | 194 | */ |
| 211 | - public static function remote_provision_response( $response, $request ) { | |
| 212 | - if ( ! empty( $request['onboarding'] ) ) { | |
| 213 | - Jetpack::create_onboarding_token(); | |
| 214 | - $response['onboarding_token'] = Jetpack_Options::get_option( 'onboarding' ); | |
| 215 | - } | |
| 195 | + public static function remote_provision_response( $response, $request ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 196 | + _deprecated_function( __METHOD__, '13.9' ); | |
| 216 | 197 | return $response; |
| 217 | 198 | } |
| 218 | 199 | |
| 219 | 200 | /** |