upskill-event-manager/includes/class-hvac-page-content-manager.php
Ben c3e7fe9140 feat: comprehensive HVAC plugin development framework and modernization
## Major Enhancements

### 🏗️ Architecture & Infrastructure
- Implement comprehensive Docker testing infrastructure with hermetic environment
- Add Forgejo Actions CI/CD pipeline for automated deployments
- Create Page Object Model (POM) testing architecture reducing test duplication by 90%
- Establish security-first development patterns with input validation and output escaping

### 🧪 Testing Framework Modernization
- Migrate 146+ tests from 80 duplicate files to centralized architecture
- Add comprehensive E2E test suites for all user roles and workflows
- Implement WordPress error detection with automatic site health monitoring
- Create robust browser lifecycle management with proper cleanup

### 📚 Documentation & Guides
- Add comprehensive development best practices guide
- Create detailed administrator setup documentation
- Establish user guides for trainers and master trainers
- Document security incident reports and migration guides

### 🔧 Core Plugin Features
- Enhance trainer profile management with certification system
- Improve find trainer functionality with advanced filtering
- Strengthen master trainer area with content management
- Add comprehensive venue and organizer management

### 🛡️ Security & Reliability
- Implement security-first patterns throughout codebase
- Add comprehensive input validation and output escaping
- Create secure credential management system
- Establish proper WordPress role-based access control

### 🎯 WordPress Integration
- Strengthen singleton pattern implementation across all classes
- Enhance template hierarchy with proper WordPress integration
- Improve page manager with hierarchical URL structure
- Add comprehensive shortcode and menu system

### 🔍 Developer Experience
- Add extensive debugging and troubleshooting tools
- Create comprehensive test data seeding scripts
- Implement proper error handling and logging
- Establish consistent code patterns and standards

### 📊 Performance & Optimization
- Optimize database queries and caching strategies
- Improve asset loading and script management
- Enhance template rendering performance
- Streamline user experience across all interfaces

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-29 11:26:10 -03:00

197 lines
No EOL
5.3 KiB
PHP

<?php
/**
* HVAC Page Content Manager
*
* Ensures all plugin pages have the correct shortcodes in their content
*
* @package HVAC_Community_Events
* @since 2.1.0
*/
if (!defined('ABSPATH')) {
exit;
}
class HVAC_Page_Content_Manager {
/**
* Instance
*/
private static $instance = null;
/**
* Page shortcode mappings
*/
private $page_shortcodes = array(
// Trainer pages
'trainer/venue/list' => '[hvac_trainer_venues_list]',
'trainer/venue/manage' => '[hvac_trainer_venue_manage]',
'trainer/organizer/manage' => '[hvac_trainer_organizer_manage]',
'trainer/profile/training-leads' => '[hvac_trainer_training_leads]',
// Master trainer pages
'master-trainer/announcements' => '[hvac_announcements_timeline]',
'master-trainer/trainers' => '[hvac_master_trainers]',
'master-trainer/pending-approvals' => '[hvac_pending_approvals]',
'master-trainer/events' => '[hvac_master_events]',
'master-trainer/google-sheets' => '[hvac_google_sheets]',
);
/**
* Get instance
*/
public static function instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
// Hook into page content filter
add_filter('the_content', array($this, 'ensure_page_content'), 5);
// Hook into plugin activation to update pages
add_action('hvac_plugin_activated', array($this, 'update_all_page_content'));
// Admin action to fix pages
add_action('admin_init', array($this, 'maybe_fix_pages'));
}
/**
* Ensure page has correct content
*/
public function ensure_page_content($content) {
if (!is_page()) {
return $content;
}
global $post;
if (!$post) {
return $content;
}
// Get the page path
$page_path = $this->get_page_path($post);
// Check if this is one of our pages
if (!isset($this->page_shortcodes[$page_path])) {
return $content;
}
$expected_shortcode = $this->page_shortcodes[$page_path];
// If content is empty or doesn't contain the shortcode, add it
if (empty(trim($content)) || strpos($content, $expected_shortcode) === false) {
// Return the shortcode to be processed
return $expected_shortcode;
}
return $content;
}
/**
* Get page path from post
*/
private function get_page_path($post) {
$path = '';
// Build path from slug and parent
if ($post->post_parent) {
$parent = get_post($post->post_parent);
if ($parent) {
$path = $this->get_page_path($parent) . '/';
}
}
$path .= $post->post_name;
return trim($path, '/');
}
/**
* Update all page content
*/
public function update_all_page_content() {
foreach ($this->page_shortcodes as $path => $shortcode) {
$this->update_page_by_path($path, $shortcode);
}
}
/**
* Update a specific page by path
*/
private function update_page_by_path($path, $shortcode) {
// Find the page by path
$page = get_page_by_path($path);
if (!$page) {
return;
}
// Check if page content needs updating
if (empty($page->post_content) || strpos($page->post_content, $shortcode) === false) {
wp_update_post(array(
'ID' => $page->ID,
'post_content' => $shortcode
));
}
}
/**
* Maybe fix pages on admin init
*/
public function maybe_fix_pages() {
// Only run once per day
$last_check = get_option('hvac_pages_last_check', 0);
if (time() - $last_check < DAY_IN_SECONDS) {
return;
}
// Check if we're on an admin page
if (!is_admin()) {
return;
}
// Update the check time
update_option('hvac_pages_last_check', time());
// Fix all pages
$this->update_all_page_content();
}
/**
* Force fix all pages (can be called manually)
*/
public function force_fix_all_pages() {
foreach ($this->page_shortcodes as $path => $shortcode) {
$page = get_page_by_path($path);
if ($page) {
wp_update_post(array(
'ID' => $page->ID,
'post_content' => $shortcode
));
error_log("HVAC: Updated page {$path} with shortcode {$shortcode}");
} else {
error_log("HVAC: Could not find page {$path}");
}
}
// Clear any caches
if (function_exists('wp_cache_flush')) {
wp_cache_flush();
}
}
}
// Initialize
add_action('init', function() {
if (class_exists('HVAC_Page_Content_Manager')) {
HVAC_Page_Content_Manager::instance();
}
});