WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/12/2018 11:19:13 PM (9 months ago)
Author:
allancole
Message:

Updating Twenty Nineteen, our new default theme for 2019, set for 5.0.

This update applies the following changes:

  • Improve menu UI to support keyboard, click and touch interactions
  • Improve variable scoping and js performance in menu interaction javascript
  • Improve custom-colors for selected text, buttons and menu hover styles
  • Improve margins structure for more consistency between editor and frontend
  • Improve discussion avatars for simpler wording and better performance
  • Improve fonts in list widgets and list blocks
  • Improve comment responsive spacing and avatar display
  • Improve various block styles to make them consistent between the editor and frontend
  • Add tabbed browsing support for ie11
  • Add backwards compatibility support for older versions of WordPress
  • Add fallback styles for older versions of WP where Gutenberg is activated and then deactivated (backwards compatibility)
  • Add sizes attribute for featured images to improve responsive performance
  • Add focus-within polyfill
  • Add a footer menu for secondary page links
  • Fix editor styles to prevent conflicts with plugins that add meta boxes to the editor
  • Fix columns block issues on small screens
  • Fix empty-space font text cursor issue in Gutenberg editor
  • Fix RTL floating styles so that left/right floats are honored
  • Fix cover image block margins/padding
  • Fix invalid rgba style
  • Fix php warning when returning attributes
  • Fix gallery widget margins to improve gallery grids
  • Fix .entry-content selectors to prevent shortcodes, plugins and other unknown content from breaking the layout
  • Remove translation escaping to follow code standards in previous default themes
  • Remove custom color output in the fronten header when default color is selected
  • Remove fly-out sub-sub-sub-menu behavior on desktop to prevent sub-menus from falling off the screen
  • General code clean up and coding standards improvements

Initial development occurred on GitHub. See: https://github.com/WordPress/twentynineteen

