我有一个简短的代码函数,用于呈现联盟登录的登录表单(与我有“my-account”页面的普通用户登录名单独),可以重定向到网址或当前页面。 / p>
function affiliates_login_redirect( $atts, $content = null ) {
extract( shortcode_atts( array( 'redirect_url' => '' ), $atts ) );
$form = '';
if ( !is_user_logged_in() ) {
if ( empty( $redirect_url ) ) {
$redirect_url = get_permalink();
}
$form = wp_login_form( array( 'echo' => false, 'redirect' => $redirect_url ) );
}
return $form;
}
它工作正常但是,如果登录表单中存在无效条目或字段保持为空,则会重定向到wp-login.php
我检查了包含http://www.markomedia.com.au/wordpress-login-widget-redirect-prevention/的选项 但我不确定如何使用该解决方案以及我的短代码功能。我可以将它添加到functions.php,但关注的是我还启用了woocommerce,这会在我的帐户页面下生成一个单独的登录表单,用于普通用户登录。
有人可以帮忙吗?提前谢谢。
答案 0 :(得分:1)
get_permalink();
中的
传递要重定向的页面的ID
<?php echo get_page_link(40); ?>
试试这个(提供您网页的ID)
function affiliates_login_redirect( $atts, $content = null ) {
extract( shortcode_atts( array( 'redirect_url' => '' ), $atts ) );
$form = '';
if ( !is_user_logged_in() ) {
if ( empty( $redirect_url ) ) {
$redirect_url = echo get_page_link(40);
}
$form = wp_login_form( array( 'echo' => false, 'redirect' => $redirect_url ) );
}
return $form;
}
答案 1 :(得分:0)
function custom_authenticate( $user, $username, $password ) {
if ( is_wp_error( $user ) && isset( $_SERVER[ 'HTTP_REFERER' ] ) && !strpos( $_SERVER[ 'HTTP_REFERER' ], 'wp-admin' ) && !strpos( $_SERVER[ 'HTTP_REFERER' ], 'wp-login.php' ) ) {
$referrer = $_SERVER[ 'HTTP_REFERER' ];
foreach ( $user->errors as $key => $error ) {
if ( in_array( $key, array( 'empty_password', 'empty_username') ) ) {
unset( $user->errors[ $key ] );
$user->errors[ 'custom_'.$key ] = $error;
wp_redirect( $referrer . '?login=failed' );
}
}
}
return $user;
}
add_filter('authenticate','custom_authenticate', 31, 3);