Skip to content

Commit ef26b76

Browse files
Add localization domain to translatable strings
1 parent 630341a commit ef26b76

6 files changed

+44
-44
lines changed

lib/class-wp-rest-client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static function get_by_key( $key ) {
151151
) );
152152

153153
if ( empty( $consumers ) || empty( $consumers[0] ) ) {
154-
return new WP_Error( 'json_consumer_notfound', __( 'Consumer Key is invalid' ), array( 'status' => 401 ) );
154+
return new WP_Error( 'json_consumer_notfound', __( 'Consumer Key is invalid', 'rest_oauth1' ), array( 'status' => 401 ) );
155155
}
156156

157157
return $consumers[0];

lib/class-wp-rest-oauth1-admin.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ protected static function handle_edit_submit( $consumer ) {
227227
*/
228228
public static function render_edit_page() {
229229
if ( ! current_user_can( 'edit_users' ) ) {
230-
wp_die( __( 'You do not have permission to access this page.' ) );
230+
wp_die( __( 'You do not have permission to access this page.', 'rest_oauth1' ) );
231231
}
232232

233233
// Are we editing?
@@ -237,7 +237,7 @@ public static function render_edit_page() {
237237
$id = absint( $_REQUEST['id'] );
238238
$consumer = WP_REST_OAuth1_Client::get( $id );
239239
if ( is_wp_error( $consumer ) || empty( $consumer ) ) {
240-
wp_die( __( 'Invalid consumer ID.' ) );
240+
wp_die( __( 'Invalid consumer ID.', 'rest_oauth1' ) );
241241
}
242242

243243
$form_action = self::get_url( array( 'action' => 'edit', 'id' => $id ) );
@@ -301,18 +301,18 @@ public static function render_edit_page() {
301301
<table class="form-table">
302302
<tr>
303303
<th scope="row">
304-
<label for="oauth-name"><?php echo esc_html_x( 'Consumer Name', 'field name' ) ?></label>
304+
<label for="oauth-name"><?php echo esc_html_x( 'Consumer Name', 'field name', 'rest_oauth1' ) ?></label>
305305
</th>
306306
<td>
307307
<input type="text" class="regular-text"
308308
name="name" id="oauth-name"
309309
value="<?php echo esc_attr( $data['name'] ) ?>" />
310-
<p class="description"><?php echo esc_html( 'This is shown to users during authorization and in their profile.' ) ?></p>
310+
<p class="description"><?php esc_html_e( 'This is shown to users during authorization and in their profile.', 'rest_oauth1' ) ?></p>
311311
</td>
312312
</tr>
313313
<tr>
314314
<th scope="row">
315-
<label for="oauth-description"><?php echo esc_html_x( 'Description', 'field name' ) ?></label>
315+
<label for="oauth-description"><?php echo esc_html_x( 'Description', 'field name', 'rest_oauth1' ) ?></label>
316316
</th>
317317
<td>
318318
<textarea class="regular-text" name="description" id="oauth-description"
@@ -321,13 +321,13 @@ public static function render_edit_page() {
321321
</tr>
322322
<tr>
323323
<th scope="row">
324-
<label for="oauth-callback"><?php echo esc_html_x( 'Callback', 'field name' ) ?></label>
324+
<label for="oauth-callback"><?php echo esc_html_x( 'Callback', 'field name', 'rest_oauth1' ) ?></label>
325325
</th>
326326
<td>
327327
<input type="text" class="regular-text"
328328
name="callback" id="oauth-callback"
329329
value="<?php echo esc_attr( $data['callback'] ) ?>" />
330-
<p class="description"><?php echo esc_html( "Your application's callback URL. The callback passed with the request token must match the scheme, host, port, and path of this URL." ) ?></p>
330+
<p class="description"><?php esc_html_e( "Your application's callback URL. The callback passed with the request token must match the scheme, host, port, and path of this URL.", 'rest_oauth1' ) ?></p>
331331
</td>
332332
</tr>
333333
</table>
@@ -336,12 +336,12 @@ public static function render_edit_page() {
336336

337337
if ( empty( $consumer ) ) {
338338
wp_nonce_field( 'rest-oauth1-add' );
339-
submit_button( __( 'Add Consumer' ) );
339+
submit_button( __( 'Add Consumer', 'rest_oauth1' ) );
340340
}
341341
else {
342342
echo '<input type="hidden" name="id" value="' . esc_attr( $consumer->ID ) . '" />';
343343
wp_nonce_field( 'rest-oauth1-edit-' . $consumer->ID );
344-
submit_button( __( 'Save Consumer' ) );
344+
submit_button( __( 'Save Consumer', 'rest_oauth1' ) );
345345
}
346346

347347
?>
@@ -354,15 +354,15 @@ public static function render_edit_page() {
354354
<table class="form-table">
355355
<tr>
356356
<th scope="row">
357-
<?php echo esc_html__( 'Client Key', 'rest_oauth1' ) ?>
357+
<?php esc_html_e( 'Client Key', 'rest_oauth1' ) ?>
358358
</th>
359359
<td>
360360
<code><?php echo esc_html( $consumer->key ) ?></code>
361361
</td>
362362
</tr>
363363
<tr>
364364
<th scope="row">
365-
<?php echo esc_html__( 'Client Secret', 'rest_oauth1' ) ?>
365+
<?php esc_html_e( 'Client Secret', 'rest_oauth1' ) ?>
366366
</th>
367367
<td>
368368
<code><?php echo esc_html( $consumer->secret ) ?></code>
@@ -391,8 +391,8 @@ public static function handle_delete() {
391391

392392
if ( ! current_user_can( 'delete_post', $id ) ) {
393393
wp_die(
394-
'<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
395-
'<p>' . __( 'You are not allowed to delete this application.' ) . '</p>',
394+
'<h1>' . __( 'Cheatin&#8217; uh?', 'rest_oauth1' ) . '</h1>' .
395+
'<p>' . __( 'You are not allowed to delete this application.', 'rest_oauth1' ) . '</p>',
396396
403
397397
);
398398
}
@@ -423,8 +423,8 @@ public static function handle_regenerate() {
423423

424424
if ( ! current_user_can( 'edit_post', $id ) ) {
425425
wp_die(
426-
'<h1>' . __( 'Cheatin&#8217; uh?' ) . '</h1>' .
427-
'<p>' . __( 'You are not allowed to edit this application.' ) . '</p>',
426+
'<h1>' . __( 'Cheatin&#8217; uh?', 'rest_oauth1' ) . '</h1>' .
427+
'<p>' . __( 'You are not allowed to edit this application.', 'rest_oauth1' ) . '</p>',
428428
403
429429
);
430430
}

lib/class-wp-rest-oauth1-listtable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public function prepare_items() {
3333
public function get_columns() {
3434
$c = array(
3535
'cb' => '<input type="checkbox" />',
36-
'name' => __( 'Name' ),
37-
'description' => __( 'Description' ),
36+
'name' => __( 'Name', 'rest_oauth1' ),
37+
'description' => __( 'Description', 'rest_oauth1' ),
3838
);
3939

4040
return $c;

lib/class-wp-rest-oauth1-ui.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function handle_request() {
5858
public function render_page() {
5959
// Check required fields
6060
if ( empty( $_REQUEST['oauth_token'] ) ) {
61-
return new WP_Error( 'json_oauth1_missing_param', sprintf( __( 'Missing parameter %s' ), 'oauth_token' ), array( 'status' => 400 ) );
61+
return new WP_Error( 'json_oauth1_missing_param', sprintf( __( 'Missing parameter %s', 'rest_oauth1' ), 'oauth_token' ), array( 'status' => 400 ) );
6262
}
6363

6464
// Set up fields
@@ -105,7 +105,7 @@ public function render_page() {
105105
exit;
106106

107107
default:
108-
return new WP_Error( 'json_oauth1_invalid_action', __( 'Invalid authorization action' ), array( 'status' => 400 ) );
108+
return new WP_Error( 'json_oauth1_invalid_action', __( 'Invalid authorization action', 'rest_oauth1' ), array( 'status' => 400 ) );
109109
}
110110
}
111111

@@ -142,8 +142,8 @@ public function handle_callback_redirect( $verifier ) {
142142

143143
if ( empty( $this->token['callback'] ) ) {
144144
// No callback registered, display verification code to the user
145-
login_header( __( 'Access Token' ) );
146-
echo '<p>' . sprintf( __( 'Your verification token is <code>%s</code>' ), $verifier ) . '</p>';
145+
login_header( __( 'Access Token', 'rest_oauth1' ) );
146+
echo '<p>' . sprintf( __( 'Your verification token is <code>%s</code>', 'rest_oauth1' ), $verifier ) . '</p>';
147147
login_footer();
148148

149149
return null;
@@ -154,7 +154,7 @@ public function handle_callback_redirect( $verifier ) {
154154
// Ensure the URL is safe to access
155155
$authenticator = new WP_REST_OAuth1();
156156
if ( ! $authenticator->check_callback( $callback, $this->token['consumer'] ) ) {
157-
return new WP_Error( 'json_oauth1_invalid_callback', __( 'The callback URL is invalid' ), array( 'status' => 400 ) );
157+
return new WP_Error( 'json_oauth1_invalid_callback', __( 'The callback URL is invalid', 'rest_oauth1' ), array( 'status' => 400 ) );
158158
}
159159

160160
$args = array(
@@ -177,7 +177,7 @@ public function handle_callback_redirect( $verifier ) {
177177
* @param WP_Error $error Error object
178178
*/
179179
public function display_error( WP_Error $error ) {
180-
login_header( __( 'Error' ), '', $error );
180+
login_header( __( 'Error', 'rest_oauth1' ), '', $error );
181181
login_footer();
182182
}
183183
}

lib/class-wp-rest-oauth1.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ public function get_parameters( $require_token = true, $extra = array() ) {
140140
if ( ! empty( $errors ) ) {
141141
$message = sprintf(
142142
_n(
143-
'Missing OAuth parameter %s',
144-
'Missing OAuth parameters %s',
143+
__( 'Missing OAuth parameter %s', 'rest_oauth1' ),
144+
__( 'Missing OAuth parameters %s', 'rest_oauth1' ),
145145
count( $errors )
146146
),
147147
implode(', ', $errors )
@@ -252,7 +252,7 @@ public function dispatch( $route ) {
252252
return $params;
253253
}
254254
if ( empty( $params ) ) {
255-
return new WP_Error( 'json_oauth1_missing_parameter', __( 'No OAuth parameters supplied' ), array( 'status' => 400 ) );
255+
return new WP_Error( 'json_oauth1_missing_parameter', __( 'No OAuth parameters supplied', 'rest_oauth1' ), array( 'status' => 400 ) );
256256
}
257257

258258
return $this->generate_request_token( $params );
@@ -264,7 +264,7 @@ public function dispatch( $route ) {
264264
return $params;
265265
}
266266
if ( empty( $params ) ) {
267-
return new WP_Error( 'json_oauth1_missing_parameter', __( 'No OAuth parameters supplied' ), array( 'status' => 400 ) );
267+
return new WP_Error( 'json_oauth1_missing_parameter', __( 'No OAuth parameters supplied', 'rest_oauth1' ), array( 'status' => 400 ) );
268268
}
269269

270270
return $this->generate_access_token(
@@ -274,7 +274,7 @@ public function dispatch( $route ) {
274274
);
275275

276276
default:
277-
return new WP_Error( 'json_oauth1_invalid_route', __( 'Route is invalid' ), array( 'status' => 404 ) );
277+
return new WP_Error( 'json_oauth1_invalid_route', __( 'Route is invalid', 'rest_oauth1' ), array( 'status' => 404 ) );
278278
}
279279
}
280280

@@ -295,7 +295,7 @@ public function check_token( $token, $consumer_key ) {
295295
}
296296

297297
if ( ! hash_equals( (string) $token['consumer'], (string) $consumer->ID ) ) {
298-
return new WP_Error( 'json_oauth1_consumer_mismatch', __( 'Token is not registered for the given consumer' ), array( 'status' => 401 ) );
298+
return new WP_Error( 'json_oauth1_consumer_mismatch', __( 'Token is not registered for the given consumer', 'rest_oauth1' ), array( 'status' => 401 ) );
299299
}
300300

301301
return array( $consumer, new WP_User( $token['user'] ) );
@@ -311,13 +311,13 @@ public function get_request_token( $key ) {
311311
$data = get_option( 'oauth1_request_' . $key, null );
312312

313313
if ( empty( $data ) ) {
314-
return new WP_Error( 'json_oauth1_invalid_token', __( 'Invalid token' ), array( 'status' => 400 ) );
314+
return new WP_Error( 'json_oauth1_invalid_token', __( 'Invalid token', 'rest_oauth1' ), array( 'status' => 400 ) );
315315
}
316316

317317
// Check expiration
318318
if ( $data['expiration'] < time() ) {
319319
$this->remove_request_token( $key );
320-
return new WP_Error( 'json_oauth1_expired_token', __( 'OAuth request token has expired' ), array( 'status' => 401 ) );
320+
return new WP_Error( 'json_oauth1_expired_token', __( 'OAuth request token has expired', 'rest_oauth1' ), array( 'status' => 401 ) );
321321
}
322322

323323
return $data;
@@ -378,7 +378,7 @@ public function set_request_token_callback( $key, $callback ) {
378378

379379
$consumer = $token['consumer'];
380380
if ( ! $this->check_callback( $callback, $consumer ) ) {
381-
return new WP_Error( 'json_oauth1_invalid_callback', __( 'Callback URL is invalid' ) );
381+
return new WP_Error( 'json_oauth1_invalid_callback', __( 'Callback URL is invalid', 'rest_oauth1' ) );
382382
}
383383

384384
$token['callback'] = $callback;
@@ -504,7 +504,7 @@ public function authorize_request_token( $key, $user = null ) {
504504
}
505505

506506
if ( empty( $user ) ) {
507-
return new WP_Error( 'json_oauth1_invalid_user', __( 'Invalid user specified for access token' ) );
507+
return new WP_Error( 'json_oauth1_invalid_user', __( 'Invalid user specified for access token', 'rest_oauth1' ) );
508508
}
509509

510510
$token['authorized'] = true;
@@ -554,11 +554,11 @@ public function generate_access_token( $oauth_consumer_key, $oauth_token, $oauth
554554

555555
// Check verification
556556
if ( $token['authorized'] !== true ) {
557-
return new WP_Error( 'json_oauth1_unauthorized_token', __( 'OAuth token has not been authorized' ), array( 'status' => 401 ) );
557+
return new WP_Error( 'json_oauth1_unauthorized_token', __( 'OAuth token has not been authorized', 'rest_oauth1' ), array( 'status' => 401 ) );
558558
}
559559

560560
if ( $oauth_verifier !== $token['verifier'] ) {
561-
return new WP_Error( 'json_oauth1_invalid_verifier', __( 'OAuth verifier does not match' ), array( 'status' => 400 ) );
561+
return new WP_Error( 'json_oauth1_invalid_verifier', __( 'OAuth verifier does not match', 'rest_oauth1' ), array( 'status' => 400 ) );
562562
}
563563

564564
$this->should_attempt = false;
@@ -600,7 +600,7 @@ public function generate_access_token( $oauth_consumer_key, $oauth_token, $oauth
600600
public function revoke_access_token( $key ) {
601601
$data = $this->get_access_token( $key );
602602
if ( empty( $data ) ) {
603-
return new WP_Error( 'json_oauth1_invalid_token', __( 'Access token does not exist' ), array( 'status' => 401 ) );
603+
return new WP_Error( 'json_oauth1_invalid_token', __( 'Access token does not exist', 'rest_oauth1' ), array( 'status' => 401 ) );
604604
}
605605

606606
delete_option( 'oauth1_access_' . $key );
@@ -652,7 +652,7 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
652652

653653
// sort parameters
654654
if ( ! uksort( $params, 'strcmp' ) )
655-
return new WP_Error( 'json_oauth1_failed_parameter_sort', __( 'Invalid Signature - failed to sort parameters' ), array( 'status' => 401 ) );
655+
return new WP_Error( 'json_oauth1_failed_parameter_sort', __( 'Invalid Signature - failed to sort parameters', 'rest_oauth1' ), array( 'status' => 401 ) );
656656

657657
$query_string = $this->create_signature_string( $params );
658658

@@ -674,13 +674,13 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
674674
break;
675675

676676
default:
677-
return new WP_Error( 'json_oauth1_invalid_signature_method', __( 'Signature method is invalid' ), array( 'status' => 401 ) );
677+
return new WP_Error( 'json_oauth1_invalid_signature_method', __( 'Signature method is invalid', 'rest_oauth1' ), array( 'status' => 401 ) );
678678
}
679679

680680
$signature = base64_encode( hash_hmac( $hash_algorithm, $string_to_sign, $key, true ) );
681681

682682
if ( ! hash_equals( $signature, $consumer_signature ) ) {
683-
return new WP_Error( 'json_oauth1_signature_mismatch', __( 'OAuth signature does not match' ), array( 'status' => 401 ) );
683+
return new WP_Error( 'json_oauth1_signature_mismatch', __( 'OAuth signature does not match', 'rest_oauth1' ), array( 'status' => 401 ) );
684684
}
685685

686686
return true;
@@ -751,15 +751,15 @@ protected function check_oauth_timestamp_and_nonce( $consumer, $timestamp, $nonc
751751
$valid_window = apply_filters( 'json_oauth1_timestamp_window', 15 * MINUTE_IN_SECONDS );
752752

753753
if ( ( $timestamp < time() - $valid_window ) || ( $timestamp > time() + $valid_window ) )
754-
return new WP_Error( 'json_oauth1_invalid_timestamp', __( 'Invalid timestamp' ), array( 'status' => 401 ) );
754+
return new WP_Error( 'json_oauth1_invalid_timestamp', __( 'Invalid timestamp', 'rest_oauth1' ), array( 'status' => 401 ) );
755755

756756
$used_nonces = $consumer->nonces;
757757

758758
if ( empty( $used_nonces ) )
759759
$used_nonces = array();
760760

761761
if ( in_array( $nonce, $used_nonces ) )
762-
return new WP_Error( 'json_oauth1_nonce_already_used', __( 'Invalid nonce - nonce has already been used' ), array( 'status' => 401 ) );
762+
return new WP_Error( 'json_oauth1_nonce_already_used', __( 'Invalid nonce - nonce has already been used', 'rest_oauth1' ), array( 'status' => 401 ) );
763763

764764
$used_nonces[ $timestamp ] = $nonce;
765765

oauth-server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ function rest_oauth1_register_rewrites() {
5252
function rest_oauth1_setup_authentication() {
5353
register_post_type( 'json_consumer', array(
5454
'labels' => array(
55-
'name' => __( 'Consumer' ),
56-
'singular_name' => __( 'Consumers' ),
55+
'name' => __( 'Consumer', 'rest_oauth1' ),
56+
'singular_name' => __( 'Consumers', 'rest_oauth1' ),
5757
),
5858
'public' => false,
5959
'hierarchical' => false,

0 commit comments

Comments
 (0)