diff --git a/modules/widgets/google-translate.php b/modules/widgets/google-translate.php index 6ed462867728f..c6f75e3738ae8 100644 --- a/modules/widgets/google-translate.php +++ b/modules/widgets/google-translate.php @@ -1,34 +1,46 @@ __( 'Automatic translation of your site content', 'jetpack' ), ) + array( 'description' => __( 'Automatic translation of your site content', 'jetpack' ) ) ); wp_register_script( 'google-translate-init', plugins_url( 'google-translate/google-translate.js', __FILE__ ) ); wp_register_script( 'google-translate', '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit', [ 'google-translate-init' ] ); } + /** + * Display the Widget. + * + * @see WP_Widget::widget() + * + * @param array $args Display arguments. + * @param array $instance The settings for the particular instance of the widget. + */ public function widget( $args, $instance ) { - // We never should show more than 1 instance of this - if ( self::$instance === null ) { + // We never should show more than 1 instance of this. + if ( null === self::$instance ) { + /** This filter is documented in core/src/wp-includes/default-widgets.php */ $title = apply_filters( 'widget_title', $instance['title'] ); echo $args['before_widget']; if ( ! empty( $title ) ) { - echo $args['before_title'] . $title . $args['after_title']; + echo $args['before_title'] . esc_html( $title ) . $args['after_title']; } wp_localize_script( 'google-translate-init', '_wp_google_translate_widget', array( lang => get_locale() ) ); wp_enqueue_script( 'google-translate-init' ); @@ -43,31 +55,50 @@ public function widget( $args, $instance ) { } } } - + + /** + * Widget form in the dashboard. + * + * @see WP_Widget::form() + * + * @param array $instance Previously saved values from database. + */ public function form( $instance ) { - if ( isset( $instance[ 'title' ] ) ) { - $title = $instance[ 'title' ]; + if ( isset( $instance['title'] ) ) { + $title = $instance['title']; } else { $title = ''; } ?>

- +

- Widgets. + */ +function jetpack_google_translate_widget_init() { register_widget( 'Google_Translate_Widget' ); } -add_action( 'widgets_init', 'load_Google_translate_widget' ); - +add_action( 'widgets_init', 'jetpack_google_translate_widget_init' );