updated theme GeneratePress version 3.0.2

This commit is contained in:
2020-10-20 15:16:18 +00:00
committed by Gitium
parent dcc1a6ca18
commit 1047e0b29f
129 changed files with 16624 additions and 8924 deletions

View File

@ -16,8 +16,14 @@ if ( ! function_exists( 'generate_navigation_position' ) ) {
* @since 0.1
*/
function generate_navigation_position() {
/**
* generate_before_navigation hook.
*
* @since 3.0.0
*/
do_action( 'generate_before_navigation' );
?>
<nav id="site-navigation" <?php generate_do_element_classes( 'navigation' ); ?> <?php generate_do_microdata( 'navigation' ); ?>>
<nav id="site-navigation" <?php generate_do_element_classes( 'navigation' ); ?>>
<div <?php generate_do_element_classes( 'inside_navigation' ); ?>>
<?php
/**
@ -46,17 +52,24 @@ if ( ! function_exists( 'generate_navigation_position' ) ) {
if ( $mobile_menu_label ) {
printf(
'<span class="mobile-menu">%s</span>',
$mobile_menu_label
$mobile_menu_label // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML allowed in filter.
);
} else {
printf(
'<span class="screen-reader-text">%s</span>',
__( 'Menu', 'generatepress' )
esc_html__( 'Menu', 'generatepress' )
);
}
?>
</button>
<?php
/**
* generate_after_mobile_menu_button hook
*
* @since 3.0.0
*/
do_action( 'generate_after_mobile_menu_button' );
wp_nav_menu(
array(
'theme_location' => 'primary',
@ -76,20 +89,85 @@ if ( ! function_exists( 'generate_navigation_position' ) ) {
*/
do_action( 'generate_after_primary_menu' );
?>
</div><!-- .inside-navigation -->
</nav><!-- #site-navigation -->
</div>
</nav>
<?php
/**
* generate_after_navigation hook.
*
* @since 3.0.0
*/
do_action( 'generate_after_navigation' );
}
}
add_action( 'generate_before_navigation', 'generate_do_header_mobile_menu_toggle' );
/**
* Build the mobile menu toggle in the header.
*
* @since 3.0.0
*/
function generate_do_header_mobile_menu_toggle() {
if ( ! generate_is_using_flexbox() ) {
return;
}
if ( ! generate_has_inline_mobile_toggle() ) {
return;
}
?>
<nav id="mobile-menu-control-wrapper" <?php generate_do_element_classes( 'mobile-navigation-toggle', array( 'main-navigation', 'mobile-menu-control-wrapper' ) ); ?>>
<?php
/**
* generate_inside_mobile_menu_control_wrapper hook.
*
* @since 3.0.0
*/
do_action( 'generate_inside_mobile_menu_control_wrapper' );
?>
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false" data-nav="site-navigation">
<?php
/**
* generate_inside_mobile_menu hook.
*
* @since 0.1
*/
do_action( 'generate_inside_mobile_menu' );
generate_do_svg_icon( 'menu-bars', true );
$mobile_menu_label = __( 'Menu', 'generatepress' );
if ( 'nav-float-right' === generate_get_navigation_location() || 'nav-float-left' === generate_get_navigation_location() ) {
$mobile_menu_label = '';
}
$mobile_menu_label = apply_filters( 'generate_mobile_menu_label', $mobile_menu_label );
if ( $mobile_menu_label ) {
printf(
'<span class="mobile-menu">%s</span>',
$mobile_menu_label // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- HTML allowed in filter.
);
} else {
printf(
'<span class="screen-reader-text">%s</span>',
esc_html__( 'Menu', 'generatepress' )
);
}
?>
</button>
</nav>
<?php
}
if ( ! function_exists( 'generate_menu_fallback' ) ) {
/**
* Menu fallback.
*
* @since 1.1.4
*
* @param array $args
* @return string
* @param array $args Existing menu args.
*/
function generate_menu_fallback( $args ) {
$generate_settings = wp_parse_args(
@ -108,34 +186,38 @@ if ( ! function_exists( 'generate_menu_fallback' ) ) {
wp_list_pages( $args );
if ( 'enable' === $generate_settings['nav_search'] ) {
printf(
'<li class="search-item"><a aria-label="%1$s" href="#">%2$s</a></li>',
esc_attr__( 'Open Search Bar', 'generatepress' ),
generate_get_svg_icon( 'search', true )
if ( ! generate_is_using_flexbox() && 'enable' === $generate_settings['nav_search'] ) {
$search_item = apply_filters(
'generate_navigation_search_menu_item_output',
sprintf(
'<li class="search-item menu-item-align-right"><a aria-label="%1$s" href="#">%2$s</a></li>',
esc_attr__( 'Open Search Bar', 'generatepress' ),
generate_get_svg_icon( 'search', true ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in function.
)
);
echo $search_item; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Safe output.
}
?>
</ul>
</div><!-- .main-nav -->
</div>
<?php
}
}
/**
* Generate the navigation based on settings
*
* It would be better to have all of these inside one action, but these
* are kept this way to maintain backward compatibility for people
* un-hooking and moving the navigation/changing the priority.
*
* @since 0.1
*/
if ( ! function_exists( 'generate_add_navigation_after_header' ) ) {
add_action( 'generate_after_header', 'generate_add_navigation_after_header', 5 );
/**
* Generate the navigation based on settings
*
* It would be better to have all of these inside one action, but these
* are kept this way to maintain backward compatibility for people
* un-hooking and moving the navigation/changing the priority.
*
* @since 0.1
*/
function generate_add_navigation_after_header() {
if ( 'nav-below-header' == generate_get_navigation_location() ) {
if ( 'nav-below-header' === generate_get_navigation_location() ) {
generate_navigation_position();
}
}
@ -143,8 +225,17 @@ if ( ! function_exists( 'generate_add_navigation_after_header' ) ) {
if ( ! function_exists( 'generate_add_navigation_before_header' ) ) {
add_action( 'generate_before_header', 'generate_add_navigation_before_header', 5 );
/**
* Generate the navigation based on settings
*
* It would be better to have all of these inside one action, but these
* are kept this way to maintain backward compatibility for people
* un-hooking and moving the navigation/changing the priority.
*
* @since 0.1
*/
function generate_add_navigation_before_header() {
if ( 'nav-above-header' == generate_get_navigation_location() ) {
if ( 'nav-above-header' === generate_get_navigation_location() ) {
generate_navigation_position();
}
}
@ -152,8 +243,17 @@ if ( ! function_exists( 'generate_add_navigation_before_header' ) ) {
if ( ! function_exists( 'generate_add_navigation_float_right' ) ) {
add_action( 'generate_after_header_content', 'generate_add_navigation_float_right', 5 );
/**
* Generate the navigation based on settings
*
* It would be better to have all of these inside one action, but these
* are kept this way to maintain backward compatibility for people
* un-hooking and moving the navigation/changing the priority.
*
* @since 0.1
*/
function generate_add_navigation_float_right() {
if ( 'nav-float-right' == generate_get_navigation_location() || 'nav-float-left' == generate_get_navigation_location() ) {
if ( 'nav-float-right' === generate_get_navigation_location() || 'nav-float-left' === generate_get_navigation_location() ) {
generate_navigation_position();
}
}
@ -161,8 +261,17 @@ if ( ! function_exists( 'generate_add_navigation_float_right' ) ) {
if ( ! function_exists( 'generate_add_navigation_before_right_sidebar' ) ) {
add_action( 'generate_before_right_sidebar_content', 'generate_add_navigation_before_right_sidebar', 5 );
/**
* Generate the navigation based on settings
*
* It would be better to have all of these inside one action, but these
* are kept this way to maintain backward compatibility for people
* un-hooking and moving the navigation/changing the priority.
*
* @since 0.1
*/
function generate_add_navigation_before_right_sidebar() {
if ( 'nav-right-sidebar' == generate_get_navigation_location() ) {
if ( 'nav-right-sidebar' === generate_get_navigation_location() ) {
echo '<div class="gen-sidebar-nav">';
generate_navigation_position();
echo '</div>';
@ -172,8 +281,17 @@ if ( ! function_exists( 'generate_add_navigation_before_right_sidebar' ) ) {
if ( ! function_exists( 'generate_add_navigation_before_left_sidebar' ) ) {
add_action( 'generate_before_left_sidebar_content', 'generate_add_navigation_before_left_sidebar', 5 );
/**
* Generate the navigation based on settings
*
* It would be better to have all of these inside one action, but these
* are kept this way to maintain backward compatibility for people
* un-hooking and moving the navigation/changing the priority.
*
* @since 0.1
*/
function generate_add_navigation_before_left_sidebar() {
if ( 'nav-left-sidebar' == generate_get_navigation_location() ) {
if ( 'nav-left-sidebar' === generate_get_navigation_location() ) {
echo '<div class="gen-sidebar-nav">';
generate_navigation_position();
echo '</div>';
@ -189,7 +307,7 @@ if ( ! class_exists( 'Generate_Page_Walker' ) && class_exists( 'Walker_Page' ) )
* @since 1.3.21
*/
class Generate_Page_Walker extends Walker_Page {
function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) { // phpcs:ignore
$css_class = array( 'page_item', 'page-item-' . $page->ID );
$button = '';
@ -204,15 +322,17 @@ if ( ! class_exists( 'Generate_Page_Walker' ) && class_exists( 'Walker_Page' ) )
if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
$css_class[] = 'current-menu-ancestor';
}
if ( $page->ID == $current_page ) {
if ( $page->ID == $current_page ) { // phpcs:ignore
$css_class[] = 'current-menu-item';
} elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
} elseif ( $_current_page && $page->ID == $_current_page->post_parent ) { // phpcs:ignore
$css_class[] = 'current-menu-parent';
}
} elseif ( $page->ID == get_option( 'page_for_posts' ) ) {
} elseif ( $page->ID == get_option( 'page_for_posts' ) ) { // phpcs:ignore
$css_class[] = 'current-menu-parent';
}
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Core filter name.
$css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
$args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
@ -223,7 +343,7 @@ if ( ! class_exists( 'Generate_Page_Walker' ) && class_exists( 'Walker_Page' ) )
$css_classes,
get_permalink( $page->ID ),
$args['link_before'],
apply_filters( 'the_title', $page->post_title, $page->ID ),
apply_filters( 'the_title', $page->post_title, $page->ID ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Core filter name.
$args['link_after'],
$button
);
@ -238,10 +358,10 @@ if ( ! function_exists( 'generate_dropdown_icon_to_menu_link' ) ) {
*
* @since 1.3.42
*
* @param string $title The menu item title.
* @param WP_Post $item All of our menu item data.
* @param string $title The menu item title.
* @param WP_Post $item All of our menu item data.
* @param stdClass $args All of our menu item args.
* @param int $dept Depth of menu item.
* @param int $depth Depth of menu item.
* @return string The menu item.
*/
function generate_dropdown_icon_to_menu_link( $title, $item, $args, $depth ) {
@ -256,7 +376,47 @@ if ( ! function_exists( 'generate_dropdown_icon_to_menu_link' ) ) {
if ( isset( $args->container_class ) && 'main-nav' === $args->container_class ) {
foreach ( $item->classes as $value ) {
if ( 'menu-item-has-children' === $value ) {
$icon = generate_get_svg_icon( 'arrow' );
$arrow_direction = 'down';
if ( 'primary' === $args->theme_location ) {
if ( 0 !== $depth ) {
$arrow_direction = 'right';
if ( 'left' === generate_get_option( 'nav_dropdown_direction' ) ) {
$arrow_direction = 'left';
}
}
if ( 'nav-left-sidebar' === generate_get_navigation_location() ) {
$arrow_direction = 'right';
if ( 'both-right' === generate_get_layout() ) {
$arrow_direction = 'left';
}
}
if ( 'nav-right-sidebar' === generate_get_navigation_location() ) {
$arrow_direction = 'left';
if ( 'both-left' === generate_get_layout() ) {
$arrow_direction = 'right';
}
}
if ( 'hover' !== generate_get_option( 'nav_dropdown_type' ) ) {
$arrow_direction = 'down';
}
}
$arrow_direction = apply_filters( 'generate_menu_item_dropdown_arrow_direction', $arrow_direction, $args, $depth );
if ( 'down' === $arrow_direction ) {
$arrow_direction = '';
} else {
$arrow_direction = '-' . $arrow_direction;
}
$icon = generate_get_svg_icon( 'arrow' . $arrow_direction );
$title = $title . '<span role="' . $role . '" class="dropdown-menu-toggle"' . $tabindex . '>' . $icon . '</span>';
}
}
@ -283,25 +443,90 @@ if ( ! function_exists( 'generate_navigation_search' ) ) {
return;
}
echo apply_filters( 'generate_navigation_search_output', sprintf( // WPCS: XSS ok, sanitization ok.
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
</form>',
esc_url( home_url( '/' ) ),
esc_attr( get_search_query() ),
esc_attr_x( 'Search', 'label', 'generatepress' )
));
echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'generate_navigation_search_output',
sprintf(
'<form method="get" class="search-form navigation-search" action="%1$s">
<input type="search" class="search-field" value="%2$s" name="s" title="%3$s" />
</form>',
esc_url( home_url( '/' ) ),
esc_attr( get_search_query() ),
esc_attr_x( 'Search', 'label', 'generatepress' )
)
);
}
}
add_action( 'generate_after_primary_menu', 'generate_do_menu_bar_item_container' );
add_action( 'generate_inside_mobile_menu_control_wrapper', 'generate_do_menu_bar_item_container' );
/**
* Add a container for menu bar items.
*
* @since 3.0.0
*/
function generate_do_menu_bar_item_container() {
if ( ! generate_is_using_flexbox() ) {
return;
}
if ( generate_has_menu_bar_items() ) {
echo '<div class="menu-bar-items">';
do_action( 'generate_menu_bar_items' );
echo '</div>';
}
}
add_action( 'wp', 'generate_add_menu_bar_items' );
/**
* Add menu bar items to the primary navigation.
*
* @since 3.0.0
*/
function generate_add_menu_bar_items() {
if ( ! generate_is_using_flexbox() ) {
return;
}
if ( 'enable' === generate_get_option( 'nav_search' ) ) {
add_action( 'generate_menu_bar_items', 'generate_do_navigation_search_button' );
}
}
/**
* Add the navigation search button.
*
* @since 3.0.0
*/
function generate_do_navigation_search_button() {
if ( ! generate_is_using_flexbox() ) {
return;
}
if ( 'enable' !== generate_get_option( 'nav_search' ) ) {
return;
}
$search_item = apply_filters(
'generate_navigation_search_menu_item_output',
sprintf(
'<span class="menu-bar-item search-item"><a aria-label="%1$s" href="#">%2$s</a></span>',
esc_attr__( 'Open Search Bar', 'generatepress' ),
generate_get_svg_icon( 'search', true ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in function.
)
);
echo $search_item; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- No escaping needed.
}
if ( ! function_exists( 'generate_menu_search_icon' ) ) {
add_filter( 'wp_nav_menu_items', 'generate_menu_search_icon', 10, 2 );
/**
* Add search icon to primary menu if set
* Add search icon to primary menu if set.
* Only used if using old float system.
*
* @since 1.2.9.7
*
* @param string $nav The HTML list content for the menu items.
* @param string $nav The HTML list content for the menu items.
* @param stdClass $args An object containing wp_nav_menu() arguments.
* @return string The search icon menu item.
*/
@ -311,6 +536,10 @@ if ( ! function_exists( 'generate_menu_search_icon' ) ) {
generate_get_defaults()
);
if ( generate_is_using_flexbox() ) {
return $nav;
}
// If the search icon isn't enabled, return the regular nav.
if ( 'enable' !== $generate_settings['nav_search'] ) {
return $nav;
@ -318,12 +547,16 @@ if ( ! function_exists( 'generate_menu_search_icon' ) ) {
// If our primary menu is set, add the search icon.
if ( isset( $args->theme_location ) && 'primary' === $args->theme_location ) {
return sprintf(
'%1$s<li class="search-item"><a aria-label="%2$s" href="#">%3$s</a></li>',
$nav,
esc_attr__( 'Open Search Bar', 'generatepress' ),
generate_get_svg_icon( 'search', true )
$search_item = apply_filters(
'generate_navigation_search_menu_item_output',
sprintf(
'<li class="search-item menu-item-align-right"><a aria-label="%1$s" href="#">%2$s</a></li>',
esc_attr__( 'Open Search Bar', 'generatepress' ),
generate_get_svg_icon( 'search', true ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in function.
)
);
return $nav . $search_item;
}
// Our primary menu isn't set, return the regular nav.
@ -335,7 +568,8 @@ if ( ! function_exists( 'generate_menu_search_icon' ) ) {
if ( ! function_exists( 'generate_mobile_menu_search_icon' ) ) {
add_action( 'generate_inside_navigation', 'generate_mobile_menu_search_icon' );
/**
* Add search icon to mobile menu bar
* Add search icon to mobile menu bar.
* Only used if using old float system.
*
* @since 1.3.12
*/
@ -350,15 +584,19 @@ if ( ! function_exists( 'generate_mobile_menu_search_icon' ) ) {
return;
}
if ( generate_is_using_flexbox() ) {
return;
}
?>
<div class="mobile-bar-items">
<?php do_action( 'generate_inside_mobile_menu_bar' ); ?>
<span class="search-item">
<a aria-label="<?php _e( 'Open Search Bar', 'generatepress' ); ?>" href="#">
<a aria-label="<?php esc_attr_e( 'Open Search Bar', 'generatepress' ); ?>" href="#">
<?php generate_do_svg_icon( 'search', true ); ?>
</a>
</span>
</div><!-- .mobile-bar-items -->
</div>
<?php
}
}