get_contact_id()

get_contact_id()

#Overview
This function retrieves a user』s CRM contact ID based on their WordPress user ID.
#Get the current user』s contact ID
$contact_id = wpf_get_contact_id();
#Get the contact ID for a different user
$contact_id = wpf_get_contact_id( $user_id );
#Force an update of the user』s contact ID by sending an API call to your CRM
In this case the updated contact ID will automatically be saved to the local user meta after it』s been retrieved.
$contact_id = wpf_get_contact_id( $user_id, true );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_woocommerce_subscription_status_apply_tags

wpf_woocommerce_subscription_status_apply_tags

#Overview
This filter is run during a WooCommerce subscription status change, before WP Fusion has applied any tags to the customer.  It can be used to modify the tags that will be applied to the customer.
To use the code examples below, add them to your active theme』s functions.php file.
#Parameters

$apply_tags: This is an array of tags that will be applied to the customer
$status: The current subscription status (i.e. active, pending-cancel, on-hold)
$subscription: The subscription object

#Examples
#Don』t apply any tags when a subscription status changes to active
This is useful if you need to manually approve new orders and you don』t want any tags applied at checkout that would unlock other content.
function custom_wpf_status_check( $apply_tags, $status, $subscription ) {

if ( 'active' == $status ) {
return false;
}

return $apply_tags;

}

add_filter( 'wpf_woocommerce_subscription_status_apply_tags', 'custom_wpf_status_check', 10, 3 );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_user_register

wpf_user_register

#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 format array('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 of the input isn』t the same as the meta field in the database. For example, you may have added the field my_custom_field to the form, 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', 10, 2 );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

get_tags()

get_tags()

#Overview
This function retrieves all CRM tags currently associated with the user.
#Get the current user』s tags
$tags = wp_fusion()->user->get_tags();
#Get the tags for a different user
$tags = wp_fusion()->user->get_tags( $user_id );
#Force an update of the user』s tags by sending an API call to your CRM
In this case the updated tag list will automatically be saved to the local user meta after it』s been retrieved.
$tags = wp_fusion()->user->get_tags( $user_id, true );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_pulled_user_meta

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?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_woocommerce_user_id

wpf_woocommerce_user_id

#Overview
When WP Fusion processes a WooCommerce checkout for a registered user, it uses the current user』s ID to determine the user』s contact record in your CRM.
That way if a user checks out with a different billing email, their original contact record is properly updated— instead of creating a new contact record and fragmenting your data.
Generally this is desirable, but there may be situations where you don』t want orders to be associated with the current user. For example if your WooCommerce checkouts are being made by agents who are purchasing on behalf of their customers. In that case you would want a new contact record to be created for the customer, rather than updating the contact record of the agent.
The wpf_woocommerce_user_id filter allows you to modify the user ID that WP Fusion uses to determine which user should be associated with the checkout. Returning false from the filter will tell WP Fusion to treat the checkout as a guest checkout.
#Parameters

$user_id (int): The user ID to be used for the checkout
$order (object): The WooCommerce order object

#Examples
#Treat all checkouts as guest checkouts
add_filter( 'wpf_woocommerce_user_id', function( $user_id, $order ) {
return false;
}, 10, 2 );

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_user_update

wpf_user_update

#Overview
This filter allows you to modify user meta data before it』s sent to 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, in the format array('meta_field' => 'value').
$user_id: ID for the user being updated.

#Examples
#Save the full URL to a user』s profile photo
If you』re using Ultimate Member to run your site』s membership platform, and want to save a link to the user』s profile photo in your CRM, you』ll find that just syncing the profile_photo field gives you the name of the file, but not the full URL. Using wpf_user_update, we can modify this so the full URL to the user』s profile is sent.
add_filter('wpf_user_update', 'set_profile_photo_url', 10, 2);

function set_profile_photo_url($user_meta, $user_id) {

// Changes "profile_photo.png" to "http://mysite.com/wp-content/uploads/ultimatemember/1/profile_photo.png"
if(isset($user_meta['profile_photo']))
$user_meta['profile_photo'] = content_url() . '/uploads/ultimatemember/' . $user_id . '/' . $user_meta['profile_photo'];

return $user_meta;

}
This filter can be used in a wide variety of ways depending on your particular site』s configuration. For assistance in configuring wpf_user_update for your site contact us and we』d be happy to help.

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_query_filter_get_posts_args

