check_requirements(); $this->create_database_tables(); $this->set_default_options(); $this->schedule_cron_jobs(); $this->set_activation_flag(); } /** * Check system requirements * * @return void * @throws \Exception If requirements not met */ private function check_requirements(): void { // PHP version check if (version_compare(PHP_VERSION, '8.0', '<')) { throw new \Exception('ThinkRank requires PHP 8.0 or higher'); } // WordPress version check if (version_compare(get_bloginfo('version'), '6.0', '<')) { throw new \Exception('ThinkRank requires WordPress 6.0 or higher'); } // Required PHP extensions $required_extensions = ['curl', 'json', 'mbstring']; foreach ($required_extensions as $extension) { if (!extension_loaded($extension)) { throw new \Exception(sprintf("Required PHP extension '%s' is not loaded", esc_html($extension))); } } // Check if we can write to WordPress root directory (for robots.txt, llms.txt, sitemaps) if (!wp_is_writable(ABSPATH)) { throw new \Exception('WordPress root directory is not writable'); } } /** * Create database tables * * Uses the consolidated Database_Schema class to create all 11 ThinkRank tables: * - SEO Tables (7): Settings, Analysis, Keywords, Schema, Social, Performance, Local * - AI/Core Tables (4): AI Cache, AI Usage, Content Briefs, SEO Scores * * @return void * @throws \Exception If table creation fails */ private function create_database_tables(): void { try { // Use the Database_Schema class to create all 11 ThinkRank tables $schema = new Database_Schema(); $results = $schema->create_tables(); if (!$results['success']) { $error_message = 'Failed to create database tables: ' . implode(', ', $results['errors']); throw new \Exception($error_message); } // Add performance indexes for Phase 2 optimization $index_results = $schema->add_performance_indexes(); if (!$index_results) { // Performance indexes could not be created - activation continues } // Database tables created successfully } catch (\Exception $e) { throw new \Exception('Database table creation failed: ' . esc_html($e->getMessage())); } } /** * Set default plugin options * * @return void */ private function set_default_options(): void { $default_options = [ 'thinkrank_version' => THINKRANK_VERSION, 'thinkrank_ai_provider' => 'openai', 'thinkrank_cache_duration' => 3600, // 1 hour 'thinkrank_max_requests_per_minute' => 10, 'thinkrank_enable_logging' => true, 'thinkrank_auto_optimize' => false, 'thinkrank_seo_score_threshold' => 70, ]; foreach ($default_options as $option_name => $option_value) { if (get_option($option_name) === false) { add_option($option_name, $option_value); } } } /** * Schedule cron jobs * * @return void */ private function schedule_cron_jobs(): void { // Schedule cache cleanup if (!wp_next_scheduled('thinkrank_cache_cleanup')) { wp_schedule_event(time(), 'daily', 'thinkrank_cache_cleanup'); } // Schedule usage analytics if (!wp_next_scheduled('thinkrank_usage_analytics')) { wp_schedule_event(time(), 'weekly', 'thinkrank_usage_analytics'); } } /** * Set activation flag for first-time setup * * @return void */ private function set_activation_flag(): void { update_option('thinkrank_activated', true); update_option('thinkrank_activation_time', time()); // Set flag for showing welcome screen update_option('thinkrank_show_welcome', true); } }