Code to create link to user's phpBB profile

teebling
User w
User w
Posts: 11
Joined: Wed Jun 10, 2020 4:26 pm

Code to create link to user's phpBB profile

Post by teebling »

Hello,

Is there any PHP code available that lets logged in users on the Wordpress side visit their phpBB profile?

I've tried myself already with this:

<a href="/memberlist.php?mode=viewprofile&u=<?php global $current_user; get_currentuserinfo(); echo '' . $current_user->ID . "
"; ?>">


This successfully takes the user to a phpBB profile page, but it's not the correct user. Why? Because the user IDs in wordpress don't match the user IDs in phpBB - this is because phpBB user IDs are higher, because bot users have IDs. For example:

A user has phpBB ID 54.

But because there are 45 bots in phpBB, and these bots are not added to Wordpress, it means that once transferred to WP via the w3all transfer, their user ID will be 9.

So I thought okay, no problem, I'll just get PHP to add on the extra 45 to the user number in the link:

<a href="/memberlist.php?mode=viewprofile&u=<?php global $current_user; get_currentuserinfo(); echo '' . $current_user->ID + 45 . "
"; ?>">


But this still takes the user to the wrong profile page. So something else is the problem now. The issue is of course that if there are existing users on WP and phpBB side, their numbers will never match up, even if bots were taken out of the equation, because they would have all registered at different times and therefore all of the user IDs are mixed up!

SO.

Is there a PHP function to create a link for the user on WP side, and this link takes them to their phpBB profile page? So like, a function that gets their phpBB user ID from the w3all database tables, and appends this to a link? Does this already exist? Are phpBB user IDs even imported and stored in the w3all database tables when a transfer is made?

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

Re: Code to create link to user's phpBB profile

Post by axew3 »

hello! Because the integration works by username/email, NOT ID.
So to retrieve the phpBB user id and all others info, for the same logged in user in wp, somewhere into your php code, via hooks, filters or also directly into your templates files, you can check the
constant (add the code wrapped into <?php ... ?> tags):
W3PHPBBUSESSION
that could be used like this:

Code: Select all

if (defined('W3PHPBBUSESSION')) {
   $phpbbUser = unserialize(W3PHPBBUSESSION);
   $user_id = $phpbbUser[0]->user_id;
   $last_mark = $phpbbUser[0]->user_lastmark; 
   $ug = $phpbbUser[0]->group_id;
  } 
it contain all phpBB user's data, you can see all with (maybe):

Code: Select all

if (defined('W3PHPBBUSESSION')) {
   $us = unserialize(W3PHPBBUSESSION);
   print_r($us); exit;
  }
will present you all available data of the phpBB user like user_id, user_type, user_password, user_email etc etc

so your above, could be something like this:

Code: Select all

<a href="https://www.axew3.com/w3/forums/memberlist.php?mode=viewprofile&u=<?php echo $us[0]->user_id; ?>">My forum profile</a>
OR like this:

Code: Select all

echo '<a href="https://www.axew3.com/w3/forums/memberlist.php?mode=viewprofile&u='.$us[0]->user_id.'">My forum profile</a>';
teebling
User w
User w
Posts: 11
Joined: Wed Jun 10, 2020 4:26 pm

Re: Code to create link to user's phpBB profile

Post by teebling »

Hey axe, thanks for getting back to me.

I tried the following but it did not work...

In one of my wordpress template files at the top I put:

Code: Select all

<?php
if (defined('W3PHPBBUSESSION')) {
   $us = unserialize(W3PHPBBUSESSION);
   print_r($us); exit;
  } 
?>
In the same template file, further down, I used the link:

Code: Select all

<a class="menulink" href="/memberlist.php?mode=viewprofile&u=<?php echo $us[0]->user_id; ?>" title="View your profile" role="menuitem">
But this doesn't work - in the URL there is no number printed at the end of &u= so it doesn't seem to pull the user ID.

Is there anything I'm missing here in terms of code?
teebling
User w
User w
Posts: 11
Joined: Wed Jun 10, 2020 4:26 pm

Re: Code to create link to user's phpBB profile

Post by teebling »

Update - I actually managed to get all of the data from the phpBB database to print:


(Attachment removed for privacy).


Only problem is that it prints EVERYTHING and not just the user_id :?

How do I, in the anchor tag, just print the user_id value?
Last edited by teebling on Wed Jun 17, 2020 3:06 pm, edited 2 times in total.
User avatar
axew3
w3all User
w3all User
Posts: 2713
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: Code to create link to user's phpBB profile

Post by axew3 »

Where you are adding the code?

You need to put this just before the call to var or vars you want, so add

Code: Select all

<?php 
if (defined('W3PHPBBUSESSION')) {
   $phpbbUser = unserialize(W3PHPBBUSESSION);
  }  
  ?>
now $phpbbUser contain all data, then
the phpBB user ID will be $phpbbUser[0]->user_id

you can do like this:

Code: Select all

<a href="https://www.axew3.com/w3/forums/memberlist.php?mode=viewprofile&u=<?php echo $phpbbUser[0]->user_id; ?>">My forum profile</a>
OR like this:

Code: Select all

echo '<a href="https://www.axew3.com/w3/forums/memberlist.php?mode=viewprofile&u='.$phpbbUser[0]->user_id.'">My forum profile</a>';
teebling
User w
User w
Posts: 11
Joined: Wed Jun 10, 2020 4:26 pm

Re: Code to create link to user's phpBB profile

Post by teebling »

Yes! That worked. Fantastic grazie mille :)

--------------------

For future users this is how I got it working:

In your Wordpress theme's (or child theme's) header file, at the very top of the file, before everything, add:

Code: Select all

<?php 
if (defined('W3PHPBBUSESSION')) {
   $phpbbUser = unserialize(W3PHPBBUSESSION);
  }  
  ?>
Then, where you want the link to the user's profile to be in the template, put:

Code: Select all

<a href="/memberlist.php?mode=viewprofile&u=<?php echo $phpbbUser[0]->user_id; ?>">My forum profile</a>
Make sure the URL path to your forum is correct ^

--------------------

So uhh... does this mean I can also pull say their avatar, signature and anything from that array?
Post Reply