[title, cap] */ public static function screens() { $ai_cap = Aeoora_Settings::get( 'ai', 'roles', 'publish_posts' ); return array( 'aeoora' => array( __( 'Dashboard', 'aeoora' ), 'manage_options', 'dashboard' ), 'aeoora-crawlers' => array( __( 'AI crawlers', 'aeoora' ), 'manage_options', 'crawlers' ), 'aeoora-referrals' => array( __( 'AI referrals', 'aeoora' ), 'manage_options', 'referrals' ), 'aeoora-audit' => array( __( 'AEO audit', 'aeoora' ), 'manage_options', 'audit' ), 'aeoora-suggestions' => array( __( 'Daily suggestions', 'aeoora' ), $ai_cap, 'suggestions' ), 'aeoora-studio' => array( __( 'AI Studio', 'aeoora' ), $ai_cap, 'studio' ), 'aeoora-access' => array( __( 'llms.txt & Markdown', 'aeoora' ), 'manage_options', 'access' ), 'aeoora-settings' => array( __( 'Settings', 'aeoora' ), 'manage_options', 'settings' ), 'aeoora-cloud' => array( __( 'aeoora Cloud', 'aeoora' ), 'manage_options', 'cloud' ), ); } /** * Menu icon (data URI so WordPress can tint it). * * @return string */ private static function icon() { // Ora the robot: head, visor (cut out), eyes, signal dot. Single fill so WordPress can tint it. $svg = ''; return 'data:image/svg+xml;base64,' . base64_encode( $svg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions } /** * Register menus. */ public static function menu() { $ai_cap = Aeoora_Settings::get( 'ai', 'roles', 'publish_posts' ); $top_cap = current_user_can( 'manage_options' ) ? 'manage_options' : $ai_cap; $pending = current_user_can( 'manage_options' ) ? Aeoora_Suggestions::pending_count() : 0; $badge = $pending ? ' ' . number_format_i18n( $pending ) . '' : ''; $first = current_user_can( 'manage_options' ) ? 'aeoora' : 'aeoora-studio'; self::$hooks[] = add_menu_page( 'aeoora', 'aeoora' . $badge, $top_cap, $first, array( __CLASS__, 'render' ), self::icon(), 58.7 ); foreach ( self::screens() as $slug => $s ) { if ( ! current_user_can( $s[1] ) ) { continue; } $label = $s[0]; if ( 'aeoora-suggestions' === $slug && $pending ) { $label .= $badge; } self::$hooks[] = add_submenu_page( $first, sprintf( /* translators: %s: screen name. */ __( '%s ‹ aeoora', 'aeoora' ), $s[0] ), $label, $s[1], $slug, array( __CLASS__, 'render' ) ); } // Hidden screen for the guided setup flow. $setup = add_submenu_page( '', __( 'Setup ‹ aeoora', 'aeoora' ), '', 'manage_options', 'aeoora-setup', array( __CLASS__, 'render' ) ); if ( $setup ) { self::$hooks[] = $setup; add_action( 'load-' . $setup, static function () { $GLOBALS['title'] = __( 'aeoora setup', 'aeoora' ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- hidden page has no menu title. } ); } } /** * Current screen key. * * @return string */ private static function current() { $page = isset( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : 'aeoora'; // phpcs:ignore WordPress.Security.NonceVerification if ( 'aeoora-setup' === $page ) { return 'setup'; } $screens = self::screens(); return isset( $screens[ $page ] ) ? $screens[ $page ][2] : 'dashboard'; } /** * Render shell. */ public static function render() { $current = self::current(); echo '

aeoora

'; echo '
'; echo '' . esc_attr__( 'aeoora home', 'aeoora' ) . ''; echo ''; if ( 'setup' === $current ) { echo '
' . esc_html__( 'Setup', 'aeoora' ) . '
'; echo '
' . esc_html__( 'Loading…', 'aeoora' ) . '
'; return; } echo ''; echo '
' . esc_html__( 'Loading…', 'aeoora' ) . '
'; echo ''; echo ''; } /** * Enqueue assets on our screens. * * @param string $hook Hook. */ public static function assets( $hook ) { if ( ! in_array( $hook, self::$hooks, true ) ) { return; } wp_enqueue_style( 'aeoora-admin', AEOORA_URL . 'assets/css/admin.css', array(), AEOORA_VERSION ); wp_enqueue_script( 'aeoora-charts', AEOORA_URL . 'assets/js/charts.js', array( 'wp-i18n' ), AEOORA_VERSION, true ); wp_set_script_translations( 'aeoora-charts', 'aeoora', AEOORA_DIR . 'languages' ); $deps = array( 'wp-api-fetch', 'wp-i18n', 'wp-a11y', 'aeoora-charts' ); if ( 'studio' === self::current() ) { // The Notion-style article editor of AI Studio's blog writer. wp_enqueue_script( 'aeoora-article-editor', AEOORA_URL . 'assets/js/block-editor.js', array( 'wp-i18n' ), AEOORA_VERSION, true ); wp_set_script_translations( 'aeoora-article-editor', 'aeoora', AEOORA_DIR . 'languages' ); $deps[] = 'aeoora-article-editor'; } wp_enqueue_script( 'aeoora-admin', AEOORA_URL . 'assets/js/admin.js', $deps, AEOORA_VERSION, true ); wp_set_script_translations( 'aeoora-admin', 'aeoora', AEOORA_DIR . 'languages' ); if ( 'settings' === self::current() ) { wp_enqueue_media(); } $user = wp_get_current_user(); wp_localize_script( 'aeoora-admin', 'AEOORA', array( 'version' => AEOORA_VERSION, 'home' => home_url( '/' ), 'origin' => Aeoora_Util::origin(), 'admin' => admin_url(), 'assets' => AEOORA_URL . 'assets/', 'isAdmin' => current_user_can( 'manage_options' ), 'seo' => Aeoora_Seo::active_label(), 'canWrite' => Aeoora_Seo::can_write(), 'locale' => str_replace( '_', '-', get_user_locale() ), 'welcome' => (bool) get_option( 'aeoora_show_welcome' ) && current_user_can( 'manage_options' ), 'dismissNonce' => wp_create_nonce( 'aeoora_dismiss' ), 'setup' => current_user_can( 'manage_options' ) ? Aeoora_Setup::status() : null, 'user' => $user ? $user->display_name : '', 'siteName' => wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), 'tagline' => wp_specialchars_decode( get_bloginfo( 'description' ), ENT_QUOTES ), 'checks' => Aeoora_Audit::check_labels(), 'cloud' => array( 'connected' => Aeoora_Cloud::connected(), 'ai' => Aeoora_Cloud::ai_available(), 'url' => admin_url( 'admin.php?page=aeoora-cloud' ), ), 'urls' => array( 'review' => self::REVIEW_URL, 'llms' => home_url( '/llms.txt' ), 'full' => home_url( '/llms-full.txt' ), 'robots' => home_url( '/robots.txt' ), 'newPost' => admin_url( 'post-new.php' ), 'settings' => admin_url( 'admin.php?page=aeoora-settings' ), ), ) ); } /** * Keep the aeoora menu open on the hidden setup screen. * * @param string $parent Parent file. * @return string */ public static function highlight_menu( $parent ) { return 'setup' === self::current() && isset( $_GET['page'] ) ? 'aeoora' : $parent; // phpcs:ignore WordPress.Security.NonceVerification } /** * Highlight "Dashboard" in the submenu on the setup screen. * * @param string|null $submenu Submenu file. * @return string|null */ public static function highlight_submenu( $submenu ) { return 'setup' === self::current() && isset( $_GET['page'] ) ? 'aeoora' : $submenu; // phpcs:ignore WordPress.Security.NonceVerification } /** * Register aeoora commands in the WordPress command palette (Ctrl/⌘+K). * Tiny, and only when WordPress itself loads the palette. */ public static function commands() { if ( ! wp_script_is( 'wp-commands', 'registered' ) || ! wp_script_is( 'wp-commands', 'enqueued' ) ) { return; } $admin = current_user_can( 'manage_options' ); $ai = Aeoora_Util::can_use_ai(); if ( ! $admin && ! $ai ) { return; } $url = static function ( $page ) { return admin_url( 'admin.php?page=' . $page ); }; $list = array(); if ( $admin ) { $list[] = array( 'id' => 'dashboard', 'label' => __( 'aeoora: AI visibility dashboard', 'aeoora' ), 'url' => $url( 'aeoora' ) ); $list[] = array( 'id' => 'crawlers', 'label' => __( 'aeoora: AI crawler policies', 'aeoora' ), 'url' => $url( 'aeoora-crawlers' ) ); $list[] = array( 'id' => 'referrals', 'label' => __( 'aeoora: AI referrals', 'aeoora' ), 'url' => $url( 'aeoora-referrals' ) ); $list[] = array( 'id' => 'audit', 'label' => __( 'aeoora: Run the AEO site audit', 'aeoora' ), 'url' => $url( 'aeoora-audit' ) ); $list[] = array( 'id' => 'llms', 'label' => __( 'aeoora: View llms.txt', 'aeoora' ), 'url' => home_url( '/llms.txt' ), 'external' => true ); $list[] = array( 'id' => 'settings', 'label' => __( 'aeoora: Settings & AI keys', 'aeoora' ), 'url' => $url( 'aeoora-settings' ) ); $setup = get_option( Aeoora_Setup::OPTION, array() ); if ( empty( $setup['completed'] ) ) { $list[] = array( 'id' => 'setup', 'label' => __( 'aeoora: Finish setup', 'aeoora' ), 'url' => $url( 'aeoora-setup' ) ); } } if ( $ai ) { $list[] = array( 'id' => 'write', 'label' => __( 'aeoora: Write a post with AI', 'aeoora' ), 'url' => $url( 'aeoora-studio' ) ); $list[] = array( 'id' => 'suggestions', 'label' => __( 'aeoora: Daily suggestions', 'aeoora' ), 'url' => $url( 'aeoora-suggestions' ) ); } wp_enqueue_script( 'aeoora-commands', AEOORA_URL . 'assets/js/commands.js', array( 'wp-commands', 'wp-data' ), AEOORA_VERSION, true ); wp_add_inline_script( 'aeoora-commands', 'window.aeooraCommands=' . wp_json_encode( array( 'commands' => $list ) ) . ';', 'before' ); } /** * Plugin action links. * * @param array $links Links. * @return array */ public static function action_links( $links ) { array_unshift( $links, '' . esc_html__( 'Dashboard', 'aeoora' ) . '', '' . esc_html__( 'Settings', 'aeoora' ) . '' ); if ( ! Aeoora_Cloud::connected() ) { $links[] = '' . esc_html__( 'Track AI answers', 'aeoora' ) . ''; } return $links; } /** * Plugin row meta. * * @param array $meta Meta. * @param string $file File. * @return array */ public static function row_meta( $meta, $file ) { if ( AEOORA_BASENAME === $file ) { $meta[] = '' . esc_html__( 'Documentation', 'aeoora' ) . ''; $meta[] = '' . esc_html__( 'Support', 'aeoora' ) . ''; $meta[] = '' . esc_html__( 'Rate ★★★★★', 'aeoora' ) . ''; $meta[] = '' . esc_html__( 'Free forever – no credits, nothing locked', 'aeoora' ) . ''; } return $meta; } /** * Admin notices. */ public static function notices() { if ( ! current_user_can( 'manage_options' ) ) { return; } $screen = get_current_screen(); $ours = $screen && in_array( $screen->id, self::$hooks, true ); if ( get_option( 'aeoora_show_welcome' ) && ! $ours && $screen && in_array( $screen->id, array( 'dashboard', 'plugins' ), true ) ) { echo '

aeoora — ' . esc_html__( 'Your free AEO toolkit is active: crawler tracking, llms.txt and Markdown are already working.', 'aeoora' ) . ' ' . esc_html__( 'Finish setup (2 minutes)', 'aeoora' ) . '

'; self::dismiss_script(); } if ( $ours && self::ask_review() ) { echo '

' . esc_html__( 'Is aeoora helping your site show up in AI answers?', 'aeoora' ) . ' ' . esc_html__( 'A quick review on WordPress.org helps other site owners find it, and keeps aeoora free.', 'aeoora' ) . '

' . '' . esc_html__( 'Leave a ★★★★★ review', 'aeoora' ) . ' ' . ' ' . '

'; self::dismiss_script(); } if ( $ours && Aeoora_Robots::has_physical() && ! get_option( 'aeoora_robots_physical_sync' ) && Aeoora_Settings::get( 'robots', 'policies' ) ) { echo '

' . esc_html__( 'A physical robots.txt file exists in your site root, so WordPress cannot apply your aeoora crawler rules. Open AI crawlers → robots.txt to sync them into the file.', 'aeoora' ) . '

'; } $error = get_option( 'aeoora_install_error' ); if ( is_array( $error ) && ! empty( $error['tables'] ) ) { echo '

aeoora — ' . esc_html( sprintf( /* translators: 1: table names, 2: database error message. */ __( 'The database tables could not be created (%1$s), so crawler visits are not being recorded. Ask your host to allow the database user to create tables; aeoora tries again every ten minutes while you use the admin. Database said: %2$s', 'aeoora' ), implode( ', ', (array) $error['tables'] ), isset( $error['error'] ) && '' !== $error['error'] ? (string) $error['error'] : '—' ) ) . '

'; } if ( $ours && ! get_option( 'aeoora_cache_notice_dismissed' ) ) { $caches = Aeoora_Compat::page_caches(); if ( $caches ) { self::cache_notice( $caches ); self::dismiss_script(); } } } /** * Page cache notice with copy-ready rules that let crawlers through the * cache (so their visits are logged and blocks apply). * * @param string[] $caches Detected caches. */ private static function cache_notice( array $caches ) { $ai = array(); $blocked = array(); foreach ( Aeoora_Bots::all() as $id => $bot ) { if ( ! empty( $bot['regex'] ) || ! empty( $bot['either'] ) || '' === (string) $bot['pattern'] ) { continue; } if ( 'block' === Aeoora_Bots::policy( $id ) ) { $blocked[ $bot['pattern'] ] = true; } elseif ( Aeoora_Bots::is_ai_category( $bot['category'] ) && ! empty( $bot['token'] ) ) { $ai[ $bot['pattern'] ] = true; } } $all = array_keys( $ai + $blocked ); if ( ! $all ) { return; } $re = implode( '|', array_map( static function ( $p ) { return str_replace( '"', '', preg_quote( $p, '#' ) ); }, $all ) ); $cf = implode( ' or ', array_map( static function ( $p ) { return '(http.user_agent contains "' . str_replace( array( '\\', '"' ), '', $p ) . '")'; }, array_slice( $all, 0, 60 ) ) ); $htaccess = "# BEGIN aeoora: AI crawlers bypass the page cache\n\nRewriteEngine On\nRewriteCond %{HTTP_USER_AGENT} \"({$re})\" [NC]\nRewriteRule .* - [E=Cache-Control:no-cache]\n\n# END aeoora: AI crawlers bypass the page cache"; $nginx = "# http {} block\nmap \$http_user_agent \$aeoora_bot {\n\tdefault 0;\n\t\"~*({$re})\" 1;\n}\n\n# server {} or location {} block that uses fastcgi_cache\nfastcgi_cache_bypass \$aeoora_bot;\nfastcgi_no_cache \$aeoora_bot;"; echo '

