Using Gravity Forms ‘gform_post_form_restored’ PHP action

The gform_post_form_restored Gravity Forms action is triggered after a form is restored from the trash, allowing you to perform additional actions.

Usage

add_action('gform_post_form_restored', 'my_function', 10);

Parameters

  • $form_id (int): The ID of the form being restored.

More information

See Gravity Forms Docs: gform_post_form_restored

This action hook is located in forms_model.php.

Examples

Send an email notification when a form is restored

Notify the admin by email when a form is restored from the trash.

add_action('gform_post_form_restored', 'send_email_on_form_restored', 10);

function send_email_on_form_restored($form_id) {
    // Email recipient
    $to = '[email protected]';

    // Email subject
    $subject = 'Form Restored';

    // Email body
    $message = "Form with ID {$form_id} has been restored from the trash.";

    // Send the email
    wp_mail($to, $subject, $message);
}

Add a log entry when a form is restored

Log a message to a custom log file when a form is restored.

add_action('gform_post_form_restored', 'log_form_restored', 10);

function log_form_restored($form_id) {
    // Log file path
    $log_file = WP_CONTENT_DIR . '/my_custom_logs/form_restored.log';

    // Log message
    $message = "Form with ID {$form_id} has been restored at " . date('Y-m-d H:i:s') . "\n";

    // Append the message to the log file
    file_put_contents($log_file, $message, FILE_APPEND);
}

Update form settings after form restoration

Update the form settings when a form is restored from the trash.

add_action('gform_post_form_restored', 'update_form_settings_on_restore', 10);

function update_form_settings_on_restore($form_id) {
    // Get the form object
    $form = GFAPI::get_form($form_id);

    // Update form settings
    $form['isTrashed'] = false;

    // Save the updated form
    GFAPI::update_form($form);
}

Add a post when a form is restored

Create a post in WordPress when a form is restored from the trash.

add_action('gform_post_form_restored', 'add_post_on_form_restored', 10);

function add_post_on_form_restored($form_id) {
    // Post data
    $post_data = array(
        'post_title'   => 'Form Restored: ' . $form_id,
        'post_content' => 'A form with ID ' . $form_id . ' has been restored.',
        'post_status'  => 'publish',
        'post_type'    => 'post',
    );

    // Insert the post
    wp_insert_post($post_data);
}