*/ function ai_seo_tools_get_modules(): array { return apply_filters( 'ai_seo_tools_modules', array( 'enable_alt_text_module' => array( 'file' => AI_SEO_TOOLS_PATH . 'modules/alt-text/class-ai-seo-tools-alt-text.php', 'class' => 'AI_SEO_Tools_Alt_Text', 'label' => 'Alt text', ), 'enable_auto_tagging_module' => array( 'file' => AI_SEO_TOOLS_PATH . 'modules/auto-tagging/class-ai-seo-tools-auto-tagging.php', 'class' => 'AI_SEO_Tools_Auto_Tagging', 'label' => 'Auto tagging', ), 'enable_meta_module' => array( 'file' => AI_SEO_TOOLS_PATH . 'modules/meta/class-ai-seo-tools-meta.php', 'class' => 'AI_SEO_Tools_Meta', 'label' => 'Search snippets', ), 'enable_schema_module' => array( 'file' => AI_SEO_TOOLS_PATH . 'modules/schema/class-ai-seo-tools-schema.php', 'class' => 'AI_SEO_Tools_Schema', 'label' => 'Structured data', ), 'enable_content_refresh_module' => array( 'file' => AI_SEO_TOOLS_PATH . 'modules/content-refresh/class-ai-seo-tools-content-refresh.php', 'class' => 'AI_SEO_Tools_Content_Refresh', 'label' => 'Content refresh', ), 'enable_internal_links_module' => array( 'file' => AI_SEO_TOOLS_PATH . 'modules/internal-links/class-ai-seo-tools-internal-links.php', 'class' => 'AI_SEO_Tools_Internal_Links', 'label' => 'Internal links', ), 'enable_post_generator_module' => array( 'file' => AI_SEO_TOOLS_PATH . 'modules/post-generator/class-ai-seo-tools-post-generator.php', 'class' => 'AI_SEO_Tools_Post_Generator', 'label' => 'Draft writer', ), ) ); } /** * Boots the plugin. */ function ai_seo_tools_boot(): void { foreach ( ai_seo_tools_core_files() as $file ) { require_once $file; } AI_SEO_Tools_Queue::init(); new AI_SEO_Tools_Undo(); // Admin classes are needed even when every module is off, so the settings // screen can turn them back on. if ( is_admin() ) { require_once AI_SEO_TOOLS_PATH . 'admin/class-ai-seo-tools-settings.php'; require_once AI_SEO_TOOLS_PATH . 'admin/class-ai-seo-tools-views.php'; require_once AI_SEO_TOOLS_PATH . 'admin/class-ai-seo-tools-admin.php'; new AI_SEO_Tools_Settings(); new AI_SEO_Tools_Admin(); } $options = get_option( AI_SEO_Tools_Client::OPTION, array() ); // The admin screens report statistics across every module, and WP-CLI can be // pointed at a module that is switched off in the UI, so both contexts need // the class files even when the module is not booted. $needs_all = is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ); foreach ( ai_seo_tools_get_modules() as $option_key => $module ) { $enabled = ( $options[ $option_key ] ?? '1' ) !== '0'; if ( ! file_exists( $module['file'] ) ) { continue; } if ( ! $enabled && ! $needs_all ) { continue; } require_once $module['file']; if ( $enabled && class_exists( $module['class'] ) ) { new $module['class'](); } } require_once AI_SEO_TOOLS_PATH . 'includes/class-ai-seo-tools-cli.php'; load_plugin_textdomain( 'ai-seo-tools', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } add_action( 'plugins_loaded', 'ai_seo_tools_boot' ); /** * Creates the log table and seeds defaults. */ function ai_seo_tools_activate(): void { require_once AI_SEO_TOOLS_PATH . 'includes/class-ai-seo-tools-log.php'; require_once AI_SEO_TOOLS_PATH . 'includes/class-ai-seo-tools-client.php'; require_once AI_SEO_TOOLS_PATH . 'admin/class-ai-seo-tools-settings.php'; AI_SEO_Tools_Log::install(); AI_SEO_Tools_Settings::migrate(); if ( ! wp_next_scheduled( 'ai_seo_tools_daily' ) ) { wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', 'ai_seo_tools_daily' ); } } register_activation_hook( __FILE__, 'ai_seo_tools_activate' ); /** * Leaves no scheduled work behind. */ function ai_seo_tools_deactivate(): void { require_once AI_SEO_TOOLS_PATH . 'includes/class-ai-seo-tools-queue.php'; AI_SEO_Tools_Queue::purge_all(); wp_clear_scheduled_hook( 'ai_seo_tools_daily' ); // Per-attachment jobs carry an argument, so they need the hook-wide call: // wp_clear_scheduled_hook() without matching args leaves every one of them behind. wp_unschedule_hook( 'ai_seo_generate_alt_text' ); } register_deactivation_hook( __FILE__, 'ai_seo_tools_deactivate' ); /** * Daily housekeeping: trim the activity log. */ function ai_seo_tools_daily(): void { $options = get_option( AI_SEO_Tools_Client::OPTION, array() ); $retention = max( 7, (int) ( $options['log_retention_days'] ?? 90 ) ); AI_SEO_Tools_Log::prune( $retention ); } add_action( 'ai_seo_tools_daily', 'ai_seo_tools_daily' ); /** * Runs the table install after an update that bumps the schema. */ function ai_seo_tools_maybe_upgrade(): void { if ( ! is_admin() ) { return; } AI_SEO_Tools_Log::maybe_install(); if ( get_option( 'ai_seo_tools_version' ) !== AI_SEO_TOOLS_VERSION ) { AI_SEO_Tools_Settings::migrate(); update_option( 'ai_seo_tools_version', AI_SEO_TOOLS_VERSION, false ); } } add_action( 'admin_init', 'ai_seo_tools_maybe_upgrade' ); /** * Settings shortcut on the Plugins screen. */ function ai_seo_tools_action_links( array $links ): array { $settings = sprintf( '%s', esc_url( admin_url( 'admin.php?page=ai-seo-tools&tab=settings' ) ), esc_html__( 'Settings', 'ai-seo-tools' ) ); array_unshift( $links, $settings ); return $links; } add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'ai_seo_tools_action_links' );