Skip to content

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

Merged
dkotter merged 3 commits into
WordPress:developfrom
raftaar1191:fix/336-has-ai-credentials-filter-connectors
Mar 30, 2026
Merged

Allow has_ai_credentials() filter fallback for non-API-key connectors#337
dkotter merged 3 commits into
WordPress:developfrom
raftaar1191:fix/336-has-ai-credentials-filter-connectors

Conversation

@raftaar1191
Copy link
Copy Markdown
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
Copy Markdown

github-actions Bot commented Mar 22, 2026

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 <raftaar1191@git.wordpress.org>
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 Mar 22, 2026

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.70%. Comparing base (32c5e2d) to head (4c5d711).
⚠️ Report is 17 commits behind head on develop.

Files with missing lines Patch % Lines
includes/helpers.php 0.00% 6 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop     #337      +/-   ##
=============================================
- Coverage      57.85%   57.70%   -0.15%     
- Complexity       615      617       +2     
=============================================
  Files             46       46              
  Lines           3165     3173       +8     
=============================================
  Hits            1831     1831              
- Misses          1334     1342       +8     
Flag Coverage Δ
unit 57.70% <0.00%> (-0.15%) ⬇️

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
Comment thread includes/helpers.php Outdated
Comment thread includes/helpers.php Outdated
@dkotter dkotter merged commit cde564d into WordPress:develop Mar 30, 2026
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants