mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Editor: Refresh nones for metaboxes after reauthentication.
This fixes an issue where metaboxes fail to save after a session expires and a user logs in again via the heartbeat API. Props LinSoftware. Fixes #52584. git-svn-id: https://develop.svn.wordpress.org/trunk@54122 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1255,6 +1255,41 @@ function wp_refresh_post_nonces( $response, $data, $screen_id ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh nonces used with meta boxes in the block editor.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @param array $response The Heartbeat response.
|
||||
* @param array $data The $_POST data sent.
|
||||
* @return array The Heartbeat response.
|
||||
*/
|
||||
function wp_refresh_metabox_loader_nonces( $response, $data ) {
|
||||
if ( empty( $data['wp-refresh-metabox-loader-nonces'] ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$received = $data['wp-refresh-metabox-loader-nonces'];
|
||||
$post_id = (int) $received['post_id'];
|
||||
|
||||
if ( ! $post_id ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response['wp-refresh-metabox-loader-nonces'] = array(
|
||||
'replace' => array(
|
||||
'metabox_loader_nonce' => wp_create_nonce( 'meta-box-loader' ),
|
||||
'_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ),
|
||||
),
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the latest Heartbeat and REST-API nonce to the Heartbeat response.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user