我的插件页面的管理 URL [英] Admin URL to my plugin's page

查看:29
本文介绍了我的插件页面的管理 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的插件基本上是一个链接显示页面,例如如果你想显示一个包含其他网站链接的页面.

My plugin is basically a link display page, for instance if you want to display a page with links to other websites.

在 wp-admin 中,我在左侧栏中添加了一个菜单项,其中添加了以下代码:

In wp-admin I have a menu item on the left side bar added with this code:

function bls_add_menu_page() {
    add_menu_page('Custom Links', 'Custom Links', 'manage_options', 
                  'customlinks', 'bsl_admin_page', '', 15);
}

添加新链接后,我想重定向到管理员中的插件主页.当我点击我的插件菜单链接时的 URL 是:

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 :

localhost/wp-admin/admin.php?page=customlinks

如何在 Worpdress 中获取该 URL?目前我只是这样做:

How do I get that URL in Worpdress? Currently I just do this :

wp_redirect('/wp-admin/admin.php?page=customlinks'); 

但我希望有更好的方法来获取我的插件管理 URL?

but I hope there is a better way of getting my plugin admin URL?

推荐答案

您可以使用 admin_url 函数:

You get the concrete URL to admin.php by using the admin_url function:

admin_url('admin.php'); # http(s)://localhost/wp-admin/admin.php

该功能会根据您的 Wordpress 配置为您选择正确的 sheme (http/https),​​因此您无需关心它.管理员路径相同.您唯一需要指定的是文件名 (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).

在您的具体示例中,您添加了 page 查询信息部分:

And in your concrete example you add the page query-info part:

$url = admin_url('admin.php?page=customlinks');
wp_redirect($url); 

这篇关于我的插件页面的管理 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