Simple Membership . Password empty or invalid

pennymachines
User www
User www
Posts: 96
Joined: Mon Feb 06, 2017 9:51 pm

Re: Simple Membership . Password empty or invalid

Post by pennymachines »

Thank you and sorry about my misunderstanding.
The new user is now auto-logged on.

I have "After Registration Redirect URL" set in Simple Membership to the member login page, but the page redirect after auto-logon goes to sub homepage. This happens even if I remove

Code: Select all

      wp_safe_redirect( home_url() );
      exit;
or if I add

Code: Select all

$member_login_url = 'https://mysite.com/subsite1/member-login/';
 if( isset($_POST['swpm_registration_submit']) && isset($_POST['password']) )
 {
   if( wp_check_password($_POST['password'], $wpu->user_pass, $wpu->ID) )
    {
      self::phpBB_user_session_set_res($wpu);
      wp_safe_redirect( $member_login_url );
      exit;
    }
 }
Not a big problem in itself, but maybe an indication of underlying conflict/incompatibility?

More significantly, if a logged in user navigates to the Simple Membership member profile page, they see, "You are not logged in."
If they navigate to the member login page [if (is_user_logged_in())] they are shown as logged in.
User avatar
axew3
w3all User
w3all User
Posts: 3054
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Simple Membership - login logut autologin fixes

Post by axew3 »

Resuming all questions in one answer:

NOTE that for WP MU-MS. you have to add this step to correctly register an user:
viewtopic.php?p=7235#p7235

To correctly login the user
through the Simple Membership form:


