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

1

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.

  • Sorry. The post is too old and currently I don't have access to that project. Thanks for clarification. – PlanetHackers Jan 12 '17 at 19:10
  • for some reason i found this question on the top, so i answer it :) – Kudratullah Jan 13 '17 at 18:24
0

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, privacy policy and cookie policy

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