PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 1.4.8
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v1.4.8
3.4.2 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 All 195 releases
convertkit / admin / section / class-convertkit-settings-general.php

class-convertkit-settings-general.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 1.4.8, at admin/section/class-convertkit-settings-general.php

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