I am developing custom login/ logout functionality in my custom wp theme, the problem is that admin cannot directly access the wp-admin ie dashboard by typing example.com/wp-admin, but when admin log in on front and then type example.com/wp-admin only then he can access dashboard directly with out going to wp-login form.
function login_user($creds=""){
$admin = current_user_can("manage_options");
if (isset($creds)){
wp_signon($creds,false);
if ( is_wp_error($user) ){
echo $user->get_error_message();
}elseif(!$admin){
wp_redirect(home_url());
}
}
}
add_action( 'after_setup_theme', 'login_user' );
function login_user($creds=""){
$admin = current_user_can("manage_options");
if (isset($creds)){
$user= wp_signon($creds,false);
if ( is_wp_error($user) ){
echo $user->get_error_message();
}elseif(!$admin){
wp_redirect(home_url());
}
}
}
add_action( 'after_setup_theme', 'login_user' );
You are not setting a value for $user which should have been returned by wp_signon(). Try the code above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.