Skip to content

Commit

Permalink
Re-add customizer menu shortcuts (godaddy-wordpress#240)
Browse files Browse the repository at this point in the history
* Remove custom styling for u-informational in header.

* Add a fallback to every wp_nav_menu call.

* Update how wp_nav_menu is called with the new fallback

* Update shared-style.css

* phpcs
  • Loading branch information
richtabor authored Aug 19, 2019
1 parent 864d932 commit 5837601
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 117 deletions.
15 changes: 9 additions & 6 deletions .dev/assets/shared/css/shared-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@
@import url("gravity/radio.css");
@import url("gravity/button.css");

/* Everything below here still needs organizing */
.u-informational {
background-color: hsla(var(--theme-feedback-informational-color), 0.1);
border: 1px solid hsla(var(--theme-feedback-informational-color), 1);
color: hsla(var(--theme-feedback-informational-color), 1);
line-height: 2;
padding: 0 0.5em;
}

.hero-center-center-align .wp-block-coblocks-hero__box {
margin: 0 auto;
}
Expand Down Expand Up @@ -261,12 +270,6 @@ strong {
padding-right: var(--theme-block-padding-x);
}

.u-informational {
background-color: hsla(var(--theme-feedback-informational-color), 0.1);
border: 1px solid hsla(var(--theme-feedback-informational-color), 1);
color: hsla(var(--theme-feedback-informational-color), 1);
}

@media (--small) {

.sm\:flex {
Expand Down
59 changes: 59 additions & 0 deletions includes/customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ function setup() {
add_action( 'customize_preview_init', $n( 'customize_preview_init' ) );
add_action( 'customize_controls_enqueue_scripts', $n( 'customize_preview_init' ) );
add_action( 'customize_preview_init', $n( 'enqueue_controls_assets' ) );

add_action( 'wp_head', $n( 'inline_css' ) );
add_action( 'wp_nav_menu_args', $n( 'wp_nav_register_fallback' ) );
}


Expand All @@ -51,6 +53,63 @@ function register_control_types( \WP_Customize_Manager $wp_customize ) {
$wp_customize->register_control_type( Range_Control::class );
}

/**
* Display a placeholder in the customizer if a menu has not been assigned,
*
* @param array $args Array of nav menu arguments.
*/
function wp_nav_fallback( $args ) {
if ( ! is_customize_preview() ) {
return;
}

$registered_nav_menus = get_registered_nav_menus();

$menu_slug = $args['theme_location'];
$instance_id = $args['customize_preview_nav_menus_args']['args_hmac'];
$attributes = '';

$attrs = array(
'data-customize-partial-id' => 'nav_menu_instance[' . esc_attr( $instance_id ) . ']',
'data-customize-partial-type' => 'nav_menu_instance',
'data-customize-partial-placement-context' => esc_attr( wp_json_encode( $args['customize_preview_nav_menus_args'] ) ),
);

$attributes = implode(
' ',
array_map(
function( $key, $value ) {
return sprintf( '%s="%s"', $key, esc_attr( $value ) );
},
array_keys( $attrs ),
$attrs
)
);
?>
<p class="u-informational" <?php echo $attributes; // phpcs:ignore ?> id="menu-primary-navigation">
<?php
echo esc_html(
sprintf(
// translators: %s is the registered nav menu name
__( 'Please assign a menu to the %s menu location', 'maverick' ),
$registered_nav_menus[ $menu_slug ]
)
);
?>
</p>
<?php
}

/**
* Filter the arguments used to display a navigation menu to add our own fallback callback.
*
* @param array $args Array of wp_nav_menu() arguments.
*/
function wp_nav_register_fallback( $args ) {
$args['fallback_cb'] = __NAMESPACE__ . '\\wp_nav_fallback';
return $args;
}

/**
* Tweaks the default customizer controls.
*
Expand Down
6 changes: 2 additions & 4 deletions partials/footers/footer-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<?php Maverick\social_icons( [ 'class' => 'social-icons list-reset' ] ); ?>

<?php if ( has_nav_menu( 'footer-1' ) ) { ?>
<?php if ( has_nav_menu( 'footer-1' ) || is_customize_preview() ) : ?>
<nav class="footer-navigation" aria-label="<?php esc_attr_e( 'Footer Menu', 'maverick' ); ?>">
<?php
wp_nav_menu(
Expand All @@ -26,9 +26,7 @@
);
?>
</nav>
<?php } elseif ( is_customize_preview() ) { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a menu to the Footer Menu #1', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>

<?php Maverick\copyright( [ 'class' => 'site-info text-sm mb-0' ] ); ?>

Expand Down
6 changes: 2 additions & 4 deletions partials/footers/footer-2.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div class="site-footer__inner flex flex-column lg:flex-row lg:flex-wrap items-center align-center max-w-wide m-auto px-1">

<?php if ( has_nav_menu( 'footer-1' ) ) { ?>
<?php if ( has_nav_menu( 'footer-1' ) || is_customize_preview() ) : ?>
<nav class="footer-navigation text-sm" aria-label="<?php esc_attr_e( 'Footer Menu', 'maverick' ); ?>">
<?php
wp_nav_menu(
Expand All @@ -24,9 +24,7 @@
);
?>
</nav>
<?php } elseif ( is_customize_preview() ) { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a menu to the Footer Menu #1', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>

<?php Maverick\social_icons( [ 'class' => 'social-icons list-reset' ] ); ?>

Expand Down
18 changes: 6 additions & 12 deletions partials/footers/footer-3.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<?php Maverick\display_site_branding( array( 'description' => false ) ); ?>

<?php if ( has_nav_menu( 'footer-1' ) ) { ?>
<?php if ( has_nav_menu( 'footer-1' ) || is_customize_preview() ) : ?>
<nav class="footer-navigation footer-navigation--1 text-sm" aria-label="<?php esc_attr_e( 'Primary Footer Menu', 'maverick' ); ?>">
<span class="footer-navigation__title bold"><?php echo esc_html( wp_get_nav_menu_name( 'footer-1' ) ); ?></span>
<?php
Expand All @@ -30,11 +30,9 @@
);
?>
</nav>
<?php } else { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a menu to the Footer Menu #1', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>

<?php if ( has_nav_menu( 'footer-2' ) ) { ?>
<?php if ( has_nav_menu( 'footer-2' ) || is_customize_preview() ) : ?>
<nav class="footer-navigation footer-navigation--2 text-sm" aria-label="<?php esc_attr_e( 'Secondary Footer Menu', 'maverick' ); ?>">
<span class="footer-navigation__title bold"><?php echo esc_html( wp_get_nav_menu_name( 'footer-2' ) ); ?></span>
<?php
Expand All @@ -47,11 +45,9 @@
);
?>
</nav>
<?php } elseif ( is_customize_preview() ) { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a menu to the Footer Menu #2', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>

<?php if ( has_nav_menu( 'footer-3' ) ) { ?>
<?php if ( has_nav_menu( 'footer-3' ) || is_customize_preview() ) : ?>
<nav class="footer-navigation footer-navigation--3 text-sm" aria-label="<?php esc_attr_e( 'Tertiary Footer Menu', 'maverick' ); ?>">
<span class="footer-navigation__title bold"><?php echo esc_html( wp_get_nav_menu_name( 'footer-3' ) ); ?></span>
<?php
Expand All @@ -64,9 +60,7 @@
);
?>
</nav>
<?php } elseif ( is_customize_preview() ) { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a menu to the Footer Menu #3', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>
</div>

<?php if ( $has_social_icons ) : ?>
Expand Down
18 changes: 6 additions & 12 deletions partials/footers/footer-4.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<?php Maverick\display_site_branding( array( 'description' => false ) ); ?>

<?php if ( has_nav_menu( 'footer-1' ) ) { ?>
<?php if ( has_nav_menu( 'footer-1' ) || is_customize_preview() ) : ?>
<nav class="footer-navigation footer-navigation--1 text-sm" aria-label="<?php esc_attr_e( 'Primary Footer Menu', 'maverick' ); ?>">
<span class="footer-navigation__title bold"><?php echo esc_html( wp_get_nav_menu_name( 'footer-1' ) ); ?></span>

Expand All @@ -31,11 +31,9 @@
);
?>
</nav>
<?php } else { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a menu to the Footer Menu #1', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>

<?php if ( has_nav_menu( 'footer-2' ) ) { ?>
<?php if ( has_nav_menu( 'footer-2' ) || is_customize_preview() ) : ?>
<nav class="footer-navigation footer-navigation--2 text-sm" aria-label="<?php esc_attr_e( 'Secondary Footer Menu', 'maverick' ); ?>">
<span class="footer-navigation__title bold"><?php echo esc_html( wp_get_nav_menu_name( 'footer-2' ) ); ?></span>

Expand All @@ -49,11 +47,9 @@
);
?>
</nav>
<?php } elseif ( is_customize_preview() ) { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a menu to the Footer Menu #2', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>

<?php if ( has_nav_menu( 'footer-3' ) ) { ?>
<?php if ( has_nav_menu( 'footer-3' ) || is_customize_preview() ) : ?>
<nav class="footer-navigation footer-navigation--3 text-sm" aria-label="<?php esc_attr_e( 'Tertiary Footer Menu', 'maverick' ); ?>">
<span class="footer-navigation__title bold"><?php echo esc_html( wp_get_nav_menu_name( 'footer-3' ) ); ?></span>

Expand All @@ -67,9 +63,7 @@
);
?>
</nav>
<?php } elseif ( is_customize_preview() ) { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a menu to the Footer Menu #3', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>
</div>

<?php if ( $has_social_icons ) : ?>
Expand Down
48 changes: 21 additions & 27 deletions partials/headers/header-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,27 @@

<?php Maverick\display_site_branding(); ?>

<?php if ( has_nav_menu( 'primary' ) ) { ?>

<?php Maverick\navigation_toggle(); ?>

<nav id="js-primary-menu" class="site-navigation c-site-navigation" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">

<?php
wp_nav_menu(
[
'theme_location' => 'primary',
'menu_class' => 'primary-menu list-reset',
'container' => false,
]
);
?>

<button id="js-site-search__toggle" class="site-search__toggle" type="button" aria-controls="js-site-search">
<?php echo Maverick\load_inline_svg( 'search.svg' ); // phpcs:ignore ?>
<span class="screen-reader-text"><?php esc_html_e( 'Search Toggle', 'maverick' ); ?></span>
</button>

<?php get_search_form(); ?>

</nav>
<?php } else { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a Primary menu to the header', 'maverick' ); ?></a></p>
<?php } ?>
<?php Maverick\navigation_toggle(); ?>

<nav id="js-primary-menu" class="site-navigation c-site-navigation" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">

<?php
wp_nav_menu(
[
'theme_location' => 'primary',
'menu_class' => 'primary-menu list-reset',
'container' => false,
]
);
?>

<button id="js-site-search__toggle" class="site-search__toggle" type="button" aria-controls="js-site-search">
<?php echo Maverick\load_inline_svg( 'search.svg' ); // phpcs:ignore ?>
<span class="screen-reader-text"><?php esc_html_e( 'Search Toggle', 'maverick' ); ?></span>
</button>

<?php get_search_form(); ?>
</nav>

</div>

Expand Down
9 changes: 3 additions & 6 deletions partials/headers/header-2.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@

<div class="site-header__inner flex items-center justify-between max-w-wide m-auto">

<?php if ( has_nav_menu( 'primary' ) ) { ?>

<?php Maverick\navigation_toggle(); ?>
<?php Maverick\navigation_toggle(); ?>

<?php if ( has_nav_menu( 'primary' ) || is_customize_preview() ) : ?>
<nav id="js-primary-menu" class="site-navigation c-site-navigation" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">

<?php
Expand All @@ -29,9 +28,7 @@
?>

</nav>
<?php } else { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a Primary menu to the header', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>

<?php Maverick\display_site_branding(); ?>

Expand Down
11 changes: 4 additions & 7 deletions partials/headers/header-3.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
<div class="site-header__inner flex lg:flex-column items-center justify-between max-w-wide m-auto relative">

<?php Maverick\display_site_branding(); ?>
<?php Maverick\navigation_toggle(); ?>

<?php if ( has_nav_menu( 'primary' ) ) { ?>

<?php Maverick\navigation_toggle(); ?>

<?php if ( has_nav_menu( 'primary' ) || is_customize_preview() ) : ?>
<nav id="js-primary-menu" class="site-navigation c-site-navigation lg:justify-center text-center" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">

<?php
Expand All @@ -31,9 +29,8 @@
?>

</nav>
<?php } else { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a Primary menu to the header', 'maverick' ); ?></a></p>
<?php } ?>
<?php endif; ?>

</div>

</header>
32 changes: 13 additions & 19 deletions partials/headers/header-4.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,23 @@
<?php get_search_form(); ?>

<?php Maverick\display_site_branding(); ?>
<?php Maverick\navigation_toggle(); ?>

<?php if ( has_nav_menu( 'primary' ) ) { ?>
<nav id="js-primary-menu" class="site-navigation c-site-navigation" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">

<?php Maverick\navigation_toggle(); ?>
<?php
wp_nav_menu(
[
'theme_location' => 'primary',
'menu_class' => 'primary-menu list-reset',
'container' => false,
]
);
?>

<nav id="js-primary-menu" class="site-navigation c-site-navigation" role="navigation" itemscope="itemscope" itemtype="http://schema.org/SiteNavigationElement">
<?php get_search_form(); ?>

<?php
wp_nav_menu(
[
'theme_location' => 'primary',
'menu_class' => 'primary-menu list-reset',
'container' => false,
]
);
?>

<?php get_search_form(); ?>

</nav>
<?php } else { ?>
<p class="u-informational"><a href="<?php echo esc_url( admin_url( 'nav-menus.php' ) ); ?>"><?php esc_html_e( 'Please assign a Primary menu to the header', 'maverick' ); ?></a></p>
<?php } ?>
</nav>

</div>

Expand Down
Loading

0 comments on commit 5837601

Please sign in to comment.