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:
- Unable to show a message after plugin activation
- How to display archive by selecting year and then selecting month
- Plugins and how to assign urls to content
- Unable to link CSS file
- Upload images to custom database table in admin backend
- redux framework: add custom css to the output css
- How to get an array out of a nav menu if it’s a plugin?
- Ajax call not working with
- How to CRUD from wordpress database in wordpress theme?
- Ajax functionality not being called under wordpress plugin
- Define a url for an email confirmation from within a plugin
- Is there better way to do this without duplicating queries?
- WordPress Search Form with Keyword Suggestion
- How to create a simple plugin which show/hide an html code in wordpress?
- plugin modal/popup integration best practice
- How can I query 3 posts from diferente categories (one of each category)
- Problem with baseurl and interaction with plugin
- Which filter to use to pre-parse form elements, which are generated by plugin’s shortcode?
- Why setcookie function redirecting to home page in wordpress?
- How to Disable Content Warning Dialog for Logged in users
- Widget won’t be activated
- Remove from a div by class name from post page if post author role is not administrator
- Pull commentdata for pre_comment_on_post from comment_post_ID
- Upgrade routine: Interaction with user confirmation
- How to display properly exception or echo string after posting in plugin?
- Function not working on any file other than the main plugin file
- Pluigin Migration – I need to move a single plugin to a different website
- Building WordPress Themes With Bootstrap with Adi Purdila → TutsPlus
- Load textdomain from global languages directory
- Woocommerce Custom Checkout
- Allow user to change homepage
- Dynamic sidebar areas not working on the Theme Customizer
- Login using /wp-admin doesn’t redirect back to /wp-admin
- Convert each new line in the textfield as a new value in an array
- sql query not working in wp plugin
- Navigate to external link if last page or post in a category
- Custom signature appears twice on page
- $wpdb Mysql trigger problem
- Query only title/field/featured media of posts [closed]
- wp_enqueue_style don’t register all google fonts
- Displaying settings information in a table
- API WordPress is Limited? Return False
- Caption Shortcode: what filter to change the image size?
- How to return a blank page
- Looping single post in a theme
- WP API users per page
- Array/List Edit in Backend
- WP Ajax on page load not working on bluehost but was working on Godaddy
- How to Modify My Plugin’s Admin Settings so that the Plugin can be Added to a Specific Page?
- Plugin options page: grouping checkboxes
- Confusing $tag specification for apply_filters call, in core options.php code
- Callback function quicktags that uses variable in start tag
- Fullwidth slider using background image Flexslider WordPress
- Font Awesome stopped showing icons, shows &# text instead [closed]
- How does one set cookies in WordPress without getting the ‘headers not sent’ error? within WP
- Delete Query executing regardless of WHERE Clause condition
- Return value of $wpdb->update() query in plugin is wrong
- WordPress Plugin Tool Tip Helpers
- Page template compatibility with different themes
- Does WordPress have something like timer hook?
- How can I add the Post ID to Class Name in Jquery?
- How to show metabox just in post.php in admin?
- Same header/footer in Admin, across all network sites in multisite
- How to change the wording of front-end `next article` for custom type registered in a plug-in?
- Get (eventual) permalink from post within Edit Post in Admin panel
- Ajax not working to insert, query and result data
- Hook for plugin to show content for certain urls
- wordpress plugin require_once file – can’t user wordpress functions
- WordPress Plugin: OSCommerce images not displaying in front end
- Change Page title when Pagingation the posts
- Acessing WP functions in form submission handler
- Object Oriented plugin, add action and variables
- Custom MySQL query to pull out Advanced Custom Fields?
- I can’t write in my DB using $wpdb->insert
- How put the correct URL to sub-menu plugin?
- Why does unzip_file always return true but nothing happens?
- Why user is added back in database after deletion?
- Multi hook deploiement
- Use plupload to upload images and save them to custom folder and database table
- Why Worpdress doesn’t create table in database?
- Form and database, plugin development
- Custom Post Type and Functions
- Adding admin for specific users
- What is more secure checking capabilities of user or checking role of user in WordPress plugin development
- Developing a plugin where users can edit entries saved in database
- Deactivate Other Incompatible Plugin Upon Activation
- WordPress custom plugin developement
- How to create session for user which is not an admin user
- What should I use instead of get_blog_option?
- Any way to make Apache’s internal redirect work?
- New Users are saved with no role selected
- get_option() is undefined in TinymceWindowManager
- How to filter get_adjacent_post()?
- Getting duplicate page when activating my plugin
- Plugin outputs content of posts unbidden!
- Should all roles be allowed CRUD operation on the database?
- Associating special meaning with user id 0
- Filter get_user_by instead of replace function
- Action Links in Class located in Subdirectory of Plugin
- Enqueue script not working