Files
2meet-data-optimizer/includes/class-tmdo-capability.php
T
wpdev 76c01e44df refactor: 全部 128 個生產檔加入 declare(strict_types=1)(PR-H)
對齊 A v3.2.0。型別強制會把隱式轉換變成 TypeError,所以一次全檔加入
並跑完整測試(unit 451 / integration 398 全綠,無迴歸)。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TbG1keQQ7XBa7qMQY16KCY
2026-07-31 06:13:33 +08:00

52 lines
1.6 KiB
PHP

<?php
/**
* TMDO_Capability — Multisite-aware admin capability check (v2.14.0).
*
* Centralizes the "can this user manage WPDO?" decision. Behaviour:
*
* - Single-site: require `manage_options` (site admin)
* - Multisite per-site: require `manage_options` (site admin on that site)
* - Multisite network: super admin always passes; site admin still passes
* on their own site if they hold `manage_options`
*
* Pre-v2.14.0 the codebase called `current_user_can('manage_options')` in 17
* places. On a network-admin context page, super admins do NOT automatically
* have `manage_options` — WordPress maps it to `do_not_allow` for non-super
* admins and lets `is_super_admin()` carry the decision separately. By
* routing through this helper, the plugin works identically on single-site
* and multisite without per-call-site if/else.
*
* @package WP_Data_Optimizer
* @since 2.14.0
*/
declare(strict_types=1);
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Static helper class — drop-in replacement for `current_user_can('manage_options')`.
*/
final class TMDO_Capability {
/**
* Whether the current user can manage WP Data Optimizer.
*
* Super admins always pass on multisite; site admins pass on their site.
* On single-site WordPress this is functionally identical to
* `current_user_can('manage_options')`.
*
* @return bool
*/
public static function current_user_can_admin(): bool {
if ( function_exists( 'is_multisite' ) && is_multisite()
&& function_exists( 'is_super_admin' ) && is_super_admin()
) {
return true;
}
return current_user_can( 'manage_options' );
}
}