Greyd Forms Filters

On this page, we’ve listed available filters for Greyd Forms. If you’re looking for filters specific to emails, see the Greyd Forms Mail Filter documentation. See the Greyd Forms Filter Snippets for examples how to use the filters.

Form Validation Filters

greyd_forms_expected_fields

Filter to modify the expected form input fields before validation.

This filter allows developers to customize which fields are expected in a form submission, enabling dynamic form field management.

Parameters:

  • array $expected_inputs – Array of expected inputs with their configuration.
  • int $post_id – WP_Post ID of the form.
  • array $data – Raw form data before validation.

Returns: array – Modified array of expected inputs.

PHP
/**
 * Filter to modify the expected form input fields before validation.
 * 
 * This filter allows developers to customize which fields are expected
 * in a form submission, enabling dynamic form field management.
 * 
 * @filter greyd_forms_expected_fields
 * 
 * @param array $expected_inputs Array of expected inputs with their configuration.
 * @param int   $post_id         WP_Post ID of the form.
 * @param array $data            Raw form data before validation.
 * 
 * @return array $expected_inputs Modified array of expected inputs.
 */
$expected_inputs = apply_filters( 'greyd_forms_expected_fields', $expected_inputs, $post_id, $data );

formhandler_allow_fields

Filter to allow custom fields in forms that are not part of the expected inputs.

This filter enables developers to whitelist additional form fields that should be allowed during form processing, bypassing the default field validation restrictions.

Parameters:

  • array $exceptions – Array of field names to be allowed, keyed by field name.
  • int $post_id – Post ID of the form.

Returns: array – Modified array of allowed field exceptions.

PHP
/**
 * Filter to allow custom fields in forms that are not part of the expected inputs.
 * 
 * This filter enables developers to whitelist additional form fields
 * that should be allowed during form processing, bypassing the default
 * field validation restrictions.
 * 
 * @filter formhandler_allow_fields
 * 
 * @param array $exceptions Array of field names to be allowed, keyed by field name.
 * @param int   $post_id    Post ID of the form.
 * 
 * @return array $exceptions Modified array of allowed field exceptions.
 */
$exceptions = apply_filters( 'formhandler_allow_fields', $exceptions, $post_id );

greyd_forms_required_fields

Filter to modify the list of required fields for form validation.

This filter allows developers to dynamically change which fields are mandatory for a form submission, enabling conditional required field logic based on form data or other conditions.

Parameters:

  • array $required_fields – Array of required field names.
  • int $post_id – WP_Post ID of the form.
  • array $data – Validated form data.

Returns: array – Modified array of required field names.

PHP
/**
 * Filter to modify the list of required fields for form validation.
 * 
 * This filter allows developers to dynamically change which fields
 * are mandatory for a form submission, enabling conditional required
 * field logic based on form data or other conditions.
 * 
 * @filter greyd_forms_required_fields
 * 
 * @param array $required_fields Array of required field names.
 * @param int   $post_id         WP_Post ID of the form.
 * @param array $data            Validated form data.
 * 
 * @return array $required_fields Modified array of required field names.
 */
$required_fields = apply_filters( 'greyd_forms_required_fields', $required_fields, $post_id, $data );

greyd_forms_handler_errors

Filter to modify form validation errors before they are sent to the user.

This filter allows developers to customize, add, or remove validation errors before they are displayed to the user, enabling custom error handling and messaging.

Parameters:

  • array $errors – Current form validation errors.
  • array $data – Validated form data.
  • int $post_id – WP_Post ID of the form.

Returns: array – Modified array of validation errors.

PHP
/**
 * Filter to modify form validation errors before they are sent to the user.
 * 
 * This filter allows developers to customize, add, or remove validation
 * errors before they are displayed to the user, enabling custom error
 * handling and messaging.
 * 
 * @filter greyd_forms_handler_errors
 * 
 * @param array $errors  Current form validation errors.
 * @param array $data    Validated form data.
 * @param int   $post_id WP_Post ID of the form.
 * 
 * @return array $errors Modified array of validation errors.
 */
$errors = apply_filters( 'greyd_forms_handler_errors', $errors, $data, $post_id );

greyd_forms_validated_data

Filter to modify the validated form data before it is processed further.

This filter allows developers to transform, clean, or add additional data to the validated form submission before it is saved or processed by other parts of the system.

Parameters:

  • array $data – Validated form data.
  • int $post_id – WP_Post ID of the form.

Returns: array – Modified validated form data.

