"install WooCommerce" state * - not connected -> live screen + connect banner, * remote-only controls disabled * - connected -> live screen * * @package Agencoen */ namespace Agencoen; defined( 'ABSPATH' ) || exit; /** * Class Admin */ class Admin { const SLUG = 'agencoen'; /** * AI crawler visits (7-day window) a site records before the optional * connect notice first appears. Until then no screen mentions an account; * the notice, when it does show, can point at value the plugin has * already measured. */ const CONNECT_NOTICE_MIN_HITS = 25; /** @var Plugin */ private $plugin; /** * @param Plugin $plugin Orchestrator. */ public function __construct( Plugin $plugin ) { $this->plugin = $plugin; } /** * Hook the menu. */ public function register() { add_action( 'admin_menu', array( $this, 'menu' ) ); add_filter( 'plugin_action_links_' . AGENCOEN_PLUGIN_BASENAME, array( $this, 'action_links' ) ); } /** * Build the top-level menu + subpages. */ public function menu() { $cap = Capabilities::manage(); add_menu_page( __( 'Agentic Commerce Engine', 'agentic-commerce-engine' ), 'ACE', $cap, self::SLUG, array( $this, 'render_dashboard' ), 'dashicons-superhero-alt', 58 ); add_submenu_page( self::SLUG, __( 'Dashboard', 'agentic-commerce-engine' ), __( 'Dashboard', 'agentic-commerce-engine' ), $cap, self::SLUG, array( $this, 'render_dashboard' ) ); add_submenu_page( self::SLUG, __( 'Products', 'agentic-commerce-engine' ), __( 'Products', 'agentic-commerce-engine' ), $cap, 'agencoen-products', array( $this, 'render_products' ) ); add_submenu_page( self::SLUG, __( 'Review', 'agentic-commerce-engine' ), __( 'Review', 'agentic-commerce-engine' ), $cap, 'agencoen-review', array( $this, 'render_review' ) ); add_submenu_page( self::SLUG, __( 'Content', 'agentic-commerce-engine' ), __( 'Content', 'agentic-commerce-engine' ), $cap, 'agencoen-content', array( $this, 'render_content' ) ); add_submenu_page( self::SLUG, __( 'AI Search', 'agentic-commerce-engine' ), __( 'AI Search', 'agentic-commerce-engine' ), $cap, 'agencoen-aisearch', array( $this, 'render_aisearch' ) ); add_submenu_page( self::SLUG, __( 'Experiments', 'agentic-commerce-engine' ), __( 'Experiments', 'agentic-commerce-engine' ), $cap, 'agencoen-experiments', array( $this, 'render_experiments' ) ); add_submenu_page( self::SLUG, __( 'Settings', 'agentic-commerce-engine' ), __( 'Settings', 'agentic-commerce-engine' ), $cap, 'agencoen-settings', array( $this, 'render_settings' ) ); add_submenu_page( self::SLUG, __( 'Connection', 'agentic-commerce-engine' ), __( 'Connection', 'agentic-commerce-engine' ), $cap, 'agencoen-connection', array( $this, 'render_connection' ) ); } /** * Add a "Settings" link on the Plugins screen. * * @param array $links Existing links. * @return array */ public function action_links( $links ) { $url = admin_url( 'admin.php?page=agencoen-settings' ); array_unshift( $links, '' . esc_html__( 'Settings', 'agentic-commerce-engine' ) . '' ); return $links; } /** Render: Dashboard. */ public function render_dashboard() { $this->render( 'page-dashboard.php', __( 'Dashboard', 'agentic-commerce-engine' ) ); } /** Render: Products (WooCommerce only). */ public function render_products() { $this->render( 'page-products.php', __( 'Products', 'agentic-commerce-engine' ), true ); } /** Render: Review (WooCommerce only). */ public function render_review() { $this->render( 'page-review.php', __( 'Review', 'agentic-commerce-engine' ), true ); } /** Render: Content. */ public function render_content() { $this->render( 'page-content.php', __( 'Content', 'agentic-commerce-engine' ) ); } /** Render: AI Search. */ public function render_aisearch() { $this->render( 'page-aisearch.php', __( 'AI Search', 'agentic-commerce-engine' ) ); } /** * Render: Experiments (WooCommerce only). * * The third argument is the Woo gate, so a Woo-less site sees the same * "install WooCommerce" state Products and Review show rather than an empty * screen that looks broken. Every subject is a WooCommerce product. */ public function render_experiments() { $this->render( 'page-experiments.php', __( 'Experiments', 'agentic-commerce-engine' ), true ); } /** Render: Settings (local preferences only). */ public function render_settings() { $this->render( 'page-settings.php', __( 'Settings', 'agentic-commerce-engine' ) ); } /** Render: Connection (the optional ACE account lives here, and only here). */ public function render_connection() { $this->render( 'page-connection.php', __( 'Connection', 'agentic-commerce-engine' ) ); } /** * Shared chrome. The WooCommerce dependency is the only state that can * replace a screen; connection state only adds a banner. * * @param string $view View file under admin/views/. * @param string $title Screen title for the header. * @param bool $needs_woo Commerce screen: show the install state without WooCommerce. */ private function render( $view, $title, $needs_woo = false ) { $plugin = $this->plugin; $connected = $plugin->settings()->is_connected(); $has_woo = $plugin->has_woo(); $data = Dashboard::data( $plugin ); echo '