id => what Schema and Access show and default to */ private static array $entries = []; public function __construct(private Registry $registry) {} /** * Adds `$toolkit` under `$id`. `$label` names it under Enabled tools and, as "Tool: label", * on its Access row, whose description is `$description`. `$capability` is the row's default * and must be one the Access tab offers (Access::CAPABILITIES); anything else is stored as * `manage_options`, so a mistake fails closed. Pass strings already translated. * * An id that is not a lower-case word, or that is already registered (a built-in or an * earlier companion), is refused with _doing_it_wrong() and false, and nothing is registered. */ public function add(string $id, ToolkitInterface $toolkit, string $label, string $description = '', string $capability = 'manage_options'): bool { if (preg_match(self::ID, $id) !== 1 || in_array($id, $this->registry->ids(), true)) { _doing_it_wrong( self::class . '::add', /* translators: %s: the toolkit id a companion asked for */ sprintf(esc_html__('The toolkit id "%s" is taken or is not a lower-case word of letters, digits and underscores, starting with a letter, of up to 32 characters.', 'alpaca-bot'), esc_html($id)), '0.8.0', ); return false; } $this->registry->register($id, $toolkit); self::$entries[$id] = [ 'label' => $label, 'description' => $description, 'capability' => in_array($capability, Access::CAPABILITIES, true) ? $capability : 'manage_options', ]; return true; } /** * Every companion toolkit registered this request, in registration order. * * @return array */ public static function all(): array { return self::$entries; } }