wpf_query_filter_get_posts_args

#Overview
WP Fusion』s Filter Queries option allows you to modify the results of database queries to exclude content that a user can』t access (based on WP Fusion』s access rules).
When used in Advanced mode, Filter Queries will build up a list of posts a user has access to before the main query is run, and add it to the main query via the post__not_in parameter (in order to exclude any restricted posts).
The wpf_query_filter_get_posts_args filter lets you modify the arguments going into that query.
#Parameters

$args (array): WP_Query arguments

#Examples
#Pre-query more posts
To protect the stability of your site, the pre-query will load at most 200 restricted posts. However if you have more than 200 posts of that post type which are protected by WP Fusion』s access rules, this could cause users to see posts they don』t have access to.
The example below extends the pre-query to check the first 1000 restricted posts.
Note that this can cause multiple thousands of extra database queries per page load, so it should be used with extreme caution.
function filter_query_posts_args( $args ) {

$args['posts_per_page'] = 1000;

return $args;

}

add_filter( 'wpf_query_filter_get_posts_args', 'filter_query_posts_args' );
#Activate Ludicrous Mode
By default, the pre-query only looks at posts that have WP Fusion access rules saved to their postmeta.
This provides improved performance, but it means that posts protected by post type rules or taxonomy term rules will not necessarily be excluded from the results, even in Advanced mode.
This snippet removes the meta_query and also sets the posts_per_page to 5000. Effectively this means that every post of the post type will be pre-checked for access before the query is run.
If you have a lot of posts and/or taxonomy terms, this will almost certainly crash your site. Use with caution.
function filter_query_ludicrous_mode( $args ) {

$args['posts_per_page'] = 5000;
unset( $args['meta_query'] );

return $args;

}

add_filter( 'wpf_query_filter_get_posts_args', 'filter_query_ludicrous_mode' );
This functionality could be made more performant by running it on a schedule (or as content is published) and building up a cache of the access list for every user on the site, ideally in a custom database table. However that is beyond the scope of this article.

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

bbPress

bbPress

#Overview
Using WP Fusion and bbPress, you can restrict access to forums based on users』 tags in your CRM. If the user does not have access you can either display a restricted content message, or redirect the user to another page on your site.
#Forums
When editing any individual forum, you can set access rules for that forum based on a logged-in user』s tags in your CRM.

For more information on the meta box, see the documentation on restricting access to content.
Note: WPF adds a class to the form, 「wpf-locked」. You can use this to style the form via CSS so that you can indicate which forums are locked.
#Hiding Restricted Forums
If you』d like to hide restricted forums from the forums archive, you can turn on Query Filtering for the forums post type.
At Settings » WP Fusion » General » Content Restriction, set Filter Queries to Standard, and from the Post Types dropdown, select forum.

Now any forums that the user doesn』t have access to will be completely hidden from the forums archive, regardless of the visibility setting of the forum.
#Global Settings
WP Fusion also has some global settings for bbPress, found at Settings » WP Fusion » Integrations » bbPress.

Here you can optionally restrict access to your forums archive page, or all forums on your site, using a CRM tag.
Note that you must specify a redirect URL for forum archive protection to work.

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No

wpf_watched_meta_fields

wpf_watched_meta_fields

#Overview
This filter lets you register meta fields in the wp_usermeta table that should always be synced whenever they are modified. This is helpful if you』re updating user data in your own code by using the functions add_user_meta() or update_user_meta().
To use the code examples below, add them to your active theme』s functions.php file.
#Parameters

$fields: An array of fields to watch

#Examples
#Watch a custom field and sync changes automatically
The example below will watch for changes in the field my_field_name and sync them.
function my_watch_meta_field( $fields ) {

$fields[] = 'my_field_name';
return $fields;

}

add_filter( 'wpf_watched_meta_fields', 'my_watch_meta_field' );

Keep in mind the field must still be associated with a field in your CRM via the Contact Fields tab in the WP Fusion settings.

#Was this helpful?

Let us know if you liked the post. That』s the only way we can improve.

Yes

No