The gform_uninstalling action hook allows you to perform clean-up tasks when the uninstall button is clicked on the Forms > Settings > Uninstall page.
Usage
To use this action hook, add the following code:
add_action('gform_uninstalling', 'your_function_name');
Parameters
This hook has no parameters.
More information
See Gravity Forms Docs: gform_uninstalling
This action hook was added in Gravity Forms v2.6.9. The source code is located in GFSettings::settings_uninstall_page() in settings.php.
Examples
Delete an option on uninstall
This example demonstrates how to delete custom options from the wp_options table when Gravity Forms is uninstalled.
add_action('gform_uninstalling', function() {
delete_option('your_option_name');
});
Place this code in the functions.php file of the active theme, a custom functions plugin, or a custom add-on. For more information on code placement, see Where Do I Put This Code?
Remove custom table on uninstall
This example shows how to remove a custom table from the database when Gravity Forms is uninstalled.
function remove_custom_table() {
global $wpdb;
$table_name = $wpdb->prefix . 'your_custom_table';
$wpdb->query("DROP TABLE IF EXISTS {$table_name}");
}
add_action('gform_uninstalling', 'remove_custom_table');
Remove custom post type data on uninstall
This example demonstrates how to remove all posts with a specific custom post type when Gravity Forms is uninstalled.
function remove_custom_post_type_data() {
$post_type = 'your_custom_post_type';
$posts = get_posts(array('post_type' => $post_type, 'numberposts' => -1));
foreach ($posts as $post) {
wp_delete_post($post->ID, true);
}
}
add_action('gform_uninstalling', 'remove_custom_post_type_data');
Delete custom user meta on uninstall
This example shows how to delete a specific custom user meta for all users when Gravity Forms is uninstalled.
function delete_custom_user_meta() {
$meta_key = 'your_custom_user_meta_key';
$users = get_users();
foreach ($users as $user) {
delete_user_meta($user->ID, $meta_key);
}
}
add_action('gform_uninstalling', 'delete_custom_user_meta');
Remove custom taxonomy terms on uninstall
This example demonstrates how to remove all terms from a specific custom taxonomy when Gravity Forms is uninstalled.
function remove_custom_taxonomy_terms() {
$taxonomy = 'your_custom_taxonomy';
$terms = get_terms(array('taxonomy' => $taxonomy, 'hide_empty' => false));
foreach ($terms as $term) {
wp_delete_term($term->term_id, $taxonomy);
}
}
add_action('gform_uninstalling', 'remove_custom_taxonomy_terms');