wordpress 我的插件页面的管理 URL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16713037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Admin URL to my plugin's page
提问by Joshua
My plugin is basically a link display page, for instance if you want to display a page with links to other websites.
我的插件基本上是一个链接显示页面,例如,如果您想显示一个包含其他网站链接的页面。
In wp-admin I have a menu item on the left side bar added with this code:
在 wp-admin 中,我在左侧栏中添加了一个菜单项,其中添加了以下代码:
function bls_add_menu_page() {
add_menu_page('Custom Links', 'Custom Links', 'manage_options',
'customlinks', 'bsl_admin_page', '', 15);
}
After adding a new link, I want to redirect to my plugin home page in admin. The URL when I click on my plugin menu link is :
添加新链接后,我想重定向到管理员中的插件主页。单击插件菜单链接时的 URL 是:
localhost/wp-admin/admin.php?page=customlinks
How do I get that URL in Worpdress? Currently I just do this :
如何在 Worpdress 中获取该 URL?目前我只是这样做:
wp_redirect('/wp-admin/admin.php?page=customlinks');
but I hope there is a better way of getting my plugin admin URL?
但我希望有更好的方法来获取我的插件管理 URL?
回答by hakre
You get the concrete URL to admin.php
by using the admin_url
function:
您可以admin.php
使用以下admin_url
函数获取具体 URL :
admin_url('admin.php'); # http(s)://localhost/wp-admin/admin.php
That function chooses the proper sheme (http/https) based on your Wordpress configuration for you so you do not need to care about it. Same for the path to the admin. The only thing you need to specify is the file name (admin.php
).
该函数会根据您的 Wordpress 配置为您选择合适的 sheme (http/https),因此您无需关心它。管理员路径相同。您唯一需要指定的是文件名 ( admin.php
)。
And in your concrete example you add the pagequery-info part:
在您的具体示例中,您添加页面查询信息部分:
$url = admin_url('admin.php?page=customlinks');
wp_redirect($url);
回答by Danijel
URL for menu page or options page has 'page' parameter ( page slug defined in add_menu_page() or add_options_page() ). You can always get the current page from $_GET['page'] param, so URL for the options page is:
菜单页面或选项页面的 URL 具有“页面”参数(在 add_menu_page() 或 add_options_page() 中定义的页面标签)。您始终可以从 $_GET['page'] 参数获取当前页面,因此选项页面的 URL 为:
admin_url( "options-general.php?page=".$_GET["page"] )
, and URL for menu page ( actually it works with options pages also ) is:
, 菜单页面的 URL(实际上它也适用于选项页面)是:
admin_url( "admin.php?page=".$_GET["page"] )