PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.0.8
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.0.8
3.4.6 3.4.5 3.4.4 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 All 199 releases
← All changes | admin/class-convertkit-admin-settings.php +100 -123 3.4.1 → 2.0.8 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,12 +152,12 @@
180 152 </form>
181 153
182 154 <p class="description">
183 155 <?php
184 - // Output Help link, if it exists.
156 + // Output Documentation link, if it exists.
185 157 $documentation_url = $this->get_active_section_documentation_url( $active_section );
186 158 if ( $documentation_url !== false ) {
187 - printf(
159 + echo sprintf(
188 160 '%s <a href="%s" target="_blank">%s</a>',
189 161 esc_html__( 'If you need help setting up the plugin please refer to the', 'convertkit' ),
190 162 esc_attr( $documentation_url ),
191 163 esc_html__( 'plugin documentation', 'convertkit' )
@@ -206,10 +178,10 @@
206 178 * @return string Tab Name
207 179 */
208 180 private function get_active_section() {
209 181
210 - if ( filter_has_var( INPUT_GET, 'tab' ) ) {
211 - return filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
182 + if ( isset( $_GET['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
183 + return sanitize_text_field( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
212 184 }
213 185
214 186 // First registered section will be the active section.
215 187 return current( $this->sections )->name;
@@ -216,36 +188,71 @@
216 188
217 189 }
218 190
219 191 /**
192 + * Display notice(s) immediately after the settings screen header.
193 + *
194 + * @since 1.9.6
195 + */
196 + private function maybe_display_notices() {
197 +
198 + $notices = array();
199 +
200 + // Check the mbstring extension is loaded.
201 + if ( ! extension_loaded( 'mbstring' ) ) {
202 + $notices[] = array(
203 + 'type' => 'warning',
204 + 'message' => sprintf(
205 + /* translators: link to php.net manual */
206 + __( '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' ),
207 + '<a href="https://php.net/manual/en/mbstring.installation.php">mbstring</a>'
208 + ),
209 + );
210 + }
211 +
212 + // Bail if no notices exist.
213 + if ( ! count( $notices ) ) {
214 + return;
215 + }
216 + ?>
217 + <div class="notices">
218 + <?php
219 + // Output inline notices.
220 + foreach ( $notices as $notice ) {
221 + ?>
222 + <div class="inline notice notice-<?php echo esc_attr( $notice['type'] ); ?>">
223 + <p>
224 + <?php echo esc_attr( $notice['message'] ); ?>
225 + </p>
226 + </div>
227 + <?php
228 + }
229 + ?>
230 + </div>
231 + <?php
232 +
233 + }
234 +
235 + /**
220 236 * Define links to display below the Plugin Name on the WP_List_Table at in the Plugins screen.
221 237 *
222 238 * @param array $links Links.
223 239 * @return array Links
224 240 */
225 - public function add_settings_page_link( $links ) {
241 + public static function add_settings_page_link( $links ) {
226 242
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' )
243 + return array_merge(
244 + array(
245 + 'settings' => sprintf(
246 + '<a href="%s">%s</a>',
247 + convertkit_get_settings_link(),
248 + __( 'Settings', 'convertkit' )
249 + ),
250 + ),
251 + $links
232 252 );
233 253
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 254 }
247 -
248 255 /**
249 256 * Output tabs, one for each registered settings section.
250 257 *
251 258 * @param string $active_section Currently displayed/selected section.
@@ -256,26 +263,25 @@
256 263 <ul class="convertkit-tabs">
257 264 <?php
258 265 foreach ( $this->sections as $section ) {
259 266 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 - )
267 + '<li><a href="?page=%s&tab=%s" class="convertkit-tab %s">%s</a></li>',
268 + sanitize_text_field( $_REQUEST['page'] ), // phpcs:ignore WordPress.Security.NonceVerification
269 + esc_html( $section->name ),
270 + $active_section === $section->name ? 'convertkit-tab-active' : '',
271 + esc_html( $section->tab_text )
276 272 );
277 273 }
274 +
275 + // Output Documentation link tab, if it exists.
276 + $documentation_url = $this->get_active_section_documentation_url( $active_section );
277 + if ( $documentation_url !== false ) {
278 + printf(
279 + '<li class="convertkit-docs"><a href="%s" class="convertkit-tab" target="_blank">%s <span class="dashicons dashicons-external"></span></a></li>',
280 + esc_attr( $documentation_url ),
281 + esc_html__( 'Documentation', 'convertkit' )
282 + );
283 + }
278 284 ?>
279 285 </ul>
280 286 <?php
281 287 // WordPress' JS will automatically move any .notice elements to be immediately below .wp-header-end
@@ -288,23 +294,10 @@
288 294
289 295 }
290 296
291 297 /**
292 - * Returns a 'beta' tab wrapped in a span.
298 + * Registers settings sections at Settings > ConvertKit.
293 299 *
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 300 * Each section has its own tab.
308 301 *
309 302 * @since 1.9.6
310 303 */
@@ -309,31 +302,16 @@
309 302 * @since 1.9.6
310 303 */
311 304 public function register_sections() {
312 305
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 306 // Register the General and Tools settings sections.
329 307 $sections = array(
330 - 'general' => new ConvertKit_Admin_Section_General(),
331 - 'tools' => new ConvertKit_Admin_Section_Tools(),
308 + 'general' => new ConvertKit_Settings_General(),
309 + 'tools' => new ConvertKit_Settings_Tools(),
332 310 );
333 311
334 312 /**
335 - * Registers settings sections at Settings > Kit.
313 + * Registers settings sections at Settings > ConvertKit.
336 314 *
337 315 * @since 1.9.6
338 316 *
339 317 * @param array $sections Array of settings classes that handle individual tabs e.g. General, Tools etc.
@@ -368,9 +346,8 @@
368 346 // Pass request to section's documentation_url() function, including UTM parameters.
369 347 return add_query_arg(
370 348 array(
371 349 'utm_source' => 'wordpress',
372 - 'utm_term' => get_locale(),
373 350 'utm_content' => 'convertkit',
374 351 ),
375 352 $this->sections[ $active_section ]->documentation_url()
376 353 );