Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

We have tons of rewrite rules saved in our wp_options table and I'd like to permanently remove any entries that we're not using on our site (such as comment feeds, page attachments, etc.).

What's the best way to clear these rules and prevent them from being saved to the database the next time flush_rules() is called? I'd prefer a solution that works in functions.php or as a standalone plugin, rather than editing core WP files such as wp-includes/rewrite.php.

share|improve this question
    
There are bundles of filters/actions inside the rewrite class, are these not suitable for removing what you don't want? –  t31os Aug 5 '11 at 0:15
    
I've looked at that file, but I don't understand how to prevent those actions from executing when flush_rules() is called. Is there a way to block them in functions.php? –  Andres Lucero Aug 5 '11 at 14:29
    
Why do you want to remove these rules? They shouldn't be hurting anything. –  BandonRandon Sep 18 '11 at 19:23
    
I already maintain 301 redirects for important pages via .htaccess, so I don't want redundant rules. –  Andres Lucero Sep 22 '11 at 23:47
add comment

1 Answer

Rather than modifying stored rules it would be more reliable to modify rules before they are stored.

  • flush_rewrite_rules() calls
  • WP_Rewrite->flush_rules()
  • WP_Rewrite->wp_rewrite_rules()
  • WP_Rewrite->rewrite_rules()

Inside last there are fitting hooks to modify rules (after which result they will be saved as usual on each flush):

do_action_ref_array('generate_rewrite_rules', array(&$this));
$this->rules = apply_filters('rewrite_rules_array', $this->rules);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.