
            || in_array(
                $current_node_id,
                $visited_nodes,
                true
            )
        ) {
            continue;
        }

        $visited_nodes[] = $current_node_id;

        $current_node = get_post( $current_node_id );

        if (
            ! $current_node
            || 'trm_node' !== $current_node->post_type
        ) {
            continue;
        }

        $node_level = (int) get_post_meta(
            $current_node_id,
            'trm_node_level',
            true
        );

        /*
        |--------------------------------------------------------------------------
        | ONLY AN ENROLLED COURSE CAN GRANT ACCESS
        |--------------------------------------------------------------------------
        */

        if ( 1 === $node_level ) {

            if (
                trm_course_sales_user_has_enrollment(
                    $user_id,
                    $current_node_id
                )
            ) {
                return true;
            }
        }

        /*
        |--------------------------------------------------------------------------
        | TRM ACCESS — FOLLOW THE ACTUAL HIERARCHICAL PARENT
        |--------------------------------------------------------------------------
        | Use trm_parent_node, which is the single parent used by the
        | Node page hierarchy and breadcrumbs. Do not use the plural
        | relationship list here, because related nodes must not grant
        | sideways access to unrelated content.
        |--------------------------------------------------------------------------
        */

        $parent_id = absint(
            get_post_meta(
                $current_node_id,
                'trm_parent_node',
                true
            )
        );

        if (
            $parent_id
            && ! in_array(
                $parent_id,
                $visited_nodes,
                true
            )
        ) {
            $nodes_to_check[] = $parent_id;
        }
    }

    return false;
}


/*
|--------------------------------------------------------------------------
| CURRENT USER ACCESS
|--------------------------------------------------------------------------
*/

/**
 * Check whether the current user has access through
 * direct enrollment or inherited Course access.
 *
 * @param int $course_node_id
 *
 * @return bool
 */
function trm_course_sales_current_user_has_access(
    $course_node_id
) {

    if ( ! is_user_logged_in() ) {
        return false;
    }

    return trm_course_sales_user_has_node_access(
        get_current_user_id(),
        $course_node_id
    );
}<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://therightmentor.com/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://therightmentor.com/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-posts-forum-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-posts-topic-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-posts-chapter-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-posts-product-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-posts-trm_node-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-taxonomies-post_tag-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-taxonomies-level-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-taxonomies-tool-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-taxonomies-product_cat-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-taxonomies-product_tag-1.xml</loc></sitemap><sitemap><loc>https://therightmentor.com/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
