PluginProbe
Polylang / 0.4
Polylang v0.4
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
polylang / include / widget.php

widget.php in Polylang 0.4, at include/widget.php

70 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Polylang_Widget extends WP_Widget {
4 function __construct() {
5 $widget_ops = array( 'description' => __( 'Displays a language switcher', 'polylang') );
6 parent::__construct('polylang', __('Language Switcher', 'polylang'), $widget_ops);
7 }
8
9 // displays the widget
10 function widget($args, $instance) {
11 extract($args);
12 extract($instance);
13
14 echo "$before_widget\n";
15 do_action('the_languages', $instance);
16 echo "$after_widget\n";
17
18 // javascript to switch the language when using a dropdown list
19 // keep the things simple for now as we switch to the posts page
20 if ($dropdown) {
21 $url = home_url('?lang=');
22 $js = "
23 <script type='text/javascript'>
24 var d = document.getElementById('lang_choice');
25 d.onchange = function() {location.href ='$url'+this.value;}
26 </script>";
27
28 echo $js;
29 }
30 }
31
32 // updates the widget options
33 function update( $new_instance, $old_instance ) {
34 $instance = $old_instance;
35 $instance['show_names'] = !empty($new_instance['show_names']) ? 1 : 0;
36 $instance['show_flags'] = !empty($new_instance['show_flags']) ? 1 : 0;
37 $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
38
39 return $instance;
40 }
41
42 // displays the widget form
43 function form($instance) {
44 $instance = wp_parse_args( (array) $instance, array( 'show_names' => 1, 'show_flags' => 0, 'dropdown' => 0) ); // default values
45
46 // language names checkbox
47 $id = $this->get_field_id('show_names');
48 $name = $this->get_field_name('show_names');
49 $output = sprintf('<input type="checkbox" class="checkbox" id="%s" name="%s"%s /> <label for="%s">%s</label><br />',
50 $id, $name, $instance['show_names'] ? 'checked="checked"' : '', $id, __('Display language names', 'polylang'));
51
52 // flags checkbox
53 $id = $this->get_field_id('show_flags');
54 $name = $this->get_field_name('show_flags');
55 $output .= sprintf('<input type="checkbox" class="checkbox" id="%s" name="%s"%s /> <label for="%s">%s</label><br />',
56 $id, $name, $instance['show_flags'] ? 'checked="checked"' : '', $id, __('Display flags', 'polylang'));
57
58 // dropdown checkbox
59 $id = $this->get_field_id('dropdown');
60 $name = $this->get_field_name('dropdown');
61 $output .= sprintf('<input type="checkbox" class="checkbox" id="%s" name="%s"%s /> <label for="%s">%s</label><br />',
62 $id, $name, $instance['dropdown'] ? 'checked="checked"' : '', $id, __('Display as dropdown', 'polylang'));
63
64 echo '<p>'.$output.'</p>';
65 }
66
67 } // Class Polylang_Widget
68
69 ?>
70