Я пытаюсь short url
моей привычной страницы, что в my-pugin
, когда я использую свою пользовательскую страницу, я буду ссылаться как ниже
http://localhost/wordpress/wp-content/plugins/my-plugin/testurl.php
, но я хочу это
http://localhost/wordpress/testurl
я пишу этот код в своем плагине
function create_rewrite_rules($rules) {
//print_r($rules);
global $wp_rewrite;
$newRule = array('/testurl' => 'wp-content/plugins/my-plugin/testurl.php');
//echo $newRule;
$newRules = $newRule + $rules;
//$newRules = $newRule;
// echo "<pre>";
// print_r($newRules);
return $newRules;
}
function flush_rewrite_rules() {
//echo 1;
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
if(class_exists('MyPlugin'))
$myPlugin = new MyPlugin();
add_filter('rewrite_rules_array', array($myPlugin, 'create_rewrite_rules'));
add_filter('init', array($myPlugin, 'flush_rewrite_rules'));
но это не поможет.