PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.0.2
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.0.2
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 -162 3.4.22.0.2 View file →
@@ -6,9 +6,9 @@
6 6 * @author ConvertKit
7 7 */
8 8
9 9 /**
10 - * Registers a screen at Settings > Kit in the WordPress Administration
10 + * Registers a screen at Settings > ConvertKit in the WordPress Administration
11 11 * interface, and handles saving its data.
12 12 *
13 13 * @package ConvertKit
14 14 * @author ConvertKit
@@ -55,24 +55,25 @@
55 55 if ( $hook !== 'settings_page_' . self::SETTINGS_PAGE_SLUG ) {
56 56 return;
57 57 }
58 58
59 - // Get active settings section / tab that has been requested.
60 - $section = $this->get_active_section();
59 + // Enqueue Select2 JS.
60 + convertkit_select2_enqueue_scripts();
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 +
62 65 /**
63 - * Enqueue JavaScript for the Settings Screen at Settings > Kit
66 + * Enqueue JavaScript for the Settings Screen at Settings > ConvertKit
64 67 *
65 68 * @since 1.9.6
66 - *
67 - * @param string $section Settings section / tab (general|tools|restrict-content).
68 69 */
69 - do_action( 'convertkit_admin_settings_enqueue_scripts', $section );
70 + do_action( 'convertkit_admin_settings_enqueue_scripts' );
70 71
71 72 }
72 73
73 74 /**
74 - * Enqueue CSS for the Settings Screens at Settings > Kit
75 + * Enqueue CSS for the Settings Screens at Settings > ConvertKit
75 76 *
76 77 * @since 1.9.6
77 78 *
78 79 * @param string $hook Hook.
@@ -83,22 +84,20 @@
83 84 if ( $hook !== 'settings_page_' . self::SETTINGS_PAGE_SLUG ) {
84 85 return;
85 86 }
86 87
87 - // Get active settings section / tab that has been requested.
88 - $section = $this->get_active_section();
88 + // Enqueue Select2 CSS.
89 + convertkit_select2_enqueue_styles();
89 90
90 - // Always enqueue Settings CSS, as this is used for the UI across all settings sections.
91 + // Enqueue Settings CSS.
91 92 wp_enqueue_style( 'convertkit-admin-settings', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/settings.css', array(), CONVERTKIT_PLUGIN_VERSION );
92 93
93 94 /**
94 - * Enqueue CSS for the Settings Screen at Settings > Kit
95 + * Enqueue CSS for the Settings Screen at Settings > ConvertKit
95 96 *
96 97 * @since 1.9.6
97 - *
98 - * @param string $section Settings section / tab (general|tools|restrict-content).
99 98 */
100 - do_action( 'convertkit_admin_settings_enqueue_styles', $section );
99 + do_action( 'convertkit_admin_settings_enqueue_styles' );
101 100
102 101 }
103 102
104 103 /**
@@ -108,10 +107,10 @@
108 107 */
109 108 public function add_settings_page() {
110 109
111 110 add_options_page(
112 - __( 'Kit', 'convertkit' ),
113 - __( 'Kit', 'convertkit' ),
111 + __( 'ConvertKit', 'convertkit' ),
112 + __( 'ConvertKit', 'convertkit' ),
114 113 'manage_options',
115 114 self::SETTINGS_PAGE_SLUG,
116 115 array( $this, 'display_settings_page' )
117 116 );
@@ -128,22 +127,14 @@
128 127 $active_section = $this->get_active_section();
129 128 ?>
130 129
131 130 <header>
132 - <h1><?php esc_html_e( 'Kit', 'convertkit' ); ?></h1>
131 + <h1><?php esc_html_e( 'ConvertKit', 'convertkit' ); ?></h1>
132 + </header>
133 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 - ?>
145 - </header>
134 + <?php
135 + $this->maybe_display_notices();
136 + ?>
146 137
147 138 <div class="wrap">
148 139 <?php
149 140 if ( count( $this->sections ) > 1 ) {
@@ -148,30 +139,11 @@
148 139 <?php
149 140 if ( count( $this->sections ) > 1 ) {
150 141 $this->display_section_nav( $active_section );
151 142 }
143 + ?>
152 144
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 );
172 - ?>
173 - <form method="<?php echo esc_attr( $form_method ); ?>" action="<?php echo esc_url( $form_action_url ); ?>" enctype="multipart/form-data">
145 + <form method="post" action="options.php" enctype="multipart/form-data">
174 146 <?php
175 147 // Iterate through sections to find the active section to render.
176 148 if ( isset( $this->sections[ $active_section ] ) ) {
177 149 $this->sections[ $active_section ]->render();
@@ -180,18 +152,12 @@
180 152 </form>
181 153
182 154 <p class="description">
183 155 <?php
184 - // Output Help link, if it exists.
185 - $documentation_url = $this->get_active_section_documentation_url( $active_section );
186 - if ( $documentation_url !== false ) {
187 - printf(
188 - '%s <a href="%s" target="_blank">%s</a>',
189 - esc_html__( 'If you need help setting up the plugin please refer to the', 'convertkit' ),
190 - esc_attr( $documentation_url ),
191 - esc_html__( 'plugin documentation', 'convertkit' )
192 - );
193 - }
156 + printf(
157 + 'If you need help setting up the plugin please refer to the %s plugin documentation.</a>',
158 + '<a href="https://help.convertkit.com/en/articles/2502591-the-convertkit-wordpress-plugin" target="_blank">'
159 + );
194 160 ?>
195 161 </p>
196 162 </div>
197 163 <?php
@@ -206,10 +172,10 @@
206 172 * @return string Tab Name
207 173 */
208 174 private function get_active_section() {
209 175
210 - if ( filter_has_var( INPUT_GET, 'tab' ) ) {
211 - return filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
176 + if ( isset( $_GET['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
177 + return sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
212 178 }
213 179
214 180 // First registered section will be the active section.
215 181 return current( $this->sections )->name;
@@ -216,36 +182,71 @@
216 182
217 183 }
218 184
219 185 /**
186 + * Display notice(s) immediately after the settings screen header.
187 + *
188 + * @since 1.9.6
189 + */
190 + private function maybe_display_notices() {
191 +
192 + $notices = array();
193 +
194 + // Check the mbstring extension is loaded.
195 + if ( ! extension_loaded( 'mbstring' ) ) {
196 + $notices[] = array(
197 + 'type' => 'warning',
198 + 'message' => sprintf(
199 + /* translators: link to php.net manual */
200 + __( 'Notice: Your server does not support the %s function - this is required for better character encoding. Please contact your webhost to have it installed.', 'convertkit' ),
201 + '<a href="https://php.net/manual/en/mbstring.installation.php">mbstring</a>'
202 + ),
203 + );
204 + }
205 +
206 + // Bail if no notices exist.
207 + if ( ! count( $notices ) ) {
208 + return;
209 + }
210 + ?>
211 + <div class="notices">
212 + <?php
213 + // Output inline notices.
214 + foreach ( $notices as $notice ) {
215 + ?>
216 + <div class="inline notice notice-<?php echo esc_attr( $notice['type'] ); ?>">
217 + <p>
218 + <?php echo esc_attr( $notice['message'] ); ?>
219 + </p>
220 + </div>
221 + <?php
222 + }
223 + ?>
224 + </div>
225 + <?php
226 +
227 + }
228 +
229 + /**
220 230 * Define links to display below the Plugin Name on the WP_List_Table at in the Plugins screen.
221 231 *
222 232 * @param array $links Links.
223 233 * @return array Links
224 234 */
225 - public function add_settings_page_link( $links ) {
235 + public static function add_settings_page_link( $links ) {
226 236
227 - // Add link to Plugin settings screen.
228 - $links['settings'] = sprintf(
229 - '<a href="%s">%s</a>',
230 - convertkit_get_settings_link(),
231 - __( 'Settings', 'convertkit' )
237 + return array_merge(
238 + array(
239 + 'settings' => sprintf(
240 + '<a href="%s">%s</a>',
241 + convertkit_get_settings_link(),
242 + __( 'Settings', 'convertkit' )
243 + ),
244 + ),
245 + $links
232 246 );
233 247
234 - /**
235 - * Define links to display below the Plugin Name on the WP_List_Table at Plugins > Installed Plugins.
236 - *
237 - * @since 2.1.2
238 - *
239 - * @param array $links HTML Links.
240 - */
241 - $links = apply_filters( 'convertkit_plugin_screen_action_links', $links );
242 -
243 - // Return.
244 - return $links;
245 -
246 248 }
247 -
248 249 /**
249 250 * Output tabs, one for each registered settings section.
250 251 *
251 252 * @param string $active_section Currently displayed/selected section.
@@ -256,24 +257,13 @@
256 257 <ul class="convertkit-tabs">
257 258 <?php
258 259 foreach ( $this->sections as $section ) {
259 260 printf(
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' : '' ),
271 - esc_html( $section->tab_text ),
272 - wp_kses(
273 - $section->is_beta ? $this->get_beta_tab() : '',
274 - convertkit_kses_allowed_html()
275 - )
261 + '<li><a href="?page=%s&tab=%s" class="convertkit-tab %s">%s</a></li>',
262 + sanitize_text_field( $_REQUEST['page'] ), // phpcs:ignore WordPress.Security.NonceVerification
263 + esc_html( $section->name ),
264 + $active_section === $section->name ? 'convertkit-tab-active' : '',
265 + esc_html( $section->tab_text )
276 266 );
277 267 }
278 268 ?>
279 269 </ul>
@@ -288,23 +278,10 @@
288 278
289 279 }
290 280
291 281 /**
292 - * Returns a 'beta' tab wrapped in a span.
282 + * Registers settings sections at Settings > ConvertKit.
293 283 *
294 - * @since 2.1.0
295 - *
296 - * @return string
297 - */
298 - private function get_beta_tab() {
299 -
300 - return '<span class="convertkit-beta-label">' . esc_html__( 'Beta', 'convertkit' ) . '</span>';
301 -
302 - }
303 -
304 - /**
305 - * Registers settings sections at Settings > Kit.
306 - *
307 284 * Each section has its own tab.
308 285 *
309 286 * @since 1.9.6
310 287 */
@@ -309,31 +286,16 @@
309 286 * @since 1.9.6
310 287 */
311 288 public function register_sections() {
312 289
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 -
328 290 // Register the General and Tools settings sections.
329 291 $sections = array(
330 - 'general' => new ConvertKit_Admin_Section_General(),
331 - 'tools' => new ConvertKit_Admin_Section_Tools(),
292 + 'general' => new ConvertKit_Settings_General(),
293 + 'tools' => new ConvertKit_Settings_Tools(),
332 294 );
333 295
334 296 /**
335 - * Registers settings sections at Settings > Kit.
297 + * Registers settings sections at Settings > ConvertKit.
336 298 *
337 299 * @since 1.9.6
338 300 *
339 301 * @param array $sections Array of settings classes that handle individual tabs e.g. General, Tools etc.
@@ -341,40 +303,8 @@
341 303 $sections = apply_filters( 'convertkit_admin_settings_register_sections', $sections );
342 304
343 305 // With our sections now registered, assign them to this class.
344 306 $this->sections = $sections;
345 -
346 - }
347 -
348 - /**
349 - * Returns the documentation URL for the active settings section viewed by the user.
350 - *
351 - * @since 2.0.8
352 - *
353 - * @param string $active_section Currently displayed/selected section.
354 - * @return bool|string
355 - */
356 - private function get_active_section_documentation_url( $active_section ) {
357 -
358 - // Bail if no sections registered.
359 - if ( ! $this->sections ) {
360 - return false;
361 - }
362 -
363 - // Bail if the active section isn't registered.
364 - if ( ! array_key_exists( $active_section, $this->sections ) ) {
365 - return false;
366 - }
367 -
368 - // Pass request to section's documentation_url() function, including UTM parameters.
369 - return add_query_arg(
370 - array(
371 - 'utm_source' => 'wordpress',
372 - 'utm_term' => get_locale(),
373 - 'utm_content' => 'convertkit',
374 - ),
375 - $this->sections[ $active_section ]->documentation_url()
376 - );
377 307
378 308 }
379 309
380 310 }