Page 1 of 1

coming 2.6.8 logs and requests

Posted: Sat Dec 17, 2022 9:11 am
by axew3
2.6.7 has been released to fix a common login issue, and to fix just little more things.

Code: Select all

== Changelog ==

= 2.6.7 =
*Release Date - 16 Dec, 2022*
* Fix: wp_login hook not firing when on wp_login page (when certain plugins installed)
* Fix: little improve last_topics and last_topics_by_forums_ids shorcodes code
* Fix: add cookie samesite param for the phpBB session cookie when on Php 7.4 or better, while leave the old setcookie code for all others olders Php versions
* Fix: minor fixes
* Hint: remember that instead to use the page-forum for the iframe integration, on the new WP templates editor, and themes like WP Twenty Twenty Three, you should use the Awesome iframe integration using shortcode: https://www.axew3.com/w3/2022/02/the-awesome-iframe-template-integration-using-shortcode/

A 2.6.7 request was about phpBB Groups/WP roles integration.
The old long time request never coded may will be considered to be done in some way on next 2.6.8.
Anyway this morning, dedicating some little time to look around this possible feature and how it should be efficiently coded, and effective for any configuration, it result to me that i have very clear how it can be done for a specific configuration, but not so easy to imagine something simple for all uses.
Maybe an array. A configurable array of values where a role/membership in WP will correspond to Groups in phpBB and viceversa.
As said, it is very easy to be coded for specifics, much less for all plugins together- We'll see if it can be surpassed some way.
p.s note that the groups/roles integration will NOT be provided by adding options into plugin admin. I will never code (i think, if not payed almost 100.000$) the UI of something like this, but i think will be easy to be modified and used for any scope by the cool people!

Re: coming 2.6.8 logs and requests

Posted: Tue Dec 20, 2022 11:35 am
by axew3
So i've just test a way to switch users roles/groups between wp and phpBB, and it is very easy to do in "one way", wp to phpBB (example: when an user switched from subscriber to editor, make him global moderator in phpBB, and the contrary etc).
I hooked it for the test into the profile_update action, so into the phpbb_update_profile() function that fire when the user's update occur, but the code can be added to run without hooking it into profile_update action, but maybe into init.
This is especially true if we want some membership plugin like Memberpress interact with this feature. With something like (but there are many ways to achieve same or more complex results)

Code: Select all

           if(current_user_can('mepr-active','rules:111')){
             echo 'yes MEPR membership2 active, move this user to a phpBB group'; exit;
           } else { remove the user from a group }
anyway, as said many times, it is very easy to do for default wp roles/phpBB groups (and it will be added on 2.6.8 as option) and specific scenarios, but to code something that can provide an UI where would be possible to setup options, is not so easy, and as said before i will not code something like this.

WP roles applies to an user, an user can be subscriber or editor or admin etc in wp, but in phpBB an user can belong to more than one group.
So what the code should do when an user is demoted from editor role in wp, to subscriber, and in phpBB the user belong to global admins group and some other group? Remove from these groups or not? May from someone and not some other. It can be complex as more we can imagine, mixing memberships and roles.

It is very easy to do per case, so it will be provided the basic that just will do +- this on code, based on WP roles:

Code: Select all

   #$uid = $w3all_phpbb_connection->get_var("SELECT user_id FROM ".$w3all_config["table_prefix"]."users WHERE LOWER(user_email) = '$old_user_data->user_email'");
   $phpbbug = $w3all_phpbb_connection->get_results("SELECT user_id, group_id FROM ".$w3all_config["table_prefix"]."users WHERE LOWER(user_email) = '$old_user_data->user_email'");
     
     if(empty($phpbbug[0])){ return; } // if the user (still?) do not exist
 
   $uid  = $phpbbug[0]->user_id;
   $ugid = $phpbbug[0]->group_id;

