diff --git a/quiztech-assessment-platform.php b/quiztech-assessment-platform.php index 5bfa6a0..2d0dc68 100644 --- a/quiztech-assessment-platform.php +++ b/quiztech-assessment-platform.php @@ -103,6 +103,69 @@ function activate_quiztech() { // Call the namespaced function for roles \Quiztech\AssessmentPlatform\Includes\quiztech_add_roles_and_capabilities(); + + // Programmatically create necessary pages and assign templates + $pages_to_create = [ + [ + 'title' => 'Quiztech Dashboard', + 'slug' => 'quiztech-dashboard', + 'template' => 'template-quiztech-dashboard.php', + ], + [ + 'title' => 'Manage Jobs', + 'slug' => 'manage-jobs', + 'template' => 'template-manage-jobs.php', + ], + [ + 'title' => 'Manage Assessments', + 'slug' => 'manage-assessments', + 'template' => 'template-manage-assessments.php', + ], + [ + 'title' => 'Manage Questions', + 'slug' => 'manage-questions', + 'template' => 'template-manage-questions.php', + ], + [ + 'title' => 'Manage Credits', + 'slug' => 'manage-credits', + 'template' => 'template-manage-credits.php', + ], + [ + 'title' => 'View Results', + 'slug' => 'view-results', + 'template' => 'template-view-results.php', + ], + ]; + + foreach ( $pages_to_create as $page_data ) { + // Check if page already exists by slug + $existing_page = get_page_by_path( $page_data['slug'], OBJECT, 'page' ); + + if ( ! $existing_page ) { + $page_args = [ + 'post_title' => $page_data['title'], + 'post_name' => $page_data['slug'], + 'post_content' => '', // Content can be added later or within the template + 'post_status' => 'publish', + 'post_author' => 1, // Assign to admin user ID 1 + 'post_type' => 'page', + 'page_template'=> $page_data['template'], // Assign the template + ]; + + $new_page_id = wp_insert_post( $page_args ); + + // Optional: Check if page creation was successful + // if ( is_wp_error( $new_page_id ) ) { + // error_log( 'Quiztech Activation Error: Failed to create page ' . $page_data['title'] . ': ' . $new_page_id->get_error_message() ); + // } elseif ( $new_page_id > 0 ) { + // // Optionally update meta if wp_insert_post didn't handle it (it should) + // // update_post_meta( $new_page_id, '_wp_page_template', $page_data['template'] ); + // } + } + } + + \flush_rewrite_rules(); // Ensure rewrite rules are updated for CPTs/taxonomies }