Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /* Create a new Widget */
  2. class WPSE180059_Widget extends WP_Widget
  3. {
  4. public function __construct() {
  5. $widget_ops = array(
  6. 'classname' => 'widget_wpse180059',
  7. 'description' => __( 'A Custom Widget')
  8. );
  9. parent::__construct('wpse180059', __('WPSE180059 Widget'), $widget_ops);
  10. }
  11.  
  12. public function widget( $args, $instance ) {
  13. $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base );
  14.  
  15. echo $args['before_widget'];
  16. if ( $title ) {
  17. echo $args['before_title'] . $title . $args['after_title'];
  18. }
  19. echo do_shortcode('[example]');
  20. echo $args['after_widget'];
  21. }
  22.  
  23. public function update( $new_instance, $old_instance ) {
  24. $instance['title'] = strip_tags($new_instance['title']);
  25. return $instance;
  26. }
  27.  
  28. public function form( $instance ) {
  29. //Defaults
  30. $title = esc_attr( $instance['title'] );
  31. ?>
  32. <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>
  33. <?php
  34. }
  35. }
  36.  
  37. /* Register your Widget */
  38. function WPSE180059_init() {
  39. register_widget('WPSE180059_Widget');
  40. }
  41. add_action('widgets_init', 'WPSE180059_init');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement