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
- Ajax request sends url rather than data
- How can I create a page as a draft from my plugin?
- Custom Module, Extending WP with a Plugin?
- How do I remove all traces of a plugin?
- How to get values from network settings panel?
- How do I reliably find a URL to a script or other file?
- How do I profit from a Plugin?
- How to add captcha to publish widget
- Adding a jQuery modal dialog to the admin area
- using wp_cache in plugin
- Pluging with content for a specific page or post
- How to automatically activate users after registration without activation email?
- Creating a plugin that will display text on every page
- I cannot include a file in my plugin settings page
- Uninstalling IntenseDebate
- How to get Recent Post From Each Category with Thumbnail?
- Paypal Framework
- help intercepting save_post through plugin
- unregister a sidebar widget
- best way to run a php script away from the template?
- Custom Post Type, Custom Columns List
- auto activate plugin when theme is active
- How to displaying Custom image, text and default image logo from Redux Framework option panel
- Should I use the action in the plugin’s main file?
- Is it possible/advisable to set last stable version to previous version?
- How to add logo to a WordPress Custom Plugin?
- Themes conflicts and overrides my WordPress Support widget Plugin styles
- Disable Author Archive just for certain roles in bulk
- How to make sure settings are not lost when plugin is updated?
- Does WordPress do any internal caching if no plugin installed?
- Use a custom block in another block
- Seperate plugin and theme files
- WordPress Plugin- How to Insert Html&JS code in specific Page and specific Div
- Xamp installed local wordpress not allowing to publish or install plugin
- How to data add to table when update post wordpress? when we clicked!
- How to make a Product page without ordering and database
- can’t unzip file
- How Can i import plugin option?
- How to Call Specific .PHP file on add_submenu_page selection in Plugin Development?
- wp_options not returning value for logged out users?
- Pass PHP variable to javascript
- WooCommerce – I want to add functionality of one plugin to another plugin — best approach?
- WordPress cron job running more than once
- Gutenberg default attributes are empty when accessing in edit
- Set Button in PluginDocumentSettingPanel Content (WordPress Gutenberg)
- How can i export and import my plugin option WordPress
- How to Add text value in Automatically in this conditions?
- Table of contents (TOC) plugin is not showing header tag
- Remove all messages, when untrash a post
- How to Get Category Name When Export Products
- Custom page from wp admin area
- Want to create custom design of progress indicator in wpforms
- Translation for a text that is not printed on the screen
- Two plugins using the same CSS id
- How to hide plugin submenu title in drop down in admin panel in wordpress?
- Remove List Bullets
- Activation flow of a plugin in a multisite environment
- Checkbox show / hide output result
- Scrape key check failed. Please try again
- How to show multi line output from metabox
- Using Class loader in WordPress boilerplate
- How to keep plugin (media-sync) running even the tab is closed?
- Custom Meta box change size
- Add a new category for posts
- How does the WP repository determine that two plugins are the same when counting active installs?
- Could add_query_arg() redirect user to external site?
- Need to edit author permissions | custom taxonomy
- How to save Setting pages data to the database?
- Woocommerce plugin – How to create two versions of the same plugin with slightly different implementation for different users
- Where do I put the code snippets I found here or somewhere else on the web?
- Is it possible to pin a post in second position from top
- Security of a WordPress Plugin
- Add hook after content without formatting
- User loggedin as Subscriber form not sending
- Widgets are not displaying in the admin panel