class WPML_LS_Widget extends WP_Widget {
const SLUG = 'icl_lang_sel_widget';
const ANCHOR_BASE = '#sidebars/';
public function __construct() {
__( 'Language Switcher', 'sitepress' ),
'description' => __( 'Language Switcher', 'sitepress' ),
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts_action' ) );
public static function register() {
register_widget( __CLASS__ );
public function admin_enqueue_scripts_action( $hook ) {
if ( 'widgets.php' === $hook ) {
$suffix = $sitepress->get_wp_api()->constant( 'SCRIPT_DEBUG' ) ? '' : '.min';
wp_enqueue_script( 'wpml-widgets', ICL_PLUGIN_URL . '/res/js/widgets' . $suffix . '.js', array( 'jquery' ) );
public function widget( $args, $instance ) {
global $wpml_language_switcher;
$sidebar = isset( $args['id'] ) ? $args['id'] : '';
$slot = $wpml_language_switcher->get_slot( 'sidebars', $sidebar );
if ( ! $slot instanceof WPML_LS_Sidebar_Slot ) {
$instanceSlot = Obj::prop( 'slot', $instance );
$slot = $instanceSlot instanceof WPML_LS_Sidebar_Slot ? $instanceSlot : $slot;
$ret = $wpml_language_switcher->render( $slot );
if ( $slot->get( 'widget_title' ) ) {
remove_filter( 'widget_title', 'icl_sw_filters_widget_title', 0 );
$ret = $args['before_title'] . apply_filters( 'widget_title', $slot->get( 'widget_title' ) )