WordPress is an amazing CMS with a couple of features Widgets are the one of them . So today i am going to explain how to create a wordpress widget plugin .

A wordpress widget consists of four major things .
1) constructor : This will initialize the widget . It is the part which defines the name of the widget .
2 form(): is the function which contains the form at the admin end .
3) pdate(): function to save the content in the form .As WordPress core developers added a really powerful widgets API, we only need to add this code to update each field
4)Widget(): function to display the saved content in the front end . This function can be customize with css and html tags according to the theme or requirements
To create a wordpress plugin we need to insert the predefined set of code in the plugins main file . Which contains the information about your plugin .

/*
Plugin Name: my widget
Plugin URI: http://www.codingbin.com/
Description: A simple plugin that adds a simple widget
Version: 1.0
Author: codingbin
Author URI: http://www.codingbin.com/
License: GPL2
*/

create a class to initialize your widget like .

class mywidget extends WP_Widget {

	// constructor
    function mywidget() {
        parent::WP_Widget(false, 'my widget' );
    }
    // widget form creation
    function form($instance) {
       // your logic
    }
    // update widget
    function update($new_instance, $old_instance) {
     // your logic here 
    }
   // display widget
   function widget($args, $instance) {
     // logic
   }
}

// register widget
add_action('widgets_init', create_function('', 'return register_widget("mywidget");'));

Create a function form(). to create a form in the admin section like given below

// widget form creation
	function form($instance) {

	// Check values
	if( $instance) {
		 $title = esc_attr($instance['title']);
		 $select = esc_attr($instance['select']);
		 $textarea = esc_textarea($instance['textarea']);
	} else {
		 $title = '';
		 $select = '';
		 $textarea = '';
	}
	?>

	<p>
	<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'mywidget'); ?></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>

	<p>
	<label for="<?php echo $this->get_field_id('textarea'); ?>"><?php _e('Textarea:', 'mywidget'); ?></label>
	<textarea class="widefat" id="<?php echo $this->get_field_id('textarea'); ?>" name="<?php echo $this->get_field_name('textarea'); ?>"><?php echo $textarea; ?></textarea>
	</p>
	
	<p>
	<label for="<?php echo $this->get_field_id('select'); ?>"><?php _e('Dropdown:', 'mywidget'); ?></label>
	<select name="<?php echo $this->get_field_name('select'); ?>" id="<?php echo $this->get_field_id('select'); ?>" class="widefat">
		<option value="1">Option 1</option>
		<option value="2">Option 2</option>
		<option value="3">Option 3</option>
	</select>
	</p>
	<?php
	}

this code will create a widget in the admin section with a form containing a text field , a textarea and a dropdown list . Now we need to save the content . so create a function widget() like given below.

function update($new_instance, $old_instance) 
{
	$instance = $old_instance;
	// Fields
	$instance['title'] = strip_tags($new_instance['title']);
	$instance['select'] = strip_tags($new_instance['select']);
	$instance['textarea'] = strip_tags($new_instance['textarea']);
	return $instance;
}

this function will save the values of your widget form . and now you can display the fields with widget() function

function widget($args, $instance) {
	   extract( $args );
	   // these are the widget options
	   $title = apply_filters('widget_title', $instance['title']);
	   $select = $instance['select'];
	   $textarea = $instance['textarea'];
	   echo $before_widget;
	   // Display the widget
	   echo '<div class="widget-text wp_widget_plugin_box">';

	   // Check if title is set
	   if ( $title ) {
		  echo $before_title . $title . $after_title;
	   }

	   // Check if select is set
	   if( $select ) {
		  echo '<p class="wp_widget_plugin_text">'.$select.'</p>';
	   }
	   // Check if textarea is set
	   if( $textarea ) {
		 echo '<p class="wp_widget_plugin_textarea">'.$textarea.'</p>';
	   }
	   echo '</div>';
	   echo $after_widget;
	}
http://codingbin.com/wp-content/uploads/2015/12/Untitled-1-copy2.jpghttp://codingbin.com/wp-content/uploads/2015/12/Untitled-1-copy2-150x150.jpgdevidcmsWordPresswidget,wordpressWordPress is an amazing CMS with a couple of features Widgets are the one of them . So today i am going to explain how to create a wordpress widget plugin . A wordpress widget consists of four major things . 1) constructor : This will initialize the widget...coding, php, wordpress, yii, cakephp, and  jquery

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request