' . esc_html( sprintf( /* translators: %s: page cache names. */ __( 'Page cache detected: %s.', 'aeoora' ), implode( ', ', $caches ) ) ) . ' ' . esc_html__( 'Cached pages are served without running WordPress, so aeoora cannot log crawler visits to them, and crawlers you block still get them. Let AI crawlers through the cache with one of these rules:', 'aeoora' ) . '

'; if ( in_array( 'WP Rocket', $caches, true ) ) { echo '

' . esc_html__( 'WP Rocket: turn on “never serve cached pages to AI crawlers” in aeoora → Settings → Tracking.', 'aeoora' ) . '

'; } $snippets = array( __( 'LiteSpeed (.htaccess, at the top)', 'aeoora' ) => $htaccess, __( 'Nginx FastCGI cache (server configuration)', 'aeoora' ) => $nginx, __( 'Cloudflare (Caching → Cache Rules → Bypass cache, “Edit expression”)', 'aeoora' ) => $cf, ); foreach ( $snippets as $label => $code ) { echo '
' . esc_html( $label ) . '
'; } echo '

' . esc_html__( 'Bypassing the cache for these crawlers makes WordPress answer their requests. The rules list the AI crawlers that respect robots.txt plus the crawlers you block.', 'aeoora' ) . '

