MC4WP_CF7_Integration

The MailChimp for WordPress Lite MC4WP CF7 Integration class.

Defined (1)

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

/includes/integrations/class-cf7.php  
  1. class MC4WP_CF7_Integration extends MC4WP_General_Integration { 
  2.  
  3. /** 
  4. * @var string 
  5. */ 
  6. protected $type = 'contact_form_7'; 
  7.  
  8. /** 
  9. * Constructor 
  10. */ 
  11. public function __construct() { 
  12.  
  13. // make sure older checkbox names work for CF7 too 
  14. $this->upgrade(); 
  15.  
  16. add_action( 'init', array( $this, 'init') ); 
  17.  
  18. add_action( 'wpcf7_mail_sent', array( $this, 'subscribe_from_cf7' ) ); 
  19. add_action( 'wpcf7_posted_data', array( $this, 'alter_cf7_data') ); 
  20.  
  21. /** 
  22. * Registers the CF7 shortcode 
  23. * @return boolean 
  24. */ 
  25. public function init() { 
  26.  
  27. if( ! function_exists( 'wpcf7_add_shortcode' ) ) { 
  28. return false; 
  29.  
  30. wpcf7_add_shortcode( 'mc4wp_checkbox', array( $this, 'get_checkbox' ) ); 
  31. return true; 
  32.  
  33. /** 
  34. * Alter Contact Form 7 data. 
  35. * Adds mc4wp_checkbox to post data so users can use `mc4wp_checkbox` in their email templates 
  36. * @param array $data 
  37. * @return array 
  38. */ 
  39. public function alter_cf7_data( $data = array() ) { 
  40. $data['mc4wp_checkbox'] = $this->checkbox_was_checked() ? __( 'Yes', 'mailchimp-for-wp' ) : __( 'No', 'mailchimp-for-wp' ); 
  41. return $data; 
  42.  
  43. /** 
  44. * Subscribe from Contact Form 7 Forms 
  45. */ 
  46. public function subscribe_from_cf7() { 
  47.  
  48. // was sign-up checkbox checked? 
  49. if ( $this->checkbox_was_checked() === false ) { 
  50. return false; 
  51.  
  52. return $this->try_subscribe(); 
  53.