push_user_meta()

push_user_meta()

#Overview
This function allows you to sync WordPress user metadata to fields in your CRM.
#Sending specific data
You can send specific fields by providing an array of field names and values.
$update_data = array(
'first_name' => 'Joe'
'custom_field' => 'Custom Value'
)

wp_fusion()->user->push_user_meta( $user_id, $update_data );
The field keys should be WordPress meta fields keys. WP Fusion will use the field mapping you』ve set on the Contact Fields tab to associate the data with the corresponding fields in your CRM.
#Sending all user data
You can also omit the array of update data, and WP Fusion will get all of the information it can find about the user from the database and send it to your CRM.
wp_fusion()->user->push_user_meta( $user_id );
 

#Was this helpful?

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

Yes

No

pull_user_meta()

pull_user_meta()

#Overview
This function triggers WP Fusion to load data from your CRM back to the WordPress user record. Any fields enabled for sync on the Contact Fields tab will be loaded.
#Parameters

$user_id: the WordPress user ID to load the metadata for

#Returns

$user_meta: array of key / value pairs of WordPress meta

#Examples
#Load a number and increment it
This example loads a custom field from the CRM, adds 1 to it if it』s numeric, and syncs the field value back to the CRM.
$user_meta = wp_fusion()->user->pull_user_meta( $user_id );

if ( ! empty( $user_meta['number_field'] ) && is_numeric( $user_meta['number_field'] ) ) {

$user_meta['number_field']++;

wp_fusion()->user->push_user_meta( $user_id, array( 'number_field' => $user_meta['number_field'] ) );

}

#Was this helpful?

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

Yes

No

has_tag()

has_tag()

#Overview
This function determines whether a user has a given tag. A tag ID or label can be provided.
if ( wpf_has_tag( 'Paying Customer' ) ) {

echo "Thanks for your payment!";

}

Or more complex conditions can be created by combining calls to has_tag(), for example:
if ( wpf_has_tag( 'New Customer' ) && ! wpf_has_tag( 'Watched Intro Video' ) ) {

echo "Welcome to our site! Please watch our introduction video here:";

}

#By User ID
To check the tags for a specific user, pass a $user_id as the second parameter:
if ( wpf_has_tag( 'Paying Customer', $user_id ) ) {

echo "Thanks for your payment!";

}

#Array Syntax
The function also accepts an array of tag names or IDs. If the user has any of the provided tags the function will return true.
if ( wpf_has_tag( array( 'Pending Affiliate', 'Accepted Affiliate' ) ) {

echo "Thanks for joining our affiliate program!";

}

#Was this helpful?

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

Yes

No

get_users_with_tag()

get_users_with_tag()

#Overview
This function returns an array of user IDs who have a specified tag. You can use either a tag ID or label.
#Get all users with the Member tag
$user_ids = wpf_get_users_with_tag( 'Member' );
#Get all users with tag ID 123
$user_ids = wpf_get_users_with_tag( 123 );

#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

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

apply_tags()

apply_tags()

#Overview
This function allows you to apply an array of tags to a user.
The function expects an array of tag IDs. Some CRM』s, like Infusionsoft, Ontraport, and ConvertKit use internal tag IDs to designate their tags. Other CRMs, like ActiveCampaign, Drip, AgileCRM, and Mautic don』t use tag IDs, and a tag label is sufficient.
If you』re unsure, you can always use get_tag_id() to get the appropriate tag ID for this function:
$tag_id = wp_fusion()->user->get_tag_id( 'Tag Name' );
#Apply tags to the current user (Infusionsoft and others which use tag IDs)
$tags = array(123, 456, 789);
wp_fusion()->user->apply_tags( $tags );
#Apply tags to the current user (ActiveCampaign and others which don』t use tag IDs)
$tags = array('Tag One', 'Tag Two', 'Tag Three');
wp_fusion()->user->apply_tags( $tags );
#Apply tags to a specific user ID
$tags = array(123, 456, 789);
wp_fusion()->user->apply_tags( $tags, $user_id );
The function will return true if the tags were applied successfully, and false if there was a connection error or the user wasn』t found in the CRM.

#Was this helpful?

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

Yes

No

add_object()

add_object()

#Overview
This helper function is available with Ontraport, Zoho, Salesforce, HubSpot, and other CRMs which use custom objects.
It』s a shortcut / alternative to using the wpf_crm_object_type filter, for cases where you just need to add a custom object one time, without changing the object type used for WP Fusion globally.
#Parameters

$data: (array) An associative array of data to sync to the CRM, using CRM field IDs for the keys
$object_type: (string) The object type you wish to update

#Examples
#Create a new Lead in Salesforce
$data = array(
'Email' => '[email protected]',
'FirstName' => 'Jane',
'LastName' => 'Doe',
);

$lead_id = wp_fusion()->crm->add_object( $data, 'Lead' );
#Update an Event object in Zoho when an Event post type is updated in WordPress
// Runs on any post with post type "event" and updates the "Event" custom object with values Title and EventDate

function create_update_event_object( $post_id, $post, $update ) {

// Don't run if WP Fusion isn't active, otherwise you'll get an error

if ( ! function_exists( 'wp_fusion' ) ) {
return;
}

// This is the data to be sent to the CRM

$event_data = array(
'Title' => $post->post_title,
'EventDate' => get_post_meta( $post_id, 'event_date', true )
);

// See if this object has already been synced

$object_id = get_post_meta( $post_id, wp_fusion()->crm->slug . '_event_id', true );

if ( empty( $object_id ) {

// New event

$object_id = wp_fusion()->crm->add_object( $event_data, 'Event' );

if ( ! is_wp_error( $object_id ) ) {

// Save the ID of the new record for future updates.

update_post_meta( $post_id, wp_fusion()->crm->slug . '_event_id', $object_id );

} else {

// Error, log it.

wpf_log( 'error', 0, 'Error creating event:' . $object_id->get_error_message() );

}

} else {

// Existing event

wp_fusion()->crm->update_object( $object_id, $event_data, 'Event' );

}

}

// save_post_event runs whenever an "event" post type is created or updated (see https://developer.wordpress.org/reference/hooks/save_post_post-post_type/)

add_action( 'save_post_event', 'create_update_event_object', 10, 3 );
#Create a custom Car object in HubSpot and associate it with a contact
For more information on working with custom objects in HubSpot, see Custom Objects with HubSpot.
define( 'HUBSPOT_API_KEY', 'xx599590-7888-43ed-a896-5abbc2ef9aa2' );

$properties = array(
'condition' => 'used',
'date_received' => '1582416000000',
'year' => '2014',
'make' => 'Nissan',
'model' => 'Frontier',
'vin' => '4Y1SL65848Z411439',
'color' => 'White',
'mileage' => '80000',
'price' => '12000',
'notes' => 'Excellent condition. No accidents.',
);

$object_type_id = '2-4370788';

$object_id = wp_fusion()->crm->add_object( $properties, $object_type_id );

if ( is_wp_error( $object_id ) ) {
wpf_log( 'error', wpf_get_current_user_id(), 'Error adding object: ' . $object_id->get_error_message() );
return false;
}

// Do what you want with $object_id here.

// For example to associate it with a contact (https://developers.hubspot.com/docs/api/crm/crm-custom-objects).

$contact_id = '101';
$association_type_id = '3';

$request = "https://api.hubapi.com/crm/v3/objects/{$object_type_id}/{$object_id}/associations/contacts/{$contact_id}/{$association_type_id}/?hapikey=" . HUBSPOT_API_KEY;

$params = array( 'method' => 'PUT' );
$response = wp_safe_remote_request( $request, $params );

if ( is_wp_error( $response ) ) {
wpf_log( 'error', wpf_get_current_user_id(), 'Error associating object with contact: ' . $response->get_error_message() );
return false;
}

#Was this helpful?

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

Yes

No

wpForo

wpForo

#Overview
WP Fusion integrates with wpForo to protect access to forums on your site by a logged in user』s CRM tags. WP Fusion also allows you to auto-assign usergroups in your wpForo forums by assigning tags in your CRM
#Forum access control
To set up forum access control, navigate to Forums » WP Fusion in the WordPress admin.

For each of your forums and categories, you can specify tags that are required to view that forum. If the user does not have any of the specified tags they will be redirected to a the page you select in the dropdown.
You can also check the box for Hide if access is denied to completely hide the restricted forum from the forums list.
#Usergroups
WP Fusion includes the ability to auto-assign usergroups in your forums by applying and removing tags in your CRM. This can also be configured under Forums » WP Fusion in the admin.

For each usergroup in wpForo you can select a tag in your CRM. When this tag is applied to a user they will be added to the associated usergroup. If the tag is removed they will revert to the default wpForo usergroup.
You can set the default usergroup in the wpForo settings under Forums » Usergroups.

#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