upskill-event-manager/includes/class-hvac-astra-integration.php
bengizmo 40274d98ad feat: Implement comprehensive user role field and certification tracking system
• Add user role field to registration, profile display, and profile edit
  - 10 role options: technician, installer, supervisor, manager, trainer, consultant, sales rep, engineer, business owner, other
  - Required field with server-side validation
  - Radio buttons in registration, dropdown in profile edit
  - Displays in profile with proper capitalization

• Implement advanced certification tracking system
  - Date Certified: HTML5 date picker with validation (no future dates)
  - Certification Type: dropdown with "Certified measureQuick Trainer" and "Certified measureQuick Champion"
  - Certification Status: color-coded status badges (Active/Expired/Pending/Disabled)

• Add sophisticated role-based access control
  - Regular trainers: read-only access to certification fields
  - Administrators & master trainers: full edit access to certification fields
  - Visual indicators for read-only fields
  - Server-side permission validation

• Enhance plugin activation system
  - Initialize all 36 user meta fields for existing users
  - Smart default assignment based on user capabilities
  - Backward compatibility maintained

• Add professional UI styling
  - Blue-bordered certification section with trophy icon
  - Color-coded status badges with proper contrast
  - Read-only field styling with visual indicators
  - Enhanced form controls with focus states

• Comprehensive testing and documentation
  - E2E test coverage with visual verification
  - Updated API reference with new meta fields
  - Access control patterns documented
  - 100% test pass rate on staging environment

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

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

345 lines
No EOL
11 KiB
PHP

