Add phpBB users to custom WordPress groups/roles

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

Re: Add phpBB users to custom WordPress groups/roles

Post by axew3 »

IMPORTANT: after some time, and as ever, i re-think on all what i do, so some other have come out: your posts words above let me think to the fact that the joke maybe work if the user come as logged into phpBB to wordpress, but not work if the user will be added due to a different scenario:
the user isn't logged into phpBB, and come to login first time into WP side.
There is also an error on code.
To fix this, the same code need to be applied also into another function, on same file class.wp.w3all-phpbb.php that is function
public static function w3_check_phpbb_profile_wpnu($username){
inside there is this code:

Code: Select all

      if ( $phpbb_user[0]->group_name == 'ADMINISTRATORS' ){
      	      $role = 'administrator';
      	      $u_role = 'a:1:{s:13:"administrator";b:1;}';
            } elseif ( $phpbb_user[0]->group_name == 'GLOBAL_MODERATORS' ){
            	   $role = 'editor';
            	   $u_role = 'a:1:{s:6:"editor";b:1;}';
               } else { 
               	$role = 'subscriber';  // for all others phpBB Groups default to WP subscriber
               	$u_role = 'a:1:{s:10:"subscriber";b:1;}'; 
               } 
actually it need to be changed also BECAUSE IT IS WRONG, into this (that is +- the same as on private static function verify_phpbb_credentials(){), so

Code: Select all

   if ( $phpbb_user[0]->group_name == 'ADMINISTRATORS' ){
      	  $role = 'administrator';
      	} elseif ( $phpbb_user[0]->group_name == 'GLOBAL_MODERATORS' ){
          $role = 'editor';
        }  else { $role = 'subscriber'; }  // for all others phpBB Groups default to WP subscriber
    
and apply modifications in the way like above explained. Note: here the array is $phpbb_user[0]->group_name and not $phpbb_user_session[0]->group_name
This part will be updated as soon on repo, and the file patched because containing wrong code and was not working properly. After the error, any user were added as subscriber in WP when coming to login WP first time.
1.8.9 will be released as soon, containing all 1.8.8 fixes.

[EDITED]
patch class.wp.w3all-phpbb.php into function
public static function w3_check_phpbb_profile_wpnu($username){
to fix code about new phpBB user addition in wordpress, when login wordpress first time


1.8.9 has been released.
User avatar
axew3
w3all User
w3all User
Posts: 2937
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Add phpBB users to custom WordPress groups/roles

Post by axew3 »

To resume here, as on 1.8.9 just released version:
to add the custom phpBB group role addition to match as you want it in wordpress, you need to apply modifications into two points, on file class.wp.w3all-phpbb.php.
One is for when an user is coming as already logged in phpBB and need to be added in WP, inside function
private static function verify_phpbb_credentials(){
this is the code to change:

Code: Select all

      if ( $phpbb_user_session[0]->group_name == 'ADMINISTRATORS' ){
      	      
      	      $role = 'administrator';
      	      
            } elseif ( $phpbb_user_session[0]->group_name == 'GLOBAL_MODERATORS' ){
        
            	   $role = 'editor';
          	  
               }  else { $role = 'subscriber'; }  // for all others phpBB Groups default to WP subscriber

and one is to add an user in wordpress when login wordpress first time (and isn't logged in phpBB already), inside function
public static function w3_check_phpbb_profile_wpnu($username){
this is the code to change:

Code: Select all

if ( $phpbb_user[0]->group_name == 'ADMINISTRATORS' ){
      	  $role = 'administrator';
      	} elseif ( $phpbb_user[0]->group_name == 'GLOBAL_MODERATORS' ){
          $role = 'editor';
        }  else { $role = 'subscriber'; }  // for all others phpBB Groups default to WP subscriber
mLgz0rn
User ww
User ww
Posts: 42
Joined: Fri Jan 20, 2017 5:23 pm

Re: Add phpBB users to custom WordPress groups/roles

Post by mLgz0rn »

Thanks alot mate!
I've updated the plugins, and updated the changes you suggested!
mLgz0rn
User ww
User ww
Posts: 42
Joined: Fri Jan 20, 2017 5:23 pm

Re: Add phpBB users to custom WordPress groups/roles

Post by mLgz0rn »

Looks like it does not work after updating to 1.8.9 and making the changes to the file that you suggested
User avatar
axew3
w3all User
w3all User
Posts: 2937
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Add phpBB users to custom WordPress groups/roles

Post by axew3 »

you may refer to the part, when an user need to be added on wp login (not coming logged from phpBB) ...
note that the array, as said before, is different, then on
public static function w3_check_phpbb_profile_wpnu($username){
where code:

Code: Select all

if ( $phpbb_user[0]->group_name == 'ADMINISTRATORS' ){
      	  $role = 'administrator';
      	} elseif ( $phpbb_user[0]->group_name == 'GLOBAL_MODERATORS' ){
          $role = 'editor';
        }  else { $role = 'subscriber'; }  // for all others phpBB Groups default to WP subscriber
you need to use
$phpbb_user[0]->group_name

and not
$phpbb_user_session[0]->group_name
that you'll use instead in the code of private static function verify_phpbb_credentials(){

Code: Select all

        if ( $phpbb_user_session[0]->group_name == 'ADMINISTRATORS' ){
      	      
      	      $role = 'administrator';
      	      
            } elseif ( $phpbb_user_session[0]->group_name == 'GLOBAL_MODERATORS' ){
        
            	   $role = 'editor';
          	  
               }  else { $role = 'subscriber'; }  // for all others phpBB Groups default to WP subscriber
the code could be changed naming the array the same, it will be done on next 1.9.0.
mLgz0rn
User ww
User ww
Posts: 42
Joined: Fri Jan 20, 2017 5:23 pm

Re: Add phpBB users to custom WordPress groups/roles

Post by mLgz0rn »

Hmm, well I got it like this?

private static function verify_phpbb_credentials()

Code: Select all

        if ( $phpbb_user_session[0]->group_name == 'ADMINISTRATORS' ){
      	      
      	      $role = 'administrator';
      	      
            } elseif ( $phpbb_user_session[0]->group_name == 'GLOBAL_MODERATORS' ){
        
            	   $role = 'editor';
          	  
			}  elseif ( $phpbb_user_session[0]->group_name == 'Raider' ){
        
            	   $role = 'raider';
				   
			}  elseif ( $phpbb_user_session[0]->group_name == 'Trial Raider' ){
        
            	   $role = 'trial';
				   
			}  elseif ( $phpbb_user_session[0]->group_name == 'Social' ){
        
            	   $role = 'social';
				   
			}  elseif ( $phpbb_user_session[0]->group_name == 'Officer' ){
        
            	   $role = 'officer';
				   
			}  elseif ( $phpbb_user_session[0]->group_name == 'GM' ){
        
            	   $role = 'guild-master';
				   
               }  else { $role = 'subscriber'; }  // for all others phpBB Groups default to WP subscriber
public static function w3_check_phpbb_profile_wpnu($username)

Code: Select all

     if ( $phpbb_user[0]->group_name == 'ADMINISTRATORS' ){
      	  $role = 'administrator';
      	} elseif ( $phpbb_user[0]->group_name == 'GLOBAL_MODERATORS' ){
          $role = 'editor';
		}  elseif ( $phpbb_user[0]->group_name == 'Raider' ){
          $role = 'raider';
		}  elseif ( $phpbb_user[0]->group_name == 'Trial Raider' ){
          $role = 'trial';
		}  elseif ( $phpbb_user[0]->group_name == 'Social' ){
          $role = 'social';
		}  elseif ( $phpbb_user[0]->group_name == 'Officer' ){
          $role = 'officer';
		}  elseif ( $phpbb_user[0]->group_name == 'GM' ){
          $role = 'guild-master';
        }  else { $role = 'subscriber'; }  // for all others phpBB Groups default to WP subscriber
This seems correct?

I am sure that group_name and role is correct, as it worked before.
Post Reply