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

admin2025-06-06  8

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:

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/g50consultants

Share Improve this question edited Apr 1, 2016 at 11:29 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Apr 1, 2016 at 10:35 Sanjay GoswamiSanjay Goswami 3341 gold badge3 silver badges15 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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.

Maybe your switching from https to http after login, you can try this plugin https://wordpress/plugins/https-redirection/ to redirect all your site to https, I used it once and also changed my site URL from http://... to https://.... in wodpress settings.

I see that you can simplify your code in these lines:

else {
  $redirect_to = home_url().'/members/'.$user->user_login.'/profile'; 
  wp_redirect($redirect_to);
  exit;
}

Beacuse the wp_signon function create all the sessions and fill the current user functions.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749172776a316974.html

最新回复(0)