Action Hook fieldPro
Run your own PHP code at a chosen place inside the form with a custom WordPress action.
The Action Hook field is for developers. At its place in the form it calls a WordPress action with a name you choose. Your code can print extra HTML there, for example a custom input or a notice. This is a Pro field.
Set it up
- Drag Action Hook into the form.
- Set Action Hook Name, for example
my_custom_form_action. Use a unique name. - Optional: fill Description to explain the hook to other developers.
- Click Save.
If Action Hook Name is empty, nothing happens.
Example
Add this to your theme’s functions.php or a small plugin:
add_action('my_custom_form_action', 'my_custom_form_html', 10, 4);
function my_custom_form_html($post_id, $attributes, $field, $form_settings) {
// $post_id: ID of the post being edited, or 'new' for a new post
// $attributes: shortcode attributes, $attributes['id'] is the form ID
// $field: settings of this Action Hook field
// $form_settings: all settings of the form
echo '<p class="my-note">Please read our rules before you submit.</p>';
}
Parameters
| Parameter | Type | Description |
|---|---|---|
$post_id |
int or 'new' |
Post being edited, or 'new' |
$attributes |
array | Shortcode attributes of the form |
$field |
array | Configuration of this field |
$form_settings |
array | form_settings and form_builder_json of the form |
The hook runs when the form is shown, not when it is submitted. To save extra inputs, use the bfe_ajax_after_front_editor_post_update_or_creation action. See Hooks.