summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/widgets/google-translate.php')
-rw-r--r--plugins/jetpack/modules/widgets/google-translate.php46
1 files changed, 32 insertions, 14 deletions
diff --git a/plugins/jetpack/modules/widgets/google-translate.php b/plugins/jetpack/modules/widgets/google-translate.php
index 0e270677..d6f0e88d 100644
--- a/plugins/jetpack/modules/widgets/google-translate.php
+++ b/plugins/jetpack/modules/widgets/google-translate.php
@@ -1,4 +1,4 @@
-<?php
+<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use Automattic\Jetpack\Assets;
@@ -15,20 +15,28 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
+/**
+ * Jetpack_Google_Translate_Widget main class.
+ */
class Jetpack_Google_Translate_Widget extends WP_Widget {
- static $instance = null;
+ /**
+ * Singleton instance of the widget, not to show more than once.
+ *
+ * @var array
+ */
+ public static $instance = null;
/**
* Default widget title.
*
* @var string $default_title
*/
- var $default_title;
+ public $default_title;
/**
* Register widget with WordPress.
*/
- function __construct() {
+ public function __construct() {
parent::__construct(
'google_translate_widget',
/** This filter is documented in modules/widgets/facebook-likebox.php */
@@ -52,13 +60,22 @@ class Jetpack_Google_Translate_Widget extends WP_Widget {
Assets::get_file_url_for_environment(
'_inc/build/widgets/google-translate/google-translate.min.js',
'modules/widgets/google-translate/google-translate.js'
- )
+ ),
+ array(),
+ JETPACK__VERSION,
+ false
+ );
+ wp_register_script(
+ 'google-translate',
+ '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit',
+ array( 'google-translate-init' ),
+ JETPACK__VERSION,
+ false
);
- wp_register_script( 'google-translate', '//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit', array( 'google-translate-init' ) );
// Admin bar is also displayed on top of the site which causes google translate bar to hide beneath.
// Overwrite position of body.admin-bar
// This is a hack to show google translate bar a bit lower.
- $lowerTranslateBar = '
+ $lower_translate_bar = '
.admin-bar {
position: inherit !important;
top: auto !important;
@@ -77,8 +94,8 @@ class Jetpack_Google_Translate_Widget extends WP_Widget {
}
}
';
- wp_add_inline_style( 'admin-bar', $lowerTranslateBar );
- wp_add_inline_style( 'wpcom-admin-bar', $lowerTranslateBar );
+ wp_add_inline_style( 'admin-bar', $lower_translate_bar );
+ wp_add_inline_style( 'wpcom-admin-bar', $lower_translate_bar );
}
/**
@@ -93,7 +110,8 @@ class Jetpack_Google_Translate_Widget extends WP_Widget {
// We never should show more than 1 instance of this.
if ( null === self::$instance ) {
$instance = wp_parse_args(
- $instance, array(
+ $instance,
+ array(
'title' => $this->default_title,
)
);
@@ -144,12 +162,12 @@ class Jetpack_Google_Translate_Widget extends WP_Widget {
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', $title );
- echo $args['before_widget'];
+ echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
if ( ! empty( $title ) ) {
echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
echo '<div id="google_translate_element"></div>';
- echo $args['after_widget'];
+ echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
self::$instance = $instance;
/** This action is documented in modules/widgets/gravatar-profile.php */
do_action( 'jetpack_stats_extra', 'widget_view', 'google-translate' );
@@ -186,11 +204,11 @@ class Jetpack_Google_Translate_Widget extends WP_Widget {
*
* @return array $instance Updated safe values to be saved.
*/
- public function update( $new_instance, $old_instance ) {
+ public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
$instance = array();
$instance['title'] = wp_kses( $new_instance['title'], array() );
if ( $instance['title'] === $this->default_title ) {
- $instance['title'] = false; // Store as false in case of language change
+ $instance['title'] = false; // Store as false in case of language change.
}
return $instance;
}