Skip to content

Commit 3cc8036

Browse files
committed
Coding standards fixes
1 parent 213ad0d commit 3cc8036

24 files changed

+452
-196
lines changed

inc/admin/class-listtable.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
/**
3+
*
4+
* @package WordPress
5+
* @subpackage JSON API
6+
*/
27

38
namespace WP\OAuth2\Admin;
49

@@ -58,7 +63,7 @@ public function column_cb( $item ) {
5863
<label class="screen-reader-text"
5964
for="cb-select-<?php echo esc_attr( $item->ID ); ?>"><?php esc_html_e( 'Select consumer', 'oauth2' ); ?></label>
6065

61-
<input id="cb-select-<?php echo esc_attr( $item->ID ) ?>" type="checkbox"
66+
<input id="cb-select-<?php echo esc_attr( $item->ID ); ?>" type="checkbox"
6267
name="consumers[]" value="<?php echo esc_attr( $item->ID ); ?>"/>
6368

6469
<?php

inc/admin/namespace.php

Lines changed: 78 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?php
2+
/**
3+
*
4+
* @package WordPress
5+
* @subpackage JSON API
6+
*/
27

38
namespace WP\OAuth2\Admin;
49

@@ -47,7 +52,7 @@ function get_url( $params = [] ) {
4752
* @return string One of 'add', 'edit', 'delete', or '' for default (list)
4853
*/
4954
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
5156
}
5257

5358
/**
@@ -75,7 +80,7 @@ function load() {
7580
default:
7681
global $wp_list_table;
7782

78-
$wp_list_table = new ListTable();
83+
$wp_list_table = new ListTable(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
7984

8085
$wp_list_table->prepare_items();
8186

@@ -84,6 +89,9 @@ function load() {
8489

8590
}
8691

92+
/**
93+
*
94+
*/
8795
function dispatch() {
8896
switch ( get_page_action() ) {
8997
case 'add':
@@ -112,16 +120,16 @@ function render() {
112120

113121
if ( current_user_can( 'create_users' ) ) :
114122
?>
115-
<a href="<?php echo esc_url( get_url( 'action=add' ) ) ?>"
123+
<a href="<?php echo esc_url( get_url( 'action=add' ) ); ?>"
116124
class="add-new-h2"><?php echo esc_html_x( 'Add New', 'application', 'oauth2' ); ?></a>
117125
<?php
118126
endif;
119127
?>
120128
</h2>
121129
<?php
122-
if ( ! empty( $_GET['deleted'] ) ) { // WPCS: CSRF OK
130+
if ( ! empty( $_GET['deleted'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
123131
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
125133
echo '<div id="message" class="updated"><p>' . esc_html__( 'Approved application.', 'oauth2' ) . '</p></div>';
126134
}
127135
?>
@@ -130,7 +138,7 @@ class="add-new-h2"><?php echo esc_html_x( 'Add New', 'application', 'oauth2' );
130138

131139
<form action="" method="get">
132140

133-
<?php $wp_list_table->search_box( __( 'Search Applications', 'oauth2' ), 'oauth2' ); ?>
141+
<?php $wp_list_table->search_box( esc_html__( 'Search Applications', 'oauth2' ), 'oauth2' ); ?>
134142

135143
<?php $wp_list_table->display(); ?>
136144

@@ -152,22 +160,22 @@ function validate_parameters( $params ) {
152160
$valid = [];
153161

154162
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' ) );
156164
}
157165
$valid['name'] = wp_kses_post( $params['name'] );
158166

159167
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' ) );
161169
}
162170
$valid['description'] = wp_kses_post( $params['description'] );
163171

164172
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' ) );
166174
}
167175
$valid['type'] = wp_kses_post( $params['type'] );
168176

169177
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' ) );
171179
}
172180
if ( ! empty( $params['callback'] ) ) {
173181
$valid['callback'] = $params['callback'];
@@ -252,7 +260,7 @@ function handle_edit_submit( Client $consumer = null ) {
252260
*/
253261
function render_edit_page() {
254262
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' ) );
256264
}
257265

258266
// Are we editing?
@@ -263,17 +271,21 @@ function render_edit_page() {
263271
$id = absint( $_REQUEST['id'] );
264272
$consumer = Client::get_by_post_id( $id );
265273
if ( is_wp_error( $consumer ) || empty( $consumer ) ) {
266-
wp_die( __( 'Invalid client ID.', 'oauth2' ) );
274+
wp_die( esc_html__( 'Invalid client ID.', 'oauth2' ) );
267275
}
268276

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+
);
277289
}
278290

279291
// Handle form submission
@@ -292,15 +304,15 @@ function render_edit_page() {
292304
if ( ! empty( $_GET['did_action'] ) ) {
293305
switch ( $_GET['did_action'] ) {
294306
case 'edit':
295-
$messages[] = __( 'Updated application.', 'oauth2' );
307+
$messages[] = esc_html__( 'Updated application.', 'oauth2' );
296308
break;
297309

298310
case 'regenerate':
299-
$messages[] = __( 'Regenerated secret.', 'oauth2' );
311+
$messages[] = esc_html__( 'Regenerated secret.', 'oauth2' );
300312
break;
301313

302314
default:
303-
$messages[] = __( 'Successfully created application.', 'oauth2' );
315+
$messages[] = esc_html__( 'Successfully created application.', 'oauth2' );
304316
break;
305317
}
306318
}
@@ -324,15 +336,17 @@ function render_edit_page() {
324336

325337
// Header time!
326338
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' );
328341
$parent_file = 'users.php';
329342
$submenu_file = BASE_SLUG;
343+
// phpcs:enable
330344

331345
include( ABSPATH . 'wp-admin/admin-header.php' );
332346
?>
333347

334348
<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>
336350

337351
<?php
338352
if ( ! empty( $messages ) ) {
@@ -342,28 +356,28 @@ function render_edit_page() {
342356
}
343357
?>
344358

345-
<form method="post" action="<?php echo esc_url( $form_action ) ?>">
359+
<form method="post" action="<?php echo esc_url( $form_action ); ?>">
346360
<table class="form-table">
347361
<tr>
348362
<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>
350364
</th>
351365
<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>
354368
</td>
355369
</tr>
356370
<tr>
357371
<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>
359373
</th>
360374
<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>
362376
</td>
363377
</tr>
364378
<tr>
365379
<th scope="row">
366-
<?php echo esc_html_x( 'Type', 'field name', 'oauth2' ) ?>
380+
<?php echo esc_html_x( 'Type', 'field name', 'oauth2' ); ?>
367381
</th>
368382
<td>
369383
<ul>
@@ -412,11 +426,11 @@ function render_edit_page() {
412426
</tr>
413427
<tr>
414428
<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>
416430
</th>
417431
<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>
420434
</td>
421435
</tr>
422436
</table>
@@ -425,42 +439,42 @@ function render_edit_page() {
425439

426440
if ( empty( $consumer ) ) {
427441
wp_nonce_field( 'rest-oauth2-add' );
428-
submit_button( __( 'Create Client', 'oauth2' ) );
442+
submit_button( esc_html__( 'Create Client', 'oauth2' ) );
429443
} else {
430444
echo '<input type="hidden" name="id" value="' . esc_attr( $consumer->get_post_id() ) . '" />';
431445
wp_nonce_field( 'rest-oauth2-edit-' . $consumer->get_post_id() );
432-
submit_button( __( 'Save Client', 'oauth2' ) );
446+
submit_button( esc_html__( 'Save Client', 'oauth2' ) );
433447
}
434448

435449
?>
436450
</form>
437451

438452
<?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>
441455

442456
<table class="form-table">
443457
<tr>
444458
<th scope="row">
445-
<?php esc_html_e( 'Client Key', 'oauth2' ) ?>
459+
<?php esc_html_e( 'Client Key', 'oauth2' ); ?>
446460
</th>
447461
<td>
448-
<code><?php echo esc_html( $consumer->get_id() ) ?></code>
462+
<code><?php echo esc_html( $consumer->get_id() ); ?></code>
449463
</td>
450464
</tr>
451465
<tr>
452466
<th scope="row">
453-
<?php esc_html_e( 'Client Secret', 'oauth2' ) ?>
467+
<?php esc_html_e( 'Client Secret', 'oauth2' ); ?>
454468
</th>
455469
<td>
456-
<code><?php echo esc_html( $consumer->get_secret() ) ?></code>
470+
<code><?php echo esc_html( $consumer->get_secret() ); ?></code>
457471
</td>
458472
</tr>
459473
</table>
460474

461475
<?php
462476
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' );
464478
?>
465479
</form>
466480
<?php endif ?>
@@ -482,22 +496,21 @@ function handle_delete() {
482496

483497
if ( ! current_user_can( 'delete_post', $id ) ) {
484498
wp_die(
485-
'<h1>' . __( 'Cheatin&#8217; uh?', 'oauth2' ) . '</h1>' .
486-
'<p>' . __( 'You are not allowed to delete this application.', 'oauth2' ) . '</p>',
499+
'<h1>' . esc_html__( 'Cheatin&#8217; uh?', 'oauth2' ) . '</h1>' .
500+
'<p>' . esc_html__( 'You are not allowed to delete this application.', 'oauth2' ) . '</p>',
487501
403
488502
);
489503
}
490504

491505
$client = Client::get_by_post_id( $id );
492506
if ( is_wp_error( $client ) ) {
493-
wp_die( $client );
507+
wp_die( $client ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
494508

495509
return;
496510
}
497511

498512
if ( ! $client->delete() ) {
499-
$message = 'Invalid client ID';
500-
wp_die( $message );
513+
wp_die( esc_html__( 'Invalid client ID' ) );
501514

502515
return;
503516
}
@@ -519,20 +532,20 @@ function handle_approve() {
519532

520533
if ( ! current_user_can( 'publish_post', $id ) ) {
521534
wp_die(
522-
'<h1>' . __( 'Cheatin&#8217; uh?', 'oauth2' ) . '</h1>' .
523-
'<p>' . __( 'You are not allowed to approve this application.', 'oauth2' ) . '</p>',
535+
'<h1>' . esc_html__( 'Cheatin&#8217; uh?', 'oauth2' ) . '</h1>' .
536+
'<p>' . esc_html__( 'You are not allowed to approve this application.', 'oauth2' ) . '</p>',
524537
403
525538
);
526539
}
527540

528541
$client = Client::get_by_post_id( $id );
529542
if ( is_wp_error( $client ) ) {
530-
wp_die( $client );
543+
wp_die( $client ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
531544
}
532545

533546
$did_approve = $client->approve();
534547
if ( is_wp_error( $did_approve ) ) {
535-
wp_die( $did_approve );
548+
wp_die( $did_approve ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
536549
}
537550

538551
wp_safe_redirect( get_url( 'approved=1' ) );
@@ -552,22 +565,26 @@ function handle_regenerate() {
552565

553566
if ( ! current_user_can( 'edit_post', $id ) ) {
554567
wp_die(
555-
'<h1>' . __( 'Cheatin&#8217; uh?', 'oauth2' ) . '</h1>' .
556-
'<p>' . __( 'You are not allowed to edit this application.', 'oauth2' ) . '</p>',
568+
'<h1>' . esc_html__( 'Cheatin&#8217; uh?', 'oauth2' ) . '</h1>' .
569+
'<p>' . esc_html__( 'You are not allowed to edit this application.', 'oauth2' ) . '</p>',
557570
403
558571
);
559572
}
560573

561574
$client = Client::get_by_post_id( $id );
562575
$result = $client->regenerate_secret();
563576
if ( is_wp_error( $result ) ) {
564-
wp_die( $result->get_error_message() );
577+
wp_die( esc_html( $result->get_error_message() ) );
565578
}
566579

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+
);
572589
exit;
573590
}

0 commit comments

Comments
 (0)