• 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
Alternatively, can you use the XFtoWP calls to the API to get the current logged in WP user and bring back the secondary usergroup of that user to set a conditional on that group in WP? Not really sure how to make that call if it's possible using XFtoWP.
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,650
Reaction score
1,877
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?
So, if XF user has usergroup y, the WP user should be synced to usergroup z in WP?

Alternatively, can you use the XFtoWP calls to the API to get the current logged in WP user and bring back the secondary usergroup of that user to set a conditional on that group in WP? Not really sure how to make that call if it's possible using XFtoWP.
Yes, you can make raw API calls by the current user ID, or static as shown in this example:

PHP:
$wp_user_id = 560;
// $wp_user_id = get_current_user_id();
$xf_user_id = xf_user_meta( $wp_user_id, 'main_account' );
$user_request = xf_request( 'GET', "users/$xf_user_id" );

print_r( $user_request->user->secondary_group_ids );

XFtoWP cycles through these groups on sync, but does not save/alter group IDs that aren't aready known from the XFtoWP > Site Setup > Usergroups settings.
 
Comment

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
Looking at the backend of XFtoWP you have an id and a name to post in the Xenforo user group details but other than that there's no other setting to match it to a WP group so not sure what I am missing?
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,650
Reaction score
1,877
Looking at the backend of XFtoWP you have an id and a name to post in the Xenforo user group details but other than that there's no other setting to match it to a WP group so not sure what I am missing?
XFtoWP doesn't currently do anything with WP user groups. Perhaps you can create a custom user fields and pass the WP user groups back to XF that way:

 
Comment

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
Ok. That's fine. What I am needing to do is to hide some stuff if they are in a specific Xenforo usergroup.
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,650
Reaction score
1,877
Ok. That's fine. What I am needing to do is to hide some stuff if they are in a specific Xenforo usergroup.
You can always check a WP user's meta fields (where data about the connected user is stored) like so:

PHP:
$wp_user_id = 99;
$xf_user_id = xf_user_meta( $wp_user_id );

You can lookup the XF usergroups that are syncing between WP-XF accounts and match the usergroup by ID.

PHP:
$wp_user_id = 99;
$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' ) );

For example, if you need to check if a current WP user has an usergroup from XF with an ID of "47" you can check:

CSS:
if ( ! empty( $xf_secondary_usergroups[47] ) )
    ...

Unlike my first example, this doesn't make any calls to the API and is already stored in the user database, so I highly recommend you use this data as much as possible in any custom dev work.
 
Comment

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
Given this a try this evening and I cannot get this to work at all. Shoved the PHP in a template

$wp_user_id = 21;
// $wp_user_id = get_current_user_id();
$xf_user_id = xf_user_meta( $wp_user_id, 'main_account' );
$user_request = xf_request( 'GET', "users/$xf_user_id" );

print_r( $user_request->user->secondary_group_ids );

And get nothing back all. Kind of stumped.
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,650
Reaction score
1,877
Given this a try this evening and I cannot get this to work at all. Shoved the PHP in a template

$wp_user_id = 21;
// $wp_user_id = get_current_user_id();
$xf_user_id = xf_user_meta( $wp_user_id, 'main_account' );
$user_request = xf_request( 'GET', "users/$xf_user_id" );

print_r( $user_request->user->secondary_group_ids );

And get nothing back all. Kind of stumped.
Does just $user_request return a value? Also, try a hard-coded XF user ID in the GET request to be sure the right ID is being sent.
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,650
Reaction score
1,877
$user_request returns nothing and tried harcoding it in and still nothing.
Last test, otherwise all I can think is that the API permissions/user/request is not setup correctly.

Paste this code into your themes functions.php file and it should print data to the top of your whole website.

PHP:
function xfwp_test_request_function() {
    $wp_user_id = 21;
    // $wp_user_id = get_current_user_id();
    $xf_user_id = xf_user_meta( $wp_user_id, 'main_account' );
    $user_request = xf_request( 'GET', "users/$xf_user_id" );
   
    print_r( $user_request->user->secondary_group_ids );
}

add_action( 'wp_enqueue_scripts', 'xfwp_test_request_function' );
 
Comment

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
Yeh that spat back nothing at all.

Checked the API permissions and it's all connected with. All green ticks showing.

alert:write
auth
auth:login_token
conversation:write
node:read
thread:read
thread:write
user:delete
user:read user:write
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,650
Reaction score
1,877
Are you working on a password protected site? Are you using XF2.2? Do other user syncing actions and basic plugin functions work?
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,650
Reaction score
1,877
Thank you for providing those details @Rush, and cool site in general.

I updated the test function in my post here to call a later hook in the WordPress load which will definitely show the data at the top of the page, just get the $wp_user_id correct. In the successful test I ran, I used WP user #524.
 
Comment

Rush

Active member
XFtoWP
Messages
65
Reaction score
8
Thanks Alex, glad you liked the site, it's a bit of a complex beast as you probably saw when it comes to the user stuff and all the other stuff needed.

I'll give this a test out today and get back to you asap.
 
Comment
Top