PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
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 0.8.8 0.8.7 All 34 releases
desktop-mode / apps / users / parts / facts.php

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

57 lines 2.2 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 'isMultisite' => is_multisite(),
45 // Roles the viewer may assign — the dropdowns list only these,
46 // so a narrowed `editable_roles` never yields "pick a role, hit
47 // save, get rejected". `allRoles` is the label catalogue.
48 'assignableRoles' => openstation_users_window_role_label_map( $viewer_id ),
49 'allRoles' => openstation_users_window_all_roles_map(),
50 'locales' => openstation_users_window_locales_map(),
51 'defaultRole' => (string) get_option( 'default_role', 'subscriber' ),
52 'contactMethods' => (array) wp_get_user_contact_methods(),
53 'colorSchemes' => openstation_user_edit_window_color_schemes(),
54 );
55 return $cache[ $viewer_id ];
56 }
57