wp_create_nonce('update_sta_options_nonce') )); } } add_action('admin_enqueue_scripts', 'toast_sta_backend_scripts'); /* * AJAX function which runs when an option is updated */ function sta_update_options() { // ✅ Nonce verification check_ajax_referer('update_sta_options_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error('Unauthorized access'); } if (!isset($_POST['option'], $_POST['value'])) { wp_send_json_error('Missing parameters'); } $option = sanitize_text_field($_POST['option']); $value = sanitize_text_field($_POST['value']); if ($value === 'off' || $value === 'false') { $value = 'off'; } elseif ($value === 'checked' || $value === 'true') { $value = 'on'; } $sta_options = get_option('toast_sta_settings', array()); if (!is_array($sta_options)) { $sta_options = array(); } $sta_options[$option] = sanitize_text_field($value); update_option('toast_sta_settings', $sta_options); wp_send_json_success('Option updated'); } add_action('wp_ajax_sta_update_options', 'sta_update_options');