Skip to main content

Attributes Reference

Quick reference for every attribute. See Core → Attributes for narrative coverage.

Field-mapping

AttributeConstructorUsed byNotes
#[MetaKey](string $key, ?string $type = null, bool $showInRest = false, bool $single = true, mixed $default = null, ?string $description = null, ?string $sanitize = null, ?string $authCapability = null, bool $encrypt = false)Sources, Sinks, MetaKeyRegistryMaps a property to a WP meta key
#[PostField](string $name)PostSource, PostSinkMaps a property to a WP_Post system field
#[UserField](string $name)UserSource, UserSinkMaps a property to a WP_User system field
#[TermField](string $name)TermSource, TermSinkMaps a property to a WP_Term system field
#[Column](string $name)RowSource, RowSinkMaps a property to a $wpdb column

Type-shape

AttributeConstructorUsed byNotes
#[ListOf](string $class)DataObject hydration, sinks, PresenterElement class for arrays
#[DateFormat](string $format)SinksOverride datetime format on writes

Security

AttributeConstructorUsed byNotes
#[Encrypted]()Sources, Sinks, MetaKeyRegistryAES-256-GCM at-rest
#[Sensitive]()PresenterExcluded from output unless includeSensitive

Validation rules (under BetterData\Validation\Rule\)

AttributeConstructorPass condition
#[Required]()not null, not empty string, not empty array
#[Email]()FILTER_VALIDATE_EMAIL (skips null)
#[Url]()FILTER_VALIDATE_URL (skips null)
#[Uuid]()RFC 4122 v1–8 (skips null)
#[Regex](string $pattern, ?string $message = null)preg_match matches (skips null)
#[Min](int|float $min)>= $min; non-numeric fails (skips null)
#[Max](int|float $max)<= $max; non-numeric fails (skips null)
#[MinLength](int $min)strings/arrays >= $min (skips null)
#[MaxLength](int $max)strings/arrays <= $max (skips null)
#[OneOf](array $allowed)strict in_array (skips null)

Callback is constructed programmatically (closures aren't valid attribute arguments):

new BetterData\Validation\Rule\Callback(
fn (mixed $value, string $field, DataObject $subject): ?string => ...
);

Interaction matrix

CombinationEffect
#[MetaKey] #[Encrypted]Encrypted-at-rest meta. Recommended for keys, tokens.
MetaKey(encrypt: true) aloneEquivalent. #[Encrypted] and MetaKey(encrypt: true) are idempotent.
#[MetaKey] #[Sensitive]Plaintext storage; hidden from Presenter unless explicitly included.
#[Encrypted] on SecretEncrypted at rest and leak-proof in memory.
#[MetaKey('_x', encrypt: true, showInRest: true)]_doing_it_wrong — REST consumers would receive ciphertext. Drop one of the two.
#[MetaKey('_x', showInRest: true)] no authCapability_doing_it_wrong — silent 403 on REST writes. Set capability or drop _.
#[PostField] AND #[MetaKey] on the same fieldMetaKey wins; PostField is silently ignored. Treat as configuration error.
#[ListOf] on a non-array propertyIgnored — only arrays are coerced element-by-element.
#[DateFormat] on a non-datetime propertyIgnored on writes.
#[Sensitive] on SecretDouble protection — Presenter excludes it; even if included, redacts to '***'.

Auto-detection (no attribute needed)

When a property name matches a known system field, the engines resolve it without an explicit attribute:

SourceAuto-detected fields
WP_PostID, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count
WP_UserID, user_login, user_nicename, user_email, user_url, user_registered, user_status, display_name
WP_Termterm_id, name, slug, term_group, term_taxonomy_id, taxonomy, description, parent, count

The id (lowercase) property auto-aliases to ID (or term_id for terms).