is_user_logged_in() undefined at shutdown in plugin context

Edit 1 – Does not work

// Catch is_user_logged_in() value before shutdown

function is_user_logged_in_init() {
    $is_user_logged_in_init = is_user_logged_in() ?? false;
}
add_action('init', 'is_user_logged_in_init');

Leaving this here for my reference. Ref

Edit 2 – Works

I found two ways to solve this:

  1. Option 1 – Not recommended Ref

include_once ABSPATH.'wp-includes/pluggable.php';

  1. Option 2 – Rewrite the script, i.e. Add shutdown action inside init action
function beautify_conditionals() {
    if (!is_admin() && !is_user_logged_in()) {
        add_action('shutdown', 'beautify_actions', 0);

        ob_start();
    }
}
add_action('init', 'beautify_conditionals');

function beautify_actions() {
    $html = ob_get_clean();

    $tidy = new tidy;
    $tidy->parseString($html, [
        'drop-empty-elements' => false,
        'drop-empty-paras' => false,
        'escape-scripts' => false,
        'fix-backslash' => false,
        'fix-style-tags' => false,
        'fix-uri' => false,
        'indent' => true,
        'indent-spaces' => 4,
        'join-styles' => false,
        'lower-literals' => false,
        'tab-size' => 4,
        'tidy-mark' => false,
        'wrap' => 0,
    ], 'utf8');
    $tidy->cleanRepair();

    $tidy = preg_replace('/<!DOCTYPE html>/', '<!doctype html>', $tidy);

    echo $tidy;
}