plugin_env = $plugin_env; $this->script_registry = $script_registry; $this->style_registry = $style_registry; } /** * Registers the plugin's available scripts and styles. * * @since 0.1.0 * * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function register_scripts_and_styles(): void { /** * Filters whether to skip API requests for all AI services. * * This effectively enables a "client-side only" mode for the AI Services plugin, * where only client-side models on the user's device are used. * * @since 0.7.0 * * @param bool $skip_api_request Whether to skip API requests for all AI services. * By default, this is true if the user is not logged in. */ $skip_api_request = (bool) apply_filters( 'ai_services_skip_api_request', ! is_user_logged_in() ); $this->script_registry->register( 'ais-ai', array( 'src' => $this->plugin_env->url( 'build/ai/index.js' ), 'manifest' => $this->plugin_env->path( 'build/ai/index.asset.php' ), 'strategy' => 'defer', ) ); if ( $skip_api_request ) { $this->script_registry->add_inline_code( 'ais-ai', 'window.AI_SERVICES_SKIP_API_REQUEST = true;' ); } $this->script_registry->register( 'ais-settings', array( 'src' => $this->plugin_env->url( 'build/settings/index.js' ), 'manifest' => $this->plugin_env->path( 'build/settings/index.asset.php' ), 'strategy' => 'defer', ) ); $this->script_registry->register( 'ais-components', array( 'src' => $this->plugin_env->url( 'build/components/index.js' ), 'manifest' => $this->plugin_env->path( 'build/components/index.asset.php' ), 'strategy' => 'defer', ) ); $this->script_registry->register( 'ais-interface', array( 'src' => $this->plugin_env->url( 'build/interface/index.js' ), 'manifest' => $this->plugin_env->path( 'build/interface/index.asset.php' ), 'strategy' => 'defer', ) ); $this->script_registry->register( 'ais-services-page', array( 'src' => $this->plugin_env->url( 'build/services-page/index.js' ), 'manifest' => $this->plugin_env->path( 'build/services-page/index.asset.php' ), 'strategy' => 'defer', ) ); $this->script_registry->register( 'ais-playground-page', array( 'src' => $this->plugin_env->url( 'build/playground-page/index.js' ), 'manifest' => $this->plugin_env->path( 'build/playground-page/index.asset.php' ), 'strategy' => 'defer', ) ); $this->style_registry->register( 'ais-components', array( 'src' => $this->plugin_env->url( 'build/components/style-index.css' ), 'path' => $this->plugin_env->path( 'build/components/style-index.css' ), 'manifest' => $this->plugin_env->path( 'build/components/index.asset.php' ), 'dependencies' => array( 'wp-components' ), ) ); $this->style_registry->register( 'ais-interface', array( 'src' => $this->plugin_env->url( 'build/interface/style-index.css' ), 'path' => $this->plugin_env->path( 'build/interface/style-index.css' ), 'manifest' => $this->plugin_env->path( 'build/interface/index.asset.php' ), 'dependencies' => array( 'wp-components', 'wp-editor' ), ) ); $this->style_registry->register( 'ais-services-page', array( 'src' => $this->plugin_env->url( 'build/services-page/style-index.css' ), 'path' => $this->plugin_env->path( 'build/services-page/style-index.css' ), 'manifest' => $this->plugin_env->path( 'build/services-page/index.asset.php' ), 'dependencies' => array( 'wp-components', 'ais-components', 'ais-interface' ), ) ); $this->style_registry->register( 'ais-playground-page', array( 'src' => $this->plugin_env->url( 'build/playground-page/style-index.css' ), 'path' => $this->plugin_env->path( 'build/playground-page/style-index.css' ), 'manifest' => $this->plugin_env->path( 'build/playground-page/index.asset.php' ), 'dependencies' => array( 'wp-components', 'ais-components', 'ais-interface' ), ) ); } }