• Welcome to the all-new Kolakube support, the official place to get help for Marketers Delight, XFtoWP, CryptoWP, and other WordPress products! Please login with your account details to access private support forums.

Usergoup Question

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
A question on the usergroup setting.

If a user in Xenforo has a secondary usergroup, can that be added to an equivalent usergroup in WP when that person is sycned up? If so, how is it done?
 

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
Still no joy with this Alex.

When you use user id 524 you get Array ( )

When you use and id of a user with a secondary id, in this case user id 185, nothing comes back.
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
Steps to take to reproduce my results:
  1. Copy code from this post to the top of your child theme functions.php file
  2. Change the $wp_user_id ID number to any user who is connected to an XF account. The best way to make sure is to go to WP admin > XF > Logs and choose a user who is synced. Again, you need to get the ID of the WordPress user and plug into this function
  3. Refresh your site and you will see the data at the top of your site
Edit: I just looked up WP user 185, and there is no user with that ID on your site, so please be sure you are plugging in the user ID from your WP site into the $wp_user_id (WP = WordPress) user ID.
 
Comment

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
Ok so I was being stupid with user Id and now have a result, So if it's in an array how do I check against that. Sorry, I am a bit fuzzy on all this.

So in the header, I need to see if they are in secondary group id 5. If they are echo something if not do nothing.
 
Last edited:
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
Ok so I was being stupid with user Id and now have a result, So if it's in an array how do I check against that. Sorry, I am a bit fuzzy on all this.

So in the header, I need to see if they are in secondary group id 5. If they are echo something if not do nothing.
Ok, so now that our basics are covered you can find the answer for that in one of my first responses:

 
Comment

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
Back on this Alex and I think I got this working.

Just added this in the header of the WP site and it seems to be working...

$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;

$wp_user_id = $current_user_id;
$xf_user_id = xf_user_meta( $wp_user_id, 'main_account' );
$xf_secondary_usergroups = xf_user_meta( $wp_user_id, array( 'users', $xf_user_id, 'xf_secondary_group_ids' ) );

if ( empty( $xf_secondary_usergroups[5] ) ) {echo 'BLAH';}

I didn't need to add anything in the functions file which I assume is correct based on the above code.

What I am still unsure of is what happens when that person is removed from the Xenforo usergroup 5 on the Xenforo side. Will the secondary usergroup in WP (what was set up in XFtoWP) be removed automatically?

In other words, when someone's sub runs out in our case will their status be removed from the WP side without any intervention from us?
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
I didn't need to add anything in the functions file which I assume is correct based on the above code.
Yes, this is valid and will adapt to the current user logged in. But to be a bit safer, I'd refactor it so it is only checking if the user is logged in:

PHP:
if ( is_user_logged_in() ) {
    $wp_user_id = get_current_user_id();
    $xf_user_id = xf_user_meta( $wp_user_id, 'main_account' );
    $xf_secondary_usergroups = xf_user_meta( $wp_user_id, array( 'users', $xf_user_id, 'xf_secondary_group_ids' ) );
    
    if ( empty( $xf_secondary_usergroups[5] ) ) {
        echo 'BLAH';
    }
}

What I am still unsure of is what happens when that person is removed from the Xenforo usergroup 5 on the Xenforo side. Will the secondary usergroup in WP (what was set up in XFtoWP) be removed automatically?
XFtoWP actions are largely only triggered from the WP side. So in your example, no, the usergroup won't be removed from the WP user.

Are you using an eCommerce or other plugin to capture registrations? If so, there are usually actions for user demotions which XFtoWP can plug into and ensure usergroups are removed on both sites.
 
Comment

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
That makes total sense and will make that code change.

We are simply using the Xenforo inbuilt user upgrade system. People can take a sub out through that system via Paypal and it moves them into a Premium usergroup on Xenforo. So I guess my question is, when their sub runs out say after 1 month, 6 months, or after a year, we need to make sure that's also unchecked on the WP side.
 
Comment

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
So after more testing, the only way to check against the usergroup is if the secondary group is checked on the WP side which is why this is probably not going to work if usergroups are controlled on the Xenforo side.

What I did not want to do is move the payment system into WP, we have links all over the place pointing to the subscription page on Xenforo and users are primarily controlled on the Xenforo side where there timed subs are controlled. Plus, they are used to using the current system.

In theory all we need to do is check against the data directly from Xenforo to ascertain if they are in the group and not against the WP stored data for that user.
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
In theory all we need to do is check against the data directly from Xenforo to ascertain if they are in the group and not against the WP stored data for that user.
The plugin is close to doing this as it already runs a data refresh every X minutes, and I am planning to add user checks to that cycle as well. For now it's possible to hook into it yourself with functions the plugin provides, and hints from this forum.
 
Comment
Top