Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined function get_editable_roles()

Tags:

wordpress

For some reason, I can't get working the WordPress function get_editable_roles(). Is there a bug with this? Doesn't mind where I add, in the functions.php, in the index.php, in the top, in the bottom. It always gives the undefined function error.

I added this line of code in Twenty Fifteen theme, in a fresh WordPress install and without any plugin:

$role = get_editable_roles();

It give this error:

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

If I load the user.php file before, then it works:

if (!function_exists('get_editable_roles')) {
   require_once(ABSPATH . '/wp-admin/includes/user.php');
}
like image 334
ThemesCreator Avatar asked Nov 28 '25 14:11

ThemesCreator


1 Answers

You should consider to load user.php even you are in admin side, especially you have created a custom admin page like options.

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

$roles = get_editable_roles();

It is also discussed here.

like image 187
kuzey beytar Avatar answered Nov 30 '25 04:11

kuzey beytar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!