From 41e572858dd1271ab1ae739d61702f63081ea9c4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 7 Jul 2020 13:41:30 +0000 Subject: [PATCH] Plugins: Make sure the HTML ID attributes in plugin action links are unique. Follow-up to [47588]. Props mukesh27, roytanck, SergeyBiryukov. Fixes #49916. git-svn-id: https://develop.svn.wordpress.org/trunk@48374 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-plugins-list-table.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/wp-admin/includes/class-wp-plugins-list-table.php b/src/wp-admin/includes/class-wp-plugins-list-table.php index f257354db6..29e5882434 100644 --- a/src/wp-admin/includes/class-wp-plugins-list-table.php +++ b/src/wp-admin/includes/class-wp-plugins-list-table.php @@ -677,10 +677,21 @@ class WP_Plugins_List_Table extends WP_List_Table { */ public function single_row( $item ) { global $status, $page, $s, $totals; + static $plugin_id_attrs = array(); list( $plugin_file, $plugin_data ) = $item; - $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_data['Name'] ); + $plugin_slug = isset( $plugin_data['slug'] ) ? $plugin_data['slug'] : sanitize_title( $plugin_data['Name'] ); + $plugin_id_attr = $plugin_slug; + + // Ensure the ID attribute is unique. + $suffix = 2; + while ( in_array( $plugin_id_attr, $plugin_id_attrs, true ) ) { + $plugin_id_attr = "$plugin_slug-$suffix"; + $suffix++; + } + + $plugin_id_attrs[] = $plugin_id_attr; $context = $status; $screen = $this->screen; @@ -739,7 +750,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions['deactivate'] = sprintf( '%s', wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ), - esc_attr( $plugin_slug ), + esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Network Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Network Deactivate' ) @@ -750,7 +761,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions['activate'] = sprintf( '%s', wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file ), - esc_attr( $plugin_slug ), + esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Network Activate %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Network Activate' ) @@ -761,7 +772,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions['delete'] = sprintf( '%s', wp_nonce_url( 'plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins' ), - esc_attr( $plugin_slug ), + esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Delete' ) @@ -782,7 +793,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions['deactivate'] = sprintf( '%s', wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'deactivate-plugin_' . $plugin_file ), - esc_attr( $plugin_slug ), + esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Deactivate %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Deactivate' ) @@ -793,7 +804,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions['resume'] = sprintf( '%s', wp_nonce_url( 'plugins.php?action=resume&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'resume-plugin_' . $plugin_file ), - esc_attr( $plugin_slug ), + esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Resume %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Resume' ) @@ -804,7 +815,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions['activate'] = sprintf( '%s', wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'activate-plugin_' . $plugin_file ), - esc_attr( $plugin_slug ), + esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Activate %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Activate' ) @@ -815,7 +826,7 @@ class WP_Plugins_List_Table extends WP_List_Table { $actions['delete'] = sprintf( '%s', wp_nonce_url( 'plugins.php?action=delete-selected&checked[]=' . urlencode( $plugin_file ) . '&plugin_status=' . $context . '&paged=' . $page . '&s=' . $s, 'bulk-plugins' ), - esc_attr( $plugin_slug ), + esc_attr( $plugin_id_attr ), /* translators: %s: Plugin name. */ esc_attr( sprintf( _x( 'Delete %s', 'plugin' ), $plugin_data['Name'] ) ), __( 'Delete' )