2015-10-29 70 views
-2

出于某种原因,我无法使用WordPress函数get_editable_roles()。这有没有一个错误? 不介意我在index.php中的functions.php,top,bottom中添加的位置。它总是给出未定义的函数错误。 调用未定义的函数get_editable_roles()

我加入二十五主题这行代码,在一个新的WordPress安装,没有任何插件:如果我加载用户

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

$role = get_editable_roles(); 

它给这个错误.php文件之前,那么它的工作原理:

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

请分享相关代码...这只会在管理部分加载,所以您需要在相应的操作钩子中使用它。 – rnevius

+0

没有相关的代码,我只是在functions.php – ThemesCreator

+0

中添加$ role = get_editable_roles()...同样,该函数只在Admin中加载。如果你想在别处使用它,你应该实现你自己的函数版本。如果你想在Admin中使用它,你应该确保你通过一个管理动作钩子来调用这个函数。 – rnevius

回答

0

你应该考虑到加载user.php的即使你是在管理方面,尤其是你已经创建了类似的选项自定义管理页面。

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

$roles = get_editable_roles(); 

它也被讨论为here