我正在尝试在这里构建一个带有自定义用户管理区域的Wordpress插件。我想做的是,当用户在页面末尾添加/编辑时,应该从我的插件打开一个页面。比如说
example.com/page-1/edit
应加载
example.com/wp-content/plugins/custom-user-admin-area/index.php?u=page-1
我试图利用WP\\U重写,但徒劳无功。
class MyPlugin {
function create_rewrite_rules($rules) {
global $wp_rewrite;
$newRule = array(\'([A-Za-z0-9-].+)/edit/\' => \'wp-content/plugins/custom-user-admin-area/index.php?u=\' . $wp_rewrite->preg_index(1));
$newRules = $newRule + $rules;
return $newRules;
}
function flush_rewrite_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
$MyPluginCode = new MyPlugin();
add_filter(\'rewrite_rules_array\', array($MyPluginCode, \'create_rewrite_rules\'));
add_filter(\'init\', array($MyPluginCode, \'flush_rewrite_rules\'));