FeaturesController::enqueue_script_to_fix_plugin_list_html()privateWC 1.0

Fix for the HTML of the plugins list when there are feature-plugin incompatibility warnings.

WordPress renders the plugin information rows in the plugins page in <tr> elements as follows:

  • If the plugin needs update, the <tr> will have an "update" class. This will prevent the lower border line to be drawn. Later an additional <tr> with an "update available" warning will be rendered, it will have a "plugin-update-tr" class which will draw the missing lower border line.
  • Otherwise, the <tr> will be already drawn with the lower border line.

This is a problem for our rendering of the "plugin is incompatible with X features" warning:

  • If the plugin info <tr> has "update", our <tr> will render nicely right after it; but then our own "plugin-update-tr" class will draw an additional line before the "needs update" warning.
  • If not, the plugin info <tr> will render its lower border line right before our compatibility info <tr>.

This small script fixes this by adding the "update" class to the plugin info <tr> if it doesn't have it (so no extra line before our <tr>), or removing 'plugin-update-tr' from our <tr> otherwise (and then some extra manual tweaking of margins is needed).

Метод класса: FeaturesController{}

Хуков нет.


null. Ничего (null).


// private - только в коде основоного (родительского) класса
$result = $this->enqueue_script_to_fix_plugin_list_html( $current_screen ): void;
$current_screen(строка) (обязательный)
The current screen object.

Код FeaturesController::enqueue_script_to_fix_plugin_list_html() WC 8.3.1

private function enqueue_script_to_fix_plugin_list_html( $current_screen ): void {
	if ( 'plugins' !== $current_screen->id ) {

    const warningRows = document.querySelectorAll('tr[data-plugin-row-type=\"feature-incomp-warn\"]');
    for(const warningRow of warningRows) {
    	const pluginName = warningRow.getAttribute('data-plugin');
		const pluginInfoRow = document.querySelector('[data-plugin=\"' + pluginName + '\"]:not(.plugin-update-tr), tr.inactive[data-plugin=\"' + pluginName + '\"]:not(.plugin-update-tr)');
		if(pluginInfoRow.classList.contains('update')) {
			warningRow.querySelector('.notice').style.margin = '5px 10px 15px 30px';
		else {