| @@ -76,8 +76,9 @@ | ||
| 76 | 76 | |
| 77 | 77 | echo wp_kses_post( $notice ); |
| 78 | 78 | |
| 79 | 79 | $admin_ajax_url = admin_url('admin-ajax.php'); |
| 80 | + $nonce = wp_create_nonce( 'timetics_dismiss_wc_notice' ); | |
| 80 | 81 | |
| 81 | 82 | ?> |
| 82 | 83 | <script> |
| 83 | 84 | jQuery(document).ready(function($) { |
| @@ -83,8 +84,9 @@ | ||
| 83 | 84 | jQuery(document).ready(function($) { |
| 84 | 85 | $('.notice.is-dismissible').on('click', '.notice-dismiss', function() { |
| 85 | 86 | var data = { |
| 86 | 87 | action: 'dismiss_woocommerce_notice', |
| 88 | + nonce: '<?php echo esc_js( $nonce ); ?>', | |
| 87 | 89 | }; |
| 88 | 90 | |
| 89 | 91 | $.post('<?php echo esc_url( $admin_ajax_url ); ?>', data, function(response) { |
| 90 | 92 | console.log(response); |
| @@ -100,8 +102,10 @@ | ||
| 100 | 102 | * |
| 101 | 103 | * @return void |
| 102 | 104 | */ |
| 103 | 105 | public function dismiss_woocommerce_notice() { |
| 106 | + check_ajax_referer( 'timetics_dismiss_wc_notice', 'nonce' ); | |
| 107 | + | |
| 104 | 108 | // Store the notice state in user meta |
| 105 | 109 | update_user_meta( get_current_user_id(), 'timetics_woocommerce_notice_dismissed', true ); |
| 106 | 110 | |
| 107 | 111 | wp_send_json_success('Notice dismissed successfully.'); |