出于某种原因,我无法使用 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/