You should prefer the uninstall hook over the file if your main plugin doesn’t have side effects (outputs html or writes to file/DB automatically when loaded). IMO there is too much risk (i.e. non zero) of doing the uninstall.php code wrong and open the file to direct execution from the outside.
This also help in having all the relevant code in one place.
uninstall.php, when exists, is being executed without loading the plugin code (that is the whole point of it) and therefor whatever is declared in the plugin code will not be available to uninstall.php.
Related Posts:
- Uninstall, Activate, Deactivate a plugin: typical features & how-to
- Best practice way to delete user meta data during plugin uninstall?
- How to delete custom taxonomy terms in plugin’s uninstall.php?
- Does plugin uninstall always put WordPress back into original state?
- How can I delete options with register_uninstall_hook?
- Plugin uninstall: why run dbDelta after $wpdb->query($drop_sql)
- Is it possible to uninstall one plugin from within another plugin?
- How to get variables from fucntion.php to my plugin files
- How to check what plugins used to be on a WordPress installation?
- Getting RGBA colour from gutenberg colourpicker
- UnInstallation of a Plugin from a developers perspective – The correct and clean method
- Plugin. Html code in Template
- One of my plugins broke when I tried to update it, how do I safely uninstall it?
- uninstall.php file in Plugin to clean DB
- Set and access global variable
- How to remove traces from widget during uninstallation
- Woocommerce Create custom product type with variations
- uninstall.php does not appear to trigger when uninstalling my plugin
- Add comments for template variables
- How to delete custom taxonomy terms in plugin’s uninstall.php?
- Custom message on plugin uninstall
- Does plugin’s uninstall.php file have access to the plugin ‘s object?
- Remove .htaccess portion upon plugin deactivation?
- Plugin retrieving results even after uninstallation
- Passing stored variables to add_filter
- Can my hooked uninstall class function access a global var declared in main plugin file?
- Use conditional logic for woocommerce variable product
- Can plugin2 uninstall plugin1 at the very beginning of plugin2’s installation?
- Add text to variable
- plugin uninstall function drop the tables, but shows errors on admin
- How Do I Uninstall a Current WordPress Theme and Install a Fresh Theme
- Passing PHP Variables to AJAX Loaded Pages
- Shortcode and variable
- Uninstalling IntenseDebate
- What’s the best way to echo out a filter variable?
- Defining the value of a variable before a function?
- How to display emails as a post?
- How to delete Crisp Chat plugin completely?
- Passing function into add_action always returns the first argument
- Defining constant in a plugin to use in another plugin
- How to display variables from plugin?
- fix undefined variable in native wp files
- Passing variable from template file to the plugin file
- Editing Global Variables from Inside Functions
- How to remove links generated by SEO-smart-links?
- Global Handle to Class unavailable in Plugin?
- Scripts don’t enqueue after removing plugin
- “Add Media” button in custom plugin
- Disabled plugins are they security holes – rumor or reality?
- When coding a WordPress theme, where does the theme (i.e. the presentation) end and the plugin (i.e. the functionality) begin?
- Core framework/helpers for logging stuff?
- Disable Specific Widgets on Selected Pages of a WordPress Website?
- How to handel multiple checkbox field in the admin settings page with Settings API
- Are orders of magnitude used for “Active Installs”?
- To remove plugin notices for non-admin users
- How do I configure WordPress to talk to a Microsoft SQL Server database?
- Files being generated in multiple directories supposedly by WordPress (advanced_settings.php and common_config.php)
- Is there a plugin that allows a user of your site to get an email from you with an attachment?
- An old plugin self-made stoped sending mail
- Is there a plugin that makes extnernal links open in new window, BUT [closed]
- plugings request url is the old url
- Unable to activate wordpress importer after installing it
- Headers already sent when I try to add headers via a shortcode
- Test files for plugin development
- Outbound Click Tracking
- Error with Image Slide plug-in/ s3slider in WP
- How to add an automatic refresh in WordPress for a Page/Post or an embedded OneDrive/Excel HTML Code?
- File Storage and Repository for individual user
- How to allow user to select User ID in Formidable Pro form? [closed]
- Custom Shortcode Broken in WordPress 3.1
- How to get plugin name from plugin file location
- How do i edit the plugin files in DataBase via phpMyAdmin?
- Sticky option for custom post types without using custom fields or plugins
- Let users sell video in my website [closed]
- WordPress Social Sharing Icons – Custom Placement
- check uncategorized category by default
- Using meta_query in a WP_Query not working for numbers properly
- How to get rid of Ellipsis on Woocommerce [Essential] Theme [closed]
- Settings API Message Error is global
- Dynamic Rating Plugin to Add Anywhere
- How can i find the cron jobs that run on my site and then move them to the server side?
- Hide fields in woocommerce settings
- How to copy the all WordPress media items to another custom plugin folder?
- Bulk Edit Media Library alt, caption, image names
- WordPress is redirecting me to homepage
- Child theme modifications not showing up
- Moving a few select DB tables to a new WP instance
- “Fire Secure” menu item
- How to get the total count of Favorite/Favorited authors
- Admin page and admin menu. Permissions plugin
- How to create a new database table whenever user changes options
- How to redirect from plugin page
- What is the Object for WP_Error Class?
- How do I locate specific file in a post that affects ssl?
- Looking for Plugin that displays Facebook group’s photos [closed]
- Publishing tweets from wordpress [closed]
- WordPress Plugins Error
- How do I put a word-press blog into my static site without installing wordpress on server?
- Translate text for empty product
- add_meta_box showing blank screen in my page