Make WordPress Core

Ticket #51256: 51256.patch

File 51256.patch, 1.5 KB (added by kishanjasani, 5 years ago)

Add a validation to restrict same ID generation

  • wp-admin/includes/class-wp-plugins-list-table.php

    diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php
    index e487e32cfb..cc76e0e53d 100644
    a b class WP_Plugins_List_Table extends WP_List_Table { 
    946946                $requires_php   = isset( $plugin_data['requires_php'] ) ? $plugin_data['requires_php'] : null;
    947947                $compatible_php = is_php_version_compatible( $requires_php );
    948948                $class          = $is_active ? 'active' : 'inactive';
    949                 $checkbox_id    = 'checkbox_' . md5( $plugin_data['Name'] );
     949
     950                static $checkbox_id_attrs = array();
     951
     952                $checkbox_id      = 'checkbox_' . md5( $plugin_data['Name'] );
     953                $checkbox_id_attr = $checkbox_id;
     954
     955                // Ensure the ID attribute is unique.
     956                $suffix = 2;
     957                while ( in_array( $checkbox_id_attr, $checkbox_id_attrs, true ) ) {
     958                        $checkbox_id_attr = "$checkbox_id-$suffix";
     959                        $suffix++;
     960                }
     961
     962                $checkbox_id_attrs[] = $checkbox_id_attr;
     963
    950964                if ( $restrict_network_active || $restrict_network_only || in_array( $status, array( 'mustuse', 'dropins' ), true ) || ! $compatible_php ) {
    951965                        $checkbox = '';
    952966                } else {
    953967                        $checkbox = sprintf(
    954968                                '<label class="screen-reader-text" for="%1$s">%2$s</label>' .
    955969                                '<input type="checkbox" name="checked[]" value="%3$s" id="%1$s" />',
    956                                 $checkbox_id,
     970                                $checkbox_id_attr,
    957971                                /* translators: %s: Plugin name. */
    958972                                sprintf( __( 'Select %s' ), $plugin_data['Name'] ),
    959973                                esc_attr( $plugin_file )