Skip to content

Allow has_ai_credentials() filter fallback for non-API-key connectors#337

Open
raftaar1191 wants to merge 1 commit intoWordPress:developfrom
raftaar1191:fix/336-has-ai-credentials-filter-connectors
Open

Allow has_ai_credentials() filter fallback for non-API-key connectors#337
raftaar1191 wants to merge 1 commit intoWordPress:developfrom
raftaar1191:fix/336-has-ai-credentials-filter-connectors

Conversation

@raftaar1191
Copy link
Contributor

@raftaar1191 raftaar1191 commented Mar 22, 2026

What?

Closes #336

Adds a filter-based fallback to has_ai_credentials() so third-party/local providers that do not use API keys can still mark credentials as configured.

Why?

The current configured-state check only returns true when an ai_provider connector uses authentication.method = api_key and the related setting is non-empty. Local/self-hosted connectors (for example connectors using authentication.method = none) can be fully usable but still fail this configured check, which triggers the settings notice and blocks expected behavior.

How?

  1. Cache registered connectors in $connectors = wp_get_connectors().
  2. Keep existing api_key logic unchanged.
  3. If no API-key credential is found, call:
    apply_filters( 'wpai_has_ai_credentials', false, $connectors )
  4. Update the filter docs to reflect the second argument is the full connectors array.

Use of AI Tools

Drafting and implementation assistance was done with GitHub Copilot (GPT-5.3-Codex). All changes were reviewed and validated before submission.

Testing Instructions

  1. Check out this PR branch.
  2. Ensure no AI provider API key options are set.
  3. Register an ai_provider connector that does not use API-key auth (for example auth method none).
  4. Add a filter callback to wpai_has_ai_credentials returning true when that connector is present.
  5. Verify \WordPress\AI\has_ai_credentials() returns true.
  6. Verify AI settings no longer show the "requires a valid AI Connector" configured-state notice in this scenario.
  7. Remove the filter and verify behavior returns to previous default (false without API-key credentials).

Testing Instructions for Keyboard

  1. Open the AI settings page using keyboard navigation only.
  2. Verify focus order and controls are unchanged.
  3. Confirm the configured-state notice visibility changes only based on credential/filter state, with no keyboard regressions.

Screenshots or screencast

N/A (no UI/layout changes; behavior-only change).

Before After
Configured check could not be overridden with connector context for non-API-key providers. Configured check can be overridden via wpai_has_ai_credentials with access to registered connectors.
Open WordPress Playground Preview

@github-actions
Copy link

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: raftaar1191 <[email protected]>

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

@codecov
Copy link

codecov bot commented Mar 22, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.83%. Comparing base (32c5e2d) to head (1110fef).

Files with missing lines Patch % Lines
includes/helpers.php 0.00% 3 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #337      +/-   ##
=============================================
- Coverage      57.85%   57.83%   -0.02%     
  Complexity       615      615              
=============================================
  Files             46       46              
  Lines           3165     3166       +1     
=============================================
  Hits            1831     1831              
- Misses          1334     1335       +1     
Flag Coverage Δ
unit 57.83% <0.00%> (-0.02%) ⬇️

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.

@jeffpaul jeffpaul requested a review from dkotter March 23, 2026 17:06
@jeffpaul jeffpaul self-requested a review March 23, 2026 17:06
@jeffpaul jeffpaul added this to the 0.7.0 milestone Mar 23, 2026
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.

Support local AI providers without API keys in credential checks

2 participants