Props allancole, karmatosed, kjellr, yingling017, mrasharirfan, milana_cap, fabiankaegy, westonruter, aaronjorbin, netweb, b-07, khleomix, blowery, dereksmart, jasmussen, audrasjb, nielslange, mmaumio, dimadin, joyously, anevins12, peterwilsoncc, dannycooper, icaleb, siriokun, technosiren, travel_girl, azchughtai, ianbelanger, nadim1992, ismailelkorchi, nativeinside, chetan200891, icaleb, grapplerulrich, ocean90, joshfeck, frankew, abdulwahab610, mendezcode, eliorivero, melchoyce, joen, laurelfulford, mdawaffe, kraftbj, dsmart, mukeshpanchal27, burhandodhy, crunnells, Ismail-elkorchi, aryaprakasa, @tlxo, @themeroots, @whizbangik, @yingles, @youthkee, @brentswisher, @smy315, @ahmadawais, @desi-developer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-content/themes/twentynineteen/inc/template-functions.php

    r43842 r43892  
    7272function twentynineteen_get_the_archive_title() {
    7373    if ( is_category() ) {
    74         $title = esc_html__( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
     74        $title = __( 'Category Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
    7575    } elseif ( is_tag() ) {
    76         $title = esc_html__( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
     76        $title = __( 'Tag Archives: ', 'twentynineteen' ) . '<span class="page-description">' . single_term_title( '', false ) . '</span>';
    7777    } elseif ( is_author() ) {
    78         $title = esc_html__( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>';
     78        $title = __( 'Author Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_author_meta( 'display_name' ) . '</span>';
    7979    } elseif ( is_year() ) {
    80         $title = esc_html__( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>';
     80        $title = __( 'Yearly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'Y', 'yearly archives date format', 'twentynineteen' ) ) . '</span>';
    8181    } elseif ( is_month() ) {
    82         $title = esc_html__( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>';
     82        $title = __( 'Monthly Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date( _x( 'F Y', 'monthly archives date format', 'twentynineteen' ) ) . '</span>';
    8383    } elseif ( is_day() ) {
    84         $title = esc_html__( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>';
     84        $title = __( 'Daily Archives: ', 'twentynineteen' ) . '<span class="page-description">' . get_the_date() . '</span>';
    8585    } elseif ( is_post_type_archive() ) {
    86         $title = esc_html__( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>';
     86        $title = __( 'Post Type Archives: ', 'twentynineteen' ) . '<span class="page-description">' . post_type_archive_title( '', false ) . '</span>';
    8787    } elseif ( is_tax() ) {
    8888        $tax = get_taxonomy( get_queried_object()->taxonomy );
     
    9090        $title = sprintf( esc_html__( '%s Archives:', 'twentynineteen' ), $tax->labels->singular_name );
    9191    } else {
    92         $title = esc_html__( 'Archives:', 'twentynineteen' );
     92        $title = __( 'Archives:', 'twentynineteen' );
    9393    }
    9494    return $title;
     
    112112    return true;
    113113}
     114
     115/**
     116 * Add custom sizes attribute to responsive image functionality for post thumbnails.
     117 *
     118 * @origin Twenty Nineteen 1.0
     119 *
     120 * @param array $attr  Attributes for the image markup.
     121 * @return string Value for use in post thumbnail 'sizes' attribute.
     122 */
     123function twentynineteen_post_thumbnail_sizes_attr( $attr ) {
     124
     125    if ( is_admin() ) {
     126        return $attr;
     127    }
     128
     129    if ( ! is_singular() ) {
     130        $attr['sizes'] = '(max-width: 34.9rem) calc(100vw - 2rem), (max-width: 53rem) calc(8 * (100vw / 12)), (min-width: 53rem) calc(6 * (100vw / 12)), 100vw';
     131    }
     132
     133    return $attr;
     134}
     135add_filter( 'wp_get_attachment_image_attributes', 'twentynineteen_post_thumbnail_sizes_attr', 10, 1 );
    114136
    115137/**
     
    141163function twentynineteen_get_discussion_data() {
    142164    static $discussion, $post_id;
     165
    143166    $current_post_id = get_the_ID();
    144     if ( $current_post_id === $post_id ) { /* If we have discussion information for post ID, return cached object */
    145         return $discussion;
    146     }
    147     $authors    = array();
    148     $commenters = array();
    149     $user_id    = -1; // is_user_logged_in() ? get_current_user_id() : -1;
    150     $comments   = get_comments(
     167    if ( $current_post_id === $post_id ) {
     168        return $discussion; /* If we have discussion information for post ID, return cached object */
     169    } else {
     170        $post_id = $current_post_id;
     171    }
     172
     173    $comments = get_comments(
    151174        array(
    152175            'post_id' => $current_post_id,
     
    154177            'order'   => get_option( 'comment_order', 'asc' ), /* Respect comment order from Settings » Discussion. */
    155178            'status'  => 'approve',
     179            'number'  => 20, /* Only retrieve the last 20 comments, as the end goal is just 6 unique authors */
    156180        )
    157181    );
     182
     183    $authors = array();
    158184    foreach ( $comments as $comment ) {
    159         $comment_user_id = (int) $comment->user_id;
    160         if ( $comment_user_id !== $user_id ) {
    161             $authors[]    = ( $comment_user_id > 0 ) ? $comment_user_id : $comment->comment_author_email;
    162             $commenters[] = $comment->comment_author_email;
    163         }
    164     }
     185        $authors[] = ( (int) $comment->user_id > 0 ) ? (int) $comment->user_id : $comment->comment_author_email;
     186    }
     187
    165188    $authors    = array_unique( $authors );
    166     $responses  = count( $commenters );
    167     $commenters = array_unique( $commenters );
    168     $post_id    = $current_post_id;
    169189    $discussion = (object) array(
    170         'authors'    => array_slice( $authors, 0, 6 ), /* Unique authors commenting on post (a subset of), excluding current user. */
    171         'commenters' => count( $commenters ),          /* Number of commenters involved in discussion, excluding current user. */
    172         'responses'  => $responses,                    /* Number of responses, excluding responses from current user. */
     190        'authors'   => array_slice( $authors, 0, 6 ),           /* Six unique authors commenting on the post. */
     191        'responses' => get_comments_number( $current_post_id ), /* Number of responses. */
    173192    );
     193
    174194    return $discussion;
    175195}
     196
     197/**
     198 * Add an extra menu to our nav for our priority+ navigation to use
     199 *
     200 * @param object $nav_menu  Nav menu.
     201 * @param object $args      Nav menu args.
     202 * @return string More link for hidden menu items.
     203 */
     204function twentynineteen_add_ellipses_to_nav( $nav_menu, $args ) {
     205
     206    if ( 'menu-1' === $args->theme_location ) :
     207
     208        $nav_menu .= '<div class="main-menu-more"   >';
     209        $nav_menu .= '<ul class="main-menu" tabindex="0">';
     210        $nav_menu .= '<li class="menu-item menu-item-has-children">';
     211        $nav_menu .= '<a href="#" class="screen-reader-text" aria-label="More" aria-haspopup="true" aria-expanded="false">' . esc_html( 'More', 'twentynineteen' ) . '</a>';
     212        $nav_menu .= '<span class="submenu-expand main-menu-more-toggle" tabindex="-1">';
     213        $nav_menu .= twentynineteen_get_icon_svg( 'arrow_drop_down_ellipsis' );
     214        $nav_menu .= '</span>';
     215        $nav_menu .= '<ul class="sub-menu hidden-links is-hidden">';
     216        $nav_menu .= '<li id="menu-item--1" class="mobile-parent-nav-menu-item menu-item--1">';
     217        $nav_menu .= '<a class="menu-item-link-return" id="menu-item-link-return-1877" href="#menu-item-link-1877" onclick="event.preventDefault();" tabindex="-1">';
     218        $nav_menu .= twentynineteen_get_icon_svg( 'chevron_left' );
     219        $nav_menu .= esc_html__( 'Back', 'twentynineteen' );
     220        $nav_menu .= '</a>';
     221        $nav_menu .= '</li>';
     222        $nav_menu .= '</ul>';
     223        $nav_menu .= '</li>';
     224        $nav_menu .= '</ul>';
     225        $nav_menu .= '</div>';
     226
     227    endif;
     228
     229    return $nav_menu;
     230}
     231add_filter( 'wp_nav_menu', 'twentynineteen_add_ellipses_to_nav', 10, 2 );
    176232
    177233/**
     
    217273        // @todo Only do this for nested submenus? If on a first-level submenu, then really the link could be "#" since the desire is to remove the target entirely.
    218274        $link = sprintf(
    219             '<a class="menu-item-link-return" id="%1$s" href="%2$s" onclick="%3$s" tabindex="-1">%4$s',
    220             esc_attr( "menu-item-link-return-{$item->original_id}" ),
    221             esc_attr( "#menu-item-link-{$item->original_id}" ),
    222             esc_attr( 'event.preventDefault();' ),
     275            '<span class="menu-item-link-return" tabindex="-1">%s',
    223276            twentynineteen_get_icon_svg( 'chevron_left', 24 )
    224277        );
    225278
     279        // replace opening <a> with <span>
    226280        $output = preg_replace(
    227281            '/<a\s.*?>/',
     
    230284            1 // Limit.
    231285        );
     286
     287        // replace closing </a> with </span>
     288        $output = preg_replace(
     289            '#</a>#i',
     290            '</span>',
     291            $output,
     292            1 // Limit.
     293        );
     294
    232295    } elseif ( in_array( 'menu-item-has-children', $item->classes, true ) ) {
    233         // Add an ID to the link element itself to facilitate navigation from submenu back to parent.
    234         $output = preg_replace( '/(?<=<a\s)/', sprintf( ' id="%s" ', esc_attr( "menu-item-link-{$item->ID}" ) ), $output );
    235296
    236297        // Add SVG icon to parent items.
    237         if ( 0 === $depth ) {
    238             $icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 );
    239         } else {
    240             $icon = twentynineteen_get_icon_svg( 'chevron_right', 24 );
    241         }
    242 
    243         // @todo We might as well just go back to using the SVG element if the link approach is not suitable for no-JS environments.
    244         $link = sprintf(
    245             '<a class="mobile-submenu-expand" href="%s" onclick="%s" tabindex="-1">%s</a>',
    246             esc_attr( "#menu-item-link-return-{$item->ID}" ),
    247             esc_attr( 'event.preventDefault();' ),
     298        $icon = twentynineteen_get_icon_svg( 'keyboard_arrow_down', 24 );
     299
     300        $output .= sprintf(
     301            '<span class="submenu-expand" tabindex="-1">%s</span>',
    248302            $icon
    249303        );
    250 
    251         $output .= $link;
    252         $output .= "<span class='desktop-submenu-expand'>$icon</span>";
    253304    }
    254305
Note: See TracChangeset for help on using the changeset viewer.