Ensure you can properly remove Providers #456
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
There's an existing filter,
{$this->menu_slug}_providers
, that allows you to filter the available Providers for each Service. This filter has been around for 4 years but in testing it out, it doesn't work properly.The problem is we have a number of places where we reference our Provider Service with code like
$this->provider_classes[0]
. There are two issues with this:array
, which may not be true now that we've started to add multiple Services in each Providerarray
that has at least one value. This is the issue that is preventing full usage of the mentioned filterThis PR fixes the second point in its entirety by making sure we always have an
array
of at least one Provider Service before we use that variable. This allows you to remove all Services from a particular Provider and not get any PHP errors.It mostly fixes the first point as well by adding a new
find_provider_class
helper function to get the Provider Service based on the Provider name, instead of position within thearray
. I think there is still one place that references the Provider Service byarray
position but it seemed fine to leave for now.If no Providers are registered within a Service, the Service still shows up in our settings but no inputs show and instead we show an error message:
Options also won't show in the new onboarding:
This helps with #404 but doesn't completely close it
How to test the Change
functions.php
or within a custom plugin, utilize the{$this->menu_slug}_providers
filter to remove one or more Services. Here's the code I've been using:Changelog Entry
Credits
Props @dkotter
Checklist: