* Dismiss notification via AJAX. If it's a new user message, also dismiss it * on all admin pages. * * @since 1.2 */ public function dismiss() { // Run a security check. check_ajax_referer('sbr-admin', 'nonce'); // Check for access and required param. if (! $this->has_access() || empty($_POST['id'])) { wp_send_json_error(); } $id = sanitize_text_field(wp_unslash($_POST['id'])); if ($id === 'review') { $sbr_statuses_option = get_option('sbr_statuses', array()); update_option('sbr_rating_notice', 'dismissed', false); $sbr_statuses_option['rating_notice_dismissed'] = sbr_get_current_time(); update_option('sbr_statuses', $sbr_statuses_option, false); } elseif ($id === 'discount') { update_user_meta(get_current_user_id(), 'sbr_ignore_new_user_sale_notice', 'always'); $current_month_number = (int)date('n', sbr_get_current_time()); $not_early_in_the_year = ($current_month_number > 5); if ($not_early_in_the_year) { update_user_meta(get_current_user_id(), 'sbr_ignore_bfcm_sale_notice', date('Y', sbr_get_current_time())); } } $option = $this->get_option(); $type = is_numeric($id) ? 'feed' : 'events'; $option['dismissed'][] = $id; $option['dismissed'] = array_unique($option['dismissed']); // Remove notification. if (is_array($option[ $type ]) && ! empty($option[ $type ])) { foreach ($option[ $type ] as $key => $notification) { if ($notification['id'] == $id) { // phpcs:ignore WordPress.PHP.StrictComparisons unset($option[ $type ][ $key ]); break; } } } update_option('sbr_notifications', $option); wp_send_json_success(); } }