- Timestamp:
- 10/08/2019 07:05:53 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentytwenty/inc/template-tags.php
r46357 r46445 10 10 /** 11 11 * Table of Contents: 12 * Logo & Description 12 13 * Comments 13 14 * Post Meta 14 15 * Menus 15 16 * Classes 16 */ 17 17 * Archives 18 * Miscellaneous 19 */ 20 21 /** 22 * Logo & Description 23 */ 18 24 /** 19 25 * Displays the site logo, either text or image. 20 26 * 21 27 * @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. 23 31 */ 24 32 function twentytwenty_site_logo( $args = array(), $echo = true ) { … … 82 90 * 83 91 * @param boolean $echo Echo or return the html. 92 * 93 * @return string $html The HTML to display. 84 94 */ 85 95 function twentytwenty_site_description( $echo = true ) { … … 119 129 * 120 130 * @param object $comment Comment data. 131 * 132 * @return bool 121 133 */ 122 134 function twentytwenty_is_comment_by_post_author( $comment = null ) { … … 143 155 * 144 156 * @param string $link Link to the top of the page. 157 * 158 * @return string $link Link to the top of the page. 145 159 */ 146 160 function twentytwenty_filter_comment_reply_link( $link ) { … … 168 182 169 183 } 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 */ 192 function 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 217 add_filter( 'edit_post_link', 'twentytwenty_edit_post_link', 10, 3 ); 170 218 171 219 /** … … 207 255 * Filters post meta info visibility 208 256 * 209 * Use this filter to hide post meta information like Author, Post date, Comments, Is sti ky status257 * Use this filter to hide post meta information like Author, Post date, Comments, Is sticky status 210 258 * 211 259 * @since 1.0.0 … … 290 338 <li class="post-author meta-wrapper"> 291 339 <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> 293 341 <?php twentytwenty_the_theme_svg( 'user' ); ?> 294 342 </span> … … 296 344 <?php 297 345 printf( 298 / / Translators: %s = the author name.299 _ x( 'By %s', '%s = author name', 'twentytwenty' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- core trusts translations346 /* translators: %s: Author name */ 347 __( 'By %s', 'twentytwenty' ), 300 348 '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author_meta( 'display_name' ) ) . '</a>' 301 349 ); … … 315 363 <a class="meta-wrapper" href="<?php the_permalink(); ?>"> 316 364 <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> 318 366 <?php twentytwenty_the_theme_svg( 'calendar' ); ?> 319 367 </span> … … 334 382 <li class="post-categories meta-wrapper"> 335 383 <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> 337 385 <?php twentytwenty_the_theme_svg( 'folder' ); ?> 338 386 </span> 339 387 <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( ', ' ); ?> 341 389 </span> 342 390 </li> … … 352 400 <li class="post-tags meta-wrapper"> 353 401 <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> 355 403 <?php twentytwenty_the_theme_svg( 'tag' ); ?> 356 404 </span> … … 390 438 </span> 391 439 <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' ); ?> 393 441 </span> 394 442 </li> … … 438 486 * styling of sub levels in the fallback. Only applied if the match_menu_classes argument is set. 439 487 * 440 * @param string$css_class CSS Class names.488 * @param array $css_class CSS Class names. 441 489 * @param string $item Comment. 442 490 * @param int $depth Depth of the current comment. 443 491 * @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. 445 495 */ 446 496 function twentytwenty_filter_wp_list_pages_item_classes( $css_class, $item, $depth, $args, $current_page ) { … … 472 522 * Add a Sub Nav Toggle to the Expanded Menu and Mobile Menu. 473 523 * 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. 477 529 */ 478 530 function twentytwenty_add_sub_toggles_to_main_menu( $args, $item, $depth ) { … … 515 567 516 568 /** 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 */ 577 function 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 590 add_filter( 'walker_nav_menu_start_el', 'twentytwenty_nav_menu_social_icons', 10, 4 ); 591 592 /** 517 593 * Classes 518 594 */ … … 532 608 533 609 /** 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 */ 616 function 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 705 add_filter( 'body_class', 'twentytwenty_body_classes' ); 706 707 /** 708 * Archives 709 */ 710 /** 534 711 * Filters the archive title and styles the word before the first colon. 535 712 * 536 713 * @param string $title Current archive title. 714 * 715 * @return string $title Current archive title. 537 716 */ 538 717 function twentytwenty_get_the_archive_title( $title ) { … … 559 738 560 739 /** 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 */ 677 742 /** 678 743 * Toggle animation duration in milliseconds. … … 692 757 return $duration; 693 758 } 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 */ 775 function 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.