-
Notifications
You must be signed in to change notification settings - Fork 16
PHP Hooks
-
Actions
jet-form-builder/before-init
jet-form-builder/after-init
jet-form-builder/form-handler/before-send
jet-form-builder/form-handler/after-send
jet-form-builder/before-trigger-event
jet-form-builder/after-trigger-event
jet-form-builder/actions/before-send
jet-form-builder/actions/after-send
jet-form-builder/actions/register
jet-form-builder/action/after-post-insert
jet-form-builder/action/after-post-update
jet-form-builder/before-page-start
jet-form-builder/before-start-form-row
jet-form-builder/after-start-form-row
jet-form-builder/before-end-form-row
jet-form-builder/after-end-form-row
jet-form-builder/media-field/before-upload
jet-form-builder/inserted-attachment
jet-form-builder/gateways/register
jet-form-builder/gateways/before-send
jet-form-builder/action/webhook/response
jet-form-builder/editor-package/before
jet-form-builder/editor-assets/before
jet-form-builder/editor-assets/after
jet-form-builder/blocks/register
jet-form-builder/custom-action/{$hook_name}
jet-fb/admin-pages/before-assets/{$current_page_slug}
-
Filters
jet-form-builder/request-handler/request
jet-form-builder/form-handler/form-data
jet-form-builder/event-types
jet-form-builder/parsers-request/register
jet-form-builder/content-filters
jet-form-builder/content-constants
jet-form-builder/custom-macro
jet-form-builder/editor/hidden-field/config
jet-form-builder/fields/hidden-field/value-cb
jet-form-builder/fields/wysiwyg-field/config
jet-form-builder/send-email/template-repeater
jet-form-builder/action/insert-post/modifiers
jet-form-builder/post-modifier/object-properties
jet-form-builder/action/insert-post/pre-check
jet-form-builder/action/webhook/request-args
jet-form-builder/action/webhook/request-url
jet-form-builder/page-config/{$current_page_slug}
jet-form-builder/render/{$field_type}/attributes
Executed before plugin initialization on hook after_setup_theme
with priority 0.
add_action(
'jet-form-builder/before-init',
function() {
// your code
}
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/plugin.php#L210
Executed after plugin initialization on hook after_setup_theme
with priority 0.
add_action(
'jet-form-builder/after-init',
function() {
// your code
}
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/plugin.php#L214
It is performed before the execution of all actions in the normal submission of the form. In other words, before running the event DEFAULT.PROCESS
- $handler
\Jet_Form_Builder\Form_Handler
add_action(
'jet-form-builder/form-handler/before-send',
/**
* @var \Jet_Form_Builder\Form_Handler $handler
*/
function( $handler ) {
// your code
},
10,
1
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/form-handler.php#L295
It is executed after all actions are executed during the normal submission of the form. In other words, after running the DEFAULT.REQUIRED
event
- $handler
\Jet_Form_Builder\Form_Handler
- $is_success
boolean
(The result of form processing)
add_action(
'jet-form-builder/form-handler/after-send',
/**
* @var \Jet_Form_Builder\Form_Handler $handler
*/
function( $handler, bool $is_success ) {
// your code
},
10,
2
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/form-handler.php#L338
It is executed before starting the actions that belong to the event passed in the first parameter.
- $event
\Jet_Form_Builder\Actions\Events\Base_Event
(This will be an object, a class that extends from Base_Event)
add_action(
'jet-form-builder/before-trigger-event',
/**
* @var \Jet_Form_Builder\Actions\Events\Base_Event $event
*/
function( $event ) {
// your code
},
10,
1
);
Executed after launching the actions that belong to the event passed in the first parameter.
Note: if one of the actions returns an error (exception) during execution, this hook will not be executed.
- $event
\Jet_Form_Builder\Actions\Events\Base_Event
(This will be an object, a class that extends from Base_Event)
add_action(
'jet-form-builder/after-trigger-event',
/**
* @var \Jet_Form_Builder\Actions\Events\Base_Event $event
*/
function( $event ) {
// your code
},
10,
1
);
Analogue of jet-form-builder/before-trigger-event
. But this hook is executed only on the DEFAULT.PROCESS
event.
add_action(
'jet-form-builder/actions/before-send',
function() {
// your code
}
);
Analogue of jet-form-builder/after-trigger-event
. But this hook is executed only on the DEFAULT.PROCESS
event.
Note: if one of the actions returns an error (exception) during execution, this hook will not be executed.
add_action(
'jet-form-builder/actions/after-send',
function() {
// your code
}
);
It is performed after registration of all actions on hook init
with priority 99
.\
Usually used to register additional actions with $manager->register_action_type( $action_instance )
- $manager
\Jet_Form_Builder\Actions\Manager
add_action(
'jet-form-builder/actions/register',
/**
* @var \Jet_Form_Builder\Actions\Manager $manager
*/
function( $manager ) {
// your code
},
10,
1
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/manager.php#L56
Executed after creating a new post through the Insert/Update Post action.
- $action
\Jet_Form_Builder\Actions\Types\Base
(This will be an object, a class that extends from Base) - $handler
\Jet_Form_Builder\Actions\Action_Handler
add_action(
'jet-form-builder/action/after-post-insert',
/**
* @var \Jet_Form_Builder\Actions\Types\Base $action
* @var \Jet_Form_Builder\Actions\Action_Handler $handler
*/
function( $action, $handler ) {
// Get the inserted post ID
$ID = $handler->get_inserted_post_id( $action->_id );
// your code
},
10,
2
);
Executed after updating the post through the Insert/Update Post action.
- $action
\Jet_Form_Builder\Actions\Types\Base
(This will be an object, a class that extends from Base) - $handler
\Jet_Form_Builder\Actions\Action_Handler
add_action(
'jet-form-builder/action/after-post-insert',
/**
* @var \Jet_Form_Builder\Actions\Types\Base $action
* @var \Jet_Form_Builder\Actions\Action_Handler $handler
*/
function( $action, $handler ) {
// Get the inserted post ID
$ID = $handler->get_inserted_post_id( $action->_id );
// your code
},
10,
2
);
Executed before rendering the opening HTML tag of the page with the jet-form-builder-page
css-class.
Currently in this hook we can change the scroll offset when going to the current page.
You must have the "Scroll to the top on page change" option enabled on the JetFormBuilder -> Settings page
- $break
\Jet_Form_Builder\Form_Break
add_action(
'jet-form-builder/before-page-start',
/**
* @var \Jet_Form_Builder\Form_Break $break
*/
function ( $break ) {
// Check form ID.
if ( 77 !== jet_fb_live()->form_id ) {
return;
}
/**
* Depending on the order of the page, we can determine the offset.
* The larger the offset, the higher the scroll will be
*/
switch ( $break->get_current() ) {
case 1:
$break->set_page_offset( 100 );
break;
case 2:
$break->set_page_offset( 0 );
break;
}
}
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/form-break.php#L210
It is executed before rendering the markup with the opening div
tag for each field.\
This element can be accessed using the jet-form-builder-row
or field-type-{$block_type}
class
add_action(
'jet-form-builder/before-start-form-row',
/**
* @var \Jet_Form_Builder\Blocks\Types\Base $block
*/
function( $block ) {
// you could use "echo" or "$block->add_attribute" here
// echo will add content outside the `div`
},
10,
1
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/base.php#L578
It is executed after rendering the markup with the opening div
tag for each field.\
This element can be accessed using the jet-form-builder-row
or field-type-{$block_type}
class
add_action(
'jet-form-builder/after-start-form-row',
/**
* @var \Jet_Form_Builder\Blocks\Types\Base $block
*/
function( $block ) {
// you could use "echo" or "$block->add_attribute" here
// echo will add content inside the `div`
},
10,
1
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/base.php#L578
Executed before rendering the markup with the closing div
tag for each field that opens on the jet-form-builder/before-start-form-row
hook
add_action(
'jet-form-builder/before-end-form-row',
/**
* @var \Jet_Form_Builder\Blocks\Types\Base $block
*/
function( $block ) {
// you could use "echo" here
// echo will add content inside the `div`
},
10,
1
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/base.php#L603
Executed after rendering the markup with the closing div
tag for each field that opens on the jet-form-builder/before-start-form-row
hook
add_action(
'jet-form-builder/after-end-form-row',
/**
* @var \Jet_Form_Builder\Blocks\Types\Base $block
*/
function( $block ) {
// you could use "echo" here
// echo will add content outside the `div`
},
10,
1
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/base.php#L607
Runs before the image upload process begins
An example of how to allow guests to upload files
add_action(
'jet-form-builder/media-field/before-upload',
/**
* @var \Jet_Form_Builder\Request\Fields\Media_Field_Parser $parser
*/
function ( $parser ) {
$class_name = $parser->get_context()->get_class_name();
// We need to add 'allow-insert-attachments' to the Advanced -> CSS Class Name option
if ( ! $class_name || false === strpos( $class_name, 'allow-insert-attachments' ) ) {
return;
}
$parser->get_context()->allow_for_guest();
$parser->get_context()->update_setting( 'insert_attachment', true );
// for second param you can use 'id', 'url' or 'both'
$parser->get_context()->update_setting( 'value_format', 'id' );
}
);
Executed after adding an attachment, namely wp_insert_attachment
- $uploaded
\Jet_Form_Builder\Classes\Resources\Uploaded_File
- $file_uploader
\Jet_Form_Builder\Request\File_Uploader
add_action(
'jet-form-builder/inserted-attachment',
/**
* @var \Jet_Form_Builder\Classes\Resources\Uploaded_File $uploaded
* @var \Jet_Form_Builder\Request\File_Uploader $file_uploader
*/
function( $uploaded, $file_uploader ) {
// your code
$attachment_ID = $uploaded->get_attachment_id();
},
10,
2
);
It is launched after the installation of basic payment gateways. Currently it is only PayPal.
Runs on the init
hook.
You can register your own gateway on it. A full example of how to do it can be found here https://github.com/girafffee/jfb-custom-gateway
add_action(
'jet-form-builder/gateways/register',
/**
* Full example here
* @link https://github.com/girafffee/jfb-custom-gateway
*
* @var \Jet_Form_Builder\Gateways\Gateway_Manager $manager
*/
function( $manager ) {
// your code
},
10,
2
);
It is launched after passing the payment gateway. Event trigger GATEWAY.SUCCESS
or GATEWAY.FAILED
occurs before this hook.
Runs after executing wp_remote_post if the result did not return WP_Error.
- $response
array
(response from wp_remote_post) - $settings
array
(settings of current action) - $action
\Jet_Form_Builder\Actions\Types\Base
(Call_Webhook instance)
add_action(
'jet-form-builder/action/webhook/response',
/**
* @var array $response
* @var array $settings
* @var \Jet_Form_Builder\Actions\Types\Base $action
*/
function( $response, $settings, $action ) {
// your code
},
10,
3
);
Runs before enqueuing package scripts on the edit page of the form. At this point, the JetFormBuilder has not added any scripts to the queue
- $editor
\Jet_Form_Builder\Admin\Editor
- $handle
string
('jet-form-builder-editor-package')
add_action(
'jet-form-builder/editor-package/before',
/**
* @var \Jet_Form_Builder\Admin\Editor $editor
* @var string $handle
*/
function( $editor, $handle ) {
// your code
},
10,
2
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/admin/editor.php#L315
Runs before adding the final scripts to the form edit page. At this point, JetFormBuilder has added the package scripts to the queue
- $editor
\Jet_Form_Builder\Admin\Editor
- $handle
string
('jet-form-builder-editor')
add_action(
'jet-form-builder/editor-assets/before',
/**
* @var \Jet_Form_Builder\Admin\Editor $editor
* @var string $handle
*/
function( $editor, $handle ) {
// your code
},
10,
2
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/admin/editor.php#L350
Executed at the very end after adding all the scripts to the edit page of the form.
- $editor
\Jet_Form_Builder\Admin\Editor
- $handle
string
('jet-form-builder-editor')
add_action(
'jet-form-builder/editor-assets/after',
/**
* @var \Jet_Form_Builder\Admin\Editor $editor
* @var string $handle
*/
function( $editor, $handle ) {
// your code
},
10,
2
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/admin/editor.php#L401
Runs after registering all main blocks, including the form block itself. On this hook, we can register a custom field for the form.
- $manager
\Jet_Form_Builder\Blocks\Manager
add_action(
'jet-form-builder/blocks/register',
/**
* @var \Jet_Form_Builder\Blocks\Manager $manager
*/
function ( $manager ) {
// $manager->register_block_type( $block_instance );
}
);
https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/manager.php#L97
This hook is executed only if there is a Call Hook action form. With its help, you can perform any actions.
But if your logic involves some complex operations that might cause an error, then you should throw \Jet_Form_Builder\Exceptions\Action_Exception
in such cases.
When an exception is thrown, the form interrupts further execution of actions.
- $request
array
- $handler
\Jet_Form_Builder\Actions\Action_Handler
If hook name is: test_action
add_action(
'jet-form-builder/custom-action/test_action',
function ( $request, $handler ) {
if ( empty( $request['age'] ) ) {
/**
* You can use one of the default statuses
* 'success' => 'Form successfully submitted.',
* 'failed' => 'There was an error trying to submit form. Please try again later.',
* 'validation_failed' => 'One or more fields have an error. Please check and try again.',
* 'captcha_failed' => 'Captcha validation failed',
* 'invalid_email' => 'The e-mail address entered is invalid.',
* 'empty_field' => 'The field is required.',
* 'internal_error' => 'Internal server error. Please try again later.',
* 'upload_max_files' => 'Maximum upload files limit is reached.',
* 'upload_max_size' => 'Upload max size exceeded.',
* 'upload_mime_types' => 'File type is not allowed.',
*/
throw new \Jet_Form_Builder\Exceptions\Action_Exception( 'empty_field' );
}
if ( absint( $request['age'] ) < 18 ) {
throw new \Jet_Form_Builder\Exceptions\Action_Exception( 'Your age is less than necessary' );
}
/**
* If all checks are passed, you just need to do Nothing,
* so that the form would continue its work or successfully complete it.
*
* In rare cases, you can interrupt the execution of the form with a successful status.
*/
if ( 199 === absint( $request['age'] ) ) {
// or throw new Action_Exception( 'success' );
throw ( new \Jet_Form_Builder\Exceptions\Action_Exception( 'Lucky!' ) )->dynamic_success();
}
},
10,
2
);
Executed before adding scripts to the queue, and after registering them on the page for each JetFormBuilder child page.
add_action(
'jet-fb/admin-pages/before-assets/jfb-settings',
/**
* @var \Jet_Form_Builder\Admin\Pages\Pages_Manager $manager
*/
function ( $manager ) {
// your code
}
);
Must return an object listing the available functions for the "Field Value" option in the Hidden Field.
- $config
array
add_filter(
'jet-form-builder/editor/hidden-field/config',
function ( array $config ) {
$config['sources'][] = array(
'value' => 'custom_value',
'label' => __( 'My custom value', 'jet-form-builder' ),
);
return $config;
}
);
Must return a function that at some point returns some value for a hidden form field.
- $callback
false|callable
- $field_value
string
(slug of field value)
add_filter(
'jet-form-builder/fields/hidden-field/value-cb',
function ( $callback, $field_value ) {
if ( 'custom_value' !== $field_value ) {
return $callback;
}
return function () {
return 'value_for_hidden_field';
};
},
10,
2
);
Should return an array with settings for the wp_editor function
- $settings
array
($settings param)
add_filter(
'jet-form-builder/fields/wysiwyg-field/config',
function ( $config ) {
/**
* You can find a list of all available plugins as folder names
* in wp-includes/js/tinymce/plugins
*/
$plugins = array(
'colorpicker',
'textcolor',
);
$toolbar_buttons = array(
'|',
'fontselect',
'fontsizeselect',
'|',
'forecolor',
'backcolor'
);
$config['tinymce']['plugins'] .= ',' . implode( ',', $plugins );
$config['tinymce']['toolbar1'] .= ',' . implode( ',', $toolbar_buttons );
// add button for upload images
$config['media_buttons'] = true;
// make wysiwyg responsive to paragraphs from Microsoft Word, Google Docs etc.
$config['tinymce'] = array_merge(
$config['tinymce'],
array(
'paste_as_text' => false,
'paste_auto_cleanup_on_paste' => false,
'paste_remove_spans' => false,
'paste_remove_styles' => false,
'paste_remove_styles_if_webkit' => false,
'paste_strip_class_attributes' => false,
)
);
return $config;
}
);
By default, the value of the repeater is returned in the form of a list, where all field values are listed in each element. Here's an example of what it looks like:
1) text_field: some value;
2) text_field: another value;
To change this behavior, you can write your own filter that generates a different template.
- $content
string
(By default empty string) - $items
array
(Repeater items)
add_filter(
'jet-form-builder/send-email/template-repeater',
function ( string $content, array $items ) {
$index = 0;
$separator = "<br>";
$tab = " ";
$repeater_label = 'Repeater Heading';
$rows = array();
$if_array = function ( $value ) {
return is_array( $value ) ? implode( ', ', $value ) : $value;
};
foreach ( $items as $item ) {
$item_data = array();
foreach ( $item as $key => $value ) {
$label = jet_fb_request_handler()->get_attr( $key, 'label', $key );
$item_data[] = sprintf( '%1$s: %2$s', $label, call_user_func( $if_array, $value ) );
}
$row = "Repeater Item " . ++ $index . $separator . $tab;
$row .= implode( $separator . $tab, $item_data );
$rows[] .= $row;
}
return ( $separator . $repeater_label . $separator . implode( $separator, $rows ) );
},
10, 2
);
This code generates the following template:
Repeater Heading
Repeater Item 1
text_field: some value
Repeater Item 2
text_field: another value
- $can_be_inserted
bool
- $postarr
array
(arguments for wp_insert_post) - $action
\Jet_Form_Builder\Actions\Types\Insert_Post
Need more information? Check out the official documentation at jetformbuilder.com or contact Crocoblock Support