[wp-trac] [WordPress Trac] #30319: Twenty Fifteen: Incorrect use of sprintf() and _x() in template-tags.php

WordPress Trac noreply at wordpress.org
Wed Nov 12 10:44:45 UTC 2014


#30319: Twenty Fifteen: Incorrect use of sprintf() and _x() in template-tags.php
--------------------------+-----------------------------
 Reporter:  aprea         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Themes        |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The current `/inc/template-tags.php` has several incorrect uses of
 `sprintf()` and `_x`, see example below:

 {{{
 if ( is_attachment() && wp_attachment_is_image() ) {
         // Retrieve attachment metadata.
         $metadata = wp_get_attachment_metadata();

         printf( '<span class="full-size-link">%1$s<a href="%2$s">%3$s
 × %4$s</a></span>',
                 sprintf( _x( '<span class="screen-reader-text">Full
 size</span>', 'Used before full size attachment link.', 'twentyfifteen' )
 ),
                 esc_url( wp_get_attachment_url() ),
                 $metadata['width'],
                 $metadata['height']
         );
 }
 }}}

 Two problems here:

 1. `sprintf()` is only passing 1 argument.
 2. `_x()` includes HTML markup in the replacement text.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30319>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list