我有一个奇怪的问题。自定义重写规则已在我的插件激活挂钩中正确注册。但是,如果我转到permalinks设置页面并在“保存更改”上单击clic,我就会丢失插件注册的重写规则。我必须停用并重新激活我的插件才能重新获得自定义重写规则。
这里是我的激活和停用挂钩
register_activation_hook( __FILE__ , \'properties_plugin_activation\' );
function properties_plugin_activation(){
create_property_post_type();
create_properties_taxonomies();
//add custom rewrite rules and custom vars before flush_rewrite_rules()
properties_add_rewrite_rules();
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__ , \'properties_plugin_deactivation\' );
function properties_plugin_deactivation(){
flush_rewrite_rules();
}
这里是我的重写规则:
// Register a new vars to be used in the rewrite rules
function properties_add_query_vars( $vars) {
$vars[] = "action"; // name of the var as seen in the URL
return $vars;
}
add_filter(\'query_vars\', \'properties_add_query_vars\');
// Add the new rewrite rules
function properties_add_rewrite_rules() {
add_rewrite_rule( \'properties/search/?$\' , \'index.php?post_type=properties&action=search\' , \'top\' );
$config = new PConfig();
foreach($config->taxonomies as $taxonomy){
add_rewrite_rule( \'properties/\'.$taxonomy["slug"].\'/(.+)/?$\' , \'index.php?post_type=properties&\'.$taxonomy["slug"].\'=$matches[1]\' , \'top\' );
}
}