PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.12
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.12
1.1.12 1.1.11 1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 All 36 releases
desktop-mode / apps / users / parts / facts.php

facts.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.12, at apps/users/parts/facts.php

63 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Users — the profile facts both apps ship as their config extra.
4 *
5 * The Users app's Profile tab and the User Edit window host the same
6 * `<os-user-profile>`, and both windows register on every request
7 * that builds the app manifests; the catalogue work behind the facts
8 * (a language directory scan, the admin colour-scheme registry, the
9 * editable-roles walk) is done once per request per viewer here and
10 * handed to both config callables.
11 *
12 * @package OpenStation
13 */
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * The static facts `<os-user-profile>` and the Users list read
19 * (`ctx.extra`), for the acting user. Memoised per request and per
20 * viewer, so switching users mid-request (a test, a `switch_to_user`)
21 * recomputes.
22 *
23 * @return array<string,mixed>
24 */
25 function openstation_users_profile_facts() {
26 static $cache = array();
27 $viewer_id = (int) get_current_user_id();
28 // Neither app is registered for a visitor; skip the catalogue work.
29 if ( $viewer_id <= 0 ) {
30 return array();
31 }
32 if ( isset( $cache[ $viewer_id ] ) ) {
33 return $cache[ $viewer_id ];
34 }
35 $cache[ $viewer_id ] = array(
36 'currentUserId' => $viewer_id,
37 // Capability flags — the UI hides actions the viewer can't
38 // perform; every action and route re-checks, so a tampered flag
39 // changes nothing.
40 'canEdit' => current_user_can( 'edit_users' ),
41 'canPromote' => current_user_can( 'promote_users' ),
42 'canCreate' => current_user_can( 'create_users' ),
43 'canDelete' => is_multisite() ? current_user_can( 'remove_users' ) : current_user_can( 'delete_users' ),
44 // The sidebar's door to the activity footprint. The footprint
45 // renders inside WP Explorer and its REST route is gated by that
46 // module's own helper, so the flag mirrors the same gate: a site
47 // that narrows WP Explorer hides the door with it. The guard
48 // covers a host where the module never loaded.
49 'canViewFootprint' => function_exists( 'openstation_my_wordpress_user_can_use' ) && openstation_my_wordpress_user_can_use(),
50 'isMultisite' => is_multisite(),
51 // Roles the viewer may assign — the dropdowns list only these,
52 // so a narrowed `editable_roles` never yields "pick a role, hit
53 // save, get rejected". `allRoles` is the label catalogue.
54 'assignableRoles' => openstation_users_window_role_label_map( $viewer_id ),
55 'allRoles' => openstation_users_window_all_roles_map(),
56 'locales' => openstation_users_window_locales_map(),
57 'defaultRole' => (string) get_option( 'default_role', 'subscriber' ),
58 'contactMethods' => (array) wp_get_user_contact_methods(),
59 'colorSchemes' => openstation_user_edit_window_color_schemes(),
60 );
61 return $cache[ $viewer_id ];
62 }
63