The problem with calling flush_rewrite_rules()
is that the rules instantly get regenerated, while your plugin’s hooks are still active.
What I usually do, because it’s the simplest route to success, is delete the rewrite_rules
option on activation/deactivation. The rules will then get regenerated on the next pageload instead of the current one:
register_deactivation_hook( __FILE__, 'my_plugin_deactivation');
function my_plugin_deactivation() {
delete_option( 'rewrite_rules' );
}
A more ideal solution is to remove your rules from the stack before flushing, but that’s kind of a pain to do (see https://core.trac.wordpress.org/ticket/29118).
Related Posts:
- Custom pages with plugin
- Add rewrite rule to permalink structure
- Does flush_rewrite_rules() remove all rules added by other plugins as well as mine?
- Add_rewrite_rule doesn’t add custom url in plugin
- flush_rewrite_rules() not working on plugin activation
- Do rewrites added with add_rewrite_rule() persist after plugin deletion?
- WordPress rewrite rule depend on meta values not ids
- Custom pages with plugin
- Apache rewrite rules and wordpress problem
- Add Rewrite Rule for custom page
- What is the best way to output plugin result in certain url
- flush_rewrite_rules not working on plugin deactivation, invalid URLs not showing 404
- Custom rewrite rule is not picked by WordPress
- How can I rewrite a plugin generated URL?
- WordPress custom URL Rewrites redirecting not masking
- Best way to hook a custom url?
- Remove rewrite rules generated by plugin during deactivation
- How does WP handle multiple matching rewrite rules?
- How to Create a Custom Plugin Permalink
- Custom rewrite rules not working with WPML
- How to Create a Custom Slug for Tags and Categories with a prefix or suffix?
- Redirect to another page using contact form 7? [closed]
- Remove .htaccess portion upon plugin deactivation?
- Custom url rewriting
- URL rewrite with external JSON query
- WordPress rewrite rules not working
- How to rewrite URL and get the values?
- How to embed a new string in url?
- i want to rewrite my custom plugin url
- add_rewrite_rule to load different page, without changing URL in browser
- Change custom rewrite rule when permalink is updated/changed
- Change default url to plugin custom post type
- WP Job Manger change jobs url (NOT slug)
- How to change a user’s password programatically
- Who are the most trusted plugin developers? [closed]
- How would you require and automatically download dependent plugins?
- How to delete custom taxonomy terms in plugin’s uninstall.php?
- Redirect to settings page after install
- What is the correct way for a theme to support plugin UIs?
- Can i create two tables at single time while installation of custom plugin?
- Using add_filter inside another class
- WordPress plugin installation error
- How long does it take for a new plugin to be approved?
- How does WooCommerce display a custom comment_type in Comment Admin?
- Detecting when a custom taxonomy has been changed and display alert?
- How to display public user profile with 2 additional fields? (GitHub source code included)
- How to make my plugin GDPR compatible?
- Why is the Settings API is not saving my array of options
- Scope for PHP Variables Assigned in functions.php or a plugin
- How to make a custom field as an editor in wordpress?
- Why is an action callback function from an instance of a class always invoking the same function from an instance?
- JS Support Ticket – Auto create WP account
- Register Page Template from Plugin
- Passing an array from shortcode-function to filter-function
- WP_Async_Task doesn’t appear to be running asynchronously
- How to delete custom taxonomy terms in plugin’s uninstall.php?
- What are the Best Practises When Using AJAX in Plugin Development?
- Setup wp_schedule_event within a custom plugin
- execute function after one completed
- How can I run a custom shortcode function on a live site and only run if the viewer is a specific machine?
- Can I use register_settings and unregister_setting once the settings page has loaded?
- Plugin function inside custom plugin
- How to Resize the Custom Post Images?
- Class or function wrapper for plugin code
- Licensing a Plugin [closed]
- Add a function call after content automatically?
- configuration of .htaccess for add_rewrite_rule to make sense
- WordPress plugin with its own “site”/theme
- Ajax request sends url rather than data
- How to displaying Custom image, text and default image logo from Redux Framework option panel
- Security of a WordPress Plugin
- Grouping imported products and showing variations based on selected product
- save_post_product action not firing
- How to display the category name in the tab and post inside the tab in WordPress?
- How would I Redirect an existing WooCommerce customer to a specific url after Checkout
- Has blocks gutenberg block multiples registers type in my Plugin
- Ultimate Members Default Post Layout problem
- best way to upload a large file to wordpress using wp all import
- Why do actions with class and public method don’t fire __construct()
- How to define the slug for my custom plugin?
- Set “Open in New tab” as default option
- Generate and send ICS file through WordPress
- Field salespeople task management
- Is it possible to create duplicate post on other site (either push, on publish, or pull, periodically)?
- Widget outputs the value but doesn’t save anything inside the textarea
- wp_schedule_event need to deactivate plugin changing recurrance
- A more elegant way to handle notices/warnings
- Redirect default login page to a custom page [duplicate]
- Creating custom URL for async content
- appointment plugin doesn’t display all appointments
- Display_rows() and column_cb() strange behaviour
- WordPress plugin options need to delete after deactivate & uninstall
- Doing action based on input from options menu
- Plugin with custom domain
- Create New Admin Menu Section – Like how custom post type works, in a way
- Combining JS files to one script
- What are the downsides of using bootstrap in plugin development?
- How to generate a responsive output from plugin?
- The plugin generated xxx characters of unexpected output during activation
- Allow manage_options capability for specific user only for specific plugin?