Open wp-w3all.php
and inside the function wp_check_password($password, $hash, $user_id = '') {
(there are two wp_check_password functions into the wp_w3all.php file, maybe apply to both, but mandatory is to add it the first)
search for lines

Code: Select all

# going to use a direct query in place of get_user_by() before, or the pass hash in this case will not match
$wpu_db_utab = (is_multisite()) ? WPW3ALL_MAIN_DBPREFIX . 'users' : $wpdb->prefix . 'users';
$wpu = $wpdb->get_row("SELECT * FROM $wpu_db_utab WHERE ID = '".$user_id."'");
 
Just after add this code:

Code: Select all

if( empty($wpu) && !empty($_POST['swpm_user_name']) ){
  $wpu = get_user_by( 'login', sanitize_user( $_POST['swpm_user_name'] ) );	
  $user_id = empty($wpu->ID) ? '' : $wpu->ID;
}

To correctly logout the user
on same wp-w3all.php file search for

Code: Select all

add_action( 'wp_logout', array( 'WP_w3all_phpbb', 'wp_w3all_phpbb_logout' ) );
Just after add this:

Code: Select all

add_action('clear_auth_cookie', array( 'WP_w3all_phpbb', 'wp_w3all_phpbb_logout' ) );

To autologin the user after registration
open the file /wp-w3all-phpbb-integration/class.wp.w3all-phpbb.php
and search for the commented lines that starts with

Code: Select all

// FIX AUTOLOGIN for woocommerce or any other plugin:
Just after add this:

Code: Select all

# Available vars to check that we are on Simple Memberships action
# 'swpm_registration_submit'  'swpm_membership_level'  'swpm_level_hash' 
# and maybe 'level_identifier'

 if( isset($_POST['swpm_registration_submit']) && isset($_POST['password']) )
 {
   if( wp_check_password($_POST['password'], $wpu->user_pass, $wpu->ID) )
    {
      self::phpBB_user_session_set_res($wpu);
      wp_safe_redirect( home_url() );
      exit;
    }
 }
Note that home_url() can be any other URL, for example

wp_redirect( home_url( '/my-profile/' ) );
or the default wp user dashboard
wp_redirect( admin_url('profile.php') );
that so maybe will automatically redirected to some front end user's profile page by some other plugin that hide the default WP dashboard to normal users redirecting to his own front-end profile page.
pennymachines
User www
User www
Posts: 96
Joined: Mon Feb 06, 2017 9:51 pm

Re: Simple Membership . Password empty or invalid

Post by pennymachines »

Thank you.

I have edited wp_w3all.php and class.wp.w3all-phpbb.php as instructed. Cleared local and Cloudflare cache. Re-run registration tests.

I'm afraid the auto-logon and page redirect still don't work.

The page redirects back to subsite homepage (not member-login) and the user is not logged on.
The redirect goes to subsite homepage regardless: wp_redirect( home_url( ) ); or wp_redirect( home_url( '/member-login/' ) );

However, if user navigates to https://mysite.com/subsite1/member-login/ and logs on using the form, logon is now successful. Logon also successful via my logon modal. And the other good news - logout now works!
User avatar
axew3
w3all User
w3all User
Posts: 3054
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Simple Membership . Password empty or invalid

Post by axew3 »

pennymachines wrote: Wed Jul 01, 2026 5:46 pm I'm afraid the auto-logon and page redirect still don't work.

The page redirects back to subsite homepage (not member-login) and the user is not logged on.
The redirect goes to subsite homepage regardless: wp_redirect( home_url( ) ); or wp_redirect( home_url( '/member-login/' ) );

However, if user navigates to https://mysite.com/subsite1/member-login/ and logs on using the form, logon is now successful. Logon also successful via my logon modal. And the other good news - logout now works!
Well, snippets perfectly works tested it into a default wordpress with Simple Membership, not a WP multisite installation.
You describe something about the redirect that can be easily resolved.
Why your login redirect to a subsite? Due to some wp admin network setting maybe?
And the user is not logged into the main site or site where the user login?
Are you sure you added the code in the right way?
I will try in a wp multisite asap.
Are you sure you added the code in the right way?
PS WP MUMS is different about some hook, so we just have to add the right one to fire on multisite installations, so despite you added it correctly the code may it will not work.
pennymachines
User www
User www
Posts: 96
Joined: Mon Feb 06, 2017 9:51 pm

Re: Simple Membership . Password empty or invalid

Post by pennymachines »

I'm sorry- this must be very frustrating.

I checked all code edits and ran a new test. I switched off 3 network plugins which I thought could possibly affect auto logons, I reverted to Simple Membership's default member login and registration pages, and I reverted to default (twenty twelve) theme (in case something in my functions.php was affecting auto logons).

Still no change. Newly registered user is directed to subsite home and is not logged on.
axew3 wrote: Wed Jul 01, 2026 8:11 pm Why your login redirect to a subsite? Due to some wp admin network setting maybe?
I can't see anything obvious in my admin network settings. Also, the redirect works fine as soon as I deactivate w3all.
It is perhaps worth mentioning that sometimes (but not always) a link from my phpBB forum to a specific WP subsite page also erroneously directs to subsite1 homepage. I have tried a couple of times to debug this, and then it occurs again. It would appear that there is a default to divert to subsite1 homepage when there is a problem with redirects.
axew3 wrote: Wed Jul 01, 2026 8:11 pm And the user is not logged into the main site or site where the user login?
The user is not logged into main or subsite. To be more accurate, what I am calling subsite1 is my main WP site (on which Simple Membership is activated).

Normally, but not for this test, I have a plugin called "Join My Multisite" network activated. It automatically adds newly registered users to all the subsites when they log in there, so a registered logged in user is logged in to all WP subsites and phpBB.
User avatar
axew3
w3all User
w3all User
Posts: 3054
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Simple Membership . Password empty or invalid

Post by axew3 »

WordPress Multisite MU-MS
I see testing it now, that the create_phpBB_user_wpms do not run when a new user is created on WP MU-MS.
It changed along the time something?
To make it work the autologin upon new user registration and correctly add the user in phpBB:

file class.wp.w3all-phpbb.php

Search for

Code: Select all

private static function create_phpBB_user($wpu, $action = ''){

   if( empty($wpu) ){ return; }
After add:

Code: Select all

if( is_multisite() ){
 self::create_phpBB_user_wpms($wpu);
 return;
}
Then just after the starting line of code (declaration of the function):
private static function create_phpBB_user_wpms($username_id_object = '', $user_email = '', $key = '', $meta = '', $user = ''){

add this:

Code: Select all

  if(empty($user)){
   $user = $username_id_object;
  } 

The user will not be logged in automatically in this case.

Native SM login could be used in some other hook or changing something, anyway, i note that Simple Membership, beside some warning errors appearing all around if you are on DEBUG, use his own way to login users with his own cookie.

Code: Select all

$auth = SwpmAuth::get_instance();
$auth->login( $user->user_login, $_POST['password'] );
Post Reply