google-language-translator
Last commit date
css
11 years ago
images
11 years ago
js
11 years ago
google-language-translator.php
11 years ago
readme.txt
11 years ago
widget.php
11 years ago
widget.php
51 lines
| 1 | <?php |
| 2 | |
| 3 | class glt_widget extends WP_Widget { |
| 4 | |
| 5 | function __construct() { |
| 6 | parent::__construct( |
| 7 | 'glt_widget', // Base ID |
| 8 | __('Google Language Translator', 'text_domain'), // Name |
| 9 | array( 'description' => __( 'Add the Google Language Translator website tool.', 'text_domain' ), ) |
| 10 | ); |
| 11 | } |
| 12 | |
| 13 | public function widget( $args, $instance ) { |
| 14 | $title = apply_filters( 'widget_title', $instance['title'] ); |
| 15 | echo $args['before_widget']; |
| 16 | if ( ! empty( $title ) ) |
| 17 | echo $args['before_title'] . $title . $args['after_title']; |
| 18 | $google_language_translator_class = new google_language_translator(); |
| 19 | $glt_shortcode = $google_language_translator_class->google_translator_shortcode(); |
| 20 | echo $glt_shortcode; |
| 21 | echo $args['after_widget']; |
| 22 | } |
| 23 | |
| 24 | public function form( $instance ) { |
| 25 | if ( isset( $instance[ 'title' ] ) ) { |
| 26 | $title = $instance[ 'title' ]; |
| 27 | } |
| 28 | else { |
| 29 | $title = __( 'Translate:', 'text_domain' ); |
| 30 | } |
| 31 | ?> |
| 32 | <p> |
| 33 | <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> |
| 34 | <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 ); ?>"> |
| 35 | </p> |
| 36 | <?php |
| 37 | } |
| 38 | |
| 39 | public function update( $new_instance, $old_instance ) { |
| 40 | $instance = array(); |
| 41 | $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; |
| 42 | |
| 43 | return $instance; |
| 44 | } |
| 45 | |
| 46 | } // class glt_widget |
| 47 | |
| 48 | function register_foo_widget() { |
| 49 | register_widget( 'glt_widget' ); |
| 50 | } |
| 51 | add_action( 'widgets_init', 'register_foo_widget' ); |