PluginProbe
Polylang / 3.7.7
Polylang v3.7.7
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/widget-languages.php +45 -5 2.93.7.7 View file →
@@ -6,8 +6,19 @@
6 6 /**
7 7 * The language switcher widget
8 8 *
9 9 * @since 0.1
10 + *
11 + * @extends WP_Widget<T>
12 + * @phpstan-template T of array{
13 + * title: string,
14 + * dropdown: 0|1,
15 + * show_names: 0|1,
16 + * show_flags: 0|1,
17 + * force_home: 0|1,
18 + * hide_current: 0|1,
19 + * hide_if_no_translation: 0|1
20 + * }
10 21 */
11 22 class PLL_Widget_Languages extends WP_Widget {
12 23
13 24 /**
@@ -32,14 +43,35 @@
32 43 * @since 0.1
33 44 *
34 45 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
35 46 * @param array $instance The settings for the particular instance of the widget
47 + * @return void
48 + *
49 + * @phpstan-param array{
50 + * name: string,
51 + * id: string,
52 + * description: string,
53 + * class: string,
54 + * before_widget: string,
55 + * after_widget: string,
56 + * before_title: string,
57 + * after_title: string,
58 + * before_sidebar: string,
59 + * after_sidebar: string,
60 + * show_in_rest: boolean,
61 + * widget_id: string,
62 + * widget_name: string
63 + * } $args
64 + * @phpstan-param T $instance
36 65 */
37 66 public function widget( $args, $instance ) {
38 67 // Sets a unique id for dropdown.
39 - $instance['dropdown'] = empty( $instance['dropdown'] ) ? 0 : $args['widget_id'];
68 + $instance['dropdown'] = empty( $instance['dropdown'] ) ? 0 : $this->id;
69 + $instance['echo'] = 0;
70 + $instance['raw'] = 0;
71 + $list = pll_the_languages( $instance );
40 72
41 - if ( $list = pll_the_languages( array_merge( $instance, array( 'echo' => 0 ) ) ) ) {
73 + if ( $list ) {
42 74 $title = empty( $instance['title'] ) ? '' : $instance['title'];
43 75
44 76 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
45 77 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
@@ -65,9 +97,9 @@
65 97 /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */
66 98 $format = apply_filters( 'navigation_widgets_format', $format );
67 99
68 100 if ( 'html5' === $format ) {
69 - echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">';
101 + echo '<nav aria-label="' . esc_attr( $aria_label ) . '">';
70 102 }
71 103
72 104 echo "<ul>\n" . $list . "</ul>\n"; // phpcs:ignore WordPress.Security.EscapeOutput
73 105
@@ -87,8 +119,11 @@
87 119 *
88 120 * @param array $new_instance New settings for this instance as input by the user via form()
89 121 * @param array $old_instance Old settings for this instance
90 122 * @return array Settings to save or bool false to cancel saving
123 + *
124 + * @phpstan-param T $new_instance
125 + * @phpstan-param T $old_instance
91 126 */
92 127 public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
93 128 $instance = array( 'title' => sanitize_text_field( $new_instance['title'] ) );
94 129 foreach ( array_keys( PLL_Switcher::get_switcher_options( 'widget' ) ) as $key ) {
@@ -98,13 +133,16 @@
98 133 return $instance;
99 134 }
100 135
101 136 /**
102 - * Displays the widget form
137 + * Displays the widget form.
103 138 *
104 139 * @since 0.4
105 140 *
106 - * @param array $instance Current settings
141 + * @param array $instance Current settings.
142 + * @return string
143 + *
144 + * @phpstan-param T $instance
107 145 */
108 146 public function form( $instance ) {
109 147 // Default values
110 148 $instance = wp_parse_args( (array) $instance, array_merge( array( 'title' => '' ), PLL_Switcher::get_switcher_options( 'widget', 'default' ) ) );
@@ -129,6 +167,8 @@
129 167 ( ! empty( $instance['dropdown'] ) && in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? ' style="display:none;"' : '' ),
130 168 esc_attr( 'pll-' . $key )
131 169 );
132 170 }
171 +
172 + return ''; // Because the parent class returns a string, however not used.
133 173 }
134 174 }