__('A widget that shows Text with Icon', 'encrypted-lite') ) ); } /** * Helper function that holds widget fields * Array is used in update and form functions */ private function widget_fields() { $style = array( 'style1' => 'Style 1', 'style2' => 'Style 2', 'style3' => 'Style 3', 'style4' => 'Style 4', ); $fields = array( // This widget has no title // Other fields 'icon_text_title' => array( 'encrypted_lite_widgets_name' => 'icon_text_title', 'encrypted_lite_widgets_title' => __('Title', 'encrypted-lite'), 'encrypted_lite_widgets_field_type' => 'text', ), 'icon_text_content' => array( 'encrypted_lite_widgets_name' => 'icon_text_content', 'encrypted_lite_widgets_title' => __('Content', 'encrypted-lite'), 'encrypted_lite_widgets_field_type' => 'textarea', 'encrypted_lite_widgets_row' => '6' ), 'icon_text_icon' => array( 'encrypted_lite_widgets_name' => 'icon_text_icon', 'encrypted_lite_widgets_title' => __('Icon', 'encrypted-lite'), 'encrypted_lite_widgets_field_type' => 'icon', ), 'icon_text_readmore' => array( 'encrypted_lite_widgets_name' => 'icon_text_readmore', 'encrypted_lite_widgets_title' => __('Read More Text', 'encrypted-lite'), 'encrypted_lite_widgets_desc' => __('Leave Empty not to show', 'encrypted-lite'), 'encrypted_lite_widgets_field_type' => 'text', ), 'icon_text_readmore_link' => array( 'encrypted_lite_widgets_name' => 'icon_text_readmore_link', 'encrypted_lite_widgets_title' => __('Read More Link', 'encrypted-lite'), 'encrypted_lite_widgets_field_type' => 'url', ), 'icon_text_style' => array( 'encrypted_lite_widgets_name' => 'icon_text_style', 'encrypted_lite_widgets_title' => __('Style', 'encrypted-lite'), 'encrypted_lite_widgets_field_type' => 'select', 'encrypted_lite_widgets_field_options' => $style ), ); return $fields; } /** * Front-end display of widget. * * @see WP_Widget::widget() * * @param array $args Widget arguments. * @param array $instance Saved values from database. */ public function widget($args, $instance) { extract($args); $icon_text_title = $instance['icon_text_title']; $icon_text_content = $instance['icon_text_content']; $icon_text_icon = $instance['icon_text_icon']; $icon_text_readmore = $instance['icon_text_readmore']; $icon_text_readmore_link = $instance['icon_text_readmore_link']; $icon_text_style = $instance['icon_text_style']; echo $before_widget; ?>
widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { extract($widget_field); // Use helper function to get updated field values $instance[$encrypted_lite_widgets_name] = encrypted_lite_widgets_updated_field_value($widget_field, $new_instance[$encrypted_lite_widgets_name]); } return $instance; } /** * Back-end widget form. * * @see WP_Widget::form() * * @param array $instance Previously saved values from database. * * @uses encrypted_lite_widgets_show_widget_field() defined in widget-fields.php */ public function form($instance) { $widget_fields = $this->widget_fields(); // Loop through fields foreach ($widget_fields as $widget_field) { // Make array elements available as variables extract($widget_field); $encrypted_lite_widgets_field_value = !empty($instance[$encrypted_lite_widgets_name]) ? esc_attr($instance[$encrypted_lite_widgets_name]) : ''; encrypted_lite_widgets_show_widget_field($this, $widget_field, $encrypted_lite_widgets_field_value); } } }