Skip to content

PHP Hooks

Sasha Ivanenko edited this page Apr 19, 2023 · 20 revisions

Table of Contents

Actions

jet-form-builder/before-init

Executed before plugin initialization on hook after_setup_theme with priority 0.

Usage

add_action(
	'jet-form-builder/before-init',
	function() {
		// your code
	}
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/plugin.php#L210

jet-form-builder/after-init

Executed after plugin initialization on hook after_setup_theme with priority 0.

Usage

add_action(
	'jet-form-builder/after-init',
	function() {
		// your code
	}
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/plugin.php#L214

jet-form-builder/form-handler/before-send

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

Parameters

Usage

add_action(
	'jet-form-builder/form-handler/before-send',
	/**
	 * @var \Jet_Form_Builder\Form_Handler $handler
	 */
	function( $handler ) {
		// your code
	},
	10,
	1
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/form-handler.php#L295

jet-form-builder/form-handler/after-send

It is executed after all actions are executed during the normal submission of the form. In other words, after running the DEFAULT.REQUIRED event

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/form-handler.php#L338

jet-form-builder/before-trigger-event

It is executed before starting the actions that belong to the event passed in the first parameter.

Parameters

Usage

add_action(
	'jet-form-builder/before-trigger-event',
	/**
	 * @var \Jet_Form_Builder\Actions\Events\Base_Event $event
	 */
	function( $event ) {
		// your code
	},
	10,
	1
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/events-manager.php#L71

jet-form-builder/after-trigger-event

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.

Parameters

Usage

add_action(
	'jet-form-builder/after-trigger-event',
	/**
	 * @var \Jet_Form_Builder\Actions\Events\Base_Event $event
	 */
	function( $event ) {
		// your code
	},
	10,
	1
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/events-manager.php#L73

jet-form-builder/actions/before-send

Analogue of jet-form-builder/before-trigger-event. But this hook is executed only on the DEFAULT.PROCESS event.

Usage

add_action(
	'jet-form-builder/actions/before-send',
	function() {
		// your code
	}
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/events/default-process/default-process-executor.php#L16

jet-form-builder/actions/after-send

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.

Usage

add_action(
	'jet-form-builder/actions/after-send',
	function() {
		// your code
	}
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/events/default-process/default-process-executor.php#L22

jet-form-builder/actions/register

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 )

Parameters

Usage

add_action(
	'jet-form-builder/actions/register',
	/**
	 * @var \Jet_Form_Builder\Actions\Manager $manager
	 */
	function( $manager ) {
		// your code
	},
	10,
	1
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/manager.php#L56

jet-form-builder/action/after-post-insert

Executed after creating a new post through the Insert/Update Post action.

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/methods/post-modification/base-post-action.php#L26

jet-form-builder/action/after-post-update

Executed after updating the post through the Insert/Update Post action.

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/methods/post-modification/base-post-action.php#L26

jet-form-builder/before-page-start

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

Parameters

Usage

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;
		}
	}
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/form-break.php#L210

jet-form-builder/before-start-form-row

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

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/base.php#L578

jet-form-builder/after-start-form-row

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

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/base.php#L578

jet-form-builder/before-end-form-row

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

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/base.php#L603

jet-form-builder/after-end-form-row

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

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/base.php#L607

jet-form-builder/media-field/before-upload

Runs before the image upload process begins

Parameters

Usage

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' );
	}
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/request/fields/media-field-parser.php

jet-form-builder/inserted-attachment

Executed after adding an attachment, namely wp_insert_attachment

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/request/file-uploader.php#L104

jet-form-builder/gateways/register

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

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/gateways/gateway-manager.php#L112

jet-form-builder/gateways/before-send

It is launched after passing the payment gateway. Event trigger GATEWAY.SUCCESS or GATEWAY.FAILED occurs before this hook.

jet-form-builder/action/webhook/response

Runs after executing wp_remote_post if the result did not return WP_Error.

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/types/call-webhook.php#L72

jet-form-builder/editor-package/before

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

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/admin/editor.php#L315

jet-form-builder/editor-assets/before

Runs before adding the final scripts to the form edit page. At this point, JetFormBuilder has added the package scripts to the queue

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/admin/editor.php#L350

jet-form-builder/editor-assets/after

Executed at the very end after adding all the scripts to the edit page of the form.

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/admin/editor.php#L401

jet-form-builder/blocks/register

Runs after registering all main blocks, including the form block itself. On this hook, we can register a custom field for the form.

Parameters

Usage

add_action(
	'jet-form-builder/blocks/register',
	/**
	 * @var \Jet_Form_Builder\Blocks\Manager $manager
	 */
	function ( $manager ) {
        // $manager->register_block_type( $block_instance );
	}
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/manager.php#L97

jet-form-builder/custom-action/{$hook_name}

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.

Parameters

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/types/call-hook.php#L55

jet-fb/admin-pages/before-assets/{$current_page_slug}

Executed before adding scripts to the queue, and after registering them on the page for each JetFormBuilder child page.

Parameters

Usage

add_action(
	'jet-fb/admin-pages/before-assets/jfb-settings',
	/**
	 * @var \Jet_Form_Builder\Admin\Pages\Pages_Manager $manager
	 */
	function ( $manager ) {
		// your code
	}
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/admin/pages/pages-manager.php#L147

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

Must return an object listing the available functions for the "Field Value" option in the Hidden Field.

Parameters

  • $config array

Usage

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;
	}
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/hidden-field.php#L338

jet-form-builder/fields/hidden-field/value-cb

Must return a function that at some point returns some value for a hidden form field.

Parameters

  • $callback false|callable
  • $field_value string (slug of field value)

Usage

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
);

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/blocks/types/hidden-field.php#L97

jet-form-builder/fields/wysiwyg-field/config

Should return an array with settings for the wp_editor function

Parameters

Usage

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;
	}
);

jet-form-builder/send-email/template-repeater

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.

Parameters

  • $content string (By default empty string)
  • $items array (Repeater items)

Usage

add_filter(
	'jet-form-builder/send-email/template-repeater',
	function ( string $content, array $items ) {

		$index          = 0;
		$separator      = "<br>";
		$tab            = "&emsp;";
		$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

jet-form-builder/action/insert-post/modifiers

jet-form-builder/post-modifier/object-properties

jet-form-builder/action/insert-post/pre-check

Parameters

Source

https://github.com/Crocoblock/jetformbuilder/blob/main/includes/actions/methods/post-modification/base-post-action.php#L34

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

Useful links

🔸 View source of current page

Clone this wiki locally