WordPress has a function called register_deactivation_hook which registers a plugin function to be run when the plugin is deactivated, so:
register_deactivation_hook( __FILE__, 'myplugin_deactivate' );
function myplugin_deactivate(){
//delete plugins option here ex:
delete_option('pa_options');
}
Update:
Like One Trick Pony mentioned, sometimes users deactivate plugins and when they reactivate it they will loose all settings if you use this method.
So a better one would be to create an uninstall option in your plugin’s admin panel and submitted, only then you should remove the options from the database and deactivate the plugin using deactivate_plugins( '/plugin-folder/plugin-name.php' );
Related Posts:
- Registering Class methods as hook callbacks
- When does WordPress.org notify sites of new version?
- wordpress get meta value by meta key
- Updating WordPress – the best approach (updating wp core, plugins and db)
- Code markup plugin like the .wordpress.com blogs offer?
- Set active theme via URL
- WooCommerce Always Include Shipping Information in Checkout [closed]
- Bad Request (Invalid Hostname) on working server, database problem
- Plugin Not Working, But Only On GoDaddy Hosted site
- Long running action from plugin
- How to get the current plugin name?
- Errors while using ajax from external wordpress page
- List of plugin updates in admin bar
- Peer Review Plugin for Posts? [closed]
- Server side validation for Contact Form 7 [closed]
- Bulk Image Uploader to create new post from each image [closed]
- How can I implement a notification system in wordpress?
- Internationalization: Not loading plugin translated text
- Building an email signup form. Where should the information be saved in the DB?
- Self deactivate plugins after an action occurs
- How to check if you are on widget.php page?
- How to get current post user id
- Plugin. Html code in Template
- wp_redirect() not working in Insert PHP plugin in WordPress
- Layout Plugin Admin Pages: Use BootStrap? [closed]
- Good rating plugin that doesn’t depend on an external service?
- switched from query_posts to WP_query, not working now?
- Rotate Widgets or Content Blocks every x sec/min
- Problem with creating tables for Plugin
- Matching Chapters to a Custom posts [closed]
- Replacing a plugin function with a custom renamed function doesn’t work
- Is there a standard way to listen for an on change event of a posts featured image
- Homemade plugin while using Themify Ultra
- How to deal with WordPress and Pocket API to automate content curation on my hosted wordpress blog? [closed]
- Product queue for my subscription box
- Updating plugins asks for FTP information, why? (this is a new one)
- Create Gallery using Custom Post Type and add sum gallery as sub gallery of Main Gallery
- Add custom text color WordPress 3.9 TinyMCE 4 Visual editor
- ACF: post query, hide duplicate values [closed]
- WordPress Jquery UI Spinner
- How to customize a plugin?
- When taxes are country specific they don’t show in the cart totals
- How to replace website?
- changes to header.php not appearing
- List out all the plugins on WordPress instance
- Proper way to use plugin functions in functions.php
- Can WordPress Drop-ins be given their own directory?
- How do I make reusable content blocks for header and footer when using WordPress headless with another front-end?
- How can I add IP address to my post?
- Remove Pagination for Product Category Pages WooCommerce
- Is there a plugin or a way in the wordpress that would let us have different versions of a post or page accessibe to users?
- Adding a simple Javascript file with a plugin
- How to add/change (woocommerce) product tab icon
- Get post content from outside the loop with plugin shortcode usability
- Adding option values as an array using a multi selectable select box
- How to set the default value as the saved value once a form of widget is saved?
- Custom post type change excerpt more and excerpt length
- Example for use tinymce in wordpress 3.5.1?
- Dynamic Image Replacement through call rail phone call tracking plugins in wordpress
- Advanced custom fields and Slideshow gallery desn’t work together? [closed]
- How can I show registration form inside modal?
- Replace video url with video player
- How could I fix the lowercase problem in nextgen gallery? [closed]
- Need to edit author permissions | custom taxonomy
- Custom Logo Link WordPress
- Where do I put the code snippets I found here or somewhere else on the web?
- WP Import All Multiple Dynamic Link Imports
- admin_notices show after load completed
- Error in Fetching Custom Post Type parent Category URL (slug)
- is there a way to display product gallery images via cdn
- Changing the Default New User Notification Email
- WP Fastest Cache -> Render Blocking Js -> Exclude Js Sources
- function post to trash problem
- How can I see $post object in frontend from functions.php?
- save short-code in my custom plugin settings problem missed something
- WordPress website working fine on localhost but not displaying front pages on webhost
- Change WordPress plugin widget `id_base` without breaking widget
- Uploading website to live causing problems to plug-in and layout
- How is it possible to create Multi part sections where people can answer or comment or vote on various parts of a page’s content as given example?
- save multi-select input using update_option for plugin
- Capture Recaptcha fail event on Contact Form 7
- How can I share my wordpress site with a friend?
- Making sure updates didn’t break anything
- wp_schedule_event function reference
- Meta box or shortcode help
- Users Ultra: Hide asterisk for required registration fields?
- Retrive images from the_content()
- How to retrieve hashtaged tweets from a list of users and post to WordPress
- Multi-step, live updating search
- Turning Existing Eccommerce Site into Multi-SIte
- wordpress select multiple options and illegal string offset ‘timeslot’ [closed]
- post_exists() returns a 0 but the 0 doesn’t register [closed]
- Display HTML5 jQuery Audio Player On Front Page
- How Do I Add Product Pictures To Search Results Of A Custom WordPress Theme Using A WooCommerce
- Is it possible to add permalink when using wp_insert_post?
- Update Plugin of wordpress to specific version
- Can WordPress updates take down site functions?
- When to store store plugin options as a single database record?
- What is the best way to override functions of thirdparty plugins?
- How to move a post in Vacancies so it appears in News/Events?