Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class my_test_Widget extends WP_Widget {
- public function __construct() {
- parent::__construct(
- 'my_test_widget', // Base ID
- 'my test Widget', // Name
- array( 'description' => 'This is a test widget.')
- );
- }
- public function widget( $args, $instance ) {
- $title = apply_filters( 'widget_title', $instance['title'] );
- $textarea = apply_filters( 'widget_textarea', empty( $instance['textarea'] ) ? '' : $instance['textarea'], $instance );
- echo $args['before_widget'];
- echo'<div id="my-test" class="text-center">';
- if ( !empty( $textarea ) ) {
- echo'<div class="page-caption text-center"><h3>' . $textarea . '</h3></div>';
- }
- echo'</div>';
- echo $args['after_widget'];
- }
- public function form( $instance ) {
- $title = ! empty( $instance['title'] ) ? $instance['title'] : '';
- $textarea = ! empty( $instance['textarea'] ) ? $instance['textarea'] : '';
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>">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 esc_attr( $title ); ?>">
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'textarea' ); ?>">Textarea:</label>
- <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>
- </p>
- <?php
- }
- public function update( $new_instance, $old_instance ) {
- $instance = array();
- $instance['title'] = ( !empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
- $instance['textarea'] = ( !empty( $new_instance['textarea'] ) ) ? strip_tags( $new_instance['textarea'] ) : '';
- return $instance;
- }
- }
- add_action( 'widgets_init', function(){
- register_widget( 'my_test_Widget' );
- });
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement