Guest User

Untitled

a guest
Jan 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AppWidgets;
  4.  
  5. class TextWidget extends WP_Widget
  6. {
  7. public function __construct()
  8. {
  9. $widgetOpts = array(
  10. 'classname' => 'widget_text',
  11. 'description' => __('Um texto puro qualquer.'),
  12. 'customize_selective_refresh' => true,
  13. );
  14.  
  15. parent::__construct('custom_text', __('Texto puro'), $widgetOpts);
  16. }
  17.  
  18. public static function init()
  19. {
  20. add_action('widgets_init', function() {
  21. register_widget(self::class);
  22. });
  23. }
  24.  
  25. public function widget($args, $instance)
  26. {
  27. echo esc_html__($instance['content'], 'text_domain');
  28. }
  29.  
  30. public function form($instance)
  31. {
  32. $instance = wp_parse_args(
  33. (array) $instance,
  34. ['content' => '']
  35. );
  36. ?>
  37. <p>
  38. <textarea
  39. class="widefat"
  40. id="<?php echo esc_attr($this->get_field_id('content')); ?>"
  41. name="<?php echo esc_attr($this->get_field_name('content')); ?>"
  42. type="text"
  43. cols="30"
  44. rows="10"
  45. ><?php echo esc_attr($instance['content']); ?></textarea>
  46. </p>
  47. <?php
  48. }
  49.  
  50. public function update($newInstance, $oldInstance)
  51. {
  52. $instance = array();
  53.  
  54. $instance['content'] = (!empty( $newInstance['content'])) ? $oldInstance['content'] : '';
  55.  
  56. return $instance;
  57. }
  58. }
Add Comment
Please, Sign In to add comment