Make WordPress Core

#64288 closed defect (bug) (fixed)

Deactivate link is active for plugins required by others when searching

Reported by: webdados Owned by: westonruter
Priority: normal Milestone: 7.0
Component: Upgrade/Install Version: 6.5
Severity: normal Keywords: has-patch
Cc: Focuses: administration

Description

Tested version: 6.9-RC2-61266

The "Deactivate" link on the plugins list is inactive if there's another active plugin that requires that one.

For example, my "Shop as Client Pro" is a paid plugin that requires the free wordpress.org "Shop as Client" plugin, so when both are active, the "Deactivate" link on "Shop as Client" is inactive. This is because I've declared "shop-as-client" on the main PHP file "Requires Plugins" header.

​https://snipboard.io/cBZGDe.jpg

I just found out that when you perform a search on the plugins page, this is not the case: ​https://snipboard.io/qOUQlk.jpg

As you can see on the screenshot above, it also does not show the "Required by" and "Requires" sections below the description of each plugin.

This only happens when the search is performed by ajax, because if you refresh the page after the search is performed, you get the same plugin results, but the list has the correct "Deactivate" link status and shows the required plugins.

Attachments (1)

64288.diff​ (537 bytes ) - added by iflairwebtechnologies 11 months ago.

Download all attachments as: .zip

Change History (12)

#1 @swissspidy
11 months ago

  • Focuses administration added
  • Keywords needs-patch added
  • Milestone Awaiting Review → 7.0
  • Version trunk → 6.5

The "Required by" etc. notes below the plugin description also appear to be missing.

This ticket was mentioned in ​PR #10547 on ​WordPress/wordpress-develop by ​@hbhalodia.


11 months ago
#2

  • Keywords has-patch added; needs-patch removed
  • Update the wp_ajax_search_plugins action function to initialize the WP_Plugin_Dependencies class to correctly identiy the plugin dependency when plugin search.

Trac ticket: https://core.trac.wordpress.org/ticket/64288

#3 @hbhalodia
11 months ago

Hi Team, I do have found the root cause for the issue. The thing is WP_Plugin_Dependencies::initialize(); is not being initialized in Ajax instance, hence the required dependencies are being identified as empty. In order to fix this, we just need to update the search plugins ajax call, wp_ajax_search_plugins to initialize the WP_Plugin_Dependencies::initialize(); class and then it would work as expected. Below is the demo video, how the fix is working as expected.

​https://app.godam.io/web/video/g50rtp25s5

Last edited 11 months ago by hbhalodia (previous) (diff)

#4 @iflairwebtechnologies
11 months ago

Patch Summary
This patch ensures that plugin dependency metadata is properly loaded when performing an AJAX plugin search. The AJAX endpoint wp_ajax_search_plugins() was not calling WP_Plugin_Dependencies::initialize(), which caused dependency-aware action links (e.g., disabling “Deactivate”) to behave incorrectly during filtered views.

Technical Details
The normal (non-AJAX) plugins list initializes dependencies during page load, but the AJAX callback does not. As a result, the dependency graph is unavailable in the AJAX context, causing incorrect display of action links in search results.
The patch inserts WP_Plugin_Dependencies::initialize() before calling $wp_list_table->prepare_items().

​https://prnt.sc/petd4LmPYagE

#5 @ravichudasama01
11 months ago

I tested this on my setup. Before the patch, the Deactivate button was still active in the search results, and the dependency message didn’t show.

Please refer below screenshot for before results:-
​https://prnt.sc/pCvVWEKBskki

After applying the patch, everything works correctly — the Deactivate button is disabled and the ‘Required by’ text appears in the search view.

Please refer below screenshot for after results:-
​https://prnt.sc/pktk4VIdbBnl

#6 @westonruter
11 months ago

  • Owner set to westonruter
  • Status new → reviewing

​@westonruter commented on ​PR #10547:


11 months ago
#8

The WP_Plugin_Dependencies::initialize() method is otherwise currently being called on:

  • src/wp-admin/plugins.php
  • src/wp-admin/plugin-install.php
  • The validate_plugin_requirements() function
  • The WP_Plugin_Dependencies::check_plugin_dependencies_during_ajax() method.

This last one indicates that it “Checks plugin dependencies after a plugin is installed via AJAX.” This is registered here:

​https://github.com/WordPress/wordpress-develop/blob/a1071476c73e110d214b1c25cba0b27ebb506386/src/wp-admin/admin-ajax.php#L173-L174

Question: Would it not make sense to hook in similarly for the search-plugins ajax action? I suppose ultimately the same effect is done since WP_Plugin_Dependencies::initialize() is added to wp_ajax_search_plugins(). The check_plugin_dependencies ajax action was added separately for plugin dependencies, whereas wp_ajax_search_plugins() already existed, to which WP_Plugin_Dependencies::initialize() can be added in the same way it was added top-level to the plugins.php and plugin-install.php admin screens.

​@hbhalodia commented on ​PR #10547:


11 months ago
#9

Hi @westonruter, Thanks for reviewing the PR.

Yes, I agree that this should get initialized in the Ajax context, as it already being done for,

​https://github.com/WordPress/wordpress-develop/blob/a1071476c73e110d214b1c25cba0b27ebb506386/src/wp-admin/admin-ajax.php#L173-L174

Ultimately for search-plugins, ajax this should get initialized to correctly identify the plugin dependency.

#10 @westonruter
11 months ago

  • Component Plugins → Upgrade/Install

#11 @westonruter
11 months ago

  • Resolution → fixed
  • Status reviewing → closed

In 61312:

Upgrade/Install: Initialize plugin dependencies during ajax plugin search.

This ensures that a plugin's "Deactivate" link is disabled for dependency plugins during searches when a dependent plugin is active. It also ensures the "Requires" metadata is shown for dependent plugins, and the "Required by" metadata is shown for dependency plugins.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/10547

Follow-up to [57545].

Props hbhalodia, webdados, swissspidy, ravichudasama01.
See #22316.
Fixes #64288.

Note: See TracTickets for help on using tickets.