public function loggedIn(): bool
    {
        $session = $this->getSession();
        if (! $session->isStarted()) {
            $session->start();
            // If there isn't a session started the user can't be logged in.
            return false;
        }

        $page = $session->getPage();

        // Look for a selector to determine if the user is logged in.
        try {
            // Search for the body element.
            $body_element = $page->find('css', 'body');

            // If the page doesn't have a body element the user is not logged in.
            if (null === $body_element) {
                return false;
            }

            // The user is logged in if:
            $is_logged_in = (
                // The body has a logged-in class (front-end).
                $body_element->hasClass('logged-in') ||
                // The body has a wp-admin class (dashboard)
                $body_element->hasClass('wp-admin')
            );
            return $is_logged_in;
        } catch (DriverException $e) {
            // This may fail if the user has not loaded any site yet.
        }

        return false;
    }
public function loggedIn(): bool
    {
        $session = $this->getSession();
        if (! $session->isStarted()) {
            $session->start();
            // If there isn't a session started the user can't be logged in.
            return false;
        }

        $page = $session->getPage();

        // Look for a selector to determine if the user is logged in.
        try {
            // Search for the body element.
            $body_element = $page->find('css', 'body');

            // If the page doesn't have a body element the user is not logged in.
            if (null === $body_element) {
                return false;
            }

            // The user is logged in if:
            $is_logged_in = (
                // The body has a logged-in class (front-end).
                $body_element->hasClass('logged-in') ||
                // The body has a wp-admin class (dashboard)
                $body_element->hasClass('wp-admin')
            );
            return $is_logged_in;
        } catch (DriverException $e) {
            // This may fail if the user has not loaded any site yet.
        }

        return false;
    }
public function loggedIn ( ) : bool { $ session = $ this -> getSession ( ) ; if ( ! $ session -> isStarted ( ) ) { $ session -> start ( ) ; // If there isn't a session started the user can't be logged in. return false ; } $ page = $ session -> getPage ( ) ; // Look for a selector to determine if the user is logged in. try { // Search for the body element. $ body_element = $ page -> find ( 'css' , 'body' ) ; // If the page doesn't have a body element the user is not logged in. if ( null === $ body_element ) { return false ; } // The user is logged in if: $ is_logged_in = ( // The body has a logged-in class (front-end). $ body_element -> hasClass ( 'logged-in' ) || // The body has a wp-admin class (dashboard) $ body_element -> hasClass ( 'wp-admin' ) ) ; return $ is_logged_in ; } catch ( DriverException $ e ) { // This may fail if the user has not loaded any site yet. } return false ; }
Determine if the current user is logged in or not.

@return bool
Determine if the current user is logged in or not .