I'm asking this here because the WP forums just have so much noise in them that things vanish.
I've got a plugin which has at the top
require_once(ABSPATH . WPINC . '/pluggable.php');
Now I've been told that this is "bad" because if anyone has over riden any of the functions define in pluggable I'm trampling over them.
But if I remove it I get:
PHP Fatal error: Call to undefined function wp_get_current_user() in /webstuff/canalblogs/wp-includes/capabilities.php
So what is the fix?
Fixed it!
I had
if (current_user_can(WORDBOOKER_MINIMUM_ADMIN_LEVEL)) {
add_action('admin_menu', 'wordbook_admin_menu');
}
So if I change it to:
add_action('admin_menu', 'wordbook_admin_menu');
It all works
Fixed, but different functionality there. It's going to add the menu for everyone now....
I know - I dont really mind if it does to be honest.
But is there any way of getting round it without needing pluggable.php?
I think it depends where in your plugin you call it. You might have to do your check in a different place. Typically, it works if you do:
add_action('admin_menu', 'wordbook_admin_menu');
And then do
function wordbook_admin_menu() {
if (!current_user_can(WORDBOOKER_MINIMUM_ADMIN_LEVEL)) {
wp_die("Hey, you're not allowed in here.");
}
}
Now why didn't I think of that ... Think maybe I need to go out and get some fresh air!
Thanks