Add user at same time into WordPress when register/login in phpBB side

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

Add user at same time into WordPress when register/login in phpBB side

Post by axew3 »

Since 2.4.5> use this instead:
https://www.axew3.com/w3/2022/02/phpbb- ... extension/


OBSOLETE since 2.4.4>

Check this for user addition at same time as soon as the registration process in phpBB finish


Force user addition in Wordpress: on first login solution

If using iframe mode, may this snippet isn't necessary, because when user register and then login via iframed phpBB into WP page, the plugin reload the Wordpress page, so add the user into Wordpress also. By the way, you may wish that when user register and then login in phpBB, is forced to be redirected into Wordpress, and added as user into Wordpress , because user isn't surfing the forum in iframe mode, nor maybe will go to visits Wordpress side. You may also want the same user redirected into phpBB, after addition in Wordpress. May not. This code can be used in several ways, with little changes as explained more below and on same inline code comments. To apply:

on your phpBB, with a text editor open file:
includes/functions.php


search for this code:

Code: Select all

function redirect($url, $return = false, $disable_cd_check = false)
{
	global $user, $phpbb_path_helper, $phpbb_dispatcher;
immediately after, add the follow:

Code: Select all

// START w3all redirect to WP onlogin
	// Note: this snippet code on this redirect() function should may be little bit changed and not used as is if iframe (?)
	// see class.wp.w3all-phpbb.php -> // START w3all redirect to phpBB (onlogin to add user in WP)
	// Note: the passed URL to redirect to, is not containing the string portion after '&sid=' that is cut off
	// Note: If you want pass also phpBB sid on URL (because phpBB login work also without cookie active on browser, using sid) maybe you'll remove the line more below where 'REMOVE this line'
	// Note: note also the last REMOVE hint about 'exit;' and iframe mode
	
	// DO NOT ADD FINAL SLASH
	$wordpress_url = 'https://www.axew3.com/wordpress'; // SET HERE the WordPress URL you want to point to - DO NOT ADD FINAL SLASH (or change the code below)
	//
	 global $request;
    if( $request->variable('mode', '') == 'login' ){
     $rurl = stristr(htmlspecialchars_decode($url), '&sid=', true); // 'REMOVE this line' to pass entire URL (with also sid var included) // stristr as of PHP 5.3.0 or > 
     if( strpos($rurl, '/') == 0 ){ $rurl = trim(substr($rurl, 1)); }
     $rurl = base64_encode(generate_board_url() . '/'. str_replace('./', '', $rurl));
      header("Location: $wordpress_url/?w3allAU=$rurl"); 
     exit; // REMOVE or comment this 'exit;' if on redirect to iframe page (because login is done in iframe mode) it cause on redirect, that the iframed forum page return a blank page (iframe not loaded, even if on output source code all seem to be ok...)
   }
// END w3all redirect to WP onlogin
on the added code, change the code line:

Code: Select all

$wordpress_url = 'https://www.axew3.com/wordpress'; 
to point to your WordPress URL.

Note also that if you not wish to redirect users into phpBB, after they have been redirected by phpBB (onlogin) into Wordpress for addition, change this line:

Code: Select all

header("Location: $wordpress_url/?w3allAU=$rurl"); 
into

Code: Select all

header("Location: $wordpress_url/");
because without passing the var w3allAU and related value, the plugin will not redirect to phpBB, after user addition in Wordpress, and WordPress will be loaded.
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Add user at same time into WordPress when register/login in phpBB side

Post by axew3 »

For solution at same time when user terminate registration process in phpBB (linked above):
register phpbb users in wordpress at same time
Post Reply