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
- wp_enqueue_scripts
- Why Does The `auto_update_plugin` Hook Disable Management?
- Return multiple values in a shortcode attribute
- Allowing .rfa Files In Media Upload [duplicate]
- Sanitizing file & directory form input
- What’s my optimal choice for remote access to my localhost sites?
- Some WordPress Posts are automatically becoming comments on other Posts
- List category posts displaying limited posts
- Get Every Key & Value from Array then Display All in New Line
- What are admin hooks
- disabling ftp on wordpress
- Woocommerce Coupon Menu and Marketing Menu missing After “Coupons can now be managed from Marketing > Coupons.” [closed]
- Is there a way to add custom endpoint to specific page only
- “uagb/section and uagb/columns block”
- IF condition based on wp_remote_get output
- shortcode not return any thing in Gutnburg
- Fatal error on some pages after cancelling WPSTAGING cloning process
- Always get creating a new table with foreign key
- Progmatically adding menu links to the default (Top) or Footer menu
- Where is my google maps on my page? [closed]
- standard custom page template hierarchy for plugins
- get specific value of a array | PHP
- How do I add $_SESSION[”] to my wordpress page?
- How to get specific string/value from an array? php [closed]
- coding a WordPress AJAX Form using PHP to check if User is Logged Out and Show error
- How do i show different group of images below a button when the button is clicked on the same page in wordpress? [closed]
- plugin wraps the entire content
- React error #231with Custom Blocks after upgrade to WP 5.5
- Add User Role: Pre-saved in User-Meta [SOLVED]
- There has been a critical error on your website – won’t fix no matter what
- Adding custom meta boxes to specified custom post type
- WordPress Console Application (ability to excecute a custom function via crontab only)
- Get orders of a specific customer woocommerce
- What am is missing? (API CORS)
- How to do database for download stats?
- Shortcode Attributes to Return different $_POST
- How to find out which plugin create captcha after login?
- Comment IP Plugin – Fixing onfocus=’this.select()’
- How do I make reusable content blocks for header and footer when using WordPress headless with another front-end?
- WordPress 5.4 – How to prevent to enter only certain values in custom field
- What form should the $query media query array have for an Elementor page builder function? [closed]
- Private Page View Counter
- WooCommerce: Force coupon for existing/registered customers [closed]
- Plugin Activation Error – The plugin generated 22 characters of unexpected output during activation
- Plugin Admin Menu Boiler Plate
- How can I add IP address to my post?
- REST API can’t get the response manually
- Super slow plugin page (lots of error 500)
- How to make a dynamic css class whose name changes every visit to confuse scraper
- serverSideRender does not render “preview” html inside Gutenberg block
- How use wp media upload liberary in react components?
- Add_rewrite_endpoint doesn’t work with post name permalink structure
- How to notify wordpress instalation about my plugin update?