|
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'); |
@@ -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