API / Minn\Runtime / WidgetAreas

WidgetAreas final class

Minn\Runtime\WidgetAreas · public/minn/src/Minn/Runtime/WidgetAreas.php · 184 lines

The widgets helper functions as the reference answers them (probe widget-helpers): a widget id split into its base and number, a sidebar by id (the inactive widgets are a sidebar too, with a name and nothing else), finding and moving a widget between sidebars, one widget rendered in its sidebar as dynamic_sidebar renders each (an unregistered widget renders nothing), and the sidebars with every registered one present.

Constants and properties

constINACTIVE = 'wp_inactive_widgets'
privateMAPPING_GROUPS = array ( 0 => array ( 0 => 'sidebar', 1 => 'primary', 2 => 'main', 3 => 'right', ), 1 => array ( 0 => 'second', 1 => 'left', ), 2 => array ( 0 => 'sidebar-2', 1 => 'footer', 2 => 'bottom', ), 3 => array ( 0 => 'header', 1 => 'top', ), )

The id fragments a theme switch matches sidebars by, group by group (probe sidebars-mapping).

Public

staticparse(string $id): array#

wp_parse_widget_id: ['id_base' => ..., 'number' => n], or the id alone as its base. @return array{id_base: string, number?: int}

@return array{id_base: string, number?: int}
staticsidebar(string $id): ?array#

wp_get_sidebar: a registered sidebar, the inactive widgets, or null. @return array<string, mixed>|null

@return array<string, mixed>|null
staticfind(string $widgetId): ?string#

wp_find_widgets_sidebar: the sidebar holding a widget, or null.

staticassign(string $widgetId, string $sidebarId): void#

wp_assign_widget_to_sidebar: out of every sidebar, then onto the end of one ('' leaves it in none).

staticrender(string $widgetId, string $sidebarId): string#

wp_render_widget: a registered widget as its sidebar wraps it, through dynamic_sidebar_params; '' otherwise.

staticcontrol(string $widgetId): ?string#

wp_render_widget_control: a registered widget's settings form, or null.

staticretrieve(array $stored, array $areas, array $registered): array#

retrieve_widgets (probe widgets-remaining): the inactive list, then every registered sidebar, holding only widgets that are registered. The inactive list takes, in order, the registered widgets no list mentions (the -1 placeholders aside, in the order they were registered), the widgets already inactive, and the widgets of sidebars no longer registered, which go.

$storedarray<string, mixed>the stored lists, sidebar => widget ids
$areaslist<string>the registered sidebars
$registeredlist<string>the registered widgets
@return array<string, list<string>>
staticmap(array $existing, array $areas, array $stored, array $registered): array#

The old theme's widget lists fitted to the new theme's sidebars (probe sidebars-mapping). One old sidebar and one new map straight across. Otherwise a sidebar of the same id keeps its widgets; then, group by group, the new sidebars whose ids hold one of the group's fragments take, in order, the old ones that do (a new sidebar may take from several groups); what is left goes after the inactive widgets. When nothing is inactive then, the stored inactive widgets that are registered and placed nowhere come back, keys kept.

$existingarray<string, mixed>the old theme's lists
$areaslist<string>the new theme's sidebars
$storedarray<array-key, mixed>the theme's stored inactive widgets
$registeredlist<string>the registered widgets
@return array<string, array<array-key, mixed>>

Internals 2

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

privateinGroup(string $id, array $fragments): bool#
$fragmentslist<string>
privateunmentioned(array $stored, array $registered): array#

Registered widgets no stored list mentions, the -1 placeholders aside.

$storedarray<string, mixed>
$registeredlist<string>
@return list<string>