| 1 |
(function () { |
| 2 |
const notices = document.querySelectorAll('.rsp-metricool-admin-notice'); |
| 3 |
|
| 4 |
notices.forEach(function (notice) { |
| 5 |
const restUrl = notice.getAttribute('data-rest-url'); |
| 6 |
const nonce = notice.getAttribute('data-nonce'); |
| 7 |
const wpNonce = notice.getAttribute('data-wp-nonce'); |
| 8 |
|
| 9 |
if (!restUrl || !nonce || !wpNonce) { |
| 10 |
return; |
| 11 |
} |
| 12 |
|
| 13 |
const buttons = notice.querySelectorAll('[data-notice-action]'); |
| 14 |
|
| 15 |
buttons.forEach(function (button) { |
| 16 |
button.addEventListener('click', function () { |
| 17 |
const noticeAction = this.getAttribute('data-notice-action'); |
| 18 |
if (!noticeAction) { |
| 19 |
return; |
| 20 |
} |
| 21 |
|
| 22 |
fetch(restUrl, { |
| 23 |
method: 'POST', |
| 24 |
credentials: 'same-origin', |
| 25 |
headers: { |
| 26 |
'Content-Type': 'application/json', |
| 27 |
'X-WP-Nonce': wpNonce, |
| 28 |
}, |
| 29 |
body: JSON.stringify({ |
| 30 |
nonce: nonce, |
| 31 |
action: noticeAction, |
| 32 |
}), |
| 33 |
}).then(function (response) { |
| 34 |
if (response.ok) { |
| 35 |
notice.style.display = 'none'; |
| 36 |
} |
| 37 |
}); |
| 38 |
}); |
| 39 |
}); |
| 40 |
}); |
| 41 |
})(); |
| 42 |
|