User logged-in from front end is logged out automatically accessing wp-admin

I have stuck in serious problem. I want to create a document and upload a word doc from front end after user login. Logged in user is admin. The plugin bp-doc uses WordPress default media uploader to upload file.

The plugin hits .../wp-admin/async-upload.php, but this throws an error An error occurred in the upload. Please try again later, after debuging in console I found 302 Moved Temporarily error and in response there is WordPress login form.

After doing some research I found another error, when I log in from frontend as an admin and goes back to wp-admin it logged me out and asks again to enter username and password.

I unable to go through the errors, anyone can help me what may goes wrong?

I uses the following code to login

$user_data = array();
$user_data['user_login'] = $username;
$user_data['user_password'] = $password;
$user_data['remember'] = $remember; 

$user = wp_signon( $user_data, false );

if ( is_wp_error($user) ) {

$err = "<strong>ERROR!</strong> Invalid username or password";

} 
else {

  wp_set_current_user( $user->ID);

  do_action('set_current_user');
  global $current_user;
  get_currentuserinfo();
  $redirect_to = home_url().'/members/'.$current_user->user_login.'/profile'; 
  wp_redirect($redirect_to);
  exit;
}

Live site url: https://www.group50.com/g50consultants

2 Answers
2

have you tried by setting the second argument of wp_signon() to true or blank?
set false will prevent wp_signon() from setting secure cookie which is essential for accessing wp-admin if your using ssl.
i have tested and $user = wp_signon( $user_data, true ); works as expected.

Leave a Comment