In WP you have 2 solutions for code to be excecuted during your plugin uninstall process.
First solution
In your plugin’s root folder, create the file uninstall.php
. This file will be loaded automatically by WP during uninstall process. Still, to prevent direct access, you need to make sure we’re in the uninstall process for example by checking the WP_UNINSTALL_PLUGIN
global.
// If uninstall.php is not called by WordPress, die
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
die;
}
delete_folders();
// ...
Second solution
In your main plugin file, use register_uninstall_hook
.
register_uninstall_hook( __FILE__, 'plugin_uninstall' );
function plugin_uninstall() {
delete_folders();
// ...
}
Related Posts:
- dbDelta not creating tables
- Default table collation on plugin activation?
- How to implement color picker from wordpress in my plugin?
- Nonces can be reused multiple times? Bug / Security issue?
- the_content after all shortcodes are parsed
- How to auto-upgrade my plugin?
- How do I resolve Notice: Undefined offset: 0 in /wp-includes/capabilities.php on line 1145
- Category listing with thumbnail and description on home page
- How to Add a .js file Only in one specific Page Dynamically to Head
- URLs of plugin resources?
- anything like add_meta_box for categories?
- Missing “category_children” option when dynamically creating categories via a plugin
- How to include class from addon after to be sure one class exists in the main plugin?
- Developing a plug-in to charge for
- WordPress: After Gutenberg plugin migration to block.json the localization/ translations with PolyGlot in JavaScript does not work anymore
- What is the Difference between directly call a function and call a function using add_action?
- What is better way to use Bootstrap inside admin panel?
- Looking for callback function after Gutenberg is rendered?
- Updating my plugin without releasing a new version
- Is it possible to check is loaded language files correctly with WordPress plugin?
- 404 errors after plugin options update and category base change
- How to determine, from plugin script, if active theme has The Post Title
- Widget Admin – Form Submit Event?
- add_filter : Passing an array instead of the callback function?
- WordPress security issue to output data from user input from theme option form
- Advice on plugin structure
- Using wp_parse_args to set up Plugin Default Settings
- how to add Jquery script to one page?
- how do you prevent showing a particular category on the admin dashboard for specific user roles?
- Problem with parameters in url and pagination
- get_posts() not working when accessing with a custom user role
- Is there no admin ui guide for 4.x?
- Where can i find wordpress auto update code flows?
- Are there any scripts, classes, and/or functions built-in to WP for a plugin to export/import its saved data from wp_options?
- Do I have to worry about useState causing a re-render?
- WordPress form action – doesn’t work
- How to fetch only current hour posts?
- Plugin sub-menu pages recommended structure and links
- Widget Dropdown doesn’t working
- template_redirect or admin-ajax.php?
- mysql_real_escape_string() vs. esc_sql() in WordPress
- how to get all the child category name in a specified category name?
- Widget HTML Display Problem
- Display list of uploaded images, filtered by user under a specific user group
- Bug: Post needs to be updated twice when adding action for save_post hook
- Which is the better way to store images for the plugin?
- Readme.txt seems to be cached but not the version
- Issue on Checkbox with Custom Option Page
- Minimum Widget Width for Plugin Development
- Encoding Method for URLs?
- Store custom meta box data as serialized array
- Should I use wp-content/cache or [PLUGIN_DIR]/cache?
- configuration of .htaccess for add_rewrite_rule to make sense
- Restrict certain actions to plugin-specific admin menu pages only
- How to get post meta in functions?
- AJAX request not routing through proxy
- Adding tables to dashboard pages programmatically?
- Plugin access to average users not only admin
- how to add custom fields into new & update post page?
- List all user post API endpoint
- Rewrite not working since upgrade to 5.9
- Why won’t this submenu page show? – My First WordPress Plugin
- Condition to check previous next article post title
- How to display plugin with javascript using markup of the theme?
- Can display plugin without shortcode?
- Multiple dynamic Tax Query – pass taxonomy argument from array
- ACF Field value in wordpress login message filter
- ajax stopped working when not logged in wordpress
- Hook for validating and rejecting frontend image upload
- Overriding the template files using a plugin for all themes
- Plugin removes itself if mistake made during edit
- Using meta_key & meta_value in add_rewrite_rule
- Multisite and the JSON REST API: How to?
- Can’t create a blank template
- Custom Registration Form and Passwords
- Determine if the current page, is being edited
- Looping single post in a theme
- WP Ajax on page load not working on bluehost but was working on Godaddy
- Fullwidth slider using background image Flexslider WordPress
- Return value of $wpdb->update() query in plugin is wrong
- Is there a way to tell if a shorcode’s handler is being run before or after the content formatting filter?
- Plugin files not updated (cache cleared)
- How to limit the number of posts a user can view based on status
- How to create an embedded code for wordpress shortcode?
- How can I send an id over the url?
- Creating custom Insert Media page
- Get fields of a widget
- How to add additional field in a table row after creating a table?
- WordPress plugin tables become corrupt
- How to call a new php page inside a plugin page?
- How can i call from custom fields to the category editor?
- How do you filter get_media_items by mime type in a custom media upload tab?
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- If I want to create new taxonomies (e.g. Project / Documents / Etc…) is it better to create them in the theme’s functions.php or within a plugin? [duplicate]
- Trying to build a plugin – Cannot modify header information
- How will i add an option under customizer the event calendar section?
- Return custom product in ajax call loop
- Is using upgrader_process_complete the correct way to perform plugin updates?
- Load images from CDN and custom features to “Add Media” dialogue
- Saving metabox updates causing fatal error