[ 'title' => 'Community Login', 'content' => '[hvac_community_login]', ], 'trainer-registration' => [ 'title' => 'Trainer Registration', 'content' => '[hvac_trainer_registration]', ], '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');