与WP重定向混淆

时间:2013-10-25 12:10:55

标签: php wordpress redirect

我在WordPress代码中找不到任何重定向网址,但每次完成注册表单时,它都会重定向到主页。我需要在注册完成后更改重定向。我可以理解下面的代码起到了作用,但是任何人都可以帮助我如何从下面的代码设置重定向到URL以及要替换哪个部分?

由于

        if ( 'publish' == $status ) {
        wp_safe_redirect( add_query_arg( 'updated', 'true', get_permalink( $campaign ) ) );
        exit();
    } elseif ( 'submit' == $action ) {
        $url = isset ( $edd_options[ 'submit_page' ] ) ? get_permalink( $edd_options[ 'submit_page' ] ) : get_permalink();

        $redirect = apply_filters( 'atcf_submit_campaign_success_redirect', add_query_arg( array( 'success' => 'true' ), $url ) );
        wp_safe_redirect( $redirect );
        exit();
    } else {
        wp_safe_redirect( add_query_arg( 'preview', 'true', get_permalink( $campaign ) ) );
        exit();
    }
}
add_action( 'template_redirect', 'atcf_shortcode_submit_process' );

/**
 * Redirect submit page if needed.
 *
 * @since Astoundify Crowdfunding 1.1
 *
 * @return void
 */
function atcf_shortcode_submit_redirect() {
    global $edd_options, $post;

    if ( ! is_a( $post, 'WP_Post' ) )
        return;

    if ( ! is_user_logged_in() && ( isset( $edd_options[ 'submit_page' ] ) && $post->ID == $edd_options[ 'submit_page' ] ) && isset ( $edd_options[ 'atcf_settings_require_account' ] ) ) {
        $url = isset ( $edd_options[ 'login_page' ] ) ? get_permalink( $edd_options[ 'login_page' ] ) : home_url();
        $url = add_query_arg( array( 'redirect_to' => get_permalink( $edd_options[ 'submit_page' ] ) ), $url );

        $redirect = apply_filters( 'atcf_require_account_redirect', $url );

        wp_safe_redirect( $redirect );
        exit();
    }
}
add_action( 'template_redirect', 'atcf_shortcode_submit_redirect', 1 );

4 个答案:

答案 0 :(得分:0)

你有很多wp_safe_redirect个功能。

atcf_shortcode_submit_redirect()以外的一些内容。

但是我不确定基于您的代码,外面的那些与注册页面没有任何关系。所以你应该改变里面的那个。

这是第一个$url变量:

$url = isset ( $edd_options[ 'login_page' ] ) ? get_permalink( $edd_options[ 'login_page' ] ) : home_url();

正如您所看到的,如果之前没有保存任何选项,则login_page名称重定向网址将是home_url(),这是您的主页链接。

如果你不想将用户重定向到登录页面,你最好去找这个选项(在相关的插件/模板设置页面的某个地方)和检查/填充那个选项,否则将home_url()更改为您想要的任何本地网址(例如"http://mywebsite/successful-page"

答案 1 :(得分:0)

在看到整个代码之前,我不确定插件(或主题)是否在内部工作,但我有点理解。

wp_safe_redirect重定向到给定的url(字符串)。所以试着修补那个。保持复制并将wp_safe_redirect参数更改为“https://google.com”或其他内容。然后你会发现哪个条件语句正在触发并重定向到你的主页。

我认为atcf_shortcode_submit_redirect函数会重定向未登录到登录页面的人,因此它与您的问题无关。

答案 2 :(得分:0)

我想使用javascript document.location。  只需在函数内部编写一个带有单个参数的函数,就可以使用脚本标记提供javascript代码

function redirect($location)
{
//inside the function place the script code 
}
<script language="javascript" type="text/javascript">
    document.location = "here will be your local variable";
</script>

答案 3 :(得分:0)

我知道这是一个老帖子,但万一其他人在寻找答案,这就是我的所作所为。

通过更改$ redirect值,我能够成功将用户重定向到个人资料页面。但是,当用户注销时,它将保留在配置文件页面上并将登录/注册添加到该页面中

无论如何,我安装了彼得的登录重定向并只设置了2个选项: &#34;所有其他用户&#34;将注销URL设置为您想要的任何页面 &#34;注册后网址&#34;将此设置为成功注册后应出现的页面

相关问题