Changeset 46236
- Timestamp:
- 09/22/2019 10:31:34 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/link-template.php
r46232 r46236 2545 2545 * @since 4.1.0 2546 2546 * @since 4.4.0 Introduced the `in_same_term`, `excluded_terms`, and `taxonomy` arguments. 2547 * @since 5.3.0 Added the `aria_label` parameter. 2547 2548 * 2548 2549 * @param array $args { … … 2554 2555 * @type array|string $excluded_terms Array or comma-separated list of excluded term IDs. Default empty. 2555 2556 * @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. 2556 * @type string $screen_reader_text Screen reader text for nav element. Default 'Post navigation'. 2557 * @type string $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'. 2558 * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. 2557 2559 * } 2558 2560 * @return string Markup for post links. 2559 2561 */ 2560 2562 function get_the_post_navigation( $args = array() ) { 2563 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. 2564 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 2565 $args['aria_label'] = $args['screen_reader_text']; 2566 } 2567 2561 2568 $args = wp_parse_args( 2562 2569 $args, … … 2568 2575 'taxonomy' => 'category', 2569 2576 'screen_reader_text' => __( 'Post navigation' ), 2577 'aria_label' => __( 'Posts' ), 2570 2578 ) 2571 2579 ); … … 2591 2599 // Only add markup if there's somewhere to navigate to. 2592 2600 if ( $previous || $next ) { 2593 $navigation = _navigation_markup( $previous . $next, 'post-navigation', $args['screen_reader_text'] );2601 $navigation = _navigation_markup( $previous . $next, 'post-navigation', $args['screen_reader_text'], $args['aria_label'] ); 2594 2602 } 2595 2603 … … 2613 2621 * 2614 2622 * @since 4.1.0 2623 * @since 5.3.0 Added the `aria_label` parameter. 2615 2624 * 2616 2625 * @global WP_Query $wp_query WordPress Query object. … … 2623 2632 * @type string $next_text Anchor text to display in the next posts link. 2624 2633 * Default 'Newer posts'. 2625 * @type string $screen_reader_text Screen reader text for nav element.2634 * @type string $screen_reader_text Screen reader text for the nav element. 2626 2635 * Default 'Posts navigation'. 2636 * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. 2627 2637 * } 2628 2638 * @return string Markup for posts links. … … 2633 2643 // Don't print empty markup if there's only one page. 2634 2644 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { 2645 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. 2646 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 2647 $args['aria_label'] = $args['screen_reader_text']; 2648 } 2649 2635 2650 $args = wp_parse_args( 2636 2651 $args, … … 2639 2654 'next_text' => __( 'Newer posts' ), 2640 2655 'screen_reader_text' => __( 'Posts navigation' ), 2656 'aria_label' => __( 'Posts' ), 2641 2657 ) 2642 2658 ); … … 2653 2669 } 2654 2670 2655 $navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'] );2671 $navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'], $args['aria_label'] ); 2656 2672 } 2657 2673 … … 2675 2691 * 2676 2692 * @since 4.1.0 2693 * @since 5.3.0 Added the `aria_label` parameter. 2677 2694 * 2678 2695 * @param array $args { … … 2681 2698 * @type string $screen_reader_text Screen reader text for navigation element. 2682 2699 * Default 'Posts navigation'. 2700 * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. 2683 2701 * } 2684 2702 * @return string Markup for pagination links. … … 2689 2707 // Don't print empty markup if there's only one page. 2690 2708 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { 2709 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. 2710 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 2711 $args['aria_label'] = $args['screen_reader_text']; 2712 } 2713 2691 2714 $args = wp_parse_args( 2692 2715 $args, … … 2696 2719 'next_text' => _x( 'Next', 'next set of posts' ), 2697 2720 'screen_reader_text' => __( 'Posts navigation' ), 2721 'aria_label' => __( 'Posts' ), 2698 2722 ) 2699 2723 ); … … 2708 2732 2709 2733 if ( $links ) { 2710 $navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'] );2734 $navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'], $args['aria_label'] ); 2711 2735 } 2712 2736 } … … 2731 2755 * 2732 2756 * @since 4.1.0 2757 * @since 5.3.0 Added the `aria_label` parameter. 2733 2758 * @access private 2734 2759 * 2735 2760 * @param string $links Navigational links. 2736 * @param string $class Optional. Custom class for nav element. Default: 'posts-navigation'. 2737 * @param string $screen_reader_text Optional. Screen reader text for nav element. Default: 'Posts navigation'. 2761 * @param string $class Optional. Custom class for the nav element. Default: 'posts-navigation'. 2762 * @param string $screen_reader_text Optional. Screen reader text for the nav element. Default: 'Posts navigation'. 2763 * @param string $aria_label Optional. ARIA label for the nav element. Default: same value as $screen_reader_text. 2738 2764 * @return string Navigation template tag. 2739 2765 */ 2740 function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '' ) {2766 function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) { 2741 2767 if ( empty( $screen_reader_text ) ) { 2742 2768 $screen_reader_text = __( 'Posts navigation' ); 2743 2769 } 2770 if ( empty( $aria_label ) ) { 2771 $aria_label = $screen_reader_text; 2772 } 2744 2773 2745 2774 $template = ' 2746 <nav class="navigation %1$s" role="navigation" >2775 <nav class="navigation %1$s" role="navigation" aria-label="%4$s"> 2747 2776 <h2 class="screen-reader-text">%2$s</h2> 2748 2777 <div class="nav-links">%3$s</div> … … 2753 2782 * 2754 2783 * Note: The filtered template HTML must contain specifiers for the navigation 2755 * class (%1$s), the screen-reader-text value (%2$s), and placement of the2756 * navigation links (%3$s):2757 * 2758 * <nav class="navigation %1$s" role="navigation" >2784 * class (%1$s), the screen-reader-text value (%2$s), placement of the navigation 2785 * links (%3$s), and ARIA label text if screen-reader-text does not fit that (%4$s): 2786 * 2787 * <nav class="navigation %1$s" role="navigation" aria-label="%4$s"> 2759 2788 * <h2 class="screen-reader-text">%2$s</h2> 2760 2789 * <div class="nav-links">%3$s</div> … … 2769 2798 $template = apply_filters( 'navigation_markup_template', $template, $class ); 2770 2799 2771 return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links );2800 return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) ); 2772 2801 } 2773 2802 … … 2978 3007 * 2979 3008 * @since 4.4.0 3009 * @since 5.3.0 Added the `aria_label` parameter. 2980 3010 * 2981 3011 * @param array $args { … … 2986 3016 * @type string $next_text Anchor text to display in the next comments link. 2987 3017 * Default 'Newer comments'. 2988 * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. 3018 * @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'. 3019 * @type string $aria_label ARIA label text for the nav element. Default 'Comments'. 2989 3020 * } 2990 3021 * @return string Markup for comments links. … … 2995 3026 // Are there comments to navigate through? 2996 3027 if ( get_comment_pages_count() > 1 ) { 3028 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. 3029 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 3030 $args['aria_label'] = $args['screen_reader_text']; 3031 } 3032 2997 3033 $args = wp_parse_args( 2998 3034 $args, … … 3001 3037 'next_text' => __( 'Newer comments' ), 3002 3038 'screen_reader_text' => __( 'Comments navigation' ), 3039 'aria_label' => __( 'Comments' ), 3003 3040 ) 3004 3041 ); … … 3015 3052 } 3016 3053 3017 $navigation = _navigation_markup( $navigation, 'comment-navigation', $args['screen_reader_text'] );3054 $navigation = _navigation_markup( $navigation, 'comment-navigation', $args['screen_reader_text'], $args['aria_label'] ); 3018 3055 } 3019 3056 … … 3036 3073 * 3037 3074 * @since 4.4.0 3075 * @since 5.3.0 Added the `aria_label` parameter. 3038 3076 * 3039 3077 * @see paginate_comments_links() … … 3042 3080 * Optional. Default pagination arguments. 3043 3081 * 3044 * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. 3082 * @type string $screen_reader_text Screen reader text for the nav element. Default 'Comments navigation'. 3083 * @type string $aria_label ARIA label text for the nav element. Default 'Comments'. 3045 3084 * } 3046 3085 * @return string Markup for pagination links. 3047 3086 */ 3048 3087 function get_the_comments_pagination( $args = array() ) { 3049 $navigation = ''; 3088 $navigation = ''; 3089 3090 // Make sure the nav element has an aria-label attribute: fallback to the screen reader text. 3091 if ( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 3092 $args['aria_label'] = $args['screen_reader_text']; 3093 } 3094 3050 3095 $args = wp_parse_args( 3051 3096 $args, 3052 3097 array( 3053 3098 'screen_reader_text' => __( 'Comments navigation' ), 3099 'aria_label' => __( 'Comments' ), 3054 3100 ) 3055 3101 ); … … 3064 3110 3065 3111 if ( $links ) { 3066 $navigation = _navigation_markup( $links, 'comments-pagination', $args['screen_reader_text'] );3112 $navigation = _navigation_markup( $links, 'comments-pagination', $args['screen_reader_text'], $args['aria_label'] ); 3067 3113 } 3068 3114
Note: See TracChangeset
for help on using the changeset viewer.