How to Sync Custom User Fields

Table of Contents

  • 1. Add Custom User Fields From XenForo
  • 2. Setup Custom User Fields From the XFtoWP Settings
  • 3. Testing Custom User Fields
  • 4. Custom User Fields and Bulk Actions
  • 5. Syncing Custom Data to User Fields

XFtoWP offers a simple connection point to map custom user fields you wish to send from a WordPress user during actions and other syncing events.

You can use Custom User Fields to enhance the XenForo user experience by using unique data that comes from the WordPress user account.

Follow this guide to learn how to sync custom user fields during XFtoWP user sync processes.

1. Add Custom User Fields From XenForo

Before a user can receive custom user fields, they must first exist on your XenForo installation. Navigate to XenForo admin > Users > Custom user fields to create your desired custom user fields.

Custom user fields from XenForo

Click the “Add field” button at the top to begin entering details about your new custom user field.

From here you will be prompted to create a Field ID and personalize other settings about the new user field.

In most cases you will want to set the Field type to a Single-line text box as most custom user field data will be stored as a simple string.

Under the Options for text fields box you will be asked to choose a validation method for the data when it is saved. XFtoWP supports XenForo’s Date validator, and will also honor simple validators such as Number and URL.

If you find data is not syncing, check the validation settings here and change it to None to debug.

Tip: you may not want user’s to be able to edit these fields, so it is recommended to disable the “User editable” setting under options.

2. Setup Custom User Fields From the XFtoWP Settings

Now that you have created Custom User Fields on XenForo, you need to add those user fields to your XFtoWP settings so the plugin can properly add fields data to your sync process.

Simply match the Field ID (see below) with the Field ID back on the XenForo side to connect across sites.

Create Custom user fields from XFtoWP.

XFtoWP comes with pre-defined custom user fields you can simply activate from this admin screen:

  • WP user ID
  • WP user role
  • First sync date
  • Last sync date

Once you have mirrored the Custom User Field names across both installations, save your settings and run your first test!

3. Testing Custom User Fields

Now, let’s see how custom user field syncing actually works!

Go edit any currently synced user from the WP admin and press the “Sync user” button.

Sync XenForo users from WordPress admin

Once Custom User Fields are setup, they will be updated each time a user is synced.

You can now see the new custom user field data when you edit any synced user from the XenForo admin:

Custom user fields profile in XenForo

4. Custom User Fields and Bulk Actions

Custom User Fields can be created at any time from the XFtoWP admin panel, and are only applied when a user is synced.

If you have already bulk connected users before setting up custom user fields, you can run the WP admin > XF > Bulk actions > Refresh users to apply the new custom user fields to all synced users.

5. Syncing Custom Data to User Fields

You may have noticed in some of the screenshots above a “Random number” field that is not a standard part of the Custom User Fields interface.

That is an example of creating your own custom data and assigning it to Custom User Fields from the XFtoWP interface, and works idential to the pre-defined custom user fields.

From your theme’s functions.php file, or other place you run custom functions, use these two XFtoWP filters to plug your own logic into custom fields, with full use of WP user data at the time of any action or user sync:

 * 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']['random_number'] = array(
        'label' => 'Random number field'
    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['random_number'] = rand();
    return $custom_fields;

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