Implements automatic creation of required plugin pages (Community Login, Trainer Registration, Trainer Dashboard) upon plugin activation. This addresses E2E test failures caused by missing pages in the test environment. - Adds activation hook in `hvac-community-events.php` to call `hvac_ce_create_required_pages`. - The callback function checks for existing pages by slug and creates them using `wp_insert_post` if missing. Includes debug logging. Also fixes issues identified during E2E test debugging: - Corrects fatal error in `includes/community/class-login-handler.php` by replacing undefined constant `HVAC_COMMUNITY_EVENTS_PATH` with `HVAC_CE_PLUGIN_DIR`. - Updates `tests/e2e/tests/login.spec.ts` to use the correct selector `#wp-submit` for the login form submit button instead of `button[type="submit"]`. Documentation updates: - Adds `docs/automatic-page-creation-plan.md`. - Updates `README.md` regarding automatic page creation. - Updates Memory Bank files (`decisionLog.md`, `progress.md`, `activeContext.md`). Note: Activation hook logging did not appear during WP-CLI activation, requiring further investigation if page creation issues persist. E2E test confirmation pending.
97 lines
No EOL
3.3 KiB
PHP
97 lines
No EOL
3.3 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;
|
|
}
|
|
|
|
// 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 upon plugin activation.
|
|
*/
|
|
function hvac_ce_create_required_pages() {
|
|
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);
|
|
}
|
|
register_activation_hook(__FILE__, 'hvac_ce_create_required_pages');
|
|
|
|
|
|
// 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() {
|
|
return HVAC_Community_Events::instance();
|
|
}
|
|
add_action('plugins_loaded', 'hvac_community_events_init'); |