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