wpf_pulled_user_meta

Overview

This filter allows you to modify a user’s meta data whenever it has been pulled from your CRM, and before it is saved to the database. To use the code examples below, add them to your active theme’s functions.php file.

Parameters

  • $user_meta: Array of user meta data, in the format array('meta_field' => 'value').
  • $user_id: ID of the user being updated

Examples

Update a user’s Display Name based on their first and last name

If you’re using the Display Name field on your site to show post authors, create member directories, or elsewhere in your templates, you may want to automatically update a user’s display name if their name is changed in your CRM.

function set_display_name( $user_meta, $user_id ) {
	
	$user_meta['display_name'] = $user_meta['first_name'] . ' ' . $user_meta['last_name'];

	return $user_meta;


}

add_filter( 'wpf_pulled_user_meta', 'set_display_name', 10, 2 );

Limit the fields that are loaded from the CRM

By default WP Fusion will load any fields from the CRM that are enabled for sync from the Contact Fields tab. This example lets you limit the loaded data to name and email address, while ignoring any other data.

function limit_loaded_metadata( $user_meta, $user_id ) {

	$limited_meta = array(
		'first_name' => $user_meta['first_name'],
		'last_name'  => $user_meta['last_name'],
		'user_email' => $user_meta['user_email'],
	);

	return $limited_meta;

}

add_filter( 'wpf_pulled_user_meta', 'limit_loaded_metadata', 10, 2 );

Was this helpful?