diff --git a/wp-admin/includes/misc.php b/wp-admin/includes/misc.php index c580c25c92..4648efc4af 100644 --- a/wp-admin/includes/misc.php +++ b/wp-admin/includes/misc.php @@ -1082,8 +1082,6 @@ function wp_refresh_post_nonces( $response, $data, $screen_id ) { function wp_refresh_heartbeat_nonces( $response ) { // Refresh the Rest API nonce. $response['rest_nonce'] = wp_create_nonce( 'wp_rest' ); - // TEMPORARY: Compat with api-fetch library - $response['rest-nonce'] = $response['rest_nonce']; // Refresh the Heartbeat nonce. $response['heartbeat_nonce'] = wp_create_nonce( 'heartbeat-nonce' ); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index af65319791..3aee09ad6a 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -521,10 +521,30 @@ function wp_default_packages_scripts( &$scripts ) { function wp_default_packages_inline_scripts( &$scripts ) { global $wp_locale; + if ( isset( $scripts->registered['wp-api-fetch'] ) ) { + $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks'; + } $scripts->add_inline_script( 'wp-api-fetch', sprintf( - 'wp.apiFetch.use( wp.apiFetch.createNonceMiddleware( "%s" ) );', + implode( + "\n", + array( + '( function() {', + ' var nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );', + ' wp.apiFetch.use( nonceMiddleware );', + ' wp.hooks.addAction(', + ' "heartbeat.tick",', + ' "core/api-fetch/create-nonce-middleware",', + ' function( response ) {', + ' if ( response[ "rest_nonce" ] ) {', + ' nonceMiddleware.nonce = response[ "rest_nonce" ];', + ' }', + ' }', + ' );', + '} )();', + ) + ), ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ) ), 'after' diff --git a/wp-includes/version.php b/wp-includes/version.php index fae66964e9..bb3eae19e5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.2-alpha-44948'; +$wp_version = '5.2-alpha-44949'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.