• 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.

Sync avatar profile fields

Solution
I am trying to send avatar urls as a custom field.
This is a GREAT use case for custom fields syncing!

As reference to code from my tutorial at Xenforo.com, the working code to add an author avatar URL to user syncing is as follows (there are two functions):

PHP:
/**
 * 1. Register field to XFtoWP + adds to Custom fields select box
 *
 * Set 'random_number' and text label as your own key
 */

function add_xftowp_custom_user_fields( $custom_fields ) {
    $custom_fields['user']['avatar_url'] = array(
        'label' => 'Author avatar'
    );
    return $custom_fields;
}

add_filter( 'xfwp_custom_fields', 'add_xftowp_custom_user_fields' );

/**
 * 2. Calculate logic to use as custom field
 *
 * Key name(s) must match as set...

joska1993

Active member
XFtoWP
Messages
32
Reaction score
1
I'm going to provide resources here to make your programming easier.

WordPress: Function to get the url of the avatar:
get_avatar_url(IDUSER);
 
Comment

joska1993

Active member
XFtoWP
Messages
32
Reaction score
1
How to get user id in custom fields @Alex ??

I am trying to send avatar urls as a custom field.

PHP:
function xftowp_custom_user_fields_calculate( $custom_fields, $wp_user, $wp_usermeta, $post_id ) {

    $custom_fields['avatar_url'] = get_avatar_url(#####IDUSER#####);

    return $custom_fields;

}

add_filter( 'xfwp_custom_user_fields_data', 'xftowp_custom_user_fields_calculate', 10, 4 );

I have tried this but it doesn't work:
$wp_user->ID
$wp_user->data->ID

thanks
 
Last edited:
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
I am trying to send avatar urls as a custom field.
This is a GREAT use case for custom fields syncing!

As reference to code from my tutorial at Xenforo.com, the working code to add an author avatar URL to user syncing is as follows (there are two functions):

PHP:
/**
 * 1. Register field to XFtoWP + adds to Custom fields select box
 *
 * Set 'random_number' and text label as your own key
 */

function add_xftowp_custom_user_fields( $custom_fields ) {
    $custom_fields['user']['avatar_url'] = array(
        'label' => 'Author avatar'
    );
    return $custom_fields;
}

add_filter( 'xfwp_custom_fields', 'add_xftowp_custom_user_fields' );

/**
 * 2. Calculate logic to use as custom field
 *
 * Key name(s) must match as set in step 1.
 * Insert your own logic into custom user fields at time of sync + other actions
 */

function xftowp_custom_user_fields_calculate( $custom_fields, $wp_user, $wp_usermeta, $post_id ) {
    $custom_fields['avatar_url'] = get_avatar_url( $wp_user->ID );
    return $custom_fields;
}

add_filter( 'xfwp_custom_user_fields_data', 'xftowp_custom_user_fields_calculate', 10, 4 );

Pay special attention to the avatar_url key, then follow the rest of the instructions to setup a matching user field in the XenForo admin. You will get this result the next time a user syncs from WP:
 

Attachments

  • Screen Shot 2022-09-12 at 8.05.08 PM.png
    Screen Shot 2022-09-12 at 8.05.08 PM.png
    43.3 KB · Views: 7
Comment
Solution

joska1993

Active member
XFtoWP
Messages
32
Reaction score
1
This is a GREAT use case for custom fields syncing!

As reference to code from my tutorial at Xenforo.com, the working code to add an author avatar URL to user syncing is as follows (there are two functions):

PHP:
/**
 * 1. Register field to XFtoWP + adds to Custom fields select box
 *
 * Set 'random_number' and text label as your own key
 */

function add_xftowp_custom_user_fields( $custom_fields ) {
    $custom_fields['user']['avatar_url'] = array(
        'label' => 'Author avatar'
    );
    return $custom_fields;
}

add_filter( 'xfwp_custom_fields', 'add_xftowp_custom_user_fields' );

/**
 * 2. Calculate logic to use as custom field
 *
 * Key name(s) must match as set in step 1.
 * Insert your own logic into custom user fields at time of sync + other actions
 */

function xftowp_custom_user_fields_calculate( $custom_fields, $wp_user, $wp_usermeta, $post_id ) {
    $custom_fields['avatar_url'] = get_avatar_url( $wp_user->ID );
    return $custom_fields;
}

add_filter( 'xfwp_custom_user_fields_data', 'xftowp_custom_user_fields_calculate', 10, 4 );

Pay special attention to the avatar_url key, then follow the rest of the instructions to setup a matching user field in the XenForo admin. You will get this result the next time a user syncs from WP:

my problem now would be to apply this field to all xenforo users and that the avatar is visible through that url (without uploading the images to xenforo again)..

Could you tell me how to make a plugin or modification in xenforo for this? Thank you!!
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
my problem now would be to apply this field to all xenforo users and that the avatar is visible through that url (without uploading the images to xenforo again)..
You will have to make a template modification somewhere on the XF side that uses the avatar URL custom user field. That is as far as I can help you here as the plugin has fulfilled its purpose. :)
 
Comment

joska1993

Active member
XFtoWP
Messages
32
Reaction score
1
You will have to make a template modification somewhere on the XF side that uses the avatar URL custom user field. That is as far as I can help you here as the plugin has fulfilled its purpose. :)

could the plugin force a sync when the user uploads a new avatar in wordpress?
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
could the plugin force a sync when the user uploads a new avatar in wordpress?
Yes, however that would require even more custom development.

The template modification should be as simple as writing an if statement that checks if the user's custom avatar URL has a value, and if not, use the regular avatar image URL.
 
Comment

joska1993

Active member
XFtoWP
Messages
32
Reaction score
1
This is a GREAT use case for custom fields syncing!

As reference to code from my tutorial at Xenforo.com, the working code to add an author avatar URL to user syncing is as follows (there are two functions):

PHP:
/**
 * 1. Register field to XFtoWP + adds to Custom fields select box
 *
 * Set 'random_number' and text label as your own key
 */

function add_xftowp_custom_user_fields( $custom_fields ) {
    $custom_fields['user']['avatar_url'] = array(
        'label' => 'Author avatar'
    );
    return $custom_fields;
}

add_filter( 'xfwp_custom_fields', 'add_xftowp_custom_user_fields' );

/**
 * 2. Calculate logic to use as custom field
 *
 * Key name(s) must match as set in step 1.
 * Insert your own logic into custom user fields at time of sync + other actions
 */

function xftowp_custom_user_fields_calculate( $custom_fields, $wp_user, $wp_usermeta, $post_id ) {
    $custom_fields['avatar_url'] = get_avatar_url( $wp_user->ID );
    return $custom_fields;
}

add_filter( 'xfwp_custom_user_fields_data', 'xftowp_custom_user_fields_calculate', 10, 4 );

Pay special attention to the avatar_url key, then follow the rest of the instructions to setup a matching user field in the XenForo admin. You will get this result the next time a user syncs from WP:

This example does not work, it does not receive anything to Xenforo
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
After you manually sync any user you should see the field filled out in the edit user screen.
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
I'm running it in bulk mode and they don't show up. How could I do more checks?
Go to the Edit user in WordPress, then syn the user at the bottom of the screen.

Also check the profile field for the same user on XF and you should see the avatar URL filled out.
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
1663102138249.png
The "username" and "email" fields should not be empty, so something is wrong with the user sync. I recommend you follow these steps:
  1. Upgrade the plugin to XFtoWP 1.5 RC1 (just released today)
    1. Read how to upgrade the plugin, go to "Manual Updates":
  2. After the upgrade, go to Bulk actions > Disconnect users. Wait to complete the process.
  3. Edit any WP user and scroll down to the "XenForo Profile" tab. It should be empty and the "User notes" section should not appear.
  4. If the user is successfully disconnected, try to manually connect an XF user to this WP user by entering the matching forum username. Once connected, each user's profile should look something like this:
    Screen Shot 2022-09-13 at 11.53.36 PM.png
  5. Finally, if your test user syncs you can run Bulk actions > Refresh users and your users should properly sync
 
Comment

Alex

MD developer
Staff member
Md
XFtoWP
Messages
6,703
Reaction score
1,901
Hey @joska1993, I've moved our other discussion into its own thread as it has turned more into a bug report. Here's the new thread and resolution for the error:

 
Comment
Top