<?php
/**
* HVAC Astra Theme Integration
*
* Properly integrates HVAC plugin with Astra theme using theme-specific hooks and filters
*
* @package HVAC_Community_Events
* @since 1.0.0
*/
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/**
* HVAC Astra Integration Class
*/
class HVAC_Astra_Integration {
/**
* Instance
*
* @var HVAC_Astra_Integration
*/
private static $instance = null;
/**
* Get instance
*/
public static function instance() {
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
// Only run if Astra theme is active
if (!defined('ASTRA_THEME_VERSION')) {
return;
}
$this->init_hooks();
}
/**
* Initialize hooks
*/
private function init_hooks() {
// Early init to catch template redirects
add_action('template_redirect', [$this, 'ensure_correct_template'], 1);
// Layout filters - use higher priority to ensure they run after Astra's defaults
add_filter('astra_page_layout', [$this, 'force_hvac_page_layout'], 999);
add_filter('astra_get_content_layout', [$this, 'force_hvac_content_layout'], 999);
add_filter('astra_site_layout', [$this, 'force_hvac_site_layout'], 999);
// Container filters
add_filter('astra_container_class', [$this, 'modify_container_class'], 999, 2);
add_filter('astra_get_container_class', [$this, 'get_hvac_container_class'], 999);
// Body classes
add_filter('body_class', [$this, 'add_hvac_body_classes'], 999);
// Content width
add_action('wp', [$this, 'setup_hvac_content_width'], 999);
// Dynamic CSS
add_filter('astra_dynamic_theme_css', [$this, 'add_hvac_dynamic_css'], 999);
// Disable sidebar for HVAC pages
add_action('wp', [$this, 'disable_sidebar_for_hvac_pages'], 1);
// Force template usage
add_filter('template_include', [$this, 'force_hvac_template'], 999);
}
/**
* Force page layout for HVAC pages
*/
public function force_hvac_page_layout($layout) {
if ($this->is_hvac_page()) {
return 'no-sidebar';
}
return $layout;
}
/**
* Force content layout for HVAC pages
*/
public function force_hvac_content_layout($layout) {
if ($this->is_hvac_page()) {
return 'plain-container';
}
return $layout;
}
/**
* Force site layout for HVAC pages
*/
public function force_hvac_site_layout($layout) {
if ($this->is_hvac_page()) {
return 'ast-full-width-layout';
}
return $layout;
}
/**
* Modify container class for HVAC pages
*/
public function modify_container_class($classes, $layout) {
if ($this->is_hvac_page()) {
// Remove any constrained container classes
$classes = str_replace('ast-container', 'ast-full-width-container', $classes);
}
return $classes;
}
/**
* Get HVAC-specific container class
*/
public function get_hvac_container_class($class) {
if ($this->is_hvac_page()) {
return 'ast-full-width-container';
}
return $class;
}
/**
* Add HVAC-specific body classes
*/
public function add_hvac_body_classes($classes) {
if ($this->is_hvac_page()) {
// Add Astra-specific classes for full-width layout
$classes[] = 'ast-no-sidebar';
$classes[] = 'ast-separate-container';
$classes[] = 'ast-full-width-layout';
$classes[] = 'ast-plain-container';
$classes[] = 'hvac-astra-integrated';
// Remove conflicting classes
$remove_classes = ['ast-right-sidebar', 'ast-left-sidebar', 'ast-page-builder-template'];
$classes = array_diff($classes, $remove_classes);
}
return $classes;
}
/**
* Setup content width for HVAC pages
*/
public function setup_hvac_content_width() {
if ($this->is_hvac_page()) {
// Set global content width
global $content_width;
$content_width = 1920; // Full HD width
// Update Astra's content width
add_filter('astra_get_content_width', function() {
return 1920;
}, 999);
}
}
/**
* Add dynamic CSS for HVAC pages
*/
public function add_hvac_dynamic_css($css) {
if ($this->is_hvac_page()) {
$hvac_css = '
/* HVAC Full-width overrides for Astra */
.hvac-astra-integrated .ast-container {
max-width: 100% !important;
width: 100% !important;
padding-left: 40px !important;
padding-right: 40px !important;
}
.hvac-astra-integrated .site-content .ast-container {
max-width: 100% !important;
}
.hvac-astra-integrated .hvac-page-wrapper {
max-width: 1920px;
margin: 0 auto;
}
/* Remove sidebar completely */
.hvac-astra-integrated .widget-area,
.hvac-astra-integrated .ast-sidebar,
.hvac-astra-integrated #secondary,
.hvac-astra-integrated aside.widget-area,
.hvac-astra-integrated .sidebar-main {
display: none !important;
width: 0 !important;
height: 0 !important;
visibility: hidden !important;
position: absolute !important;
left: -9999px !important;
}
/* Full-width content area */
.hvac-astra-integrated #primary,
.hvac-astra-integrated .site-main,
.hvac-astra-integrated .content-area {
width: 100% !important;
max-width: 100% !important;
margin: 0 !important;
float: none !important;
display: block !important;
}
/* Force single column layout */
.hvac-astra-integrated .ast-container > .ast-row {
display: block !important;
}
.hvac-astra-integrated .ast-col-md-8,
.hvac-astra-integrated .ast-col-lg-8 {
width: 100% !important;
max-width: 100% !important;
}
/* Ensure content takes full width */
.hvac-astra-integrated .entry-content {
width: 100% !important;
max-width: 100% !important;
}
';
$css .= $hvac_css;
}
return $css;
}
/**
* Disable sidebar for HVAC pages
*/
public function disable_sidebar_for_hvac_pages() {
if ($this->is_hvac_page()) {
// Remove ALL sidebar actions from Astra
remove_action('astra_sidebars', 'astra_get_sidebar');
remove_action('astra_sidebar', 'astra_get_sidebar');
remove_action('astra_primary_content_bottom', 'astra_primary_content_bottom');
// Force sidebar removal via filters
add_filter('astra_display_sidebar', '__return_false', 999);
add_filter('is_active_sidebar', [$this, 'disable_sidebar'], 999, 2);
// Update post meta to ensure no sidebar
global $post;
if ($post) {
update_post_meta($post->ID, 'site-sidebar-layout', 'no-sidebar');
update_post_meta($post->ID, 'site-content-layout', 'plain-container');
update_post_meta($post->ID, 'ast-site-sidebar-layout', 'no-sidebar');
update_post_meta($post->ID, 'ast-featured-img', 'disabled');
update_post_meta($post->ID, 'ast-breadcrumbs-content', 'disabled');
}
}
}
/**
* Disable sidebar check for HVAC pages
*/
public function disable_sidebar($is_active, $index) {
if ($this->is_hvac_page()) {
return false;
}
return $is_active;
}
/**
* Check if current page is an HVAC page
*/
private function is_hvac_page() {
// Check by template
if (is_page_template()) {
$template = get_page_template_slug();
if (strpos($template, 'page-trainer') !== false ||
strpos($template, 'page-master') !== false ||
strpos($template, 'page-certificate') !== false ||
strpos($template, 'page-generate') !== false) {
return true;
}
}
// Check by URL
$current_url = $_SERVER['REQUEST_URI'];
$hvac_paths = ['trainer/', 'master-trainer/', 'certificate', 'generate-certificates'];
foreach ($hvac_paths as $path) {
if (strpos($current_url, $path) !== false) {
return true;
}
}
// Check by page slug
if (is_page()) {
global $post;
if ($post) {
$slug = $post->post_name;
$hvac_slugs = ['trainer', 'dashboard', 'profile', 'certificate', 'venue', 'organizer'];
foreach ($hvac_slugs as $hvac_slug) {
if (strpos($slug, $hvac_slug) !== false) {
return true;
}
}
}
}
return false;
}
/**
* Ensure correct template is loaded
*/
public function ensure_correct_template() {
if ($this->is_hvac_page() && is_page()) {
global $post;
if ($post && $post->post_name === 'profile') {
// Force the profile template
$template = get_post_meta($post->ID, '_wp_page_template', true);
if (empty($template) || $template === 'default') {
update_post_meta($post->ID, '_wp_page_template', 'templates/page-trainer-profile.php');
}
}
}
}
/**
* Force HVAC template loading
*/
public function force_hvac_template($template) {
// Temporarily disabled to avoid errors
return $template;
}
}
// Initialize
HVAC_Astra_Integration::instance();