get(); $is_visible = apply_filters( 'quadlayers_aicp_chatbot_is_visible', true, $chatbot ); if ( ! $is_visible ) { return; } add_action( 'wp_enqueue_scripts', array( $this, 'add_assets' ), 5 ); add_action( 'wp_footer', array( $this, 'add_app' ) ); } public function add_assets() { $frontend_chatbot = include QUADLAYERS_AICP_PLUGIN_DIR . 'build/frontend-chatbot/js/index.asset.php'; $all_assistants = Models_Assistants::instance()->get_all(); $assistants = array_reduce( $all_assistants, function ( $assistants, $assistant ) use ( $all_assistants ) { $is_unique_assistant = count( $all_assistants ) === 1; if ( $is_unique_assistant ) { $assistants[ $assistant['assistant_id'] ] = $assistant; return $assistants; } $is_visible = apply_filters( 'quadlayers_aicp_assistant_is_visible', true, $assistant ); if ( $is_visible ) { $assistants[ $assistant['assistant_id'] ] = $assistant; } return $assistants; }, array() ); $chatbot = Models_Chatbots::instance()->get(); wp_enqueue_script( 'aicp-frontend-chatbot', plugins_url( '/build/frontend-chatbot/js/index.js', QUADLAYERS_AICP_PLUGIN_FILE ), $frontend_chatbot['dependencies'], $frontend_chatbot['version'], true ); wp_localize_script( 'aicp-frontend-chatbot', 'aicpFrontendChatbot', array( 'assistants' => $assistants, 'chatbot' => $chatbot, ) ); wp_enqueue_style( 'aicp-frontend-chatbot', plugins_url( '/build/frontend-chatbot/css/style.css', QUADLAYERS_AICP_PLUGIN_FILE ), array(), QUADLAYERS_AICP_PLUGIN_VERSION ); /* $css = ':root {'; foreach ( $chatbot['chatbot_palette'] as $key => $value ) { if ( '' !== $value ) { $css .= sprintf( '--ai-copilot--%s-color: %s;', esc_attr( str_replace( '_', '-', $key ) ), esc_attr( $value ) ); } } $css .= '}'; $css .= $chatbot['chatbot_custom_css']; wp_add_inline_style( 'aicp-frontend-chatbot', $css ); */ } public function add_app() { echo '
'; } public static function instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } }