PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.1.0
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.1.0
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
← All changes | includes/class-convertkit-setup.php +574 -68 2.2.33.1.0 View file →
@@ -22,15 +22,32 @@
22 22 */
23 23 public function activate() {
24 24
25 25 // Call any functions to e.g. schedule WordPress Cron events now.
26 - $posts = new ConvertKit_Resource_Posts( 'cron' );
27 - $posts->schedule_cron_event();
26 + $this->schedule_cron_events();
27 +
28 + // Install entries database table.
29 + $entries = new ConvertKit_Form_Entries();
30 + $entries->create_database_table();
31 +
28 32 }
29 33
30 34 /**
31 - * Runs routines when the Plugin version has been updated.
35 + * Runs routines on every Plugin request e.g.
36 + * ensuring WordPress Cron events are scheduled.
32 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 + *
33 50 * @since 1.9.7.4
34 51 */
35 52 public function update() {
36 53
@@ -43,15 +60,81 @@
43 60 return;
44 61 }
45 62
46 63 /**
47 - * 1.4.1: Change ID to form_id for API version 3.0.
64 + * 3.0.4: Add form_id to entries database table.
48 65 */
49 - if ( ! $current_version || version_compare( $current_version, '1.4.1', '<' ) ) {
50 - $this->change_id_to_form_id();
66 + if ( version_compare( $current_version, '3.0.4', '<' ) ) {
67 + $this->add_form_id_column_and_key_to_form_entries_database_table();
51 68 }
52 69
53 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 + /**
54 137 * 1.6.1+: Refresh Forms, Landing Pages and Tags data stored in settings,
55 138 * to get new Forms Builder Settings.
56 139 */
57 140 if ( version_compare( $current_version, '1.6.1', '<' ) ) {
@@ -60,9 +143,9 @@
60 143
61 144 /**
62 145 * 1.9.6+: Migrate _wp_convertkit_settings[default_form] to _wp_convertkit_settings[page_form] and
63 146 * _wp_convertkit_settings[post_form], now that each Post Type has its own Default Form setting
64 - * in Settings > ConvertKit > General.
147 + * in Settings > Kit > General.
65 148 */
66 149 if ( version_compare( $current_version, '1.9.6', '<' ) ) {
67 150 $this->migrate_default_form_settings();
68 151 }
@@ -81,11 +164,477 @@
81 164
82 165 }
83 166
84 167 /**
168 + * Adds form_id column and key to form entries database table.
169 + *
170 + * @since 3.0.4
171 + */
172 + private function add_form_id_column_and_key_to_form_entries_database_table() {
173 +
174 + global $wpdb;
175 +
176 + // Check if the column exists.
177 + $exists = $wpdb->get_var(
178 + $wpdb->prepare(
179 + 'SELECT COLUMN_NAME
180 + FROM INFORMATION_SCHEMA.COLUMNS
181 + WHERE table_name = %s
182 + AND table_schema = %s
183 + AND column_name = %s',
184 + $wpdb->prefix . 'kit_form_entries',
185 + $wpdb->dbname,
186 + 'form_id'
187 + )
188 + );
189 +
190 + // If the column exists, don't add it again.
191 + if ( $exists === 'form_id' ) {
192 + return;
193 + }
194 +
195 + // Add the form_id column and key.
196 + $wpdb->query(
197 + $wpdb->prepare( 'ALTER TABLE %i ADD COLUMN `form_id` int(11) NOT NULL AFTER `custom_fields`', $wpdb->prefix . 'kit_form_entries' )
198 + );
199 + $wpdb->query(
200 + $wpdb->prepare( 'ALTER TABLE %i ADD KEY `form_id` (`form_id`)', $wpdb->prefix . 'kit_form_entries' )
201 + );
202 +
203 + }
204 +
205 + /**
206 + * 3.0.0: Migrate reCAPTCHA settings from Restrict Content settings to General settings.
207 + *
208 + * @since 3.0.0
209 + */
210 + private function migrate_recaptcha_settings() {
211 +
212 + // Read Restrict Content settings directly from options table,
213 + // as Convertkit_Settings_Restrict_Content won't have helper
214 + // methods to return the specific settings.
215 + $settings = get_option( '_wp_convertkit_settings_restrict_content' );
216 +
217 + // If no reCAPTCHA settings exist, bail.
218 + if ( ! isset( $settings['recaptcha_site_key'] ) || ! isset( $settings['recaptcha_secret_key'] ) || ! isset( $settings['recaptcha_minimum_score'] ) ) {
219 + return;
220 + }
221 +
222 + // Load settings class, saving the reCAPTCHA settings to the General settings.
223 + $convertkit_settings = new ConvertKit_Settings();
224 + $convertkit_settings->save(
225 + array(
226 + 'recaptcha_site_key' => $settings['recaptcha_site_key'],
227 + 'recaptcha_secret_key' => $settings['recaptcha_secret_key'],
228 + 'recaptcha_minimum_score' => $settings['recaptcha_minimum_score'],
229 + )
230 + );
231 +
232 + // Remove reCAPTCHA settings from Restrict Content settings.
233 + unset( $settings['recaptcha_site_key'] );
234 + unset( $settings['recaptcha_secret_key'] );
235 + unset( $settings['recaptcha_minimum_score'] );
236 + update_option( '_wp_convertkit_settings_restrict_content', $settings );
237 +
238 + }
239 +
240 + /**
241 + * Change the Default value of 0 to -1 in wp_convertkit_term_meta[form], to
242 + * match how the Default value is stored in Posts.
243 + *
244 + * @since 2.6.6
245 + */
246 + private function migrate_term_default_form_settings() {
247 +
248 + // Get all Terms that have ConvertKit settings defined.
249 + $query = new WP_Term_Query(
250 + array(
251 + 'taxonomy' => 'category',
252 + 'hide_empty' => false,
253 + 'fields' => 'ids',
254 + 'meta_query' => array(
255 + array(
256 + 'key' => '_wp_convertkit_term_meta',
257 + 'comparison' => 'EXISTS',
258 + ),
259 + ),
260 + )
261 + );
262 +
263 + // Bail if no Terms exist.
264 + if ( ! $query->terms ) {
265 + return;
266 + }
267 +
268 + // Iterate through Terms, mapping settings.
269 + foreach ( $query->terms as $term_id ) {
270 + $term_settings = new ConvertKit_Term( $term_id );
271 +
272 + // If the Form setting is Default i.e. it does not have a formchange it from 0 to -1.
273 + if ( ! $term_settings->has_form() ) {
274 + $term_settings->save(
275 + array(
276 + 'form' => -1,
277 + )
278 + );
279 + }
280 + }
281 +
282 + }
283 +
284 + /**
285 + * 2.5.4: Migrate WLM settings:
286 + * - Prefix any WishList Member to ConvertKit Form ID mappings with `form:`,
287 + * - Prefix any WishList Member to ConvertKit Tag ID mappings with `tag:`,
288 + * - Standardise the settings keys to the format {wlm_level_id}_subscribe
289 + * and {wlm_level_id}_unsubscribe.
290 + *
291 + * @since 2.5.4
292 + */
293 + private function migrate_wlm_form_tag_mapping_settings() {
294 +
295 + $convertkit_wlm_settings = new ConvertKit_Wishlist_Settings();
296 +
297 + // Bail if no settings exist.
298 + if ( ! $convertkit_wlm_settings->has_settings() ) {
299 + return;
300 + }
301 +
302 + // Define new array for settings.
303 + $settings = array();
304 +
305 + // Iterate through settings.
306 + foreach ( $convertkit_wlm_settings->get() as $key => $convertkit_form_or_tag_id ) {
307 + // Split the settings key.
308 + list( $wlm_level_id, $type ) = explode( '_', $key );
309 +
310 + switch ( $type ) {
311 + case 'form':
312 + // This is the action to perform when the user is added to the WLM Level.
313 + // Use a new name for the setting key to reflect this.
314 + // < 2.5.4, forms were the only option here, so prefix the resource ID with `form:`.
315 + $settings[ $wlm_level_id . '_add' ] = ( empty( $convertkit_form_or_tag_id ) ? '' : 'form:' . $convertkit_form_or_tag_id );
316 + break;
317 +
318 + case 'unsubscribe':
319 + // This is the action to perform when the user is removed from the WLM Level.
320 + // Use a new name for the setting key to reflect this.
321 + // < 2.5.4, tags were the only option here, so prefix the resource ID with `tag:`.
322 + $settings[ $wlm_level_id . '_remove' ] = ( empty( $convertkit_form_or_tag_id ) ? '' : 'tag:' . $convertkit_form_or_tag_id );
323 + break;
324 + }
325 + }
326 +
327 + // Update settings.
328 + update_option( $convertkit_wlm_settings::SETTINGS_NAME, $settings );
329 +
330 + }
331 +
332 + /**
333 + * 2.5.3: Migrate Third Party Form integrations' 'None' option values from `default` to blank.
334 + *
335 + * 2.4.9 changed the 'None' label's value from `default` to a blank string, as the v4 API's
336 + * `add_subscriber_to_form()` method introduces type declarations, which would result in
337 + * an uncaught TypeError when passing a non integer value.
338 + *
339 + * The PR for that (https://github.com/ConvertKit/convertkit-wordpress/pull/655) didn't include
340 + * any tests or upgrade/migration routines to change any existing saved settings where the 'None'
341 + * label's value was stored as `default`.
342 + */
343 + private function migrate_contact_form_7_none_setting() {
344 +
345 + $convertkit_contact_form_7_settings = new ConvertKit_ContactForm7_Settings();
346 +
347 + // Bail if no settings exist.
348 + if ( ! $convertkit_contact_form_7_settings->has_settings() ) {
349 + return;
350 + }
351 +
352 + // Get settings.
353 + $settings = $convertkit_contact_form_7_settings->get();
354 +
355 + // Iterate through settings.
356 + foreach ( $settings as $contact_form_7_form_id => $convertkit_form_id ) {
357 + // Skip keys that are non-numeric e.g. `creator_network_recommendations_*`.
358 + if ( ! is_numeric( $contact_form_7_form_id ) ) {
359 + continue;
360 + }
361 +
362 + // Change 'default' to a blank string.
363 + if ( $convertkit_form_id === 'default' ) {
364 + $settings[ $contact_form_7_form_id ] = '';
365 + }
366 + }
367 +
368 + // Update settings.
369 + update_option( $convertkit_contact_form_7_settings::SETTINGS_NAME, $settings );
370 +
371 + }
372 +
373 + /**
374 + * 2.5.3: Migrate Third Party Form integrations' 'None' option values from `default` to blank.
375 + *
376 + * 2.4.9 changed the 'None' label's value from `default` to a blank string, as the v4 API's
377 + * `add_subscriber_to_form()` method introduces type declarations, which would result in
378 + * an uncaught TypeError when passing a non integer value.
379 + *
380 + * The PR for that (https://github.com/ConvertKit/convertkit-wordpress/pull/655) didn't include
381 + * any tests or upgrade/migration routines to change any existing saved settings where the 'None'
382 + * label's value was stored as `default`.
383 + */
384 + private function migrate_forminator_none_setting() {
385 +
386 + $convertkit_forminator_settings = new ConvertKit_Forminator_Settings();
387 +
388 + // Bail if no settings exist.
389 + if ( ! $convertkit_forminator_settings->has_settings() ) {
390 + return;
391 + }
392 +
393 + // Get settings.
394 + $settings = $convertkit_forminator_settings->get();
395 +
396 + // Iterate through settings.
397 + foreach ( $settings as $forminator_form_id => $convertkit_form_id ) {
398 + // Skip keys that are non-numeric e.g. `creator_network_recommendations_*`.
399 + if ( ! is_numeric( $forminator_form_id ) ) {
400 + continue;
401 + }
402 +
403 + // Change 'default' to a blank string.
404 + if ( $convertkit_form_id === 'default' ) {
405 + $settings[ $forminator_form_id ] = '';
406 + }
407 + }
408 +
409 + // Update settings.
410 + update_option( $convertkit_forminator_settings::SETTINGS_NAME, $settings );
411 +
412 + }
413 +
414 + /**
415 + * 2.5.3: Migrate Third Party Form integrations' 'None' option values from `default` to blank.
416 + *
417 + * 2.4.9 changed the 'None' label's value from `default` to a blank string, as the v4 API's
418 + * `add_subscriber_to_form()` method introduces type declarations, which would result in
419 + * an uncaught TypeError when passing a non integer value.
420 + *
421 + * The PR for that (https://github.com/ConvertKit/convertkit-wordpress/pull/655) didn't include
422 + * any tests or upgrade/migration routines to change any existing saved settings where the 'None'
423 + * label's value was stored as `default`.
424 + */
425 + private function migrate_wlm_none_setting() {
426 +
427 + $convertkit_wlm_settings = new ConvertKit_Wishlist_Settings();
428 +
429 + // Bail if no settings exist.
430 + if ( ! $convertkit_wlm_settings->has_settings() ) {
431 + return;
432 + }
433 +
434 + // Get settings.
435 + $settings = $convertkit_wlm_settings->get();
436 +
437 + // Iterate through settings.
438 + foreach ( $settings as $wlm_level_id => $value ) {
439 + // Change 'default' to a blank string.
440 + if ( $value === 'default' ) {
441 + $settings[ $wlm_level_id ] = '';
442 + }
443 + }
444 +
445 + // Update settings.
446 + update_option( $convertkit_wlm_settings::SETTINGS_NAME, $settings );
447 +
448 + }
449 +
450 + /**
451 + * 2.5.2: Prefix any Forminator to ConvertKit Form ID mappings with `form:`, now that
452 + * the Plugin supports adding a subscriber to a Form, Tag or Sequence.
453 + *
454 + * @since 2.5.2
455 + */
456 + private function migrate_forminator_form_mapping_settings() {
457 +
458 + $convertkit_forminator_settings = new ConvertKit_Forminator_Settings();
459 +
460 + // Bail if no settings exist.
461 + if ( ! $convertkit_forminator_settings->has_settings() ) {
462 + return;
463 + }
464 +
465 + // Get settings.
466 + $settings = $convertkit_forminator_settings->get();
467 +
468 + // Iterate through settings.
469 + foreach ( $settings as $forminator_form_id => $convertkit_form_id ) {
470 + // Skip keys that are non-numeric e.g. `creator_network_recommendations_*`.
471 + if ( ! is_numeric( $forminator_form_id ) ) {
472 + continue;
473 + }
474 +
475 + // Skip values that are blank i.e. no ConvertKit Form ID specified.
476 + if ( empty( $convertkit_form_id ) ) {
477 + continue;
478 + }
479 +
480 + // Skip values that are non-numeric i.e. the `form_` prefix was already added.
481 + // This should never happen as this routine runs once, but this is a sanity check.
482 + if ( ! is_numeric( $convertkit_form_id ) ) {
483 + continue;
484 + }
485 +
486 + // Prefix the ConvertKit Form ID with `form_`.
487 + $settings[ $forminator_form_id ] = 'form:' . $convertkit_form_id;
488 + }
489 +
490 + // Update settings.
491 + update_option( $convertkit_forminator_settings::SETTINGS_NAME, $settings );
492 +
493 + }
494 +
495 + /**
496 + * 2.5.2: Prefix any Contact Form 7 to ConvertKit Form ID mappings with `form:`, now that
497 + * the Plugin supports adding a subscriber to a Form, Tag or Sequence.
498 + *
499 + * @since 2.5.2
500 + */
501 + private function migrate_contact_form_7_form_mapping_settings() {
502 +
503 + $convertkit_contact_form_7_settings = new ConvertKit_ContactForm7_Settings();
504 +
505 + // Bail if no settings exist.
506 + if ( ! $convertkit_contact_form_7_settings->has_settings() ) {
507 + return;
508 + }
509 +
510 + // Get settings.
511 + $settings = $convertkit_contact_form_7_settings->get();
512 +
513 + // Iterate through settings.
514 + foreach ( $settings as $contact_form_7_form_id => $convertkit_form_id ) {
515 + // Skip keys that are non-numeric e.g. `creator_network_recommendations_*`.
516 + if ( ! is_numeric( $contact_form_7_form_id ) ) {
517 + continue;
518 + }
519 +
520 + // Skip values that are blank i.e. no ConvertKit Form ID specified.
521 + if ( empty( $convertkit_form_id ) ) {
522 + continue;
523 + }
524 +
525 + // Skip values that are non-numeric i.e. the `form_` prefix was already added.
526 + // This should never happen as this routine runs once, but this is a sanity check.
527 + if ( ! is_numeric( $convertkit_form_id ) ) {
528 + continue;
529 + }
530 +
531 + // Prefix the ConvertKit Form ID with `form_`.
532 + $settings[ $contact_form_7_form_id ] = 'form:' . $convertkit_form_id;
533 + }
534 +
535 + // Update settings.
536 + update_option( $convertkit_contact_form_7_settings::SETTINGS_NAME, $settings );
537 +
538 + }
539 +
540 + /**
541 + * 2.5.0: Fetch an Access Token, Refresh Token and Expiry for v4 API use
542 + * based on the Plugin setting's v3 API Key and Secret.
543 + *
544 + * @since 2.5.0
545 + */
546 + private function maybe_get_access_token_by_api_key_and_secret() {
547 +
548 + $convertkit_settings = new ConvertKit_Settings();
549 +
550 + // Bail if an Access Token exists; we don't need to fetch another one.
551 + if ( $convertkit_settings->has_access_token() ) {
552 + return;
553 + }
554 +
555 + // Bail if no API Key or Secret.
556 + if ( empty( $convertkit_settings->get_api_key() ) ) {
557 + return;
558 + }
559 + if ( empty( $convertkit_settings->get_api_secret() ) ) {
560 + return;
561 + }
562 +
563 + // Get Access Token by API Key and Secret.
564 + $api = new ConvertKit_API_V4( CONVERTKIT_OAUTH_CLIENT_ID, CONVERTKIT_OAUTH_CLIENT_REDIRECT_URI );
565 + $result = $api->get_access_token_by_api_key_and_secret(
566 + $convertkit_settings->get_api_key(),
567 + $convertkit_settings->get_api_secret(),
568 + get_site_url()
569 + );
570 +
571 + // Bail if an error occured.
572 + if ( is_wp_error( $result ) ) {
573 + return;
574 + }
575 +
576 + // Store the new credentials.
577 + // We don't use update_credentials(), because the response
578 + // includes an `expires_at`, not a `created_at` and `expires_in`.
579 + $convertkit_settings->save(
580 + array(
581 + 'access_token' => $result['oauth']['access_token'],
582 + 'refresh_token' => $result['oauth']['refresh_token'],
583 + 'token_expires' => $result['oauth']['expires_at'],
584 + )
585 + );
586 +
587 + }
588 +
589 + /**
590 + * Migrate ck_default_form to _wp_convertkit_term_meta[form], as Term settings
591 + * support multiple options (form, position etc).
592 + *
593 + * @since 2.4.9.1
594 + */
595 + private function migrate_term_form_settings() {
596 +
597 + // Get all Terms that have ConvertKit settings defined.
598 + $query = new WP_Term_Query(
599 + array(
600 + 'taxonomy' => 'category',
601 + 'hide_empty' => false,
602 + 'fields' => 'ids',
603 + 'meta_query' => array(
604 + array(
605 + 'key' => 'ck_default_form',
606 + 'comparison' => 'EXISTS',
607 + ),
608 + ),
609 + )
610 + );
611 +
612 + // Bail if no Terms exist.
613 + if ( ! $query->terms ) {
614 + return;
615 + }
616 +
617 + // Iterate through Terms, mapping settings.
618 + foreach ( $query->terms as $term_id ) {
619 + $term_settings = new ConvertKit_Term( $term_id );
620 + $term_settings->save(
621 + array(
622 + 'form' => get_term_meta( $term_id, 'ck_default_form', true ), // Fetch form setting from old meta key.
623 + 'form_position' => '', // Default to no position.
624 + )
625 + );
626 +
627 + // Delete old Term meta.
628 + delete_term_meta( $term_id, 'ck_default_form' );
629 + }
630 +
631 + }
632 +
633 + /**
85 634 * 1.9.6+: Migrate _wp_convertkit_settings[default_form] to _wp_convertkit_settings[page_form] and
86 635 * _wp_convertkit_settings[post_form], now that each Post Type has its own Default Form setting
87 - * in Settings > ConvertKit > General.
636 + * in Settings > Kit > General.
88 637 */
89 638 private function migrate_default_form_settings() {
90 639
91 640 $convertkit_settings = new ConvertKit_Settings();
@@ -127,81 +676,38 @@
127 676
128 677 }
129 678
130 679 /**
131 - * 1.4.1: Change ID to form_id for API version 3.0.
680 + * Runs routines when the Plugin is deactivated.
132 681 *
133 - * @since 1.4.1
682 + * @since 1.9.7.4
134 683 */
135 - private function change_id_to_form_id() {
684 + public function deactivate() {
136 685
137 - // Bail if the API isn't configured.
138 - $convertkit_settings = new ConvertKit_Settings();
139 - if ( ! $convertkit_settings->has_api_key_and_secret() ) {
140 - return;
141 - }
686 + // Call any functions to e.g. unschedule WordPress Cron events now.
687 + $this->unschedule_cron_events();
142 688
143 - // Get all posts and pages to track what has been updated.
144 - $posts = get_option( '_wp_convertkit_upgrade_posts' );
145 - if ( ! $posts ) {
146 - $args = array(
147 - 'post_type' => array( 'post', 'page' ),
148 - 'fields' => 'ids',
149 - );
689 + }
150 690
151 - $result = new WP_Query( $args );
152 - $posts = $result->posts;
153 - update_option( '_wp_convertkit_upgrade_posts', $posts );
154 - }
691 + /**
692 + * Schedules any Plugin specific CRON events, if they do not already exist.
693 + *
694 + * @since 2.6.6
695 + */
696 + private function schedule_cron_events() {
155 697
156 - // Initialize the API.
157 - $api = new ConvertKit_API(
158 - $convertkit_settings->get_api_key(),
159 - $convertkit_settings->get_api_secret(),
160 - $convertkit_settings->debug_enabled(),
161 - 'setup'
162 - );
698 + $posts = new ConvertKit_Resource_Posts( 'cron' );
699 + $posts->schedule_cron_event();
163 700
164 - // Get form mappings.
165 - $mappings = $api->get_subscription_forms();
166 -
167 - // Bail if no form mappings exist.
168 - if ( ! $mappings ) {
169 - return;
170 - }
171 -
172 - // 1. Update global form.
173 - $settings_data = $convertkit_settings->get();
174 - $settings_data['default_form'] = isset( $mappings[ $convertkit_settings->get_default_form( 'post' ) ] ) ? $mappings[ $convertkit_settings->get_default_form( 'post' ) ] : 0;
175 - update_option( $convertkit_settings::SETTINGS_NAME, $settings_data );
176 -
177 - // 2. Scan posts/pages for _wp_convertkit_post_meta and update IDs
178 - // Scan content for shortcode and update
179 - // Remove page_id from posts array after page is updated.
180 - foreach ( $posts as $key => $post_id ) {
181 - $post_settings = get_post_meta( $post_id, '_wp_convertkit_post_meta', true );
182 -
183 - if ( isset( $post_settings['form'] ) && ( 0 < $post_settings['form'] ) ) {
184 - $post_settings['form'] = isset( $mappings[ $post_settings['form'] ] ) ? $mappings[ $post_settings['form'] ] : 0;
185 - }
186 - if ( isset( $post_settings['landing_page'] ) && ( 0 < $post_settings['landing_page'] ) ) {
187 - $post_settings['landing_page'] = isset( $mappings[ $post_settings['landing_page'] ] ) ? $mappings[ $post_settings['landing_page'] ] : 0;
188 - }
189 - update_post_meta( $post_id, '_wp_convertkit_post_meta', $post_settings );
190 - unset( $posts[ $key ] );
191 - update_option( '_wp_convertkit_upgrade_posts', $posts );
192 - }
193 -
194 701 }
195 702
196 703 /**
197 - * Runs routines when the Plugin is deactivated.
704 + * Unschedules any Plugin specific CRON events, if they exist.
198 705 *
199 - * @since 1.9.7.4
706 + * @since 2.6.6
200 707 */
201 - public function deactivate() {
708 + private function unschedule_cron_events() {
202 709
203 - // Call any functions to e.g. unschedule WordPress Cron events now.
204 710 $posts = new ConvertKit_Resource_Posts( 'cron' );
205 711 $posts->unschedule_cron_event();
206 712
207 713 }