$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin: rewrite rules are lost when WP updates|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin: rewrite rules are lost when WP updates

matteradmin39PV0评论

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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far