The gform_post_form_views_deleted action is triggered when a form view count has been reset to zero, allowing further actions to be performed.
Usage
add_action('gform_post_form_views_deleted', 'my_function', 10, 1);
Parameters
- $form_id (int): The ID of the form that the view count is being reset on.
More information
See Gravity Forms Docs: gform_post_form_views_deleted
This action hook is located in forms_model.php.
Examples
Send an email notification when form views are reset
This example sends an email to the admin when a form view count is reset to zero.
add_action('gform_post_form_views_deleted', 'send_email_notification', 10, 1);
function send_email_notification($form_id) {
// Define the email subject and message
$subject = "Form Views Reset";
$message = "The view count for form ID {$form_id} has been reset to zero.";
// Send an email to the admin
wp_mail(get_option('admin_email'), $subject, $message);
}
Log the form view reset event
This example logs the form view reset event with the current timestamp.
add_action('gform_post_form_views_deleted', 'log_form_view_reset', 10, 1);
function log_form_view_reset($form_id) {
// Get the current timestamp
$timestamp = current_time('mysql');
// Log the form view reset event
error_log("Form ID {$form_id} views were reset at {$timestamp}");
}
Update a custom meta field when form views are reset
This example updates a custom meta field named ‘form_views_reset_count’ for a form when its view count is reset to zero.
add_action('gform_post_form_views_deleted', 'update_form_views_reset_count', 10, 1);
function update_form_views_reset_count($form_id) {
// Get the current form views reset count
$reset_count = get_post_meta($form_id, 'form_views_reset_count', true);
// Increment the reset count
$reset_count++;
// Update the form views reset count
update_post_meta($form_id, 'form_views_reset_count', $reset_count);
}
Trigger an action in third-party service
This example triggers an action in a third-party service when a form view count is reset to zero.
add_action('gform_post_form_views_deleted', 'trigger_third_party_action', 10, 1);
function trigger_third_party_action($form_id) {
// Your custom code to trigger an action in third-party service
}
Display a custom message when form views are reset
This example displays a custom message on the dashboard when a form view count is reset to zero.
add_action('gform_post_form_views_deleted', 'display_custom_message', 10, 1);
function display_custom_message($form_id) {
// Set a custom message to be displayed on the dashboard
$message = "The view count for form ID {$form_id} has been reset to zero.";
// Display the custom message
set_transient('custom_dashboard_message', $message, 60);
}