PluginProbe
Polylang / 2.8
Polylang v2.8
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 +51 -26 2.9.12.8 View file →
@@ -34,49 +34,26 @@
34 34 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
35 35 * @param array $instance The settings for the particular instance of the widget
36 36 */
37 37 public function widget( $args, $instance ) {
38 - // Sets a unique id for dropdown.
38 + // Sets a unique id for dropdown
39 39 $instance['dropdown'] = empty( $instance['dropdown'] ) ? 0 : $args['widget_id'];
40 40
41 41 if ( $list = pll_the_languages( array_merge( $instance, array( 'echo' => 0 ) ) ) ) {
42 42 $title = empty( $instance['title'] ) ? '' : $instance['title'];
43 -
44 43 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
45 44 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
46 45
47 46 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput
48 -
49 47 if ( $title ) {
50 48 echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput
51 49 }
52 -
53 - // The title may be filtered: Strip out HTML and make sure the aria-label is never empty.
54 - $aria_label = trim( wp_strip_all_tags( $title ) );
55 - if ( ! $aria_label ) {
56 - $aria_label = __( 'Choose a language', 'polylang' );
57 - }
58 -
59 50 if ( $instance['dropdown'] ) {
60 - echo '<label class="screen-reader-text" for="' . esc_attr( 'lang_choice_' . $instance['dropdown'] ) . '">' . esc_html( $aria_label ) . '</label>';
51 + echo '<label class="screen-reader-text" for="' . esc_attr( 'lang_choice_' . $instance['dropdown'] ) . '">' . esc_html__( 'Choose a language', 'polylang' ) . '</label>';
61 52 echo $list; // phpcs:ignore WordPress.Security.EscapeOutput
62 53 } else {
63 - $format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
64 -
65 - /** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */
66 - $format = apply_filters( 'navigation_widgets_format', $format );
67 -
68 - if ( 'html5' === $format ) {
69 - echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">';
70 - }
71 -
72 54 echo "<ul>\n" . $list . "</ul>\n"; // phpcs:ignore WordPress.Security.EscapeOutput
73 -
74 - if ( 'html5' === $format ) {
75 - echo '</nav>';
76 - }
77 55 }
78 -
79 56 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput
80 57 }
81 58 }
82 59
@@ -88,9 +65,9 @@
88 65 * @param array $new_instance New settings for this instance as input by the user via form()
89 66 * @param array $old_instance Old settings for this instance
90 67 * @return array Settings to save or bool false to cancel saving
91 68 */
92 - public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
69 + public function update( $new_instance, $old_instance ) {
93 70 $instance = array( 'title' => sanitize_text_field( $new_instance['title'] ) );
94 71 foreach ( array_keys( PLL_Switcher::get_switcher_options( 'widget' ) ) as $key ) {
95 72 $instance[ $key ] = ! empty( $new_instance[ $key ] ) ? 1 : 0;
96 73 }
@@ -129,6 +106,54 @@
129 106 ( ! empty( $instance['dropdown'] ) && in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? ' style="display:none;"' : '' ),
130 107 esc_attr( 'pll-' . $key )
131 108 );
132 109 }
110 +
111 + // FIXME echoing script in form is not very clean
112 + // but it does not work if enqueued properly :
113 + // clicking save on a widget makes this code unreachable for the just saved widget ( ?! )
114 + $this->admin_print_script();
115 + }
116 +
117 + /**
118 + * Add javascript to control the language switcher options
119 + *
120 + * @since 1.3
121 + */
122 + public function admin_print_script() {
123 + static $done = false;
124 +
125 + if ( $done ) {
126 + return;
127 + }
128 +
129 + $done = true;
130 + ?>
131 + <script type='text/javascript'>
132 + //<![CDATA[
133 + jQuery( document ).ready( function( $ ) {
134 + function pll_toggle( a, test ) {
135 + test ? a.show() : a.hide();
136 + }
137 +
138 + // Remove all options if dropdown is checked
139 + $( '.widgets-sortables,.control-section-sidebar' ).on( 'change', '.pll-dropdown', function() {
140 + var this_id = $( this ).parent().parent().parent().children( '.widget-id' ).attr( 'value' );
141 + pll_toggle( $( '.no-dropdown-' + this_id ), true != $( this ).prop( 'checked' ) );
142 + } );
143 +
144 + // Disallow unchecking both show names and show flags
145 + var options = ['-show_flags', '-show_names'];
146 + $.each( options, function( i, v ) {
147 + $( '.widgets-sortables,.control-section-sidebar' ).on( 'change', '.pll' + v, function() {
148 + var this_id = $( this ).parent().parent().parent().children( '.widget-id' ).attr( 'value' );
149 + if ( true != $( this ).prop( 'checked' ) ) {
150 + $( '#widget-' + this_id + options[ 1-i ] ).prop( 'checked', true );
151 + }
152 + } );
153 + } );
154 + } );
155 + //]]>
156 + </script>
157 + <?php
133 158 }
134 159 }