Ticket #38659: 38659.1.patch
File 38659.1.patch, 3.2 KB (added by , 8 years ago) |
---|
-
src/wp-content/themes/twentyseventeen/inc/icon-functions.php
49 49 'icon' => '', 50 50 'title' => '', 51 51 'desc' => '', 52 'aria_hidden' => true, // Hide from screen readers.53 52 'fallback' => false, 54 53 ); 55 54 … … 57 56 $args = wp_parse_args( $args, $defaults ); 58 57 59 58 // Set aria hidden. 60 $aria_hidden = ' ';59 $aria_hidden = ' aria-hidden="true"'; 61 60 62 if ( true === $args['aria_hidden'] ) {63 $aria_hidden = ' aria-hidden="true"';64 }65 66 61 // Set ARIA. 67 62 $aria_labelledby = ''; 68 63 69 if ( $args['title'] && $args['desc'] ) { 70 $aria_labelledby = ' aria-labelledby="title desc"'; 64 /* 65 * Twentyseventeen doesn't use title or description anywhere in the theme because all the icons are decorative. 66 * 67 * But child themes can use title and desc arguments for none decorative icons in accessible way. 68 * 69 * Example 1 with title: <?php echo twentyseventeen_get_svg( array( 'icon' => 'arrow-right', 'title' => __( 'This is title', 'textdomain' ) ) ); ?> 70 * 71 * Example 2 with title and desc: <?php echo twentyseventeen_get_svg( array( 'icon' => 'arrow-right', 'title' => __( 'This is title', 'textdomain' ), 'desc' => __( 'This is longer desc', 'textdomain' ) ) ); ?> 72 * 73 * See https://www.paciellogroup.com/blog/2013/12/using-aria-enhance-svg-accessibility/. 74 */ 75 if ( $args['title'] ) { 76 $aria_hidden = ''; 77 $unique_id = uniqid(); 78 $aria_labelledby = ' aria-labelledby="title-' . $unique_id . '"'; 79 80 if ( $args['desc'] ) { 81 $aria_labelledby = ' aria-labelledby="title-' . $unique_id . ' desc-' . $unique_id . '"'; 82 } 71 83 } 72 84 73 85 // Begin SVG markup. 74 86 $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . $aria_labelledby . ' role="img">'; 75 87 76 // If there is a title, display it.88 // Display the title. 77 89 if ( $args['title'] ) { 78 $svg .= '<title>' . esc_html( $args['title'] ) . '</title>'; 79 } 90 $svg .= '<title id="title-' . $unique_id . '">' . esc_html( $args['title'] ) . '</title>'; 80 91 81 // If there is a description, display it. 82 if ( $args['desc'] ) { 83 $svg .= '<desc>' . esc_html( $args['desc'] ) . '</desc>'; 92 // Display the desc only if the title is already set. 93 if ( $args['desc'] ) { 94 $svg .= '<desc id="desc-' . $unique_id . '">' . esc_html( $args['desc'] ) . '</desc>'; 95 } 84 96 } 85 97 86 / / Use absolute path in the Customizer so that icons show up in there.87 if ( is_customize_preview() ) {88 $svg .= '<use xlink:href="' . get_parent_theme_file_uri( '/assets/images/svg-icons.svg#icon-' . esc_html( $args['icon'] ) ) . '"></use>';89 } else {90 $svg .= '<use xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use>';91 }98 /* 99 * Display the icon. 100 * 101 * The whitespace around `<use>` is intentional. See https://core.trac.wordpress.org/ticket/38387. 102 */ 103 $svg .= ' <use xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> '; 92 104 93 105 // Add some markup to use as a fallback for browsers that do not support SVGs. 94 106 if ( $args['fallback'] ) {