0

我们有一个双语 Wordpress 主题。英文版位于mydomain.com ,捷克语版位于mydomain.com/cs/的虚拟目录中

当用户在mydomain.com/login登录时,他们将被重定向到mydomain.com/dashboard,如下面的代码中所指定(即页面名称)。我需要使用mydomain.com/cs/login登录的用户登录到mydomain.com/cs/dashboard

该函数使用的代码在这里:

<?php wp_login_form( apply_filters( 'atcf_shortcode_profile_login_args', array( 'redirect' => isset ( $edd_options[ 'profile_page' ] ) ? get_permalink( $edd_options[ 'profile_page' ] ) : home_url() ) ) ); ?>

home_url是返回站点的完整 URL。有什么想法可以通过转义当前目录(/登录)来实现重定向吗?

4

1 回答 1

1

您可以检查该$_SERVER["REQUEST_URI"]值以查看它是否以开头,/cs/然后相应地动态更新配置文件页面值。

// The current URI (does not incude host/domain)
$uri = $_SERVER["REQUEST_URI"];
// The home URL
$redirect = home_url();

// $edd_options[ 'profile_page' ] must return the page ID for get_permalink to work
if ( isset( $edd_options[ 'profile_page' ] ) ) {

    // The profile URL. 
    $profile_page_id = $edd_options[ 'profile_page' ];
    $redirect = get_permalink( $profile_page_id );

    // Check if the URI starts with /cs/
    if ( strpos( $uri, '/cs/' ) == 0 ){
        // Explode into an array
        $url_array = explode( '/', $profile_page );

        // Insert /cs/ into array
        $url_array = array_slice($url_array, 0, 3, true) +
                 array("x"=>"cs") +
                 array_slice($url_array, 3, count($url_array)-3, true);

        // Implode back to a string
        $redirect = implode( '/', $url_array );
    }
}

// Set up params to send to login form
$args = apply_filters( 'atcf_shortcode_profile_login_args', array( 'redirect' => $redirect ) );
wp_login_form( $args );
于 2013-04-11T16:57:54.840 回答