在插件开启时候刷新url规则来实现post type链接更新

Published
April 21, 2022
浏览次数 :  4

register_activation_hook( __FILE__, array($this,'_themename_pluginname_activate' ));
register_deactivation_hook( __FILE__, array($this,'_themename_pluginname_deactivate' ));

public function _themename_pluginname_activate() {
    $this->post_types();  // 在插件开启的时候刷新url 但是此时post type 还没有注册,所以要先召唤post type的注册。
    $this->taxonomies();
    flush_rewrite_rules( );
  }

  public function _themename_pluginname_deactivate() {
    unregister_post_type( 'portfolio' );
    unregister_taxonomy( 'project_type' );
    flush_rewrite_rules(  );
  }

Top