Example #1
0
function pll_the_languages($args = '')
{
    if (PLL_ADMIN) {
        return '';
    }
    $switcher = new PLL_Switcher();
    return $switcher->the_languages(PLL()->links, $args);
}
Example #2
0
/**
 * Template tag: displays the language switcher
 *
 * List of parameters accepted in $args:
 *
 * dropdown               => displays a dropdown if set to 1, defaults to 0
 * echo                   => echoes the the switcher if set to 1 ( default )
 * hide_if_empty          => hides languages with no posts ( or pages ) if set to 1 ( default )
 * show_flags             => shows flags if set to 1, defaults to 0
 * show_names             => shows languages names if set to 1 ( default )
 * display_names_as       => whether to display the language name or code. valid options are 'slug' and 'name'
 * force_home             => forces linking to the home page is set to 1, defaults to 0
 * hide_if_no_translation => hides the link if there is no translation if set to 1, defaults to 0
 * hide_current           => hides the current language if set to 1, defaults to 0
 * post_id                => if not null, link to translations of post defined by post_id, defaults to null
 * raw                    => set this to true to build your own custom language switcher, defaults to 0
 *
 * @since 0.5
 *
 * @param array $args optional
 * @return null|string|array null if displaying, array if raw is requested, string otherwise
 */
function pll_the_languages($args = '')
{
    if (PLL() instanceof PLL_Frontend) {
        $switcher = new PLL_Switcher();
        return $switcher->the_languages(PLL()->links, $args);
    }
    return '';
}
Example #3
0
function pll_the_languages($args = '')
{
    global $polylang;
    if ($polylang instanceof PLL_Frontend && !empty($polylang->links)) {
        $switcher = new PLL_Switcher();
        return $switcher->the_languages($polylang->links, $args);
    }
    return '';
}
 /**
  * Splits the one item of backend in several items on frontend
  * take care to menu_order as it is used later in wp_nav_menu
  *
  * @since 1.1.1
  *
  * @param array $items menu items
  * @return array modified items
  */
 public function wp_get_nav_menu_items($items)
 {
     if (doing_action('customize_register')) {
         // needed since WP 4.3, doing_action available since WP 3.9
         return $items;
     }
     // The customizer menus does not sort the items and we need them to be sorted before splitting the language switcher
     usort($items, array($this, 'usort_menu_items'));
     $new_items = array();
     $offset = 0;
     foreach ($items as $key => $item) {
         if ($options = get_post_meta($item->ID, '_pll_menu_item', true)) {
             $i = 0;
             $switcher = new PLL_Switcher();
             $args = array_merge(array('raw' => 1), $options);
             $the_languages = $switcher->the_languages(PLL()->links, $args);
             // parent item for dropdown
             if (!empty($options['dropdown'])) {
                 $item->title = $options['show_flags'] && $options['show_names'] ? $this->curlang->flag . ' ' . esc_html($this->curlang->name) : ($options['show_flags'] ? $this->curlang->flag : esc_html($this->curlang->name));
                 $item->url = '';
                 $item->classes = array('pll-parent-menu-item');
                 $new_items[] = $item;
                 $offset++;
             }
             foreach ($the_languages as $lang) {
                 $lang_item = clone $item;
                 $lang_item->ID = $lang_item->ID . '-' . $lang['slug'];
                 // A unique ID
                 $lang_item->title = $options['show_flags'] && $options['show_names'] ? $lang['flag'] . '<span style="margin-left:0.3em;">' . esc_html($lang['name']) . '</span>' : ($options['show_flags'] ? $lang['flag'] : esc_html($lang['name']));
                 $lang_item->url = $lang['url'];
                 $lang_item->lang = $lang['locale'];
                 // Save this for use in nav_menu_link_attributes
                 $lang_item->classes = $lang['classes'];
                 $lang_item->menu_order += $offset + $i++;
                 if (!empty($options['dropdown'])) {
                     $lang_item->menu_item_parent = $item->db_id;
                     $lang_item->db_id = 0;
                     // to avoid recursion
                 }
                 $new_items[] = $lang_item;
             }
             $offset += $i - 1;
         } else {
             $item->menu_order += $offset;
             $new_items[] = $item;
         }
     }
     return $new_items;
 }
Example #5
0
 public function wp_get_nav_menu_items($items)
 {
     if (doing_action('customize_register')) {
         // needed since WP 4.3, doing_action available since WP 3.9
         return $items;
     }
     // the customizer menus does not sort the items and we need them to be sorted before splitting the language switcher
     usort($items, array($this, 'usort_menu_items'));
     $new_items = array();
     $offset = 0;
     foreach ($items as $key => $item) {
         if ($options = get_post_meta($item->ID, '_pll_menu_item', true)) {
             $i = 0;
             $switcher = new PLL_Switcher();
             $args = array_merge(array('raw' => 1), $options);
             $the_languages = $switcher->the_languages(PLL()->links, $args);
             foreach ($the_languages as $lang) {
                 $lang_item = clone $item;
                 $lang_item->ID = $lang_item->ID . '-' . $lang['slug'];
                 // a unique ID
                 $lang_item->title = $options['show_flags'] && $options['show_names'] ? $lang['flag'] . '&nbsp;' . esc_html($lang['name']) : ($options['show_flags'] ? $lang['flag'] : esc_html($lang['name']));
                 $lang_item->url = $lang['url'];
                 $lang_item->lang = $lang['locale'];
                 // save this for use in nav_menu_link_attributes
                 $lang_item->classes = $lang['classes'];
                 $lang_item->menu_order += $offset + $i++;
                 $new_items[] = $lang_item;
             }
             $offset += $i - 1;
         } else {
             $item->menu_order += $offset;
             $new_items[] = $item;
         }
     }
     return $new_items;
 }
 /**
  * @return string Menu HTML.
  */
 public function alternate_versions_menu()
 {
     global $polylang;
     $wpml_selector = $this->wpml_language_selector_html();
     if ($wpml_selector) {
         return $wpml_selector;
     }
     if (!class_exists('PLL_Switcher')) {
         return '';
     }
     $switcher = new PLL_Switcher();
     $languages = $switcher->the_languages($polylang->links, array('post_id' => $this->post->ID, 'echo' => false, 'hide_if_no_translation' => true, 'hide_current' => true));
     return empty($languages) ? '' : html('ul class="alternate-languages"', $languages);
 }