PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 2.5.2
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v2.5.2
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 2.2.9 2.3.0 All 197 releases
← All changes | includes/class-convertkit-settings.php +34 -373 3.3.82.5.2 View file →
@@ -44,8 +44,11 @@
44 44 } else {
45 45 $this->settings = array_merge( $this->get_defaults(), $settings );
46 46 }
47 47
48 + // Update Access Token when refreshed by the API class.
49 + add_action( 'convertkit_api_refresh_token', array( $this, 'update_credentials' ), 10, 2 );
50 +
48 51 }
49 52
50 53 /**
51 54 * Returns Plugin settings.
@@ -158,13 +161,10 @@
158 161 * @return bool
159 162 */
160 163 public function has_api_key_and_secret() {
161 164
162 - _deprecated_function( __FUNCTION__, '2.6.3', 'has_access_and_refresh_token()' );
165 + return $this->has_api_key() && $this->has_api_secret();
163 166
164 - // Use check for access and refresh token.
165 - return $this->has_access_and_refresh_token();
166 -
167 167 }
168 168
169 169 /**
170 170 * Returns the Access Token Plugin setting.
@@ -174,11 +174,8 @@
174 174 * @return string
175 175 */
176 176 public function get_access_token() {
177 177
178 - // Reload settings from options table, to ensure we have the latest tokens.
179 - $this->refresh_settings();
180 -
181 178 // Return Access Token from settings.
182 179 return $this->settings['access_token'];
183 180
184 181 }
@@ -204,11 +201,8 @@
204 201 * @return string
205 202 */
206 203 public function get_refresh_token() {
207 204
208 - // Reload settings from options table, to ensure we have the latest tokens.
209 - $this->refresh_settings();
210 -
211 205 // Return Refresh Token from settings.
212 206 return $this->settings['refresh_token'];
213 207
214 208 }
@@ -294,86 +288,23 @@
294 288
295 289 }
296 290
297 291 /**
298 - * Returns the Default Form Position Plugin setting.
299 - *
300 - * @since 2.5.8
301 - *
302 - * @param string $post_type Post Type.
303 - * @return string|int Default Form (default|form id)
304 - */
305 - public function get_default_form_position( $post_type ) {
306 -
307 - // Return after_content if this Post Type's position doesn't exist as a setting.
308 - if ( ! array_key_exists( $post_type . '_form_position', $this->settings ) ) {
309 - return 'after_content';
310 - }
311 -
312 - return $this->settings[ $post_type . '_form_position' ];
313 -
314 - }
315 -
316 - /**
317 - * Returns the Default Form Position Element Plugin setting.
318 - *
319 - * @since 2.6.1
320 - *
321 - * @param string $post_type Post Type.
322 - * @return string Element to insert form after
323 - */
324 - public function get_default_form_position_element( $post_type ) {
325 -
326 - // Return after_content if this Post Type's position doesn't exist as a setting.
327 - if ( ! array_key_exists( $post_type . '_form_position_element', $this->settings ) ) {
328 - return 'p';
329 - }
330 -
331 - return $this->settings[ $post_type . '_form_position_element' ];
332 -
333 - }
334 -
335 - /**
336 - * Returns the Default Form Position Index Plugin setting.
337 - *
338 - * @since 2.6.1
339 - *
340 - * @param string $post_type Post Type.
341 - * @return int Number of elements before inserting form
342 - */
343 - public function get_default_form_position_element_index( $post_type ) {
344 -
345 - // Return 1 if this Post Type's position index doesn't exist as a setting.
346 - if ( ! array_key_exists( $post_type . '_form_position_element_index', $this->settings ) ) {
347 - return 1;
348 - }
349 -
350 - return (int) $this->settings[ $post_type . '_form_position_element_index' ];
351 -
352 - }
353 -
354 - /**
355 292 * Returns the Global non-inline Form Plugin setting.
356 293 *
357 294 * @since 2.3.3
358 295 *
359 - * @return array
296 + * @return string|int Non-inline Form (blank string|form id)
360 297 */
361 298 public function get_non_inline_form() {
362 299
363 - // Return blank array if no inline form is specified.
300 + // Return blank string if no inline form is specified.
364 301 if ( ! $this->has_non_inline_form() ) {
365 - return array();
302 + return '';
366 303 }
367 304
368 - // 2.6.8 and earlier stored a single Form ID in a string.
369 - if ( is_string( $this->settings['non_inline_form'] ) ) {
370 - return array( (int) $this->settings['non_inline_form'] );
371 - }
305 + return $this->settings['non_inline_form'];
372 306
373 - // Cast values to integers and return.
374 - return array_map( 'intval', $this->settings['non_inline_form'] );
375 -
376 307 }
377 308
378 309 /**
379 310 * Returns whether the Global non-inline Form has been set in the Plugin settings.
@@ -383,207 +314,13 @@
383 314 * @return bool Global non-inline Form setting specified in Plugin Settings.
384 315 */
385 316 public function has_non_inline_form() {
386 317
387 - // 2.6.8 and earlier stored a single Form ID in a string.
388 - if ( is_string( $this->settings['non_inline_form'] ) ) {
389 - if ( ! empty( $this->settings['non_inline_form'] ) ) {
390 - return true;
391 - }
318 + return ( ! empty( $this->settings['non_inline_form'] ) ? true : false );
392 319
393 - return false;
394 - }
395 -
396 - return ( count( $this->settings['non_inline_form'] ) > 0 ? true : false );
397 -
398 320 }
399 321
400 322 /**
401 - * Returns whether the Global non-inline Form setting should honor the Page / Post
402 - * None setting.
403 - *
404 - * @since 2.7.3
405 - *
406 - * @return bool
407 - */
408 - public function non_inline_form_honor_none_setting() {
409 -
410 - return ( $this->settings['non_inline_form_honor_none_setting'] === 'on' ? true : false );
411 -
412 - }
413 -
414 - /**
415 - * Returns whether the Non-inline Form Limit per Session setting has been set in the Plugin settings.
416 - *
417 - * @since 3.0.0
418 - *
419 - * @return bool
420 - */
421 - public function non_inline_form_limit_per_session() {
422 -
423 - return ( $this->settings['non_inline_form_limit_per_session'] === 'on' ? true : false );
424 -
425 - }
426 -
427 - /**
428 - * Returns the active spam protection provider Plugin setting.
429 - *
430 - * @since 3.3.7
431 - *
432 - * @return string none|recaptcha|turnstile
433 - */
434 - public function spam_protection_provider() {
435 -
436 - return $this->settings['spam_protection_provider'];
437 -
438 - }
439 -
440 - /**
441 - * Returns the reCAPTCHA Site Key Plugin setting.
442 - *
443 - * @since 3.0.0
444 - *
445 - * @return string
446 - */
447 - public function recaptcha_site_key() {
448 -
449 - return $this->settings['recaptcha_site_key'];
450 -
451 - }
452 -
453 - /**
454 - * Returns whether the reCAPTCHA Site Key has been set in the Plugin settings.
455 - *
456 - * @since 3.0.0
457 - *
458 - * @return bool
459 - */
460 - public function has_recaptcha_site_key() {
461 -
462 - return ! empty( $this->recaptcha_site_key() );
463 -
464 - }
465 -
466 - /**
467 - * Returns the reCAPTCHA Secret Key Plugin setting.
468 - *
469 - * @since 3.0.0
470 - *
471 - * @return string
472 - */
473 - public function recaptcha_secret_key() {
474 -
475 - return $this->settings['recaptcha_secret_key'];
476 -
477 - }
478 -
479 - /**
480 - * Returns whether the reCAPTCHA Secret Key has been set in the Plugin settings.
481 - *
482 - * @since 3.0.0
483 - *
484 - * @return bool
485 - */
486 - public function has_recaptcha_secret_key() {
487 -
488 - return ! empty( $this->recaptcha_secret_key() );
489 -
490 - }
491 -
492 - /**
493 - * Returns whether the reCAPTCH Site Key and Secret Key are defined
494 - * in the Plugin settings.
495 - *
496 - * @since 3.0.0
497 - *
498 - * @return bool
499 - */
500 - public function has_recaptcha_site_and_secret_keys() {
501 -
502 - return $this->has_recaptcha_site_key() && $this->has_recaptcha_secret_key();
503 -
504 - }
505 -
506 - /**
507 - * Returns the reCAPTCHA minimum score Plugin setting.
508 - *
509 - * @since 3.0.0
510 - *
511 - * @return float
512 - */
513 - public function recaptcha_minimum_score() {
514 -
515 - return (float) $this->settings['recaptcha_minimum_score'];
516 -
517 - }
518 -
519 - /**
520 - * Returns the Cloudflare Turnstile Site Key Plugin setting.
521 - *
522 - * @since 3.3.7
523 - *
524 - * @return string
525 - */
526 - public function cloudflare_turnstile_site_key() {
527 -
528 - return $this->settings['cloudflare_turnstile_site_key'];
529 -
530 - }
531 -
532 - /**
533 - * Returns whether the Cloudflare Turnstile Site Key has been set in the Plugin settings.
534 - *
535 - * @since 3.3.7
536 - *
537 - * @return bool
538 - */
539 - public function has_cloudflare_turnstile_site_key() {
540 -
541 - return ! empty( $this->cloudflare_turnstile_site_key() );
542 -
543 - }
544 -
545 - /**
546 - * Returns the Cloudflare Turnstile Secret Key Plugin setting.
547 - *
548 - * @since 3.3.7
549 - *
550 - * @return string
551 - */
552 - public function cloudflare_turnstile_secret_key() {
553 -
554 - return $this->settings['cloudflare_turnstile_secret_key'];
555 -
556 - }
557 -
558 - /**
559 - * Returns whether the Cloudflare Turnstile Secret Key has been set in the Plugin settings.
560 - *
561 - * @since 3.3.7
562 - *
563 - * @return bool
564 - */
565 - public function has_cloudflare_turnstile_secret_key() {
566 -
567 - return ! empty( $this->cloudflare_turnstile_secret_key() );
568 -
569 - }
570 -
571 - /**
572 - * Returns whether the Cloudflare Turnstile Site Key and Secret Key are defined
573 - * in the Plugin settings.
574 - *
575 - * @since 3.3.7
576 - *
577 - * @return bool
578 - */
579 - public function has_cloudflare_turnstile_site_and_secret_keys() {
580 -
581 - return $this->has_cloudflare_turnstile_site_key() && $this->has_cloudflare_turnstile_secret_key();
582 -
583 - }
584 -
585 - /**
586 323 * Returns whether debugging is enabled in the Plugin settings.
587 324 *
588 325 * @since 1.9.6
589 326 *
@@ -621,34 +358,8 @@
621 358
622 359 }
623 360
624 361 /**
625 - * Returns whether the Add New Landing Page / Member Content button is disabled in the Plugin settings.
626 - *
627 - * @since 3.2.0
628 - *
629 - * @return bool
630 - */
631 - public function add_new_button_disabled() {
632 -
633 - return ( $this->settings['no_add_new_button'] === 'on' ? true : false );
634 -
635 - }
636 -
637 - /**
638 - * Returns whether usage tracking is enabled in the Plugin settings.
639 - *
640 - * @since 3.0.4
641 - *
642 - * @return bool
643 - */
644 - public function usage_tracking() {
645 -
646 - return ( $this->settings['usage_tracking'] === 'on' ? true : false );
647 -
648 - }
649 -
650 - /**
651 362 * The default settings, used when the ConvertKit Plugin Settings haven't been saved
652 363 * e.g. on a new installation.
653 364 *
654 365 * @since 1.9.6
@@ -658,47 +369,26 @@
658 369 public function get_defaults() {
659 370
660 371 $defaults = array(
661 372 // OAuth.
662 - 'access_token' => '', // string.
663 - 'refresh_token' => '', // string.
664 - 'token_expires' => '', // integer.
373 + 'access_token' => '', // string.
374 + 'refresh_token' => '', // string.
375 + 'token_expires' => '', // integer.
665 376
666 377 // API Key. Retained if needed for backward compat.
667 - 'api_key' => '', // string.
668 - 'api_secret' => '', // string.
378 + 'api_key' => '', // string.
379 + 'api_secret' => '', // string.
669 380
670 - // Site Wide.
671 - 'non_inline_form' => array(), // array.
672 - 'non_inline_form_honor_none_setting' => '', // blank|on.
673 - 'non_inline_form_limit_per_session' => '', // blank|on.
674 -
675 - // Spam Protection.
676 - 'spam_protection_provider' => 'recaptcha', // recaptcha|turnstile.
677 -
678 - // reCAPTCHA.
679 - 'recaptcha_site_key' => '', // string.
680 - 'recaptcha_secret_key' => '', // string.
681 - 'recaptcha_minimum_score' => 0.5, // float.
682 -
683 - // Cloudflare Turnstile.
684 - 'cloudflare_turnstile_site_key' => '', // string.
685 - 'cloudflare_turnstile_secret_key' => '', // string.
686 -
687 - // Advanced.
688 - 'debug' => '', // blank|on.
689 - 'no_scripts' => '', // blank|on.
690 - 'no_css' => '', // blank|on.
691 - 'no_add_new_button' => '', // blank|on.
692 - 'usage_tracking' => '', // blank|on.
381 + // Settings.
382 + 'non_inline_form' => '', // string.
383 + 'debug' => '', // blank|on.
384 + 'no_scripts' => '', // blank|on.
385 + 'no_css' => '', // blank|on.
693 386 );
694 387
695 388 // Add Post Type Default Forms.
696 389 foreach ( convertkit_get_supported_post_types() as $post_type ) {
697 - $defaults[ $post_type . '_form' ] = 0; // -1, 0 or Form ID.
698 - $defaults[ $post_type . '_form_position' ] = 'after_content'; // before_content,after_content,before_after_content,element.
699 - $defaults[ $post_type . '_form_position_element' ] = 'p';
700 - $defaults[ $post_type . '_form_position_element_index' ] = 1;
390 + $defaults[ $post_type . '_form' ] = 0; // -1, 0 or Form ID.
701 391 }
702 392
703 393 /**
704 394 * The default settings, used when the ConvertKit Plugin Settings haven't been saved
@@ -714,39 +404,36 @@
714 404
715 405 }
716 406
717 407 /**
718 - * Saves the new access token, refresh token and its expiry, and schedules
719 - * a WordPress Cron event to refresh the token on expiry.
408 + * Saves the new access token, refresh token and its expiry when the API
409 + * class automatically refreshes an outdated access token.
720 410 *
721 - * @since 2.8.3
411 + * @since 2.5.0
722 412 *
723 - * @param array $result New Access Token, Refresh Token and Expiry.
413 + * @param array $result New Access Token, Refresh Token and Expiry.
414 + * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens.
724 415 */
725 - public function update_credentials( $result ) {
416 + public function update_credentials( $result, $client_id ) {
726 417
727 - // Remove any existing persistent notice.
728 - WP_ConvertKit()->get_class( 'admin_notices' )->delete( 'authorization_failed' );
418 + // Don't save these credentials if they're not for this Client ID.
419 + // They're for another ConvertKit Plugin that uses OAuth.
420 + if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) {
421 + return;
422 + }
729 423
730 424 $this->save(
731 425 array(
732 426 'access_token' => $result['access_token'],
733 427 'refresh_token' => $result['refresh_token'],
734 - 'token_expires' => ( time() + $result['expires_in'] ),
428 + 'token_expires' => ( $result['created_at'] + $result['expires_in'] ),
735 429 )
736 430 );
737 431
738 - // Clear any existing scheduled WordPress Cron event.
739 - wp_clear_scheduled_hook( 'convertkit_refresh_token' );
740 -
741 - // Schedule a WordPress Cron event to refresh the token on expiry.
742 - wp_schedule_single_event( ( time() + $result['expires_in'] ), 'convertkit_refresh_token' );
743 -
744 432 }
745 433
746 434 /**
747 - * Deletes any existing access token, refresh token and its expiry from the Plugin settings,
748 - * and clears any existing scheduled WordPress Cron event to refresh the token on expiry.
435 + * Deletes any existing access token, refresh token and its expiry from the Plugin settings.
749 436 *
750 437 * @since 2.5.0
751 438 */
752 439 public function delete_credentials() {
@@ -752,22 +439,14 @@
752 439 public function delete_credentials() {
753 440
754 441 $this->save(
755 442 array(
756 - // OAuth.
757 443 'access_token' => '',
758 444 'refresh_token' => '',
759 445 'token_expires' => '',
760 -
761 - // API Key.
762 - 'api_key' => '',
763 - 'api_secret' => '',
764 446 )
765 447 );
766 448
767 - // Clear any existing scheduled WordPress Cron event.
768 - wp_clear_scheduled_hook( 'convertkit_refresh_token' );
769 -
770 449 }
771 450
772 451 /**
773 452 * Saves the given array of settings to the WordPress options table.
@@ -780,27 +459,9 @@
780 459
781 460 update_option( self::SETTINGS_NAME, array_merge( $this->get(), $settings ) );
782 461
783 462 // Reload settings in class, to reflect changes.
784 - $this->refresh_settings();
785 -
786 - }
787 -
788 - /**
789 - * Reloads settings from the options table so this instance has the latest values.
790 - *
791 - * @since 3.1.1
792 - */
793 - private function refresh_settings() {
794 -
795 - $settings = get_option( self::SETTINGS_NAME );
796 -
797 - if ( ! $settings ) {
798 - $this->settings = $this->get_defaults();
799 - return;
800 - }
801 -
802 - $this->settings = array_merge( $this->get_defaults(), $settings );
463 + $this->settings = get_option( self::SETTINGS_NAME );
803 464
804 465 }
805 466
806 467 }