The gform_pre_notification_deactivated Gravity Forms action is triggered before a notification is deactivated, allowing further actions to be performed.
Usage
add_action('gform_pre_notification_deactivated', 'my_function', 10, 2);
Parameters
- $notification_id (int): The ID of the notification being deactivated.
- $form (array): The form object.
More information
See Gravity Forms Docs: gform_pre_notification_deactivated
This action hook is located in forms_model.php
.
Examples
Log notification deactivation
Log the deactivation of a notification to a custom log file.
function log_notification_deactivation($notification_id, $form) { // Log the notification deactivation error_log("Notification ID {$notification_id} deactivated for form ID {$form['id']}"); } add_action('gform_pre_notification_deactivated', 'log_notification_deactivation', 10, 2);
Send email when notification is deactivated
Send an email to the admin when a notification is deactivated.
function email_admin_on_deactivation($notification_id, $form) { // Send an email to the admin wp_mail(get_option('admin_email'), 'Notification Deactivated', "Notification ID {$notification_id} deactivated for form ID {$form['id']}"); } add_action('gform_pre_notification_deactivated', 'email_admin_on_deactivation', 10, 2);
Prevent notification deactivation for specific form
Prevent the deactivation of notifications for a specific form.
function prevent_deactivation($notification_id, $form) { if ($form['id'] == 5) { wp_die('Deactivation of notifications for form ID 5 is not allowed.'); } } add_action('gform_pre_notification_deactivated', 'prevent_deactivation', 10, 2);
Update notification settings before deactivation
Update the notification settings before deactivation.
function update_notification_settings($notification_id, $form) { // Your custom code to update notification settings } add_action('gform_pre_notification_deactivated', 'update_notification_settings', 10, 2);
Track notification deactivations
Store the number of times a notification has been deactivated.
function track_notification_deactivations($notification_id, $form) { $count_key = "deactivation_count_{$notification_id}"; $count = get_option($count_key, 0); update_option($count_key, ++$count); } add_action('gform_pre_notification_deactivated', 'track_notification_deactivations', 10, 2);
field’, 10, 2 );
function update_custom_field( $notification_id, $form_id ) {
$value = ‘deactivated’;
update_post_meta( $form_id, ‘notification_status’, $value );
}</code></pre>
<h3>Example 5: Disable a WordPress Plugin</h3>
<p>If you want to disable a WordPress plugin after a notification is deactivated, you can use the "gform_pre_notification_deactivated" action to perform the deactivation.</p>
<pre><code class=”language-php”>add_action( ‘gform_pre_notification_deactivated’, ‘disable_plugin’, 10, 2 );
function disable_plugin( $notification_id, $form_id ) {
deactivate_plugins( ‘my-plugin/my-plugin.php’ );
}</code></pre>
<h2>Conclusion</h2>
<p>The "gform_pre_notification_deactivated" action in Gravity Forms can be very useful if you need to perform any tasks before a notification is deleted. With the five practical examples provided in this guide, you should have a good understanding of how to use this action in your own WordPress sites.</p>