[英]How can I link pages in wordpress plugin without first registering an admin menu or submenu?
I am registering the submenu page like so:我正在像这样注册子菜单页面:
function MYPLUGIN_submenu_fn(){
add_submenu_page(
'books-home', //parent slug
'edit book', //page title
' Edit Book', //menu title
'manage_options', //capability
'edit-book', //slug
'MYPLUGIN_submenu_fn_callback',//callable function
'dashicons-location-alt' //icon url
);
}
//callback function
MYPLUGIN_submenu_fn_callback(){
include("edit_book.php");
}
// I register the submen
add_action('admin_menu','MYPLUGIN_submenu_fn');
The I can link to edit_book.php like so:我可以像这样链接到edit_book.php:
<a href="<?php echo admin_url('admin.php?page=edit-book&id='.$book->id);?>">
This works just fine.这工作得很好。 My problem is;
我的问题是; I don't want the edit book menu title on the books menu.
我不希望书籍菜单上的编辑书籍菜单标题。 I registered the menu just to use its slug internally.
我注册菜单只是为了在内部使用它的 slug。 So I removed the title name from the menu function so that it does not appear on the books menu like so:
所以我从菜单 function 中删除了标题名称,这样它就不会像这样出现在书籍菜单上:
function MYPLUGIN_submenu_fn(){
add_submenu_page(
'books-home', //parent slug
'edit book', //page title
'', //menu title text deleted
'manage_options', //capability
'edit-book', //slug
'MYPLUGIN_submenu_fn_callback',//callable function
'dashicons-location-alt' //icon url
);
}
Though the submenu looks blank, but its still there.虽然子菜单看起来是空白的,但它仍然存在。 When I click on it despite being blank it just works.
当我点击它时,尽管它是空白的,但它就可以工作。 I have no doubt this is not the right way to do it.
我毫不怀疑这不是正确的做法。 My question, is there away you can register a url in wordpress plugin without necessarily registering a menu or a submenu?
我的问题是,您是否可以在 wordpress 插件中注册 url 而不必注册菜单或子菜单? Or is there a better way I can hide the submenu so that it cannot appear to end users but still use its slug internally to link pages in my plugin?
或者有没有更好的方法可以隐藏子菜单,这样它就不会出现在最终用户面前,但仍然在内部使用它的 slug 来链接我插件中的页面? Please Help.
请帮忙。
If You replace parent slug parameter with empty string it will register page but not show in menu structure.如果您将父 slug 参数替换为空字符串,它将注册页面但不会显示在菜单结构中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.