Skip to content

Commit

Permalink
Try: Return error when session is missing for REST nonce refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka committed Jan 8, 2025
1 parent ad4da87 commit a790c45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/compat/wordpress-6.8/ajax-actions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Temporary compatibility shims for Core Ajax handlers.
*
* @package gutenberg
*/

/**
* Handles renewing the REST API nonce via AJAX.
*
* @since 5.3.0
* @since 6.8.0 Returns error when session token is missing.
*/
function gutenberg_ajax_rest_nonce() {
$token = wp_get_session_token();
if ( empty( $token ) ) {
wp_send_json_error( null, rest_authorization_required_code() );
}

exit( wp_create_nonce( 'wp_rest' ) );
}
add_action( 'wp_ajax_rest-nonce', 'gutenberg_ajax_rest_nonce', 0 );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.7/post-formats.php';

// WordPress 6.8 compat.
require __DIR__ . '/compat/wordpress-6.8/ajax-actions.php';
require __DIR__ . '/compat/wordpress-6.8/preload.php';
require __DIR__ . '/compat/wordpress-6.8/blocks.php';
require __DIR__ . '/compat/wordpress-6.8/functions.php';
Expand Down

0 comments on commit a790c45

Please sign in to comment.