API / Minn\Runtime / ThemeSwitch

ThemeSwitch final class

Minn\Runtime\ThemeSwitch · public/minn/src/Minn/Runtime/ThemeSwitch.php · 145 lines

Switching the theme as the reference does it, in two halves. The switch (switch_theme): the leaving theme keeps its widgets and its menu locations are remembered, the three theme options move, the switch is recorded (theme_switched), the arriving theme's mods start with the classic sidebars, only its mods stay autoloaded, then switch_theme. The next load, on init (check_theme_switched): after_switch_theme with the theme that left, whose defaults map the menu locations across (_wp_menus_changed) and look the widgets over, then the rules flushed and the record cleared. Deleting a theme fires delete_theme and deleted_theme around its folder going, and forgets the update check.

Constants and properties

privateSLUG_GROUPS = array ( 0 => array ( 0 => 'primary', 1 => 'menu-1', 2 => 'main', 3 => 'header', 4 => 'navigation', 5 => 'top', ), 1 => array ( 0 => 'secondary', 1 => 'menu-2', 2 => 'footer', 3 => 'subsidiary', 4 => 'bottom', ), 2 => array ( 0 => 'social', ), )

The menu location names, by role, a theme's locations are matched across by.

Public

staticswitchTo(string $stylesheet): void#

switch_theme.

staticcheckSwitched(): void#

check_theme_switched: on the load after a switch, after_switch_theme with the theme that left.

staticmenusChanged(): void#

_wp_menus_changed: the leaving theme's menu locations mapped onto the arriving theme's.

staticmapLocations(array $new, mixed $old): array#

wp_map_nav_menu_locations: with one location on each side, it is kept; otherwise a location of the same name keeps its menu, then by role, each name of a role in turn hands the next unused location of that role (with a menu) to the arriving locations that name it.

$newarray<string, int>
staticdelete(string $stylesheet, ?callable $remove = NULL): bool#

delete_theme: the folder removed between delete_theme and deleted_theme (by $remove when the caller removes it its own way); false for no name.

$remove(callable(string): bool)|null

Internals 3

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privateremoveFolder(string $stylesheet): bool#

A theme's folder, directly inside the themes folder (a symlink unlinked, never followed); one already gone counts.

privatenextOfGroup(array $old, array $group): ?string#

The first location left in $old that a name of the group names, with a menu in it. @param array<string, mixed> $old @param list<string> $group

$oldarray<string, mixed>@param list<string> $group
privatenames(string $location, string $slug): bool#

Whether a location and a role's name contain one another, letter case aside.