Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AppWidgets;
- class TextWidget extends WP_Widget
- {
- public function __construct()
- {
- $widgetOpts = array(
- 'classname' => 'widget_text',
- 'description' => __('Um texto puro qualquer.'),
- 'customize_selective_refresh' => true,
- );
- parent::__construct('custom_text', __('Texto puro'), $widgetOpts);
- }
- public static function init()
- {
- add_action('widgets_init', function() {
- register_widget(self::class);
- });
- }
- public function widget($args, $instance)
- {
- echo esc_html__($instance['content'], 'text_domain');
- }
- public function form($instance)
- {
- $instance = wp_parse_args(
- (array) $instance,
- ['content' => '']
- );
- ?>
- <p>
- <textarea
- class="widefat"
- id="<?php echo esc_attr($this->get_field_id('content')); ?>"
- name="<?php echo esc_attr($this->get_field_name('content')); ?>"
- type="text"
- cols="30"
- rows="10"
- ><?php echo esc_attr($instance['content']); ?></textarea>
- </p>
- <?php
- }
- public function update($newInstance, $oldInstance)
- {
- $instance = array();
- $instance['content'] = (!empty( $newInstance['content'])) ? $oldInstance['content'] : '';
- return $instance;
- }
- }
Add Comment
Please, Sign In to add comment