4

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

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.

4
  • Sorry. The post is too old and currently I don't have access to that project. Thanks for clarification. Jan 12, 2017 at 19:10
  • 1
    for some reason i found this question on the top, so i answer it :) Jan 13, 2017 at 18:24
  • I'm facing this issue and none of your solution is solving it Jul 11, 2021 at 22:52
  • The answer dated 2017-01-10, WordPress core updated a lot, you might want to enable WP_DEBUB, and take a look if anything interesting int the debug.log file also you might need to post a new question with your findings. Jul 12, 2021 at 5:04
1

Maybe your switching from https to http after login, you can try this plugin https://wordpress.org/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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.