############################################
### START
# Roles -> Groups switches
  
  // **** MemberPress: (do not know if it is a bug of the version i am testing) but when an user is set as NoRole in WordPress,
  // set/leave the user as subscriber by the way. 
  // So that it is necessary another way to detect that the user may have no active mepr subscriptions/memberships and deactivate the user in phpBB if the case
  
  // ** note that here, may you would add memberships from external wp plugins and more complex roles/groups/memberships switches
   include( WPW3ALL_PLUGIN_DIR.'common/wpRoles_phpbbGroups.php' );
   
  // before we check if this user has been set as NoRole in WP    
     if( empty($wpu->roles) )
      { // no role for this site, deactivate in phpBB
        $w3all_phpbb_connection->query("UPDATE ".$w3all_config["table_prefix"]."users SET user_type = '1' WHERE user_id = '$uid'");
      }
   
  // if old user's data role do not match, then there is an user role change: update/activate in phpBB based on Roles/Groups array
  // check that the user had a role before 
   if( empty($old_user_data->roles[0]) && !empty($wpu->roles) && !empty($wpRoles_phpBBGroups) 
       OR !empty($wpu->roles) && $old_user_data->roles[0] != $wpu->roles[0] && !empty($wpRoles_phpBBGroups) ) // **
   { // retrieve all groups which the user belong to (for more complex roles/groups switches)
     $uid_groups = $w3all_phpbb_connection->get_results("SELECT * FROM ".$w3all_config["table_prefix"]."user_group WHERE user_id = $uid");

       if( $wpu->roles[0] == 'subscriber' OR $wpu->roles[0] == 'contributor' )
       {
     	   if( $ugid != 2 )
     	   {
     	 	  $w3all_phpbb_connection->query("UPDATE ".$w3all_config["table_prefix"]."users SET user_type = '0', group_id = '2' WHERE user_id = '$uid'");
      	  // on duplicate key is not possible, there is no index into the user_group table: remove the record if exist before to insert again
      	  // even if the user_group table can contain duplicated values
      	  // *** also note that here, may the phpBB user should be removed from any other group, which may belong to into phpBB 
      	  $w3all_phpbb_connection->query("DELETE FROM ".$w3all_config["table_prefix"]."user_group WHERE user_id = '$uid' AND group_id IN('2','$ugid')");
          $w3all_phpbb_connection->query("INSERT INTO ".$w3all_config["table_prefix"]."user_group (group_id, user_id, group_leader, user_pending) VALUES ('2','$uid','0','0')");
     	   } 
     	 } elseif( $wpu->roles[0] == 'editor' && $ugid != 4 )
         {
     	 	  $w3all_phpbb_connection->query("UPDATE ".$w3all_config["table_prefix"]."users SET user_type = '0', group_id = '4' WHERE user_id = '$uid'");
      	  // same as above
      	  $w3all_phpbb_connection->query("DELETE FROM ".$w3all_config["table_prefix"]."user_group WHERE user_id = '$uid' AND group_id IN('4','$ugid')");
          $w3all_phpbb_connection->query("INSERT INTO ".$w3all_config["table_prefix"]."user_group (group_id, user_id, group_leader, user_pending) VALUES ('4','$uid','0','0')");
       	  } elseif( $wpu->roles[0] == 'administrator' && $ugid != 5 )
            {
     	 	     $w3all_phpbb_connection->query("UPDATE ".$w3all_config["table_prefix"]."users SET user_type = '0', group_id = '5' WHERE user_id = '$uid'");
      	     // same as above
      	     $w3all_phpbb_connection->query("DELETE FROM ".$w3all_config["table_prefix"]."user_group WHERE user_id = '$uid' AND group_id IN('5','$ugid')");
             $w3all_phpbb_connection->query("INSERT INTO ".$w3all_config["table_prefix"]."user_group (group_id, user_id, group_leader, user_pending) VALUES ('5','$uid','0','0')");
       	    }
    }

     # if(current_user_can('mepr-active','rules:111')){
     #  # the user belong and is active on mepr Rule ID 111
     # }
     
# Roles -> Groups switches
### END
############################################
in words:
if an user is promoted to author in wp, will be moved to global moderator group as primary group in phpBB, the previous primary group membership will be removed.
If an user is demoted from author to contributor or subscriber, will be moved to registered group in phpBB, the previous primary group membership will be removed.
Same goes for administrator.

All works so smooth, but what else can be considered?
1) should be the user removed from any other group which belong to in phpBB, when role updated in WP (so that the primary in phpBB update also, and should be the unique one?
Considering the one way, the default code will NOT remove the user from more groups, but only update the primary (which maybe is the unique one normally).
Set the user as deactivated when NoRole in WP.

2) About MemberPress:
// **** MemberPress: (do not know if it is a bug of the version i am testing) but when an user is set as NoRole in WordPress,
// set/leave the user as subscriber by the way.
// So that it is necessary another way to detect that the user may have no active mepr subscriptions/memberships and deactivate the user in phpBB if the case
will follow more logs...

Re: coming 2.6.8 logs and requests

Posted: Wed Dec 21, 2022 9:41 pm
by axew3
WP_w3all phpBB integration 2.6.8> option

(admin - user profile update)

Author in WP or Woocommerce Shop Manager, will be added into the Global Moderator group as primary group in phpBB, the previous primary user's group membership will be removed.
Contributor or Subscriber or Woocommerce customer, will be added into the Registered group in phpBB, the previous primary group membership will be removed.
Administrator in WP will be set as Administrator in phpBB (not with all founder's powers), the previous primary user's group membership will be removed.

User with No role in WP will be deactivated in phpBB.

Re: coming 2.6.8 logs and requests

Posted: Sat Dec 31, 2022 6:42 pm
by axew3
The w3all_phpbb_unotifications shortcode code has been rewritten to work into any phpBB setup. The notifications.type.id, never match the same into different installations, because IDS of types are not created all in once when phpBB installed, but at runtime when those kind of notifications being activated by some user.
Only firsts default are created when phpBB is installed, but many are not.
The code about has been to fit any configuration.

Re: coming 2.6.8 logs and requests

Posted: Sun Jan 01, 2023 8:35 pm
by axew3
2.6.8 has been released!
About Roles/groups switches (possible option from 2.6.8>)
https://www.axew3.com/w3/2022/12/switch ... le-update/

Re: coming 2.6.8 logs and requests

Posted: Tue Jan 03, 2023 9:47 am
by axew3
The file
/wp-content/plugins/wp-w3all-phpbb-integration/views/wp_w3all_phpbb_unotifications_short.php
https://plugins.trac.wordpress.org/expo ... _short.php
has been updated to fix all remaining bugs and to add
type.forum
type.disapprove_topic
type.disapprove_post

has been updated to fix all remaining bugs and to add latest lacking
You can download the file by clicking the link above and replace into views folder, if you want update to this before the coming 2.6.9 release.

A new log 2.6.9 topic will be opened, this is now closed.

See phpBB user's notifications shortcode page
https://www.axew3.com/w3/2022/10/phpbb- ... wordpress/