FieldValueStore
\Benecaster\Fields\FieldValueStore
Handles all reads and writes of stored custom field values. Every read passes through the benecaster_field_value filter; every write fires benecaster_field_value_saved, and every write to an episode also goes through the change detection that fires benecaster_episode_field_values_updated. Saving a null value deletes the stored value outright — a field is either set or absent, never explicitly null. Non-null values overwrite any existing value for the same field and object. Registered as a singleton in the container.
Add-on code rarely calls FieldValueStore directly. Use benecaster_get_field() and benecaster_get_fields() for reads, and benecaster_update_field() for writes: it checks the field against the object’s post type first, which the store does not. Use FieldValueStore directly for delete_for_object() (cascade delete on post deletion) or get_raw_map() (unfiltered before/after snapshot).
Methods
| Method | Visibility | Since | Description |
|---|---|---|---|
get( int $field_id, int $object_id ): mixed |
Public | — | Returns the stored value for a field on an object, passed through the benecaster_field_value filter. Returns null when no value is stored. |
get_for_group( int $group_id, int $object_id ): array |
Public | — | Returns all stored values for a field group on an object, keyed by field_key. Values pass through benecaster_field_value individually. Fields with no stored value appear with null. |
set( int $field_id, int $object_id, string $object_type, int $group_id, mixed $value ): void |
Public | — | Saves one field value. When $value is non-null, upserts the row. When null, deletes the row (clears the field). Fires benecaster_field_value_saved after every call. A one-field call to set_many(), so on an episode a change also fires benecaster_episode_field_values_updated. |
set_many( int $object_id, string $object_type, array $writes ): void |
Public | — | Writes several field values on one object as one save. $writes is keyed by field ID, each entry {group_id, value}, with a null value clearing that field. Fires benecaster_field_value_saved once per field, changed or not. For an episode it also fires benecaster_episode_field_values_updated once per call, naming only the fields whose stored value changed; it does not fire for other post types, or when the episode cannot be loaded. This is where that hook fires, so any write path must come through here. |
get_raw_map( int $object_id, array $field_ids ): array |
Public | — | Returns unfiltered stored values for a set of field IDs. Bypasses benecaster_field_value filter. Used internally for before/after change detection. Not typically called by add-on code. |
delete_for_object( int $object_id, string $object_type ): void |
Public | — | Deletes all field values for an object. Called on post deletion to prevent orphaned rows. Scoped to a specific CPT. Benecaster calls this automatically for benecaster_episode; add-ons must wire it for their own CPTs. |