Skip to content

Commit 1aee510

Browse files
committed
Fix stats nonce
1 parent 771100f commit 1aee510

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

js/cloudinary.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

php/ui/component/class-progress-sync.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ class Progress_Sync extends Progress_Ring {
3434
protected function wrap( $struct ) {
3535
$struct = parent::wrap( $struct );
3636
if ( true === $this->setting->get_param( 'poll' ) ) {
37-
$struct['attributes']['data-url'] = Utils::rest_url( REST_API::BASE . '/stats' );
38-
$struct['attributes']['data-poll'] = true;
37+
$struct['attributes']['data-url'] = Utils::rest_url( REST_API::BASE . '/stats' );
38+
$struct['attributes']['data-poll'] = true;
39+
$struct['attributes']['data-nonce'] = wp_create_nonce( REST_API::NONCE_KEY );
3940
}
4041

4142
return $struct;

src/js/components/progress.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { __ } from '@wordpress/i18n';
66

77
const Progress = {
88
data: {},
9+
nonce: '',
910
context: null,
1011
init( context ) {
1112
this.context = context;
@@ -26,6 +27,10 @@ const Progress = {
2627
} else if ( 'circle' === item.dataset.progress ) {
2728
this.circle( item );
2829
}
30+
31+
if ( ! this.nonce ) {
32+
this.nonce = item.dataset?.nonce;
33+
}
2934
} );
3035

3136
for ( const url in this.data ) {
@@ -143,6 +148,9 @@ const Progress = {
143148
apiFetch( {
144149
path: url,
145150
method: 'GET',
151+
headers: {
152+
'X-WP-Nonce': this.nonce,
153+
},
146154
} ).then( ( result ) => {
147155
this.data[ url ].items.forEach( ( item ) => {
148156
if ( typeof result[ item.dataset.basetext ] !== 'undefined' ) {

0 commit comments

Comments
 (0)