Example:
<?php class Icon_Fields_Widget extends WP_Widget { function __construct() { // Instantiate the parent object $widget_ops = array( 'classname' => 'widget_icon_fields_entries', 'description' => esc_attr__('Icon Field Widget - Created by deshisoft', 'eye-theme') ); $control_ops = array( 'width' => 275 ); parent::__construct( false, 'Icon Field Widget', $widget_ops, $control_ops ); } function widget( $args, $instance ) { extract( $args ); // Widget output $title = apply_filters('widget_title', $instance['title']); $icon = apply_filters('widget_icon', $instance['icon']); echo $before_widget; echo '<div style="border:1px solid #ddd; background:#f6f6f6;padding:15px;">'; echo esc_attr($title); echo esc_attr($icon); echo '</div>'; echo $after_widget; } function update( $new_instance, $old_instance ) { // Save widget options $instance = array(); $instance = $old_instance; $instance['title'] = strip_tags( $new_instance['title'] ); $instance['icon'] = strip_tags( $new_instance['icon'] ); return $instance; } function form( $instance ) { // Output admin widget options form $title = $instance['title']; $icon = $instance['icon']; ?> <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p> <?php eye_add_icons(); eye_icons_list(); wp_enqueue_style('theme-icons'); ?> <?php if($icon =='') { ?> <p><input class="icon_upload_image all-options" id="<?php echo $this->get_field_id('icon'); ?>" name="<?php echo $this->get_field_name('icon'); ?>" value="<?php echo $icon; ?>" type="hidden"> <span id="<?php echo $this->get_field_id('icon'); ?>_icon" data-class="eye_new_icon_img"></span> <input id="<?php echo $this->get_field_id('icon'); ?>_button" data-target="#<?php echo $this->get_field_id('icon'); ?>" class="eye_icon_choose_button button" value="Choose icon" type="button"> <a href="#" class="eye_remove_icon admin-icon-remove" title="Remove" style="display: none;"></a></p> <?php } else { ?> <p><input class="icon_upload_image all-options" id="<?php echo $this->get_field_id('icon'); ?>" name="<?php echo $this->get_field_name('icon'); ?>" value="<?php echo $icon; ?>" type="hidden"> <span id="<?php echo $this->get_field_id('icon'); ?>_icon" data-class="eye_new_icon_img" class="<?php echo $icon; ?>" style="display: inline;"></span> <input id="<?php echo $this->get_field_id('icon'); ?>_button" data-target="#<?php echo $this->get_field_id('icon'); ?>" class="eye_icon_choose_button button" value="Choose icon" type="button"> <a href="#" class="eye_remove_icon admin-icon-remove" title="Remove" style="display: inline;"></a></p> <?php } ?><!-- // Icon End --> <?php } } function icon_field_register_widgets() { register_widget( 'Icon_Fields_Widget' ); } add_action( 'widgets_init', 'icon_field_register_widgets' ); ?>
Theme Folder -> function.php
Add this line:
require_once('inc/icon-widget/index.php'); require get_template_directory() . '/inc/icon-widget/eye-icon-fields.php'; // inc folder name depend on your theme.