PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / assets / js / admin-notice.js

admin-notice.js in Metricool – Social media and site statistics 2.1.1, at assets/js/admin-notice.js

42 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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