item` map passed once through a public `*_register_*` filter. * Built on first use (after `init`), so labels can be translated. * * @since 1.0.0 */ abstract class AbstractRegistry { /** * Resolved items. * * @var array|null */ private ?array $items = null; /** * Lite defaults. * * @return array */ abstract protected function defaults(): array; /** * Public filter name. */ abstract protected function filter_name(): string; /** * Whether an item is valid for this registry. * * @param mixed $item Item. */ abstract protected function accepts( mixed $item ): bool; /** * All items keyed by slug. * * @return array */ public function all(): array { if ( null === $this->items ) { $items = apply_filters( $this->filter_name(), $this->defaults() ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Every subclass returns a prefixed, documented hook name. $this->items = array(); foreach ( (array) $items as $slug => $item ) { if ( is_string( $slug ) && '' !== $slug && $this->accepts( $item ) ) { $this->items[ $slug ] = $item; } } } return $this->items; } /** * Whether a slug is registered. * * @param string $slug Slug. */ public function has( string $slug ): bool { return isset( $this->all()[ $slug ] ); } /** * Forces the registry to be rebuilt (tests). */ public function reset(): void { $this->items = null; } }