Using Gravity Forms ‘gform_disable_post_creation’ is a filter’ PHP action

The gform_disable_post_creation filter allows you to disable post creation when submitting a Gravity Form.

Note: This filter is intended for use with Gravity Forms built-in Post creation feature, it doesn’t support the Advanced Post Creation add-on.

Usage

add_filter('gform_disable_post_creation', 'disable_post_creation', 10, 3);

To specify this per form, add the form id after the hook name:

add_filter('gform_disable_post_creation_6', 'disable_post_creation', 10, 3);

Parameters

  • $is_disabled (bool): Variable to be filtered. Set it to true to prevent posts from being created.
  • $form (Form Object): Current form.
  • $entry (Entry Object): Current Entry array.

More information

See Gravity Forms Docs: gform_disable_post_creation

Examples

Disable for all forms

This example disables the post creation process for all forms:

add_filter('gform_disable_post_creation', 'disable_post_creation', 10, 3);

function disable_post_creation($is_disabled, $form, $entry) {
    return true;
}

Disable based on a field value

add_filter('gform_disable_post_creation_6', 'disable_post_creation', 10, 3);

function disable_post_creation($is_disabled, $form, $entry) {
    $is_disabled = rgar($entry, '2') != 'something' ? true : $is_disabled;
    return $is_disabled;
}

Disable post creation for specific forms

This example disables the post creation process for form with ID 6 and 8:

add_filter('gform_disable_post_creation', 'disable_post_creation_for_specific_forms', 10, 3);

function disable_post_creation_for_specific_forms($is_disabled, $form, $entry) {
    if (in_array($form['id'], array(6, 8))) {
        return true;
    }
    return $is_disabled;
}

Disable post creation based on user role

This example disables the post creation process for users with the “subscriber” role:

add_filter('gform_disable_post_creation', 'disable_post_creation_for_subscribers', 10, 3);

function disable_post_creation_for_subscribers($is_disabled, $form, $entry) {
    $user = wp_get_current_user();
    if (in_array('subscriber', $user->roles)) {
        return true;
    }
    return $is_disabled;
}

Disable post creation for specific forms and field values

This example disables the post creation process for form with ID 6 when the value of field 2 is ‘disable’:

add_filter('gform_disable_post_creation_6', 'disable_post_creation_for_specific_field_value', 10, 3);

function disable_post_creation_for_specific_field_value($is_disabled, $form, $entry) {
    if (rgar($entry, '2') == 'disable') {
        return true;
    }
    return $is_disabled;
}