PluginProbe
Polylang / 2.0.3
Polylang v2.0.3
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 +25 -29 2.72.0.3 View file →
@@ -11,14 +11,14 @@
11 11 * Constructor
12 12 *
13 13 * @since 0.1
14 14 */
15 - public function __construct() {
15 + function __construct() {
16 16 parent::__construct(
17 17 'polylang',
18 - __( 'Language switcher', 'polylang' ),
18 + __( 'Language Switcher', 'polylang' ),
19 19 array(
20 - 'description' => __( 'Displays a language switcher', 'polylang' ),
20 + 'description' => __( 'Displays a language switcher', 'polylang' ),
21 21 'customize_selective_refresh' => true,
22 22 )
23 23 );
24 24 }
@@ -30,9 +30,9 @@
30 30 *
31 31 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
32 32 * @param array $instance The settings for the particular instance of the widget
33 33 */
34 - public function widget( $args, $instance ) {
34 + function widget( $args, $instance ) {
35 35 // Sets a unique id for dropdown
36 36 $instance['dropdown'] = empty( $instance['dropdown'] ) ? 0 : $args['widget_id'];
37 37
38 38 if ( $list = pll_the_languages( array_merge( $instance, array( 'echo' => 0 ) ) ) ) {
@@ -39,19 +39,14 @@
39 39 $title = empty( $instance['title'] ) ? '' : $instance['title'];
40 40 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
41 41 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
42 42
43 - echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput
43 + echo $args['before_widget'];
44 44 if ( $title ) {
45 - echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput
45 + echo $args['before_title'] . $title . $args['after_title'];
46 46 }
47 - if ( $instance['dropdown'] ) {
48 - echo '<label class="screen-reader-text" for="' . esc_attr( 'lang_choice_' . $instance['dropdown'] ) . '">' . esc_html__( 'Choose a language', 'polylang' ) . '</label>';
49 - echo $list; // phpcs:ignore WordPress.Security.EscapeOutput
50 - } else {
51 - echo "<ul>\n" . $list . "</ul>\n"; // phpcs:ignore WordPress.Security.EscapeOutput
52 - }
53 - echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput
47 + echo $instance['dropdown'] ? $list : "<ul>\n" . $list . "</ul>\n";
48 + echo $args['after_widget'];
54 49 }
55 50 }
56 51
57 52 /**
@@ -62,10 +57,10 @@
62 57 * @param array $new_instance New settings for this instance as input by the user via form()
63 58 * @param array $old_instance Old settings for this instance
64 59 * @return array Settings to save or bool false to cancel saving
65 60 */
66 - public function update( $new_instance, $old_instance ) {
67 - $instance = array( 'title' => sanitize_text_field( $new_instance['title'] ) );
61 + function update( $new_instance, $old_instance ) {
62 + $instance['title'] = strip_tags( $new_instance['title'] );
68 63 foreach ( array_keys( PLL_Switcher::get_switcher_options( 'widget' ) ) as $key ) {
69 64 $instance[ $key ] = ! empty( $new_instance[ $key ] ) ? 1 : 0;
70 65 }
71 66
@@ -78,9 +73,9 @@
78 73 * @since 0.4
79 74 *
80 75 * @param array $instance Current settings
81 76 */
82 - public function form( $instance ) {
77 + function form( $instance ) {
83 78 // Default values
84 79 $instance = wp_parse_args( (array) $instance, array_merge( array( 'title' => '' ), PLL_Switcher::get_switcher_options( 'widget', 'default' ) ) );
85 80
86 81 // Title
@@ -85,27 +80,30 @@
85 80
86 81 // Title
87 82 printf(
88 83 '<p><label for="%1$s">%2$s</label><input class="widefat" id="%1$s" name="%3$s" type="text" value="%4$s" /></p>',
89 - esc_attr( $this->get_field_id( 'title' ) ),
84 + $this->get_field_id( 'title' ),
90 85 esc_html__( 'Title:', 'polylang' ),
91 - esc_attr( $this->get_field_name( 'title' ) ),
86 + $this->get_field_name( 'title' ),
92 87 esc_attr( $instance['title'] )
93 88 );
94 89
90 + $fields = '';
95 91 foreach ( PLL_Switcher::get_switcher_options( 'widget' ) as $key => $str ) {
96 - printf(
92 + $fields .= sprintf(
97 93 '<div%5$s%6$s><input type="checkbox" class="checkbox %7$s" id="%1$s" name="%2$s"%3$s /><label for="%1$s">%4$s</label></div>',
98 - esc_attr( $this->get_field_id( $key ) ),
99 - esc_attr( $this->get_field_name( $key ) ),
100 - checked( $instance[ $key ], true, false ),
94 + $this->get_field_id( $key ),
95 + $this->get_field_name( $key ),
96 + $instance[ $key ] ? ' checked="checked"' : '',
101 97 esc_html( $str ),
102 - in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? sprintf( ' class="no-dropdown-%s"', esc_attr( $this->id ) ) : '',
103 - ( ! empty( $instance['dropdown'] ) && in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? ' style="display:none;"' : '' ),
104 - esc_attr( 'pll-' . $key )
98 + in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? ' class="no-dropdown-' . $this->id . '"' : '',
99 + ! empty( $instance['dropdown'] ) && in_array( $key, array( 'show_names', 'show_flags', 'hide_current' ) ) ? ' style="display:none;"' : '',
100 + 'pll-' . $key
105 101 );
106 102 }
107 103
104 + echo $fields;
105 +
108 106 // FIXME echoing script in form is not very clean
109 107 // but it does not work if enqueued properly :
110 108 // clicking save on a widget makes this code unreachable for the just saved widget ( ?! )
111 109 $this->admin_print_script();
@@ -122,10 +120,9 @@
122 120 if ( $done ) {
123 121 return;
124 122 }
125 123
126 - $done = true;
127 - ?>
124 + $done = true; ?>
128 125 <script type='text/javascript'>
129 126 //<![CDATA[
130 127 jQuery( document ).ready( function( $ ) {
131 128 function pll_toggle( a, test ) {
@@ -149,8 +146,7 @@
149 146 } );
150 147 } );
151 148 } );
152 149 //]]>
153 - </script>
154 - <?php
150 + </script><?php
155 151 }
156 152 }