PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.2
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.2
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 / comments-window / permissions.php

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

80 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Native Comments Window: capability gates.
4 *
5 * Multi-tier gating, parallel to WordPress core's
6 * `edit-comments.php` flow:
7 *
8 * - `edit_posts` → REGISTER the window. The cheapest classic-admin
9 * cap that gates "can read the comments screen"
10 * for any author (their own comments). The REST
11 * controller does per-row checks.
12 * - `moderate_comments`
13 * → bulk approve / unapprove / spam / trash actions
14 * and the global Pending tab badge.
15 * - `edit_comment` → edit a comment's text (per-target, server-checked).
16 *
17 * UI-side gating is purely UX polish — the REST routes in `rest.php`
18 * re-validate every cap and every per-target permission before
19 * mutating anything.
20 *
21 * @package OpenStation
22 */
23
24 defined( 'ABSPATH' ) || exit;
25
26 /**
27 * Whether the user is eligible to have the Comments window registered.
28 *
29 * @param int|null $user_id Optional. Defaults to `get_current_user_id()`.
30 * @return bool
31 */
32 function openstation_comments_window_user_can_register( $user_id = null ) {
33 $user_id = null === $user_id ? get_current_user_id() : (int) $user_id;
34 $can = $user_id > 0 && user_can( $user_id, 'edit_posts' );
35
36 /**
37 * Filter whether the current user can have the Comments window registered.
38 *
39 * @param bool $can Default: `edit_posts` capability.
40 * @param int $user_id User being checked.
41 */
42 return (bool) apply_filters(
43 'openstation_comments_window_user_can_register',
44 $can,
45 $user_id
46 );
47 }
48
49 /**
50 * Combined cap-and-opt-in check.
51 *
52 * @param int|null $user_id Optional.
53 * @return bool
54 */
55 function openstation_comments_window_user_can_use( $user_id = null ) {
56 $user_id = null === $user_id ? get_current_user_id() : (int) $user_id;
57
58 $cap_ok = openstation_comments_window_user_can_register( $user_id );
59
60 $opt_in = false;
61 if ( $cap_ok && function_exists( 'openstation_get_os_settings' ) ) {
62 $settings = openstation_get_os_settings( $user_id );
63 $opt_in = ! empty( $settings['nativeCommentsEnabled'] );
64 }
65
66 $can = $cap_ok && $opt_in;
67
68 /**
69 * Filter whether the current user has opted into the native Comments experience.
70 *
71 * @param bool $can Default gate result.
72 * @param int $user_id User being checked.
73 */
74 return (bool) apply_filters(
75 'openstation_comments_window_user_can_use',
76 $can,
77 $user_id
78 );
79 }
80