1 | <?php |
||
12 | class Google_Translate_Widget extends WP_Widget { |
||
13 | static $instance = null; |
||
|
|||
14 | |||
15 | /** |
||
16 | * Register widget with WordPress. |
||
17 | */ |
||
18 | function __construct() { |
||
28 | |||
29 | /** |
||
30 | * Display the Widget. |
||
31 | * |
||
32 | * @see WP_Widget::widget() |
||
33 | * |
||
34 | * @param array $args Display arguments. |
||
35 | * @param array $instance The settings for the particular instance of the widget. |
||
36 | */ |
||
37 | public function widget( $args, $instance ) { |
||
38 | // We never should show more than 1 instance of this. |
||
39 | if ( null === self::$instance ) { |
||
40 | /** This filter is documented in core/src/wp-includes/default-widgets.php */ |
||
41 | $title = apply_filters( 'widget_title', $instance['title'] ); |
||
42 | echo $args['before_widget']; |
||
43 | if ( ! empty( $title ) ) { |
||
44 | echo $args['before_title'] . esc_html( $title ) . $args['after_title']; |
||
45 | } |
||
46 | wp_localize_script( 'google-translate-init', '_wp_google_translate_widget', array( 'lang' => get_locale() ) ); |
||
47 | wp_enqueue_script( 'google-translate-init' ); |
||
48 | wp_enqueue_script( 'google-translate' ); |
||
49 | echo '<div id="google_translate_element"></div>'; |
||
50 | echo $args['after_widget']; |
||
51 | self::$instance = $instance; |
||
52 | // Admin bar is also displayed on top of the site which causes google translate bar to hide beneath. |
||
53 | // This is a hack to show google translate bar a bit lower. |
||
54 | if ( is_admin_bar_showing() ) { |
||
55 | echo '<style>.goog-te-banner-frame { top:32px !important } </style>'; |
||
56 | } |
||
57 | /** This action is documented in modules/widgets/gravatar-profile.php */ |
||
58 | do_action( 'jetpack_stats_extra', 'widget_view', 'google-translate' ); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Widget form in the dashboard. |
||
64 | * |
||
65 | * @see WP_Widget::form() |
||
66 | * |
||
67 | * @param array $instance Previously saved values from database. |
||
68 | */ |
||
69 | public function form( $instance ) { |
||
82 | |||
83 | /** |
||
84 | * Sanitize widget form values as they are saved. |
||
85 | * |
||
86 | * @see WP_Widget::update() |
||
87 | * |
||
88 | * @param array $new_instance Values just sent to be saved. |
||
89 | * @param array $old_instance Previously saved values from database. |
||
90 | * |
||
91 | * @return array $instance Updated safe values to be saved. |
||
92 | */ |
||
93 | public function update( $new_instance, $old_instance ) { |
||
98 | |||
99 | } |
||
100 | |||
108 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.