3667b7a154
David's call after a short discussion about WordPress.org marketplace considerations. WP.org's trademark policy historically discourages plugins implying official endorsement via a "WP" prefix and has been known to request rename during submission review. Dropping it now makes the name cleaner AND sidesteps that future hurdle if/when the plugin lands on the marketplace. CHANGES All user-facing brand mentions: WP Logbook → Logbook across: - Plugin header (Plugin Name + docblock) - Admin menu top-level - Admin sidebar submenu label still "My Log" (already prefix-free) - Admin bar count menu - Dashboard widget title - Settings page H1 - Main page H1 - About page intro card + "What Logbook does" card heading - Email feedback subject + body intro - Legacy feedback.php subject lines - error_log() prefix [WP Logbook] → [Logbook] - Updater panel description text - styles.php docblock VERSION - wp-notes.php header Version: 3.3.0 → 3.3.1 - WP_NOTES_VERSION constant: 3.3.0 → 3.3.1 - About page version-history card gets new top entry for v3.3.1 with green "latest" pill; v3.3.0 demoted to previous entry - CHANGELOG header line tracks the full naming lineage now: A-WP-Notes (≤v3.1.0) → WP Logbook (v3.2.0-v3.3.0) → Logbook (v3.3.1+) NOTABLY NOT CHANGED - Historical CHANGELOG entries for v3.2.0 still say "WP Logbook" — that was the correct name at the time, rewriting would be revisionist. - Same zero-migration commitment: internal function names, constants, DB option keys, user_meta keys, file paths, plugin slug 'wp-notes', and text domain 'a-wp-notes' all unchanged. - Pure user-facing string change. No data migration, no behaviour change. Existing installs see "Logbook" appear on next page refresh. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
161 lines
5.8 KiB
PHP
161 lines
5.8 KiB
PHP
<?php
|
|
/**
|
|
* Feedback Form for Logbook 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 = '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 = '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');
|
|
|
|
?>
|