| @@ -16,15 +16,14 @@ | ||
| 16 | 16 | * Ownership: run only by the version-elected winner (via do_shell_registration), |
| 17 | 17 | * so a single authority orders ALL submenus — including those registered by |
| 18 | 18 | * older co-installed copies. Positions are read from a shared cross-scope map |
| 19 | 19 | * populated by AdminShell::register_plugin(). |
| 20 | - * @internal | |
| 21 | 20 | */ |
| 22 | 21 | class SubmenuPositioner |
| 23 | 22 | { |
| 24 | 23 | const PARENT = 'yaycommerce'; |
| 25 | 24 | const POSITION_KEY = 'yaycommerce_admin_shell_submenu_positions'; |
| 26 | - public function init() : void | |
| 25 | + public function init(): void | |
| 27 | 26 | { |
| 28 | 27 | // Priority 9999: run after every plugin (<=10) and TopLevelMenu's parent |
| 29 | 28 | // submenu cleanup (999) have finished, so the array is complete. |
| 30 | 29 | // Bound to both hooks so reordering also applies in Network Admin. |
| @@ -34,12 +33,12 @@ | ||
| 34 | 33 | * Reorder $submenu['yaycommerce'] by declared position. |
| 35 | 34 | * Lower position first; ties and unknown/null positions keep their existing |
| 36 | 35 | * order and sort after positioned items. |
| 37 | 36 | */ |
| 38 | - public function reorder() : void | |
| 37 | + public function reorder(): void | |
| 39 | 38 | { |
| 40 | 39 | global $submenu; |
| 41 | - if (empty($submenu[self::PARENT]) || !\is_array($submenu[self::PARENT])) { | |
| 40 | + if (empty($submenu[self::PARENT]) || !is_array($submenu[self::PARENT])) { | |
| 42 | 41 | return; |
| 43 | 42 | } |
| 44 | 43 | $positions = $GLOBALS[self::POSITION_KEY] ?? []; |
| 45 | 44 | // Decorate with original index for a stable sort (usort is not stable |
| @@ -48,9 +47,9 @@ | ||
| 48 | 47 | foreach ($submenu[self::PARENT] as $index => $item) { |
| 49 | 48 | $slug = $item[2] ?? ''; |
| 50 | 49 | $decorated[] = ['item' => $item, 'index' => $index, 'position' => $positions[$slug] ?? null]; |
| 51 | 50 | } |
| 52 | - \usort($decorated, function ($a, $b) { | |
| 51 | + usort($decorated, function ($a, $b) { | |
| 53 | 52 | $pa = $a['position']; |
| 54 | 53 | $pb = $b['position']; |
| 55 | 54 | if (null === $pa && null === $pb) { |
| 56 | 55 | return $a['index'] <=> $b['index']; |
| @@ -68,7 +67,7 @@ | ||
| 68 | 67 | } |
| 69 | 68 | return $pa <=> $pb; |
| 70 | 69 | }); |
| 71 | 70 | // Re-index to sequential keys; WP renders the submenu in array order. |
| 72 | - $submenu[self::PARENT] = \array_values(\array_column($decorated, 'item')); | |
| 71 | + $submenu[self::PARENT] = array_values(array_column($decorated, 'item')); | |
| 73 | 72 | } |
| 74 | 73 | } |