# desktop-mode/1.0.0/includes/comments-window/permissions.php

OpenStation: Desktop Windows, Dock &amp; Virtual Desktops for WP Admin, version 1.0.0. 80 lines.

- Page: https://pluginprobe.com/plugins/desktop-mode/1.0.0/code/includes/comments-window/permissions.php
- Raw: https://pluginprobe.com/plugins/desktop-mode/1.0.0/raw/includes/comments-window/permissions.php
- Modified: 2026-08-07T20:39:04+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/desktop-mode/1.0.0/code/includes/comments-window/permissions.php#L10-L20`.

```php
<?php
/**
 * OpenStation — Native Comments Window: capability gates.
 *
 * Multi-tier gating, parallel to WordPress core's
 * `edit-comments.php` flow:
 *
 *   - `edit_posts`     → REGISTER the window. The cheapest classic-admin
 *                        cap that gates "can read the comments screen"
 *                        for any author (their own comments). The REST
 *                        controller does per-row checks.
 *   - `moderate_comments`
 *                      → bulk approve / unapprove / spam / trash actions
 *                        and the global Pending tab badge.
 *   - `edit_comment`   → edit a comment's text (per-target, server-checked).
 *
 * UI-side gating is purely UX polish — the REST routes in `rest.php`
 * re-validate every cap and every per-target permission before
 * mutating anything.
 *
 * @package OpenStation
 */

defined( 'ABSPATH' ) || exit;

/**
 * Whether the user is eligible to have the Comments window registered.
 *
 * @param int|null $user_id Optional. Defaults to `get_current_user_id()`.
 * @return bool
 */
function openstation_comments_window_user_can_register( $user_id = null ) {
	$user_id = null === $user_id ? get_current_user_id() : (int) $user_id;
	$can     = $user_id > 0 && user_can( $user_id, 'edit_posts' );

	/**
	 * Filter whether the current user can have the Comments window registered.
	 *
	 * @param bool $can     Default: `edit_posts` capability.
	 * @param int  $user_id User being checked.
	 */
	return (bool) apply_filters(
		'openstation_comments_window_user_can_register',
		$can,
		$user_id
	);
}

/**
 * Combined cap-and-opt-in check.
 *
 * @param int|null $user_id Optional.
 * @return bool
 */
function openstation_comments_window_user_can_use( $user_id = null ) {
	$user_id = null === $user_id ? get_current_user_id() : (int) $user_id;

	$cap_ok = openstation_comments_window_user_can_register( $user_id );

	$opt_in = false;
	if ( $cap_ok && function_exists( 'openstation_get_os_settings' ) ) {
		$settings = openstation_get_os_settings( $user_id );
		$opt_in   = ! empty( $settings['nativeCommentsEnabled'] );
	}

	$can = $cap_ok && $opt_in;

	/**
	 * Filter whether the current user has opted into the native Comments experience.
	 *
	 * @param bool $can     Default gate result.
	 * @param int  $user_id User being checked.
	 */
	return (bool) apply_filters(
		'openstation_comments_window_user_can_use',
		$can,
		$user_id
	);
}

```
