Cybo Advanced Field EngineCyboweb Technologies · Documentation · v1.0.2

Editing objects

An edit form shows the saved values of one object and saves the changes.

Object Arguments Who may use it
A post 'object_id' => 123 or 'current_post' people who may edit that post (edit_post)
The signed-in user 'object_type' => 'user', 'object_id' => 'current_user' the user (edit_user on themselves)
Another user 'object_type' => 'user', 'object_id' => 45 people who may edit that user
A term 'object_type' => 'term', 'object_id' => 7 or 'current_term' people who may edit the term (edit_term)
Global options 'object_type' => 'option' people with manage_options

These are the same checks as the edit screens in wp-admin. With capability set, that capability is needed as well.

A profile form

cafe_dynamic_form( [
	'id'           => 'my-profile',
	'field_groups' => [ 'group_profile' ],
	'object_type'  => 'user',
	'object_id'    => 'current_user',
	'submit_label' => 'Save profile',
] );

"Edit this post" on the post itself

// single-event.php
if ( current_user_can( 'edit_post', get_the_ID() ) ) {
	cafe_dynamic_form( [
		'id'           => 'edit-event',
		'field_groups' => [ 'group_event_details' ],
		'object_id'    => get_the_ID(),   // or 'current_post'
		'post_fields'  => [ 'title' ],
	] );
}

A registered form can be reused for many posts: register it once and pass the object when showing it: cafe_dynamic_form( [ 'id' => 'edit-event', 'object_id' => get_the_ID() ] ).

In CAFE → Forms, choose Edit the post being viewed, Edit the signed-in user, Edit the category / term being viewed or Edit global options.

What is saved

  • Only fields that were sent change. A field missing from the submission keeps its value (unless it is required, then the form asks for it).
  • Password fields left empty keep the saved password.
  • Fields that an integration shows read-only (for example WPML "copy" fields on a translation) are never saved from a form.
  • Post fields (title, content, excerpt) update the post with wp_update_post(); the post's status and author do not change.

Options

'object_type' => 'option' edits the global options read with cafe_get_option() / cafe_get_field( 'name', 'option' ). The fields come from the field groups you list, for example the groups placed on a Settings Page.