Traits
HasCapabilities
v1.0.0Adds 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.
Works Well With
Helpers
protected function currentUserCan(string $capability): boolReturns whether the current user has the requested capability.
protected function requireCapability(string $capability): voidThrows or stops execution when the current user lacks the capability.
protected function isAdmin(): boolReturns whether the current request is in the WordPress admin area.
protected function isMeteorackAdmin(): boolReturns 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>';
}