benecaster_field_value_saved
Fires after a custom field value is written to the database via the field values REST endpoint. Fires for both writes (a non-null value is upserted) and deletes (a null value removes the row). When multiple field values are saved in a single request, this action fires once per field — not once per batch.
This action fires synchronously during the REST request. Avoid slow or blocking operations in the callback. Use `wp_schedule_single_event()` to defer external API calls, large queries, or any non-trivial work to a background request.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$field_id |
int |
— | ID of the field definition (benecaster_fields.id) |
$object_id |
int |
— | ID of the object the field value belongs to |
$cpt_slug |
string |
— | CPT slug (e.g. 'benecaster_episode', 'benecaster_guest') |
$value |
mixed |
— | The value that was saved; null when value was cleared |
Examples
Push guest field update to external CRM
add_action( 'benecaster_field_value_saved', function (
int $field_id,
int $object_id,
string $cpt_slug,
mixed $value
): void {
if ( 'benecaster_guest' !== $cpt_slug || null === $value ) {
return;
}
// Map Benecaster field IDs to CRM field keys.
$field_map = [
15 => 'guest_name',
16 => 'booking_url',
17 => 'bio',
];
if ( ! isset( $field_map[ $field_id ] ) ) {
return;
}
wp_remote_post( 'https://api.mycrm.com/contacts/' . $object_id, [
'body' => wp_json_encode( [ $field_map[ $field_id ] => $value ] ),
'headers' => [ 'Content-Type' => 'application/json' ],
'timeout' => 5,
] );
}, 10, 4 );
Invalidate episode cache on any field change
add_action( 'benecaster_field_value_saved', function (
int $field_id,
int $object_id,
string $cpt_slug,
mixed $value
): void {
if ( 'benecaster_episode' !== $cpt_slug ) {
return;
}
delete_transient( 'my_plugin_episode_cache_' . $object_id );
}, 10, 4 );
Notes
When $value is null, the database row was deleted — the field has no stored value for this object. This action fires synchronously during the REST request; avoid slow or blocking operations and use wp_schedule_single_event() to defer any heavy work. This is a Free action — it fires regardless of license status.