[wp-trac] [WordPress Trac] #28090: Multiple add media buttons all have same ID attribute

WordPress Trac noreply at wordpress.org
Thu May 1 10:32:25 UTC 2014


#28090: Multiple add media buttons all have same ID attribute
----------------------------+-----------------------------
 Reporter:  helgatheviking  |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  General         |    Version:  3.9
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 If you add an editor to a metabox (using `wp_editor()`) and that editor
 has media buttons then the content's media buttons and the ''new'' media
 buttons have the same ID, because the media buttons link has the same ID
 no matter what, which is invalid markup.

 The source of the problem is the `media_buttons()` function:

 {{{
 /**
  * Adds the media button to the editor
  *
  * @since 2.5.0
  *
  * @param string $editor_id
  */
 function media_buttons($editor_id = 'content') {
         $post = get_post();
         if ( ! $post && ! empty( $GLOBALS['post_ID'] ) )
                 $post = $GLOBALS['post_ID'];

         wp_enqueue_media( array(
                 'post' => $post
         ) );

         $img = '<span class="wp-media-buttons-icon"></span> ';

         echo '<a href="#" id="insert-media-button" class="button insert-
 media add_media" data-editor="' . esc_attr( $editor_id ) . '" title="' .
 esc_attr__( 'Add Media' ) . '">' . $img . __( 'Add Media' ) . '</a>';

         /**
          * Filter the legacy (pre-3.5.0) media buttons.
          *
          * @since 2.5.0
          * @deprecated 3.5.0 Use 'media_buttons' action instead.
          *
          * @param string $string Media buttons context. Default empty.
          */
         $legacy_filter = apply_filters( 'media_buttons_context', '' );

         if ( $legacy_filter ) {
                 // #WP22559. Close <a> if a plugin started by closing <a>
 to open their own <a> tag.
                 if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) )
                         $legacy_filter .= '</a>';
                 echo $legacy_filter;
         }
 }
 add_action( 'media_buttons', 'media_buttons' );
 }}}

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


More information about the wp-trac mailing list