| 1 |
<?php |
| 2 |
|
| 3 |
/* Language Switcher Widget */ |
| 4 |
|
| 5 |
add_action( 'widgets_init', 'bogo_widgets_init' ); |
| 6 |
|
| 7 |
function bogo_widgets_init() { |
| 8 |
register_widget( 'Bogo_Widget_Language_Switcher' ); |
| 9 |
} |
| 10 |
|
| 11 |
class Bogo_Widget_Language_Switcher extends WP_Widget { |
| 12 |
|
| 13 |
function __construct() { |
| 14 |
$widget_ops = array( |
| 15 |
'description' => __( 'Language switcher widget by Bogo plugin', 'bogo' ) ); |
| 16 |
|
| 17 |
$control_ops = array(); |
| 18 |
|
| 19 |
WP_Widget::__construct( 'bogo_language_switcher', |
| 20 |
__( 'Language Switcher', 'bogo' ), |
| 21 |
$widget_ops, $control_ops ); |
| 22 |
} |
| 23 |
|
| 24 |
function widget( $args, $instance ) { |
| 25 |
extract( $args ); |
| 26 |
|
| 27 |
$title = apply_filters( 'widget_title', |
| 28 |
empty( $instance['title'] ) ? __( 'Language Switcher', 'bogo' ) : $instance['title'], |
| 29 |
$instance, $this->id_base ); |
| 30 |
|
| 31 |
echo $before_widget; |
| 32 |
|
| 33 |
if ( $title ) |
| 34 |
echo $before_title . $title . $after_title; |
| 35 |
|
| 36 |
echo bogo_language_switcher(); |
| 37 |
|
| 38 |
echo $after_widget; |
| 39 |
} |
| 40 |
|
| 41 |
function form( $instance ) { |
| 42 |
$instance = wp_parse_args( (array) $instance, array( 'title' => '' ) ); |
| 43 |
$title = strip_tags( $instance['title'] ); |
| 44 |
|
| 45 |
echo '<p><label for="' . $this->get_field_id( 'title' ) . '">' . esc_html( __( 'Title:', 'bogo' ) ) . '</label> <input class="widefat" id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" type="text" value="' . esc_attr( $title ) . '" /></p>'; |
| 46 |
} |
| 47 |
|
| 48 |
function update( $new_instance, $old_instance ) { |
| 49 |
$instance = $old_instance; |
| 50 |
$new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '' ) ); |
| 51 |
$instance['title'] = strip_tags( $new_instance['title'] ); |
| 52 |
|
| 53 |
return $instance; |
| 54 |
} |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
/* Locale Option */ |
| 59 |
|
| 60 |
add_filter( 'widget_display_callback', 'bogo_widget_display_callback', 10, 3 ); |
| 61 |
|
| 62 |
function bogo_widget_display_callback( $instance, $widget, $args ) { |
| 63 |
if ( isset( $instance['bogo_locales'] ) ) { |
| 64 |
$locale = get_locale(); |
| 65 |
|
| 66 |
if ( ! in_array( $locale, (array) $instance['bogo_locales'] ) ) |
| 67 |
$instance = false; |
| 68 |
} |
| 69 |
|
| 70 |
return $instance; |
| 71 |
} |
| 72 |
|
| 73 |
?> |