After an intense research without finding the proper answer I decided to ask my question here.
I need to add some rewrite rules when activating a plugin in WordPress without existing custom rules being deleted. Example: if I add rules for plugin A, they are written into .htaccess (inside the WordPress block). But if I activate another plugin B which also has custom rewrite rules, then the rules of plugin A are overwritten by the rules of plugin B.
How I add the rules:
register_activation_hook(__FILE__, 'activatemyplugin');
function activatemyplugin() {
add_rewrite_rule('pdf/([^/]*)$', plugins_url('pdfexport') . '/out/$1', 'top');
flush_rewrite_rules();
}
On deactivation of A or B, all custom rules (of A and B) are removed (replaced by default rules).
function deactivatemyplugin() {
flush_rewrite_rules();
}
How can I add and delete specific rewrite rules, so that previously added rules remain?
Every help is appreciated. Thanks in advance.