Simple Memberships - Login Logout Autologin fixes

User avatar
axew3
w3all User
w3all User
Posts: 3055
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Simple Memberships - Login Logout Autologin fixes

Post by axew3 »

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.

To login the user by phpBB cookie
viewtopic.php?p=7239#p7239