Implements the full HTML structure for the Community Registration form based on requirements, including all specified fields, labels, hints, and basic structure for error display. Adds corresponding JavaScript for dynamic state/province dropdown population.
Creates initial E2E tests (`registration.spec.ts`) for the registration page covering loading, validation scenarios (empty fields, invalid email, password mismatch, weak password), and successful submission. Creates a test data file (`personas.ts`) with sample user data.
Undertakes extensive debugging of failing E2E tests:
- Resolved initial shortcode rendering failure by correctly instantiating the `HVAC_Registration` class.
- Fixed incorrect form ID and submit button selectors in E2E tests.
- Corrected field ID selector (`#business_phone`) in E2E test.
- Refactored form submission handling multiple times (trying `init` hook, `admin_post` hooks, and direct shortcode processing) to address issues with validation error display and success redirects. Reverted to using the `init` hook with transient-based error handling as the most promising path despite current display issues.
- Identified and fixed a fatal PHP error ("Cannot redeclare handle_profile_image_upload") caused by duplicated code during refactoring.
- Troubleshot and resolved Docker volume/cache issues preventing code fixes from taking effect by restarting containers and flushing caches.
- Added and subsequently removed extensive diagnostic logging throughout the PHP classes and main plugin file to trace execution flow.
- Refined Playwright waits in E2E tests, specifically for the dynamically populated state dropdown.
Updates Memory Bank files (`activeContext.md`, `progress.md`) and `docs/implementation_plan.md` to reflect the completed unit test validation (Task 0.6) and the current debugging status of registration E2E tests (Task 1.10).
Current Status:
- Fatal errors resolved, plugin initializes correctly.
- Login E2E tests pass.
- Registration page loads correctly.
- Successful registration E2E test path completes form filling and submission, resulting in the expected redirect.
- Validation error E2E tests still fail as backend errors are not displayed on the frontend after form submission/redirect. Further debugging needed on error display mechanism (likely transient handling or HTML rendering).
Modified Files:
- docs/implementation_plan.md
- memory-bank/activeContext.md
- memory-bank/progress.md
- wordpress-dev/tests/e2e/data/personas.ts (new)
- wordpress-dev/tests/e2e/tests/registration.spec.ts (new)
- wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/assets/js/hvac-registration.js
- wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/hvac-community-events.php
- wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/class-hvac-community-events.php
- wordpress-dev/wordpress/wp-content/plugins/hvac-community-events/includes/class-hvac-registration.php
121 lines
No EOL
4.4 KiB
PHP
121 lines
No EOL
4.4 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: HVAC Community Events
|
|
* Plugin URI: https://upskillhvac.com
|
|
* Description: Custom plugin for HVAC trainer event management system
|
|
* Version: 1.0.0
|
|
* Author: Upskill HVAC
|
|
* Author URI: https://upskillhvac.com
|
|
* License: GPL-2.0+
|
|
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
|
* Text Domain: hvac-community-events
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
// error_log('[HVAC DEBUG] Main plugin file hvac-community-events.php loaded.'); // REMOVED DEBUG LOG
|
|
|
|
// Define plugin constants
|
|
define('HVAC_CE_VERSION', '1.0.0');
|
|
define('HVAC_CE_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
|
define('HVAC_CE_PLUGIN_URL', plugin_dir_url(__FILE__));
|
|
|
|
|
|
/**
|
|
* Create required pages and roles upon plugin activation.
|
|
*/
|
|
function hvac_ce_create_required_pages() {
|
|
|
|
// Ensure the roles class is available
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-roles.php';
|
|
error_log('HVAC CE: Activation hook fired.'); // Add logging start
|
|
$required_pages = [
|
|
'community-login' => [
|
|
'title' => 'Community Login',
|
|
'content' => '<!-- wp:shortcode -->[hvac_community_login]<!-- /wp:shortcode -->',
|
|
],
|
|
'trainer-registration' => [
|
|
'title' => 'Trainer Registration',
|
|
'content' => '<!-- wp:shortcode -->[hvac_trainer_registration]<!-- /wp:shortcode -->',
|
|
],
|
|
'hvac-dashboard' => [
|
|
'title' => 'Trainer Dashboard',
|
|
'content' => '', // Content handled by template or redirect
|
|
],
|
|
// Add future required pages here
|
|
];
|
|
|
|
$created_pages_option = 'hvac_community_pages';
|
|
$created_pages = get_option($created_pages_option, []);
|
|
|
|
foreach ($required_pages as $slug => $page_data) {
|
|
// Check if page already exists (by slug)
|
|
$existing_page = get_page_by_path($slug, OBJECT, 'page');
|
|
|
|
if (!$existing_page) {
|
|
error_log("HVAC CE: Page with slug '{$slug}' not found. Attempting to create."); // Add logging: page missing
|
|
// Page does not exist, create it
|
|
$post_data = [
|
|
'post_title' => $page_data['title'],
|
|
'post_name' => $slug,
|
|
'post_content' => $page_data['content'],
|
|
'post_status' => 'publish',
|
|
'post_type' => 'page',
|
|
'comment_status' => 'closed',
|
|
'ping_status' => 'closed',
|
|
];
|
|
|
|
$page_id = wp_insert_post($post_data);
|
|
|
|
// Log the result of wp_insert_post
|
|
if (is_wp_error($page_id)) {
|
|
error_log("HVAC CE: Error creating page '{$slug}': " . $page_id->get_error_message());
|
|
} else {
|
|
error_log("HVAC CE: Successfully created page '{$slug}' with ID: {$page_id}.");
|
|
}
|
|
|
|
// Store the created page ID
|
|
if ($page_id && !is_wp_error($page_id)) {
|
|
// Use a key based on the slug or feature name for clarity
|
|
$feature_key = str_replace('-', '_', $slug);
|
|
$created_pages[$feature_key] = $page_id;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Update the option with any newly created page IDs
|
|
update_option($created_pages_option, $created_pages);
|
|
|
|
// Create the custom role (Moved inside the activation function)
|
|
$roles_manager = new HVAC_Roles();
|
|
$roles_manager->create_trainer_role();
|
|
error_log('HVAC CE: Attempted to create hvac_trainer role.'); // Add logging: role creation attempt
|
|
|
|
} // <<-- Brace moved here
|
|
register_activation_hook(__FILE__, 'hvac_ce_create_required_pages');
|
|
|
|
|
|
/**
|
|
* Remove custom roles upon plugin deactivation.
|
|
*/
|
|
function hvac_ce_remove_roles() {
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-roles.php';
|
|
$roles_manager = new HVAC_Roles();
|
|
$roles_manager->remove_trainer_role();
|
|
error_log('HVAC CE: Deactivation hook fired, attempted to remove hvac_trainer role.');
|
|
}
|
|
register_deactivation_hook(__FILE__, 'hvac_ce_remove_roles');
|
|
|
|
|
|
// Include the main plugin class
|
|
require_once HVAC_CE_PLUGIN_DIR . 'includes/class-hvac-community-events.php';
|
|
|
|
// Initialize the plugin
|
|
function hvac_community_events_init() {
|
|
// error_log('[HVAC DEBUG] hvac_community_events_init function called (plugins_loaded hook).'); // REMOVED DEBUG LOG
|
|
return HVAC_Community_Events::instance();
|
|
}
|
|
// error_log('[HVAC DEBUG] About to add plugins_loaded action hook.'); // REMOVED DEBUG LOG
|
|
add_action('plugins_loaded', 'hvac_community_events_init'); |