wordpress - 调用未定义函数 get_editable_roles()

标签 wordpress

出于某种原因,我无法使用 WordPress 函数 get_editable_roles()。这有错误吗? 不介意我在哪里添加,在 functions.php 中,在 index.php 中,在顶部,在底部。它总是给出未定义的函数错误。

我在全新的 WordPress 安装且没有任何插件的情况下,在二十十五主题中添加了这行代码:

$role = get_editable_roles();

它给出了这个错误:

Error: Call to undefined function get_editable_roles()...

如果我之前加载了 user.php 文件,那么它可以工作:

if (!function_exists('get_editable_roles')) {
   require_once(ABSPATH . '/wp-admin/includes/user.php');
}

最佳答案

即使您在管理端,您也应该考虑加载 user.php,尤其是您已经创建了一个自定义管理页面,如选项。

if ( ! function_exists( 'get_editable_roles' ) ) {
    require_once ABSPATH . 'wp-admin/includes/user.php';
}

$roles = get_editable_roles();

也讨论了here .

关于wordpress - 调用未定义函数 get_editable_roles(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33423315/

相关文章:

php - 在 woocommerce 属性中添加自定义字段

php - 如何更改此正则表达式以便它选择具有多个 img 的段落元素

wordpress - 我可以将现有的 html 主页谷歌分析代码添加到新的 wordpress 主页吗?

php - 如何在发送联系表格 7 之前更改数据?

php - WordPress 子查询在 SELECT 上返回超过 1 行

javascript - 使用 jquery/isotope 类调用/链接 wordpress 类别

wordpress - 我可以为 Wordpress 的 add_action() 的 Action Hook 参数使用变量而不是字符串吗?

php - Woocommerce 3 中的自定义模板

html - 基于列表的下拉菜单在 IE 中不起作用

html - div 后面的链接中的边距隐藏链接