Traits

HasCapabilities

v1.0.0

Adds currentUserCan, requireCapability, isAdmin, and isMeteorackAdmin helpers for permission checks.

Use Trait

use Meteorack\Sdk\RuntimeWp\Traits\HasCapabilities;

How To Use It

  • Use the helpers to centralize permission checks inside the module instead of scattering current_user_can() calls across controllers and views.
  • Prefer requireCapability() at entrypoints that must hard-stop unauthorized access, and use the predicate helpers for lighter conditional UI.

Helpers

protected function currentUserCan(string $capability): bool

Returns whether the current user has the requested capability.

protected function requireCapability(string $capability): void

Throws or stops execution when the current user lacks the capability.

protected function isAdmin(): bool

Returns whether the current request is in the WordPress admin area.

protected function isMeteorackAdmin(): bool

Returns whether the current request is inside the Meteorack admin context.

Example

bootstrap.php
public function renderSettingsPage(): void
{
    $this->requireCapability('manage_options');

    if (! $this->isMeteorackAdmin()) {
        return;
    }

    echo '<div id="reports-settings-root"></div>';
}