PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.7
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.7
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 / pages / parts / permissions.php

permissions.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.7, at apps/pages/parts/permissions.php

84 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 * Pages app — the capability gates, the Posts app's twins.
4 *
5 * The Pages window answers two questions, each filterable:
6 *
7 * 1. May the app be registered for this user? Cap-only
8 * (`edit_pages`, parity with `edit.php?post_type=page`) — the
9 * app's `can()` gate.
10 * 2. Has the user opted into the native window? Cap AND the
11 * `nativePagesEnabled` toggle in OS Settings → Features; flipped
12 * off, the iframe path returns without an F5.
13 *
14 * Filterable so plugins can widen the gate to a custom role, close it
15 * per user (force the iframe back on), or bypass the opt-in on a
16 * managed install.
17 *
18 * @package OpenStation
19 */
20
21 defined( 'ABSPATH' ) || exit;
22
23 /**
24 * Whether the user is eligible to have the Pages app registered.
25 * Cap-only: the opt-in toggle is a runtime, JS-side gate (the URL →
26 * app remap registry), so flipping the setting takes effect at once.
27 *
28 * @param int|null $user_id Optional. Defaults to `get_current_user_id()`.
29 * @return bool
30 */
31 function openstation_pages_window_user_can_register( $user_id = null ) {
32 $user_id = null === $user_id ? get_current_user_id() : (int) $user_id;
33
34 $can = $user_id > 0 && user_can( $user_id, 'edit_pages' );
35
36 /**
37 * Filter whether the current user is eligible to have the Pages
38 * app registered. This is the boot-time check; runtime "should the
39 * dock click use the native window?" is the JS-side
40 * `nativePagesEnabled` flag.
41 *
42 * @param bool $can Default: `edit_pages` capability.
43 * @param int $user_id User being checked.
44 */
45 return (bool) apply_filters(
46 'openstation_pages_window_user_can_register',
47 $can,
48 $user_id
49 );
50 }
51
52 /**
53 * Whether the user has opted into the native Pages experience: the
54 * cap AND the toggle. Registration uses
55 * {@see openstation_pages_window_user_can_register()}; the dock-click
56 * remap reads the JS-side settings snapshot. This is the combined
57 * answer for any caller that wants it.
58 *
59 * @param int|null $user_id Optional.
60 * @return bool
61 */
62 function openstation_pages_window_user_can_use( $user_id = null ) {
63 $user_id = null === $user_id ? get_current_user_id() : (int) $user_id;
64
65 $cap_ok = openstation_pages_window_user_can_register( $user_id );
66
67 $opt_in = false;
68 if ( $cap_ok && function_exists( 'openstation_get_os_settings' ) ) {
69 $settings = openstation_get_os_settings( $user_id );
70 $opt_in = ! empty( $settings['nativePagesEnabled'] );
71 }
72
73 $can = $cap_ok && $opt_in;
74
75 /**
76 * Filter whether the current user has opted into the native Pages
77 * experience.
78 *
79 * @param bool $can Default gate result.
80 * @param int $user_id User being checked.
81 */
82 return (bool) apply_filters( 'openstation_pages_window_user_can_use', $can, $user_id );
83 }
84