Directory

Add new filter 'mu_plugins' by nate-allen · Pull Request #3728 · WordPress/wordpress-develop · GitHub
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 new filter 'mu_plugins' #3728

Closed
wants to merge 15 commits into from
Closed

Conversation

nate-allen
Copy link

Adds a new filter called mu_plugins that allows the filtering of the must-use plugins array.

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


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

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

Thanks @nate-allen, Left one nit-pick document changes. Can you please add unit tests for the new filter?

src/wp-admin/includes/plugin.php Outdated Show resolved Hide resolved
Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @nate-allen! I've left some feedback in this review.

@@ -292,11 +292,20 @@ public function prepare_items() {
}
}

if ( strlen( $s ) ) {
if ( isset( $s ) && strlen( $s ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change doesn't appear to be related to the addition of the new filter. @nate-allen Was this part of a patch for another ticket?

Copy link
Author

Choose a reason for hiding this comment

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

Hi @costdev. It's required for the unit test for this ticket.

Copy link
Contributor

@costdev costdev Jun 19, 2023

Choose a reason for hiding this comment

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

Thanks @nate-allen!

Pinging @TimothyBJacobs and @spacedmonkey as REST API maintainers. Are you happy for this source change to be made here to allow PHPUnit tests to pass, or should it be made in a separate ticket, or should the test(s) instead set a value for the $s global?

Copy link
Member

Choose a reason for hiding this comment

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

@costdev This doesn't look REST API related to me? But since I'm here 🙂.

To me it looks like the relevant globals should be getting initialized in the test. Though I think @SergeyBiryukov or @hellofromtonya could give a more informed opinion on the direction for these kinds of unit tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @TimothyBJacobs! It appears my brain skipped a beat when I posted that at 3AM 😅

Yeah that's what I was thinking - and that the isset( $s ) check, if it's going to be added at some point, should probably be separate rather than bundled in the addition of a new filter.

Let's see what Sergey or Tonya think too 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for ping @TimothyBJacobs and @costdev.

To me it looks like the relevant globals should be getting initialized in the test.

In this PR, yes, I agree.

How to do it?

  • Store each global's original value in a new property added to the test class.
    • Add the property.
    • The initialization of the property in either the before_set_up_class() or set_up() fixture method.
  • The test is then able to modify the global to its needs.
  • How to restore / reset the original value? In the tear_down(), set the global to its the original value using the property.
    • Why the tear_down() and not within the test method? The tear_down() ensures the global gets reset, as it runs after each test regardless if the test fails and skips any of it test code.

Here's an example test.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you @hellofromtonya (and everyone else that has helped move this along!) I will make these changes and reach out if I have any issues.

nate-allen and others added 2 commits June 18, 2023 22:11
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
nate-allen and others added 2 commits June 19, 2023 00:00
Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
@audrasjb
Copy link
Contributor

I committed fb4a416 to solve a conflict against trunk.

@audrasjb
Copy link
Contributor

closing in favor of #4717

@audrasjb audrasjb closed this Jun 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants