1
1
<?php
2
+ /**
3
+ *
4
+ * @package WordPress
5
+ * @subpackage JSON API
6
+ */
2
7
3
8
namespace WP \OAuth2 \Admin ;
4
9
@@ -47,7 +52,7 @@ function get_url( $params = [] ) {
47
52
* @return string One of 'add', 'edit', 'delete', or '' for default (list)
48
53
*/
49
54
function get_page_action () {
50
- return isset ( $ _GET ['action ' ] ) ? $ _GET ['action ' ] : '' ; // WPCS: CSRF OK
55
+ return isset ( $ _GET ['action ' ] ) ? sanitize_text_field ( wp_unslash ( $ _GET ['action ' ] ) ) : '' ; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
51
56
}
52
57
53
58
/**
@@ -75,7 +80,7 @@ function load() {
75
80
default :
76
81
global $ wp_list_table ;
77
82
78
- $ wp_list_table = new ListTable ();
83
+ $ wp_list_table = new ListTable (); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
79
84
80
85
$ wp_list_table ->prepare_items ();
81
86
@@ -84,6 +89,9 @@ function load() {
84
89
85
90
}
86
91
92
+ /**
93
+ *
94
+ */
87
95
function dispatch () {
88
96
switch ( get_page_action () ) {
89
97
case 'add ' :
@@ -112,16 +120,16 @@ function render() {
112
120
113
121
if ( current_user_can ( 'create_users ' ) ) :
114
122
?>
115
- <a href="<?php echo esc_url ( get_url ( 'action=add ' ) ) ?> "
123
+ <a href="<?php echo esc_url ( get_url ( 'action=add ' ) ); ?> "
116
124
class="add-new-h2"><?php echo esc_html_x ( 'Add New ' , 'application ' , 'oauth2 ' ); ?> </a>
117
125
<?php
118
126
endif ;
119
127
?>
120
128
</h2>
121
129
<?php
122
- if ( ! empty ( $ _GET ['deleted ' ] ) ) { // WPCS: CSRF OK
130
+ if ( ! empty ( $ _GET ['deleted ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
123
131
echo '<div id="message" class="updated"><p> ' . esc_html__ ( 'Deleted application. ' , 'oauth2 ' ) . '</p></div> ' ;
124
- } elseif ( ! empty ( $ _GET ['approved ' ] ) ) { // WPCS: CSRF OK
132
+ } elseif ( ! empty ( $ _GET ['approved ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
125
133
echo '<div id="message" class="updated"><p> ' . esc_html__ ( 'Approved application. ' , 'oauth2 ' ) . '</p></div> ' ;
126
134
}
127
135
?>
@@ -130,7 +138,7 @@ class="add-new-h2"><?php echo esc_html_x( 'Add New', 'application', 'oauth2' );
130
138
131
139
<form action="" method="get">
132
140
133
- <?php $ wp_list_table ->search_box ( __ ( 'Search Applications ' , 'oauth2 ' ), 'oauth2 ' ); ?>
141
+ <?php $ wp_list_table ->search_box ( esc_html__ ( 'Search Applications ' , 'oauth2 ' ), 'oauth2 ' ); ?>
134
142
135
143
<?php $ wp_list_table ->display (); ?>
136
144
@@ -152,22 +160,22 @@ function validate_parameters( $params ) {
152
160
$ valid = [];
153
161
154
162
if ( empty ( $ params ['name ' ] ) ) {
155
- return new WP_Error ( 'rest_oauth2_missing_name ' , __ ( 'Client name is required ' , 'oauth2 ' ) );
163
+ return new WP_Error ( 'rest_oauth2_missing_name ' , esc_html__ ( 'Client name is required ' , 'oauth2 ' ) );
156
164
}
157
165
$ valid ['name ' ] = wp_kses_post ( $ params ['name ' ] );
158
166
159
167
if ( empty ( $ params ['description ' ] ) ) {
160
- return new WP_Error ( 'rest_oauth2_missing_description ' , __ ( 'Client description is required ' , 'oauth2 ' ) );
168
+ return new WP_Error ( 'rest_oauth2_missing_description ' , esc_html__ ( 'Client description is required ' , 'oauth2 ' ) );
161
169
}
162
170
$ valid ['description ' ] = wp_kses_post ( $ params ['description ' ] );
163
171
164
172
if ( empty ( $ params ['type ' ] ) ) {
165
- return new WP_Error ( 'rest_oauth2_missing_type ' , __ ( 'Type is required. ' , 'oauth2 ' ) );
173
+ return new WP_Error ( 'rest_oauth2_missing_type ' , esc_html__ ( 'Type is required. ' , 'oauth2 ' ) );
166
174
}
167
175
$ valid ['type ' ] = wp_kses_post ( $ params ['type ' ] );
168
176
169
177
if ( empty ( $ params ['callback ' ] ) ) {
170
- return new WP_Error ( 'rest_oauth2_missing_callback ' , __ ( 'Client callback is required and must be a valid URL. ' , 'oauth2 ' ) );
178
+ return new WP_Error ( 'rest_oauth2_missing_callback ' , esc_html__ ( 'Client callback is required and must be a valid URL. ' , 'oauth2 ' ) );
171
179
}
172
180
if ( ! empty ( $ params ['callback ' ] ) ) {
173
181
$ valid ['callback ' ] = $ params ['callback ' ];
@@ -252,7 +260,7 @@ function handle_edit_submit( Client $consumer = null ) {
252
260
*/
253
261
function render_edit_page () {
254
262
if ( ! current_user_can ( 'edit_users ' ) ) {
255
- wp_die ( __ ( 'You do not have permission to access this page. ' , 'oauth2 ' ) );
263
+ wp_die ( esc_html__ ( 'You do not have permission to access this page. ' , 'oauth2 ' ) );
256
264
}
257
265
258
266
// Are we editing?
@@ -263,17 +271,21 @@ function render_edit_page() {
263
271
$ id = absint ( $ _REQUEST ['id ' ] );
264
272
$ consumer = Client::get_by_post_id ( $ id );
265
273
if ( is_wp_error ( $ consumer ) || empty ( $ consumer ) ) {
266
- wp_die ( __ ( 'Invalid client ID. ' , 'oauth2 ' ) );
274
+ wp_die ( esc_html__ ( 'Invalid client ID. ' , 'oauth2 ' ) );
267
275
}
268
276
269
- $ form_action = get_url ( [
270
- 'action ' => 'edit ' ,
271
- 'id ' => $ id ,
272
- ] );
273
- $ regenerate_action = get_url ( [
274
- 'action ' => 'regenerate ' ,
275
- 'id ' => $ id ,
276
- ] );
277
+ $ form_action = get_url (
278
+ [
279
+ 'action ' => 'edit ' ,
280
+ 'id ' => $ id ,
281
+ ]
282
+ );
283
+ $ regenerate_action = get_url (
284
+ [
285
+ 'action ' => 'regenerate ' ,
286
+ 'id ' => $ id ,
287
+ ]
288
+ );
277
289
}
278
290
279
291
// Handle form submission
@@ -292,15 +304,15 @@ function render_edit_page() {
292
304
if ( ! empty ( $ _GET ['did_action ' ] ) ) {
293
305
switch ( $ _GET ['did_action ' ] ) {
294
306
case 'edit ' :
295
- $ messages [] = __ ( 'Updated application. ' , 'oauth2 ' );
307
+ $ messages [] = esc_html__ ( 'Updated application. ' , 'oauth2 ' );
296
308
break ;
297
309
298
310
case 'regenerate ' :
299
- $ messages [] = __ ( 'Regenerated secret. ' , 'oauth2 ' );
311
+ $ messages [] = esc_html__ ( 'Regenerated secret. ' , 'oauth2 ' );
300
312
break ;
301
313
302
314
default :
303
- $ messages [] = __ ( 'Successfully created application. ' , 'oauth2 ' );
315
+ $ messages [] = esc_html__ ( 'Successfully created application. ' , 'oauth2 ' );
304
316
break ;
305
317
}
306
318
}
@@ -324,15 +336,17 @@ function render_edit_page() {
324
336
325
337
// Header time!
326
338
global $ title , $ parent_file , $ submenu_file ;
327
- $ title = $ consumer ? __ ( 'Edit Application ' , 'oauth2 ' ) : __ ( 'Add Application ' , 'oauth2 ' );
339
+ // phpcs:disable WordPress.WP.GlobalVariablesOverride.Prohibited
340
+ $ title = $ consumer ? esc_html__ ( 'Edit Application ' , 'oauth2 ' ) : esc_html__ ( 'Add Application ' , 'oauth2 ' );
328
341
$ parent_file = 'users.php ' ;
329
342
$ submenu_file = BASE_SLUG ;
343
+ // phpcs:enable
330
344
331
345
include ( ABSPATH . 'wp-admin/admin-header.php ' );
332
346
?>
333
347
334
348
<div class="wrap">
335
- <h2 id="edit-site"><?php echo esc_html ( $ title ) ?> </h2>
349
+ <h2 id="edit-site"><?php echo esc_html ( $ title ); ?> </h2>
336
350
337
351
<?php
338
352
if ( ! empty ( $ messages ) ) {
@@ -342,28 +356,28 @@ function render_edit_page() {
342
356
}
343
357
?>
344
358
345
- <form method="post" action="<?php echo esc_url ( $ form_action ) ?> ">
359
+ <form method="post" action="<?php echo esc_url ( $ form_action ); ?> ">
346
360
<table class="form-table">
347
361
<tr>
348
362
<th scope="row">
349
- <label for="oauth-name"><?php echo esc_html_x ( 'Client Name ' , 'field name ' , 'oauth2 ' ) ?> </label>
363
+ <label for="oauth-name"><?php echo esc_html_x ( 'Client Name ' , 'field name ' , 'oauth2 ' ); ?> </label>
350
364
</th>
351
365
<td>
352
- <input type="text" class="regular-text" name="name" id="oauth-name" value="<?php echo esc_attr ( $ data ['name ' ] ) ?> "/>
353
- <p class="description"><?php esc_html_e ( 'This is shown to users during authorization and in their profile. ' , 'oauth2 ' ) ?> </p>
366
+ <input type="text" class="regular-text" name="name" id="oauth-name" value="<?php echo esc_attr ( $ data ['name ' ] ); ?> "/>
367
+ <p class="description"><?php esc_html_e ( 'This is shown to users during authorization and in their profile. ' , 'oauth2 ' ); ?> </p>
354
368
</td>
355
369
</tr>
356
370
<tr>
357
371
<th scope="row">
358
- <label for="oauth-description"><?php echo esc_html_x ( 'Description ' , 'field name ' , 'oauth2 ' ) ?> </label>
372
+ <label for="oauth-description"><?php echo esc_html_x ( 'Description ' , 'field name ' , 'oauth2 ' ); ?> </label>
359
373
</th>
360
374
<td>
361
- <textarea class="regular-text" name="description" id="oauth-description" cols="30" rows="5" style="width: 500px"><?php echo esc_textarea ( $ data ['description ' ] ) ?> </textarea>
375
+ <textarea class="regular-text" name="description" id="oauth-description" cols="30" rows="5" style="width: 500px"><?php echo esc_textarea ( $ data ['description ' ] ); ?> </textarea>
362
376
</td>
363
377
</tr>
364
378
<tr>
365
379
<th scope="row">
366
- <?php echo esc_html_x ( 'Type ' , 'field name ' , 'oauth2 ' ) ?>
380
+ <?php echo esc_html_x ( 'Type ' , 'field name ' , 'oauth2 ' ); ?>
367
381
</th>
368
382
<td>
369
383
<ul>
@@ -412,11 +426,11 @@ function render_edit_page() {
412
426
</tr>
413
427
<tr>
414
428
<th scope="row">
415
- <label for="oauth-callback"><?php echo esc_html_x ( 'Callback ' , 'field name ' , 'oauth2 ' ) ?> </label>
429
+ <label for="oauth-callback"><?php echo esc_html_x ( 'Callback ' , 'field name ' , 'oauth2 ' ); ?> </label>
416
430
</th>
417
431
<td>
418
- <input type="text" class="regular-text" name="callback" id="oauth-callback" value="<?php echo esc_attr ( $ data ['callback ' ] ) ?> "/>
419
- <p class="description"><?php esc_html_e ( "Your application's callback URI or a list of comma separated URIs. The callback passed with the request token must match the scheme, host, port, and path of this URL. " , 'oauth2 ' ) ?> </p>
432
+ <input type="text" class="regular-text" name="callback" id="oauth-callback" value="<?php echo esc_attr ( $ data ['callback ' ] ); ?> "/>
433
+ <p class="description"><?php esc_html_e ( "Your application's callback URI or a list of comma separated URIs. The callback passed with the request token must match the scheme, host, port, and path of this URL. " , 'oauth2 ' ); ?> </p>
420
434
</td>
421
435
</tr>
422
436
</table>
@@ -425,42 +439,42 @@ function render_edit_page() {
425
439
426
440
if ( empty ( $ consumer ) ) {
427
441
wp_nonce_field ( 'rest-oauth2-add ' );
428
- submit_button ( __ ( 'Create Client ' , 'oauth2 ' ) );
442
+ submit_button ( esc_html__ ( 'Create Client ' , 'oauth2 ' ) );
429
443
} else {
430
444
echo '<input type="hidden" name="id" value=" ' . esc_attr ( $ consumer ->get_post_id () ) . '" /> ' ;
431
445
wp_nonce_field ( 'rest-oauth2-edit- ' . $ consumer ->get_post_id () );
432
- submit_button ( __ ( 'Save Client ' , 'oauth2 ' ) );
446
+ submit_button ( esc_html__ ( 'Save Client ' , 'oauth2 ' ) );
433
447
}
434
448
435
449
?>
436
450
</form>
437
451
438
452
<?php if ( ! empty ( $ consumer ) ) : ?>
439
- <form method="post" action="<?php echo esc_url ( $ regenerate_action ) ?> ">
440
- <h3><?php esc_html_e ( 'OAuth Credentials ' , 'oauth2 ' ) ?> </h3>
453
+ <form method="post" action="<?php echo esc_url ( $ regenerate_action ); ?> ">
454
+ <h3><?php esc_html_e ( 'OAuth Credentials ' , 'oauth2 ' ); ?> </h3>
441
455
442
456
<table class="form-table">
443
457
<tr>
444
458
<th scope="row">
445
- <?php esc_html_e ( 'Client Key ' , 'oauth2 ' ) ?>
459
+ <?php esc_html_e ( 'Client Key ' , 'oauth2 ' ); ?>
446
460
</th>
447
461
<td>
448
- <code><?php echo esc_html ( $ consumer ->get_id () ) ?> </code>
462
+ <code><?php echo esc_html ( $ consumer ->get_id () ); ?> </code>
449
463
</td>
450
464
</tr>
451
465
<tr>
452
466
<th scope="row">
453
- <?php esc_html_e ( 'Client Secret ' , 'oauth2 ' ) ?>
467
+ <?php esc_html_e ( 'Client Secret ' , 'oauth2 ' ); ?>
454
468
</th>
455
469
<td>
456
- <code><?php echo esc_html ( $ consumer ->get_secret () ) ?> </code>
470
+ <code><?php echo esc_html ( $ consumer ->get_secret () ); ?> </code>
457
471
</td>
458
472
</tr>
459
473
</table>
460
474
461
475
<?php
462
476
wp_nonce_field ( 'rest-oauth2-regenerate: ' . $ consumer ->get_post_id () );
463
- submit_button ( __ ( 'Regenerate Secret ' , 'oauth2 ' ), 'delete ' );
477
+ submit_button ( esc_html__ ( 'Regenerate Secret ' , 'oauth2 ' ), 'delete ' );
464
478
?>
465
479
</form>
466
480
<?php endif ?>
@@ -482,22 +496,21 @@ function handle_delete() {
482
496
483
497
if ( ! current_user_can ( 'delete_post ' , $ id ) ) {
484
498
wp_die (
485
- '<h1> ' . __ ( 'Cheatin’ uh? ' , 'oauth2 ' ) . '</h1> ' .
486
- '<p> ' . __ ( 'You are not allowed to delete this application. ' , 'oauth2 ' ) . '</p> ' ,
499
+ '<h1> ' . esc_html__ ( 'Cheatin’ uh? ' , 'oauth2 ' ) . '</h1> ' .
500
+ '<p> ' . esc_html__ ( 'You are not allowed to delete this application. ' , 'oauth2 ' ) . '</p> ' ,
487
501
403
488
502
);
489
503
}
490
504
491
505
$ client = Client::get_by_post_id ( $ id );
492
506
if ( is_wp_error ( $ client ) ) {
493
- wp_die ( $ client );
507
+ wp_die ( $ client ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
494
508
495
509
return ;
496
510
}
497
511
498
512
if ( ! $ client ->delete () ) {
499
- $ message = 'Invalid client ID ' ;
500
- wp_die ( $ message );
513
+ wp_die ( esc_html__ ( 'Invalid client ID ' ) );
501
514
502
515
return ;
503
516
}
@@ -519,20 +532,20 @@ function handle_approve() {
519
532
520
533
if ( ! current_user_can ( 'publish_post ' , $ id ) ) {
521
534
wp_die (
522
- '<h1> ' . __ ( 'Cheatin’ uh? ' , 'oauth2 ' ) . '</h1> ' .
523
- '<p> ' . __ ( 'You are not allowed to approve this application. ' , 'oauth2 ' ) . '</p> ' ,
535
+ '<h1> ' . esc_html__ ( 'Cheatin’ uh? ' , 'oauth2 ' ) . '</h1> ' .
536
+ '<p> ' . esc_html__ ( 'You are not allowed to approve this application. ' , 'oauth2 ' ) . '</p> ' ,
524
537
403
525
538
);
526
539
}
527
540
528
541
$ client = Client::get_by_post_id ( $ id );
529
542
if ( is_wp_error ( $ client ) ) {
530
- wp_die ( $ client );
543
+ wp_die ( $ client ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
531
544
}
532
545
533
546
$ did_approve = $ client ->approve ();
534
547
if ( is_wp_error ( $ did_approve ) ) {
535
- wp_die ( $ did_approve );
548
+ wp_die ( $ did_approve ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
536
549
}
537
550
538
551
wp_safe_redirect ( get_url ( 'approved=1 ' ) );
@@ -552,22 +565,26 @@ function handle_regenerate() {
552
565
553
566
if ( ! current_user_can ( 'edit_post ' , $ id ) ) {
554
567
wp_die (
555
- '<h1> ' . __ ( 'Cheatin’ uh? ' , 'oauth2 ' ) . '</h1> ' .
556
- '<p> ' . __ ( 'You are not allowed to edit this application. ' , 'oauth2 ' ) . '</p> ' ,
568
+ '<h1> ' . esc_html__ ( 'Cheatin’ uh? ' , 'oauth2 ' ) . '</h1> ' .
569
+ '<p> ' . esc_html__ ( 'You are not allowed to edit this application. ' , 'oauth2 ' ) . '</p> ' ,
557
570
403
558
571
);
559
572
}
560
573
561
574
$ client = Client::get_by_post_id ( $ id );
562
575
$ result = $ client ->regenerate_secret ();
563
576
if ( is_wp_error ( $ result ) ) {
564
- wp_die ( $ result ->get_error_message () );
577
+ wp_die ( esc_html ( $ result ->get_error_message () ) );
565
578
}
566
579
567
- wp_safe_redirect ( get_url ( [
568
- 'action ' => 'edit ' ,
569
- 'id ' => $ id ,
570
- 'did_action ' => 'regenerate ' ,
571
- ] ) );
580
+ wp_safe_redirect (
581
+ get_url (
582
+ [
583
+ 'action ' => 'edit ' ,
584
+ 'id ' => $ id ,
585
+ 'did_action ' => 'regenerate ' ,
586
+ ]
587
+ )
588
+ );
572
589
exit ;
573
590
}
0 commit comments