'; } /** * Tiny dismiss script for notices outside our screens. */ private static function dismiss_script() { static $added = false; if ( $added ) { return; } $added = true; $js = "document.addEventListener('click',function(e){if(!e.target.closest){return;}var a=e.target.closest('.aeoora-notice [data-aeoora-action]');var n=a||e.target.closest('.aeoora-notice .notice-dismiss');if(!n){return;}var box=n.closest('.aeoora-notice');var fd=new FormData();fd.append('action','aeoora_dismiss');fd.append('what',a?a.getAttribute('data-aeoora-action'):box.getAttribute('data-aeoora-dismiss'));fd.append('_wpnonce'," . wp_json_encode( wp_create_nonce( 'aeoora_dismiss' ) ) . ");fetch(window.ajaxurl,{method:'POST',body:fd,credentials:'same-origin'});if(a){box.remove();}});"; wp_add_inline_script( 'common', $js ); } /** * Time to ask for a review? Seven days after install, never during setup, * and not again once answered ("later" waits 30 days). * * @return bool */ private static function ask_review() { $state = get_option( 'aeoora_review', 0 ); if ( 'done' === $state || ( is_numeric( $state ) && time() < (int) $state ) || 'setup' === self::current() ) { return false; } $installed = (int) get_option( 'aeoora_installed_at', time() ); return time() - $installed > 7 * DAY_IN_SECONDS && (bool) apply_filters( 'aeoora_ask_review', true ); } /** * Dismiss handler. */ public static function dismiss() { check_ajax_referer( 'aeoora_dismiss' ); $what = isset( $_POST['what'] ) ? sanitize_key( wp_unslash( $_POST['what'] ) ) : ''; if ( current_user_can( 'manage_options' ) ) { if ( 'welcome' === $what ) { delete_option( 'aeoora_show_welcome' ); } elseif ( 'cache' === $what ) { update_option( 'aeoora_cache_notice_dismissed', 1, false ); } elseif ( 'review_done' === $what ) { update_option( 'aeoora_review', 'done', false ); } elseif ( 'review_later' === $what ) { update_option( 'aeoora_review', time() + 30 * DAY_IN_SECONDS, false ); } } wp_send_json_success(); } /** * Footer text on our screens. * * @param string $text Text. * @return string */ public static function footer_text( $text ) { $screen = get_current_screen(); if ( $screen && in_array( $screen->id, self::$hooks, true ) ) { /* translators: %s: version. */ return sprintf( esc_html__( 'aeoora %s · Free and open source AEO for WordPress · Built by Codefreex', 'aeoora' ), esc_html( AEOORA_VERSION ) ) . ' · aeoora.com · ' /* translators: %s: link to the review form, with five stars as its text. */ . sprintf( esc_html__( 'Enjoying aeoora? Rate it %s on WordPress.org.', 'aeoora' ), '★★★★★' ); } return $text; } }