Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php
  2. class my_test_Widget extends WP_Widget {
  3.  
  4. public function __construct() {
  5. parent::__construct(
  6. 'my_test_widget', // Base ID
  7. 'my test Widget', // Name
  8. array( 'description' => 'This is a test widget.')
  9. );
  10. }
  11.  
  12. public function widget( $args, $instance ) {
  13.  
  14. $title = apply_filters( 'widget_title', $instance['title'] );
  15. $textarea = apply_filters( 'widget_textarea', empty( $instance['textarea'] ) ? '' : $instance['textarea'], $instance );
  16.  
  17. echo $args['before_widget'];
  18.  
  19. echo'<div id="my-test" class="text-center">';
  20. if ( !empty( $textarea ) ) {
  21. echo'<div class="page-caption text-center"><h3>' . $textarea . '</h3></div>';
  22. }
  23. echo'</div>';
  24.  
  25. echo $args['after_widget'];
  26. }
  27.  
  28. public function form( $instance ) {
  29.  
  30. $title = ! empty( $instance['title'] ) ? $instance['title'] : '';
  31. $textarea = ! empty( $instance['textarea'] ) ? $instance['textarea'] : '';
  32.  
  33. ?>
  34. <p>
  35. <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
  36. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
  37. </p>
  38. <p>
  39. <label for="<?php echo $this->get_field_id( 'textarea' ); ?>">Textarea:</label>
  40. <textarea class="widefat" id="<?php echo $this->get_field_id( 'textarea' ); ?>" name="<?php echo $this->get_field_name( 'textarea' ); ?>" rows="10" cols="20" value="<?php echo $textarea; ?>"></textarea>
  41. </p>
  42.  
  43. <?php
  44. }
  45.  
  46. public function update( $new_instance, $old_instance ) {
  47. $instance = array();
  48. $instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  49. $instance['textarea'] = ( !empty( $new_instance['textarea'] ) ) ? strip_tags( $new_instance['textarea'] ) : '';
  50.  
  51. return $instance;
  52. }
  53. }
  54.  
  55. add_action( 'widgets_init', function(){
  56. register_widget( 'my_test_Widget' );
  57. });
  58.  
  59. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement