Make WordPress Core

Ticket #38659: 38659.patch

File 38659.patch, 2.4 KB (added by sami.keijonen, 8 years ago)
  • src/wp-content/themes/twentyseventeen/inc/icon-functions.php

     
    4949                'icon'        => '',
    5050                'title'       => '',
    5151                'desc'        => '',
    52                 'aria_hidden' => true, // Hide from screen readers.
    5352                'fallback'    => false,
    5453        );
    5554
     
    5756        $args = wp_parse_args( $args, $defaults );
    5857
    5958        // Set aria hidden.
    60         $aria_hidden = '';
     59        $aria_hidden = ' aria-hidden="true"';
    6160
    62         if ( true === $args['aria_hidden'] ) {
    63                 $aria_hidden = ' aria-hidden="true"';
    64         }
    65 
    6661        // Set ARIA.
    6762        $aria_labelledby = '';
    6863
    6964        if ( $args['title'] && $args['desc'] ) {
    70                 $aria_labelledby = ' aria-labelledby="title desc"';
     65                $unique_id       = uniqid();
     66                $aria_labelledby = ' aria-labelledby="title-' . $unique_id . ' desc-' . $unique_id . '"';
     67                $aria_hidden     = '';
    7168        }
    7269
    7370        // Begin SVG markup.
    7471        $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . $aria_labelledby . ' role="img">';
    7572
    76         // If there is a title, display it.
    77         if ( $args['title'] ) {
    78                 $svg .= '<title>' . esc_html( $args['title'] ) . '</title>';
     73        // If there is title and description, display them.
     74        if ( $args['title'] && $args['desc'] ) {
     75                $svg .= '<title id="title-' . $unique_id . '">' . esc_html( $args['title'] ) . '</title>';
     76                $svg .= '<desc id="desc-' . $unique_id . '">' . esc_html( $args['desc'] ) . '</desc>';
    7977        }
    8078
    81         // If there is a description, display it.
    82         if ( $args['desc'] ) {
    83                 $svg .= '<desc>' . esc_html( $args['desc'] ) . '</desc>';
    84         }
     79        /*
     80         * Display the icon.
     81         *
     82         * The whitespace around `<use>` is intentional. See https://core.trac.wordpress.org/ticket/38387.
     83         */
     84        $svg .= ' <use xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> ';
    8585
    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         }
    92 
    9386        // Add some markup to use as a fallback for browsers that do not support SVGs.
    9487        if ( $args['fallback'] ) {
    9588                $svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>';