Download the PHP package pollora/meta without Composer
On this page you can find all versions of the php package pollora/meta. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package meta
Typed WordPress meta, declared with attributes: a property of a class is a meta, its PHP type is the meta's type, its initial value is the default. The package registers it with register_meta(), reads and writes it with its PHP type (an int, a bool, a CarbonImmutable, an enum, a list, a data object), checks its rules on every write, and gives the compiled schemas to the tooling and to the UI drivers (ACF, Meta Box) that build the editing fields.
Part of Pollora, the Laravel framework for WordPress, where it is installed and wired for you: see Typed meta. It runs without Laravel too: in a plugin, a Bedrock site or any PHP project.
Installation
Requires PHP 8.3+ and WordPress. It builds on pollora/attributes (the #[Meta] attribute), pollora/discovery and pollora/hook.
Declaring
#[Meta] takes key, showInRest, label, description, sanitize, capability, revisions, rules, single, items, control, group, hints, media and public; see the attribute's own documentation in pollora/attributes. #[PostMeta], #[TermMeta], #[UserMeta] and #[CommentMeta] declare the meta of a type you do not own.
Reading and writing
A write goes through WordPress's meta API, under the declared key. A value that breaks a rule throws MetaValidationException and nothing is written; a stored value that cannot be read as its type reads as the property default.
The rules are checked by a MetaValidatorInterface. In a Pollora application it is Laravel's validator (min:0, max:5000, in:…, email…); without Laravel, pass your own to MetaAccessor, or none: the rules are then not checked.
Schemas and UI drivers
MetaAccessor::schemas() and schemaFor('post', 'event') give the compiled MetaSchemas. A package that builds editing fields implements MetaUiDriver and registers it by name with MetaAccessor::extend('acf', AcfDriver::class); MetaUiDriverConformance::check($driver) checks it against the contract from any test framework.
Wiring it outside Pollora
Discover the classes that declare meta, then build the accessor with the same pieces the framework's provider builds:
The meta are registered with WordPress on init. The Eloquent accessors (HasTypedMeta), the Laravel validator, the pollora:meta:* commands and the pollora:doctor check stay in the framework.
Testing
License
MIT. See LICENSE.
All versions of meta with dependencies
nesbot/carbon Version ^3.0
pollora/attributes Version ^0.1 || ^1.0
pollora/discovery Version ^0.1 || ^1.0
pollora/hook Version ^2.0.1
psr/container Version ^2.0
psr/log Version ^3.0