Completed
Push — kraftbj-patch-2 ( 82c983...ae9d16 )
by
unknown
513:58 queued 503:20
created

widget()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
if ( ! class_exists( 'Jetpack_MailChimp_Subscriber_Popup_Widget' ) ) {
4
5
	//register MailChimp Subscriber Popup widget
6
	function jetpack_mailchimp_subscriber_popup_widget_init() {
7
		if ( class_exists( 'MailChimp_Subscriber_Popup' ) ) {
8
			register_widget( 'Jetpack_MailChimp_Subscriber_Popup_Widget' );
9
		}
10
	}
11
12
	add_action( 'widgets_init', 'jetpack_mailchimp_subscriber_popup_widget_init' );
13
14
	/**
15
	 * Add a MailChimp subscription form.
16
	 */
17
	class Jetpack_MailChimp_Subscriber_Popup_Widget extends WP_Widget {
18
19
		/**
20
		 * Constructor
21
		 */
22 View Code Duplication
		function __construct() {
23
			parent::__construct(
24
				'widget_mailchimp_subscriber_popup',
25
				/** This filter is documented in modules/widgets/facebook-likebox.php */
26
				apply_filters( 'jetpack_widget_name', __( 'MailChimp Subscriber Popup', 'jetpack' ) ),
27
				array(
28
					'classname'                   => 'widget_mailchimp_subscriber_popup',
29
					'description'                 => __( 'Allows displaying a popup subscription form to visitors.', 'jetpack' ),
30
					'customize_selective_refresh' => true,
31
				)
32
			);
33
		}
34
35
		/**
36
		 * Outputs the HTML for this widget.
37
		 *
38
		 * @param array $args     An array of standard parameters for widgets in this theme
39
		 * @param array $instance An array of settings for this widget instance
40
		 *
41
		 * @return void Echoes it's output
42
		 **/
43
		function widget( $args, $instance ) {
44
			$instance = wp_parse_args( $instance, array( 'code' => '' ) );
45
46
			// Regular expresion that will match maichimp shortcode.
47
			$regex = "(\[mailchimp_subscriber_popup[^\]]+\])";
48
49
			// Check if the shortcode exists.
50
			preg_match( $regex, $instance['code'], $matches );
51
52
			// Process the shortcode only, if exists.
53
			if ( ! empty( $matches[0] ) ) {
54
				echo do_shortcode( $matches[0] );
55
			}
56
57
			/** This action is documented in modules/widgets/gravatar-profile.php */
58
			do_action( 'jetpack_stats_extra', 'widget_view', 'mailchimp_subscriber_popup' );
59
		}
60
61
62
		/**
63
		 * Deals with the settings when they are saved by the admin.
64
		 *
65
		 * @param array $new_instance New configuration values
66
		 * @param array $old_instance Old configuration values
67
		 *
68
		 * @return array
69
		 */
70
		function update( $new_instance, $old_instance ) {
71
			$instance         = array();
72
			$instance['code'] = wp_kses_post( stripslashes( $new_instance['code'] ) );
73
74
			return $instance;
75
		}
76
77
78
		/**
79
		 * Displays the form for this widget on the Widgets page of the WP Admin area.
80
		 *
81
		 * @param array $instance Instance configuration.
82
		 *
83
		 * @return void
84
		 */
85
		function form( $instance ) {
86
			$instance = wp_parse_args( $instance, array( 'code' => '' ) );
87
			?>
88
89
			<p>
90
				<label for="<?php echo esc_attr( $this->get_field_id( 'code' ) ); ?>">
91
					<?php printf( __( 'Code: <a href="%s" target="_blank">( ? )</a>', 'jetpack' ), 'https://en.support.wordpress.com/mailchimp/' ); ?>
92
				</label>
93
				<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>
94
			</p>
95
96
			<?php
97
		}
98
99
	}
100
101
}
102