name()], $spec->aliases()); foreach ($names as $name) { if (!preg_match(self::NAME, $name) || str_starts_with($name, 'sarcio/')) { return false; } } $run = $spec->run(); if ($run === null || !in_array($spec->kind(), [AbilitySpec::READ, AbilitySpec::WRITE], true)) { return false; } $stage = $spec->stage(); $ability = new Ability( $spec->name(), $spec->label(), $spec->kind() === AbilitySpec::WRITE ? Ability::WRITE : Ability::READ, $spec->description(), $spec->input(), $spec->permission() ?? static fn (array $args): bool => current_user_can('manage_options'), $run, $spec->preview(), $spec->undo(), $spec->consent(), $stage === null ? null : self::stageThroughPreview($spec->name(), $stage), ); return Registry::addAbility($ability, $spec->aliases(), $spec->render()); } private static function stageThroughPreview(string $name, Closure $stage): Closure { return static fn (array $args, Overlay $overlay): array => $stage($args, new OverlayPreview($overlay, $name)); } }