Skip to main content

benecaster_field_value_saved

Action Free

Fires after a custom field value is written to the database, whether by an episode editor save or by benecaster_update_field(). Fires for both writes (a non-null value is upserted) and deletes (a null value removes the row, and $value is null). It fires once per field, changed or not, and never once per batch. For one call per save naming only the fields that changed, use benecaster_episode_field_values_updated.

This action fires synchronously during the write. 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
$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.

Need this built rather than just documented? See our services →