Integrate your WordPress Site with Highrise using a Plugin

Highrise and WordPress, both are the most used applications in their own fields. Integrating Highrise with WordPres can bring in automation, reduce the human efforts and prove to be more advantageous.

Unfortunately, there is no ready-made plugin available, that can enable this efficiently. Here in this post, we will make a plugin that integrates the WordPress and the Highrise CRM. With this plugin when a visitor fills up the form on your website or you get any leads through your website, it will store the data on Highrise. It will also create a task and assign it to a user.

Highrise provides its API that helps to integrate Highrise with a WordPress website. We will use the same to develop a plugin that will enable  the following functionalities.

  1. Check if the contact with the given email ID exists on Highrise or not.
  2. If does not exist, it creates a contact on Highrise.
  3. Add a note from the message to the contact.
  4. Create a task for a particular note with the mentioned task category.
  5.  Assign the task to the mentioned CRM user.
  6. If any exception is generated by the API, it will send an email to the admin.

To integrate Highrise with WordPress site you will need its credentials:

1). Account Name

2). Highrise API token key

Getting Required Credentials Of Highrise CRM

1). Account Name

When you login to 37Signal’s Highrise CRM , it redirects to a page with a sub-domain. The ‘sub-domain’ here is your account name. For example, your link is:

http://xyz.highrisehq.com

Then your account name is ‘xyz’.

2). Highrise API Token Key

After logging into your Highrise CRM’s account, visit ‘My Profile’ under ‘Accounts & Settings’ . Under the tab API token you can find your key there.

Make sure you do not reveal the key to anyone, because with this key and account name, anyone can easily access your Highrise account. In case, the key is revealed to someone, you can regenerate it there.

Getting Started With Plugin Development for Integrating Highrise With WordPress

Before starting the tutorial you may like to get the whole source code for integrating Highrise with WordPress on GitHub.

To start coding open up your project in any of your favorite IDE. Go to ‘ Wp-Content’ and under that go to the folder ‘ Plugins’. Create a new folder with the name ‘ highrise-api’.

Now in the ‘ highrise-api’ create a file with the name ‘ index.php ’. This will act as your base file for the WordPress plugin to integrate Highrise with WordPress site. Copy paste the below given code in your index file.

  1. /*
  2.  Plugin Name: Highrise API
  3.  Plugin URI: https://www.regur.net
  4.  Description: The plugin integrates the CRM highrise with the WordPress website. Whenever a form is submitted by the end user, the plugin will store the details in Highrise in the predefined format.
  5.  Author: Regur Technology Solutions
  6.  Version: 1.0
  7.  Author URI: https://www.regur.net
  8.  */

This will make up a base for your plugin, which will show it in the plugin’s list in your WordPress admin panel.

Getting The Highrise Library For Your WordPress Plugin

Visit GitHub for Highrise PHP API and in the files stored there, go to ‘ lib’ folder. Under that open up the file HighriseAPI.class.php. You can click here to directly open up the HighriseAPI.class.php file.

Now go back to the IDE and create a new folder named ‘ lib ’ under the ‘ highrise-api’ folder that we created recently. Now download the file and save it in the ‘ lib’ folder. If you face difficulty in downloading the file, simply copy paste the whole content and paste it in a new file in the ‘ lib’ folder. Make sure that you name the new file similar to that of the file in GitHub i.e. HighriseAPI.class.php.

This will help us in integrating Highrise with WordPress to call all the methods to store and fetch data from Highrise.

Create Config File To Define Constants Used In Integrating Highrise With WordPress

There are a few constants that will be used throughout the code. So in case if you need to change them in future, you do not need to go changing all the variables throughout the code. Here, we will decalre constatnts like form Id, task owner in Highrise, time frame of each task, etc.

Create a file ‘highrise-api-config.php’ in the ‘highrise-api’ folder and paste the below given code:

