Skip to content

Instantly share code, notes, and snippets.

@jmslbam
Forked from thefuxia/mlp_navigation_with_login.php
Last active February 11, 2016 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmslbam/c2d9240e76654cd27481 to your computer and use it in GitHub Desktop.
Save jmslbam/c2d9240e76654cd27481 to your computer and use it in GitHub Desktop.
function mlp_navigation_with_login()
<?php
// copy from here
/**
* Create a navigation like: DE | EN | RU | Log in
*
* @return string
*/
function mlp_navigation_with_login()
{
$linked = (array) mlp_get_interlinked_permalinks();
$items = $login = array ();
$links[] = array (
'permalink' => '',
'lang' => mlp_get_current_blog_language()
);
$links = array_merge( $links, $linked );
// add log in/out link
if ( ! is_user_logged_in() ) {
$login['permalink'] = wp_login_url( $_SERVER['REQUEST_URI'] );
$login['text'] = __( 'Log in' );
}
else {
$login['permalink'] = wp_logout_url( $_SERVER['REQUEST_URI'] );
$login['text'] = __( 'Log out' );
}
$links[] = $login;
// format the items
foreach ( $links as $link ) {
// log in/out
if ( isset ( $link['text'] ) )
$text = $link['text'];
else
$text = strtoupper( strtok( $link['lang'], '_' ) );
$hreflang = '';
if ( ! empty ( $link['lang'] ) )
$hreflang = 'hreflang="' . esc_attr( $link['lang'] ) . '"';
$items[] = sprintf(
'<a href="%1$s" rel="nofollow" %2$s>%3$s</a>',
esc_url( $link['permalink'] ),
$hreflang,
$text
);
}
return '<p class="lang-login-nav">' . join( ' | ', $items ) . '</p>';
}
@jmslbam
Copy link
Author

jmslbam commented Feb 11, 2016

Gives an notice if the linked permalinks array $links is empty. If you array merge these 2 array it doesn't have an empty array in the loop.
See https://gist.github.com/jmslbam/c2d9240e76654cd27481/revisions#diff-6a0f70159046c3eb1bd4a4a7b317eed4L12

Thanks btw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment