diff --git a/infusionsoft-sdk.php b/infusionsoft-sdk.php index 7077d36..80f21e1 100644 --- a/infusionsoft-sdk.php +++ b/infusionsoft-sdk.php @@ -2,7 +2,7 @@ /* Plugin Name: Infusionsoft SDK -Version: 1.0.12 +Version: 1.0.13 Description: Integrate with the Infusionsoft API using the Novak Solutions SDK. This plugin is a dependency for other Infusionsoft plugins, like the Infusionsoft One-click Upsell plugin. Author: Novak Solutions Author URI: http://novaksolutions.com/ @@ -19,21 +19,49 @@ /** * Check if options are set properly, and add credentials to SDK if they are. */ -if (get_option('infusionsoft_sdk_app_name') && get_option('infusionsoft_sdk_api_key')) +if ( infusionsoft_get_app_name() && infusionsoft_get_api_key() ) { try{ - Infusionsoft_AppPool::addApp(new Infusionsoft_App(get_option('infusionsoft_sdk_app_name') . '.infusionsoft.com', get_option('infusionsoft_sdk_api_key'))); + Infusionsoft_AppPool::addApp(new Infusionsoft_App(infusionsoft_get_app_name() . '.infusionsoft.com', infusionsoft_get_api_key())); } catch(Infusionsoft_Exception $e) { // SDK didn't load. } } +/** + * Infusionsoft connection credentials + * Connection details can be provided by PHP constant in your wp-config.php file + * @return array + */ +function infusionsoft_get_connection_creds() { + return array( + 'app_name' => defined('INFUSIONSOFT_APP_NAME') ? INFUSIONSOFT_APP_NAME : get_option('infusionsoft_sdk_app_name'), + 'api_key' => defined('INFUSIONSOFT_API_KEY') ? INFUSIONSOFT_API_KEY : get_option('infusionsoft_sdk_api_key') + ); +} + +/** + * Get the Infusionsoft App Name + * @return string + */ +function infusionsoft_get_app_name() { + return infusionsoft_get_connection_creds()['app_name']; +} + +/** + * Get the Infusionsoft API Key + * @return string + */ +function infusionsoft_get_api_key() { + return infusionsoft_get_connection_creds()['api_key']; +} + /** * Display error message if app name and API key aren't set. */ function infusionsoft_sdk_error() { - if(get_option('infusionsoft_sdk_app_name') == '' || get_option('infusionsoft_sdk_api_key') == ''){ - echo "
Please set your Infusionsoft SDK app name and API key on the settings page.
Please set your Infusionsoft SDK app name and API key on the settings page or in your wp-config.php
file.
Your Infusionsoft connection details are set via PHP constant; usually in your wp-config.php file.
"; + echo "