PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.0.0
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.0.0
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 / includes / user-edit-window / permissions.php

permissions.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.0.0, at includes/user-edit-window/permissions.php

62 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Native User Edit Window: capability gates.
4 *
5 * The window is registered for ANY logged-in user (everyone has a
6 * profile they can edit). Per-target capability is re-checked at
7 * REST time — saving uses core's `/wp/v2/users/<id>` PUT, which
8 * already enforces `edit_user, $id`; the insights endpoint here
9 * applies the same check before returning data.
10 *
11 * @package OpenStation
12 */
13
14 defined( 'ABSPATH' ) || exit;
15
16 /**
17 * Whether the user is eligible to have the User Edit window registered.
18 *
19 * Defaults to `true` for any logged-in user — everyone has at least
20 * their own profile to edit. Returning `false` from the filter
21 * disables registration entirely, which falls back to the classic
22 * `user-edit.php` / `profile.php` iframe path.
23 *
24 * @param int|null $user_id Optional. Defaults to `get_current_user_id()`.
25 * @return bool
26 */
27 function openstation_user_edit_window_user_can_register( $user_id = null ) {
28 $user_id = null === $user_id ? get_current_user_id() : (int) $user_id;
29 $can = $user_id > 0;
30
31 /**
32 * Filter whether the current user can have the User Edit window
33 * registered.
34 *
35 * @param bool $can Default: any logged-in user.
36 * @param int $user_id User being checked.
37 */
38 return (bool) apply_filters(
39 'openstation_user_edit_window_user_can_register',
40 $can,
41 $user_id
42 );
43 }
44
45 /**
46 * Whether `$viewer_id` may edit `$target_id`'s profile. Server-side
47 * canonical check used by the insights endpoint and any plugin code
48 * that wants to mirror the gating.
49 *
50 * @param int $viewer_id
51 * @param int $target_id
52 * @return bool
53 */
54 function openstation_user_edit_window_can_edit( $viewer_id, $target_id ) {
55 $viewer_id = (int) $viewer_id;
56 $target_id = (int) $target_id;
57 if ( $viewer_id <= 0 || $target_id <= 0 ) {
58 return false;
59 }
60 return (bool) user_can( $viewer_id, 'edit_user', $target_id );
61 }
62