PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.8.7
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.8.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 / includes / comments-window / permissions.php

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

89 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — 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 WPDesktopMode
22 * @since 0.19.0
23 */
24
25 defined( 'ABSPATH' ) || exit;
26
27 /**
28 * Whether the user is eligible to have the Comments window registered.
29 *
30 * @since 0.19.0
31 *
32 * @param int|null $user_id Optional. Defaults to `get_current_user_id()`.
33 * @return bool
34 */
35 function desktop_mode_comments_window_user_can_register( $user_id = null ) {
36 $user_id = null === $user_id ? get_current_user_id() : (int) $user_id;
37 $can = $user_id > 0 && user_can( $user_id, 'edit_posts' );
38
39 /**
40 * Filter whether the current user can have the Comments window registered.
41 *
42 * @since 0.19.0
43 *
44 * @param bool $can Default: `edit_posts` capability.
45 * @param int $user_id User being checked.
46 */
47 return (bool) apply_filters(
48 'desktop_mode_comments_window_user_can_register',
49 $can,
50 $user_id
51 );
52 }
53
54 /**
55 * Combined cap-and-opt-in check.
56 *
57 * @since 0.19.0
58 *
59 * @param int|null $user_id Optional.
60 * @return bool
61 */
62 function desktop_mode_comments_window_user_can_use( $user_id = null ) {
63 $user_id = null === $user_id ? get_current_user_id() : (int) $user_id;
64
65 $cap_ok = desktop_mode_comments_window_user_can_register( $user_id );
66
67 $opt_in = false;
68 if ( $cap_ok && function_exists( 'desktop_mode_get_os_settings' ) ) {
69 $settings = desktop_mode_get_os_settings( $user_id );
70 $opt_in = ! empty( $settings['nativeCommentsEnabled'] );
71 }
72
73 $can = $cap_ok && $opt_in;
74
75 /**
76 * Filter whether the current user has opted into the native Comments experience.
77 *
78 * @since 0.19.0
79 *
80 * @param bool $can Default gate result.
81 * @param int $user_id User being checked.
82 */
83 return (bool) apply_filters(
84 'desktop_mode_comments_window_user_can_use',
85 $can,
86 $user_id
87 );
88 }
89