' . '#adminmenu #toplevel_page_wpwand .wp-menu-image img{width:20px;height:20px;padding-top:7px;}' . '#wpadminbar #wp-admin-bar-wpwand-trigger .ab-item img{width:18px;height:18px;vertical-align:middle;margin-right:4px;}' . ''; } public function add_menu(): void { $brand = \WPWand\Data\Brand::resolve(); $label = $brand['name']; $icon = $brand['icon'] ?: 'dashicons-edit'; add_menu_page($label, $label, 'edit_posts', self::PAGE_SLUG, [$this, 'render'], $icon); // Rename the auto-created first submenu (which defaults to the brand name) to "Settings". add_submenu_page( self::PAGE_SLUG, __('Settings', 'wp-wand'), __('Settings', 'wp-wand'), 'edit_posts', self::PAGE_SLUG, [$this, 'render'] ); } /** * The container carries a static, JS-free loading skeleton so the page paints the REAL settings * layout the moment WordPress prints it — before settings.js has even downloaded. It reuses the * app's actual markup/classes (wpwand-app header, wpws-card/tabs/panel/rows), which are styled by * style-settings.css (enqueued in , independent of JS), blurred under a spinner overlay. * React's createRoot() clears these children on first mount, so the skeleton is replaced by the * live UI with no teardown code. Skeleton-only CSS is scoped under #wpwand-settings-root. */ public function render(): void { echo '
'; echo $this->skeleton(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static markup, brand name escaped below echo '
'; } private function skeleton(): string { $brand = \WPWand\Data\Brand::resolve(); $name = $brand['name'] !== '' ? $brand['name'] : 'WP Wand'; // Mirrors the General tab: the four provider key rows exactly as the app renders them. $labels = [ __('OpenAI API Key', 'wp-wand'), __('Claude API Key', 'wp-wand'), __('DeepSeek API Key', 'wp-wand'), __('OpenRouter API Key', 'wp-wand'), ]; $desc = esc_html__('Add your API key to activate.', 'wp-wand'); $rows = ''; foreach ($labels as $label) { $rows .= '
' . '
' . '' . $desc . '
' . '
' . '
'; } // Only the form panel blurs behind the spinner; the brand header + tab rail + Pro button // stay crisp so the page reads as "loaded, fetching your settings" — not a blurred mess. return '' . '
' . '

' . esc_html($name) . '

' . '
' . '
' . '' . '' . '' . esc_html__('Get Pro Version', 'wp-wand') . '' . '
' . '
' . '
' . $rows . '
' . '
' . esc_html__('Loading settings…', 'wp-wand') . '
' . '
' . '
'; } public function enqueue(string $hook): void { // Only load on our page. Submenu hooks look like "{parent}_page_{slug}". if (substr($hook, -strlen(self::PAGE_SLUG)) !== self::PAGE_SLUG) { return; } $asset_file = WPWAND_NEW_DIR . 'build/settings.asset.php'; if (!is_readable($asset_file)) { return; // build not present (dev forgot `npm run build`) } $asset = require $asset_file; // The White Label tab picks the logo/icon from the media library (window.wp.media). wp_enqueue_media(); wp_enqueue_script( self::HANDLE, WPWAND_NEW_URL . 'build/settings.js', $asset['dependencies'], $asset['version'], true ); // Inter font (same as the legacy UI) + the app's compiled stylesheet. wp_enqueue_style( 'wpwand-inter-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap', [], $asset['version'] ); // @wordpress/scripts emits the entry's stylesheet as style-{entry}.css. if (is_readable(WPWAND_NEW_DIR . 'build/style-settings.css')) { wp_enqueue_style( self::HANDLE, WPWAND_NEW_URL . 'build/style-settings.css', [], (string) filemtime(WPWAND_NEW_DIR . 'build/style-settings.css') ); } wp_localize_script( self::HANDLE, 'wpwandApi', [ 'root' => esc_url_raw(rest_url()), 'nonce' => wp_create_nonce('wp_rest'), ] ); if (function_exists('wp_set_script_translations')) { wp_set_script_translations(self::HANDLE, 'wp-wand'); } } }