PluginProbe
Polylang / 0.4.1
Polylang v0.4.1
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.1, at include/widget.php

82 lines 3.1 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 $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
15
16 echo "$before_widget\n";
17 if ($title)
18 echo $before_title . $title . $after_title;
19 do_action('the_languages', $instance);
20 echo "$after_widget\n";
21
22 // javascript to switch the language when using a dropdown list
23 // keep the things simple for now as we switch to the posts page
24 if ($dropdown) {
25 $url = home_url('?lang=');
26 $js = "
27 <script type='text/javascript'>
28 var d = document.getElementById('lang_choice');
29 d.onchange = function() {location.href ='$url'+this.value;}
30 </script>";
31
32 echo $js;
33 }
34 }
35
36 // updates the widget options
37 function update( $new_instance, $old_instance ) {
38 $instance = $old_instance;
39 $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'show_names' => 1, 'show_flags' => 0, 'dropdown' => 0) ); // default values
40 $instance['title'] = strip_tags($new_instance['title']);
41 $instance['show_names'] = !empty($new_instance['show_names']) ? 1 : 0;
42 $instance['show_flags'] = !empty($new_instance['show_flags']) ? 1 : 0;
43 $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
44
45 return $instance;
46 }
47
48 // displays the widget form
49 function form($instance) {
50 $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'show_names' => 1, 'show_flags' => 0, 'dropdown' => 0) ); // default values
51
52 // title
53 $id = $this->get_field_id('title');
54 $name = $this->get_field_name('title');
55 $title = sprintf('<p><label for="%s">%s</label><input class="widefat" id="%s" name="%s" type="text" value="%s" /></p>',
56 $id, __('Title:'), $id, $name, esc_attr($instance['title']));
57
58 // language names checkbox
59 $id = $this->get_field_id('show_names');
60 $name = $this->get_field_name('show_names');
61 $fields = sprintf('<input type="checkbox" class="checkbox" id="%s" name="%s"%s /> <label for="%s">%s</label><br />',
62 $id, $name, $instance['show_names'] ? 'checked="checked"' : '', $id, __('Display language names', 'polylang'));
63
64 // flags checkbox
65 $id = $this->get_field_id('show_flags');
66 $name = $this->get_field_name('show_flags');
67 $fields .= sprintf('<input type="checkbox" class="checkbox" id="%s" name="%s"%s /> <label for="%s">%s</label><br />',
68 $id, $name, $instance['show_flags'] ? 'checked="checked"' : '', $id, __('Display flags', 'polylang'));
69
70 // dropdown checkbox
71 $id = $this->get_field_id('dropdown');
72 $name = $this->get_field_name('dropdown');
73 $fields .= sprintf('<input type="checkbox" class="checkbox" id="%s" name="%s"%s /> <label for="%s">%s</label><br />',
74 $id, $name, $instance['dropdown'] ? 'checked="checked"' : '', $id, __('Display as dropdown', 'polylang'));
75
76 echo $title.'<p>'.$fields.'</p>';
77 }
78
79 } // Class Polylang_Widget
80
81 ?>
82