| 1 |
<?php |
| 2 |
|
| 3 |
require_once "base.php"; |
| 4 |
|
| 5 |
class ConvertKitSettingsGeneral extends ConvertKitSettingsSection { |
| 6 |
|
| 7 |
public function __construct() { |
| 8 |
$this->settings_key = WP_ConvertKit::SETTINGS_PAGE_SLUG; |
| 9 |
$this->name = 'general'; |
| 10 |
$this->title = 'General Settings'; |
| 11 |
$this->tab_text = 'General'; |
| 12 |
|
| 13 |
parent::__construct(); |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Register and add settings |
| 18 |
*/ |
| 19 |
public function register_fields() { |
| 20 |
add_settings_field( |
| 21 |
'api_key', |
| 22 |
'API Key', |
| 23 |
array($this, 'api_key_callback'), |
| 24 |
$this->settings_key, |
| 25 |
$this->name |
| 26 |
); |
| 27 |
|
| 28 |
add_settings_field( |
| 29 |
'default_form', |
| 30 |
'Default Form', |
| 31 |
array($this, 'default_form_callback'), |
| 32 |
$this->settings_key, |
| 33 |
$this->name, |
| 34 |
$this->api->get_resources('forms') |
| 35 |
); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Prints help info for this section |
| 40 |
*/ |
| 41 |
public function print_section_info() { |
| 42 |
?> |
| 43 |
<p> |
| 44 |
Choosing a default form will embed it at the bottom of every post or page |
| 45 |
(in single view only) across your site. If you wish to turn off form |
| 46 |
embedding or select a different form for an individual post or page, you |
| 47 |
can do so within the ConvertKit meta box on the editing form. |
| 48 |
</p> |
| 49 |
<p> |
| 50 |
The default form can be inserted into the middle of post or page content |
| 51 |
by using the <code>[convertkit]</code> shortcode. |
| 52 |
</p> |
| 53 |
<?php |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Renders the input for api key entry |
| 58 |
*/ |
| 59 |
public function api_key_callback() { |
| 60 |
$html = sprintf( |
| 61 |
'<input type="text" class="regular-text code" id="api_key" name="%s[api_key]" value="%s" />', |
| 62 |
$this->settings_key, |
| 63 |
isset($this->options['api_key']) ? esc_attr($this->options['api_key']) : '' |
| 64 |
); |
| 65 |
|
| 66 |
$html .= '<p class="description"><a href="https://app.convertkit.com/account/edit" target="_blank">Get your ConvertKit API Key</a></p>'; |
| 67 |
|
| 68 |
echo $html; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Renders the form select list |
| 73 |
* |
| 74 |
* @param array $forms Form listing |
| 75 |
*/ |
| 76 |
public function default_form_callback($forms) { |
| 77 |
$html = sprintf('<select id="default_form" name="%s[default_form]">', $this->settings_key); |
| 78 |
$html .= '<option value="default">None</option>'; |
| 79 |
foreach($forms as $form) { |
| 80 |
$html .= sprintf( |
| 81 |
'<option value="%s" %s>%s</option>', |
| 82 |
esc_attr($form['id']), |
| 83 |
selected($this->options['default_form'], $form['id'], false), |
| 84 |
esc_html($form['name']) |
| 85 |
); |
| 86 |
} |
| 87 |
$html .= '</select>'; |
| 88 |
|
| 89 |
if (empty($forms)) { |
| 90 |
$html .= '<p class="description">Enter your API Key above to get your available forms.</p>'; |
| 91 |
} |
| 92 |
|
| 93 |
echo $html; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Sanitizes the settings |
| 98 |
* |
| 99 |
* @param array $settings The settings fields submitted |
| 100 |
* @return array Sanitized settings |
| 101 |
*/ |
| 102 |
public function sanitize_settings($settings) { |
| 103 |
return shortcode_atts(array( |
| 104 |
'api_key' => '', |
| 105 |
'default_form' => 0 |
| 106 |
), $settings); |
| 107 |
} |
| 108 |
} |
| 109 |
|