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:
- Delete WordPress plugin Repository
- Better to fire specific hooks or generic hooks with parameters?
- How to make simply “report” button on posts
- Load plugin selectively for pages or posts, etc
- Is there a hook attached to general settings save?
- Multiple plugins vs combined one
- WooCommerce – Load Templates From Plugin For All Template Files
- Plugin for automatic database backup? [closed]
- wp-cli silently fails with error code 255
- Plugin for changing a post’s category based on it’s post date?
- WordPress Enqueue Script Chaos (jQuery & Foundation.js)
- Multisite functions to communicate with individual site functions
- Alter post slug by a filter that is fired just after a post is created
- Check javascript file Proper way in functions.php
- I’m trying to create security question field for my login page
- Restrict backend but allow to use post.php?action=delete&post=POSTID from front-end
- Standard permissions for wordpress; Plugin installation asks for FTP credentials
- WooCommerce “Save Changes” button appears inside custom settings
- How to override my plugin’s php classes with duplicates that are in my child theme folder
- How to make my plugin GDPR compatible?
- WordPress sending emails continuously. How to stop it?
- Sage WordPress – Plugin Namespace: Not Found
- Detect when any plugin is activated or deactivated
- Why is an action callback function from an instance of a class always invoking the same function from an instance?
- Is there a way to get dynamic data into a Slider Revolution slide from a PHP script?
- register_activation_hook with include file [closed]
- Add htmlentities and/or shortcode into data-attributes
- WAMP to XAMPP WordPress transfer
- How can i list random post from multiple category?
- Memberpress functions/documentation
- Editing admin pages in WordPress [closed]
- Dropdown menu on custom page with product to choose number of products per page
- Custom form action to handle data inside a plugin
- Add column to plugins table screen
- Auto activate plugin with unique user settings
- Pagination Broken on Static Pages but Works on Blog Articles
- How to change constants in WordPress wp-config.php programmatically?
- add_shortcode is not working in plugin where others are working
- Plugin options page with live preview?
- How to hide CSS by default and show on button press
- How to upload WordPress Images to remote web server and display those images in WordPress gallery [closed]
- WordPress backend delay by server side HTTP Request
- Anspress Customization: How to show logged in user votes on a single answer?
- Using window.onload with Ubermenu
- Ordering taxonomies by rank
- Embed plugin into Custom Page Template
- My homemade plugin is trying to update to someone else’s plugin
- Is there a way to embed a Google Docs form in a page without using plugins?
- Advanced Custom Fields – Disable Users to Edit Custom Fields
- Retrieving links and names of images from a NextGEN gallery [closed]
- REST route from a plugin not working if WordPress is installed in a subdirectory
- Plugin development: what to prefix?
- Submit Form data to another page via Ajax (WordPress Way)
- Getting taxonomy images to display on single-post with their terms
- Is changing post from category in a large blog a good practice?
- Contact Form 7 – Show image on successful send? [closed]
- Send email to multiple addresses on Contact Form 7, but exclude personal details on all but one
- Display site language setting in source code
- simple-job-board Plugin throws an error on live server [closed]
- How to return the values from a row where a value occurs for the first time among the rows available?
- Smarter navigation plugin and custom taxonomies
- How to embed a new string in url?
- Make 2 different WooCommerce checkout pages?
- A good heatmapping plugin for WordPress? (No 3rd-party services please) [closed]
- TN3 Plugin Not Working Under IIS / WebMatrix
- Including content from legacy app: via plugin or custom content?
- How to install a translation for a WP plugin?
- Plugin for TinyMCE to create reference to other posts
- Why may one avoid Jetpack plugin? [closed]
- XML Sitemap Generator and 404 problem
- How do I work with the SlideDeck plug-in?
- Why is adoptStyles-css stylesheet link added to every page?
- Stopping WordPress’ WYSIWYG Editor from Converting “didn’t” into “didn””””’t”?
- Sold out Label for variable products which are partially sold out
- User loggedin as Subscriber form not sending
- wc_get_template_part doesnt display the content [duplicate]
- Thumbnail image doesn’t show up in Shortcode output
- how to split and upload a theme on wordpress?
- Fatal error: require_once(): Failed opening required
- shortcodes not working [dt_carousel & [dt_fancy_image
- Load google font script based on optgroup label selected
- Easiest way to load/fire a handful of functions, IF checkbox is checked?
- Unload a woff file from WordPress
- Crazy redirect happening with no redirects set up
- How To Use htaccess to Rewrite Link Structure for a Page that is Generated Programatcially
- Programmatically generate new pages for a site based on page template and content elements accessed via DB
- Custom Icon assigned to menu items not working for multi-site networks
- How to display widget in front end?
- Shows warning when enable “wp_gallery_custom_links” plugin with Themify Builder
- WordPress environment not loading properly
- Where to store media uploaded by the plugin?
- Integrating a hosted app with wordpress using the API
- WP_Query Date Filtering Inclusive Being Ignored
- is_plugin_active() not defined on active plugin, in the thumbnails.php file
- wordpress plugin | short code issue
- WordPress site keeps getting flagged as malware [closed]
- How to put tags on photos in Windows that WordPress can read and apply on media files?
- List category-posts not work properly
- Auto-scroll to beginning of accordion item
- A splash page on landing page