Skip to content

Commit 6e46a8d

Browse files
author
Philip Downer
committed
Allow connection creds to be supplied via PHP constant.
This allows users to prevent connection details from being stored in the WordPress database.
1 parent 8d95340 commit 6e46a8d

File tree

1 file changed

+47
-10
lines changed

1 file changed

+47
-10
lines changed

infusionsoft-sdk.php

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/*
44
Plugin Name: Infusionsoft SDK
5-
Version: 1.0.12
5+
Version: 1.0.13
66
Description: Integrate with the Infusionsoft API using the Novak Solutions SDK. This plugin is a dependency for other Infusionsoft plugins, like the <a href="http://wordpress.org/plugins/infusionsoft-one-click-upsell/">Infusionsoft One-click Upsell</a> plugin.
77
Author: Novak Solutions
88
Author URI: http://novaksolutions.com/
@@ -19,21 +19,49 @@
1919
/**
2020
* Check if options are set properly, and add credentials to SDK if they are.
2121
*/
22-
if (get_option('infusionsoft_sdk_app_name') && get_option('infusionsoft_sdk_api_key'))
22+
if ( infusionsoft_get_app_name() && infusionsoft_get_api_key() )
2323
{
2424
try{
25-
Infusionsoft_AppPool::addApp(new Infusionsoft_App(get_option('infusionsoft_sdk_app_name') . '.infusionsoft.com', get_option('infusionsoft_sdk_api_key')));
25+
Infusionsoft_AppPool::addApp(new Infusionsoft_App(infusionsoft_get_app_name() . '.infusionsoft.com', infusionsoft_get_api_key()));
2626
} catch(Infusionsoft_Exception $e) {
2727
// SDK didn't load.
2828
}
2929
}
3030

31+
/**
32+
* Infusionsoft connection credentials
33+
* Connection details can be provided by PHP constant in your wp-config.php file
34+
* @return array
35+
*/
36+
function infusionsoft_get_connection_creds() {
37+
return array(
38+
'app_name' => defined('INFUSIONSOFT_APP_NAME') ? INFUSIONSOFT_APP_NAME : get_option('infusionsoft_sdk_app_name'),
39+
'api_key' => defined('INFUSIONSOFT_API_KEY') ? INFUSIONSOFT_API_KEY : get_option('infusionsoft_sdk_api_key')
40+
);
41+
}
42+
43+
/**
44+
* Get the Infusionsoft App Name
45+
* @return string
46+
*/
47+
function infusionsoft_get_app_name() {
48+
return infusionsoft_get_connection_creds()['app_name'];
49+
}
50+
51+
/**
52+
* Get the Infusionsoft API Key
53+
* @return string
54+
*/
55+
function infusionsoft_get_api_key() {
56+
return infusionsoft_get_connection_creds()['api_key'];
57+
}
58+
3159
/**
3260
* Display error message if app name and API key aren't set.
3361
*/
3462
function infusionsoft_sdk_error() {
35-
if(get_option('infusionsoft_sdk_app_name') == '' || get_option('infusionsoft_sdk_api_key') == ''){
36-
echo "<div class=\"error\"><p><strong>Please set your Infusionsoft SDK app name and API key on the <a href=\"" . admin_url( 'options-general.php?page=infusionsoft-sdk/infusionsoft-sdk.php' ) . "\">settings page.</a></strong></p></div>";
63+
if( !infusionsoft_get_app_name() || !infusionsoft_get_api_key() ) {
64+
echo "<div class=\"error\"><p><strong>Please set your Infusionsoft SDK app name and API key on the <a href=\"" . admin_url( 'options-general.php?page=infusionsoft-sdk/infusionsoft-sdk.php' ) . "\">settings page or in your <pre>wp-config.php</pre> file.</a></strong></p></div>";
3765
}
3866
}
3967
add_action('admin_notices', 'infusionsoft_sdk_error');
@@ -136,11 +164,20 @@ function infusionsoft_sdk_display_link_back(){
136164
function infusionsoft_sdk_display_admin_page(){
137165
echo '<h2>Infusionsoft SDK Settings</h2>';
138166

139-
echo '<form method="POST" action="options.php">';
140-
settings_fields('infusionsoft_sdk_settings'); //pass slug name of page
141-
do_settings_sections('infusionsoft_sdk_settings'); //pass slug name of page
142-
submit_button();
143-
echo '</form>';
167+
if( !defined('INFUSIONSOFT_APP_NAME') && !defined('INFUSIONSOFT_API_KEY') ) {
168+
echo '<form method="POST" action="options.php">';
169+
settings_fields('infusionsoft_sdk_settings'); //pass slug name of page
170+
do_settings_sections('infusionsoft_sdk_settings'); //pass slug name of page
171+
submit_button();
172+
echo '</form>';
173+
}
174+
else {
175+
echo "<p>Your Infusionsoft connection details are set via PHP constant; usually in your wp-config.php file.</p>";
176+
echo "<ul>";
177+
echo "<li><strong>App Name:</strong> " . INFUSIONSOFT_APP_NAME . "</li>";
178+
echo "<li><strong>API Key:</strong> " . str_repeat('*', strlen(INFUSIONSOFT_API_KEY)-4) . substr(INFUSIONSOFT_API_KEY, -4) . "</li>";
179+
echo "</ul>";
180+
}
144181

145182
infusionsoft_sdk_display_link_back();
146183
}

0 commit comments

Comments
 (0)