| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * A class to display a language switcher on frontend |
| 8 | 5 | * |
| @@ -15,9 +12,9 @@ | ||
| 15 | 12 | * either strings to display the options or default values |
| 16 | 13 | * |
| 17 | 14 | * @since 0.7 |
| 18 | 15 | * |
| 19 | - * @param string $type optional either 'menu', 'widget' or 'block', defaults to 'widget' | |
| 16 | + * @param string $type optional either 'menu' or 'widget', defaults to 'widget' | |
| 20 | 17 | * @param string $key optional either 'string' or 'default', defaults to 'string' |
| 21 | 18 | * @return array list of switcher options strings or default values |
| 22 | 19 | */ |
| 23 | 20 | public static function get_switcher_options( $type = 'widget', $key = 'string' ) { |
| @@ -28,8 +25,9 @@ | ||
| 28 | 25 | 'force_home' => array( 'string' => __( 'Forces link to front page', 'polylang' ), 'default' => 0 ), |
| 29 | 26 | 'hide_current' => array( 'string' => __( 'Hides the current language', 'polylang' ), 'default' => 0 ), |
| 30 | 27 | 'hide_if_no_translation' => array( 'string' => __( 'Hides languages with no translation', 'polylang' ), 'default' => 0 ), |
| 31 | 28 | ); |
| 29 | + | |
| 32 | 30 | return wp_list_pluck( $options, $key ); |
| 33 | 31 | } |
| 34 | 32 | |
| 35 | 33 | /** |
| @@ -34,9 +32,9 @@ | ||
| 34 | 32 | |
| 35 | 33 | /** |
| 36 | 34 | * Get the language elements for use in a walker |
| 37 | 35 | * |
| 38 | - * @see PLL_Switcher::the_languages() for the list of parameters accepted in $args | |
| 36 | + * @see list of parameters accepted in $args documented for PLL_Switcher::the_languages | |
| 39 | 37 | * |
| 40 | 38 | * @since 1.2 |
| 41 | 39 | * |
| 42 | 40 | * @param object $links instance of PLL_Frontend_Links |
| @@ -53,12 +51,10 @@ | ||
| 53 | 51 | $slug = $language->slug; |
| 54 | 52 | $locale = $language->get_locale( 'display' ); |
| 55 | 53 | $classes = array( 'lang-item', 'lang-item-' . $id, 'lang-item-' . esc_attr( $slug ) ); |
| 56 | 54 | $url = null; // Avoids potential notice |
| 57 | - $curlang = 0 === $args['admin_render'] ? $links->curlang->slug : $args['admin_current_lang']; | |
| 58 | - $current_lang = $curlang == $slug; | |
| 59 | 55 | |
| 60 | - if ( $current_lang ) { | |
| 56 | + if ( $current_lang = $links->curlang->slug == $slug ) { | |
| 61 | 57 | if ( $args['hide_current'] && ! ( $args['dropdown'] && ! $args['raw'] ) ) { |
| 62 | 58 | continue; // Hide current language except for dropdown |
| 63 | 59 | } else { |
| 64 | 60 | $classes[] = 'current-lang'; |
| @@ -66,9 +62,9 @@ | ||
| 66 | 62 | } |
| 67 | 63 | |
| 68 | 64 | if ( null !== $args['post_id'] && ( $tr_id = $links->model->post->get( $args['post_id'], $language ) ) && $links->model->post->current_user_can_read( $tr_id ) ) { |
| 69 | 65 | $url = get_permalink( $tr_id ); |
| 70 | - } elseif ( null === $args['post_id'] && 0 === $args['admin_render'] ) { | |
| 66 | + } elseif ( null === $args['post_id'] ) { | |
| 71 | 67 | $url = $links->get_translation_url( $language ); |
| 72 | 68 | } |
| 73 | 69 | |
| 74 | 70 | if ( $no_translation = empty( $url ) ) { |
| @@ -93,9 +89,9 @@ | ||
| 93 | 89 | |
| 94 | 90 | $url = empty( $url ) || $args['force_home'] ? $links->get_home_url( $language ) : $url; // If the page is not translated, link to the home page |
| 95 | 91 | |
| 96 | 92 | $name = $args['show_names'] || ! $args['show_flags'] || $args['raw'] ? ( 'slug' == $args['display_names_as'] ? $slug : $language->name ) : ''; |
| 97 | - $flag = $args['raw'] && ! $args['show_flags'] ? $language->get_display_flag_url() : ( $args['show_flags'] ? $language->get_display_flag() : '' ); | |
| 93 | + $flag = $args['raw'] && ! $args['show_flags'] ? $language->flag_url : ( $args['show_flags'] ? $language->flag : '' ); | |
| 98 | 94 | |
| 99 | 95 | if ( $first ) { |
| 100 | 96 | $classes[] = 'lang-item-first'; |
| 101 | 97 | $first = false; |
| @@ -124,10 +120,8 @@ | ||
| 124 | 120 | * hide_current => hide the current language if set to 1, defaults to 0 |
| 125 | 121 | * post_id => returns links to translations of post defined by post_id if set, defaults not set |
| 126 | 122 | * raw => return a raw array instead of html markup if set to 1, defaults to 0 |
| 127 | 123 | * item_spacing => whether to preserve or discard whitespace between list items, valid options are 'preserve' and 'discard', defaults to preserve |
| 128 | - * admin_render => allows to force the current language code in an admin context if set, default to 0. Need to set the admin_current_lang argument below | |
| 129 | - * admin_current_lang => the current language code in an admin context. Need to set the admin_render to 1, defaults not set | |
| 130 | 124 | * |
| 131 | 125 | * @since 0.1 |
| 132 | 126 | * |
| 133 | 127 | * @param object $links instance of PLL_Frontend_Links |
| @@ -148,10 +142,8 @@ | ||
| 148 | 142 | 'hide_current' => 0, // don't hide current language |
| 149 | 143 | 'post_id' => null, // if not null, link to translations of post defined by post_id |
| 150 | 144 | 'raw' => 0, // set this to true to build your own custom language switcher |
| 151 | 145 | 'item_spacing' => 'preserve', // 'preserve' or 'discard' whitespace between list items |
| 152 | - 'admin_render' => 0, // make the switcher in an frontend context | |
| 153 | - 'admin_current_lang' => null, // use when admin_render is set to 1, if not null use it instead of the current language | |
| 154 | 146 | ); |
| 155 | 147 | $args = wp_parse_args( $args, $defaults ); |
| 156 | 148 | |
| 157 | 149 | /** |
| @@ -176,9 +168,9 @@ | ||
| 176 | 168 | |
| 177 | 169 | if ( $args['dropdown'] ) { |
| 178 | 170 | $args['name'] = 'lang_choice_' . $args['dropdown']; |
| 179 | 171 | $walker = new PLL_Walker_Dropdown(); |
| 180 | - $args['selected'] = 0 === $args['admin_render'] ? $links->curlang->slug : $args['admin_current_lang']; | |
| 172 | + $args['selected'] = $links->curlang->slug; | |
| 181 | 173 | } |
| 182 | 174 | else { |
| 183 | 175 | $walker = new PLL_Walker_List(); |
| 184 | 176 | } |
| @@ -193,9 +185,9 @@ | ||
| 193 | 185 | */ |
| 194 | 186 | $out = apply_filters( 'pll_the_languages', $walker->walk( $elements, -1, $args ), $args ); |
| 195 | 187 | |
| 196 | 188 | // Javascript to switch the language when using a dropdown list |
| 197 | - if ( $args['dropdown'] && 0 === $args['admin_render'] ) { | |
| 189 | + if ( $args['dropdown'] ) { | |
| 198 | 190 | // Accept only few valid characters for the urls_x variable name ( as the widget id includes '-' which is invalid ) |
| 199 | 191 | $out .= sprintf( |
| 200 | 192 | '<script type="text/javascript"> |
| 201 | 193 | //<![CDATA[ |