-
-
Save Lonsdale201/369ede45f8161699911548183457f580 to your computer and use it in GitHub Desktop.
JetEngine Custom macro - Fluent CRM get Contact users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// place the code in the child theme functions.php or a custom code snippets plugin like FluentSnippets | |
// how to use | |
// Create a new Users Query in the Query builder | |
// Go to the Include/Exclude section | |
// click the Include section dynamic icon and choose the Fluent CRM / WP Users macro | |
// HELP IMAGE https://prnt.sc/06FFNY9E24Sg | |
// This macro returns the identifiers of users who can be found in fluentCRM as both contacts and wordpress users. | |
// It will not return users who are not registered on your WordPress site. The subscription status is independent for this macro. | |
add_action( 'jet-engine/register-macros', function() { | |
class Fluent_CRM_WP_Users extends \Jet_Engine_Base_Macros { | |
public function macros_tag() { | |
return 'fluent_crm_wp_users'; | |
} | |
public function macros_name() { | |
return 'Fluent CRM / WP Users'; | |
} | |
public function macros_args() { | |
return array(); | |
} | |
public function macros_callback( $args = array() ) { | |
$users = get_users( array( 'fields' => array( 'ID' ) ) ); | |
$crm_users = array(); | |
$contacts = fluentCrmApi('contacts')->all(); | |
foreach ( $users as $user ) { | |
foreach ( $contacts as $contact ) { | |
if ( $contact->user_id == $user->ID ) { | |
$crm_users[] = $user->ID; | |
break; | |
} | |
} | |
} | |
if ( empty( $crm_users ) ) { | |
return 'No CRM users found'; | |
} | |
return implode( ',', $crm_users ); | |
} | |
} | |
new Fluent_CRM_WP_Users(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment