Make WordPress Core


Ignore:
Timestamp:
09/11/2022 08:44:50 PM (3 years ago)
Author:
joemcgill
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/misc.php

    r54071 r54122  
    12571257
    12581258/**
     1259 * Refresh nonces used with meta boxes in the block editor.
     1260 *
     1261 * @since 6.1.0
     1262 *
     1263 * @param array  $response  The Heartbeat response.
     1264 * @param array  $data      The $_POST data sent.
     1265 * @return array The Heartbeat response.
     1266 */
     1267function wp_refresh_metabox_loader_nonces( $response, $data ) {
     1268    if ( empty( $data['wp-refresh-metabox-loader-nonces'] ) ) {
     1269        return $response;
     1270    }
     1271
     1272    $received = $data['wp-refresh-metabox-loader-nonces'];
     1273    $post_id  = (int) $received['post_id'];
     1274
     1275    if ( ! $post_id ) {
     1276        return $response;
     1277    }
     1278
     1279    if ( ! current_user_can( 'edit_post', $post_id ) ) {
     1280        return $response;
     1281    }
     1282
     1283    $response['wp-refresh-metabox-loader-nonces'] = array(
     1284        'replace' => array(
     1285            'metabox_loader_nonce' => wp_create_nonce( 'meta-box-loader' ),
     1286            '_wpnonce'             => wp_create_nonce( 'update-post_' . $post_id ),
     1287        ),
     1288    );
     1289
     1290    return $response;
     1291}
     1292
     1293/**
    12591294 * Adds the latest Heartbeat and REST-API nonce to the Heartbeat response.
    12601295 *
Note: See TracChangeset for help on using the changeset viewer.