PHP
/**
 * Filter to modify the validated form data before it is processed further.
 * 
 * This filter allows developers to transform, clean, or add additional
 * data to the validated form submission before it is saved or processed
 * by other parts of the system.
 * 
 * @filter greyd_forms_validated_data
 * 
 * @param array $data    Validated form data.
 * @param int   $post_id WP_Post ID of the form.
 * 
 * @return array $data Modified validated form data.
 */
$data = apply_filters( 'greyd_forms_validated_data', $data, $post_id );

greyd_forms_enable_duplicate_entries

Filter to enable or disable duplicate form submissions.

This filter allows developers to control whether users can submit the same form data multiple times, overriding the default duplicate prevention behavior.

Parameters:

  • bool $enabled – Whether duplicate entries are enabled (default: false).
  • int $post_id – WP_Post ID of the form.
  • array $data – Validated form data.
  • string $host – User IP address.
  • string $token – Generated form token.

Returns: bool – Whether duplicate entries should be allowed.

PHP
/**
 * Filter to enable or disable duplicate form submissions.
 * 
 * This filter allows developers to control whether users can
 * submit the same form data multiple times, overriding the default
 * duplicate prevention behavior.
 * 
 * @filter greyd_forms_enable_duplicate_entries
 * 
 * @param bool   $enabled Whether duplicate entries are enabled (default: false).
 * @param int    $post_id WP_Post ID of the form.
 * @param array  $data    Validated form data.
 * @param string $host    User IP address.
 * @param string $token   Generated form token.
 * 
 * @return bool $enabled Whether duplicate entries should be allowed.
 */
$enabled = apply_filters( 'greyd_forms_enable_duplicate_entries', $enabled, $post_id, $data, $host, $token );

Form input configuration filters

formhelper_modify_minlength

Filter to modify the minimum length restriction for form input fields.

This filter allows developers to customize the minimum character requirement for specific input fields, enabling dynamic validation rules based on field context or other conditions.

Parameters:

  • int $minlength – The minimum length value for the input field.
  • string $name – The name of the input field.

Returns: int – Modified minimum length value.

PHP
/**
 * Filter to modify the minimum length restriction for form input fields.
 * 
 * This filter allows developers to customize the minimum character requirement
 * for specific input fields, enabling dynamic validation rules based on field
 * context or other conditions.
 * 
 * @filter formhelper_modify_minlength
 * 
 * @param int    $minlength The minimum length value for the input field.
 * @param string $name      The name of the input field.
 * 
 * @return int $minlength Modified minimum length value.
 */
$minlength = apply_filters( 'formhelper_modify_minlength', $minlength, $name );

greyd_forms_input_maxlength_{block_name}

Filter to modify the maximum length for a specific input field type.

This filter allows developers to customize the maximum character limit for specific input field types (e.g., text, email, etc.), enabling field-type-specific validation rules.

Parameters:

  • int $maxlength – The maximum length value for the input field.

Returns: int – Modified maximum length value.

PHP
/**
 * Filter to modify the maximum length for a specific input field type.
 * 
 * This filter allows developers to customize the maximum character limit
 * for specific input field types (e.g., text, email, etc.), enabling
 * field-type-specific validation rules.
 * 
 * @filter greyd_forms_input_maxlength_{block_name}
 * 
 * @param int $maxlength The maximum length value for the input field.
 * 
 * @return int $maxlength Modified maximum length value.
 */
$maxlength = apply_filters( 'greyd_forms_input_maxlength_' . $block_name, $maxlength );

greyd_forms_input_maxlength_all

Filter to modify the maximum length for all input fields globally.

This filter allows developers to customize the maximum character limit for all input fields across the entire form, providing a global override for length validation.

Parameters:

  • int $maxlength – The maximum length value for all input fields.

Returns: int – Modified maximum length value.

PHP
/**
 * Filter to modify the maximum length for all input fields globally.
 * 
 * This filter allows developers to customize the maximum character limit
 * for all input fields across the entire form, providing a global override
 * for length validation.
 * 
 * @filter greyd_forms_input_maxlength_all
 * 
 * @param int $maxlength The maximum length value for all input fields.
 * 
 * @return int $maxlength Modified maximum length value.
 */
$maxlength = apply_filters( 'greyd_forms_input_maxlength_all', $maxlength );

greyd_forms_get_all_inputs

Filter to modify the complete array of form inputs before returning.

This filter allows developers to customize, add, or remove input field configurations after they have been processed, enabling dynamic form field management and customization.

Parameters:

  • array $inputs – Array of processed input field configurations.
  • string $post_content – The form’s post content.

