widget_cssclass = 'widget_blogmarks_mailchimp_form'; $this->widget_description = __( 'Displays MailChimp form if you have any', 'blogmarks' ); $this->widget_id = 'blogmarks_mailchimp_form'; $this->widget_name = __( 'Blogmarks: MailChimp Form', 'blogmarks' ); $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __( 'Widget Title', 'blogmarks' ), ), 'mailchimp_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Mailchimp Settings', 'blogmarks' ), ), 'mailchimp_title' => array( 'type' => 'text', 'label' => __( 'Mailchimp Title', 'blogmarks' ), ), 'desc' => array( 'type' => 'textarea', 'label' => __( 'Description', 'blogmarks' ), 'rows' => 10, ), 'form_shortcode' => array( 'type' => 'text', 'label' => __( 'MailChimp Form Shortcode', 'blogmarks' ), ), 'widget_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Widget Settings', 'blogmarks' ), ), 'style' => array( 'type' => 'select', 'label' => __( 'Style', 'blogmarks' ), 'desc' => __( 'For Inline Style, make sure to wrap each element ( like name, email, submit, etc. ) you want to display as inline, inside a "<p></p>" tag.', 'blogmarks' ), 'options' => array( 'style_1' => __( 'Default Style', 'blogmarks' ), 'style_2' => __( 'Form Items Inline', 'blogmarks' ), ), 'std' => 'style_1', ), 'mailchimp-fullwidth' => array( 'type' => 'checkbox', 'label' => __( 'Enable Fullwidth', 'blogmarks' ), 'std' => false, ), 'center_aligned_form' => array( 'type' => 'checkbox', 'label' => __( 'Center Aligned Form', 'blogmarks' ), 'std' => false, ), 'enable_bg_color' => array( 'type' => 'checkbox', 'label' => __( 'Enable Background Color', 'blogmarks' ), 'std' => false, ), 'bg_color' => array( 'type' => 'color', 'label' => __( 'Background Color', 'blogmarks' ), 'std' => '#000000', 'desc' => __( 'Will be overridden if used background image.', 'blogmarks' ), ), 'inverted_block_color' => array( 'type' => 'checkbox', 'label' => __( 'Inverted Color', 'blogmarks' ), 'desc' => __( 'Can be used if you have dark background and want lighter color on the text.', 'blogmarks' ), 'std' => false, ), 'bg_image' => array( 'type' => 'image', 'label' => __( 'Background Image', 'blogmarks' ), 'desc' => __( 'Don\'t upload any image if you do not want to show the background image.', 'blogmarks' ), ), 'enable_fixed_bg' => array( 'type' => 'checkbox', 'label' => __( 'Enable Fixed Background Image', 'blogmarks' ), 'std' => true, ), 'bg_overlay_color' => array( 'type' => 'color', 'label' => __( 'Overlay Color', 'blogmarks' ), 'std' => '#000000', ), 'overlay_opacity' => array( 'type' => 'number', 'step' => 10, 'min' => 0, 'max' => 100, 'std' => 50, 'label' => __( 'Overlay Opacity', 'blogmarks' ), ), 'height' => array( 'type' => 'number', 'step' => 1, 'min' => 150, 'max' => '', 'std' => 500, 'label' => __( 'Height (px)', 'blogmarks' ), 'desc' => __( 'Works when there is either a background color or image.', 'blogmarks' ), ), ); parent::__construct(); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); } /** * Output widget. * * @see WP_Widget * * @param array $args * @param array $instance */ public function widget( $args, $instance ) { if ( ! empty( $instance['form_shortcode'] ) ) { ob_start(); $style = ''; $class = $instance['style']; $image_enabled = false; $this->widget_start( $args, $instance ); if ( $instance['center_aligned_form'] ) { $class .= ' mailchimp-aligned-centered'; } if ( $instance['mailchimp-fullwidth'] ) { $class .= ' site-mailchimp-fullwidth'; } if ( $instance['enable_bg_color'] ) { $bg_color = isset( $instance['bg_color'] ) ? $instance['bg_color'] : $this->settings['bg_color']['std']; $style = 'background-color:' . esc_attr( $bg_color ) . ';'; } $inverted_block_color = isset( $instance['inverted_block_color'] ) ? $instance['inverted_block_color'] : $this->settings['inverted_block_color']['std']; if ( ( $instance['bg_image'] && 0 != $instance['bg_image'] ) ) { $image_enabled = true; if ( $instance['enable_fixed_bg'] ) { $class .= ' blogmarks-bg-image blogmarks-bg-attachment-fixed'; } } if ( $instance['enable_bg_color'] || $image_enabled ) { $height = isset( $instance['height'] ) ? $instance['height'] : $this->settings['height']['std']; $style .= 'min-height:' . esc_attr( $height ) . 'px;'; $class .= ' widget-has-background'; } // Inverted Color. if ( $inverted_block_color ) { $class .= ' widget-inverted-scheme'; } do_action( 'blogmarks_before_mailchimp' ); ?>
widget_end( $args ); echo ob_get_clean(); } } public function enqueue_assets() { if ( is_active_widget( false, false, $this->id_base ) ) { $file_prefix = is_rtl() ? '-rtl' : ''; $css_file = get_template_directory() . '/include/widgets/assets/mailchimp-form' . $file_prefix . '.css'; if ( file_exists( $css_file ) ) { $styles = wp_strip_all_tags( file_get_contents( $css_file ) ); wp_add_inline_style( 'blogmarks-style', $styles ); } } } }