Developer API
Every public function, grouped by task. Each page explains Purpose, Syntax, Parameters, Return value, Example and Notes.
Names from before the rename. Until 0.15.0 the plugin was called Advanced Field
Core (AFC). Since 0.16.0 only the new names exist: replace afc_get_field() with
cafe_get_field(), afc() with cafe(), and AFC\… classes with
Cybo\AdvancedFieldEngine\… (AFC\Fields\Field is Cybo\AdvancedFieldEngine\Fields\Field).
Reading
| Function | Does |
|---|---|
cafe_get_field() |
Returns one field value |
cafe_get_fields() |
Returns all saved values of an object |
cafe_has_field() |
Checks whether a value is saved |
cafe_get_option() |
Returns a global option value |
cafe_prime_fields() |
Loads the fields of many objects at once (loops, REST) |
Writing
| Function | Does |
|---|---|
cafe_update_field() |
Saves a value |
cafe_save_values() |
Saves several values of one object at once (all or nothing) |
cafe_check_value() |
Checks a value without saving it |
cafe_delete_field() |
Deletes a value |
cafe_update_option() |
Saves a global option value |
cafe_delete_option() |
Deletes a global option value |
Extending
| Function | Does |
|---|---|
cafe_register_field_type() |
Registers a custom field type |
cafe_add_settings_page() |
Adds a Settings Page (e.g. "Contact Settings") from PHP |
Front-end forms (CAFE Forms)
| Function | Does |
|---|---|
cafe_dynamic_form() |
Shows a form that creates a post or edits a post, user, term or options |
cafe_get_dynamic_form() |
Returns that form's HTML (shortcodes, builders) |
cafe_register_dynamic_form() |
Registers a form to use by ID (templates, shortcode, REST) |
cafe_submit_dynamic_form() |
Validates and saves data through a form from PHP |
Import & export
| Function | Does |
|---|---|
cafe_export_field_groups() |
Exports field group definitions as a CAFE JSON document |
cafe_validate_field_group_import() |
Checks an export and shows what an import would do (dry run) |
cafe_import_field_groups() |
Imports field group definitions (create, update or upsert) |
Migration (CAFE Connector)
| Function | Does |
|---|---|
cafe_import_object() |
Creates or updates one object with its CAFE values (custom migration code) |
cafe_imported_object_id() |
Old ID → the object a migration imported |
cafe_register_migration_source() |
Adds your own source to CAFE → Migration |
cafe_register_migration_transformer() |
Adds a value transformation to CAFE → Migration |
Advanced
| Function | Does |
|---|---|
cafe() |
Access to CAFE services (detailed errors, schema manager, registries) |
The $object_id argument
Most functions accept the same flexible object argument:
| You pass | CAFE uses |
|---|---|
nothing / null |
The current object: the post in the loop, the term of a term archive, the author of an author archive |
123 or '123' |
Post 123 (add $object_type for other types) |
123, 'term' |
Term 123 (also 'user', 'comment', 'post') |
a WP_Post, WP_Term, WP_User or WP_Comment |
That object |
'option' |
The global options |
Names and keys
$selector is normally the field name ('hero_title'). You may also pass the
field key ('field_65a1c2e4b0f1d2'), which is unique across all field groups.
Use the key when two field groups define the same name and you need a specific one.
When two groups share a name, CAFE picks, in order: the field that has a saved value for this object, then fields in active groups, then the lowest group order.
Rows (Collection, Section Builder, Field Set)
| Function | Does |
|---|---|
| cafe_rows() | Items / sections as row objects for foreach |