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 / user-edit / parts / permissions.php

permissions.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.10, at apps/user-edit/parts/permissions.php

57 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 * User Edit app — 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 routes in `rest.php` apply
9 * 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. Returning `false` from
20 * the filter disables registration entirely, which falls back to the
21 * classic `user-edit.php` / `profile.php` iframe path.
22 *
23 * @param int|null $user_id Optional. Defaults to `get_current_user_id()`.
24 * @return bool
25 */
26 function openstation_user_edit_window_user_can_register( $user_id = null ) {
27 $user_id = null === $user_id ? get_current_user_id() : (int) $user_id;
28 $can = $user_id > 0;
29
30 /**
31 * Filter whether the current user can have the User Edit window
32 * registered.
33 *
34 * @param bool $can Default: any logged-in user.
35 * @param int $user_id User being checked.
36 */
37 return (bool) apply_filters( 'openstation_user_edit_window_user_can_register', $can, $user_id );
38 }
39
40 /**
41 * Whether `$viewer_id` may edit `$target_id`'s profile. Server-side
42 * canonical check used by the routes and any plugin code that wants
43 * to mirror the gating.
44 *
45 * @param int $viewer_id Viewer.
46 * @param int $target_id Target.
47 * @return bool
48 */
49 function openstation_user_edit_window_can_edit( $viewer_id, $target_id ) {
50 $viewer_id = (int) $viewer_id;
51 $target_id = (int) $target_id;
52 if ( $viewer_id <= 0 || $target_id <= 0 ) {
53 return false;
54 }
55 return (bool) user_can( $viewer_id, 'edit_user', $target_id );
56 }
57