Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function healthexcel_wpf_infusionsoft_tag_staff_members() {
- if ( empty( $_REQUEST['contactId'] ) ) {
- return false;
- // wp_die( '<h3>Error</h3>Referring Practitioner Contact ID not provided! Aborting.', 'Error', 500 );
- } else if ( empty( $_REQUEST['isTagId'] ) ) {
- return false;
- // wp_die( '<h3>Error</h3>Target Tag ID not provided! Aborting.', 'Error', 500 );
- }
- $app = tboc_healthexcel_isdk_api();
- if ( is_wp_error( $app ) ) {
- return;
- }
- $practitioner_contact_id = (int) $_REQUEST['contactId'];
- // Search for contacts with Referring Practitioner field value equal to contactId value
- $returnFields = array('Id');
- $staffMembers = $app->dsFind(
- 'Contact', // table
- 1, // limit
- 0, // page
- '_ReferringPractitioner', // fieldName
- $practitioner_contact_id, // fieldValue
- $returnFields // returnFields
- );
- // Check do we have success array with contacts from IS?
- if ( empty( $staffMembers ) ) {
- return true;
- // wp_die( '<h3>Nothing to do!</h3>No staff members registered by this practitioner. Aborting.', 'OK', 200 );
- }
- // Extract staff member contactId
- $contact_id = (int) $staffMembers[0]['Id'];
- // Extract IS Tag ID's
- $is_tag_id = $_REQUEST['isTagId'];
- $tag_ids = explode(',', $is_tag_id);
- // Get WordPress user ID
- $user_id = wp_fusion()->user->get_user_id( $contact_id );
- // If no matching user found apply tags directly in Infusionsoft
- if( $user_id == false ) {
- $ret = wp_fusion()->crm->apply_tags( $tag_ids, $contact_id );
- } else {
- $ret = wp_fusion()->user->apply_tags( $tag_ids, $user_id );
- }
- if ( is_wp_error( $ret ) || $ret == false ) {
- error_log('Error performing request');
- error_log(print_r($ret, true));
- }
- wp_die();
- } // END function healthexcel_wpf_infusionsoft_tag_staff_members() {
- add_action( 'wp_ajax_nopriv_wpf_tag_staff_members', 'healthexcel_wpf_infusionsoft_tag_staff_members' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement