Recipe: Custom RSVP Field
Goal: Add a custom field to the RSVP form, persist the submitted value against the RSVP record using the Meta API, and expose it in the attendee admin table.
Seams Used
| Seam | Type | Purpose |
|---|---|---|
evnm_register_meta |
Action | Register the meta key with type + sanitizer so it is typed and REST-accessible. |
evnm_registration_fields |
Filter | Add the field definition to the RSVP form. |
evnm_after_create_rsvp |
Action | Persist the submitted value from the REST payload. |
evnm_get_meta / evnm_update_meta |
Functions | Read/write against evnm_meta (public Meta API). |
The Code
<?php
// my-addon/my-addon.php
// 1. Register the meta key so it is typed and optionally REST-exposed.
add_action( 'evnm_register_meta', function () {
evnm_register_meta( 'rsvp', 'tshirt_size', [
'type' => 'string',
'sanitize_callback' => 'sanitize_text_field',
'show_in_rest' => true, // surfaced in GET /rsvps/{id} responses
] );
} );
// 2. Add the field to the RSVP form.
add_filter( 'evnm_registration_fields', function ( array $fields, array $event ): array {
$fields[] = [
'id' => 'tshirt_size',
'label' => __( 'T-shirt size', 'my-addon' ),
'type' => 'select',
'options' => [ 'XS', 'S', 'M', 'L', 'XL', 'XXL' ],
'required' => false,
];
return $fields;
}, 10, 2 );
// 3. Persist the submitted value after the RSVP is created.
// $rsvp['meta'] is populated by Free from the REST payload for registered fields.
add_action( 'evnm_after_create_rsvp', function ( array $rsvp, array $context ) {
$size = isset( $rsvp['meta']['tshirt_size'] )
? sanitize_text_field( (string) $rsvp['meta']['tshirt_size'] )
: '';
if ( '' !== $size ) {
evnm_update_meta( 'rsvp', $rsvp['id'], 'tshirt_size', $size );
}
}, 10, 2 );
// 4. (Optional) Show the value in the attendee list via the REST prepare filter.
add_filter( 'evnm_rest_prepare_rsvp', function ( array $data, array $rsvp, $request ): array {
$data['tshirt_size'] = evnm_get_meta( 'rsvp', $rsvp['id'], 'tshirt_size', '' );
return $data;
}, 10, 3 );
Supported Field Types
The evnm_registration_fields filter accepts these type values, which the block renders as native form controls:
| Type | Renders as |
|---|---|
text |
<input type="text"> |
textarea |
<textarea> |
select |
<select> with options array |
checkbox |
<input type="checkbox"> |
Verify It Worked
- Visit a published event's single-event page.
- Submit an RSVP - the T-shirt size field should appear in the form.
- After submission, run in WP-CLI:
wp eval 'echo evnm_get_meta("rsvp", RSVP_ID, "tshirt_size");' - Confirm the selected size is returned.
- Check
GET /wp-json/eventonomy/v1/events/{id}/rsvps- each RSVP object should includetshirt_sizeifshow_in_rest: truewas set.
Related
- Hooks & Filters - full
evnm_registration_fieldssignature. docs/EXTENDING.mdยง8 - Meta API reference.- Recipes Index