/* --------------------------------------------------------------
   0. Child theme stylesheet
   -------------------------------------------------------------- */
add_action('wp_enqueue_scripts', function() {
    wp_enqueue_style('astra-child', get_stylesheet_uri());
});


/* --------------------------------------------------------------
   1. Custom header + footer uitschakelen in klantenzone
   -------------------------------------------------------------- */
function gz_custom_portal_layout() {

    if (
        is_page('klantenzone') ||
        is_page('dashboard') ||
        is_singular('cuar_private_page') ||
        is_singular('cuar_private_file') ||
        is_post_type_archive('cuar_private_file')
    ) {

        // Eerst alles verwijderen
        remove_all_actions('astra_header');
        remove_all_actions('astra_footer');

        // Dan eigen header toevoegen
        add_action('astra_header', function() {
            get_template_part('header-klantenzone');
        }, 1);
    }
}
add_action('wp', 'gz_custom_portal_layout');



/* --------------------------------------------------------------
   2. Redirect na inloggen → Dashboard (alleen klanten)
   -------------------------------------------------------------- */
function gz_redirect_after_login($redirect_to, $request, $user) {
    if (isset($user->roles) && in_array('subscriber', $user->roles)) {
        return home_url('/dashboard/');
    }
    return $redirect_to;
}
add_filter('login_redirect', 'gz_redirect_after_login', 10, 3);



/* --------------------------------------------------------------
   3. WP Customer Area navigatie uitschakelen
   -------------------------------------------------------------- */
add_filter('cuar/core/settings/enable-private-area-navigation', '__return_false');
add_filter('cuar/core/settings/show-private-pages-in-menu', '__return_false');
add_filter('cuar/core/settings/show-private-files-in-menu', '__return_false');



/* --------------------------------------------------------------
   4. Alleen "Uitloggen" rechtsboven
   -------------------------------------------------------------- */
function gz_add_logout_link() {
    if (is_user_logged_in()) {

        echo '
        <div style="
            position: fixed;
            top: 15px;
            right: 20px;
            font-size: 14px;
            font-family: serif;
            color: #6a5f52;
            z-index: 9999;
        ">
            <a href="'.wp_logout_url(home_url('/')).'"
               style="color:#6a5f52; text-decoration:none;">
                Uitloggen
            </a>
        </div>';
    }
}
add_action('wp_footer', 'gz_add_logout_link');



/* --------------------------------------------------------------
   5. Loginpagina styling + back-to-blog link verwijderen
   -------------------------------------------------------------- */
function gm_login_styles() {
    wp_enqueue_style('gm-login', get_stylesheet_directory_uri() . '/login-style.css');
}
add_action('login_enqueue_scripts', 'gm_login_styles');

add_action('<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://grafzorgmemoriamportaal.nl/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://grafzorgmemoriamportaal.nl/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://grafzorgmemoriamportaal.nl/wp-sitemap-posts-cuar_private_page-1.xml</loc></sitemap><sitemap><loc>https://grafzorgmemoriamportaal.nl/wp-sitemap-posts-sureforms_form-1.xml</loc></sitemap><sitemap><loc>https://grafzorgmemoriamportaal.nl/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
