This will give you the option to register your unistall hook during plugin activation.
function myplugin_activation_callback(){
register_uninstall_hook( __FILE__, 'myplugin_uninstall_callback' );
}
register_activation_hook( __FILE__, 'myplugin_activation_callback' );
function myplugin_uninstall_callback(){
//Perform your uninstall operations here
delete_option('test_option');
}
However, the simplest way is to use an uninstall.php
file with the following codes:
if (!defined('WP_UNINSTALL_PLUGIN')) {
die;
}
//Perform your uninstall operations here
delete_option('test_option');
It’s not recommended to use both at the same time.
Related Posts:
- Why is it important to deactivate a plugin before deleting it?
- Does the number of downloads displayed for a plug-in in the WordPress.org plug-in directory include automatic updates?
- How to get the active theme’s slug?
- Using plural-only translation of register_post_status() in plugin
- admin-ajax returning 400 error when request is made with Fetch API
- Which method is best to enqueue scripts
- Function to activate WordPress theme inside a plugin
- How do I retrieve a list of popular plugins using the WordPress.org Plugin API?
- Removing blank spaces from scripts to reducing page load time
- Edit Imported advanced Custom Fields from wordpress Dashboard
- Restrict access and display for categories
- What is the correct way to check if WP_Filesystem can write to a directory without aking for username / password?
- Change My Basket text in the header of WooCommerce Artificer theme
- ACF for audio url in wordpress audio shortcode
- Don’t send notification if author comments his own post plugin help?
- Custom interval is not working
- Built in admin ajax hooks?
- recommended breadcrumb plugins with possibility for hiding “Home” link [closed]
- dequeue not work
- ‘Easy Table’ Plugin has float issues
- Could someone please help me to add category id with in this query so this will return posts from a certain category?
- Adding a section to admin menu for global settings
- what the hook for displaying course list page for learndash plugin? [closed]
- Copyright messages for a particular set of pages
- Feature Differences between WordPress.com and Hosting on your Own Server?
- How do you add custom logo to entire themes
- wp_get_environment_type is undefined
- Is the wordpress user-model changed in wpmu?
- More than one text-domain is being used because of the included templates for plugins
- Dynamic CSS Vs Inline Issues in Code any Way around in a WordPress Themes?
- plugin development: problem with functions
- How to determine if a plugin affects your file-system
- View Private Published Page with URL Code (no login required)
- Why does my functions.php cause white-screen and media-library issues?
- Solutions to repost categories into multisite blogs?
- Custom random quote widget breaks when used in multiple sidebars
- Building plugin with changeable custom post type values…advice needed
- Added slug after URL permalink last slash returns different content
- How to escape the tailwindcss responsive syntax when using with contact form 7? [closed]
- $wpdb->get_row returns column name instead of column value
- Remove ‘Check Compatibility’ from Plugins menu
- WordPress “Categories to tags converter” not working. Pointing to import.php instead
- Some one is trying to hack my website, Need guidance [closed]
- WordPress premium theme development [duplicate]
- Mass SQL WordPress Meta Key deletion
- Gathering and logging data from a plugin: how to do it without race conditions?
- How to pass the API key to the client from the database? [closed]
- Elementor: How to override global theme style settings? [closed]
- Add user role to generated plugin
- plugin shortcode not working on ajax request call
- One sub site is slow while all others load fine, same theme & plugins [closed]
- Issues with a WP plugin menu system
- Ajax Plugin Not Echoing Response
- Affect on speed of wordpress membership plugins — currently trying s2member
- JQuery prepend a function
- Different custom templates for product category [closed]
- How to check wp_options’s rewrite_rules if current and existing are the same before flush the rules?
- WordPress Ajax code is not Working
- Clear out old images, any advice?
- problem with sql query
- Can i legally remove a credit from a free plugin on wordpress.org? [closed]
- What goes into wp_postmeta and why?
- WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version [closed]
- Woocommerce product info in a sidebar?
- output the debug lines to the end of the page
- A question of etiquette when forking a plugin? [closed]
- Localise settings section headline
- WordPress Plugin for pastimes/participation in contest [closed]
- Plugin to create unlimited custom shortcodes?
- How do I create pages within a WordPress post?
- Gutenberg default attributes are empty when accessing in edit
- how to create a custom page in child theme or plugin?
- How to add custom plugin data to the cart in woocommerce using custom button on product page?
- How can I display selected content from a seperate database in an Activity style widget?
- how to show all posts of each category in pages
- Hide all Admin Notices and move on a separate page
- Allowed memory size of 134217728 … wp-includes/wp-db.php on line 1989
- Pricing Calculator – WordPress
- Make the product page as homepage WooCommerce
- Genesis Child Theme – Customize body
- Creating categories while importing via CSV
- Multiple wordpress installations with same plugin folder (Apache Virtualhost)
- Website content not displayed anymore after updates
- WordPress plugin changes not updating
- Meta box: Undefined index
- How to update plugins in a distributed wordpress scenario?
- What’s the preferred method of writing AJAX-enabled plugins?
- WordPress API hook
- Shortcode registered from a plugin not recognized
- Plugin for Reading Documents, PDF’s etc
- Simple Data Table Update and Page Integration
- How to add a box for list items?
- wp_update_post call really slow when official Facebook plugin is installed
- Show latest and related articles from 3 different blogs
- Woocommerce custom fields
- This plugin throws error on the events page only [closed]
- Is it possible to set different payment gateway on each Gravity Forms form? [closed]
- Can’t save formdata in DB
- Event Made Easy – Block registration to two or more events that have the same category
- Allow manage_options capability for specific user only for specific plugin?