Note: Make sure you change all the constant’s values to make it compatible with your site.

  1. //
  2. 	define('ACCOUNT_NAME', 'xyz');			// Form ID should be similar to the form you have in your front end
  3. 	define('API_TOKEN', 'g126dv1df1vgfd2b546dfg12dgf');			// Form ID should be similar to the form you have in your front end
  4.  
  5. 	define('FORM_ID', 'contact-us');			// Form ID should be similar to the form you have in your front end
  6.  
  7. 	define('FROM_EMAIL', 'highrise.api@yoursite.com');		// FROM EMAIL to send email in case any exception occurs
  8. 	define('TO_EMAIL', 'someone@client.site');						// TO EMAIL to send email in case any exception occurs
  9. 	define('EMAIL_SUBJECT', 'IMP: Form Entry was not submitted to Highrise');		// EMAIL SUBJECT to send email in case any exception occurs
  10.  
  11. 	define('TASK_CATEGORY_ID', '5959885');				//Category ID for Highrise. You can get this by inspecting the element of dropdown in task category list.
  12. 	define('TIME_FRAME', 'tomorrow');					//Time frame for each created task on highrise
  13. 	define('SUBJECT_NOTE', 'Party');					//Note Subject to be put up on Highrise
  14. 	define('OWNER_ID', '1152365');						//The CRM user to whom the tasks will be assigned. You can get it by inspecitn the dropdown element in the users list while creating a task

Configuring Highrise API.

Now, its time to link up your WordPress site with Highrise API. Create a ‘functions.php’ file in the ‘ highrise-api’ folder. Paste the below given code into the file.

  1. //=====================================================================
  2. //			Connect To Highrise
  3. //=====================================================================
  4.  
  5. 	function initiateApi()
  6. 	{
  7. 		require_once("lib/HighriseAPI.class.php");
  8.  
  9. 			$highrise = new HighriseAPI();
  10. 			$highrise->setAccount( ACCOUNT_NAME );
  11. 			$highrise->setToken( API_TOKEN );
  12. 			$highrise->debug = false;	
  13.  
  14. 		return $highrise; 
  15.         }

This will create a function to initiate the API integration every time we need.  Now go to index.php and include the ‘functions.php‘ and ‘highrise-api-config.php‘ file.

  1. include "highrise-api-config.php";
  2. include "functions.php";

Now, Its Time To Get In Action. Save Details On Highrise

Go to ‘ functions.php’ and paste the below-given code snippets:

Initializing Connection With Highrise API:

