|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* MslsWidget |
|
4
|
|
|
* @author Dennis Ploetner <[email protected]> |
|
5
|
|
|
* @since 0.9.8 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace lloc\Msls; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* The standard widget of the Multisite Language Switcher |
|
12
|
|
|
* @package Msls |
|
13
|
|
|
*/ |
|
14
|
|
|
class MslsWidget extends \WP_Widget { |
|
15
|
|
|
|
|
16
|
|
|
public $id_base = 'mslswidget'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Constructor |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct() { |
|
22
|
|
|
parent::__construct( |
|
23
|
|
|
$this->id_base, |
|
24
|
|
|
apply_filters( |
|
25
|
|
|
'msls_widget_title', |
|
26
|
|
|
__( 'Multisite Language Switcher', 'multisite-language-switcher' ) |
|
27
|
|
|
) |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Output of the widget in the frontend |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $args |
|
35
|
|
|
* @param array $instance |
|
36
|
|
|
* |
|
37
|
|
|
* @user MslsOutput |
|
38
|
|
|
*/ |
|
39
|
|
|
public function widget( $args, $instance ) { |
|
40
|
|
|
$args = wp_parse_args( |
|
41
|
|
|
$args, |
|
42
|
|
|
[ |
|
43
|
|
|
'before_widget' => '', |
|
44
|
|
|
'after_widget' => '', |
|
45
|
|
|
'before_title' => '', |
|
46
|
|
|
'after_title' => '', |
|
47
|
|
|
] |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
/** This filter is documented in wp-includes/default-widgets.php */ |
|
51
|
|
|
$title = apply_filters( |
|
52
|
|
|
'widget_title', |
|
53
|
|
|
( isset( $instance['title'] ) ? $instance['title'] : '' ), |
|
54
|
|
|
$instance, |
|
55
|
|
|
$this->id_base |
|
56
|
|
|
); |
|
57
|
|
|
if ( $title ) { |
|
58
|
|
|
$title = $args['before_title'] . esc_attr( $title ) . $args['after_title']; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$content = MslsOutput::init()->__toString(); |
|
62
|
|
|
if ( '' == $content ) { |
|
63
|
|
|
$content = apply_filters( |
|
64
|
|
|
'msls_widget_alternative_content', |
|
65
|
|
|
__( 'No available translations found', 'multisite-language-switcher' ) |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
echo $args['before_widget'], $title, $content, $args['after_widget']; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Update widget in the backend |
|
74
|
|
|
* |
|
75
|
|
|
* @param array $new_instance |
|
76
|
|
|
* @param array $old_instance |
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
public function update( $new_instance, $old_instance ) { |
|
81
|
|
|
$instance = $old_instance; |
|
82
|
|
|
|
|
83
|
|
|
if ( isset( $new_instance['title'] ) ) { |
|
84
|
|
|
$instance['title'] = strip_tags( $new_instance['title'] ); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $instance; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Display an input-form in the backend |
|
92
|
|
|
* |
|
93
|
|
|
* @param array $instance |
|
94
|
|
|
* |
|
95
|
|
|
* @codeCoverageIgnore |
|
96
|
|
|
*/ |
|
97
|
|
|
public function form( $instance ) { |
|
98
|
|
|
printf( |
|
99
|
|
|
'<p><label for="%1$s">%2$s:</label> <input class="widefat" id="%1$s" name="%3$s" type="text" value="%4$s" /></p>', |
|
100
|
|
|
$this->get_field_id( 'title' ), |
|
101
|
|
|
__( 'Title', 'multisite-language-switcher' ), |
|
102
|
|
|
$this->get_field_name( 'title' ), |
|
103
|
|
|
( isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '' ) |
|
104
|
|
|
); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|