Using Gravity Forms ‘gform_post_form_deactivated’ PHP action

The gform_post_form_deactivated is an action in Gravity Forms that gets triggered once an active form is set as inactive. This opens an opportunity to execute additional actions.

Usage

Here’s a basic example of how you can use the gform_post_form_deactivated action:

add_action( 'gform_post_form_deactivated', 'my_custom_deactivation_function', 10, 1 );

function my_custom_deactivation_function( $form_id ) {
  // your custom code here
  return $form_id;
}

Parameters

  • $form_id (int): The ID of the form that is being switched to inactive.

More Information

See Gravity Forms Docs: gform_post_form_deactivated
This action hook is found in the forms_model.php file.

Examples

Logging Form Deactivation

This code logs a message every time a form is deactivated.

add_action( 'gform_post_form_deactivated', 'log_form_deactivation', 10, 1 );

function log_form_deactivation( $form_id ) {
  error_log("Form with ID: {$form_id} has been deactivated");
}

Send Email Notification

This code sends an email notification when a form is deactivated.

add_action( 'gform_post_form_deactivated', 'email_notify_form_deactivation', 10, 1 );

function email_notify_form_deactivation( $form_id ) {
  wp_mail('[email protected]', 'Form Deactivated', "Form with ID: {$form_id} has been deactivated");
}

Update Post Status

This code updates the associated post’s status to ‘draft’ when a form is deactivated.

add_action( 'gform_post_form_deactivated', 'update_post_status_on_deactivation', 10, 1 );

function update_post_status_on_deactivation( $form_id ) {
  // Assuming the form ID is the same as the Post ID
  wp_update_post(array(
    'ID'    =>  $form_id,
    'post_status'   =>  'draft'
  ));
}

Deleting Transient on Deactivation

This code deletes a transient related to the form when it’s deactivated.

add_action( 'gform_post_form_deactivated', 'delete_form_transient', 10, 1 );

function delete_form_transient( $form_id ) {
  delete_transient( "form_{$form_id}_data" );
}

This code removes options related to the deactivated form.

add_action( 'gform_post_form_deactivated', 'remove_form_options', 10, 1 );

function remove_form_options( $form_id ) {
  delete_option( "form_{$form_id}_settings" );
}