…, 'dayNight' => …]`, and `dayNight` *is* this question. So this class asks * `SiteTokens::appearance()` and never reads a theme option. * * The circle: the theme's answer to that filter used to be computed by calling * `AumCreate_Theme_Toggle::enabled()` — the class that is now here. Moving the class as-is would have made * the plugin ask the theme a question the theme answered by asking the plugin. Broken by moving the * *implementation* of `enabled()` into the theme as a plain function, next to the setting it reads. * * 2. A site with no theme of ours has no answerer, so `dayNight` is false and this renders an empty * string. That is right: with no palette there is nothing to switch between. * * 3. `was_placed()` stays with the renderer, i.e. here. The theme's floating column uses it to avoid a * second button when a template already placed one in the header; it now asks this class, and renders * through `do_shortcode()` rather than calling a method — so both buttons stay literally the same button. * * `aum-theme-switcher` is the class the theme's `theme-mode.js` binds to, and the icon size and * `fill="currentColor"` are load-bearing (see render()). **The markup here is byte-for-byte what the theme * emitted** — renaming anything silently turns the button into decoration that does nothing when pressed. */ final class ThemeToggle { /** Sun / crescent split by a diagonal. See render() for why fill and size are not free choices. */ const ICON_PATH = 'M202.915 3.8c-2.106 2.917-2.592 8.263-2.592 25.11 0 19.44.324 21.87 3.24 24.786 4.698 4.698 11.988 4.212 16.038-.972 3.078-3.888 3.402-6.48 3.402-23.652 0-24.461-1.944-28.835-12.474-28.835-3.564 0-5.994 1.134-7.614 3.564M467.62 167.419C254.916 379.636 50.15 584.726 40.269 595.255c-6.966 7.452-8.424 10.044-7.452 12.96 1.782 5.994 5.67 9.234 11.016 9.234 4.536 0 34.181-29.16 294.674-289.652C554.775 111.529 627.997 37.334 627.997 34.58c0-4.698-6.803-11.664-11.663-11.664-2.754 0-41.31 37.422-148.714 144.503M370.42 54.992c-1.295.324-10.205 8.424-19.763 17.82-13.608 13.446-17.496 18.306-17.496 21.708 0 4.86 6.48 11.015 11.826 11.015 2.106 0 9.882-6.48 20.898-17.495 14.58-14.58 17.496-18.306 17.496-22.356 0-6.804-6.966-12.636-12.96-10.692M66.189 60.176c-5.508 2.268-7.938 8.748-5.022 14.256 3.564 6.966 33.047 34.343 37.097 34.343 4.536 0 11.34-6.965 11.34-11.663 0-4.05-33.372-38.556-37.26-38.394-1.296 0-4.05.648-6.155 1.458M195.625 80.426c-32.238 7.128-54.917 19.764-77.273 43.415-10.368 10.854-14.904 17.334-21.546 30.456-12.15 24.462-13.932 32.885-13.77 63.827 0 23.976.324 27.054 4.536 39.69 5.346 16.2 10.368 26.405 19.278 39.69 11.988 17.495 38.718 41.309 46.493 41.309 5.022 0 11.34-6.318 11.34-11.502s-1.62-6.966-15.227-17.496c-11.502-8.586-26.568-27.378-33.21-40.986-11.502-23.49-14.904-55.889-8.262-81.323 7.938-30.941 30.942-60.263 58.32-73.547 19.601-9.72 35.8-13.445 57.509-13.445 45.359-.162 83.915 22.517 106.108 62.207 6.48 11.502 11.502 15.228 17.496 13.122 2.43-.81 5.346-3.564 6.48-5.994 1.944-4.05 1.782-5.508-2.592-14.58-13.608-28.836-42.605-55.08-74.843-67.391-24.786-9.558-57.023-12.474-80.837-7.452M4.953 204.03c-3.078 1.944-5.67 8.424-4.698 11.502 2.268 7.29 5.346 8.1 30.78 8.424 23.166.162 24.3 0 27.054-3.402 3.888-4.698 3.726-10.53-.324-14.58-2.916-2.916-5.346-3.24-27.054-3.24-13.284 0-24.786.648-25.758 1.296M469.24 300.743l-3.888 4.212 5.184 20.574c6.965 27.377 8.423 38.07 8.423 60.425 0 30.618-5.831 54.431-20.25 82.295-22.679 43.901-60.91 75.977-111.454 93.473-19.278 6.642-22.68 9.558-19.602 17.982 3.726 10.691 42.768 33.695 70.793 41.633 64.962 18.63 137.537-4.536 179.98-57.671 20.25-25.272 32.886-55.728 36.774-88.775 8.91-78.083-43.74-155.032-119.555-174.958-16.686-4.374-21.707-4.212-26.405.81m36.611 25.92c15.714 5.994 28.998 14.58 43.254 28.187 45.359 43.416 57.347 108.539 30.293 165.238-19.278 40.176-54.593 69.497-98.495 81.485-16.847 4.698-54.269 5.022-69.983.648-15.876-4.374-34.02-11.664-41.795-17.01l-7.128-4.697 17.496-8.262c68.2-32.562 110.968-90.395 120.688-163.294 2.43-18.144.972-49.734-3.402-70.145-1.782-8.424-3.24-15.552-3.24-15.876 0-.81 1.782-.162 12.312 3.726M69.59 340.757c-17.01 17.01-19.925 20.411-19.925 24.785 0 6.318 4.374 10.53 10.692 10.53 4.05 0 8.1-3.402 24.623-19.926 21.384-21.545 23.004-25.11 16.038-31.59s-10.044-5.021-31.428 16.2'; /** Has a toggle already been placed on this page? */ private static $placed = false; public static function boot(): void { add_shortcode('aumframe_theme_toggle', [self::class, 'render']); } /** * Should the front end show the toggle? * * This is not "is the site light or dark by default" — that is `mode`. It is whether the visitor * is allowed to switch at all, which the theme declares as `dayNight`. */ public static function enabled(): bool { return !empty(SiteTokens::appearance()['dayNight']); } public static function was_placed(): bool { return self::$placed; } public static function render($atts = []): string { if (!self::enabled()) { return ''; } /* * The flag is set here rather than after output — the shell renders before `wp_footer`, so the * order is naturally correct; but this note is for whoever later changes it to render lazily. */ self::$placed = true; $a = shortcode_atts([ 'light' => __('Light', 'aumframe'), 'dark' => __('Dark', 'aumframe'), 'class' => '', ], is_array($atts) ? $atts : []); // `aum-theme-switcher` is the class the AumCreate theme's theme-mode.js looks for; without it the // button does nothing when pressed. $cls = trim('aum-theme-toggle aum-theme-switcher ' . $a['class']); /* * One mark, not two icons. * * It used to emit a sun and a moon as separate SVGs with no CSS to hide either — both sat side by * side in a round 50px button, reading as decoration rather than a control. A toggle that shows both * states at once says nothing about which one pressing it gives you. The replacement is a single * glyph: sun upper left, crescent lower right, split by a diagonal. * * Two things that are easy to undo by accident: * * `fill="currentColor"` lives on the ``, not on the path, and it is load-bearing. The path * carries no fill of its own, so without it SVG falls back to black — invisible against the dark * palette, which is exactly half the time this button is on screen. * * The size is 24px, not the 18px the old icons used. The path runs edge to edge of its viewBox with * no padding and its strokes are thin (~13 units of 628, about half a pixel once scaled); at 18px it * renders as a grey wisp. Checked at 18, 22 and 26 — 24 is where the crescent still reads as a * crescent. Shrinking it back undoes that. */ return sprintf( '', esc_attr($cls), esc_attr__('Switch between light and dark', 'aumframe'), self::ICON_PATH ); } }