PluginProbe
Bogo / 2.6
Bogo v2.6
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
← All changes | includes/link-template.php +103 -0 2.72.6 View file →
@@ -186,8 +186,111 @@
186 186 }
187 187 }
188 188 }
189 189
190 +function bogo_language_switcher( $args = '' ) {
191 + $args = wp_parse_args( $args, array(
192 + 'echo' => false ) );
193 +
194 + $links = bogo_language_switcher_links( $args );
195 + $total = count( $links );
196 + $count = 0;
197 +
198 + $output = '';
199 +
200 + foreach ( $links as $link ) {
201 + $count += 1;
202 + $class = array();
203 + $class[] = bogo_language_tag( $link['locale'] );
204 + $class[] = bogo_lang_slug( $link['locale'] );
205 +
206 + if ( get_locale() == $link['locale'] ) {
207 + $class[] = 'current';
208 + }
209 +
210 + if ( 1 == $count ) {
211 + $class[] = 'first';
212 + }
213 +
214 + if ( $total == $count ) {
215 + $class[] = 'last';
216 + }
217 +
218 + $class = implode( ' ', array_unique( $class ) );
219 +
220 + $label = $link['native_name'] ? $link['native_name'] : $link['title'];
221 + $title = $link['title'];
222 +
223 + if ( empty( $link['href'] ) ) {
224 + $li = esc_html( $label );
225 + } else {
226 + $li = sprintf(
227 + '<a rel="alternate" hreflang="%1$s" href="%2$s" title="%3$s">%4$s</a>',
228 + $link['lang'],
229 + esc_url( $link['href'] ),
230 + esc_attr( $title ),
231 + esc_html( $label ) );
232 + }
233 +
234 + $li = sprintf( '<li class="%1$s">%2$s</li>', $class, $li );
235 +
236 + $output .= $li . "\n";
237 + }
238 +
239 + $output = '<ul class="bogo-language-switcher">' . $output . '</ul>' . "\n";
240 +
241 + $output = apply_filters( 'bogo_language_switcher', $output, $args );
242 +
243 + if ( $args['echo'] ) {
244 + echo $output;
245 + } else {
246 + return $output;
247 + }
248 +}
249 +
250 +function bogo_language_switcher_links( $args = '' ) {
251 + global $wp_query;
252 +
253 + $args = wp_parse_args( $args, array() );
254 +
255 + $locale = get_locale();
256 + $available_languages = bogo_available_languages( array(
257 + 'exclude_enus_if_inactive' => true ) );
258 +
259 + $translations = array();
260 + $is_singular = false;
261 +
262 + if ( is_singular() || ! empty( $wp_query->is_posts_page ) ) {
263 + $translations = bogo_get_post_translations( get_queried_object_id() );
264 + $is_singular = true;
265 + }
266 +
267 + $links = array();
268 +
269 + foreach ( $available_languages as $code => $name ) {
270 + $link = array(
271 + 'locale' => $code,
272 + 'lang' => bogo_language_tag( $code ),
273 + 'title' => $name,
274 + 'native_name' => bogo_get_language_native_name( $code ),
275 + 'href' => '' );
276 +
277 + if ( $is_singular ) {
278 + if ( $locale != $code && ! empty( $translations[$code] ) ) {
279 + $link['href'] = get_permalink( $translations[$code] );
280 + }
281 + } else {
282 + if ( $locale != $code ) {
283 + $link['href'] = bogo_url( null, $code );
284 + }
285 + }
286 +
287 + $links[] = $link;
288 + }
289 +
290 + return apply_filters( 'bogo_language_switcher_links', $links, $args );
291 +}
292 +
190 293 add_filter( 'get_previous_post_join', 'bogo_adjacent_post_join', 10, 3 );
191 294 add_filter( 'get_next_post_join', 'bogo_adjacent_post_join', 10, 3 );
192 295
193 296 function bogo_adjacent_post_join( $join, $in_same_term, $excluded_terms ) {