├── README.md └── my-widget-plugin.php /README.md: -------------------------------------------------------------------------------- 1 | # My Widget Plugin 2 | 3 | Full code from the WPExplorer.com tutorial: [How To Create A Widget Plugin For WordPress](http://www.wpexplorer.com/create-widget-plugin-wordpress/) -------------------------------------------------------------------------------- /my-widget-plugin.php: -------------------------------------------------------------------------------- 1 | true, 22 | ) 23 | ); 24 | } 25 | 26 | // The widget form (for the backend ) 27 | public function form( $instance ) { 28 | 29 | // Set widget defaults 30 | $defaults = array( 31 | 'title' => '', 32 | 'text' => '', 33 | 'textarea' => '', 34 | 'checkbox' => '', 35 | 'select' => '', 36 | ); 37 | 38 | // Parse current settings with defaults 39 | extract( wp_parse_args( ( array ) $instance, $defaults ) ); ?> 40 | 41 | 42 |
43 | 44 | 45 |
46 | 47 | 48 |49 | 50 | 51 |
52 | 53 | 54 |55 | 56 | 57 |
58 | 59 | 60 |61 | /> 62 | 63 |
64 | 65 | 66 |67 | 68 | 84 |
85 | 86 | '; 116 | 117 | // Display widget title if defined 118 | if ( $title ) { 119 | echo $before_title . $title . $after_title; 120 | } 121 | 122 | // Display text field 123 | if ( $text ) { 124 | echo '' . $text . '
'; 125 | } 126 | 127 | // Display textarea field 128 | if ( $textarea ) { 129 | echo '' . $textarea . '
'; 130 | } 131 | 132 | // Display select field 133 | if ( $select ) { 134 | echo '' . $select . '
'; 135 | } 136 | 137 | // Display something if checkbox is true 138 | if ( $checkbox ) { 139 | echo 'Something awesome
'; 140 | } 141 | 142 | echo ''; 143 | 144 | // WordPress core after_widget hook (always include ) 145 | echo $after_widget; 146 | 147 | } 148 | 149 | } 150 | 151 | // Register the widget 152 | function my_register_custom_widget() { 153 | register_widget( 'My_Custom_Widget' ); 154 | } 155 | add_action( 'widgets_init', 'my_register_custom_widget' ); --------------------------------------------------------------------------------