Jetpack_MailChimp_Subscriber_Popup_Widget

Add a MailChimp subscription form.

Defined (1)

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

/modules/widgets/mailchimp.php  
  1. class Jetpack_MailChimp_Subscriber_Popup_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Constructor 
  5. */ 
  6. function __construct() { 
  7. parent::__construct( 
  8. 'widget_mailchimp_subscriber_popup',  
  9. /** This filter is documented in modules/widgets/facebook-likebox.php */ 
  10. apply_filters( 'jetpack_widget_name', __( 'MailChimp Subscriber Popup', 'jetpack' ) ),  
  11. array( 
  12. 'classname' => 'widget_mailchimp_subscriber_popup',  
  13. 'description' => __( 'Allows displaying a popup subscription form to visitors.', 'jetpack' ),  
  14. 'customize_selective_refresh' => true,  
  15. ); 
  16.  
  17. /** 
  18. * Outputs the HTML for this widget. 
  19. * @param array $args An array of standard parameters for widgets in this theme 
  20. * @param array $instance An array of settings for this widget instance 
  21. * @return void Echoes it's output 
  22. **/ 
  23. function widget( $args, $instance ) { 
  24. $instance = wp_parse_args( $instance, array( 'code' => '' ) ); 
  25.  
  26. // Regular expresion that will match maichimp shortcode. 
  27. $regex = "(\[mailchimp_subscriber_popup[^\]]+\])"; 
  28.  
  29. // Check if the shortcode exists. 
  30. preg_match( $regex, $instance['code'], $matches ); 
  31.  
  32. // Process the shortcode only, if exists. 
  33. if ( ! empty( $matches[0] ) ) { 
  34. echo do_shortcode( $matches[0] ); 
  35.  
  36. /** This action is documented in modules/widgets/gravatar-profile.php */ 
  37. do_action( 'jetpack_stats_extra', 'widget_view', 'mailchimp_subscriber_popup' ); 
  38.  
  39.  
  40. /** 
  41. * Deals with the settings when they are saved by the admin. 
  42. * @param array $new_instance New configuration values 
  43. * @param array $old_instance Old configuration values 
  44. * @return array 
  45. */ 
  46. function update( $new_instance, $old_instance ) { 
  47. $instance = array(); 
  48. $instance['code'] = wp_kses_post( stripslashes( $new_instance['code'] ) ); 
  49.  
  50. return $instance; 
  51.  
  52.  
  53. /** 
  54. * Displays the form for this widget on the Widgets page of the WP Admin area. 
  55. * @param array $instance Instance configuration. 
  56. * @return void 
  57. */ 
  58. function form( $instance ) { 
  59. $instance = wp_parse_args( $instance, array( 'code' => '' ) ); 
  60. ?> 
  61.  
  62. <p> 
  63. <label for="<?php echo esc_attr( $this->get_field_id( 'code' ) ); ?>"> 
  64. <?php printf( __( 'Code: <a href="%s" target="_blank">( ? )</a>', 'jetpack' ), 'https://en.support.wordpress.com/mailchimp/' ); ?> 
  65. </label> 
  66. <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'code' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'code' ) ); ?>" rows="3"><?php echo esc_textarea( $instance['code'] ); ?></textarea> 
  67. </p> 
  68.  
  69. <?php 
  70.