Opened 11 years ago
Closed 10 years ago
#28090 closed defect (bug) (fixed)
Multiple add media buttons all have same ID attribute
Reported by: | helgatheviking | Owned by: | helen |
---|---|---|---|
Milestone: | 4.0 | Priority: | normal |
Severity: | minor | Version: | 3.5 |
Component: | Media | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
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' );
Attachments (3)
Change History (16)
#6
@
10 years ago
- Owner set to wonderboymusic
- Resolution set to fixed
- Status changed from new to closed
In 28837:
#7
follow-up:
↓ 8
@
10 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
I suspect someone may be relying on the first button being insert-media-button. I have two alternative solutions:
- Is there a reason why IDs are needed at all here for all subsequent instances?
- Or, can we make it so the first one is insert-media-button, and all later ones receive an ID appended?
#8
in reply to:
↑ 7
@
10 years ago
- Is there a reason why IDs are needed at all here for all subsequent instances?
Sounds like an ID is required for tabfocus.
- Or, can we make it so the first one is insert-media-button, and all later ones receive an ID appended?
Agree.
#9
@
10 years ago
attachment:28090.2.diff sets the first button's id to insert-media-button
, subsequent button ids to insert-media-button-1
, -2
, etc.
I briefly considered starting at -2
, but it implied that there should be a -1
somewhere.
#10
@
10 years ago
- Keywords commit added
Let's go with 28090.3.diff. Another core or lead dev can come by and commit this if it suits them.
#11
@
10 years ago
- Owner changed from wonderboymusic to helen
- Status changed from reopened to assigned
Fine to be committed.
We can't get rid of an ID here, since we need a unique identifier to pass to the
wp_editor()
options hash fortabfocus_elements
.In attachment:28090.diff, introduce a $static variable to keep track of the ID attribute for the anchor, and set
tabfocus_elements
toinsert-media-button-1
in edit-form-advanced.php.