MC4WP_Lite_Widget

Adds MC4WP_Widget widget.

Defined (1)

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

/includes/class-widget.php  
  1. class MC4WP_Lite_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Register widget with WordPress. 
  5. */ 
  6. function __construct() { 
  7. parent::__construct( 
  8. 'MC4WP_Widget', // Base ID 
  9. __( 'MailChimp Sign-Up Form', 'mailchimp-for-wp' ), // Name 
  10. array( 
  11. 'description' => __( 'Displays your MailChimp for WordPress sign-up form', 'mailchimp-for-wp' ),  
  12. ); 
  13.  
  14. /** 
  15. * Front-end display of widget. 
  16. * @see WP_Widget::widget() 
  17. * @param array $args Widget arguments. 
  18. * @param array $instance Saved values from database. 
  19. */ 
  20. public function widget( $args, $instance ) { 
  21.  
  22. $title = isset( $instance['title'] ) ? $instance['title'] : ''; 
  23. $title = apply_filters( 'widget_title', $title ); 
  24.  
  25. echo $args['before_widget']; 
  26.  
  27. if ( ! empty( $title ) ) { 
  28. echo $args['before_title'] . $title . $args['after_title']; 
  29.  
  30. // make sure template functions exist (for usage in avia layout builder) 
  31. if ( ! function_exists( 'mc4wp_get_form' ) ) { 
  32. include_once MC4WP_LITE_PLUGIN_DIR . 'includes/functions/template.php'; 
  33.  
  34. echo mc4wp_get_form(); 
  35.  
  36. echo $args['after_widget']; 
  37.  
  38. /** 
  39. * Back-end widget form. 
  40. * @see WP_Widget::form() 
  41. * @param array $instance Previously saved values from database. 
  42. * @return string|void 
  43. */ 
  44. public function form( $instance ) { 
  45. $title = isset( $instance['title'] ) ? $instance['title'] : __( 'Newsletter', 'mailchimp-for-wp' ); 
  46. ?> 
  47. <p> 
  48. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'mailchimp-for-wp' ); ?></label> 
  49. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> 
  50. </p> 
  51. <p class="help"> 
  52. <?php printf( __( 'You can edit your sign-up form in the <a href="%s">MailChimp for WordPress form settings</a>.', 'mailchimp-for-wp' ), admin_url( 'admin.php?page=mailchimp-for-wp-form-settings' ) ); ?> 
  53. </p> 
  54. <?php 
  55.  
  56. /** 
  57. * Sanitize widget form values as they are saved. 
  58. * @see WP_Widget::update() 
  59. * @param array $new_instance Values just sent to be saved. 
  60. * @param array $old_instance Previously saved values from database. 
  61. * @return array Updated safe values to be saved. 
  62. */ 
  63. public function update( $new_instance, $old_instance ) { 
  64. $instance = array(); 
  65. $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : ''; 
  66. return $instance; 
  67.  
  68. } // class MC4WP_Widget