WP_AJAX icon indicating copy to clipboard operation
WP_AJAX copied to clipboard

Undefined: is_user_logged_in()

Open jpmurray opened this issue 5 years ago • 0 comments

I'm getting that as an error and, it seems that it's because is_user_logged_in() is a pluggable function. And since I'm using WP_AJAX in a plugin I'm working on, it fails because it can't find the function because it's called too soon in the WP workflow.

I don't know what a decent solution would be to be honest, and that's why I didn't make a pull request. At first I though to make a protected $isPlugin = false by default, and then overwrite it on demand that would use different method in isLoggedIn(), but I'm not sure what would be the different method.

At this moment, this is how I modified the file. It's not perfect, but it works.

public function isLoggedIn()
    {
        if (function_exists('is_user_logged_in')) {
            return is_user_logged_in();
        }

        return null;
    }

What would you do?

jpmurray avatar Jul 31 '18 18:07 jpmurray