WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/22/2018 07:39:02 PM (9 months ago)
Author:
youknowriad
Message:

Block Editor: Refresh nonces used by wp.apiFetch.

Adds heartbeat nonces refreshing support to wp.apiFetch requests.

Props pento, adamsilverstein, dd32, desrosj.
Fixes #45113.

File:
1 edited

Legend:

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

    r43920 r43939  
    10211021                '_wpnonce' => wp_create_nonce( 'update-post_' . $post_id ),
    10221022            ),
    1023             'heartbeatNonce' => wp_create_nonce( 'heartbeat-nonce' ),
    10241023        );
    10251024    }
    10261025
     1026    return $response;
     1027}
     1028
     1029/**
     1030 * Add the latest Heartbeat and REST-API nonce to the Heartbeat response.
     1031 *
     1032 * @since 5.0.0
     1033 *
     1034 * @param array  $response  The Heartbeat response.
     1035 * @return array The Heartbeat response.
     1036 */
     1037function wp_refresh_heartbeat_nonces( $response ) {
     1038    // Refresh the Rest API nonce.
     1039    $response['rest_nonce'] = wp_create_nonce( 'wp_rest' );
     1040    // TEMPORARY: Compat with api-fetch library
     1041    $response['rest-nonce'] = $response['rest_nonce'];
     1042
     1043    // Refresh the Heartbeat nonce.
     1044    $response['heartbeat_nonce'] = wp_create_nonce( 'heartbeat-nonce' );
    10271045    return $response;
    10281046}
Note: See TracChangeset for help on using the changeset viewer.