widget_cssclass = 'blogmarks_address_info_widget'; $this->widget_description = __( 'Displays address and contact info', 'blogmarks' ); $this->widget_id = 'blogmarks_address_info'; $this->widget_name = __( 'Blogmarks: Address Info', 'blogmarks' ); $this->settings = array( 'title' => array( 'type' => 'text', 'label' => __( 'Title', 'blogmarks' ), ), 'desc' => array( 'type' => 'textarea', 'label' => __( 'Description', 'blogmarks' ), ), 'address' => array( 'type' => 'textarea', 'label' => __( 'Address', 'blogmarks' ), ), 'phone' => array( 'type' => 'text', 'label' => __( 'Phone', 'blogmarks' ), ), 'fax' => array( 'type' => 'text', 'label' => __( 'Fax', 'blogmarks' ), ), 'email' => array( 'type' => 'text', 'label' => __( 'Email', 'blogmarks' ), ), 'widget_settings_heading' => array( 'type' => 'heading', 'label' => __( 'Widget Settings', 'blogmarks' ), ), 'style' => array( 'type' => 'select', 'label' => __( 'Style', 'blogmarks' ), 'options' => array( 'style_1' => __( 'Stack', 'blogmarks' ), 'style_2' => __( 'Inline', 'blogmarks' ), ), 'std' => 'style_1', ), 'show_icons' => array( 'type' => 'checkbox', 'label' => __( 'Show Icons', 'blogmarks' ), 'std' => false, ), 'icon_color' => array( 'type' => 'color', 'label' => __( 'Icon Color', 'blogmarks' ), 'std' => '', ), '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, ), ); 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 ) { ob_start(); $this->widget_start( $args, $instance ); do_action( 'blogmarks_before_address_info' ); $widget_class = ''; $desc = isset( $instance['desc'] ) ? $instance['desc'] : ''; $address = isset( $instance['address'] ) ? $instance['address'] : ''; $phone = isset( $instance['phone'] ) ? $instance['phone'] : ''; $fax = isset( $instance['fax'] ) ? $instance['fax'] : ''; $email = isset( $instance['email'] ) ? $instance['email'] : ''; $show_icons = isset( $instance['show_icons'] ) ? $instance['show_icons'] : $this->settings['show_icons']['std']; $style = isset( $instance['style'] ) ? $instance['style'] : $this->settings['inverted_block_color']['std']; $inverted_block_color = isset( $instance['inverted_block_color'] ) ? $instance['inverted_block_color'] : $this->settings['inverted_block_color']['std']; $widget_class .= ' ' . $style; // Inverted Color. if ( $inverted_block_color ) { $widget_class .= ' widget-inverted-scheme'; } $widget_inline_styles = ''; $widget_id = isset( $args['widget_id'] ) ? $args['widget_id'] : ''; if ( $widget_id ) { $icon_color = isset( $instance['icon_color'] ) ? $instance['icon_color'] : $this->settings['icon_color']['std']; if ( $icon_color ) { $widget_inline_styles .= " #{$widget_id} .blogmarks-address-info-widget svg { fill:{$icon_color} !important; } "; } if ( $widget_inline_styles ) { echo ''; } } ?>
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/address-info' . $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 ); } } } }