API / Minn\Runtime / WidgetAreas

WidgetAreas final class

Minn\Runtime\WidgetAreas · public/minn/src/Minn/Runtime/WidgetAreas.php · 331 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; the stored sidebars read and written, and which are registered.

Constants and properties

privateDEFAULT_WIDGETS = array ( 0 => 'WP_Widget_Pages', 1 => 'WP_Widget_Calendar', 2 => 'WP_Widget_Archives', 3 => 'WP_Widget_Media_Audio', 4 => 'WP_Widget_Media_Image', 5 => 'WP_Widget_Media_Gallery', 6 => 'WP_Widget_Media_Video', 7 => 'WP_Widget_Meta', 8 => 'WP_Widget_Search', 9 => 'WP_Widget_Text', 10 => 'WP_Widget_Categories', 11 => 'WP_Widget_Recent_Posts', 12 => 'WP_Widget_Recent_Comments', 13 => 'WP_Widget_RSS', 14 => 'WP_Widget_Tag_Cloud', 15 => 'WP_Nav_Menu_Widget', 16 => 'WP_Widget_Custom_HTML', 17 => 'WP_Widget_Block', )

The widgets the engine provides.

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

staticregisterDefaults(): void#

The widgets the engine provides registered, then widgets_init for plugin and theme code (wp_widgets_init); the Links widget only while the link manager is on. The block widget is the one every modern sidebar is made of, so it is registered before the action runs.

staticshow(mixed $widget, mixed $instance = array ( ), mixed $args = array ( )): void#

A registered widget shown outside a sidebar (the_widget), in a div with its class unless the arguments say otherwise.

staticstored(mixed $deprecated = true): mixed#

The stored sidebars and their widgets (wp_get_sidebars_widgets), as sidebars_widgets leaves them.

@return array<string, mixed>
staticconvertSettings(string $base, mixed $settings): array#

A widget's settings in the numbered form (wp_convert_widget_settings, probe blocks-rest-widget-doubts): settings that are empty or not keyed by number are a single widget's, made number 2, and the sidebars this request holds name it by its new id; every result is marked a multi-widget's. Nothing is stored.

@return array<int|string, mixed>
staticconvertStoredSettings(string $base, string $option, mixed $settings): array#

The same conversion as the admin makes it: a single widget's new id goes into the stored sidebars (not this request's), and the settings are stored under their option either way.

@return array<int|string, mixed>
staticstore(mixed $sidebars): void#

The sidebars stored (wp_set_sidebars_widgets), at array version 3.

staticcurrent(mixed $themeChanged = false): array#

The sidebars with every registered one present and the widgets that lost theirs inactive (retrieve_widgets), stored; before widgets_init, the stored ones with the registered areas filled in empty.

@return array<string, mixed>
staticisRegistered(mixed $id): bool#

Whether a sidebar is registered (is_registered_sidebar).

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, array<int, 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 4

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

privatenumbered(mixed $settings): array#
@return array{0: array<int|string, mixed>, 1: bool} the settings numbered and marked, and whether they were a single widget's
privaterenamed(array $sidebars, string $base): array#
$sidebarsarray<string, mixed>@return array<string, mixed> each sidebar naming the single widget by its numbered id
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>