Returns: array – Modified array of input field configurations.

PHP
/**
 * Filter to modify the complete array of form inputs before returning.
 * 
 * This filter allows developers to customize, add, or remove input
 * field configurations after they have been processed, enabling
 * dynamic form field management and customization.
 * 
 * @filter greyd_forms_get_all_inputs
 * 
 * @param array  $inputs       Array of processed input field configurations.
 * @param string $post_content The form's post content.
 * 
 * @return array $inputs Modified array of input field configurations.
 */
$inputs = apply_filters( 'greyd_forms_get_all_inputs', $inputs, $post_content );

Form rendering filters

formshortcode_add_hidden_fields

Filter to add hidden fields to the form before rendering.

This filter allows developers to dynamically add hidden input fields to forms, enabling the inclusion of additional data like user IDs, session tokens, or other contextual information.

Parameters:

  • array $hidden_fields – Array of hidden field data, keyed by field name.
  • int $post_id – WP_Post ID of the form.

Returns: array – Modified array of hidden field data.

PHP
/**
 * Filter to add hidden fields to the form before rendering.
 * 
 * This filter allows developers to dynamically add hidden input fields
 * to forms, enabling the inclusion of additional data like user IDs,
 * session tokens, or other contextual information.
 * 
 * @filter formshortcode_add_hidden_fields
 * 
 * @param array $hidden_fields Array of hidden field data, keyed by field name.
 * @param int   $post_id       WP_Post ID of the form.
 * 
 * @return array $hidden_fields Modified array of hidden field data.
 */
$hidden_fields = apply_filters( 'formshortcode_add_hidden_fields', $hidden_fields, $post_id );

greyd_forms_css_classes

Filter to modify the CSS classes applied to the form wrapper.

This filter allows developers to customize the CSS classes that are applied to the form element, enabling custom styling and layout modifications based on form content or other conditions.

Parameters:

  • array $classes – Array of CSS classes with their values.
  • string $post_content – The form’s post content.
  • int $post_id – WP_Post ID of the form.

Returns: array – Modified array of CSS classes.

PHP
/**
 * Filter to modify the CSS classes applied to the form wrapper.
 * 
 * This filter allows developers to customize the CSS classes
 * that are applied to the form element, enabling custom styling
 * and layout modifications based on form content or other conditions.
 * 
 * @filter greyd_forms_css_classes
 * 
 * @param array  $classes      Array of CSS classes with their values.
 * @param string $post_content The form's post content.
 * @param int    $post_id      WP_Post ID of the form.
 * 
 * @return array $classes Modified array of CSS classes.
 */
$classes = apply_filters( 'greyd_forms_css_classes', $classes, $post_content, $post_id );

greyd_forms_raw_content

Filter to modify the raw form content before it is processed and rendered.

This filter allows developers to customize the form content before it is processed by the block renderer, enabling content modifications or preprocessing based on specific requirements.

Parameters:

  • string $post_content – The raw post content of the form.
  • object $post – WP_Post object of the form.

Returns: string – Modified raw post content.

PHP
/**
 * Filter to modify the raw form content before it is processed and rendered.
 * 
 * This filter allows developers to customize the form content before it is
 * processed by the block renderer, enabling content modifications or
 * preprocessing based on specific requirements.
 * 
 * @filter formblocks_raw_content
 * 
 * @param string $post_content The raw post content of the form.
 * @param object $post         WP_Post object of the form.
 * 
 * @return string $post_content Modified raw post content.
 */
$post_content = apply_filters( 'formblocks_raw_content', $post_content, $post );

greyd_forms_hidden_field_value

Filter to modify the value of hidden form fields before rendering.

This filter allows developers to customize the value of hidden form fields, enabling dynamic value generation based on field attributes, user context, or other conditions.

Parameters:

  • string $value – The value of the hidden field.
  • string $name – The name of the hidden field.
  • array $attrs – The attributes of the hidden field.

Returns: string – The filtered value of the hidden field.

PHP
/**
 * Filter to modify the value of hidden form fields before rendering.
 * 
 * This filter allows developers to customize the value of hidden form fields,
 * enabling dynamic value generation based on field attributes, user context,
 * or other conditions.
 * 
 * @filter greyd_forms_hidden_field_value
 * 
 * @param string $value The value of the hidden field.
 * @param string $name  The name of the hidden field.
 * @param array  $attrs The attributes of the hidden field.
 * 
 * @return string $value The filtered value of the hidden field.
 */
$value = apply_filters( 'greyd_forms_hidden_field_value', $value, $name, $attrs );

