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 +91 -65 2.32.6 View file →
@@ -148,32 +148,24 @@
148 148 function bogo_m17n_headers() {
149 149 $languages = array();
150 150
151 151 if ( is_singular() ) {
152 - if ( ! $post_id = get_queried_object_id() ) {
153 - return;
154 - }
152 + $post_id = get_queried_object_id();
155 153
156 - if ( ! $translations = bogo_get_post_translations( $post_id ) ) {
157 - return;
158 - }
154 + if ( $post_id && $translations = bogo_get_post_translations( $post_id ) ) {
155 + $locale = get_locale();
156 + $translations[$locale] = get_post( $post_id );
159 157
160 - $locale = get_locale();
161 - $translations[$locale] = get_post( $post_id );
162 -
163 - foreach ( $translations as $lang => $translation ) {
164 - $languages[] = array(
165 - 'hreflang' => bogo_language_tag( $lang ),
166 - 'href' => get_permalink( $translation ) );
158 + foreach ( $translations as $lang => $translation ) {
159 + $languages[] = array(
160 + 'hreflang' => bogo_language_tag( $lang ),
161 + 'href' => get_permalink( $translation ) );
162 + }
167 163 }
168 -
169 164 } else {
170 - $available_locales = bogo_available_locales();
165 + $available_locales = bogo_available_locales( array(
166 + 'exclude_enus_if_inactive' => true ) );
171 167
172 - if ( count( $available_locales ) < 2 ) {
173 - return;
174 - }
175 -
176 168 foreach ( $available_locales as $locale ) {
177 169 $languages[] = array(
178 170 'hreflang' => bogo_language_tag( $locale ),
179 171 'href' => bogo_url( null, $locale ) );
@@ -179,49 +171,40 @@
179 171 'href' => bogo_url( null, $locale ) );
180 172 }
181 173 }
182 174
183 - if ( ! $languages ) {
184 - return;
185 - }
175 + $languages = apply_filters( 'bogo_rel_alternate_hreflang', $languages );
186 176
187 - foreach ( $languages as $language ) {
188 - echo '<link rel="alternate" hreflang="' . esc_attr( $language['hreflang'] ) . '" href="' . esc_url( $language['href'] ) . '" />' . "\n";
177 + foreach ( (array) $languages as $language ) {
178 + $hreflang = isset( $language['hreflang'] ) ? $language['hreflang'] : '';
179 + $href = isset( $language['href'] ) ? $language['href'] : '';
180 +
181 + if ( $hreflang && $href ) {
182 + $link = sprintf( '<link rel="alternate" hreflang="%1$s" href="%2$s" />',
183 + esc_attr( $hreflang ), esc_url( $href ) );
184 +
185 + echo $link . "\n";
186 + }
189 187 }
190 188 }
191 189
192 190 function bogo_language_switcher( $args = '' ) {
193 - global $wp_query;
191 + $args = wp_parse_args( $args, array(
192 + 'echo' => false ) );
194 193
195 - $defaults = array(
196 - 'echo' => false );
194 + $links = bogo_language_switcher_links( $args );
195 + $total = count( $links );
196 + $count = 0;
197 197
198 - $args = wp_parse_args( $args, $defaults );
198 + $output = '';
199 199
200 - $locale = get_locale();
201 - $available_languages = bogo_available_languages();
202 -
203 - $translations = array();
204 - $is_singular = false;
205 - $post_id = get_queried_object_id();
206 -
207 - if ( is_singular() || ! empty( $wp_query->is_posts_page ) ) {
208 - $translations = bogo_get_post_translations( $post_id );
209 - $is_singular = true;
210 - }
211 -
212 - $output = '<ul class="bogo-language-switcher">';
213 -
214 - $total = count( $available_languages );
215 - $count = 0;
216 -
217 - foreach ( $available_languages as $code => $name ) {
200 + foreach ( $links as $link ) {
218 201 $count += 1;
219 202 $class = array();
220 - $class[] = bogo_language_tag( $code );
221 - $class[] = bogo_lang_slug( $code );
203 + $class[] = bogo_language_tag( $link['locale'] );
204 + $class[] = bogo_lang_slug( $link['locale'] );
222 205
223 - if ( $locale == $code ) {
206 + if ( get_locale() == $link['locale'] ) {
224 207 $class[] = 'current';
225 208 }
226 209
227 210 if ( 1 == $count ) {
@@ -233,29 +216,31 @@
233 216 }
234 217
235 218 $class = implode( ' ', array_unique( $class ) );
236 219
237 - $output .= '<li class="' . esc_attr( $class ) . '">';
220 + $label = $link['native_name'] ? $link['native_name'] : $link['title'];
221 + $title = $link['title'];
238 222
239 - if ( $is_singular ) {
240 - if ( empty( $translations[$code] ) || $locale == $code ) {
241 - $output .= esc_html( $name );
242 - } else {
243 - $output .= '<a rel="alternate" hreflang="' . bogo_language_tag( $code ) . '" href="' . get_permalink( $translations[$code] ) . '">' . esc_html( $name ) . '</a>';
244 - }
223 + if ( empty( $link['href'] ) ) {
224 + $li = esc_html( $label );
245 225 } else {
246 - if ( $locale == $code ) {
247 - $output .= esc_html( $name );
248 - } else {
249 - $output .= '<a rel="alternate" hreflang="' . bogo_language_tag( $code ) . '" href="' . esc_url( bogo_url( null, $code ) ) . '">' . esc_html( $name ) . '</a>';
250 - }
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 ) );
251 232 }
252 233
253 - $output .= '</li>';
234 + $li = sprintf( '<li class="%1$s">%2$s</li>', $class, $li );
235 +
236 + $output .= $li . "\n";
254 237 }
255 238
256 - $output .= '</ul>' . "\n";
239 + $output = '<ul class="bogo-language-switcher">' . $output . '</ul>' . "\n";
257 240
241 + $output = apply_filters( 'bogo_language_switcher', $output, $args );
242 +
258 243 if ( $args['echo'] ) {
259 244 echo $output;
260 245 } else {
261 246 return $output;
@@ -261,8 +246,51 @@
261 246 return $output;
262 247 }
263 248 }
264 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 +
265 293 add_filter( 'get_previous_post_join', 'bogo_adjacent_post_join', 10, 3 );
266 294 add_filter( 'get_next_post_join', 'bogo_adjacent_post_join', 10, 3 );
267 295
268 296 function bogo_adjacent_post_join( $join, $in_same_term, $excluded_terms ) {
@@ -299,6 +327,4 @@
299 327 }
300 328
301 329 return $where;
302 330 }
303 -
304 -?>