'; return 'data:image/svg+xml;base64,' . base64_encode( $svg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Core only recolors base64 SVG icons. } /** * Registers the Aoedia admin menu. */ function aoedia_register_admin_page(): void { $hook = add_menu_page( __( 'Aoedia', 'aoedia' ), __( 'Aoedia', 'aoedia' ), 'edit_posts', 'aoedia', 'aoedia_render_admin_page', aoedia_menu_icon(), // Below the first separator (4), above Posts (5). 4.5 ); add_action( "admin_print_scripts-{$hook}", 'aoedia_enqueue_admin_assets' ); // Rename the first submenu item, which WordPress otherwise names after the menu. add_submenu_page( 'aoedia', __( 'Aoedia', 'aoedia' ), __( 'Assistant', 'aoedia' ), 'edit_posts', 'aoedia', 'aoedia_render_admin_page' ); $log_hook = add_submenu_page( 'aoedia', __( 'Aoedia Activity', 'aoedia' ), __( 'Activity', 'aoedia' ), 'manage_options', 'aoedia-activity', 'aoedia_render_log_page' ); add_action( "admin_print_styles-{$log_hook}", static function (): void { wp_enqueue_style( 'aoedia-log', AOEDIA_URL . 'assets/log.css', array(), aoedia_asset_version( 'assets/log.css' ) ); } ); add_submenu_page( 'aoedia', __( 'Aoedia Settings', 'aoedia' ), __( 'Settings', 'aoedia' ), 'manage_options', 'aoedia-settings', 'aoedia_render_settings_page' ); } /** * Registers the shared chat script and style. */ function aoedia_register_chat_assets(): void { wp_register_script( 'aoedia-chat', AOEDIA_URL . 'assets/chat.js', array( 'wp-element', 'wp-components', 'wp-api-fetch', 'wp-i18n' ), aoedia_asset_version( 'assets/chat.js' ), true ); wp_set_script_translations( 'aoedia-chat', 'aoedia' ); wp_localize_script( 'aoedia-chat', 'aoediaSettings', array( 'aiEnabled' => wp_supports_ai(), 'connectorsUrl' => current_user_can( 'manage_options' ) ? admin_url( 'options-connectors.php' ) : '', 'userId' => get_current_user_id(), 'userName' => wp_get_current_user()->display_name, 'quota' => aoedia_get_token_usage(), ) ); wp_register_style( 'aoedia-chat', AOEDIA_URL . 'assets/chat.css', array( 'wp-components' ), aoedia_asset_version( 'assets/chat.css' ) ); } /** * Enqueues the chat app on the Aoedia screen. */ function aoedia_enqueue_admin_assets(): void { aoedia_register_chat_assets(); wp_enqueue_script( 'aoedia-admin', AOEDIA_URL . 'assets/admin.js', array( 'aoedia-chat' ), aoedia_asset_version( 'assets/admin.js' ), true ); wp_enqueue_style( 'aoedia-chat' ); } /** * Adds the Aoedia sidebar to the block editor for posts and pages. */ function aoedia_enqueue_editor_assets(): void { $screen = get_current_screen(); if ( ! $screen || ! in_array( $screen->post_type, array( 'post', 'page' ), true ) || ! current_user_can( 'edit_posts' ) || ! wp_supports_ai() ) { return; } aoedia_register_chat_assets(); wp_enqueue_script( 'aoedia-editor', AOEDIA_URL . 'assets/editor.js', array( 'aoedia-chat', 'wp-plugins', 'wp-editor', 'wp-data', 'wp-blocks', 'wp-notices' ), aoedia_asset_version( 'assets/editor.js' ), true ); wp_set_script_translations( 'aoedia-editor', 'aoedia' ); wp_enqueue_style( 'aoedia-chat' ); } /** * Renders the Aoedia admin screen container. */ function aoedia_render_admin_page(): void { ?>