PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.6
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.6
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
convertkit / includes / class-convertkit-setup.php

class-convertkit-setup.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.6, at includes/class-convertkit-setup.php

750 lines 21.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin activation, update and deactivation class.
4 *
5 * @package ConvertKit
6 * @author ConvertKit
7 */
8
9 /**
10 * Runs any steps required on plugin activation, update and deactivation.
11 *
12 * @package ConvertKit
13 * @author ConvertKit
14 * @version 1.9.7.4
15 */
16 class ConvertKit_Setup {
17
18 /**
19 * Runs routines when the Plugin is activated.
20 *
21 * @since 1.9.7.4
22 */
23 public function activate() {
24
25 // Call any functions to e.g. schedule WordPress Cron events now.
26 $this->schedule_cron_events();
27
28 // Install entries database table.
29 $entries = new ConvertKit_Form_Entries();
30 $entries->create_database_table();
31
32 }
33
34 /**
35 * Runs routines on every Plugin request e.g.
36 * ensuring WordPress Cron events are scheduled.
37 *
38 * @since 2.6.6
39 */
40 public function initialize() {
41
42 // Call any functions to e.g. schedule WordPress Cron events now.
43 $this->schedule_cron_events();
44
45 }
46
47 /**
48 * Runs routines if the Plugin version has been updated.
49 *
50 * @since 1.9.7.4
51 */
52 public function update() {
53
54 // Get installed Plugin version.
55 $current_version = get_option( 'convertkit_version' );
56
57 // If the version number matches the plugin version, no update routines
58 // need to run.
59 if ( $current_version === CONVERTKIT_PLUGIN_VERSION ) {
60 return;
61 }
62
63 /**
64 * 3.0.4: Add form_id to entries database table.
65 */
66 if ( version_compare( $current_version, '3.0.4', '<' ) ) {
67 $this->add_form_id_column_and_key_to_form_entries_database_table();
68 }
69
70 /**
71 * 3.0.0: Migrate reCAPTCHA settings from Restrict Content to General settings.
72 * Install entries database table.
73 */
74 if ( version_compare( $current_version, '3.0.0', '<' ) ) {
75 $this->migrate_recaptcha_settings();
76
77 // Install entries database table.
78 $entries = new ConvertKit_Form_Entries();
79 $entries->create_database_table();
80 }
81
82 /**
83 * 2.6.6: Migrate 'Default' Form value in _wp_convertkit_term_meta[form] from 0 to -1,
84 * to match Posts.
85 */
86 if ( version_compare( $current_version, '2.6.6', '<' ) ) {
87 $this->migrate_term_default_form_settings();
88 }
89
90 /**
91 * 2.5.4: Migrate WishList Member to ConvertKit Form Mappings
92 */
93 if ( ! $current_version || version_compare( $current_version, '2.5.4', '<' ) ) {
94 $this->migrate_wlm_none_setting();
95 $this->migrate_wlm_form_tag_mapping_settings();
96 }
97
98 /**
99 * 2.5.3: Migrate Third Party Form integrations' 'None' option values from `default` to blank.
100 */
101 if ( ! $current_version || version_compare( $current_version, '2.5.3', '<' ) ) {
102 $this->migrate_contact_form_7_none_setting();
103 $this->migrate_forminator_none_setting();
104 $this->migrate_wlm_none_setting();
105 }
106
107 /**
108 * 2.5.2: Migrate Forminator to ConvertKit Form Mappings
109 */
110 if ( ! $current_version || version_compare( $current_version, '2.5.2', '<' ) ) {
111 $this->migrate_forminator_form_mapping_settings();
112 }
113
114 /**
115 * 2.5.2: Migrate Contact Form 7 to ConvertKit Form Mappings
116 */
117 if ( ! $current_version || version_compare( $current_version, '2.5.2', '<' ) ) {
118 $this->migrate_contact_form_7_form_mapping_settings();
119 }
120
121 /**
122 * 2.5.0: Get Access token for API version 4.0 using a v3 API Key and Secret.
123 */
124 if ( ! $current_version || version_compare( $current_version, '2.5.0', '<' ) ) {
125 $this->maybe_get_access_token_by_api_key_and_secret();
126 }
127
128 /**
129 * 2.4.9.1+: Migrate ck_default_form to _wp_convertkit_term_meta[form], as Term settings
130 * support multiple options (form, position etc).
131 */
132 if ( version_compare( $current_version, '2.4.9.1', '<' ) ) {
133 $this->migrate_term_form_settings();
134 }
135
136 /**
137 * 1.9.6+: Migrate _wp_convertkit_settings[default_form] to _wp_convertkit_settings[page_form] and
138 * _wp_convertkit_settings[post_form], now that each Post Type has its own Default Form setting
139 * in Settings > Kit > General.
140 */
141 if ( version_compare( $current_version, '1.9.6', '<' ) ) {
142 $this->migrate_default_form_settings();
143 }
144
145 /**
146 * 1.9.7.4+: Schedule Post Resources' Cron event to refresh Posts cache hourly,
147 * as the activate() routine won't pick this up for existing active installations.
148 */
149 if ( version_compare( $current_version, '1.9.7.4', '<' ) ) {
150 $posts = new ConvertKit_Resource_Posts( 'cron' );
151 $posts->schedule_cron_event();
152 }
153
154 // Actions that should run regardless of the version number
155 // whenever the Plugin is updated.
156 $this->remove_v3_api_secret_from_settings();
157 $this->maybe_delete_old_cached_resource_structure();
158
159 // Update the installed version number in the options table.
160 update_option( 'convertkit_version', CONVERTKIT_PLUGIN_VERSION );
161
162 }
163
164 /**
165 * Remove v3 API Secret from settings.
166 *
167 * @since 3.2.4
168 */
169 private function remove_v3_api_secret_from_settings() {
170
171 $settings = new ConvertKit_Settings();
172 $settings->save(
173 array(
174 'api_secret' => '',
175 )
176 );
177
178 }
179
180 /**
181 * Deletes any cached resources stored in the options table if they are a flat array
182 * that originates from between 1.6.0 and 1.9.5.2 of the Plugin.
183 * i.e. [id => name], rather than the expected [id => [id => '...', name => '...', ...]].
184 *
185 * This will permit the Resources classes to fetch and cache the Form resources correctly
186 * from the API, and prevent fatal errors when a user activates the latest version of the Plugin
187 * on a site that previously had a very old Plugin version installed.
188 *
189 * @since 3.2.5
190 */
191 private function maybe_delete_old_cached_resource_structure() {
192
193 // Define the resource options to check.
194 $resource_options = array(
195 'convertkit_forms',
196 'convertkit_landing_pages',
197 'convertkit_tags',
198 );
199
200 foreach ( $resource_options as $resource_option ) {
201 // Get the resource option.
202 $resource = get_option( $resource_option, false );
203
204 // If the resource option does not exist, there's nothing to delete.
205 if ( false === $resource ) {
206 return;
207 }
208
209 // If the resource structure is correct e.g. [id => [name => '...']], there's nothing to delete.
210 if ( is_array( reset( $resource ) ) ) {
211 return;
212 }
213
214 // Delete the cached resource.
215 delete_option( $resource_option );
216 }
217
218 }
219
220 /**
221 * Adds form_id column and key to form entries database table.
222 *
223 * @since 3.0.4
224 */
225 private function add_form_id_column_and_key_to_form_entries_database_table() {
226
227 global $wpdb;
228
229 // Check if the column exists.
230 $exists = $wpdb->get_var(
231 $wpdb->prepare(
232 'SELECT COLUMN_NAME
233 FROM INFORMATION_SCHEMA.COLUMNS
234 WHERE table_name = %s
235 AND table_schema = %s
236 AND column_name = %s',
237 $wpdb->prefix . 'kit_form_entries',
238 $wpdb->dbname,
239 'form_id'
240 )
241 );
242
243 // If the column exists, don't add it again.
244 if ( $exists === 'form_id' ) {
245 return;
246 }
247
248 // Add the form_id column and key.
249 // The table name isn't prepared, as the %i placeholder requires WordPress 6.2+.
250 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}kit_form_entries` ADD COLUMN `form_id` int(11) NOT NULL AFTER `custom_fields`" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
251 $wpdb->query( "ALTER TABLE `{$wpdb->prefix}kit_form_entries` ADD KEY `form_id` (`form_id`)" ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
252
253 }
254
255 /**
256 * 3.0.0: Migrate reCAPTCHA settings from Restrict Content settings to General settings.
257 *
258 * @since 3.0.0
259 */
260 private function migrate_recaptcha_settings() {
261
262 // Read Restrict Content settings directly from options table,
263 // as Convertkit_Settings_Restrict_Content won't have helper
264 // methods to return the specific settings.
265 $settings = get_option( '_wp_convertkit_settings_restrict_content' );
266
267 // If no reCAPTCHA settings exist, bail.
268 if ( ! isset( $settings['recaptcha_site_key'] ) || ! isset( $settings['recaptcha_secret_key'] ) || ! isset( $settings['recaptcha_minimum_score'] ) ) {
269 return;
270 }
271
272 // Load settings class, saving the reCAPTCHA settings to the General settings.
273 $convertkit_settings = new ConvertKit_Settings();
274 $convertkit_settings->save(
275 array(
276 'recaptcha_site_key' => $settings['recaptcha_site_key'],
277 'recaptcha_secret_key' => $settings['recaptcha_secret_key'],
278 'recaptcha_minimum_score' => $settings['recaptcha_minimum_score'],
279 )
280 );
281
282 // Remove reCAPTCHA settings from Restrict Content settings.
283 unset( $settings['recaptcha_site_key'] );
284 unset( $settings['recaptcha_secret_key'] );
285 unset( $settings['recaptcha_minimum_score'] );
286 update_option( '_wp_convertkit_settings_restrict_content', $settings );
287
288 }
289
290 /**
291 * Change the Default value of 0 to -1 in wp_convertkit_term_meta[form], to
292 * match how the Default value is stored in Posts.
293 *
294 * @since 2.6.6
295 */
296 private function migrate_term_default_form_settings() {
297
298 // Get all Terms that have ConvertKit settings defined.
299 $query = new WP_Term_Query(
300 array(
301 'taxonomy' => 'category',
302 'hide_empty' => false,
303 'fields' => 'ids',
304 'meta_query' => array(
305 array(
306 'key' => '_wp_convertkit_term_meta',
307 'comparison' => 'EXISTS',
308 ),
309 ),
310 )
311 );
312
313 // Bail if no Terms exist.
314 if ( ! $query->terms ) {
315 return;
316 }
317
318 // Iterate through Terms, mapping settings.
319 foreach ( $query->terms as $term_id ) {
320 $term_settings = new ConvertKit_Term( $term_id );
321
322 // If the Form setting is Default i.e. it does not have a formchange it from 0 to -1.
323 if ( ! $term_settings->has_form() ) {
324 $term_settings->save(
325 array(
326 'form' => -1,
327 )
328 );
329 }
330 }
331
332 }
333
334 /**
335 * 2.5.4: Migrate WLM settings:
336 * - Prefix any WishList Member to ConvertKit Form ID mappings with `form:`,
337 * - Prefix any WishList Member to ConvertKit Tag ID mappings with `tag:`,
338 * - Standardise the settings keys to the format {wlm_level_id}_subscribe
339 * and {wlm_level_id}_unsubscribe.
340 *
341 * @since 2.5.4
342 */
343 private function migrate_wlm_form_tag_mapping_settings() {
344
345 $convertkit_wlm_settings = new ConvertKit_Wishlist_Settings();
346
347 // Bail if no settings exist.
348 if ( ! $convertkit_wlm_settings->has_settings() ) {
349 return;
350 }
351
352 // Define new array for settings.
353 $settings = array();
354
355 // Iterate through settings.
356 foreach ( $convertkit_wlm_settings->get() as $key => $convertkit_form_or_tag_id ) {
357 // Split the settings key.
358 list( $wlm_level_id, $type ) = explode( '_', $key );
359
360 switch ( $type ) {
361 case 'form':
362 // This is the action to perform when the user is added to the WLM Level.
363 // Use a new name for the setting key to reflect this.
364 // < 2.5.4, forms were the only option here, so prefix the resource ID with `form:`.
365 $settings[ $wlm_level_id . '_add' ] = ( empty( $convertkit_form_or_tag_id ) ? '' : 'form:' . $convertkit_form_or_tag_id );
366 break;
367
368 case 'unsubscribe':
369 // This is the action to perform when the user is removed from the WLM Level.
370 // Use a new name for the setting key to reflect this.
371 // < 2.5.4, tags were the only option here, so prefix the resource ID with `tag:`.
372 $settings[ $wlm_level_id . '_remove' ] = ( empty( $convertkit_form_or_tag_id ) ? '' : 'tag:' . $convertkit_form_or_tag_id );
373 break;
374 }
375 }
376
377 // Update settings.
378 update_option( $convertkit_wlm_settings::SETTINGS_NAME, $settings );
379
380 }
381
382 /**
383 * 2.5.3: Migrate Third Party Form integrations' 'None' option values from `default` to blank.
384 *
385 * 2.4.9 changed the 'None' label's value from `default` to a blank string, as the v4 API's
386 * `add_subscriber_to_form()` method introduces type declarations, which would result in
387 * an uncaught TypeError when passing a non integer value.
388 *
389 * The PR for that (https://github.com/ConvertKit/convertkit-wordpress/pull/655) didn't include
390 * any tests or upgrade/migration routines to change any existing saved settings where the 'None'
391 * label's value was stored as `default`.
392 */
393 private function migrate_contact_form_7_none_setting() {
394
395 $convertkit_contact_form_7_settings = new ConvertKit_ContactForm7_Settings();
396
397 // Bail if no settings exist.
398 if ( ! $convertkit_contact_form_7_settings->has_settings() ) {
399 return;
400 }
401
402 // Get settings.
403 $settings = $convertkit_contact_form_7_settings->get();
404
405 // Iterate through settings.
406 foreach ( $settings as $contact_form_7_form_id => $convertkit_form_id ) {
407 // Skip keys that are non-numeric e.g. `creator_network_recommendations_*`.
408 if ( ! is_numeric( $contact_form_7_form_id ) ) {
409 continue;
410 }
411
412 // Change 'default' to a blank string.
413 if ( $convertkit_form_id === 'default' ) {
414 $settings[ $contact_form_7_form_id ] = '';
415 }
416 }
417
418 // Update settings.
419 update_option( $convertkit_contact_form_7_settings::SETTINGS_NAME, $settings );
420
421 }
422
423 /**
424 * 2.5.3: Migrate Third Party Form integrations' 'None' option values from `default` to blank.
425 *
426 * 2.4.9 changed the 'None' label's value from `default` to a blank string, as the v4 API's
427 * `add_subscriber_to_form()` method introduces type declarations, which would result in
428 * an uncaught TypeError when passing a non integer value.
429 *
430 * The PR for that (https://github.com/ConvertKit/convertkit-wordpress/pull/655) didn't include
431 * any tests or upgrade/migration routines to change any existing saved settings where the 'None'
432 * label's value was stored as `default`.
433 */
434 private function migrate_forminator_none_setting() {
435
436 $convertkit_forminator_settings = new ConvertKit_Forminator_Settings();
437
438 // Bail if no settings exist.
439 if ( ! $convertkit_forminator_settings->has_settings() ) {
440 return;
441 }
442
443 // Get settings.
444 $settings = $convertkit_forminator_settings->get();
445
446 // Iterate through settings.
447 foreach ( $settings as $forminator_form_id => $convertkit_form_id ) {
448 // Skip keys that are non-numeric e.g. `creator_network_recommendations_*`.
449 if ( ! is_numeric( $forminator_form_id ) ) {
450 continue;
451 }
452
453 // Change 'default' to a blank string.
454 if ( $convertkit_form_id === 'default' ) {
455 $settings[ $forminator_form_id ] = '';
456 }
457 }
458
459 // Update settings.
460 update_option( $convertkit_forminator_settings::SETTINGS_NAME, $settings );
461
462 }
463
464 /**
465 * 2.5.3: Migrate Third Party Form integrations' 'None' option values from `default` to blank.
466 *
467 * 2.4.9 changed the 'None' label's value from `default` to a blank string, as the v4 API's
468 * `add_subscriber_to_form()` method introduces type declarations, which would result in
469 * an uncaught TypeError when passing a non integer value.
470 *
471 * The PR for that (https://github.com/ConvertKit/convertkit-wordpress/pull/655) didn't include
472 * any tests or upgrade/migration routines to change any existing saved settings where the 'None'
473 * label's value was stored as `default`.
474 */
475 private function migrate_wlm_none_setting() {
476
477 $convertkit_wlm_settings = new ConvertKit_Wishlist_Settings();
478
479 // Bail if no settings exist.
480 if ( ! $convertkit_wlm_settings->has_settings() ) {
481 return;
482 }
483
484 // Get settings.
485 $settings = $convertkit_wlm_settings->get();
486
487 // Iterate through settings.
488 foreach ( $settings as $wlm_level_id => $value ) {
489 // Change 'default' to a blank string.
490 if ( $value === 'default' ) {
491 $settings[ $wlm_level_id ] = '';
492 }
493 }
494
495 // Update settings.
496 update_option( $convertkit_wlm_settings::SETTINGS_NAME, $settings );
497
498 }
499
500 /**
501 * 2.5.2: Prefix any Forminator to ConvertKit Form ID mappings with `form:`, now that
502 * the Plugin supports adding a subscriber to a Form, Tag or Sequence.
503 *
504 * @since 2.5.2
505 */
506 private function migrate_forminator_form_mapping_settings() {
507
508 $convertkit_forminator_settings = new ConvertKit_Forminator_Settings();
509
510 // Bail if no settings exist.
511 if ( ! $convertkit_forminator_settings->has_settings() ) {
512 return;
513 }
514
515 // Get settings.
516 $settings = $convertkit_forminator_settings->get();
517
518 // Iterate through settings.
519 foreach ( $settings as $forminator_form_id => $convertkit_form_id ) {
520 // Skip keys that are non-numeric e.g. `creator_network_recommendations_*`.
521 if ( ! is_numeric( $forminator_form_id ) ) {
522 continue;
523 }
524
525 // Skip values that are blank i.e. no ConvertKit Form ID specified.
526 if ( empty( $convertkit_form_id ) ) {
527 continue;
528 }
529
530 // Skip values that are non-numeric i.e. the `form_` prefix was already added.
531 // This should never happen as this routine runs once, but this is a sanity check.
532 if ( ! is_numeric( $convertkit_form_id ) ) {
533 continue;
534 }
535
536 // Prefix the ConvertKit Form ID with `form_`.
537 $settings[ $forminator_form_id ] = 'form:' . $convertkit_form_id;
538 }
539
540 // Update settings.
541 update_option( $convertkit_forminator_settings::SETTINGS_NAME, $settings );
542
543 }
544
545 /**
546 * 2.5.2: Prefix any Contact Form 7 to ConvertKit Form ID mappings with `form:`, now that
547 * the Plugin supports adding a subscriber to a Form, Tag or Sequence.
548 *
549 * @since 2.5.2
550 */
551 private function migrate_contact_form_7_form_mapping_settings() {
552
553 $convertkit_contact_form_7_settings = new ConvertKit_ContactForm7_Settings();
554
555 // Bail if no settings exist.
556 if ( ! $convertkit_contact_form_7_settings->has_settings() ) {
557 return;
558 }
559
560 // Get settings.
561 $settings = $convertkit_contact_form_7_settings->get();
562
563 // Iterate through settings.
564 foreach ( $settings as $contact_form_7_form_id => $convertkit_form_id ) {
565 // Skip keys that are non-numeric e.g. `creator_network_recommendations_*`.
566 if ( ! is_numeric( $contact_form_7_form_id ) ) {
567 continue;
568 }
569
570 // Skip values that are blank i.e. no ConvertKit Form ID specified.
571 if ( empty( $convertkit_form_id ) ) {
572 continue;
573 }
574
575 // Skip values that are non-numeric i.e. the `form_` prefix was already added.
576 // This should never happen as this routine runs once, but this is a sanity check.
577 if ( ! is_numeric( $convertkit_form_id ) ) {
578 continue;
579 }
580
581 // Prefix the ConvertKit Form ID with `form_`.
582 $settings[ $contact_form_7_form_id ] = 'form:' . $convertkit_form_id;
583 }
584
585 // Update settings.
586 update_option( $convertkit_contact_form_7_settings::SETTINGS_NAME, $settings );
587
588 }
589
590 /**
591 * 2.5.0: Fetch an Access Token, Refresh Token and Expiry for v4 API use
592 * based on the Plugin setting's v3 API Key and Secret.
593 *
594 * @since 2.5.0
595 */
596 private function maybe_get_access_token_by_api_key_and_secret() {
597
598 $convertkit_settings = new ConvertKit_Settings();
599
600 // Bail if an Access Token exists; we don't need to fetch another one.
601 if ( $convertkit_settings->has_access_token() ) {
602 return;
603 }
604
605 // Bail if no API Key or Secret.
606 if ( empty( $convertkit_settings->get_api_key() ) ) {
607 return;
608 }
609 if ( empty( $convertkit_settings->get_api_secret() ) ) {
610 return;
611 }
612
613 // Get Access Token by API Key and Secret.
614 $api = new ConvertKit_API_V4( CONVERTKIT_OAUTH_CLIENT_ID, CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI );
615 $result = $api->get_access_token_by_api_key_and_secret(
616 $convertkit_settings->get_api_key(),
617 $convertkit_settings->get_api_secret(),
618 get_site_url()
619 );
620
621 // Bail if an error occurred.
622 if ( is_wp_error( $result ) ) {
623 return;
624 }
625
626 // Store the new credentials.
627 // We don't use update_credentials(), because the response
628 // includes an `expires_at`, not a `created_at` and `expires_in`.
629 $convertkit_settings->save(
630 array(
631 'access_token' => $result['oauth']['access_token'],
632 'refresh_token' => $result['oauth']['refresh_token'],
633 'token_expires' => $result['oauth']['expires_at'],
634 )
635 );
636
637 }
638
639 /**
640 * Migrate ck_default_form to _wp_convertkit_term_meta[form], as Term settings
641 * support multiple options (form, position etc).
642 *
643 * @since 2.4.9.1
644 */
645 private function migrate_term_form_settings() {
646
647 // Get all Terms that have ConvertKit settings defined.
648 $query = new WP_Term_Query(
649 array(
650 'taxonomy' => 'category',
651 'hide_empty' => false,
652 'fields' => 'ids',
653 'meta_query' => array(
654 array(
655 'key' => 'ck_default_form',
656 'comparison' => 'EXISTS',
657 ),
658 ),
659 )
660 );
661
662 // Bail if no Terms exist.
663 if ( ! $query->terms ) {
664 return;
665 }
666
667 // Iterate through Terms, mapping settings.
668 foreach ( $query->terms as $term_id ) {
669 $term_settings = new ConvertKit_Term( $term_id );
670 $term_settings->save(
671 array(
672 'form' => get_term_meta( $term_id, 'ck_default_form', true ), // Fetch form setting from old meta key.
673 'form_position' => '', // Default to no position.
674 )
675 );
676
677 // Delete old Term meta.
678 delete_term_meta( $term_id, 'ck_default_form' );
679 }
680
681 }
682
683 /**
684 * 1.9.6+: Migrate _wp_convertkit_settings[default_form] to _wp_convertkit_settings[page_form] and
685 * _wp_convertkit_settings[post_form], now that each Post Type has its own Default Form setting
686 * in Settings > Kit > General.
687 */
688 private function migrate_default_form_settings() {
689
690 $convertkit_settings = new ConvertKit_Settings();
691
692 // Bail if no default_form setting exists.
693 $settings = get_option( $convertkit_settings::SETTINGS_NAME );
694 if ( ! $settings ) {
695 return;
696 }
697 if ( ! array_key_exists( 'default_form', $settings ) ) {
698 return;
699 }
700
701 // Restructure settings.
702 $settings['page_form'] = $settings['default_form'];
703 $settings['post_form'] = $settings['default_form'];
704
705 // Remove obsolete default_form setting.
706 unset( $settings['default_form'] );
707
708 // Update.
709 update_option( $convertkit_settings::SETTINGS_NAME, $settings );
710
711 }
712
713 /**
714 * Runs routines when the Plugin is deactivated.
715 *
716 * @since 1.9.7.4
717 */
718 public function deactivate() {
719
720 // Call any functions to e.g. unschedule WordPress Cron events now.
721 $this->unschedule_cron_events();
722
723 }
724
725 /**
726 * Schedules any Plugin specific CRON events, if they do not already exist.
727 *
728 * @since 2.6.6
729 */
730 private function schedule_cron_events() {
731
732 $posts = new ConvertKit_Resource_Posts( 'cron' );
733 $posts->schedule_cron_event();
734
735 }
736
737 /**
738 * Unschedules any Plugin specific CRON events, if they exist.
739 *
740 * @since 2.6.6
741 */
742 private function unschedule_cron_events() {
743
744 $posts = new ConvertKit_Resource_Posts( 'cron' );
745 $posts->unschedule_cron_event();
746
747 }
748
749 }
750