is_user_logged_in() undefined at shutdown in plugin context


The function is_user_logged_in() is not available at shutdown (plugin context, not theme).

I want my plugin to run only (1) on front-end pages and (2) when the user is not logged in.

This partially works, but it also runs on Divi builder front-end pages, so I need to add !is_user_logged_in:

if (!is_admin()) {
    add_action('shutdown', function () {
        // Do some ob_start() and PHP_Tidy() stuff...
    }, 0);

Unfortunately changing my conditional to if (!is_admin() && !is_user_logged_in()) fails with:

Uncaught Error: Call to undefined function is_user_logged_in() in...

Jeff 1 month 2023-04-18T13:59:26-05:00 0 Answers 0 views 0

Leave an answer