run(); } // run_quiztech(); // Placeholder for activation/deactivation hooks \register_activation_hook( __FILE__, __NAMESPACE__ . '\activate_quiztech' ); \register_deactivation_hook( __FILE__, __NAMESPACE__ . '\deactivate_quiztech' ); /** * The code that runs during plugin activation. * This action is documented in includes/class-quiztech-activator.php */ function activate_quiztech() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); $table_name = $wpdb->prefix . 'quiztech_invitations'; $sql = "CREATE TABLE {$table_name} ( id mediumint(9) NOT NULL AUTO_INCREMENT, token varchar(32) NOT NULL, job_id bigint(20) unsigned NOT NULL, assessment_id bigint(20) unsigned NOT NULL, applicant_email varchar(255) NOT NULL, status varchar(20) NOT NULL DEFAULT 'pending', created_timestamp datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, expiry_timestamp datetime DEFAULT NULL, PRIMARY KEY (id), UNIQUE KEY token (token), KEY job_id (job_id), KEY assessment_id (assessment_id), KEY applicant_email (applicant_email(191)), KEY status (status) ) {$charset_collate};"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); \dbDelta( $sql ); // Call the namespaced function for roles \Quiztech\AssessmentPlatform\Includes\quiztech_add_roles_and_capabilities(); \flush_rewrite_rules(); // Ensure rewrite rules are updated for CPTs/taxonomies } /** * The code that runs during plugin deactivation. * This action is documented in includes/class-quiztech-deactivator.php */ function deactivate_quiztech() { // Call the namespaced function \Quiztech\AssessmentPlatform\Includes\quiztech_remove_roles_and_capabilities(); \flush_rewrite_rules(); // Clean up rewrite rules } /** * Initialize the plugin's features. */ function quiztech_init() { // Initialize frontend handler for invitation links $frontend_handler = new \Quiztech\AssessmentPlatform\Includes\FrontendHandler(); $frontend_handler->init_hooks(); // Initialize AJAX handler for assessment interactions \Quiztech\AssessmentPlatform\Includes\Ajax\AssessmentAjaxHandler::init(); // Initialize Admin-specific features if ( is_admin() ) { $admin_list_tables = new \Quiztech\AssessmentPlatform\Admin\AdminListTables(); $admin_list_tables->register_hooks(); $settings_page = new \Quiztech\AssessmentPlatform\Admin\SettingsPage(); $settings_page->register_hooks(); $job_metaboxes = new \Quiztech\AssessmentPlatform\Admin\JobMetaboxes(); $job_metaboxes->register_hooks(); } // Future core classes (e.g., Shortcode handlers) should be instantiated here. } add_action( 'plugins_loaded', 'quiztech_init' ); /** * Configure PHPMailer to use SMTP settings if enabled. * * @param PHPMailer\PHPMailer\PHPMailer $phpmailer The PHPMailer instance. */ function quiztech_configure_smtp( $phpmailer ) { $options = get_option( 'quiztech_settings', [] ); // Check if SMTP is enabled in settings if ( empty( $options['smtp_enabled'] ) || ! $options['smtp_enabled'] ) { return; // SMTP not enabled, do nothing } // Basic validation if ( empty( $options['smtp_host'] ) || empty( $options['smtp_port'] ) ) { // Optionally log an error or add an admin notice here error_log('Quiztech SMTP Error: Host or Port not configured.'); return; // Cannot configure SMTP without host and port } // Set mailer to use SMTP $phpmailer->isSMTP(); // Set SMTP server details $phpmailer->Host = $options['smtp_host']; $phpmailer->Port = (int) $options['smtp_port']; // Set encryption type (tls, ssl, or none) $encryption = isset( $options['smtp_encryption'] ) ? strtolower( $options['smtp_encryption'] ) : ''; if ( in_array( $encryption, [ 'ssl', 'tls' ] ) ) { $phpmailer->SMTPSecure = $encryption; } else { $phpmailer->SMTPSecure = ''; // Explicitly set to none if not ssl/tls } // Set authentication details if enabled $phpmailer->SMTPAuth = ! empty( $options['smtp_auth'] ) && $options['smtp_auth']; if ( $phpmailer->SMTPAuth ) { if ( empty( $options['smtp_username'] ) || empty( $options['smtp_password'] ) ) { error_log('Quiztech SMTP Error: Auth enabled but Username or Password missing.'); // Decide if we should prevent sending or let PHPMailer handle the error // For now, we proceed and let PHPMailer fail if credentials are bad } $phpmailer->Username = isset( $options['smtp_username'] ) ? $options['smtp_username'] : ''; $phpmailer->Password = isset( $options['smtp_password'] ) ? $options['smtp_password'] : ''; } // Set From address (optional, but recommended) $from_address = isset( $options['smtp_from_address'] ) ? $options['smtp_from_address'] : ''; $from_name = isset( $options['smtp_from_name'] ) ? $options['smtp_from_name'] : get_bloginfo( 'name' ); if ( ! empty( $from_address ) && is_email( $from_address ) ) { try { $phpmailer->setFrom( $from_address, $from_name ); } catch ( \PHPMailer\PHPMailer\Exception $e ) { error_log( 'Quiztech SMTP Error setting From address: ' . $e->getMessage() ); // Continue without setting From if it fails } } // Optional: Add debugging // $phpmailer->SMTPDebug = 2; // Enable verbose debug output (use 0 in production) // $phpmailer->Debugoutput = 'error_log'; // Log debug output to PHP error log } add_action( 'phpmailer_init', 'quiztech_configure_smtp' );