add_all_pages(); } elseif ( current_user_can( Capabilities::files() ) ) { $this->add_files_page_only(); } } /** * Adds the full menu with Settings, llms.txt and Verify & Preview. * * @return void */ private function add_all_pages(): void { add_menu_page( __( 'AgentWelcome', 'agentwelcome' ), __( 'AgentWelcome', 'agentwelcome' ), 'manage_options', SettingsPage::SLUG, array( $this->settings, 'render' ), $this->icon(), self::POSITION ); add_submenu_page( SettingsPage::SLUG, __( 'AgentWelcome Settings', 'agentwelcome' ), __( 'Settings', 'agentwelcome' ), 'manage_options', SettingsPage::SLUG, array( $this->settings, 'render' ) ); add_submenu_page( SettingsPage::SLUG, __( 'llms.txt', 'agentwelcome' ), __( 'llms.txt', 'agentwelcome' ), Capabilities::files(), LlmsPage::SLUG, array( $this->llms, 'render' ) ); add_submenu_page( SettingsPage::SLUG, __( 'Verify & Preview', 'agentwelcome' ), __( 'Verify & Preview', 'agentwelcome' ), 'manage_options', VerifyPage::SLUG, array( $this->verify, 'render' ) ); } /** * Adds a top-level menu with the llms.txt page alone. * * @return void */ private function add_files_page_only(): void { add_menu_page( __( 'llms.txt', 'agentwelcome' ), __( 'llms.txt', 'agentwelcome' ), Capabilities::files(), LlmsPage::SLUG, array( $this->llms, 'render' ), $this->icon(), self::POSITION ); } /** * Replaces the admin footer text on the plugin pages. * * @param mixed $text Current footer text. * @return mixed The new text on the plugin pages, otherwise the text unchanged. */ public function footer_text( mixed $text ): mixed { if ( ! $this->is_plugin_screen() ) { return $text; } return wp_kses( sprintf( /* translators: %s: author name, linked to their profile. */ __( 'Thank you for using AgentWelcome. Built by %s.', 'agentwelcome' ), 'Sami Ahmed Siddiqui' ), array( 'a' => array( 'href' => array(), 'target' => array(), 'rel' => array(), ), ) ); } /** * Replaces the WordPress version in the footer on the plugin pages. * * @param mixed $text Current footer text. * @return mixed The plugin version on the plugin pages, otherwise the text unchanged. */ public function footer_version( mixed $text ): mixed { if ( ! $this->is_plugin_screen() ) { return $text; } /* translators: %s: plugin version. */ return esc_html( sprintf( __( 'AgentWelcome %s', 'agentwelcome' ), AGENTWELCOME_VERSION ) ); } /** * Whether the current admin screen is one of the plugin pages. * * @return bool True when it is. */ private function is_plugin_screen(): bool { $screen = get_current_screen(); return $screen instanceof \WP_Screen && in_array( $screen->id, array( 'toplevel_page_' . SettingsPage::SLUG, 'toplevel_page_' . LlmsPage::SLUG, 'agentwelcome_page_' . LlmsPage::SLUG, 'agentwelcome_page_' . VerifyPage::SLUG ), true ); } /** * Menu icon: a sparkle, as an SVG that WordPress recolors to match the admin scheme. * * @return string Data URI of the icon. */ private function icon(): string { $svg = ''; return 'data:image/svg+xml;base64,' . base64_encode( $svg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Required for a menu icon data URI. } }