Default Themes: Import Twenty Nineteen from the 5.0 branch.
Merges [43808,43821,43842,43860,43892,43904,43909,43926-43929,43956,43961-43963] from the 5.0 branch to trunk.
Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, jorbin, netweb, b-07, khleomix, audrasjb, nielslange, mmaumio, richsalvucci, littlebigthing, dimadin, joyously, anevins, peterwilsoncc, dannycooper, iCaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, grapplerulrich, ocean90, joshfeck, frankew, AbdulWahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, nao, mayukojpn, enodekciw, ketuchetan, atanasangelovdev, poena, sharaz, artisticasad, mukesh27, burhandodhy, crunnells, aprakasa, themeroots, imonly_ik, tlxo, youthkee, brentswisher, smyoon315, mrahmadawais, desideveloper, Kau-Boy, mor10, mikeyarce, dingo_bastard, xkon, twoabove.
Fixes #45424.
Built from https://develop.svn.wordpress.org/trunk@44149
git-svn-id: http://core.svn.wordpress.org/trunk@43979 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 03:33:41 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Functions which enhance the theme by hooking into WordPress
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Twenty_Nineteen
|
2019-12-07 14:56:06 +01:00
|
|
|
* @since Twenty Nineteen 1.0
|
Default Themes: Import Twenty Nineteen from the 5.0 branch.
Merges [43808,43821,43842,43860,43892,43904,43909,43926-43929,43956,43961-43963] from the 5.0 branch to trunk.
Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, jorbin, netweb, b-07, khleomix, audrasjb, nielslange, mmaumio, richsalvucci, littlebigthing, dimadin, joyously, anevins, peterwilsoncc, dannycooper, iCaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, grapplerulrich, ocean90, joshfeck, frankew, AbdulWahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, nao, mayukojpn, enodekciw, ketuchetan, atanasangelovdev, poena, sharaz, artisticasad, mukesh27, burhandodhy, crunnells, aprakasa, themeroots, imonly_ik, tlxo, youthkee, brentswisher, smyoon315, mrahmadawais, desideveloper, Kau-Boy, mor10, mikeyarce, dingo_bastard, xkon, twoabove.
Fixes #45424.
Built from https://develop.svn.wordpress.org/trunk@44149
git-svn-id: http://core.svn.wordpress.org/trunk@43979 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 03:33:41 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds custom classes to the array of body classes.
|
|
|
|
*
|
|
|
|
* @param array $classes Classes for the body element.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function twentynineteen_body_classes( $classes ) {
|
|
|
|
|
|
|
|
if ( is_singular() ) {
|
|
|
|
// Adds `singular` to singular pages.
|
|
|
|
$classes[] = 'singular';
|
|
|
|
} else {
|
2020-06-20 14:16:10 +02:00
|
|
|
// Adds `hfeed` to non-singular pages.
|
Default Themes: Import Twenty Nineteen from the 5.0 branch.
Merges [43808,43821,43842,43860,43892,43904,43909,43926-43929,43956,43961-43963] from the 5.0 branch to trunk.
Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, jorbin, netweb, b-07, khleomix, audrasjb, nielslange, mmaumio, richsalvucci, littlebigthing, dimadin, joyously, anevins, peterwilsoncc, dannycooper, iCaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, grapplerulrich, ocean90, joshfeck, frankew, AbdulWahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, nao, mayukojpn, enodekciw, ketuchetan, atanasangelovdev, poena, sharaz, artisticasad, mukesh27, burhandodhy, crunnells, aprakasa, themeroots, imonly_ik, tlxo, youthkee, brentswisher, smyoon315, mrahmadawais, desideveloper, Kau-Boy, mor10, mikeyarce, dingo_bastard, xkon, twoabove.
Fixes #45424.
Built from https://develop.svn.wordpress.org/trunk@44149
git-svn-id: http://core.svn.wordpress.org/trunk@43979 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 03:33:41 +01:00
|
|
|
$classes[] = 'hfeed';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adds a class if image filters are enabled.
|
|
|
|
if ( twentynineteen_image_filters_enabled() ) {
|
|
|
|
$classes[] = 'image-filters-enabled';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
add_filter( 'body_class', 'twentynineteen_body_classes' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds custom class to the array of posts classes.
|
|
|
|
*/
|
|
|
|
function twentynineteen_post_classes( $classes, $class, $post_id ) {
|
|
|
|
$classes[] = 'entry';
|
|
|
|
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
add_filter( 'post_class', 'twentynineteen_post_classes', 10, 3 );
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
|
|
|
|
*/
|
|
|
|
function twentynineteen_pingback_header() {
|
|
|
|
if ( is_singular() && pings_open() ) {
|
|
|
|
echo '<link rel="pingback" href="', esc_url( get_bloginfo( 'pingback_url' ) ), '">';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_head', 'twentynineteen_pingback_header' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes comment form default fields.
|
|
|
|
*/
|
|
|
|
function twentynineteen_comment_form_defaults( $defaults ) {
|
|
|
|
$comment_field = $defaults['comment_field'];
|
|
|
|
|
|
|
|
// Adjust height of comment form.
|
|
|
|
$defaults['comment_field'] = preg_replace( '/rows="\d+"/', 'rows="5"', $comment_field );
|
|
|
|
|
|
|
|
return $defaults;
|
|
|
|
}
|
|
|
|
add_filter( 'comment_form_defaults', 'twentynineteen_comment_form_defaults' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filters the default archive titles.
|
|
|
|
*/
|
|
|
|
function twentynineteen_get_the_archive_title() {
|
|
|
|
if ( is_category() ) {
|
|
|
|
$title = __( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
|
|
|
|
} elseif ( is_tag() ) {
|
|
|
|
$title = __( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
|
|
|
|
} elseif ( is_author() ) {
|
|
|
|
$title = __( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>';
|
|
|
|
} elseif ( is_year() ) {
|
|
|
|
$title = __( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>';
|
|
|
|
} elseif ( is_month() ) {
|
|
|
|
$title = __( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>';
|
|
|
|
} elseif ( is_day() ) {
|
|
|
|
$title = __( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>';
|
|
|
|
} elseif ( is_post_type_archive() ) {
|
|
|
|
$title = __( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>';
|
|
|
|
} elseif ( is_tax() ) {
|
|
|
|
$tax = get_taxonomy( get_queried_object()->taxonomy );
|
2019-09-03 02:41:05 +02:00
|
|
|
/* translators: %s: Taxonomy singular name. */
|
Default Themes: Import Twenty Nineteen from the 5.0 branch.
Merges [43808,43821,43842,43860,43892,43904,43909,43926-43929,43956,43961-43963] from the 5.0 branch to trunk.
Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, jorbin, netweb, b-07, khleomix, audrasjb, nielslange, mmaumio, richsalvucci, littlebigthing, dimadin, joyously, anevins, peterwilsoncc, dannycooper, iCaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, grapplerulrich, ocean90, joshfeck, frankew, AbdulWahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, nao, mayukojpn, enodekciw, ketuchetan, atanasangelovdev, poena, sharaz, artisticasad, mukesh27, burhandodhy, crunnells, aprakasa, themeroots, imonly_ik, tlxo, youthkee, brentswisher, smyoon315, mrahmadawais, desideveloper, Kau-Boy, mor10, mikeyarce, dingo_bastard, xkon, twoabove.
Fixes #45424.
Built from https://develop.svn.wordpress.org/trunk@44149
git-svn-id: http://core.svn.wordpress.org/trunk@43979 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 03:33:41 +01:00
|
|
|
$title = sprintf( esc_html__( '%s Archives:', 'twentynineteen' ), $tax->labels->singular_name );
|
|
|
|
} else {
|
|
|
|
$title = __( 'Archives:', 'twentynineteen' );
|
|
|
|
}
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
add_filter( 'get_the_archive_title', 'twentynineteen_get_the_archive_title' );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add custom sizes attribute to responsive image functionality for post thumbnails.
|
|
|
|
*
|
|
|
|
* @origin Twenty Nineteen 1.0
|
|
|
|
*
|
|
|
|
* @param array $attr Attributes for the image markup.
|
|
|
|
* @return string Value for use in post thumbnail 'sizes' attribute.
|
|
|
|
*/
|
|
|
|
function twentynineteen_post_thumbnail_sizes_attr( $attr ) {
|
|
|
|
|
|
|
|
if ( is_admin() ) {
|
|
|
|
return $attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! is_singular() ) {
|
|
|
|
$attr['sizes'] = '(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $attr;
|
|
|
|
}
|
|
|
|
add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an extra menu to our nav for our priority+ navigation to use
|
|
|
|
*
|
2020-10-17 18:05:09 +02:00
|
|
|
* @param string $nav_menu Nav menu.
|
Default Themes: Import Twenty Nineteen from the 5.0 branch.
Merges [43808,43821,43842,43860,43892,43904,43909,43926-43929,43956,43961-43963] from the 5.0 branch to trunk.
Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, jorbin, netweb, b-07, khleomix, audrasjb, nielslange, mmaumio, richsalvucci, littlebigthing, dimadin, joyously, anevins, peterwilsoncc, dannycooper, iCaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, grapplerulrich, ocean90, joshfeck, frankew, AbdulWahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, nao, mayukojpn, enodekciw, ketuchetan, atanasangelovdev, poena, sharaz, artisticasad, mukesh27, burhandodhy, crunnells, aprakasa, themeroots, imonly_ik, tlxo, youthkee, brentswisher, smyoon315, mrahmadawais, desideveloper, Kau-Boy, mor10, mikeyarce, dingo_bastard, xkon, twoabove.
Fixes #45424.
Built from https://develop.svn.wordpress.org/trunk@44149
git-svn-id: http://core.svn.wordpress.org/trunk@43979 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 03:33:41 +01:00
|
|
|
* @param object $args Nav menu args.
|
|
|
|
* @return string More link for hidden menu items.
|
|
|
|
*/
|
|
|
|
function twentynineteen_add_ellipses_to_nav( $nav_menu, $args ) {
|
|
|
|
|
|
|
|
if ( 'menu-1' === $args->theme_location ) :
|
|
|
|
|
2019-07-04 11:15:58 +02:00
|
|
|
$nav_menu .= '
|
|
|
|
<div class="main-menu-more">
|
|
|
|
<ul class="main-menu">
|
|
|
|
<li class="menu-item menu-item-has-children">
|
2019-07-04 11:23:55 +02:00
|
|
|
<button class="submenu-expand main-menu-more-toggle is-empty" tabindex="-1"
|
|
|
|
aria-label="' . esc_attr__( 'More', 'twentynineteen' ) . '" aria-haspopup="true" aria-expanded="false">' .
|
2019-07-04 11:15:58 +02:00
|
|
|
twentynineteen_get_icon_svg( 'arrow_drop_down_ellipsis' ) . '
|
|
|
|
</button>
|
|
|
|
<ul class="sub-menu hidden-links">
|
2019-07-04 11:23:55 +02:00
|
|
|
<li class="mobile-parent-nav-menu-item">
|
2019-07-04 11:15:58 +02:00
|
|
|
<button class="menu-item-link-return">' .
|
|
|
|
twentynineteen_get_icon_svg( 'chevron_left' ) .
|
|
|
|
esc_html__( 'Back', 'twentynineteen' ) . '
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>';
|
Default Themes: Import Twenty Nineteen from the 5.0 branch.
Merges [43808,43821,43842,43860,43892,43904,43909,43926-43929,43956,43961-43963] from the 5.0 branch to trunk.
Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, jorbin, netweb, b-07, khleomix, audrasjb, nielslange, mmaumio, richsalvucci, littlebigthing, dimadin, joyously, anevins, peterwilsoncc, dannycooper, iCaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, grapplerulrich, ocean90, joshfeck, frankew, AbdulWahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, nao, mayukojpn, enodekciw, ketuchetan, atanasangelovdev, poena, sharaz, artisticasad, mukesh27, burhandodhy, crunnells, aprakasa, themeroots, imonly_ik, tlxo, youthkee, brentswisher, smyoon315, mrahmadawais, desideveloper, Kau-Boy, mor10, mikeyarce, dingo_bastard, xkon, twoabove.
Fixes #45424.
Built from https://develop.svn.wordpress.org/trunk@44149
git-svn-id: http://core.svn.wordpress.org/trunk@43979 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 03:33:41 +01:00
|
|
|
|
|
|
|
endif;
|
|
|
|
|
|
|
|
return $nav_menu;
|
|
|
|
}
|
|
|
|
add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WCAG 2.0 Attributes for Dropdown Menus
|
|
|
|
*
|
|
|
|
* Adjustments to menu attributes tot support WCAG 2.0 recommendations
|
|
|
|
* for flyout and dropdown menus.
|
|
|
|
*
|
|
|
|
* @ref https://www.w3.org/WAI/tutorials/menus/flyout/
|
|
|
|
*/
|
|
|
|
function twentynineteen_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
|
|
|
|
|
2020-01-29 01:45:18 +01:00
|
|
|
// Add [aria-haspopup] and [aria-expanded] to menu items that have children.
|
2020-04-05 05:02:11 +02:00
|
|
|
$item_has_children = in_array( 'menu-item-has-children', $item->classes, true );
|
Default Themes: Import Twenty Nineteen from the 5.0 branch.
Merges [43808,43821,43842,43860,43892,43904,43909,43926-43929,43956,43961-43963] from the 5.0 branch to trunk.
Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, jorbin, netweb, b-07, khleomix, audrasjb, nielslange, mmaumio, richsalvucci, littlebigthing, dimadin, joyously, anevins, peterwilsoncc, dannycooper, iCaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, grapplerulrich, ocean90, joshfeck, frankew, AbdulWahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, nao, mayukojpn, enodekciw, ketuchetan, atanasangelovdev, poena, sharaz, artisticasad, mukesh27, burhandodhy, crunnells, aprakasa, themeroots, imonly_ik, tlxo, youthkee, brentswisher, smyoon315, mrahmadawais, desideveloper, Kau-Boy, mor10, mikeyarce, dingo_bastard, xkon, twoabove.
Fixes #45424.
Built from https://develop.svn.wordpress.org/trunk@44149
git-svn-id: http://core.svn.wordpress.org/trunk@43979 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2018-12-14 03:33:41 +01:00
|
|
|
if ( $item_has_children ) {
|
|
|
|
$atts['aria-haspopup'] = 'true';
|
|
|
|
$atts['aria-expanded'] = 'false';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $atts;
|
|
|
|
}
|
|
|
|
add_filter( 'nav_menu_link_attributes', 'twentynineteen_nav_menu_link_attributes', 10, 4 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a nav menu item to be displayed on mobile to navigate from submenu back to the parent.
|
|
|
|
*
|
|
|
|
* This duplicates each parent nav menu item and makes it the first child of itself.
|
|
|
|
*
|
|
|
|
* @param array $sorted_menu_items Sorted nav menu items.
|
|
|
|
* @param object $args Nav menu args.
|
|
|
|
* @return array Amended nav menu items.
|
|
|
|
*/
|
|
|
|
function twentynineteen_add_mobile_parent_nav_menu_items( $sorted_menu_items, $args ) {
|
|
|
|
static $pseudo_id = 0;
|
|
|
|
if ( ! isset( $args->theme_location ) || 'menu-1' !== $args->theme_location ) {
|
|
|
|
return $sorted_menu_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
$amended_menu_items = array();
|
|
|
|
foreach ( $sorted_menu_items as $nav_menu_item ) {
|
|
|
|
$amended_menu_items[] = $nav_menu_item;
|
|
|
|
if ( in_array( 'menu-item-has-children', $nav_menu_item->classes, true ) ) {
|
|
|
|
$parent_menu_item = clone $nav_menu_item;
|
|
|
|
$parent_menu_item->original_id = $nav_menu_item->ID;
|
|
|
|
$parent_menu_item->ID = --$pseudo_id;
|
|
|
|
$parent_menu_item->db_id = $parent_menu_item->ID;
|
|
|
|
$parent_menu_item->object_id = $parent_menu_item->ID;
|
|
|
|
$parent_menu_item->classes = array( 'mobile-parent-nav-menu-item' );
|
|
|
|
$parent_menu_item->menu_item_parent = $nav_menu_item->ID;
|
|
|
|
|
|
|
|
$amended_menu_items[] = $parent_menu_item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $amended_menu_items;
|
|
|
|
}
|
|
|
|
add_filter( 'wp_nav_menu_objects', 'twentynineteen_add_mobile_parent_nav_menu_items', 10, 2 );
|