fix: Prevent event creation content from appearing on registration page

The HVAC_Manage_Event class was using is_page('manage') which was too generic
and could match any page with 'manage' in its slug. Changed to check for
specific page slugs: 'manage-event' and 'trainer-event-manage' to ensure
the event creation content only appears on the actual event management page.

This resolves the issue where "Create Your Training Event" content was
incorrectly showing on the trainer registration page.

Ben Reed <ben@tealmaker.com>
This commit is contained in:
bengizmo 2025-07-25 16:54:42 -03:00
parent 0942bf19c8
commit 3934b6353c

View file

@ -0,0 +1,515 @@
<?php
/**
* HVAC Manage Event Handler
*
* Ensures proper shortcode processing for the manage-event page
*
* @package HVAC_Community_Events
* @since 1.0.0
*/
if (!defined('ABSPATH')) {
exit;
}
class HVAC_Manage_Event {
/**
* Constructor
*/
public function __construct() {
// Hook into content filter with low priority (99) to run after other filters
add_filter('the_content', array($this, 'ensure_shortcode_processing'), 99);
// Also try wp_head to inject styles and navigation
add_action('wp_head', array($this, 'inject_page_content'));
// Add authentication check for manage-event page
add_action('template_redirect', array($this, 'check_manage_event_auth'));
// Debug: Log when this class is instantiated
if (defined('HVAC_CE_PLUGIN_DIR') && class_exists('HVAC_Logger')) {
HVAC_Logger::info('HVAC_Manage_Event class instantiated', 'ManageEvent');
}
}
/**
* Ensure shortcode processing for manage-event page
*/
public function ensure_shortcode_processing($content) {
// Check if we're on the manage page using multiple methods
$is_manage_page = false;
// Method 1: Check by specific slugs
if (is_page('manage-event') || is_page('trainer-event-manage')) {
$is_manage_page = true;
}
// Method 2: Check by post ID (if we can get it)
if (is_page(5334)) {
$is_manage_page = true;
}
// Method 3: Check by URL path
$current_path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if ($current_path === 'trainer/event/manage' || $current_path === 'trainer/event/manage/') {
$is_manage_page = true;
}
// Only process on manage page (the event creation page)
if (!$is_manage_page) {
return $content;
}
// Debug logging
if (class_exists('HVAC_Logger')) {
HVAC_Logger::info('Processing manage-event page content', 'ManageEvent');
HVAC_Logger::info('Original content: ' . substr($content, 0, 200), 'ManageEvent');
}
// Process all shortcodes in the content
$processed_content = do_shortcode($content);
// Debug: Log if content changed
if (class_exists('HVAC_Logger') && $processed_content !== $content) {
HVAC_Logger::info('Content was processed by do_shortcode', 'ManageEvent');
}
// Add navigation bar to the content
$navigation_html = $this->get_navigation_bar();
// If shortcode wasn't processed (plugin might be inactive), show helpful message
if (strpos($processed_content, '[tribe_community_events') !== false) {
if (class_exists('HVAC_Logger')) {
HVAC_Logger::warning('tribe_community_events shortcode not processed - plugin may be inactive', 'ManageEvent');
}
$error_content = '<div class="hvac-notice hvac-error">
<p><strong>Event Submission Form Unavailable</strong></p>
<p>The event submission form is currently unavailable. Please ensure:</p>
<ul>
<li>The Events Calendar plugin is active</li>
<li>The Events Calendar Community Events add-on is active</li>
<li>You are logged in as a trainer</li>
</ul>
<p><a href="' . esc_url(home_url('/hvac-dashboard/')) . '" class="button">Return to Dashboard</a></p>
</div>
<style>
.hvac-notice.hvac-error {
background: #f8d7da;
border: 1px solid #f5c6cb;
color: #721c24;
padding: 20px;
margin: 20px 0;
border-radius: 4px;
}
.hvac-notice.hvac-error ul {
margin: 15px 0 15px 30px;
}
</style>';
return $navigation_html . $error_content;
}
// Wrap the form content with navigation and styling
$final_content = $navigation_html . '
<div class="hvac-manage-event-content">
' . $processed_content . '
</div>
<style>
.hvac-manage-event-content {
margin-top: 30px;
}
/* Instruction text styling */
.hvac-info-section {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 8px;
padding: 20px;
margin: 20px 0 30px 0;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.hvac-instruction-text {
font-size: 0.95rem;
line-height: 1.6;
color: #495057;
}
.hvac-instruction-text p {
margin: 0 0 12px 0;
}
.hvac-instruction-text p:last-child {
margin-bottom: 0;
}
.hvac-instruction-text strong {
color: #212529;
font-weight: 600;
}
/* Style the TEC Community Events form */
.tribe-community-events-form {
background: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 30px;
}
.tribe-community-events-form .tribe-events-page-title {
color: #333;
margin-bottom: 20px;
padding-bottom: 15px;
border-bottom: 2px solid #eee;
}
/* Form field styling */
.tribe-community-events-form .tribe-events-form-row {
margin-bottom: 20px;
}
.tribe-community-events-form label {
font-weight: 600;
color: #333;
display: block;
margin-bottom: 8px;
}
.tribe-community-events-form input[type="text"],
.tribe-community-events-form input[type="email"],
.tribe-community-events-form input[type="url"],
.tribe-community-events-form textarea,
.tribe-community-events-form select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
transition: border-color 0.3s ease;
}
.tribe-community-events-form input:focus,
.tribe-community-events-form textarea:focus,
.tribe-community-events-form select:focus {
outline: none;
border-color: #007cba;
box-shadow: 0 0 5px rgba(0, 124, 186, 0.3);
}
/* Submit button styling */
.tribe-community-events-form input[type="submit"],
.tribe-community-events-form .tribe-events-submit {
background: #007cba;
color: white;
padding: 12px 30px;
border: none;
border-radius: 4px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s ease;
}
.tribe-community-events-form input[type="submit"]:hover,
.tribe-community-events-form .tribe-events-submit:hover {
background: #005a87;
}
/* TinyMCE editor styling */
.tribe-community-events-form .wp-editor-wrap {
border: 1px solid #ddd;
border-radius: 4px;
}
/* Date picker styling */
.tribe-community-events-form .tribe-datetime-block {
background: #f9f9f9;
padding: 15px;
border-radius: 4px;
margin: 10px 0;
}
/* Venue fields styling */
.tribe-community-events-form .tribe-events-venue-form {
background: #f9f9f9;
padding: 20px;
border-radius: 4px;
margin: 15px 0;
}
/* Error and success messages */
.tribe-community-events-form .tribe-events-notices {
padding: 15px;
margin: 20px 0;
border-radius: 4px;
}
.tribe-community-events-form .tribe-events-error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.tribe-community-events-form .tribe-events-success {
background: #d1e7dd;
color: #0f5132;
border: 1px solid #badbcc;
}
</style>';
return $final_content;
}
/**
* Generate the navigation bar HTML
*/
private function get_navigation_bar() {
// Check if Help System is available for tooltips
$help_available = class_exists('HVAC_Help_System');
$nav_html = '
<div class="hvac-dashboard-header">
<h1 class="entry-title">Create Event</h1>
<div class="hvac-dashboard-nav">';
// Dashboard link
if ($help_available) {
$nav_html .= HVAC_Help_System::add_tooltip(
'<a href="' . esc_url(home_url('/hvac-dashboard/')) . '" class="ast-button ast-button-secondary">Dashboard</a>',
'Return to your main dashboard to view stats and manage events'
);
} else {
$nav_html .= '<a href="' . esc_url(home_url('/hvac-dashboard/')) . '" class="ast-button ast-button-secondary">Dashboard</a>';
}
// Generate Certificates link
if ($help_available) {
$nav_html .= HVAC_Help_System::add_tooltip(
'<a href="' . esc_url(home_url('/generate-certificates/')) . '" class="ast-button ast-button-primary">Generate Certificates</a>',
'Create professional certificates for attendees who completed your training'
);
} else {
$nav_html .= '<a href="' . esc_url(home_url('/generate-certificates/')) . '" class="ast-button ast-button-primary">Generate Certificates</a>';
}
// Certificate Reports link
if ($help_available) {
$nav_html .= HVAC_Help_System::add_tooltip(
'<a href="' . esc_url(home_url('/certificate-reports/')) . '" class="ast-button ast-button-primary">Certificate Reports</a>',
'View and manage all certificates you\'ve issued to attendees'
);
} else {
$nav_html .= '<a href="' . esc_url(home_url('/certificate-reports/')) . '" class="ast-button ast-button-primary">Certificate Reports</a>';
}
// Trainer Profile link
if ($help_available) {
$nav_html .= HVAC_Help_System::add_tooltip(
'<a href="' . esc_url(home_url('/trainer-profile/')) . '" class="ast-button ast-button-secondary">View Profile</a>',
'Update your professional credentials, business information, and training specialties'
);
} else {
$nav_html .= '<a href="' . esc_url(home_url('/trainer-profile/')) . '" class="ast-button ast-button-secondary">View Profile</a>';
}
// Help and Logout links
$nav_html .= '
<a href="' . esc_url(home_url('/hvac-documentation/')) . '" class="ast-button ast-button-secondary">Help</a>
<a href="' . esc_url(wp_logout_url(home_url('/community-login/'))) . '" class="ast-button ast-button-secondary">Logout</a>
</div>
</div>
<div class="hvac-info-section">
<div class="hvac-instruction-text">
<p><strong>📝 Create Your Training Event:</strong> Fill in the required fields below including event title, dates, and pricing. All fields marked with an asterisk (*) are required for publication.</p>
<p><strong>🎯 Event Visibility:</strong> Your published events will appear in the main events directory and your trainer dashboard, where attendees can register and make payments.</p>
<p><strong>💼 Professional Features:</strong> Each event includes automatic attendee management, certificate generation capabilities, and integrated payment processing through PayPal.</p>
</div>
</div>';
return $nav_html;
}
/**
* Inject navigation and styles into the head section for manage page
*/
public function inject_page_content() {
// Check if we're on the manage page using multiple methods
$is_manage_page = false;
// Method 1: Check by specific slugs
if (is_page('manage-event') || is_page('trainer-event-manage')) {
$is_manage_page = true;
}
// Method 2: Check by post ID
if (is_page(5334)) {
$is_manage_page = true;
}
// Method 3: Check by URL path
$current_path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if ($current_path === 'trainer/event/manage' || $current_path === 'trainer/event/manage/') {
$is_manage_page = true;
}
if (!$is_manage_page) {
return;
}
// Generate navigation HTML
$navigation_html = $this->get_navigation_bar();
// Escape the HTML for JavaScript
$escaped_nav = json_encode($navigation_html);
echo '<style>
/* Instruction text styling */
.hvac-info-section {
background: #f8f9fa;
border: 1px solid #e9ecef;
border-radius: 8px;
padding: 20px;
margin: 20px 0 30px 0;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.hvac-instruction-text {
font-size: 0.95rem;
line-height: 1.6;
color: #495057;
}
.hvac-instruction-text p {
margin: 0 0 12px 0;
}
.hvac-instruction-text p:last-child {
margin-bottom: 0;
}
.hvac-instruction-text strong {
color: #212529;
font-weight: 600;
}
/* Style the TEC Community Events form */
.tribe-community-events-form {
background: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 30px;
}
.tribe-community-events-form .tribe-events-page-title {
color: #333;
margin-bottom: 20px;
padding-bottom: 15px;
border-bottom: 2px solid #eee;
}
/* Form field styling */
.tribe-community-events-form .tribe-events-form-row {
margin-bottom: 20px;
}
.tribe-community-events-form label {
font-weight: 600;
color: #333;
display: block;
margin-bottom: 8px;
}
.tribe-community-events-form input[type="text"],
.tribe-community-events-form input[type="email"],
.tribe-community-events-form input[type="url"],
.tribe-community-events-form textarea,
.tribe-community-events-form select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 14px;
transition: border-color 0.3s ease;
}
.tribe-community-events-form input:focus,
.tribe-community-events-form textarea:focus,
.tribe-community-events-form select:focus {
outline: none;
border-color: #007cba;
box-shadow: 0 0 5px rgba(0, 124, 186, 0.3);
}
/* Submit button styling */
.tribe-community-events-form input[type="submit"],
.tribe-community-events-form .tribe-events-submit {
background: #007cba;
color: white;
padding: 12px 30px;
border: none;
border-radius: 4px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: background-color 0.3s ease;
}
.tribe-community-events-form input[type="submit"]:hover,
.tribe-community-events-form .tribe-events-submit:hover {
background: #005a87;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", function() {
// Find the main content area
var contentArea = document.querySelector(".entry-content, .post-content, .page-content, main, .content");
if (contentArea) {
// Create the navigation HTML
var navHTML = ' . $escaped_nav . ';
// Insert the navigation at the beginning of the content
contentArea.insertAdjacentHTML("afterbegin", navHTML);
}
});
</script>';
}
/**
* Check authentication for manage-event page
*/
public function check_manage_event_auth() {
// Check if we're on the manage page using multiple methods
$is_manage_page = false;
// Method 1: Check by specific slugs
if (is_page('manage-event') || is_page('trainer-event-manage')) {
$is_manage_page = true;
}
// Method 2: Check by post ID
if (is_page(5334)) {
$is_manage_page = true;
}
// Method 3: Check by URL path
$current_path = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
if ($current_path === 'trainer/event/manage' || $current_path === 'trainer/event/manage/') {
$is_manage_page = true;
}
// Check if we're on the manage page (event creation page) and not logged in
if ($is_manage_page && !is_user_logged_in()) {
// Redirect to login page
wp_redirect(home_url('/training-login/?redirect_to=' . urlencode($_SERVER['REQUEST_URI'])));
exit;
}
}
}