Conversation
…ider credentials, passing those through a filter
…ential fields it uses
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
peterwilsoncc
left a comment
There was a problem hiding this comment.
I've added a few notes inline.
Primarily, I think we could make the filter easier to use by including the provider name in the filter. Secondly, I'm wondering about back-compat with the type change.
| * @param array $credentials The credentials for the Provider. | ||
| * @param string $provider_id The ID of the Provider. | ||
| * @param string|null $feature_id The ID of the Feature, or null if not set. | ||
| * @param array $feature_provider_settings The Provider specific Feature settings. |
There was a problem hiding this comment.
Nitpick: align name and descriptions with spaces.
It's a little mixed but for the most part the docblocks are aligned in this manner.
| public function __construct( string $api_key = '', string $feature = '' ) { | ||
| $this->api_key = $api_key; | ||
| $this->feature = $feature; | ||
| public function __construct( Provider $provider, ?Feature $feature, array $settings = [] ) { |
There was a problem hiding this comment.
Back-compat: The type changes here will affect any third party developers making use of the class, resulting in a fatal error.
- Do we need to handle this situation?
- Does this affect developers registering custom features/providers?
If it's possible to handle this without breaking back-compat it would be nice to do so.
🔢 This same change is made in a few of places.
There was a problem hiding this comment.
So the plan here is to get rid of these individual APIRequest classes and instead use a single APIRequest class for everything, that uses the PHP AI Client when possible. This is likely coming in the next release so I wasn't overly worried about back-compat here as that change will also break things.
That said, not hard to maintain back-compat for now so I've updated the approach to do that: 97d126c and 04d2bca
…se wanting to filter credentials for a single Provider
Yeah, the issue here is a couple checks we run when most Provider settings are saved (varies slightly on a Provider by Provider basis). The first is a check like this: So if the credentials we want (in this case the endpoint URL and API key) aren't passed in, we don't try and authenticate. This used to make sense as there's no reason to authenticate if we don't have the needed credentials. But now that credentials don't need to be set in the UI and can instead be set by a filter, this check can cause problems. Second, we have checks like this: In this case if the credentials we have saved aren't different from the credentials being submitted, we also don't try to authenticate again. This is a less likely issue to run into but could cause problems. Both of these should be addressed but unless you think differently @peterwilsoncc, I'm inclined to merge this in and address these problems in a follow-up PR, allowing us to get this part of it released sooner (and hopefully get some real user testing on it to see if there are additional follow-ups needed). |

Description of the Change
This PR takes just the Provider credential filtering out of #1038 in order to make both of those PRs easier to review and test and hopefully get this piece merged in sooner.
The work here was heavily inspired by the work done in #1020 (and supersedes that PR) and was originally done in #1038 to ensure any changes we make around credentials management also work when we move Providers to be global.
Here's a high-level overview of changes here:
classifai_provider_credentials_{$provider_id}andclassifai_provider_credentials) making it easy for other to hook in and change those credentialsCloses #1019
How to test the Change
Practically all Feature/Provider combinations are touched by this update though in general, this is all fairly minor changes. Testing to ensure Features still work as expected (that API requests work) is what is needed here.
Changelog Entry
Credits
Props @fabiankaegy, @dkotter
Checklist: