Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exception to Admin view for Multisite installations #3831

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

dariusk
Copy link

@dariusk dariusk commented Mar 13, 2025

All Submissions:

Changes proposed in this Pull Request:

On a Multisite Network installation, local Admins (as opposed to "Network" AKA "Super" Admins) have reduced capabilities compared to the Admin role on standard installations. Specifically they can't install new plugins.

For Multisite users viewing the Admin page but who do not have Network Admin privileges, this commit skips over some add_filter calls that were causing errors on the plugin listing page (since the Admin did not actually have those capabilities).

This will still work correctly for a Network Admin with the plugin installation privileges since the is_network_admin() will catch that and render the correct available actions.

(co-authored by @jsdiaz)

How to test the changes in this Pull Request:

  1. Install Newspack in a Multisite Network environment
  2. View the plugins page as a regular Admin user (not a Network Admin)
  3. Observe php errors at the top of the page
  4. Apply this patch
  5. View the plugins page again as the same user
  6. Observe no errors

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

On a Multisite Network installation, local Admins (as opposed to "Network" AKA "Super" Admins) [have reduced capabilities compared to the Admin role on standard installations](https://developer.wordpress.org/advanced-administration/multisite/administration/#user-access-capabilities). Specifically they can't install new plugins. This commit skips over some `add_filter` calls that were causing errors on the plugin listing page when an Admin without the elevated multisite privileges would view the plugin listings.

This will still work correctly for a super-Admin with the plugin installation privileges since the `is_network_admin()` will catch that and render the correct available actions.
@dariusk dariusk requested a review from a team as a code owner March 13, 2025 17:45
@@ -18,8 +18,10 @@ class Admin_Plugins_Screen {
* Constructor.
*/
public function __construct() {
add_filter( 'all_plugins', [ $this, 'inject_managed_plugins' ] );
add_filter( 'plugin_action_links', [ $this, 'modify_action_links' ], 10, 3 );
if ( ! is_multisite() || is_network_admin() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it works, it's a somewhat roundabout way – it'd be more readable to add a current_user_can( 'install_plugins' ) in both methods (the check won't work in the constructor. Like so: dd8946e. Would that still work for your use case @dariusk ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants