Repository navigation
PHP Functions
FunnelKithq edited this page Nov 29, 2023
·
6 revisions
PHP functions to interact with FunnelKit Automations
FunnelKit Automations Pro plugin is required. Add code in the beginning.
/** Checking if class exists */
if ( ! class_exists( 'BWFCRM_Contact' ) ) {
return;
}
/** Passing Email as argument */
$crm_contact = new BWFCRM_Contact( $email );
/** Passing Contact ID as argument */
$crm_contact = new BWFCRM_Contact( $contact_id );
Contact Tags
/**
* Get Contact Tags
*/
$crm_contact->get_tags();
/**
* Add tags to a contact
*/
$tags = [
[ 'id' => 81 ],
[ 'id' => 82 ]
];
$assigned_tags = $crm_contact->add_tags( $tags );
/**
* Remove Tags from a Contact
*/
$tags = [ 81, 82 ];
$removed_tags = $crm_contact->remove_tags( $tags );
$crm_contact->save();
Contact Lists
/**
* Get Contact Lists
*/
$crm_contact->get_lists();
/**
* Assign Lists to a Contact
*/
$lists = [
[ 'id' => 30 ],
[ 'id' => 35 ],
[ 'id' => 36 ]
];
$assigned_lists = $crm_contact->add_lists( $lists );
/**
* Remove Lists from a Contact
*/
$lists = [ 30, 35, 36 ];
$removed_lists = $crm_contact->remove_lists( $lists );
$crm_contact->save();
Update contact fields
/**
* Update contact field
*/
$crm_contact->set_field_by_slug( 'address-1', 'address 1 comes here' );
$crm_contact->set_field_by_slug( 'address-2', 'address 2 comes here' );
$crm_contact->set_field_by_slug( 'city', 'New York' );
$crm_contact->set_field_by_slug( 'postcode', '10001' );
$crm_contact->set_field_by_slug( 'company', 'Company Name' );
$crm_contact->set_field_by_slug( 'gender', 'Male' );
$crm_contact->set_field_by_slug( 'dob', '1990-01-07' );
$crm_contact->save_fields();
Unsubscribe Contact
/**
* Unsubscribe Contact
*/
$crm_contact->unsubscribe();
Get contact status
/**
* Get contact status
* 1 - Subscribed, 2 - Unsubscribed, 3 - Unverified, 4 - Bounced
*/
$crm_contact->get_display_status();
/** Get all Tags */
$all_tags = BWFCRM_Tag::get_tags();
/**
* Output
[0] => Array (
[ID] => 1
[name] => Tag Name
[type] => 1
[created_at] => 2021-07-25 04:54:08
[updated_at] =>
[data] =>
)
*/
/** Get Lists */
$all_lists = BWFCRM_Lists::get_lists();
/**
* Output
[0] => Array (
[ID] => 1
[name] => List Name
[type] => 2
[created_at] => 2021-07-25 04:54:08
[updated_at] =>
[data] =>
)
*/
/** Get Custom Fields */
$all_fields = BWFCRM_Fields::get_custom_fields( 1, 1 );
/**
* Output
[1] => Array (
[group_id] => 1
[ID] => 1
[name] => Field Name
[type] => 1
[meta] => Array
(
)
[created_at] => 2021-02-01 11:56:45
[slug] => new-field
)
*/
Fetch Contacts
/**
* Fetch Contacts by Tag(s)
*/
$data = [
'tags_any' => [ 30 ]
];
$contacts = BWFCRM_Contact::get_contacts( '', '', '', $data );
/**
* Fetch Contacts by List(s)
*/
$data = [
'lists_any' => [ 30 ]
];
$contacts = BWFCRM_Contact::get_contacts( '', '', '', $data );
/**
* Fetch Contacts by Audience(s) id or name
*/
if ( version_compare( BWFAN_PRO_VERSION, '2.0.5', '>=' ) ) {
$contacts = BWFCRM_Contact::get_contacts_by_audience( 'audience1' );
}
For any other queries, write to us at https://funnelkit.com/support/