$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>uploads - User logged-in from front end is logged out automatically accessing wp-admin|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin5PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far