Browse Source

Generate fallback menu (fix #44). (#45)

pull/49/head
Ned Zimmerman 7 years ago committed by GitHub
parent
commit
5084eb4195
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      header.php
  2. 46
      inc/filters/namespace.php
  3. 69
      inc/helpers/namespace.php

1
header.php

@ -68,6 +68,7 @@
<a class="header__nav-icon js-header-nav-toggle" href="#navigation"><?php _e( 'Toggle Menu', 'pressbooks-book' ); ?><span class="header__nav-icon__icon"></span></a>
<?php wp_nav_menu( [
'theme_location' => 'primary-menu',
'fallback_cb' => '\Aldine\Helpers\default_menu',
'container' => 'nav',
'container_class' => 'js-header-nav',
'container_id' => 'navigation',

46
inc/filters/namespace.php

@ -106,51 +106,7 @@ function add_blocks( $init_array ) {
function adjust_menu( $items, $args ) {
if ( $args->theme_location === 'primary-menu' ) {
if ( ! is_front_page() ) {
$items = sprintf(
'<li><a href="%1$s">%2$s</a></li>',
'/',
__( 'Home', 'pressbooks-aldine' )
) . $items;
}
if ( get_option( 'pb_network_contact_form' ) ) {
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
'#contact',
__( 'Contact', 'pressbooks-aldine' )
);
}
if ( ! is_user_logged_in() ) {
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
wp_login_url( get_permalink() ),
__( 'Sign In', 'pressbooks-aldine' )
);
if ( in_array( get_site_option( 'registration' ), [ 'user', 'all' ], true ) ) {
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
network_home_url( '/wp-signup.php' ),
__( 'Sign Up', 'pressbooks-aldine' )
);
}
} else {
if ( is_super_admin() || is_user_member_of_blog() ) {
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
admin_url(),
__( 'Admin', 'pressbooks-aldine' )
);
}
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
wp_logout_url( get_permalink() ),
__( 'Sign Out', 'pressbooks-aldine' )
);
}
/* @codingStandardsIgnoreStart $items .= sprintf(
'<li class="header__search js-search"><div class="header__search__form">%s</div></li>',
get_search_form( false )
); @codingStandardsIgnoreEnd */
return \Aldine\Helpers\get_default_menu( $items );
}
return $items;

69
inc/helpers/namespace.php

@ -64,6 +64,75 @@ function get_catalog_licenses() {
return [];
}
/**
* Return the default (non-page) menu items.
*
* @param string $items
* @return string $items
*/
function get_default_menu( $items = '' ) {
if ( ! is_front_page() ) {
$items = sprintf(
'<li><a href="%1$s">%2$s</a></li>',
'/',
__( 'Home', 'pressbooks-aldine' )
) . $items;
}
if ( get_option( 'pb_network_contact_form' ) ) {
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
'#contact',
__( 'Contact', 'pressbooks-aldine' )
);
}
if ( ! is_user_logged_in() ) {
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
wp_login_url( get_permalink() ),
__( 'Sign In', 'pressbooks-aldine' )
);
if ( in_array( get_site_option( 'registration' ), [ 'user', 'all' ], true ) ) {
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
network_home_url( '/wp-signup.php' ),
__( 'Sign Up', 'pressbooks-aldine' )
);
}
} else {
if ( is_super_admin() || is_user_member_of_blog() ) {
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
admin_url(),
__( 'Admin', 'pressbooks-aldine' )
);
}
$items .= sprintf(
'<li><a href="%1$s">%2$s</a></li>',
wp_logout_url( get_permalink() ),
__( 'Sign Out', 'pressbooks-aldine' )
);
}
/* @codingStandardsIgnoreStart $items .= sprintf(
'<li class="header__search js-search"><div class="header__search__form">%s</div></li>',
get_search_form( false )
); @codingStandardsIgnoreEnd */
return $items;
}
/**
* Echo the default menu.
*
* @param string $items
* @return null
*/
function default_menu( $args = [], $items = '' ) {
printf(
"<{$args['container']} id='{$args['container_id']}' class='{$args['container_class']}'><ul id='{$args['menu_id']}' class='{$args['menu_class']}'>%s</ul></{$args['container']}>",
get_default_menu( $items )
);
}
/**
*
* Handler for contact form submissions.

Loading…
Cancel
Save