
// 1. Force FluentAuth frontend forms and assets
add_filter( "fluent_auth/auth_forms_enabled", "__return_true", 999 );

// 2. Change standard WordPress login URL to /login
add_filter( "login_url", function( $login_url, $redirect, $force_reauth ) {
    $custom_url = home_url( "/login" );
    if ( ! empty( $redirect ) ) {
        $custom_url = add_query_arg( "redirect_to", urlencode( $redirect ), $custom_url );
    }
    return $custom_url;
}, 999, 3 );

// 3. Register custom rewrite rule for /login
add_action( "init", function() {
    add_rewrite_rule( "^login/?$", "index.php?mdh_custom_login=1", "top" );
} );

add_filter( "query_vars", function( $vars ) {
    $vars[] = "mdh_custom_login";
    return $vars;
} );

// 4. Intercept request for /login and render FluentAuth form
add_action( "template_redirect", function() {
    $is_login = get_query_var( "mdh_custom_login" );
    if ( ! $is_login ) {
        $req_path = trim( parse_url( $_SERVER["REQUEST_URI"] ?? "", PHP_URL_PATH ), "/" );
        if ( $req_path === "login" ) {
            $is_login = true;
        }
    }

    if ( $is_login ) {
        if ( is_user_logged_in() ) {
            $redirect = isset( $_GET["redirect_to"] ) ? esc_url_raw( $_GET["redirect_to"] ) : home_url( "/" );
            wp_safe_redirect( $redirect );
            exit;
        }

        status_header( 200 );
        nocache_headers();

        get_header();

        $title = esc_html__( "Sign In", "MDH" );
        $subtitle = esc_html__( "Welcome back to Muzakarah Darulhana", "MDH" );
        $form_html = do_shortcode( "[fluent_auth_login]" );

        echo "<div class=\"site-content py-12 px-4 sm:px-6 lg:px-8 min-h-[70vh] flex items-center justify-center\">";
        echo "  <div class=\"w-full max-w-md\">";
        echo "    <div class=\"clay-card p-6 sm:p-8 rounded-3xl border border-ink-900/10 shadow-clay bg-white\">";
        echo "      <div class=\"text-center mb-6\">";
        echo "        <h1 class=\"text-2xl font-serif font-bold text-ink-900\">" . $title . "</h1>";
        echo "        <p class=\"text-xs text-ink-500 mt-1\">" . $subtitle . "</p>";
        echo "      </div>";
        echo $form_html;
        echo "    </div>";
        echo "  </div>";
        echo "</div>";

        get_footer();
        exit;
    }
} );

// 5. Intercept wp-login.php GET requests and redirect to /login
add_action( "init", function() {
    global $pagenow;
    if ( "wp-login.php" === $pagenow && ! is_admin() ) {
        $action = isset( $_REQUEST["action"] ) ? sanitize_text_field( $_REQUEST["action"] ) : "";
        if ( empty( $action ) || "login" === $action ) {
            if ( ( $_SERVER["REQUEST_METHOD"] ?? "GET" ) === "GET" ) {
                $redirect_to = isset( $_GET["redirect_to"] ) ? $_GET["redirect_to"] : "";
                $target = home_url( "/login" );
                if ( ! empty( $redirect_to ) ) {
                    $target = add_query_arg( "redirect_to", urlencode( $redirect_to ), $target );
                }
                wp_safe_redirect( $target );
                exit;
            }
        }
    }
} );
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://08.darulhana.org/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://08.darulhana.org/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://08.darulhana.org/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://08.darulhana.org/wp-sitemap-posts-mdh_element-1.xml</loc></sitemap><sitemap><loc>https://08.darulhana.org/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://08.darulhana.org/wp-sitemap-taxonomies-element_category-1.xml</loc></sitemap><sitemap><loc>https://08.darulhana.org/muzakarah/site-maps/index.xml</loc></sitemap></sitemapindex>
