Ticket #47123: 47123.diff
| File 47123.diff, 8.7 KB (added by , 6 years ago) |
|---|
-
src/wp-includes/link-template.php
2546 2546 * @type array|string $excluded_terms Array or comma-separated list of excluded term IDs. Default empty. 2547 2547 * @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. 2548 2548 * @type string $screen_reader_text Screen reader text for nav element. Default 'Post navigation'. 2549 * @type string $aria_label ARIA label text for nav element. Default 'Posts'. 2549 2550 * } 2550 2551 * @return string Markup for post links. 2551 2552 */ 2552 2553 function get_the_post_navigation( $args = array() ) { 2554 // Is screen_reader_text customized but not aria_label? 2555 if( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 2556 $args['aria_label'] = $args['screen_reader_text']; 2557 } 2558 2553 2559 $args = wp_parse_args( 2554 2560 $args, 2555 2561 array( … … 2559 2565 'excluded_terms' => '', 2560 2566 'taxonomy' => 'category', 2561 2567 'screen_reader_text' => __( 'Post navigation' ), 2568 'aria_label' => __( 'Posts' ), 2562 2569 ) 2563 2570 ); 2564 2571 … … 2582 2589 2583 2590 // Only add markup if there's somewhere to navigate to. 2584 2591 if ( $previous || $next ) { 2585 $navigation = _navigation_markup( $previous . $next, 'post-navigation', $args['screen_reader_text'] );2592 $navigation = _navigation_markup( $previous . $next, 'post-navigation', $args['screen_reader_text'], $args['aria_label'] ); 2586 2593 } 2587 2594 2588 2595 return $navigation; … … 2616 2623 * Default 'Newer posts'. 2617 2624 * @type string $screen_reader_text Screen reader text for nav element. 2618 2625 * Default 'Posts navigation'. 2626 * @type string $aria_label ARIA label text for nav element. 2627 * Default 'Posts'. 2619 2628 * } 2620 2629 * @return string Markup for posts links. 2621 2630 */ … … 2624 2633 2625 2634 // Don't print empty markup if there's only one page. 2626 2635 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { 2636 // Is screen_reader_text customized but not aria_label? 2637 if( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 2638 $args['aria_label'] = $args['screen_reader_text']; 2639 } 2640 2627 2641 $args = wp_parse_args( 2628 2642 $args, 2629 2643 array( 2630 2644 'prev_text' => __( 'Older posts' ), 2631 2645 'next_text' => __( 'Newer posts' ), 2632 2646 'screen_reader_text' => __( 'Posts navigation' ), 2647 'aria_label' => __( 'Posts' ), 2633 2648 ) 2634 2649 ); 2635 2650 … … 2644 2659 $navigation .= '<div class="nav-next">' . $next_link . '</div>'; 2645 2660 } 2646 2661 2647 $navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'] );2662 $navigation = _navigation_markup( $navigation, 'posts-navigation', $args['screen_reader_text'], $args['aria_label'] ); 2648 2663 } 2649 2664 2650 2665 return $navigation; … … 2672 2687 * 2673 2688 * @type string $screen_reader_text Screen reader text for navigation element. 2674 2689 * Default 'Posts navigation'. 2690 * @type string $aria_label ARIA label text for nav element. 2691 * Default 'Posts'. 2675 2692 * } 2676 2693 * @return string Markup for pagination links. 2677 2694 */ … … 2680 2697 2681 2698 // Don't print empty markup if there's only one page. 2682 2699 if ( $GLOBALS['wp_query']->max_num_pages > 1 ) { 2700 // Is screen_reader_text customized but not aria_label? 2701 if( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 2702 $args['aria_label'] = $args['screen_reader_text']; 2703 } 2704 2683 2705 $args = wp_parse_args( 2684 2706 $args, 2685 2707 array( … … 2687 2709 'prev_text' => _x( 'Previous', 'previous set of posts' ), 2688 2710 'next_text' => _x( 'Next', 'next set of posts' ), 2689 2711 'screen_reader_text' => __( 'Posts navigation' ), 2712 'aria_label' => __( 'Posts' ), 2690 2713 ) 2691 2714 ); 2692 2715 … … 2699 2722 $links = paginate_links( $args ); 2700 2723 2701 2724 if ( $links ) { 2702 $navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'] );2725 $navigation = _navigation_markup( $links, 'pagination', $args['screen_reader_text'], $args['aria_label'] ); 2703 2726 } 2704 2727 } 2705 2728 … … 2727 2750 * @param string $links Navigational links. 2728 2751 * @param string $class Optional. Custom class for nav element. Default: 'posts-navigation'. 2729 2752 * @param string $screen_reader_text Optional. Screen reader text for nav element. Default: 'Posts navigation'. 2753 * @param string $aria_label Optional. ARIA label for nav element. Default: same value as $screen_reader_text. 2730 2754 * @return string Navigation template tag. 2731 2755 */ 2732 function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '' ) {2756 function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) { 2733 2757 if ( empty( $screen_reader_text ) ) { 2734 2758 $screen_reader_text = __( 'Posts navigation' ); 2735 2759 } 2760 if ( empty( $aria_label ) ) { 2761 $aria_label = $screen_reader_text; 2762 } 2736 2763 2737 2764 $template = ' 2738 <nav class="navigation %1$s" role="navigation" >2765 <nav class="navigation %1$s" role="navigation" aria-label="%4$s"> 2739 2766 <h2 class="screen-reader-text">%2$s</h2> 2740 2767 <div class="nav-links">%3$s</div> 2741 2768 </nav>'; … … 2744 2771 * Filters the navigation markup template. 2745 2772 * 2746 2773 * Note: The filtered template HTML must contain specifiers for the navigation 2747 * class (%1$s), the screen-reader-text value (%2$s), and placement of the2748 * navigation links (%3$s):2774 * class (%1$s), the screen-reader-text value (%2$s), placement of the navigation 2775 * links (%3$s), and ARIA label text if screen-reader-text does not fit that (%4$s): 2749 2776 * 2750 * <nav class="navigation %1$s" role="navigation" >2777 * <nav class="navigation %1$s" role="navigation" aria-label="%4$s"> 2751 2778 * <h2 class="screen-reader-text">%2$s</h2> 2752 2779 * <div class="nav-links">%3$s</div> 2753 2780 * </nav> … … 2760 2787 */ 2761 2788 $template = apply_filters( 'navigation_markup_template', $template, $class ); 2762 2789 2763 return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links );2790 return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) ); 2764 2791 } 2765 2792 2766 2793 /** … … 2978 3005 * @type string $next_text Anchor text to display in the next comments link. 2979 3006 * Default 'Newer comments'. 2980 3007 * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. 3008 * @type string $aria_label ARIA label text for nav element. Default 'Comments'. 2981 3009 * } 2982 3010 * @return string Markup for comments links. 2983 3011 */ … … 2986 3014 2987 3015 // Are there comments to navigate through? 2988 3016 if ( get_comment_pages_count() > 1 ) { 3017 // Is screen_reader_text customized but not aria_label? 3018 if( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 3019 $args['aria_label'] = $args['screen_reader_text']; 3020 } 3021 2989 3022 $args = wp_parse_args( 2990 3023 $args, 2991 3024 array( 2992 3025 'prev_text' => __( 'Older comments' ), 2993 3026 'next_text' => __( 'Newer comments' ), 2994 3027 'screen_reader_text' => __( 'Comments navigation' ), 3028 'aria_label' => __( 'Comments' ), 2995 3029 ) 2996 3030 ); 2997 3031 … … 3006 3040 $navigation .= '<div class="nav-next">' . $next_link . '</div>'; 3007 3041 } 3008 3042 3009 $navigation = _navigation_markup( $navigation, 'comment-navigation', $args['screen_reader_text'] );3043 $navigation = _navigation_markup( $navigation, 'comment-navigation', $args['screen_reader_text'], $args['aria_label'] ); 3010 3044 } 3011 3045 3012 3046 return $navigation; … … 3034 3068 * Optional. Default pagination arguments. 3035 3069 * 3036 3070 * @type string $screen_reader_text Screen reader text for nav element. Default 'Comments navigation'. 3071 * @type string $aria_label ARIA label text for nav element. Default 'Comments'. 3037 3072 * } 3038 3073 * @return string Markup for pagination links. 3039 3074 */ 3040 3075 function get_the_comments_pagination( $args = array() ) { 3041 3076 $navigation = ''; 3077 3078 // Is screen_reader_text customized but not aria_label? 3079 if( ! empty( $args['screen_reader_text'] ) && empty( $args['aria_label'] ) ) { 3080 $args['aria_label'] = $args['screen_reader_text']; 3081 } 3082 3042 3083 $args = wp_parse_args( 3043 3084 $args, 3044 3085 array( 3045 3086 'screen_reader_text' => __( 'Comments navigation' ), 3087 'aria_label' => __( 'Comments' ), 3046 3088 ) 3047 3089 ); 3048 3090 $args['echo'] = false; … … 3055 3097 $links = paginate_comments_links( $args ); 3056 3098 3057 3099 if ( $links ) { 3058 $navigation = _navigation_markup( $links, 'comments-pagination', $args['screen_reader_text'] );3100 $navigation = _navigation_markup( $links, 'comments-pagination', $args['screen_reader_text'], $args['aria_label'] ); 3059 3101 } 3060 3102 3061 3103 return $navigation;