class-field-mailchimp-signup.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\ConfigurationUI
  6. */
  7. /**
  8. * Class WPSEO_Config_Field_Mailchimp_Signup.
  9. */
  10. class WPSEO_Config_Field_Mailchimp_Signup extends WPSEO_Config_Field {
  11. /**
  12. * WPSEO_Config_Field_Mailchimp_Signup constructor.
  13. */
  14. public function __construct() {
  15. parent::__construct( 'mailchimpSignup', 'MailchimpSignup' );
  16. $current_user = wp_get_current_user();
  17. $user_email = ( $current_user->ID > 0 ) ? $current_user->user_email : '';
  18. $signup_text = sprintf(
  19. /* translators: %1$s expands to Yoast SEO for WordPress, %2$s expands to Yoast */
  20. __( 'Sign up for our newsletter if you would like to keep up-to-date about %1$s, other cool plugins by %2$s, and interesting news and tips from the world of SEO.', 'wordpress-seo' ),
  21. 'Yoast SEO for WordPress',
  22. 'Yoast'
  23. );
  24. $gdpr_notice = sprintf(
  25. /* translators: %1$s expands Yoast, %2$s expands to an opening anchor tag, %3$s expands to a closing anchor tag. */
  26. __( '%1$s respects your privacy. Read our %2$sprivacy policy%3$s on how we handle your personal information.', 'wordpress-seo' ),
  27. 'Yoast',
  28. '<a target="_blank" rel="noopener noreferrer" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/gdpr-config-wizard' ) . '">',
  29. '</a>'
  30. );
  31. $this->set_property( 'label', $signup_text );
  32. $this->set_property( 'decoration', plugin_dir_url( WPSEO_FILE ) . 'images/newsletter-collage.png' );
  33. $this->set_property( 'mailchimpActionUrl', 'https://yoast.us1.list-manage.com/subscribe/post-json?u=ffa93edfe21752c921f860358&id=972f1c9122' );
  34. $this->set_property( 'currentUserEmail', $user_email );
  35. $this->set_property( 'freeAccountNotice', __( 'Includes a free MyYoast account which gives you access to our free SEO for Beginners course!', 'wordpress-seo' ) );
  36. $this->set_property( 'GDPRNotice', sprintf( '<small>%s</small>', $gdpr_notice ) );
  37. }
  38. /**
  39. * Get the data.
  40. *
  41. * @return array
  42. */
  43. public function get_data() {
  44. return [
  45. 'hasSignup' => $this->has_mailchimp_signup(),
  46. ];
  47. }
  48. /**
  49. * Checks if the user has entered their email for mailchimp already.
  50. *
  51. * @return bool
  52. */
  53. protected function has_mailchimp_signup() {
  54. $user_meta = get_user_meta( get_current_user_id(), WPSEO_Config_Component_Mailchimp_Signup::META_NAME, true );
  55. return ( ! empty( $user_meta ) );
  56. }
  57. }