PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.3
3.4.3 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 All 196 releases
← All changes | admin/class-convertkit-admin-settings.php +92 -52 2.2.03.4.3 View file →
@@ -6,9 +6,9 @@
6 6 * @author ConvertKit
7 7 */
8 8
9 9 /**
10 - * Registers a screen at Settings > ConvertKit in the WordPress Administration
10 + * Registers a screen at Settings > Kit in the WordPress Administration
11 11 * interface, and handles saving its data.
12 12 *
13 13 * @package ConvertKit
14 14 * @author ConvertKit
@@ -55,25 +55,24 @@
55 55 if ( $hook !== 'settings_page_' . self::SETTINGS_PAGE_SLUG ) {
56 56 return;
57 57 }
58 58
59 - // Enqueue Select2 JS.
60 - convertkit_select2_enqueue_scripts();
59 + // Get active settings section / tab that has been requested.
60 + $section = $this->get_active_section();
61 61
62 - // Enqueue Preview Output JS.
63 - wp_enqueue_script( 'convertkit-admin-preview-output', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/preview-output.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true );
64 -
65 62 /**
66 - * Enqueue JavaScript for the Settings Screen at Settings > ConvertKit
63 + * Enqueue JavaScript for the Settings Screen at Settings > Kit
67 64 *
68 65 * @since 1.9.6
66 + *
67 + * @param string $section Settings section / tab (general|tools|restrict-content).
69 68 */
70 - do_action( 'convertkit_admin_settings_enqueue_scripts' );
69 + do_action( 'convertkit_admin_settings_enqueue_scripts', $section );
71 70
72 71 }
73 72
74 73 /**
75 - * Enqueue CSS for the Settings Screens at Settings > ConvertKit
74 + * Enqueue CSS for the Settings Screens at Settings > Kit
76 75 *
77 76 * @since 1.9.6
78 77 *
79 78 * @param string $hook Hook.
@@ -84,20 +83,22 @@
84 83 if ( $hook !== 'settings_page_' . self::SETTINGS_PAGE_SLUG ) {
85 84 return;
86 85 }
87 86
88 - // Enqueue Select2 CSS.
89 - convertkit_select2_enqueue_styles();
87 + // Get active settings section / tab that has been requested.
88 + $section = $this->get_active_section();
90 89
91 - // Enqueue Settings CSS.
90 + // Always enqueue Settings CSS, as this is used for the UI across all settings sections.
92 91 wp_enqueue_style( 'convertkit-admin-settings', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/settings.css', array(), CONVERTKIT_PLUGIN_VERSION );
93 92
94 93 /**
95 - * Enqueue CSS for the Settings Screen at Settings > ConvertKit
94 + * Enqueue CSS for the Settings Screen at Settings > Kit
96 95 *
97 96 * @since 1.9.6
97 + *
98 + * @param string $section Settings section / tab (general|tools|restrict-content).
98 99 */
99 - do_action( 'convertkit_admin_settings_enqueue_styles' );
100 + do_action( 'convertkit_admin_settings_enqueue_styles', $section );
100 101
101 102 }
102 103
103 104 /**
@@ -107,10 +108,10 @@
107 108 */
108 109 public function add_settings_page() {
109 110
110 111 add_options_page(
111 - __( 'ConvertKit', 'convertkit' ),
112 - __( 'ConvertKit', 'convertkit' ),
112 + __( 'Kit', 'convertkit' ),
113 + __( 'Kit', 'convertkit' ),
113 114 'manage_options',
114 115 self::SETTINGS_PAGE_SLUG,
115 116 array( $this, 'display_settings_page' )
116 117 );
@@ -127,9 +128,21 @@
127 128 $active_section = $this->get_active_section();
128 129 ?>
129 130
130 131 <header>
131 - <h1><?php esc_html_e( 'ConvertKit', 'convertkit' ); ?></h1>
132 + <h1><?php esc_html_e( 'Kit', 'convertkit' ); ?></h1>
133 +
134 + <?php
135 + // Output Help link tab, if it exists.
136 + $documentation_url = $this->get_active_section_documentation_url( $active_section );
137 + if ( $documentation_url !== false ) {
138 + printf(
139 + '<a href="%s" class="convertkit-docs" target="_blank">%s</a>',
140 + esc_attr( $documentation_url ),
141 + esc_html__( 'Help', 'convertkit' )
142 + );
143 + }
144 + ?>
132 145 </header>
133 146
134 147 <div class="wrap">
135 148 <?php
@@ -135,11 +148,30 @@
135 148 <?php
136 149 if ( count( $this->sections ) > 1 ) {
137 150 $this->display_section_nav( $active_section );
138 151 }
152 +
153 + /**
154 + * Defines the settings form's method.
155 + *
156 + * @since 3.0.0
157 + *
158 + * @param string $form_method The method of the form.
159 + * @param string $active_section The active section.
160 + */
161 + $form_method = apply_filters( 'convertkit_admin_settings_form_method', 'post', $active_section );
162 +
163 + /**
164 + * Defines the settings form's action URL.
165 + *
166 + * @since 3.0.0
167 + *
168 + * @param string $form_action_url The URL to submit the form to.
169 + * @param string $active_section The active section.
170 + */
171 + $form_action_url = apply_filters( 'convertkit_admin_settings_form_action_url', admin_url( 'options.php' ), $active_section );
139 172 ?>
140 -
141 - <form method="post" action="options.php" enctype="multipart/form-data">
173 + <form method="<?php echo esc_attr( $form_method ); ?>" action="<?php echo esc_url( $form_action_url ); ?>" enctype="multipart/form-data">
142 174 <?php
143 175 // Iterate through sections to find the active section to render.
144 176 if ( isset( $this->sections[ $active_section ] ) ) {
145 177 $this->sections[ $active_section ]->render();
@@ -148,12 +180,12 @@
148 180 </form>
149 181
150 182 <p class="description">
151 183 <?php
152 - // Output Documentation link, if it exists.
184 + // Output Help link, if it exists.
153 185 $documentation_url = $this->get_active_section_documentation_url( $active_section );
154 186 if ( $documentation_url !== false ) {
155 - echo sprintf(
187 + printf(
156 188 '%s <a href="%s" target="_blank">%s</a>',
157 189 esc_html__( 'If you need help setting up the plugin please refer to the', 'convertkit' ),
158 190 esc_attr( $documentation_url ),
159 191 esc_html__( 'plugin documentation', 'convertkit' )
@@ -174,10 +206,10 @@
174 206 * @return string Tab Name
175 207 */
176 208 private function get_active_section() {
177 209
178 - if ( isset( $_GET['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
179 - return sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
210 + if ( filter_has_var( INPUT_GET, 'tab' ) ) {
211 + return filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
180 212 }
181 213
182 214 // First registered section will be the active section.
183 215 return current( $this->sections )->name;
@@ -224,26 +256,26 @@
224 256 <ul class="convertkit-tabs">
225 257 <?php
226 258 foreach ( $this->sections as $section ) {
227 259 printf(
228 - '<li><a href="?page=%s&tab=%s" class="convertkit-tab %s">%s%s</a></li>',
229 - sanitize_text_field( $_REQUEST['page'] ), // phpcs:ignore WordPress.Security.NonceVerification
230 - esc_html( $section->name ),
231 - $active_section === $section->name ? 'convertkit-tab-active' : '',
260 + '<li><a href="%s" class="convertkit-tab %s">%s%s</a></li>',
261 + esc_url(
262 + add_query_arg(
263 + array(
264 + 'page' => self::SETTINGS_PAGE_SLUG,
265 + 'tab' => $section->name,
266 + ),
267 + admin_url( 'options-general.php' )
268 + )
269 + ),
270 + ( $active_section === $section->name ? 'convertkit-tab-active' : '' ),
232 271 esc_html( $section->tab_text ),
233 - $section->is_beta ? $this->get_beta_tab() : '' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
272 + wp_kses(
273 + $section->is_beta ? $this->get_beta_tab() : '',
274 + convertkit_kses_allowed_html()
275 + )
234 276 );
235 277 }
236 -
237 - // Output Documentation link tab, if it exists.
238 - $documentation_url = $this->get_active_section_documentation_url( $active_section );
239 - if ( $documentation_url !== false ) {
240 - printf(
241 - '<li class="convertkit-docs"><a href="%s" class="convertkit-tab" target="_blank">%s <span class="dashicons dashicons-external"></span></a></li>',
242 - esc_attr( $documentation_url ),
243 - esc_html__( 'Documentation', 'convertkit' )
244 - );
245 - }
246 278 ?>
247 279 </ul>
248 280 <?php
249 281 // WordPress' JS will automatically move any .notice elements to be immediately below .wp-header-end
@@ -256,10 +288,9 @@
256 288
257 289 }
258 290
259 291 /**
260 - * Returns a 'beta' tab wrapped in a span, using wp_kses to ensure only permitted
261 - * HTML elements are included in the output.
292 + * Returns a 'beta' tab wrapped in a span.
262 293 *
263 294 * @since 2.1.0
264 295 *
265 296 * @return string
@@ -265,21 +296,14 @@
265 296 * @return string
266 297 */
267 298 private function get_beta_tab() {
268 299
269 - return wp_kses(
270 - '<span class="convertkit-beta-label">' . esc_html__( 'Beta', 'convertkit' ) . '</span>',
271 - array(
272 - 'span' => array(
273 - 'class' => array(),
274 - ),
275 - )
276 - );
300 + return '<span class="convertkit-beta-label">' . esc_html__( 'Beta', 'convertkit' ) . '</span>';
277 301
278 302 }
279 303
280 304 /**
281 - * Registers settings sections at Settings > ConvertKit.
305 + * Registers settings sections at Settings > Kit.
282 306 *
283 307 * Each section has its own tab.
284 308 *
285 309 * @since 1.9.6
@@ -285,16 +309,31 @@
285 309 * @since 1.9.6
286 310 */
287 311 public function register_sections() {
288 312
313 + // If no Access Token exists, register a settings section that shows a button
314 + // to start the OAuth authentication flow.
315 + $settings = new ConvertKit_Settings();
316 + if ( ! $settings->has_access_and_refresh_token() ) {
317 + // Just register the OAuth screen.
318 + $sections = array(
319 + 'oauth' => new ConvertKit_Admin_Section_OAuth(),
320 + );
321 +
322 + // Assign them to this class.
323 + $this->sections = $sections;
324 +
325 + return;
326 + }
327 +
289 328 // Register the General and Tools settings sections.
290 329 $sections = array(
291 - 'general' => new ConvertKit_Settings_General(),
292 - 'tools' => new ConvertKit_Settings_Tools(),
330 + 'general' => new ConvertKit_Admin_Section_General(),
331 + 'tools' => new ConvertKit_Admin_Section_Tools(),
293 332 );
294 333
295 334 /**
296 - * Registers settings sections at Settings > ConvertKit.
335 + * Registers settings sections at Settings > Kit.
297 336 *
298 337 * @since 1.9.6
299 338 *
300 339 * @param array $sections Array of settings classes that handle individual tabs e.g. General, Tools etc.
@@ -329,8 +368,9 @@
329 368 // Pass request to section's documentation_url() function, including UTM parameters.
330 369 return add_query_arg(
331 370 array(
332 371 'utm_source' => 'wordpress',
372 + 'utm_term' => get_locale(),
333 373 'utm_content' => 'convertkit',
334 374 ),
335 375 $this->sections[ $active_section ]->documentation_url()
336 376 );