The ‘Run WordPress Hook’ action runs a WordPress action or filter when a user saves or submits a form. Although simple this action is powerful and allows developers to run any PHP code when a website visitor submits a form.
Adding This Action
To add a ‘Run WordPress Hook’ action:
- When editing your form, click the ‘Actions’ icon at the top of the page. The ‘Actions’ sidebar will open on the right-hand side of the page.
- Click the ‘Add’ icon to add a new action.
- Select ‘Run WordPress Hook’ from the Action pulldown. A series of settings will appear.
As with all sidebars in WS Form, click the ‘Save’ button at the bottom to save your changes, or click ‘Cancel’ to disregard your changes.
The ‘Run WordPress Hooks’ action settings are as follows:
When should this action run?
You can choose to run the WordPress hook when the form is saved, submitted, or both.
Select the type of hook you would like to run:
- Filter (apply_filter)
- Action (do_action)
Enter the tag name of the filter or action you want to run.
Choose whether to run the hook before or after other actions.
If you want to manipulate field values before other actions run, select ‘Before’.
If you want to use the data after other actions have run (For example, to obtain a Zendesk ticket ID), select ‘After’.
WS Form PRO will call the filter as follows:
apply_filters($tag_name, $form, $submit);
- $form – This contains the form object.
- $submit – This contains the submit object.
The return from your filter function will be processed as follows:
|Return Type||Processed As|
|$submit object||$submit object will be replaced and passed to the next action|
|Integer: 0 – 100||Spam level set
0 = Not spam, 100 = Spam
|Boolean: false||Action processing halted|
WS Form PRO will call the action as follows:
do_action($tag_name, $form, $submit);
- $form – This contains the form data.
- $submit – This contains the submit data.