greyd_forms_hidden_field_value_{name}

Filter to modify the value of a specific hidden form field by name.

This filter allows developers to customize the value of a specific hidden form field identified by its name, enabling targeted value modifications for individual fields.

Parameters:

  • string $value – The value of the hidden field.
  • array $attrs – The attributes of the hidden field.

Returns: string – The filtered value of the hidden field.

PHP
/**
 * Filter to modify the value of a specific hidden form field by name.
 * 
 * This filter allows developers to customize the value of a specific hidden
 * form field identified by its name, enabling targeted value modifications
 * for individual fields.
 * 
 * @filter greyd_forms_hidden_field_value_{name}
 * 
 * @param string $value The value of the hidden field.
 * @param array  $attrs The attributes of the hidden field.
 * 
 * @return string $value The filtered value of the hidden field.
 */
$value = apply_filters( 'greyd_forms_hidden_field_value_' . $name, $value, $attrs );

Post and language filters

greyd_filter_post_id

Filter to modify the post ID after language-specific filtering.

This filter allows developers to customize the final post ID after WPML and Polylang translations have been processed, enabling additional post ID modifications or custom logic.

Parameters:

  • int $post_id – The post ID after language processing.
  • string $post_type – The post type being filtered.

Returns: int – Modified post ID.

PHP
/**
 * Filter to modify the post ID after language-specific filtering.
 * 
 * This filter allows developers to customize the final post ID after WPML
 * and Polylang translations have been processed, enabling additional post
 * ID modifications or custom logic.
 * 
 * @filter greyd_filter_post_id
 * 
 * @param int    $post_id   The post ID after language processing.
 * @param string $post_type The post type being filtered.
 * 
 * @return int $post_id Modified post ID.
 */
$post_id = apply_filters( 'greyd_filter_post_id', $post_id, $post_type );

Data processing filters

greyd_forms_filter_data_tag_value

Filter to modify form field values before they are used in data tag replacement.

This filter allows developers to customize, format, or transform individual form field values before they are inserted into mail content, success messages, or other content areas.

Parameters:

  • string $val – The field value to be filtered.
  • string $key – The field name/key (e.g., ‘user_email’ for [user_email] tag).
  • string $subject – The content being modified (usually mail content).
  • int $post_id – WP_Post ID of the form.

Returns: string – Modified field value.

PHP
/**
 * Filter to modify form field values before they are used in data tag replacement.
 * 
 * This filter allows developers to customize, format, or transform individual
 * form field values before they are inserted into mail content, success
 * messages, or other content areas.
 * 
 * @filter greyd_forms_filter_data_tag_value
 * 
 * @param string $val     The field value to be filtered.
 * @param string $key     The field name/key (e.g., 'user_email' for [user_email] tag).
 * @param string $subject The content being modified (usually mail content).
 * @param int    $post_id WP_Post ID of the form.
 * 
 * @return string $val Modified field value.
 */
$val = apply_filters( 'greyd_forms_filter_data_tag_value', $val, $key, $subject, $post_id );

Bot detection filters

greyd_forms_is_bot

Filter to modify the bot detection result for the current user agent.

This filter allows developers to customize the bot detection logic, enabling custom bot identification rules or overriding the default detection behavior based on specific requirements.

Parameters:

  • bool $is_bot – Whether the current user agent is detected as a bot.
  • string $user_agent – The user agent string being analyzed.

Returns: bool – Modified bot detection result.

PHP
/**
 * Filter to modify the bot detection result for the current user agent.
 * 
 * This filter allows developers to customize the bot detection logic,
 * enabling custom bot identification rules or overriding the default
 * detection behavior based on specific requirements.
 * 
 * @filter greyd_forms_is_bot
 * 
 * @param bool   $is_bot     Whether the current user agent is detected as a bot.
 * @param string $user_agent The user agent string being analyzed.
 * 
 * @return bool $is_bot Modified bot detection result.
 */
$is_bot = apply_filters( 'greyd_forms_is_bot', $is_bot, $user_agent );

Deprecated filter names

The following filter names have been deprecated in favor of the unified greyd_forms_ prefix but are still supported for backward compatibility:

  • formhandler_allow_fieldsgreyd_forms_allow_fields
  • formhelper_modify_minlengthgreyd_forms_modify_minlength
  • formshortcode_add_hidden_fieldsgreyd_forms_add_hidden_fields
  • formblocks_raw_contentgreyd_forms_raw_content

Note: While these deprecated filters will continue to work, it’s recommended to use the new unified filter names for new development.