admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('wp_notes_feedback_nonce') )); } add_action('admin_enqueue_scripts', 'wp_notes_enqueue_feedback_script'); // Feedback Form HTML function wp_notes_feedback_form() { ?> $name, 'email' => $email, 'message' => $message, 'timestamp' => current_time('mysql') ); // Example: Save feedback to an option $feedbacks = get_option('wp_notes_feedbacks', array()); $feedbacks[] = $feedback; update_option('wp_notes_feedbacks', $feedbacks); // Example: Send feedback via email $to = 'david@icanhelp.ie'; $subject = 'WP Logbook Feedback'; $body = "Name: $name\nEmail: $email\nMessage: $message"; $headers = array('Content-Type: text/plain; charset=UTF-8'); wp_mail($to, $subject, $body, $headers); wp_send_json_success('Feedback submitted successfully.'); } add_action('wp_ajax_wp_notes_submit_feedback', 'wp_notes_submit_feedback'); // Handle Help Form Submission function wp_notes_submit_help() { // 1. Nonce Check (already good) if (!check_ajax_referer('wp_notes_feedback_nonce', 'nonce', false)) { wp_send_json_error('Invalid nonce.'); return; } // 2. Capability Check (e.g., any logged-in user can request help) if (!current_user_can('read')) { // 'read' is a basic capability for any logged-in user wp_send_json_error('You do not have permission to submit a help request.', 403); return; } // Validate required fields $required_fields = ['help_name', 'help_email', 'help_message']; foreach ($required_fields as $field) { if (!isset($_POST[$field]) || empty($_POST[$field])) { wp_send_json_error("Missing required field: $field"); return; } } // 3. Sanitize and validate data (already good) $name = sanitize_text_field($_POST['help_name']); $email = sanitize_email($_POST['help_email']); $message = sanitize_textarea_field($_POST['help_message']); // Save help request to database or send via email $help_request = array( 'name' => $name, 'email' => $email, 'message' => $message, 'timestamp' => current_time('mysql') ); // Example: Save help request to an option $help_requests = get_option('wp_notes_help_requests', array()); $help_requests[] = $help_request; update_option('wp_notes_help_requests', $help_requests); // Example: Send help request via email $to = 'david@icanhelp.ie'; $subject = 'WP Logbook Help Request'; $body = "Name: $name\nEmail: $email\nMessage: $message"; $headers = array('Content-Type: text/plain; charset=UTF-8'); wp_mail($to, $subject, $body, $headers); wp_send_json_success('Help request submitted successfully.'); } add_action('wp_ajax_wp_notes_submit_help', 'wp_notes_submit_help'); ?>