Purpose
The wr_form_builder_modify_entry_id filter allows you to dynamically set or modify the entry ID that is used to load an existing form entry. This is particularly useful for forms that require data linked to a specific context, such as a user’s profile or other contextual entries.
Usage
add_filter( "wr_form_builder_modify_entry_id", array( $this, "set_entry_id" ), 10, 2 );
Parameters
$entry_id (string|int)
: The current entry ID derived from the form payload or other sources. Defaults to an empty string if no entry ID is present.$form (Form)
: The form object being processed.
Use Case
This filter is useful when:
- You need to dynamically determine the entry ID based on specific form types or contexts (e.g., user profile forms).
- External logic or database queries are required to identify the appropriate entry for a form.
Implementation Example
The following example sets the entry ID for a profile form based on the currently logged-in user:
add_filter( "wr_form_builder_modify_entry_id", array( $this, "set_entry_id" ), 10, 2 );
/**
* Dynamically set the entry ID for the profile form.
*
* @param mixed $entry_id
* @param Form $form
* @return mixed
*/
public function set_entry_id( $entry_id, Form $form ) {
// Check if the form is the profile form
if ( $form->get_identifier() === 'form_identifier' ) {
// Query to find the profile entry for the current user
$result = ( new Executor( 'query_identifier' ) )->get_row();
// If a result is found, set the entry ID
if ( ! empty( $result ) ) {
$entry_id = $result['id'];
}
}
return $entry_id;
}