Cybo Advanced Field EngineCyboweb Technologies · Documentation · v1.0.2

cafe_register_dynamic_form()

Purpose

Registers a dynamic form once so it can be used by ID: in templates (cafe_dynamic_form( 'new-event' )), in the [cafe_dynamic_form] shortcode, over REST (GET /cafe/v1/forms/{id}) and in CAFE → Forms.

Syntax

cafe_register_dynamic_form( array $args ): bool|WP_Error

Parameters

Parameter Type Default Description
$args array - Form arguments; id is required. See cafe_dynamic_form() for every argument.

Return value

true, or a WP_Error explaining what is wrong with the arguments (for example a missing ID, an unknown post type or a create form for users).

Example

add_action( 'init', function () {
	cafe_register_dynamic_form( [
		'id'           => 'new-event',
		'field_groups' => [ 'group_event_details' ],
		'post_type'    => 'event',
		'post_fields'  => [ 'title' ],
	] );
} );

// Later, in a template: the registered form, editing one event.
cafe_dynamic_form( [ 'id' => 'new-event', 'object_id' => get_the_ID() ] );

Notes

  • Register on init (or later): the post types and taxonomies the form uses must exist.
  • Registrations live for the request, like post types. Nothing is stored in the database.
  • Only registered forms can be used by shortcode authors: they choose the ID (and optionally an object_id), never the field groups.