MC4WP_MultiSite_Integration

The MailChimp for WordPress Lite MC4WP MultiSite Integration class.

Defined (1)

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

/includes/integrations/class-multisite.php  
  1. class MC4WP_MultiSite_Integration extends MC4WP_User_Integration { 
  2.  
  3. protected $type = 'multisite_form'; 
  4.  
  5. public function __construct() { 
  6.  
  7. parent::__construct(); 
  8.  
  9. add_action( 'signup_extra_fields', array( $this, 'output_checkbox' ), 20 ); 
  10. add_action( 'signup_blogform', array( $this, 'add_multisite_hidden_checkbox' ), 20 ); 
  11. add_action( 'wpmu_activate_blog', array( $this, 'on_multisite_blog_signup' ), 20, 5 ); 
  12. add_action( 'wpmu_activate_user', array( $this, 'on_multisite_user_signup' ), 20, 3 ); 
  13.  
  14. add_filter( 'add_signup_meta', array( $this, 'add_multisite_usermeta' ) ); 
  15.  
  16. /** 
  17. * Add hidden checkbox to 2nd MultiSite registration form 
  18. */ 
  19. public function add_multisite_hidden_checkbox() { 
  20. $value = $this->checkbox_was_checked() ? 1 : 0; 
  21. ?><input type="hidden" name="_mc4wp_subscribe" value="<?php echo $value; ?>" /><?php 
  22.  
  23. /** 
  24. * Subscribe from Multisite blog sign-ups 
  25. * @param int $blog_id 
  26. * @param int $user_id 
  27. * @return boolean 
  28. */ 
  29. public function on_multisite_blog_signup( $blog_id, $user_id, $a, $b, $meta = null ) { 
  30. // was sign-up checkbox checked? 
  31. if ( ! isset( $meta['_mc4wp_subscribe'] ) || $meta['_mc4wp_subscribe'] !== 1 ) { 
  32. return false; 
  33.  
  34. return $this->subscribe_from_multisite( $user_id ); 
  35.  
  36. /** 
  37. * Subscribe from Multisite user sign-ups 
  38. * @param int $user_id 
  39. * @param string $password 
  40. * @param array $meta 
  41. * @return boolean 
  42. */ 
  43. public function on_multisite_user_signup( $user_id, $password = null, $meta = array() ) { 
  44. // abandon if sign-up checkbox was not checked 
  45. if ( ! isset( $meta['_mc4wp_subscribe'] ) || $meta['_mc4wp_subscribe'] !== 1 ) { 
  46. return false; 
  47.  
  48. return $this->subscribe_from_multisite( $user_id ); 
  49.  
  50. /** 
  51. * Add user meta from Multisite sign-ups to store the checkbox value 
  52. * @param array $meta 
  53. * @return array 
  54. */ 
  55. public function add_multisite_usermeta( $meta = array() ) { 
  56. $meta['_mc4wp_subscribe'] = $this->checkbox_was_checked() ? 1 : 0; 
  57. return $meta; 
  58.  
  59. /** 
  60. * Subscribe from Multisite forms 
  61. * @param int $user_id 
  62. * @return bool 
  63. */ 
  64. public function subscribe_from_multisite( $user_id ) { 
  65. $user = get_userdata( $user_id ); 
  66.  
  67. if ( ! is_object( $user ) ) { 
  68. return false; 
  69.  
  70. $email = $user->user_email; 
  71. $merge_vars = $this->user_merge_vars( $user ); 
  72.  
  73. return $this->subscribe( $email, $merge_vars, 'multisite_registration', $user_id ); 
  74.