| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation — Wallpaper context-menu server side. |
| 4 |
* |
| 5 |
* Builds the array shipped to the shell as |
| 6 |
* `serverWallpaperMenuItems`. Plugins extend the menu by |
| 7 |
* filtering the array — empty by default, so no menu items |
| 8 |
* arrive from the server unless plugins add them. |
| 9 |
* |
| 10 |
* The built-in items (Create folder, New URL, Sort by, Show |
| 11 |
* desktop, OS Settings) are JS-defined inside the shell — they |
| 12 |
* need access to closures we'd lose across the wire. Server |
| 13 |
* items take a `callbackId` string the JS bundle resolves in |
| 14 |
* its `serverCallbacks` map; plugins that don't ship a JS |
| 15 |
* callback subscribe via the |
| 16 |
* `os.wallpaper-context-menu.activated` action |
| 17 |
* instead. |
| 18 |
* |
| 19 |
* @package OpenStation |
| 20 |
*/ |
| 21 |
|
| 22 |
defined( 'ABSPATH' ) || exit; |
| 23 |
|
| 24 |
/** |
| 25 |
* Builds the server-borne wallpaper-menu items. |
| 26 |
* |
| 27 |
* @return array[] |
| 28 |
*/ |
| 29 |
function openstation_build_wallpaper_menu_items() { |
| 30 |
$items = array(); |
| 31 |
|
| 32 |
/** |
| 33 |
* Filter the server-borne wallpaper context-menu items. |
| 34 |
* |
| 35 |
* Each item must have at least `id` and `label`. Optional: |
| 36 |
* `icon`, `sort`, `disabled`, `callbackId`. |
| 37 |
* |
| 38 |
* @param array[] $items Items list. |
| 39 |
*/ |
| 40 |
$items = (array) apply_filters( 'openstation_wallpaper_context_menu_items', $items ); |
| 41 |
|
| 42 |
$out = array(); |
| 43 |
foreach ( $items as $entry ) { |
| 44 |
if ( ! is_array( $entry ) || empty( $entry['id'] ) || empty( $entry['label'] ) ) { |
| 45 |
continue; |
| 46 |
} |
| 47 |
$out[] = array( |
| 48 |
'id' => (string) $entry['id'], |
| 49 |
'label' => (string) $entry['label'], |
| 50 |
'icon' => isset( $entry['icon'] ) ? (string) $entry['icon'] : '', |
| 51 |
'sort' => isset( $entry['sort'] ) ? (int) $entry['sort'] : 100, |
| 52 |
'disabled' => ! empty( $entry['disabled'] ), |
| 53 |
'callbackId' => isset( $entry['callbackId'] ) ? (string) $entry['callbackId'] : '', |
| 54 |
); |
| 55 |
} |
| 56 |
return $out; |
| 57 |
} |
| 58 |
|