Skip to content

Change our AI connector check from looking at configuration to looking at if authentication is set#603

Open
dkotter wants to merge 3 commits into
WordPress:developfrom
dkotter:fix/provider-check
Open

Change our AI connector check from looking at configuration to looking at if authentication is set#603
dkotter wants to merge 3 commits into
WordPress:developfrom
dkotter:fix/provider-check

Conversation

@dkotter
Copy link
Copy Markdown
Collaborator

@dkotter dkotter commented May 21, 2026

What?

Adds new helper functions that check if a connector has authentication in place, going from ENV var to constant to API key in the database. Use this in place of our new is_connector_configured check.

Why?

In #537 we added a new is_connector_configured function and use that when determining if we have AI credentials. In testing something else, I was seeing lots of extra requests being made and realized that the $registry->isProviderConfigured( $connector_id ) check that we run in is_connector_configured makes an actual API request to validate credentials.

While this can be great in some circumstances, by attaching that to our has_ai_credentials function, this ends up running all the time (basically every admin page load).

The original code here never verified credentials, it just checked if we had an API key set. As reported in #536, the issue with that check is it didn't consider ENV vars or constants and we fixed that with this new is_connector_configured function.

But I don't think it's ideal to make all of these requests so this PR adds new functions that are now used instead of is_connector_configured that bring us back to just checking for the existence of credentials, though now checking ENV var, constants and API keys in the database to resolve the original issue. This matches the original intent discussed here.

How?

  • Adds a new has_connector_authentication and get_connector_api_key_source, the latter mirroring what WordPress Core does in _wp_connectors_get_api_key_source and the former being used as a replacement for is_connector_configured
  • We retain the is_connector_configured function in case we want to use this at some point in the future. For example, likely could replace our has_valid_ai_credentials with this, or use it within that

Use of AI Tools

AI assistance: Yes
Tool(s): Cursor
Model(s): GPT-5.5
Used for: Investigating the issue and researching a few approaches to resolving. Execution and testing done by me

Testing Instructions

See testing instructions on #537 to ensure that issue is still resolved

Changelog Entry

Added - New helper functions that are used to determine if we have valid AI Connector credentials.
Changed - Use the new has_connector_authentication instead of is_connector_configured to avoid unnecessary API requests.

Open WordPress Playground Preview

dkotter added 2 commits May 21, 2026 14:11
…ce functions that are used to determine if a connector has authentication set, either via ENV var, constant or API key in the database. Use this instead of is_connector_configured as that makes actual API requests
@dkotter dkotter added this to the 1.1.0 milestone May 21, 2026
@dkotter dkotter self-assigned this May 21, 2026
@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: dkotter <dkotter@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 75.86207% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.20%. Comparing base (3624c91) to head (a7e035d).

Files with missing lines Patch % Lines
includes/helpers.php 78.57% 6 Missing ⚠️
includes/Admin/Dashboard/AI_Status_Widget.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #603      +/-   ##
=============================================
+ Coverage      73.18%   73.20%   +0.01%     
  Complexity      1731     1731              
=============================================
  Files             85       85              
  Lines           7473     7500      +27     
=============================================
+ Hits            5469     5490      +21     
- Misses          2004     2010       +6     
Flag Coverage Δ
unit 73.20% <75.86%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dkotter
Copy link
Copy Markdown
Collaborator Author

dkotter commented May 21, 2026

@LukasFritzeDev wondering if you might have time to review this and ensure it still resolves your reported issue in #536? In testing some other things, realized the approach we took in #537 introduced some unintended side effects so I've switched things to the approach you mentioned here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs review

Development

Successfully merging this pull request may close these issues.

2 participants