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.

I am attempting to set non-wordpress rewrites inside of a plugin. My $wp_rewrite->rules are getting set properly, but the $wp_rewrite->non_wp_rules are not getting set at all when I deactivate/activate my plugin. However, if I set the flush_rewrite_rules() to flush in the "init" action instead of on activation of the plugin they work just fine.

Here is a watered down version of my code...

class My_Plugin
{

    public function __construct()
    {
        register_activation_hook(__FILE__, array(&$this, 'activate'));
        register_deactivation_hook( __FILE__, array(&$this, 'deactivate'))
        add_action('generate_rewrite_rules', array(&$this, 'rewrite'));
    }

    public function rewrite()
    {
        global $wp_rewrite;
        $new_rules = array(
            'something/?$' => 'index.php?custom_page=something',
        );
        $new_non_wp_rules = array(
            'theme/(.*)' => 'wp-content/themes/$1',
        );
        $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
        $wp_rewrite->non_wp_rules = $new_non_wp_rules + $wp_rewrite->non_wp_rules;
    }

    public function activate()
    {
        flush_rewrite_rules();
    }

    public function deactivate()
    {
        flush_rewrite_rules();
    }

}
share|improve this question
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.