Advertisement
rakeshr

custom widget code template with comments - important

Aug 25th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3. /*
  4. Plugin Name: Custom Widget
  5. Plugin URI: http://wpguru.in
  6. Description: Custom Widget..
  7. Author: Rakesh Raja
  8. Version: 1.6
  9. Author URI: http://wpguru.in
  10. */
  11.  
  12. /*main widget class starts here*/
  13. class wpg_textwidget extends WP_Widget {
  14.    
  15.  
  16. /*construct widget /display it */
  17.     function __construct()
  18.     {
  19.         $params = array(
  20.         'description' => 'Simple Text Widget',
  21.         'name' => 'WPG Text Widget'
  22.         );
  23.        
  24.         parent:: __construct('wpg_textwidget', '', $params);
  25.     } /* construct of widget ends here */
  26.    
  27.     /*widget form starts here*/
  28.     public function form($instance)
  29.     {
  30.         extract($instance);
  31.        
  32.          ?>
  33.  
  34.             <p>
  35.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"> Title: </label>
  36.             <input  type="text" class="widefat"
  37.                 id="<?php echo $this->get_field_id( 'title' ); ?>"
  38.                 name="<?php echo $this->get_field_name( 'title' ); ?>"
  39.                 value="<?php if( isset($title) ) echo esc_attr($title); ?>"  />
  40.        
  41.             <label for="<?php echo $this->get_field_id( 'info' ); ?>"> Info: </label>
  42.             <textarea  class="widefat"
  43.                 id="<?php echo $this->get_field_id( 'info' ); ?>"
  44.                 name="<?php echo $this->get_field_name( 'info' ); ?>" ><?php if( isset($info) ) echo esc_attr($info); ?>
  45.             </textarea>      
  46.        
  47. <?php
  48.     } /*  widget form ends here */
  49.     /* this print widget on theme page */
  50.     public function widget($args, $instance)
  51.     {
  52.         extract($args);
  53.         extract($instance);
  54.        
  55.         echo $before_widget;
  56.             echo $before_title . $title . $after_title;
  57.             echo $info;
  58.         echo $after_widget;
  59.        
  60.     }/* print widget ends here */
  61.  
  62.  
  63. } /*end if main widget class*/
  64.  
  65. add_action('widgets_init', 'wpg_register_wpgtextwidget');
  66. function wpg_register_wpgtextwidget()
  67. {
  68. register_widget('wpg_textwidget'); 
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement