#Overview
This filter allows you to modify any user meta data captured at registration, before a new contact record is created in your crm. To use the code examples below, add them to your active theme’s functions.php file.
#Parameters
$user_meta
: Array of user meta data collected at registration, in the formatarray('meta_field' => 'value')
.$user_id
: ID for the user being updated.
#Examples
#Correct an invalid input field name on a registration form
Some plugins allow you to add custom fields to registration forms via code, but the “name” value on the input isn’t the same as the meta field in the database (or the meta field enabled for sync in the Contact Fields list).
For example, you may have added the field my_custom_field
to the form (i.e. <input type="text" name="my_custom_field">
, but in the database (and WP Fusion’s Contact Fields settings) the field is myplugin_my_custom_field
.
Since WP Fusion is looking for the meta key value as it’s set in the database, it won’t be detected on the registration form.
To correct this, you can use the wpf_user_register
filter like so:
function my_wpf_filter_registration( $user_meta, $user_id ) {
if( isset( $user_meta['my_custom_field'] ) ) {
$user_meta['myplugin_my_custom_field'] = $user_meta['my_custom_field'];
}
return $user_meta;
}
add_filter( 'wpf_user_register', 'my_wpf_filter_registration', 10, 2 );
#Preventing a user from being synced to the CRM
If you return null
from the wpf_user_register
filter, WP Fusion will not create a contact record in your CRM.
In this example we prevent a contact record from being created at registration if the user has the author role:
function my_wpf_filter_registration( $user_meta, $user_id ) {
$user = get_userdata( $user_id );
if ( in_array( 'author', (array) $user->roles ) ) {
return null;
}
return $user_meta;
}
add_filter( 'wpf_user_register', 'my_wpf_filter_registration', 100, 2 );