Here we will call the function ‘initiateApi that we defined earlier. This will give the necessary credentials to connect with the Highrise API. The ‘try’ block at the end of this code snippet is used to check whether an exception has occured or not.

  1. //=====================================================================
  2. //			Save Details On Highrise
  3. //=====================================================================
  4.  
  5.  
  6. 	function saveDetailsOnHighrise()
  7. 	{
  8.  
  9. 		$highrise = initiateApi();
  10.  
  11. 		if( $_POST['contact-form-id'] == FORM_ID )			//$_POST['contact-form-id'] will give the id of the form. Make sure you have such field in your contact form. If not make a hidden field.
  12. 		{
  13. 			try{

Get Required Details To Store Data In Highrise

Here we will collect the data sent by the form. In this example, we have three fields namely name, email Id, and message (as a note). Also, we need few other constants to create a task on highrise like time frame, owner, etc.

  1. //
  2. 				//Get required details  IMPORTANT: Change the field names according to your form.
  3. 				//
  4.  
  5. 				$name 			= $_POST['name'];				//Name of the contact
  6. 				$emailId 		= $_POST['email'];				//Email of the contact
  7. 				$noteBody 		= $_POST['message'];			//Message in the form to be stored as note in Highrise
  8. 				$taskCategoryId = TASK_CATEGORY_ID;				//Task Category ID
  9. 				$timeFrame 		= TIME_FRAME;					//Set the time frame for task generated at Highrise
  10. 				$noteSubject 	= SUBJECT_NOTE;					//Set the subject of each note
  11. 				$ownerId 		= OWNER_ID;				//To whom the task will be assigned

Check If A Contact Exists In Highrise

As per our description above, our code will first check if there exists a contact on Highrise with the same email Id that is entered in the form. If the contact exists, it will return the contact’s unique Id.

  1. //
  2. 				// Get a persons' ID if person exists with the entered mailId.
  3. 				//
  4.  
  5. 				$personId = '';
  6. 				$people = $highrise->findPeopleByEmail($emailId);
  7. 				foreach($people as $person)
  8. 				{
  9. 					$personId = $person->getId();
  10. 				}

If A Contact Is Not Found On Highrise, Add It

Now, if the contact is not found on the highrise with the same email Id as that entered in the form, it will be created. We do this so that all the notes for the same person could be viewed at the same time in chronological order.

  1. //
  2. 				//If no person found with the entered email ID add the person (Modify the fields according to the form)
  3. 				//
  4.  
  5. 				if( empty( $personId ) )
  6. 				{
  7. 					$person = new HighrisePerson($highrise);
  8. 					$person->setFirstName($name);
  9. 					$person->addEmailAddress($emailId);
  10. 					$person->save();
  11.  
  12. 					$people = $highrise->findPeopleByEmail($emailId);
  13. 					foreach($people as $person)
  14. 					{
  15. 						$personId = $person->getId();
  16. 					}
  17. 				}

Add A Note On Highrise With Your WordPress Plugin

Here, we are saving the message in the form as a note on Highrise. It will be saved under the contact / person that we created in the above code snippet.

  1. //
  2. 				//Add Note
  3. 				//
  4.  
  5. 				$note = new HighriseNote($highrise);
  6. 				$note->setSubjectId($personId);
  7. 				$note->setSubjectType($noteSubject);
  8. 				$note->setBody($noteBody);
  9. 				$note->save();

Create A Task On Highrise

After adding a note to the contact, we will now add a task to follow up and assign it to the specified CRM user. This task can be viewed from the tasks list and from the contact’s detail as well.

  1. //
  2. 				// Create a task
  3. 				//
  4.  
  5. 				$task = new HighriseTask($highrise);
  6. 				$task->setBody("Follow up with $name by Email");
  7. 				$task->setPublic(true);
  8. 				$task->setCategoryId($taskCategoryId);
  9. 				$task->setFrame($timeFrame);
  10. 				$task->setSubjectId($personId);
  11. 				$task->setSubjectName($name);
  12. 				$task->setSubjectType($noteSubject);
  13. 				$task->setOwnerId($ownerId);
  14. 				$task->save();
  15.  
  16. 			} //End try

Send An Email To The Admin If An Exception Is Thrown.

We started a ‘try‘ at the beginning of the code. If the Highrise API throws an exception it could be caught by ‘catch’ and it will be stored in $e as in the below code. If an exception occurs, the WordPress plugin will send an email to the admin, notifying about the exception.

  1.                          catch (Exception $e){
  2. 				//Send an email to the admin, in case there is any exception generated by Highrise API.
  3.  
  4. 				$body = "The data was not stored in Highrise. 
  5. 						Get the data for this entry from  WordPress admin panel. 
  6. 						Please verify the credentials and if the problem persists, contact site admin.<br>
  7.  
  8. 						Name: $name<br>
  9. 						EmailId = $emailId<br>
  10. 						Note:<br>
  11. 						$noteBody"; 
  12.  
  13. 				$body = nl2br($body);
  14.  
  15. 				sendEmail($body);
  16. 			}
  17.  
  18. 		}
  19. 	}

Sending Custom Emails With A Custom WordPress Plugin

As the above code is sending an email when an exception is thrown, there is a function in the last line ‘sendEmail($body);‘ We need to define the function that will send an email using the ‘wp_email()’ function of WordPress.

  1.         function sendEmail($body)
  2. 	{
  3. 		$from 		= FROM_EMAIL;
  4. 		$to 		= TO_EMAIL;
  5. 		$subject 	= EMAIL_SUBJECT;
  6.  
  7. 		if(empty($from) || empty($to) || empty($subject) || empty($body))
  8. 		{
  9. 			return false;
  10. 		}
  11.  
  12. 		if(!(filter_var($to, FILTER_VALIDATE_EMAIL)))
  13. 		{			
  14. 			return false;		
  15. 		}
  16.  
  17. 		$headers = "MIME-Version: 1.0" . "\r\n";
  18. 		$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
  19. 		$headers .= "From: $from \r\n";
  20.  
  21. 		wp_mail($to,$subject,$body,$headers);
  22. 	}

Hook The Function When Form Is Submitted

Here, in this example we have used the hook of JetPack forms. You need to use the hook that is compatible with your form. Paste the below given code in ‘index.php‘.

  1.         function addContact()
  2. 	{
  3. 		saveDetailsOnHighrise();
  4. 	}
  5.  
  6. 	add_action('save_post_feedback', 'addContact');

Here, ‘save_post_feedback‘ is the hook of the JetPack form, you need to replace it with the hook of your form.

You can also find the complete source code for integrating Highrise with WordPress on GitHub.

This completes our WordPress custom Plugin to integrate Highrise with WordPress. Now, activate your plugin in the WordPress admin panel and Get, Set, Go..!

For more such posts follow us on Facebook. 🙂