How do you add your rewrite rule?
If you are adding it manually (opening the .htaccess and adding the lines by yourself in php) then you are also supposed to remove it manually. As you suggested the best way would then be to use regex.
If the rewrite rule was added through the WordPress API using add_rewrite_rule() you are able to remove it using flush_rewrite_rules(). You could use it like this:
register_activation_hook( __FILE__, 'myplugin_activate' );
function myplugin_deactivate() {
global $wp_rewrite;
unset($wp_rewrite->non_wp_rules['the-string-you-passed-as-param-to-add-rewrite-rule']);
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'myplugin_deactivate' );
Related Posts:
- Redirect to another page using contact form 7? [closed]
- Do rewrites added with add_rewrite_rule() persist after plugin deletion?
- Apache rewrite rules and wordpress problem
- Uninstall, Activate, Deactivate a plugin: typical features & how-to
- Custom pages with plugin
- How to delete custom taxonomy terms in plugin’s uninstall.php?
- Add rewrite rule to permalink structure
- add_rewrite_rule, plugin activation and plugin deactivation
- 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
- Write to / remove from default .htaccess file from plugin?
- Remove rewrite rules generated by plugin during deactivation
- UnInstallation of a Plugin from a developers perspective – The correct and clean method
- uninstall.php file in Plugin to clean DB
- How to delete custom taxonomy terms in plugin’s uninstall.php?
- Is there a directory my plugin can write files to that cannot be viewed via the browser/url?
- Custom url rewriting
- Can plugin2 uninstall plugin1 at the very beginning of plugin2’s installation?
- plugin uninstall function drop the tables, but shows errors on admin
- WordPress rewrite rules not working
- can’t install any wp plugins [duplicate]
- WordPress rewrite rule depend on meta values not ids
- Help Code Review – I need to write on .htaccess file from theme’s function.php
- Custom pages with plugin
- 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?
- Redirect to settings page after install
- What is the correct way for a theme to support plugin UIs?
- How does WordPress determine the primary plugin PHP file?
- translation does not work with text_domain
- Publish Post After Click On A Link
- Custom url structure for custom template
- Determine plugin name from within plugin_action_links filter
- Having separate plugins and themes folder for multi-site setup
- gallery option is not available in media upload box in costum theme option page
- Many plugins making WordPress run slow by design?
- How do I turn a custom post type into a plugin?
- Add keywords meta to index.php page
- How to create ‘import dummy data’ option in custom wordpress plugin
- Object Oriented Plugin not working
- Does WP identify plugin by plugin name or plugin_basename?
- Modifying Author Link to add Author Meta in URL
- What are the specifics of WordPress development I need to know? [closed]
- Insert data from .sql file in wordpress plugin
- How can i get the post’s full html source by its ID?
- Force file download on plugin activation
- How to create a custom post type that contains another custom post type?
- How to change the name of the “edit my profile” link in the WordPress admin backend
- Add action to fire when a published post is updated
- 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?
- URL rewrite with external JSON query
- Class or function wrapper for plugin code
- Licensing a Plugin [closed]
- Add a function call after content automatically?
- 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
- Shortcode do not return the right data in post
- 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)?
- .htaccess file doesn’t work, with hundred tries
- Widget outputs the value but doesn’t save anything inside the textarea
- Change localization only for plugin
- How to get author developer link on plugin page
- 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]
- 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
- How to remove links generated by SEO-smart-links?
- 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
- How to dispaly post informations (such as titles) in an admin plugin menu page?
- add_meta_box showing blank screen in my page
- Plugin translations are not loaded from translate.wordpress.org
- Use inline callable for hooks and filters
- Error in using ‘admin_enqueue_scripts’ action through a class