WPSEO_Config_Component_Mailchimp_Signup

Represents the mailchimp signup components.

Defined (1)

The class is defined in the following location(s).

/admin/config-ui/components/class-component-mailchimp-signup.php  
  1. class WPSEO_Config_Component_Mailchimp_Signup implements WPSEO_Config_Component { 
  2.  
  3. const META_NAME = 'wpseo-has-mailchimp-signup'; 
  4.  
  5. /** 
  6. * Gets the component identifier. 
  7. * @return string 
  8. */ 
  9. public function get_identifier() { 
  10. return 'MailchimpSignup'; 
  11.  
  12. /** 
  13. * Gets the field. 
  14. * @return WPSEO_Config_Field 
  15. */ 
  16. public function get_field() { 
  17. return new WPSEO_Config_Field_Mailchimp_Signup(); 
  18.  
  19. /** 
  20. * Get the data for the field. 
  21. * @return mixed 
  22. */ 
  23. public function get_data() { 
  24. $data = array( 
  25. 'hasSignup' => $this->has_mailchimp_signup(),  
  26. ); 
  27.  
  28. return $data; 
  29.  
  30. /** 
  31. * Save data 
  32. * @param array $data Data containing changes. 
  33. * @return mixed 
  34. */ 
  35. public function set_data( $data ) { 
  36.  
  37. $has_saved = false; 
  38. if ( ! empty( $data['hasSignup'] ) ) { 
  39. // Saves the user meta. 
  40. update_user_meta( get_current_user_id(), self::META_NAME, true ); 
  41.  
  42. $has_saved = ( $data['hasSignup'] === $this->has_mailchimp_signup() ); 
  43.  
  44. // Collect results to return to the configurator. 
  45. $results = array( 
  46. 'hasSignup' => $has_saved,  
  47. ); 
  48.  
  49. return $results; 
  50.  
  51. /** 
  52. * Checks if the user has entered his email for mailchimp already. 
  53. * @return bool 
  54. */ 
  55. protected function has_mailchimp_signup() { 
  56. $user_meta = get_user_meta( get_current_user_id(), self::META_NAME, true ); 
  57.  
  58. return ( ! empty( $user_meta ) );