Skip to content

Commit

Permalink
Bulk/Quick Edit: Remove duplicate HTML IDs from post list tables.
Browse files Browse the repository at this point in the history
Removes duplicate IDs on the post list admin pages affecting various list items, selects and checkboxes:

* JavaScript duplication of the inline editing HTML for bulk editing renames various IDs to include the prefix `bulk-edit-`,
* IDs in the Category Checkbox Walker make use of `wp_unique_prefixed_id()` to avoid duplicates, resulting in a numeric suffix, and,
* the post parent dropdown for the bulk editor is given a custom ID `bulk_edit_post_parent`.

Props peterwilsoncc, sergeybiryukov, azaozz, joedolson, siliconforks, zodiac1978, rcreators.
Fixes #61014.



git-svn-id: https://develop.svn.wordpress.org/trunk@58894 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
peterwilsoncc committed Aug 13, 2024
1 parent c20224b commit 2061a52
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/js/_enqueues/admin/inline-edit-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,16 @@ window.wp = window.wp || {};
inlineEditPost.edit( this );
});

// Clone quick edit categories for the bulk editor.
var beCategories = $( '#inline-edit fieldset.inline-edit-categories' ).clone();

// Make "id" attributes globally unique.
beCategories.find( '*[id]' ).each( function() {
this.id = 'bulk-edit-' + this.id;
});

$('#bulk-edit').find('fieldset:first').after(
$('#inline-edit fieldset.inline-edit-categories').clone()
beCategories
).siblings( 'fieldset:last' ).prepend(
$( '#inline-edit .inline-edit-tags-wrap' ).clone()
);
Expand Down
2 changes: 1 addition & 1 deletion src/wp-admin/css/list-tables.css
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ tr.inline-edit-row td {
width: 75%;
}

.inline-edit-row #post_parent,
.inline-edit-row select[name="post_parent"],
.inline-edit-row select[name="page_template"] {
max-width: 80%;
}
Expand Down
10 changes: 6 additions & 4 deletions src/wp-admin/includes/class-walker-category-checklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ public function start_el( &$output, $data_object, $depth = 0, $args = array(), $
/** This filter is documented in wp-includes/category-template.php */
esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>';
} else {
$is_selected = in_array( $category->term_id, $args['selected_cats'], true );
$is_disabled = ! empty( $args['disabled'] );
$is_selected = in_array( $category->term_id, $args['selected_cats'], true );
$is_disabled = ! empty( $args['disabled'] );
$li_element_id = wp_unique_prefixed_id( "in-{$taxonomy}-{$category->term_id}-" );
$checkbox_element_id = wp_unique_prefixed_id( "in-{$taxonomy}-{$category->term_id}-" );

$output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
'<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
$output .= "\n<li id='" . esc_attr( $li_element_id ) . "'$class>" .
'<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="' . esc_attr( $checkbox_element_id ) . '"' .
checked( $is_selected, true, false ) .
disabled( $is_disabled, true, false ) . ' /> ' .
/** This filter is documented in wp-includes/category-template.php */
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1842,6 +1842,7 @@ public function inline_edit() {

if ( $bulk ) {
$dropdown_args['show_option_no_change'] = __( '&mdash; No Change &mdash;' );
$dropdown_args['id'] = 'bulk_edit_post_parent';
}

/**
Expand Down

0 comments on commit 2061a52

Please sign in to comment.