array( 'label' => __( 'Overview', 'ai-seo-tools' ), 'icon' => 'grid', ), 'write' => array( 'label' => __( 'Write', 'ai-seo-tools' ), 'icon' => 'pen', 'module' => 'enable_post_generator_module', ), 'alt-text' => array( 'label' => __( 'Alt text', 'ai-seo-tools' ), 'icon' => 'image', 'module' => 'enable_alt_text_module', ), 'tags' => array( 'label' => __( 'Tags', 'ai-seo-tools' ), 'icon' => 'tag', 'module' => 'enable_auto_tagging_module', ), 'snippets' => array( 'label' => __( 'Snippets', 'ai-seo-tools' ), 'icon' => 'search', 'module' => 'enable_meta_module', ), 'schema' => array( 'label' => __( 'Structured data', 'ai-seo-tools' ), 'icon' => 'code', 'module' => 'enable_schema_module', ), 'activity' => array( 'label' => __( 'Activity', 'ai-seo-tools' ), 'icon' => 'activity', ), 'settings' => array( 'label' => __( 'Settings', 'ai-seo-tools' ), 'icon' => 'settings', ), ); } public function __construct() { add_action( 'admin_menu', array( $this, 'register_menu' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); add_filter( 'admin_body_class', array( $this, 'body_class' ) ); add_action( 'wp_ajax_ai_seo_queue_status', array( $this, 'ajax_queue_status' ) ); add_action( 'wp_ajax_ai_seo_queue_stop', array( $this, 'ajax_queue_stop' ) ); add_action( 'wp_ajax_ai_seo_queue_reset', array( $this, 'ajax_queue_reset' ) ); add_action( 'wp_ajax_ai_seo_refresh_models', array( $this, 'ajax_refresh_models' ) ); add_action( 'wp_ajax_ai_seo_test_key', array( $this, 'ajax_test_key' ) ); add_action( 'wp_ajax_ai_seo_activity', array( $this, 'ajax_activity' ) ); } /* --------------------------------------------------------------------- */ /* Menu */ /* --------------------------------------------------------------------- */ public function register_menu(): void { add_menu_page( esc_html__( 'AI SEO Tools', 'ai-seo-tools' ), esc_html__( 'AI SEO Tools', 'ai-seo-tools' ), 'manage_options', self::SLUG, array( $this, 'render_page' ), $this->menu_icon(), 76 ); } /** * Menu mark for the admin sidebar. * * WordPress runs svg-painter.js over base64 menu icons and rewrites every * fill to a single colour from the active admin scheme, so this variant is * deliberately flat: no gradients, no strokes and no background plate. The * full-colour brand icon is used on the plugin's own screen instead. */ private function menu_icon(): string { $path = AI_SEO_TOOLS_PATH . 'assets/images/menu-icon.svg'; if ( ! is_readable( $path ) ) { return 'dashicons-search'; } // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Bundled asset. $svg = file_get_contents( $path ); if ( false === $svg ) { return 'dashicons-search'; } $svg = trim( (string) preg_replace( '/\s+/S', ' ', $svg ) ); return 'data:image/svg+xml;base64,' . base64_encode( $svg ); } /** * URL of the full-colour brand icon. */ public static function brand_icon_url(): string { return AI_SEO_TOOLS_URL . 'assets/images/icon.svg'; } public function body_class( string $classes ): string { if ( $this->is_plugin_screen() ) { $classes .= ' ai-seo-admin '; } return $classes; } private function is_plugin_screen(): bool { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen check. return isset( $_GET['page'] ) && self::SLUG === sanitize_key( wp_unslash( $_GET['page'] ) ); } public static function current_tab(): string { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only screen check. $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'overview'; return array_key_exists( $tab, self::tabs() ) ? $tab : 'overview'; } public static function tab_url( string $tab ): string { return add_query_arg( array( 'page' => self::SLUG, 'tab' => $tab, ), admin_url( 'admin.php' ) ); } /* --------------------------------------------------------------------- */ /* Assets */ /* --------------------------------------------------------------------- */ public function enqueue( string $hook ): void { $on_plugin_screen = $this->is_plugin_screen(); $on_list_table = in_array( $hook, array( 'upload.php', 'edit.php' ), true ); $on_editor = in_array( $hook, array( 'post.php', 'post-new.php' ), true ); if ( ! $on_plugin_screen && ! $on_list_table && ! $on_editor ) { return; } wp_enqueue_style( 'ai-seo-admin', AI_SEO_TOOLS_URL . 'admin/assets/css/ai-seo-admin.css', array(), AI_SEO_TOOLS_VERSION ); wp_enqueue_script( 'ai-seo-admin', AI_SEO_TOOLS_URL . 'admin/assets/js/ai-seo-admin.js', array(), AI_SEO_TOOLS_VERSION, true ); wp_localize_script( 'ai-seo-admin', 'aiSeo', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => AI_SEO_Tools_Ajax::nonce(), 'ready' => AI_SEO_Tools_Client::is_ready(), 'settings' => self::tab_url( 'settings' ), 'i18n' => array( 'working' => __( 'Working…', 'ai-seo-tools' ), 'generating' => __( 'Generating…', 'ai-seo-tools' ), 'saved' => __( 'Saved', 'ai-seo-tools' ), 'failed' => __( 'Failed', 'ai-seo-tools' ), 'noKey' => __( 'Add an API key first.', 'ai-seo-tools' ), 'confirmStop' => __( 'Stop this run? Anything already processed is kept.', 'ai-seo-tools' ), 'undo' => __( 'Undo', 'ai-seo-tools' ), 'undone' => __( 'Reverted', 'ai-seo-tools' ), 'nothing' => __( 'Nothing to show yet.', 'ai-seo-tools' ), 'apply' => __( 'Apply', 'ai-seo-tools' ), 'noLinks' => __( 'No worthwhile internal links found for this post.', 'ai-seo-tools' ), 'added' => __( 'Added', 'ai-seo-tools' ), 'generate' => __( 'Generate', 'ai-seo-tools' ), 'save' => __( 'Save', 'ai-seo-tools' ), 'review' => __( 'Review and save', 'ai-seo-tools' ), 'drafted' => __( 'Draft created', 'ai-seo-tools' ), 'openDraft' => __( 'Open draft', 'ai-seo-tools' ), 'noTopic' => __( 'Type a topic first.', 'ai-seo-tools' ), 'regenerate' => __( 'Regenerate', 'ai-seo-tools' ), 'removed' => __( 'Removed', 'ai-seo-tools' ), ), ) ); } /* --------------------------------------------------------------------- */ /* Page shell */ /* --------------------------------------------------------------------- */ public function render_page(): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have permission to view this page.', 'ai-seo-tools' ) ); } $tab = self::current_tab(); $options = get_option( AI_SEO_Tools_Client::OPTION, array() ); ?>