how to deny login from wordpress login page
-
hello, I want to allow only front-end user login and deny the login access page
-
You could use
bp_core_redirect
and hook totemplate_redirect
isnt
bp_core_redirect
for redirect after user login?bp_core_redirect
is for redirecting anytime you like. It uses the WordPress functionwp_safe_redirect
. See here for more info on it:https://codex.wordpress.org/Function_Reference/wp_safe_redirect
ok, thx, but how do I redirect only the buddy users?
Try this:
function redirect_wp_login(){ global $pagenow; if( 'wp-login.php' == $pagenow ) { wp_redirect( home_url() . '/login/', 301 ); exit(); } } add_action( 'init', 'redirect_wp_login' );
Note: Change
/login/
to your login page’s slug.For some reason hooking to
template_redirect
doesn’t work so I’ve hooked in toinit
instead.thank u for try to help me, but I ask again,
I have many needs for diffrent users, one type of users is buddypress, I dont want all my users to connect through front-end, only buddypress users.
in ur suggestion I will redirect all logins to specific loaction.so what I did is :
//redirect buddypress users login to frontpage function redirect_wp_login_buddypress(){ global $pagenow; $prev_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; if ( $prev_url ) { $prev_path = str_replace( home_url(), '', $prev_url ); $page = get_page_by_path( $prev_path ); } if ( $page->ID == '31' && $pagenow == 'wp-login.php') { // buddypress parent page wp_redirect( home_url() . '/?p=31/', 301 ); exit(); } } add_action( 'init', 'redirect_wp_login_buddypress' );
$page->ID == '31'
31 is my buddypress frontend pagethe problem with this is that if user insert incorrect pass or user name, he will not be noticed, also he wont get resend details option,
can u think of a better way?The question is how can you differentiate between your users before they have logged in? i.e. what makes user A different from user B before they have logged in?
After login is a different story, you can differentiate between users easily via several different methods.
if a user came from buddypress page and try to connect he is buddypress user for sure ,but if he got to login page from another place he isnt.
u can see the idea in the func above.
is there a way to pass all the login warnnings like wrong password to the buddypress pageif you are using buddypress theme or child theme, you can easily hook the error message to the sidebar using:
‘add_action ( ‘bp_before_sidebar_login_form’, ‘my_xyz’);’
can u give more details pls,
I tried to edit buddypress\bp-core\bp-core-widgets.php
line 80
<?php else : ?> <?php do_action( 'bp_before_login_widget_loggedout' ); ?> <?php do_action( 'bp_before_sidebar_login_form' ); ?> <form name="bp-login-form" id="bp-login-widget-form" class="standard-form" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post"> <label for="bp-login-widget-user-login"><?php _e( 'Username', 'buddypress' ); ?></label> <input type="text" name="log" id="bp-login-widget-user-login" class="input" value="" /> <br/> <label for="bp-login-widget-user-pass"><?php _e( 'Password', 'buddypress' ); ?></label> <input type="password" name="pwd" id="bp-login-widget-user-pass" class="input" value="" /> <div class="forgetmenot"><label><input name="rememberme" type="checkbox" id="bp-login-widget-rememberme" value="forever" /> <?php _e( 'Remember Me', 'buddypress' ); ?></label></div> <input type="submit" name="wp-submit" id="bp-login-widget-submit" value="<?php _e( 'Log In', 'buddypress' ); ?>" /> <?php if ( bp_get_signup_allowed() ) : ?> <span class="bp-login-widget-register-link"><?php printf( __( '<a href="%s" title="Register for a new account">Register</a>', 'buddypress' ), bp_get_signup_page() ); ?></span> <?php endif; ?>
and no results
- The topic ‘how to deny login from wordpress login page’ is closed to new replies.