|
2 | 2 |
|
3 | 3 | /* |
4 | 4 | Plugin Name: Infusionsoft SDK |
5 | | -Version: 1.0.12 |
| 5 | +Version: 1.0.13 |
6 | 6 | 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. |
7 | 7 | Author: Novak Solutions |
8 | 8 | Author URI: http://novaksolutions.com/ |
|
19 | 19 | /** |
20 | 20 | * Check if options are set properly, and add credentials to SDK if they are. |
21 | 21 | */ |
22 | | -if (get_option('infusionsoft_sdk_app_name') && get_option('infusionsoft_sdk_api_key')) |
| 22 | +if ( infusionsoft_get_app_name() && infusionsoft_get_api_key() ) |
23 | 23 | { |
24 | 24 | 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())); |
26 | 26 | } catch(Infusionsoft_Exception $e) { |
27 | 27 | // SDK didn't load. |
28 | 28 | } |
29 | 29 | } |
30 | 30 |
|
| 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 | + |
31 | 59 | /** |
32 | 60 | * Display error message if app name and API key aren't set. |
33 | 61 | */ |
34 | 62 | 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>"; |
37 | 65 | } |
38 | 66 | } |
39 | 67 | add_action('admin_notices', 'infusionsoft_sdk_error'); |
@@ -95,15 +123,15 @@ function infusionsoft_sdk_sanitize($value) { |
95 | 123 | * Display the app name field. |
96 | 124 | */ |
97 | 125 | function infusionsoft_sdk_callback_function_app_name() { |
98 | | - echo 'https://<input type="text" name="infusionsoft_sdk_app_name" value="' . get_option('infusionsoft_sdk_app_name') . '" size="15" />.infusionsoft.com<br />'; |
| 126 | + echo 'https://<input type="text" name="infusionsoft_sdk_app_name" value="' . infusionsoft_get_app_name() . '" size="15" />.infusionsoft.com<br />'; |
99 | 127 | echo '<span class="description">Your app name is the URL you use to access Infusionsoft.</span>'; |
100 | 128 | } |
101 | 129 |
|
102 | 130 | /** |
103 | 131 | * Display the API key field. |
104 | 132 | */ |
105 | 133 | function infusionsoft_sdk_callback_function_api_key() { |
106 | | - echo '<input type="text" name="infusionsoft_sdk_api_key" value="' . get_option('infusionsoft_sdk_api_key') . '" size="45" /><br />'; |
| 134 | + echo '<input type="text" name="infusionsoft_sdk_api_key" value="' . infusionsoft_get_api_key() . '" size="45" /><br />'; |
107 | 135 | echo '<span class="description"><a href="http://ug.infusionsoft.com/article/AA-00442/0/How-do-I-enable-the-Infusionsoft-API-and-generate-an-API-Key.html">Click here</a> for instructions on finding your API key.</span>'; |
108 | 136 | } |
109 | 137 |
|
@@ -136,11 +164,20 @@ function infusionsoft_sdk_display_link_back(){ |
136 | 164 | function infusionsoft_sdk_display_admin_page(){ |
137 | 165 | echo '<h2>Infusionsoft SDK Settings</h2>'; |
138 | 166 |
|
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 | + } |
144 | 181 |
|
145 | 182 | infusionsoft_sdk_display_link_back(); |
146 | 183 | } |
0 commit comments