PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 1.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v1.4.3
3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 All 194 releases
convertkit / admin / section / general.php

general.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 1.4.3, at admin/section/general.php

183 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once "base.php";
4
5 /**
6 * Class ConvertKitSettingsGeneral
7 */
8 class ConvertKitSettingsGeneral extends ConvertKitSettingsSection {
9
10 /**
11 * Constructor
12 */
13 public function __construct() {
14 $this->settings_key = WP_ConvertKit::SETTINGS_PAGE_SLUG;
15 $this->name = 'general';
16 $this->title = 'General Settings';
17 $this->tab_text = 'General';
18
19 parent::__construct();
20 }
21
22 /**
23 * Register and add settings
24 */
25 public function register_fields() {
26 add_settings_field(
27 'api_key',
28 'API Key',
29 array($this, 'api_key_callback'),
30 $this->settings_key,
31 $this->name
32 );
33
34 add_settings_field(
35 'api_secret',
36 'API Secret',
37 array($this, 'api_secret_callback'),
38 $this->settings_key,
39 $this->name
40 );
41
42 add_settings_field(
43 'default_form',
44 'Default Form',
45 array($this, 'default_form_callback'),
46 $this->settings_key,
47 $this->name,
48 $this->api->get_resources('forms')
49 );
50
51 add_settings_field(
52 'debug',
53 'Debug',
54 array($this, 'debug_callback'),
55 $this->settings_key,
56 $this->name
57 );
58
59 }
60
61 /**
62 * Prints help info for this section
63 */
64 public function print_section_info() {
65 ?>
66 <p>
67 Choosing a default form will embed it at the bottom of every post or page
68 (in single view only) across your site. If you wish to turn off form
69 embedding or select a different form for an individual post or page, you
70 can do so within the ConvertKit meta box on the editing form.
71 </p>
72 <p>
73 The default form can be inserted into the middle of post or page content
74 by using the <code>[convertkit]</code> shortcode.
75 </p>
76 <?php
77
78 }
79
80 /**
81 * Renders the input for api key entry
82 */
83 public function api_key_callback() {
84 $html = sprintf(
85 '<input type="text" class="regular-text code" id="api_key" name="%s[api_key]" value="%s" />',
86 $this->settings_key,
87 isset($this->options['api_key']) ? esc_attr($this->options['api_key']) : ''
88 );
89
90 $html .= '<p class="description"><a href="https://app.convertkit.com/account/edit" target="_blank">Get your ConvertKit API Key</a></p>';
91
92 echo $html;
93 }
94
95 /**
96 * Renders the input for api key entry
97 */
98 public function api_secret_callback() {
99 $html = sprintf(
100 '<input type="text" class="regular-text code" id="api_secret" name="%s[api_secret]" value="%s" />',
101 $this->settings_key,
102 isset($this->options['api_secret']) ? esc_attr($this->options['api_secret']) : ''
103 );
104
105 $html .= '<p class="description"><a href="https://app.convertkit.com/account/edit" target="_blank">Get your ConvertKit API Secret.</a> This setting is required to unsubscribe subscribers.</p>';
106
107 echo $html;
108 }
109
110 /**
111 * Renders the form select list
112 *
113 * @param array $forms Form listing
114 */
115 public function default_form_callback($forms) {
116
117 // check for error in response
118 if ( isset( $forms[0]['id'] ) && '-2' == $forms[0]['id'] ) {
119 $html = '<p class="error">' . __('Error connecting to API. Please verify your site can connect to <code>https://api.convertkit.com</code>','convertkit') . '</p>';
120 } else {
121 $html = sprintf( '<select id="default_form" name="%s[default_form]">', $this->settings_key );
122 $html .= '<option value="default">None</option>';
123 foreach ( $forms as $form ) {
124 $html .= sprintf(
125 '<option value="%s" %s>%s</option>',
126 esc_attr( $form['id'] ),
127 selected( $this->options['default_form'], $form['id'], false ),
128 esc_html( $form['name'] )
129 );
130 }
131 $html .= '</select>';
132 }
133
134 if ( empty( $this->options['api_key'] ) ) {
135 $html .= '<p class="description">Enter your API Key above to get your available forms.</p>';
136 }
137
138 if (empty($forms)) {
139 $html .= '<p class="description">There are no forms setup in your account. You can go <a href="https://app.convertkit.com/landing_pages/new" target="_blank">here</a> to create one.</p>';
140 }
141
142 echo $html;
143 }
144
145 /**
146 * Renders the input for debug setting
147 */
148 public function debug_callback() {
149
150 $debug = '';
151 if ( isset( $this->options['debug'] ) && 'on' == $this->options['debug'] ) {
152 $debug = 'checked';
153 }
154
155 $html = sprintf(
156 '<input type="checkbox" class="" id="debug" name="%s[debug]" %s />%s',
157 $this->settings_key,
158 $debug,
159 __('Save connection data to a log file.','convertkit')
160 );
161
162 echo $html;
163 }
164
165 /**
166 * Sanitizes the settings
167 *
168 * @param array $settings The settings fields submitted
169 * @return array Sanitized settings
170 */
171 public function sanitize_settings($settings) {
172
173 // clear api transient
174 delete_transient( 'convertkit_get_api_response' );
175 return shortcode_atts(array(
176 'api_key' => '',
177 'api_secret' => '',
178 'default_form' => 0,
179 'debug' => ''
180 ), $settings);
181 }
182 }
183