Add guest management and GDPR privacy compliance (v0.4.0)
All checks were successful
Create Release Package / build-release (push) Successful in 1m26s

- Create Guest CPT with personal info, address, ID/passport tracking
- Add guest-booking integration with AJAX search and linking
- Implement GDPR compliance via WordPress Privacy API (export/erasure)
- Update EmailNotifier to use Guest CPT data with new placeholders
- Add CSS styles for guest search, linked display, and privacy UI

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-31 14:59:43 +01:00
parent c66af8e299
commit aab3a4d1aa
9 changed files with 2858 additions and 71 deletions

View File

@@ -688,3 +688,403 @@
gap: 10px;
}
}
/* ==========================================================================
Guest Management Styles
========================================================================== */
/* Guest Search Container */
.bnb-guest-search-container {
margin-bottom: 15px;
padding: 12px;
background: #f6f7f7;
border: 1px solid #c3c4c7;
border-radius: 4px;
}
.bnb-guest-search-container label {
display: block;
margin-bottom: 8px;
font-weight: 600;
}
.bnb-guest-search-container input[type="text"] {
width: 100%;
max-width: 300px;
}
/* Guest Search Results */
.bnb-guest-results {
margin-top: 10px;
max-height: 200px;
overflow-y: auto;
border: 1px solid #c3c4c7;
border-radius: 4px;
background: #fff;
}
.bnb-guest-result {
padding: 10px 12px;
border-bottom: 1px solid #f0f0f1;
cursor: pointer;
transition: background 0.15s ease;
}
.bnb-guest-result:last-child {
border-bottom: none;
}
.bnb-guest-result:hover {
background: #f0f6fc;
}
.bnb-guest-result-name {
font-weight: 600;
color: #1d2327;
}
.bnb-guest-result-email {
font-size: 12px;
color: #646970;
margin-top: 2px;
}
.bnb-guest-result-meta {
font-size: 11px;
color: #a7aaad;
margin-top: 4px;
}
.bnb-guest-no-results {
padding: 15px;
text-align: center;
color: #646970;
font-style: italic;
}
.bnb-guest-create-new {
padding: 10px 12px;
background: #f0f6fc;
border-top: 1px solid #c3c4c7;
cursor: pointer;
}
.bnb-guest-create-new:hover {
background: #d4e4f7;
}
.bnb-guest-create-new .dashicons {
color: #2271b1;
margin-right: 5px;
vertical-align: text-bottom;
}
/* Guest Linked Display */
.bnb-guest-linked {
padding: 12px 15px;
background: #d4edda;
border: 1px solid #c3e6cb;
border-radius: 4px;
margin-bottom: 15px;
}
.bnb-guest-linked-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 8px;
}
.bnb-guest-linked-name {
font-size: 14px;
font-weight: 600;
color: #155724;
}
.bnb-guest-linked-name .dashicons {
font-size: 16px;
width: 16px;
height: 16px;
margin-right: 5px;
vertical-align: text-bottom;
}
.bnb-guest-linked-details {
font-size: 13px;
color: #155724;
}
.bnb-guest-linked-details div {
margin-top: 4px;
}
.bnb-guest-linked-actions {
display: flex;
gap: 8px;
margin-top: 10px;
}
/* Guest Admin Columns */
.column-email,
.column-phone,
.column-country,
.column-bookings {
width: 120px;
}
.column-bookings a {
text-decoration: none;
}
/* Guest Status Badges */
.bnb-guest-status {
display: inline-block;
padding: 3px 8px;
border-radius: 3px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
}
.bnb-guest-status-active {
background: #d4edda;
color: #155724;
}
.bnb-guest-status-inactive {
background: #f6f7f7;
color: #646970;
}
.bnb-guest-status-blocked {
background: #f8d7da;
color: #721c24;
}
/* Booking History Table in Guest */
.bnb-booking-history {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
.bnb-booking-history th,
.bnb-booking-history td {
padding: 8px 10px;
text-align: left;
border-bottom: 1px solid #f0f0f1;
}
.bnb-booking-history th {
background: #f6f7f7;
font-weight: 600;
color: #1d2327;
}
.bnb-booking-history tr:hover td {
background: #f9f9f9;
}
.bnb-booking-history-empty {
padding: 20px;
text-align: center;
color: #646970;
font-style: italic;
}
.bnb-booking-stats {
display: flex;
gap: 20px;
padding: 12px 0;
border-bottom: 1px solid #c3c4c7;
margin-bottom: 15px;
}
.bnb-booking-stat {
text-align: center;
}
.bnb-booking-stat-value {
font-size: 20px;
font-weight: 600;
color: #135e96;
}
.bnb-booking-stat-label {
font-size: 11px;
color: #646970;
text-transform: uppercase;
}
/* ==========================================================================
GDPR / Privacy Styles
========================================================================== */
/* Consent Status */
.bnb-consent-status {
display: flex;
flex-direction: column;
gap: 8px;
}
.bnb-consent-item {
display: flex;
align-items: center;
gap: 8px;
}
.bnb-consent-item .dashicons {
font-size: 16px;
width: 16px;
height: 16px;
}
.bnb-consent-granted {
color: #00a32a;
}
.bnb-consent-not-granted {
color: #646970;
}
.bnb-consent-date {
font-size: 11px;
color: #646970;
margin-left: 24px;
}
/* Consent Checkboxes in Guest Form */
.bnb-consent-checkbox {
display: flex;
align-items: flex-start;
gap: 8px;
margin: 10px 0;
}
.bnb-consent-checkbox input[type="checkbox"] {
margin-top: 3px;
}
.bnb-consent-checkbox label {
font-weight: normal;
cursor: pointer;
}
.bnb-consent-checkbox-description {
font-size: 12px;
color: #646970;
margin-left: 24px;
margin-top: 2px;
}
/* Privacy Settings Section */
.bnb-privacy-settings {
margin-top: 20px;
}
.bnb-privacy-section {
background: #fff;
border: 1px solid #c3c4c7;
border-radius: 4px;
margin-bottom: 20px;
}
.bnb-privacy-section-header {
padding: 12px 15px;
background: #f6f7f7;
border-bottom: 1px solid #c3c4c7;
font-weight: 600;
}
.bnb-privacy-section-content {
padding: 15px;
}
.bnb-privacy-notice {
display: flex;
align-items: flex-start;
gap: 10px;
padding: 12px 15px;
background: #f0f6fc;
border-left: 4px solid #72aee6;
margin-bottom: 15px;
}
.bnb-privacy-notice .dashicons {
color: #72aee6;
flex-shrink: 0;
}
.bnb-privacy-notice p {
margin: 0;
}
/* Privacy Actions in Guest Profile */
.bnb-privacy-actions {
margin-top: 20px;
padding-top: 15px;
border-top: 1px solid #f0f0f1;
}
.bnb-privacy-actions h4 {
margin: 0 0 10px 0;
font-size: 13px;
}
.bnb-privacy-actions-buttons {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.bnb-privacy-action-button {
display: inline-flex;
align-items: center;
gap: 5px;
}
.bnb-privacy-action-button .dashicons {
font-size: 16px;
width: 16px;
height: 16px;
}
/* Anonymized Data Display */
.bnb-anonymized {
font-style: italic;
color: #a7aaad;
}
.bnb-anonymized-badge {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 2px 8px;
background: #f0f0f1;
border-radius: 3px;
font-size: 11px;
color: #646970;
}
.bnb-anonymized-badge .dashicons {
font-size: 14px;
width: 14px;
height: 14px;
}
/* Data Retention Settings */
.bnb-retention-settings {
display: flex;
align-items: center;
gap: 10px;
}
.bnb-retention-settings input[type="number"] {
width: 80px;
}
.bnb-retention-description {
font-size: 12px;
color: #646970;
margin-top: 5px;
}

View File

@@ -577,6 +577,184 @@
});
}
/**
* Initialize guest search functionality for booking form.
*/
function initGuestSearch() {
var $searchInput = $('#bnb_booking_guest_search');
var $searchResults = $('#bnb-guest-search-results');
var $guestIdInput = $('#bnb_booking_guest_id');
var $linkedGuestInfo = $('#bnb-linked-guest-info');
var $searchContainer = $('#bnb-guest-search-container');
var $fieldsContainer = $('#bnb-guest-fields-container');
var $unlinkBtn = $('#bnb-unlink-guest');
var $guestNameInput = $('#bnb_booking_guest_name');
var $guestEmailInput = $('#bnb_booking_guest_email');
var $guestPhoneInput = $('#bnb_booking_guest_phone');
// Exit if not on booking form.
if (!$searchInput.length) {
return;
}
var searchTimer = null;
/**
* Perform guest search via AJAX.
*/
function searchGuests() {
var query = $searchInput.val().trim();
if (query.length < 2) {
$searchResults.hide().empty();
return;
}
$searchResults.html('<div class="bnb-search-loading">' + wpBnbAdmin.i18n.searchingGuests + '</div>').show();
$.ajax({
url: wpBnbAdmin.ajaxUrl,
type: 'POST',
data: {
action: 'wp_bnb_search_guest',
nonce: wpBnbAdmin.nonce,
search: query
},
success: function(response) {
if (response.success && response.data.guests.length > 0) {
var html = '<div class="bnb-guest-search-list">';
$.each(response.data.guests, function(i, guest) {
var isBlocked = guest.status === 'blocked';
var statusClass = isBlocked ? 'bnb-guest-blocked' : '';
var statusLabel = isBlocked ? ' <span class="bnb-blocked-label">' + wpBnbAdmin.i18n.guestBlocked + '</span>' : '';
html += '<div class="bnb-guest-search-item ' + statusClass + '" data-guest=\'' + JSON.stringify(guest) + '\'>';
html += '<div class="bnb-guest-item-info">';
html += '<strong>' + escapeHtml(guest.name) + '</strong>' + statusLabel + '<br>';
html += '<small>' + escapeHtml(guest.email || '') + '</small>';
if (guest.phone) {
html += ' <small>(' + escapeHtml(guest.phone) + ')</small>';
}
html += '</div>';
if (!isBlocked) {
html += '<button type="button" class="button button-small bnb-select-guest">' + wpBnbAdmin.i18n.selectGuest + '</button>';
}
html += '</div>';
});
html += '</div>';
$searchResults.html(html);
} else {
$searchResults.html('<div class="bnb-no-guests">' + wpBnbAdmin.i18n.noGuestsFound + '</div>');
}
},
error: function() {
$searchResults.html('<div class="bnb-search-error">' + wpBnbAdmin.i18n.error + '</div>');
}
});
}
/**
* Escape HTML entities.
*
* @param {string} text Text to escape.
* @return {string} Escaped text.
*/
function escapeHtml(text) {
if (!text) return '';
var div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
/**
* Select a guest from search results.
*
* @param {Object} guest Guest data.
*/
function selectGuest(guest) {
// Set hidden guest ID.
$guestIdInput.val(guest.id);
// Populate guest fields (for display/fallback).
$guestNameInput.val(guest.name).prop('readonly', true);
$guestEmailInput.val(guest.email).prop('readonly', true);
$guestPhoneInput.val(guest.phone).prop('readonly', true);
// Update linked guest display.
var infoHtml = '<p>';
infoHtml += '<span class="dashicons dashicons-admin-users"></span> ';
infoHtml += '<strong>' + escapeHtml(guest.name) + '</strong> ';
infoHtml += '<a href="' + wpBnbAdmin.ajaxUrl.replace('admin-ajax.php', 'post.php?post=' + guest.id + '&action=edit') + '" target="_blank" class="button button-small">View Guest Profile</a> ';
infoHtml += '<button type="button" id="bnb-unlink-guest" class="button button-small button-link-delete">Unlink</button>';
infoHtml += '</p>';
if (guest.email) {
infoHtml += '<p><small>' + escapeHtml(guest.email) + '</small></p>';
}
$linkedGuestInfo.html(infoHtml).show();
$searchContainer.hide();
$fieldsContainer.hide();
$searchResults.hide().empty();
$searchInput.val('');
// Re-bind unlink button.
bindUnlinkButton();
}
/**
* Unlink guest from booking.
*/
function unlinkGuest() {
$guestIdInput.val('');
$guestNameInput.val('').prop('readonly', false);
$guestEmailInput.val('').prop('readonly', false);
$guestPhoneInput.val('').prop('readonly', false);
$linkedGuestInfo.hide();
$searchContainer.show();
$fieldsContainer.show();
}
/**
* Bind unlink button event.
*/
function bindUnlinkButton() {
$('#bnb-unlink-guest').off('click').on('click', function(e) {
e.preventDefault();
unlinkGuest();
});
}
// Search input with debounce.
$searchInput.on('input', function() {
if (searchTimer) {
clearTimeout(searchTimer);
}
searchTimer = setTimeout(searchGuests, 300);
});
// Select guest from results.
$searchResults.on('click', '.bnb-select-guest', function(e) {
e.preventDefault();
var guest = $(this).closest('.bnb-guest-search-item').data('guest');
if (guest) {
selectGuest(guest);
}
});
// Initial unlink button binding.
bindUnlinkButton();
// Close search results when clicking outside.
$(document).on('click', function(e) {
if (!$(e.target).closest('#bnb_booking_guest_search, #bnb-guest-search-results').length) {
$searchResults.hide();
}
});
}
// Initialize on document ready.
$(document).ready(function() {
initLicenseManagement();
@@ -586,6 +764,7 @@
initPricingMetaBox();
initBookingForm();
initCalendarPage();
initGuestSearch();
});
})(jQuery);