{"id":6611,"date":"2022-12-21T12:36:13","date_gmt":"2022-12-21T11:36:13","guid":{"rendered":"https:\/\/www.axew3.com\/w3\/?p=6611"},"modified":"2024-06-12T12:20:40","modified_gmt":"2024-06-12T10:20:40","slug":"phpbb-wordpress-roles-groups-switch","status":"publish","type":"post","link":"https:\/\/www.axew3.com\/w3\/2022\/12\/phpbb-wordpress-roles-groups-switch\/","title":{"rendered":"Switch WP user to specified Group in phpBB, when Role updated in WordPress and vice versa"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">WP_w3all phpBB integration <strong>2.6.8&gt;<\/strong> option<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0);color:#ff0d00\" class=\"has-inline-color\"><strong>Read all the follow<\/strong><\/mark> before to activate the option<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># The groups\/roles integration can be complex as more like\n# It is substantially quite hard to put here any possible combination of things expecting that it will fit the required for any possible scenario.\n# This file (<strong>wpRoles_phpbbGroups.php<\/strong>) can be edited as more like, and can be copied into the 'wp-content\/plugins\/<strong>wp-w3all-custom<\/strong>\/wpRoles_phpbbGroups.php' folder\n# so that when the plugin will update, custom modifications will not be lost<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Basic default WP Roles and phpBB groups switches will work as follow by default, if no custom file provided:<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">When an <strong>admin in WordPress update an user <\/strong>Role, or Role change due to user&#8217;s subscriptions:<\/h5>\n\n\n\n<p class=\"has-light-gray-background-color has-background wp-block-paragraph\"><strong>Editor in WP<\/strong> or Woocommerce <strong>Shop Manager<\/strong>, will be added into the <strong>Global Moderator group as primary group in phpBB<\/strong>, the previous primary user&#8217;s group membership will be removed.<br><strong>Author, Contributor<\/strong> or <strong>Subscriber<\/strong> or <strong>Woocommerce customer<\/strong>, will be added into the  <strong>Registered group in phpBB<\/strong>, the previous primary group membership will be removed.<br><strong>Administrator<\/strong> in WP will be set as <strong>Administrator<\/strong> in phpBB (not with all founder&#8217;s powers), the previous primary user&#8217;s group membership will be removed. The User with <strong>No role<\/strong> in WP will be <strong>deactivated<\/strong> in phpBB.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">When an <strong>user change\/update group<\/strong> in phpBB:<\/h5>\n\n\n\n<div class=\"wp-block-group has-light-gray-background-color has-background has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\">If belong as default group to the <strong>Registered<\/strong> phpBB group, will be updated in WP to <strong>Subscriber <\/strong>and the previous primary Role removed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If belong as default group to the <strong>Global Moderators <\/strong>phpBB group, will updated in WP to <strong>Editor<\/strong> and the previous primary Role removed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Administrators<\/strong> in this case are not considered by default. But you can activate the code about, into<\/p>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">the file <code>wp-content\/plugins\/wp-w3all-phpbb-integration\/common\/<strong>wpRoles_phpbbGroups.php<\/strong><\/code> . It contain the code that can be customized as more like to get complex <em>WP Roles<\/em> and <em>phpBB Groups<\/em> switches. It already contain basic code example and basic hints. Advanced wp coders will find out that&#8217;s quite easy to write owns code snippets and achieve any kind of complex Roles\/Groups switches. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-dark-red-color\">How i can customize the file<\/mark><\/strong> <code><strong>wpRoles_phpbbGroups.php<\/strong><\/code> expecting that when the integration plugin will update, <strong>modifications done into this file aren&#8217;t lost<\/strong>?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create a folder<\/strong> (if you did not it already, activating the custom <em>\/views<\/em> files option) named <strong><em>wp-w3all-custom<\/em><\/strong> inside the folder <strong><em>\/wp-content\/plugins\/<\/em><\/strong> so you&#8217;ll have <em>\/wp-content\/plugins\/<\/em><strong><em>wp-w3all-custom\/<\/em><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>copy the file<\/strong> <em>\/wp-content\/plugins\/wp-w3all-phpbb-integration\/common\/<strong>wpRoles_phpbbGroups.php<\/strong><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">and paste it inside the created folder, so you&#8217;ll have <em>\/wp-content\/plugins\/wp-w3all-custom\/<strong>wpRoles_phpbbGroups.php<\/strong><\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Custom files inside this folder, are not overwritten when the plugin will be updated (like all the custom views files).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong> that the option <em>Use custom files to display Last Topics Widgets, Login Widget and Shortcodes<\/em> <strong>do not affect this<\/strong>. If the custom file <em>\/wp-content\/plugins\/wp-w3all-custom\/<strong>wpRoles_phpbbGroups.php<\/strong><\/em> exist, it will be included, <strong>even if the<\/strong> <em>Use custom files to display Last Topics Widgets, Login Widget and Shortcodes<\/em> <strong>option is set to No<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Advanced and common hints<\/h3>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Where the <code>wpRoles_phpbbGroups.php<\/code><\/strong> file <strong>is included?<\/strong><\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-dark-red-color\">About a WP Admin<\/mark> that update an user role (the update will be synchronous)<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open: <code>\/wp-content\/plugins\/wp-w3all-phpbb-integration\/<\/code><strong><code>class.wp.w3all-phpbb.php<\/code> <\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">search for: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if( $w3all_link_roles_groups<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"> inside<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>public static function phpbb_update_profile($user_id, $old_user_data) {<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-dark-red-color\">Current WP logged in user<\/mark> updates (the update will be asynchronou<strong>s)<\/strong><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">an user that changed Group in phpBB side** and <strong>that so will be updated to the related WP Role when as logged in will visit WordPress<\/strong>, search for:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if($w3all_link_roles_groups &gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"> into <code>\/wp-content\/plugins\/wp-w3all-phpbb-integration\/<strong>class.wp.w3all-phpbb.php<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">inside the <code>function verify_phpbb_credentials()<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>About<\/strong> Memberpress or others external memberships plugins:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  \/\/ **** MemberPress note: do not know if it is a bug of the version 10 Legacy i am testing on, or a default behavior, but when an user is set as NoRole in WordPress, WP set\/leave the user as subscriber by the way.\n  \/\/ So that it is necessary to detect that the user may have not an active mepr subscriptions\/memberships and deactivate or move the user into another group in phpBB if the case\n<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-left wp-block-paragraph\">Remember: this is a WP plugin, it run ONLY in WP side! So it has been defined <strong>synchronou<strong>s<\/strong><\/strong> the Role update when done in WP side updating an user profile. In this case the update occur at same time in phpBB. It is <strong>asynchronous<\/strong> when the WP role change due to some other reason, for example due to some Role update that fire on the background, after a subscribed membership or something else, but the affected user is not currently logged in into WordPress.<\/p>\n\n\n\n<p class=\"has-text-align-left wp-block-paragraph\">It is also <strong>asynchronou<strong>s<\/strong><\/strong> if the user change profile&#8217;s data in phpBB, because until the same user will not visit the WP side as logged, no code will run to update his Role in WP.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-bright-blue-color\">Read more inline hints<\/mark><\/strong> into the file <em><strong>wpRoles_phpbbGroups.php<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># The groups\/roles integration can be complex as more like\n# It is substantially quite hard to put here any possible combination of things expecting that it will fit the required for any possible scenario.\n# This file can be edited as more like, and can be copied into the 'wp-content\/plugins\/wp-w3all-custom\/wpRoles_phpbbGroups.php' folder\n# so that when the plugin will update, custom modifications will not be lost<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Could be all <strong>synchronous<\/strong>? Yes, the result can be achieved in several ways, for any configuration or\/and plugin\/extension installed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A basic <strong>One Way<\/strong> (WP to phpBB only) explained <strong>example is here<\/strong> (read all answers):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.axew3.com\/w3\/forums\/viewtopic.php?t=1806\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.axew3.com\/w3\/forums\/viewtopic.php?t=1806<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WP_w3all phpBB integration 2.6.8&gt; option Read all the follow before to activate the option Basic default WP Roles and phpBB groups switches will work as follow by default, if no custom file provided: When an admin in WordPress update an user Role, or Role change due to user&#8217;s subscriptions: Editor in WP or Woocommerce Shop [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[213,42,212,214,41],"class_list":["post-6611","post","type-post","status-publish","format-standard","hentry","category-wordpress-phpbb-integration","tag-groups","tag-phpbb","tag-roles","tag-switch","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/posts\/6611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/comments?post=6611"}],"version-history":[{"count":2,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/posts\/6611\/revisions"}],"predecessor-version":[{"id":8109,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/posts\/6611\/revisions\/8109"}],"wp:attachment":[{"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/media?parent=6611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/categories?post=6611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.axew3.com\/w3\/wp-json\/wp\/v2\/tags?post=6611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}