我正在尝试刷新插件中的重写规则,但它不起作用。我必须在管理面板中转到permalinks->save,以便刷新重写。有人知道为什么吗?
class SpektrixPlugin {
public function __construct(){
add_filter(\'query_vars\', array($this, \'add_query_vars\'));
add_action(\'init\', array($this, \'add_rewrite_rules\'));
}
public function activate() {
flush_rewrite_rules();
}
public function deactivate() {
flush_rewrite_rules();
}
public function add_query_vars($vars) {
$vars[] = "event"; // name of the var as seen in the URL
return $vars;
}
public function add_rewrite_rules() {
$page = get_page_by_title( \'Event\' );
add_rewrite_rule( \'whats-on/(.+)/?$\' , \'index.php?page_id=\'.$page->ID.\'&event=$matches[1]\' , \'top\' );
}
}
$SpektrixEvents = new SpektrixPlugin;
register_activation_hook( __FILE__, array($SpektrixEvents, \'activate\') );
register_deactivation_hook( __FILE__, array($SpektrixEvents, \'deactivate\') );