Make WordPress Core


Ignore:
Timestamp:
12/17/2018 07:27:08 PM (6 years ago)
Author:
desrosj
Message:

Block Editor: Refresh nonces used by wp.apiFetch.

Adds heartbeat nonces refreshing support to wp.apiFetch requests.

Props pento, adamsilverstein, dd32, desrosj, youknowriad.

Merges [43939] into trunk.

Fixes #45113.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-admin/includes/misc.php

    r44168 r44275  
    10551055
    10561056        $response['wp-refresh-post-nonces'] = array(
    1057             'replace'        => array(
     1057            'replace' => array(
    10581058                'getpermalinknonce'    => wp_create_nonce( 'getpermalink' ),
    10591059                'samplepermalinknonce' => wp_create_nonce( 'samplepermalink' ),
     
    10621062                '_wpnonce'             => wp_create_nonce( 'update-post_' . $post_id ),
    10631063            ),
    1064             'heartbeatNonce' => wp_create_nonce( 'heartbeat-nonce' ),
    10651064        );
    10661065    }
    10671066
     1067    return $response;
     1068}
     1069
     1070/**
     1071 * Add the latest Heartbeat and REST-API nonce to the Heartbeat response.
     1072 *
     1073 * @since 5.0.0
     1074 *
     1075 * @param array  $response  The Heartbeat response.
     1076 * @return array The Heartbeat response.
     1077 */
     1078function wp_refresh_heartbeat_nonces( $response ) {
     1079    // Refresh the Rest API nonce.
     1080    $response['rest_nonce'] = wp_create_nonce( 'wp_rest' );
     1081    // TEMPORARY: Compat with api-fetch library
     1082    $response['rest-nonce'] = $response['rest_nonce'];
     1083
     1084    // Refresh the Heartbeat nonce.
     1085    $response['heartbeat_nonce'] = wp_create_nonce( 'heartbeat-nonce' );
    10681086    return $response;
    10691087}
Note: See TracChangeset for help on using the changeset viewer.