Files
rangerhq-logbook/inc/wp-notes-feedback.php
T
ranger 433de27d9b chore: archive A-WP-Notes v3.0.2 — minimalist parallel fork
Imports the v3.0.2 line of A-WP-Notes as it existed on M5 at:
  Local Sites/wordpress/public/wp-content/plugins/a-wp-notes/

This is a deliberately minimal parallel fork of the plugin, distinct
from the v1.2.0 line in ranger/a-wp-notes. It carries only the core
note-taking functionality:

  wp-notes.php                       — plugin bootstrap + admin UI
  inc/wp-notes-display.php           — note rendering
  inc/wp-notes-about.php             — About page
  inc/wp-notes-feedback.php          — feedback module
  inc/wp-notes-styles.php            — style enqueues
  inc/wp-notes-updater.php           — self-hosted updater stub
  inc/admin-bar.php                  — admin bar integration
  js/wp-notes-feedback.js            — feedback front-end
  js/Chart.js                        — charting (bundled)
  assets/wp-notes-banner.jpg         — plugin banner

The AI ecosystem (chat, personalities, MCP), speed-test system, OS info
pages, and the bulk of the v1.2.0 / v2.0.x feature surface are
intentionally absent — this fork was created by copying the plugin to a
second WP install and trimming back to a lighter baseline.

Archived for comparison and parallel-line testing. No further development
is planned on this line; the active line continues at v1.2.0 in
ranger/a-wp-notes.
2026-05-22 16:43:03 +01:00

161 lines
5.8 KiB
PHP

<?php
/**
* Feedback Form for WP Notes Plugin
*
* This file contains the HTML and AJAX handling for the feedback form.
*/
// Enqueue Feedback Form Script
function wp_notes_enqueue_feedback_script() {
wp_enqueue_script('wp-notes-feedback', WP_NOTES_URL . 'js/wp-notes-feedback.js', array('jquery'), null, true);
wp_localize_script('wp-notes-feedback', 'wp_notes_feedback_vars', array(
'ajax_url' => 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() {
?>
<div id="feedback-form-improve" style="display: none;">
<h2>Leave Feedback</h2>
<form id="wp-notes-feedback-form" method="post">
<label for="feedback_name">Your Name:</label><br>
<input type="text" id="feedback_name" name="feedback_name" required><br><br>
<label for="feedback_email">Your Email:</label><br>
<input type="email" id="feedback_email" name="feedback_email" required><br><br>
<label for="feedback_message">Your Feedback:</label><br>
<textarea id="feedback_message" name="feedback_message" rows="5" required></textarea><br><br>
<input type="submit" value="Submit Feedback" class="button button-primary">
</form>
</div>
<div id="feedback-form-help" style="display: none;">
<h2>Need Help?</h2>
<form id="wp-notes-help-form" method="post">
<label for="help_name">Your Name:</label><br>
<input type="text" id="help_name" name="help_name" required><br><br>
<label for="help_email">Your Email:</label><br>
<input type="email" id="help_email" name="help_email" required><br><br>
<label for="help_message">Your Message:</label><br>
<textarea id="help_message" name="help_message" rows="5" required></textarea><br><br>
<input type="submit" value="Submit Help Request" class="button button-primary">
</form>
</div>
<?php
}
// Handle Feedback Form Submission
function wp_notes_submit_feedback() {
// 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 submit feedback)
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 feedback.', 403);
return;
}
// Validate required fields
$required_fields = ['feedback_name', 'feedback_email', 'feedback_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['feedback_name']);
$email = sanitize_email($_POST['feedback_email']);
$message = sanitize_textarea_field($_POST['feedback_message']);
// Save feedback to database or send via email
$feedback = array(
'name' => $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 Notes 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 Notes 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');
?>