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

Published
2022-04-21
浏览次数 :  130

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(  );
  }

  • 标签1
  • 标签1
  • 标签1
Top