Make WordPress Core


Ignore:
Timestamp:
10/08/2019 07:05:53 PM (5 years ago)
Author:
desrosj
Message:

Bundled Themes: Update Twenty Twenty.

This brings trunk's version of Twenty Twenty in-sync with GitHub.

For a complete list of changes since [46357], see https://github.com/WordPress/twentytwenty/compare/7157870...7246fd6.

Props anlino, ianbelanger, poena, williampatton, nielslange, acosmin, netweb, joyusly, luminuu, itowhid06, cbravobernal, intimez, glauberglauber, ocean90, amolv, briceduclos, aristath, mukesh27, garrett-eclipse, audrasjb, afercia, dianeco, utsav72640, mahesh901122, tobifjellner.
See #48110.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwenty/inc/template-tags.php

    r46357 r46445  
    1010/**
    1111 * Table of Contents:
     12 * Logo & Description
    1213 * Comments
    1314 * Post Meta
    1415 * Menus
    1516 * Classes
    16  */
    17 
     17 * Archives
     18 * Miscellaneous
     19 */
     20
     21/**
     22 * Logo & Description
     23 */
    1824/**
    1925 * Displays the site logo, either text or image.
    2026 *
    2127 * @param array   $args Arguments for displaying the site logo either as an image or text.
    22  * @param boolean $echo Echo or return the html.
     28 * @param boolean $echo Echo or return the HTML.
     29 *
     30 * @return string $html Compiled HTML based on our arguments.
    2331 */
    2432function twentytwenty_site_logo( $args = array(), $echo = true ) {
     
    8290 *
    8391 * @param boolean $echo Echo or return the html.
     92 *
     93 * @return string $html The HTML to display.
    8494 */
    8595function twentytwenty_site_description( $echo = true ) {
     
    119129 *
    120130 * @param object $comment Comment data.
     131 *
     132 * @return bool
    121133 */
    122134function twentytwenty_is_comment_by_post_author( $comment = null ) {
     
    143155 *
    144156 * @param string $link Link to the top of the page.
     157 *
     158 * @return string $link Link to the top of the page.
    145159 */
    146160function twentytwenty_filter_comment_reply_link( $link ) {
     
    168182
    169183}
     184
     185/**
     186 * Filters the edit post link to add an icon and use the post meta structure.
     187 *
     188 * @param string $link    Anchor tag for the edit link.
     189 * @param int    $post_id Post ID.
     190 * @param string $text    Anchor text.
     191 */
     192function twentytwenty_edit_post_link( $link, $post_id, $text ) {
     193
     194    $edit_url = get_edit_post_link( $post_id );
     195
     196    if ( ! $edit_url ) {
     197        return;
     198    }
     199
     200    $text = sprintf(
     201        wp_kses(
     202            /* translators: %s: Post title. Only visible to screen readers. */
     203            __( 'Edit <span class="screen-reader-text">%s</span>', 'twentytwenty' ),
     204            array(
     205                'span' => array(
     206                    'class' => array(),
     207                ),
     208            )
     209        ),
     210        get_the_title( $post_id )
     211    );
     212
     213    return '<div class="post-meta-wrapper post-meta-edit-link-wrapper"><ul class="post-meta"><li class="post-edit meta-wrapper"><span class="meta-icon">' . twentytwenty_get_theme_svg( 'edit' ) . '</span><span class="meta-text"><a href="' . esc_url( $edit_url ) . '">' . $text . '</a></span></li></ul><!-- .post-meta --></div><!-- .post-meta-wrapper -->';
     214
     215}
     216
     217add_filter( 'edit_post_link', 'twentytwenty_edit_post_link', 10, 3 );
    170218
    171219/**
     
    207255        * Filters post meta info visibility
    208256        *
    209         * Use this filter to hide post meta information like Author, Post date, Comments, Is stiky status
     257        * Use this filter to hide post meta information like Author, Post date, Comments, Is sticky status
    210258        *
    211259        * @since 1.0.0
     
    290338                    <li class="post-author meta-wrapper">
    291339                        <span class="meta-icon">
    292                             <span class="screen-reader-text"><?php _e( 'Post author', 'twentytwenty' );// phpcs:ignore WordPress.Security.EscapeOutput.UnsafePrintingFunction -- core trusts translations ?></span>
     340                            <span class="screen-reader-text"><?php _e( 'Post author', 'twentytwenty' ); ?></span>
    293341                            <?php twentytwenty_the_theme_svg( 'user' ); ?>
    294342                        </span>
     
    296344                            <?php
    297345                            printf(
    298                                 // Translators: %s = the author name.
    299                                 _x( 'By %s', '%s = author name', 'twentytwenty' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- core trusts translations
     346                                /* translators: %s: Author name */
     347                                __( 'By %s', 'twentytwenty' ),
    300348                                '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author_meta( 'display_name' ) ) . '</a>'
    301349                            );
     
    315363                        <a class="meta-wrapper" href="<?php the_permalink(); ?>">
    316364                            <span class="meta-icon">
    317                                 <span class="screen-reader-text"><?php _e( 'Post date', 'twentytwenty' ); // phpcs:ignore WordPress.Security.EscapeOutput.UnsafePrintingFunction -- core trusts translations ?></span>
     365                                <span class="screen-reader-text"><?php _e( 'Post date', 'twentytwenty' ); ?></span>
    318366                                <?php twentytwenty_the_theme_svg( 'calendar' ); ?>
    319367                            </span>
     
    334382                    <li class="post-categories meta-wrapper">
    335383                        <span class="meta-icon">
    336                             <span class="screen-reader-text"><?php _e( 'Categories', 'twentytwenty' ); // phpcs:ignore WordPress.Security.EscapeOutput.UnsafePrintingFunction -- core trusts translations ?></span>
     384                            <span class="screen-reader-text"><?php _e( 'Categories', 'twentytwenty' ); ?></span>
    337385                            <?php twentytwenty_the_theme_svg( 'folder' ); ?>
    338386                        </span>
    339387                        <span class="meta-text">
    340                             <?php _e( 'In', 'twentytwenty' ); // phpcs:ignore WordPress.Security.EscapeOutput.UnsafePrintingFunction -- core trusts translations ?> <?php the_category( ', ' ); ?>
     388                            <?php _ex( 'In', 'A string that is output before one or more categories', 'twentytwenty' ); ?> <?php the_category( ', ' ); ?>
    341389                        </span>
    342390                    </li>
     
    352400                    <li class="post-tags meta-wrapper">
    353401                        <span class="meta-icon">
    354                             <span class="screen-reader-text"><?php _e( 'Tags', 'twentytwenty' ); // phpcs:ignore WordPress.Security.EscapeOutput.UnsafePrintingFunction -- core trusts translations ?></span>
     402                            <span class="screen-reader-text"><?php _e( 'Tags', 'twentytwenty' ); ?></span>
    355403                            <?php twentytwenty_the_theme_svg( 'tag' ); ?>
    356404                        </span>
     
    390438                        </span>
    391439                        <span class="meta-text">
    392                             <?php _e( 'Sticky post', 'twentytwenty' ); // phpcs:ignore WordPress.Security.EscapeOutput.UnsafePrintingFunction -- core trusts translations ?>
     440                            <?php _e( 'Sticky post', 'twentytwenty' ); ?>
    393441                        </span>
    394442                    </li>
     
    438486 * styling of sub levels in the fallback. Only applied if the match_menu_classes argument is set.
    439487 *
    440  * @param string $css_class CSS Class names.
     488 * @param array $css_class CSS Class names.
    441489 * @param string $item Comment.
    442490 * @param int    $depth Depth of the current comment.
    443491 * @param array  $args An array of arguments.
    444  * @param string $current_page Wether or not the item is the current item.
     492 * @param string $current_page Whether or not the item is the current item.
     493 *
     494 * @return array $css_class CSS Class names.
    445495 */
    446496function twentytwenty_filter_wp_list_pages_item_classes( $css_class, $item, $depth, $args, $current_page ) {
     
    472522 * Add a Sub Nav Toggle to the Expanded Menu and Mobile Menu.
    473523 *
    474  * @param array  $args An array of arguments.
    475  * @param string $item Menu item.
    476  * @param int    $depth Depth of the current menu item.
     524 * @param stdClass $args An array of arguments.
     525 * @param string   $item Menu item.
     526 * @param int      $depth Depth of the current menu item.
     527 *
     528 * @return stdClass $args An object of wp_nav_menu() arguments.
    477529 */
    478530function twentytwenty_add_sub_toggles_to_main_menu( $args, $item, $depth ) {
     
    515567
    516568/**
     569 * Display SVG icons in social links menu.
     570 *
     571 * @param  string  $item_output The menu item output.
     572 * @param  WP_Post $item        Menu item object.
     573 * @param  int     $depth       Depth of the menu.
     574 * @param  array   $args        wp_nav_menu() arguments.
     575 * @return string  $item_output The menu item output with social icon.
     576 */
     577function twentytwenty_nav_menu_social_icons( $item_output, $item, $depth, $args ) {
     578    // Change SVG icon inside social links menu if there is supported URL.
     579    if ( 'social' === $args->theme_location ) {
     580        $svg = TwentyTwenty_SVG_Icons::get_social_link_svg( $item->url );
     581        if ( empty( $svg ) ) {
     582            $svg = twentytwenty_get_theme_svg( 'link' );
     583        }
     584        $item_output = str_replace( $args->link_after, '</span>' . $svg, $item_output );
     585    }
     586
     587    return $item_output;
     588}
     589
     590add_filter( 'walker_nav_menu_start_el', 'twentytwenty_nav_menu_social_icons', 10, 4 );
     591
     592/**
    517593 * Classes
    518594 */
     
    532608
    533609/**
     610 * Add conditional body classes.
     611 *
     612 * @param array $classes Classes added to the body tag.
     613 *
     614 * @return array $classes Classes added to the body tag.
     615 */
     616function twentytwenty_body_classes( $classes ) {
     617
     618    global $post;
     619    $post_type = isset( $post ) ? $post->post_type : false;
     620
     621    // Check whether we're singular.
     622    if ( is_singular() ) {
     623        $classes[] = 'singular';
     624    }
     625
     626    // Check whether the current page should have an overlay header.
     627    if ( is_page_template( array( 'templates/template-cover.php' ) ) ) {
     628        $classes[] = 'overlay-header';
     629    }
     630
     631    // Check whether the current page has full-width content.
     632    if ( is_page_template( array( 'templates/template-full-width.php' ) ) ) {
     633        $classes[] = 'has-full-width-content';
     634    }
     635
     636    // Check for enabled search.
     637    if ( true === get_theme_mod( 'enable_header_search', true ) ) {
     638        $classes[] = 'enable-search-modal';
     639    }
     640
     641    // Check for post thumbnail.
     642    if ( is_singular() && has_post_thumbnail() ) {
     643        $classes[] = 'has-post-thumbnail';
     644    } elseif ( is_singular() ) {
     645        $classes[] = 'missing-post-thumbnail';
     646    }
     647
     648    // Check whether we're in the customizer preview.
     649    if ( is_customize_preview() ) {
     650        $classes[] = 'customizer-preview';
     651    }
     652
     653    // Check if posts have single pagination.
     654    if ( is_single() && ( get_next_post() || get_previous_post() ) ) {
     655        $classes[] = 'has-single-pagination';
     656    } else {
     657        $classes[] = 'has-no-pagination';
     658    }
     659
     660    // Check if we're showing comments.
     661    if ( $post && ( ( 'post' === $post_type || comments_open() || get_comments_number() ) && ! post_password_required() ) ) {
     662        $classes[] = 'showing-comments';
     663    } else {
     664        $classes[] = 'not-showing-comments';
     665    }
     666
     667    // Check if avatars are visible.
     668    $classes[] = get_option( 'show_avatars' ) ? 'show-avatars' : 'hide-avatars';
     669
     670    // Slim page template class names (class = name - file suffix).
     671    if ( is_page_template() ) {
     672        $classes[] = basename( get_page_template_slug(), '.php' );
     673    }
     674
     675    // Check for the elements output in the top part of the footer.
     676    $has_footer_menu = has_nav_menu( 'footer' );
     677    $has_social_menu = has_nav_menu( 'social' );
     678    $has_sidebar_1   = is_active_sidebar( 'sidebar-1' );
     679    $has_sidebar_2   = is_active_sidebar( 'sidebar-2' );
     680
     681    // Add a class indicating whether those elements are output.
     682    if ( $has_footer_menu || $has_social_menu || $has_sidebar_1 || $has_sidebar_2 ) {
     683        $classes[] = 'footer-top-visible';
     684    } else {
     685        $classes[] = 'footer-top-hidden';
     686    }
     687
     688    // Get header/footer background color.
     689    $header_footer_background = get_theme_mod( 'header_footer_background_color', '#ffffff' );
     690    $header_footer_background = strtolower( '#' . ltrim( $header_footer_background, '#' ) );
     691
     692    // Get content background color.
     693    $background_color = get_theme_mod( 'background_color', 'f5efe0' );
     694    $background_color = strtolower( '#' . ltrim( $background_color, '#' ) );
     695
     696    // Add extra class if main background and header/footer background are the same color.
     697    if ( $background_color === $header_footer_background ) {
     698        $classes[] = 'reduced-spacing';
     699    }
     700
     701    return $classes;
     702
     703}
     704
     705add_filter( 'body_class', 'twentytwenty_body_classes' );
     706
     707/**
     708 * Archives
     709 */
     710/**
    534711 * Filters the archive title and styles the word before the first colon.
    535712 *
    536713 * @param string $title Current archive title.
     714 *
     715 * @return string $title Current archive title.
    537716 */
    538717function twentytwenty_get_the_archive_title( $title ) {
     
    559738
    560739/**
    561  * Filters the edit post link to add an icon and use the post meta structure.
    562  *
    563  * @param string $link    Anchor tag for the edit link.
    564  * @param int    $post_id Post ID.
    565  * @param string $text    Anchor text.
    566  */
    567 function twentytwenty_edit_post_link( $link, $post_id, $text ) {
    568 
    569     $edit_url = get_edit_post_link( $post_id );
    570 
    571     if ( ! $edit_url ) {
    572         return;
    573     }
    574 
    575     return '<div class="post-meta-wrapper post-meta-edit-link-wrapper"><ul class="post-meta"><li class="post-edit meta-wrapper"><span class="meta-icon">' . twentytwenty_get_theme_svg( 'edit' ) . '</span><span class="meta-text"><a href="' . esc_url( $edit_url ) . '">' . $text . '</a></span></li></ul><!-- .post-meta --></div><!-- .post-meta-wrapper -->';
    576 
    577 }
    578 
    579 add_filter( 'edit_post_link', 'twentytwenty_edit_post_link', 10, 3 );
    580 
    581 /**
    582  * Add conditional body classes.
    583  *
    584  * @param string $classes Classes added to the body tag.
    585  */
    586 function twentytwenty_body_classes( $classes ) {
    587 
    588     global $post;
    589     $post_type = isset( $post ) ? $post->post_type : false;
    590 
    591     // Check whether we're singular.
    592     if ( is_singular() ) {
    593         $classes[] = 'singular';
    594     }
    595 
    596     // Check whether the current page should have an overlay header.
    597     if ( is_page_template( array( 'templates/template-cover.php' ) ) ) {
    598         $classes[] = 'overlay-header';
    599     }
    600 
    601     // Check whether the current page has full-width content.
    602     if ( is_page_template( array( 'templates/template-full-width.php' ) ) ) {
    603         $classes[] = 'has-full-width-content';
    604     }
    605 
    606     // Check for enabled search.
    607     if ( true === get_theme_mod( 'enable_header_search', true ) ) {
    608         $classes[] = 'enable-search-modal';
    609     }
    610 
    611     // Check for post thumbnail.
    612     if ( is_singular() && has_post_thumbnail() ) {
    613         $classes[] = 'has-post-thumbnail';
    614     } elseif ( is_singular() ) {
    615         $classes[] = 'missing-post-thumbnail';
    616     }
    617 
    618     // Check whether we're in the customizer preview.
    619     if ( is_customize_preview() ) {
    620         $classes[] = 'customizer-preview';
    621     }
    622 
    623     // Check if posts have single pagination.
    624     if ( is_single() && ( get_next_post() || get_previous_post() ) ) {
    625         $classes[] = 'has-single-pagination';
    626     } else {
    627         $classes[] = 'has-no-pagination';
    628     }
    629 
    630     // Check if we're showing comments.
    631     if ( $post && ( ( 'post' === $post_type || comments_open() || get_comments_number() ) && ! post_password_required() ) ) {
    632         $classes[] = 'showing-comments';
    633     } else {
    634         $classes[] = 'not-showing-comments';
    635     }
    636 
    637     // Check if avatars are visible.
    638     $classes[] = get_option( 'show_avatars' ) ? 'show-avatars' : 'hide-avatars';
    639 
    640     // Slim page template class names (class = name - file suffix).
    641     if ( is_page_template() ) {
    642         $classes[] = basename( get_page_template_slug(), '.php' );
    643     }
    644 
    645     // Check for the elements output in the top part of the footer.
    646     $has_footer_menu = has_nav_menu( 'footer' );
    647     $has_social_menu = has_nav_menu( 'social' );
    648     $has_sidebar_1   = is_active_sidebar( 'sidebar-1' );
    649     $has_sidebar_2   = is_active_sidebar( 'sidebar-2' );
    650 
    651     // Add a class indicating whether those elements are output.
    652     if ( $has_footer_menu || $has_social_menu || $has_sidebar_1 || $has_sidebar_2 ) {
    653         $classes[] = 'footer-top-visible';
    654     } else {
    655         $classes[] = 'footer-top-hidden';
    656     }
    657 
    658     // Get header/footer background color.
    659     $header_footer_background = get_theme_mod( 'header_footer_background_color', '#ffffff' );
    660     $header_footer_background = strtolower( '#' . ltrim( $header_footer_background, '#' ) );
    661 
    662     // Get content background color.
    663     $background_color = get_theme_mod( 'background_color', 'f5efe0' );
    664     $background_color = strtolower( '#' . ltrim( $background_color, '#' ) );
    665 
    666     // Add extra class if main background and header/footer background are the same color.
    667     if ( $background_color === $header_footer_background ) {
    668         $classes[] = 'reduced-spacing';
    669     }
    670 
    671     return $classes;
    672 
    673 }
    674 
    675 add_filter( 'body_class', 'twentytwenty_body_classes' );
    676 
     740 * Miscellaneous
     741 */
    677742/**
    678743 * Toggle animation duration in milliseconds.
     
    692757    return $duration;
    693758}
     759
     760/**
     761 * Get unique ID.
     762 *
     763 * This is a PHP implementation of Underscore's uniqueId method. A static variable
     764 * contains an integer that is incremented with each call. This number is returned
     765 * with the optional prefix. As such the returned value is not universally unique,
     766 * but it is unique across the life of the PHP process.
     767 *
     768 * @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead.
     769 *
     770 * @staticvar int $id_counter
     771 *
     772 * @param string $prefix Prefix for the returned ID.
     773 * @return string Unique ID.
     774 */
     775function twentytwenty_unique_id( $prefix = '' ) {
     776    static $id_counter = 0;
     777    if ( function_exists( 'wp_unique_id' ) ) {
     778        return wp_unique_id( $prefix );
     779    }
     780    return $prefix . (string) ++$id_counter;
     781}
Note: See TracChangeset for help on using the changeset viewer.