You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Added
Input fields for typed meta, through a contract (experimental): #[Meta(control: Control::Color, group: 'Profile', hints: ['acf' => [...]])] describes the field in neutral terms, a control being derived from the type otherwise (Text, RichText with sanitize: 'wp_kses_post', Number, Toggle, DateTime, Select). A package implements MetaUiDriver and registers it with Meta::extend('acf', AcfDriver::class); the project picks it in meta.ui (none by default), and the driver receives each schema on init, with only the meta it supports. Meta::schemas(), Meta::schemaFor('post', 'event'), the MetaSchemasRegistered event, and MetaUiDriverConformance::check($driver) for driver authors. The framework names no field plugin
Arrays and data objects as typed meta: an array property declares its item type with items: 'int' (or a class) or a @var list<string> docblock, and is stored as one serialized array or, with single: false, one row per item (whereMeta() then matches a model by one of its items). A class with public typed properties (scalars, dates, backed enums) is stored as an array, never as a PHP object, and read back as an instance; absent, it reads as an instance with its own defaults. REST publishes items and properties schemas, so WordPress refuses an item or a property of the wrong type; strings inside are sanitized like a string meta
Typed meta: a post type declared with #[PostType] gets custom-fields support when one of its #[Meta] has showInRest: true, without which WordPress leaves meta out of its REST responses. A post type targeted by #[PostMeta] is left as it is
Typed meta validation: #[Meta(rules: ['min:0', 'max:5000'])] checks a value with Laravel's validator, the type rule implied (integer for an int, so max compares numbers). A write from PHP (Meta::of()->set(), a model attribute) throws a MetaValidationException naming the meta; a REST write to a post, term, user or comment answers 400 with the message of the rule (params → meta.<key>) before anything is stored. Writes through WordPress's own functions (update_post_meta()) are only sanitized
Typed meta for every object (experimental): #[PostMeta('product')] or #[PostMeta(['post', 'page'])] for post types the project does not declare, #[TermMeta('category')], #[UserMeta] and #[CommentMeta] (every comment type: WordPress has no per-type comment meta). Meta::of() reads and writes them by object ID; a key two classes declare for the same objects is refused at discovery
Typed meta on the Eloquent models (experimental): Pollora\Models\Post, Page, Term, User and Comment read the #[Meta] their object carries as attributes, with their PHP type ($event->capacity, or by key $event->sold_out), check a write at once and store it through update_metadata() when the model is saved; whereMeta('capacity', '>=', 100) compares numbers as numbers. A post model with protected $postType = 'event' is bound to its post type at discovery, so Post::find() returns it. A class known to carry typed meta stops eager loading the meta relation and primes WordPress's meta cache once per collection (one query instead of the relation); other models and undeclared keys keep Colt's behaviour
Roles in Laravel (experimental), a role being named by its slug or by the class of a #[Role]: hasRole(), assignRole(), removeRole() and roles() on Pollora\Models\User (trait HasRoles; writes go through WP_User, an unknown role is refused); the role: route middleware (role:event_manager,editor, or EnsureUserHasRole::using(EventManager::class)), which refuses with a 403 a user who has none of the roles, an alias the application already uses being kept; @role accepts role classes (@role(EventManager::class)) and keeps the behaviour of Sage Directives' @role for slugs
REST permission Can for #[WpRestRoute] and #[Method]: permissionCallback: new Can('edit_posts'), a #[CapabilitySet] enum case, or new Can('edit_post', parameter: 'id') to check a meta capability on the object in the request. permissionCallback now accepts a Permission instance as well as a class name; a refusal answers 401 to a guest and 403 to a logged-in user
Translated role labels: #[Role(…, textDomain: 'my-theme')] translates the label with that domain wherever WordPress shows role names (translate_user_role(): users list, role dropdowns). Translation happens when the admin displays the role, through gettext_with_context_default, so no translation is loaded early; a label WordPress already translates is left alone