@@ -65,6 +65,9 @@ public static function load() {
65
65
case 'delete ' :
66
66
return self ::handle_delete ();
67
67
68
+ case 'regenerate ' :
69
+ return self ::handle_regenerate ();
70
+
68
71
default :
69
72
global $ wp_list_table ;
70
73
@@ -238,6 +241,7 @@ public static function render_edit_page() {
238
241
}
239
242
240
243
$ form_action = self ::get_url ( array ( 'action ' => 'edit ' , 'id ' => $ id ) );
244
+ $ regenerate_action = self ::get_url ( array ( 'action ' => 'regenerate ' , 'id ' => $ id ) );
241
245
}
242
246
243
247
// Handle form submission
@@ -246,10 +250,18 @@ public static function render_edit_page() {
246
250
$ messages = self ::handle_edit_submit ( $ consumer );
247
251
}
248
252
if ( ! empty ( $ _GET ['did_action ' ] ) ) {
249
- if ( $ _GET ['did_action ' ] === 'edit ' ) {
250
- $ messages [] = __ ( 'Updated application. ' , 'rest_oauth1 ' );
251
- } else {
252
- $ messages [] = __ ( 'Successfully created application. ' , 'rest_oauth1 ' );
253
+ switch ( $ _GET ['did_action ' ] ) {
254
+ case 'edit ' :
255
+ $ messages [] = __ ( 'Updated application. ' , 'rest_oauth1 ' );
256
+ break ;
257
+
258
+ case 'regenerate ' :
259
+ $ messages [] = __ ( 'Regenerated secret. ' , 'rest_oauth1 ' );
260
+ break ;
261
+
262
+ default :
263
+ $ messages [] = __ ( 'Successfully created application. ' , 'rest_oauth1 ' );
264
+ break ;
253
265
}
254
266
}
255
267
@@ -318,25 +330,6 @@ public static function render_edit_page() {
318
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>
319
331
</td>
320
332
</tr>
321
-
322
- <?php if ( ! empty ( $ consumer ) ): ?>
323
- <tr>
324
- <th scope="row">
325
- <?php echo esc_html__ ( 'Client Key ' ) ?>
326
- </th>
327
- <td>
328
- <code><?php echo esc_html ( $ consumer ->key ) ?> </code>
329
- </td>
330
- </tr>
331
- <tr>
332
- <th scope="row">
333
- <?php echo esc_html__ ( 'Client Secret ' ) ?>
334
- </th>
335
- <td>
336
- <code><?php echo esc_html ( $ consumer ->secret ) ?> </code>
337
- </td>
338
- </tr>
339
- <?php endif ?>
340
333
</table>
341
334
342
335
<?php
@@ -353,11 +346,39 @@ public static function render_edit_page() {
353
346
354
347
?>
355
348
</form>
349
+
350
+ <?php if ( ! empty ( $ consumer ) ): ?>
351
+ <form method="post" action="<?php echo esc_url ( $ regenerate_action ) ?> ">
352
+ <h3><?php esc_html_e ( 'OAuth Credentials ' , 'rest_oauth1 ' ) ?> </h3>
353
+
354
+ <table class="form-table">
355
+ <tr>
356
+ <th scope="row">
357
+ <?php echo esc_html__ ( 'Client Key ' , 'rest_oauth1 ' ) ?>
358
+ </th>
359
+ <td>
360
+ <code><?php echo esc_html ( $ consumer ->key ) ?> </code>
361
+ </td>
362
+ </tr>
363
+ <tr>
364
+ <th scope="row">
365
+ <?php echo esc_html__ ( 'Client Secret ' , 'rest_oauth1 ' ) ?>
366
+ </th>
367
+ <td>
368
+ <code><?php echo esc_html ( $ consumer ->secret ) ?> </code>
369
+ </td>
370
+ </tr>
371
+ </table>
372
+
373
+ <?php
374
+ wp_nonce_field ( 'rest-oauth1-regenerate: ' . $ consumer ->ID );
375
+ submit_button ( __ ( 'Regenerate Secret ' , 'rest_oauth1 ' ), 'delete ' );
376
+ ?>
377
+ </form>
378
+ <?php endif ?>
356
379
</div>
357
380
358
381
<?php
359
-
360
- include (ABSPATH . 'wp-admin/admin-footer.php ' );
361
382
}
362
383
363
384
public static function handle_delete () {
@@ -383,4 +404,19 @@ public static function handle_delete() {
383
404
wp_redirect ( self ::get_url ( 'deleted=1 ' ) );
384
405
exit ;
385
406
}
407
+
408
+ public static function handle_regenerate () {
409
+ if ( empty ( $ _GET ['id ' ] ) ) {
410
+ return ;
411
+ }
412
+
413
+ $ id = $ _GET ['id ' ];
414
+ check_admin_referer ( 'rest-oauth1-regenerate: ' . $ id );
415
+
416
+ $ client = WP_REST_OAuth1_Client::get ( $ id );
417
+ $ client ->regenerate_secret ();
418
+
419
+ wp_redirect ( self ::get_url ( array ( 'action ' => 'edit ' , 'id ' => $ id , 'did_action ' => 'regenerate ' ) ) );
420
+ exit ;
421
+ }
386
422
}
0 commit comments