plugin: rewrite rules are lost when WP updates

I'm developing a plugin, and noticed that my custom rewrite rules are lost after WP updates its core.It's no b

I'm developing a plugin, and noticed that my custom rewrite rules are lost after WP updates its core.

It's no big deal, it works again if I disable/reactivate my plugin.

But since I would like to share the plugin on the WP repo at the end, I would like to fix this bug. Can someone help ? Here's how my code works. I guess there is something that is incompatible with WP updating.

class WP_SoundSystem {
    public static function instance() {

            if ( ! isset( self::$instance ) ) {
                    self::$instance = new WP_SoundSystem;
                    self::$instance->setup_globals();
                    self::$instance->includes();
                    self::$instance->setup_actions();
            }
            return self::$instance;
    }

    private function __construct() { /* Do nothing here */ }

    function setup_globals() {
        //...
    }
    function includes(){
        //...
    }
    function setup_actions(){
        // activation
        register_activation_hook( $this->file, array( $this, 'activate_wpsstm'));

        // deactivation
        register_deactivation_hook( $this->file, array( $this, 'deactivate_wpsstm'));

        //...

    }
    function activate_wpsstm() {
        $this->debug_log('activation');
        $this->init_post_types();
        $this->add_custom_capabilites();
        $this->init_rewrite();
        flush_rewrite_rules();
    }
    function deactivate_wpsstm() {
        $this->debug_log('deactivation');
        $this->remove_custom_capabilities();
        flush_rewrite_rules();
    }
    /*
    Hook for rewrite rules.
    */
    function init_rewrite(){
        $this->debug_log('set rewrite rules');

        //files included in includes() above will hook on this to add rewrite rules
        do_action('wpsstm_init_rewrite');
    }
}


function wpsstm() {
    return WP_SoundSystem::instance();
}

wpsstm();

Thanks.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745675642a4639669.html

相关推荐

  • plugin: rewrite rules are lost when WP updates

    I'm developing a plugin, and noticed that my custom rewrite rules are lost after WP updates its core.It's no b

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信