w3all Public functions - groups roles switches

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

Re: W3all Public functions

Post by axew3 »

Hello Brian,
I just finished and prepared yesterday night 2 different:

Code: Select all

function w3all_wp_phpbb_user_groupSwitch_phpbb_wp( $phpbb_u_list_ids_emails_phpbbGroups = '', $phpbbGroups_wpRoles_schema = '' ){
and

Code: Select all

function w3all_wp_phpbb_user_groupSwitch_wp_phpbb( $wp_u_list_ids_emails = '', $wp_u_list_ids_emails_and_roles = '', $wpRoles_phpbbGroups_schema = '' ){

phpBB to WP

the

Code: Select all

function w3all_wp_phpbb_user_groupSwitch_phpbb_wp( $phpbb_u_list_ids_emails_phpbbGroups = '', $phpbbGroups_wpRoles_schema = '' ){
can be called as internal function, within any other function or class into any plugin, or used like an API: if it exists certain vars into the request, then the function execute tasks based on passed $_POST vars, maybe due to a phpBB cURL request, but can be easily switched to work fine with any other script just changing few easy things on it. If do not exist an $_POST request, then the function assume and go to process the vars passed as argument. It work awesome, accepting any number of users to be processed each time (but would be not good, as the code is, to process thousand per time). But we can assume that it will be used most of the time for calls within hooks that aims to process a single user or few for each call and anyway, calls to the function can be easily throttled in rare cases where it could be necessary, for example maybe due to an automated and external script that call it and which requirement is to mass move users roles, after a migration.
The param $phpbbGroups_wpRoles_schema allow to have into this case, a predictable behavior that can be applied the same for any scenario.
In WordPress can be removed an user from the main role and assign a new one with easy.
I do not remember if there is a scenario where an user in WP can belong to more than one role.
If yes, the code can be easily modified to accomplish and fit any scenario.
And as it will be by default, it consider to remove the WP Role on key 0, substituting it with the new one, based on the passed schema.
If a schema param is not provided, it will be used the default one.


WP to phpBB

while the

Code: Select all

function w3all_wp_phpbb_user_groupSwitch_wp_phpbb( $wp_u_list_ids_emails = '', $wp_u_list_ids_emails_and_roles = '', $wpRoles_phpbbGroups_schema = '' ){
works only as internal function (using db queries only).
It is intended to be used into any hook or class within WP.
It accept into the first param the WP user ID(s) or email(s) (1 or more separated by comma), then it switch into phpBB the user's group so to be the corresponding one, based on the passed schema. If a schema will not be provided as param, the default one will be used.
The $wp_u_list_ids_emails_and_roles = '', param is not used at all at moment, but result to be useful to be implemented in certain circumstances, where to make it lighter the function work, if we know at the time that we call the function, not only the user's email or ID, but also the value of his actual WP user Role, we can pass it together with the userID or email. But will be not mandatory nor default, just a plus.
brianp6
User w
User w
Posts: 6
Joined: Thu Aug 15, 2024 8:10 pm

Re: W3all Public functions

Post by brianp6 »

Thank you, looks good.
Do you know when you are planning for these latest changes to be released?

many thanks,
Brian.
User avatar
axew3
w3all User
w3all User
Posts: 2862
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: W3all Public functions

Post by axew3 »

2.9.0
I hope just in these days to release it!
User avatar
axew3
w3all User
w3all User
Posts: 2862
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: W3all Public functions

Post by axew3 »

I liked to add

Code: Select all

function w3all_wp_phpbb_USER_groupSwitch_wp_phpbb( $wpu_email_id = '', $phpbbGroupsAdd = '', $phpbbGroupsRemove = '' ){
which get 3 params:

wpu_email_id email or id of the WP user
phpbbGroupsAdd list of groups ID/s where the user need to be added to (separated by comma)
phpbbGroupsRemove list of groups ID/s where the user need to be removed from (separated by comma)

but will be also another function named instead

Code: Select all

function w3all_wp_phpbb_USERS_groupSwitch_wp_phpbb( $wp_u_list_ids_emails = '', $wp_u_list_ids_emails_and_roles = '', $wpRoles_phpbbGroups_schema = '' ){
these two params

Code: Select all

$wp_u_list_ids_emails_and_roles = '', $wpRoles_phpbbGroups_schema = ''
can be used as necessary, the one or the other will be processed as needed based on, if the one or the other is empty or not.

that's more complex because will manage multiple users groups switches based on these two params.
So this second, since the first can be used also into a loop to achieve the same exact result (on filters and hooks)
i am not sure if i will be able to complete it as i intended before 2.9.1.
It will be probably released as basic on 2.9.0 then completed on 2.9.1.
User avatar
axew3
w3all User
w3all User
Posts: 2862
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: W3all Public functions

Post by axew3 »

4 params:

Code: Select all

function w3all_wp_phpbb_USER_groupSwitch_wp_phpbb( $wpu_email_id = '', $phpbbGroupsAdd = '', $phpbbGroupsRemove = '', $phpbbGroupDefault = '' ){

     # $wpu_email_id - the WP user email or user id
     # $phpbbGroupDefault - The default phpBB user group into which the user will be set
     # $phpbbGroupAdd - phpBB Groups ids where the user will be added (single or separated by comma)
     # $phpbbGroupRemove - phpBB Groups ids where the user will be removed from (single or separated by comma)
User avatar
axew3
w3all User
w3all User
Posts: 2862
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: W3all Public functions

Post by axew3 »

It is easy to say 4 params, when then you figure out that:
if it is not removed any and each userID record from the user_group table, before to insert the new one, or more then one it is the same, a duplicate record insertion happen!
And i have not find out a valid work around for this.
Why it happen is a mystery to me at moment, but i noted the same into some other aspect, when inserting in WP a new user (in this case the duplicate insertion is done into WP).
I suspect then, or there is a bug some way into the library used by wordpress, that is a (custom?) ezSQL libraryor there is something wrong somewhere else or even, i still do not have understand something.

Anyway so, to fix it, the function will work this way with 3 params:

Code: Select all

function w3all_wp_phpbb_USER_groupSwitch_wp_phpbb( $wpu_email_id = '', $phpbbGroupsAdd = '', $phpbbGroupDefault = '' ){
when it is executed, the function REMOVE the phpBB user from any and each group which the user belong to, then will re-add following values of:
$phpbbGroupsAdd groupID or IDs separated by comma which the user will be added to
$phpbbGroupDefault the default group which the user will be set to

P.s
it has been an hard fight to understand why the double insertion happen.
That i have not win at moment.
I will maybe open a topic where someone could apply the code and test what i really mean.
It is very strange behavior that have not a possible reason to be for me.
Post Reply