Sharing one AI provider key across a WordPress multisite network is possible today, but it is not the default behaviour of the plugins that manage those keys. In wp-ai-client, credentials are stored as a per-site option — get_option( 'wp_ai_client_provider_credentials', [] ) — and the credentials screen is registered with add_options_page(), which means every subsite keeps its own copy. Network-wide storage via get_site_option() and update_site_option() is an open feature request in that project, not a shipped feature (WordPress/wp-ai-client issue #44).
So the practical answer has two halves. If you want a genuinely shared credential set, you either implement network-scoped storage yourself behind a filter, or you take the key out of the database altogether and inject it from wp-config.php or an environment variable. Security guidance for WordPress AI connectors favours the second approach for production sites, because a key that is never written to a database is a key that never lands in a backup or a staging clone (WS Form).
Why multisite changes the credential problem
In a single-site install, get_option() and get_site_option() are effectively interchangeable for most plugins. In multisite they are not. get_option() reads from the wp_{blog_id}_options table of the current site, while get_site_option() reads from wp_sitemeta, which is shared by the whole network.
Two consequences follow. First, a plugin that only calls get_option() will show an empty credentials screen on every subsite until someone re-enters the key on each one — the exact friction described in issue #44. Second, the administrative surface changes: a settings page added with add_options_page() appears in each site’s own Settings menu and is guarded by the site-level manage_options capability. A network-scoped equivalent belongs in the Network Admin and should be guarded by manage_network_options, which only super admins hold by default.
That capability difference is not a technicality. It is the main reason a shared key is riskier than a per-site key: one compromised super admin account, or one careless subsite administrator who has been promoted, exposes the credential for every site on the network.
Decide first: one key for the network, or one per site?
Before writing any code, decide what you are actually optimising for. A single network-wide key is convenient and cheap to rotate once. It is also a single point of failure and a single point of billing. Published guidance on WordPress AI connectors recommends the opposite by default: a separate project or workspace per website, and a unique API key for every site and environment (WS Form).
For a host-managed network where all sites belong to the same organisation and the bill is central, a shared key is a reasonable trade. For a network of independent client sites, per-site keys with per-site spend limits are usually the better decision, even though they are more work to manage.
| Storage mechanism | Scope | Who can change it | Best suited to |
|---|---|---|---|
Per-site option (get_option) | One subsite | Site admins with manage_options | Independent client sites, per-site billing |
Network option (get_site_option) | Whole network | Super admins with manage_network_options | Single-organisation networks, central billing |
wp-config.php constant or environment variable | Wherever the code runs | Server operator | Production, immutable deploys, staging parity |
| Filter or storage hook | Whatever the callback decides | Developer | Agencies and hosts with an external secret store |
Pattern 1: network-scoped option storage
This is the behaviour requested in issue #44: an opt-in mode that reads and writes through the network options API. Until the plugin ships it, you can approximate it with a small shim. The example below is illustrative and is not code from wp-ai-client; treat it as a shape to adapt, not a drop-in.
// Illustrative storage shim — not part of wp-ai-client.
function mynet_ai_credentials() {
if ( is_multisite() && get_site_option( 'mynet_ai_use_network_credentials' ) ) {
return get_site_option( 'wp_ai_client_provider_credentials', array() );
}
return get_option( 'wp_ai_client_provider_credentials', array() );
}If you go this route, the admin screen must move with it. Register it on network_admin_menu rather than the site-level options menu, and point it at settings.php:
add_action( 'network_admin_menu', function () {
add_submenu_page(
'settings.php',
'AI Credentials',
'AI Credentials',
'manage_network_options',
'mynet-ai-credentials',
'mynet_render_ai_credentials_page'
);
} );The save handler needs both a capability check and a nonce. Omitting either is the most common way a credentials screen becomes an escalation path:
function mynet_save_ai_credentials() {
if ( ! current_user_can( 'manage_network_options' ) ) {
wp_die( 'Insufficient permissions.' );
}
check_admin_referer( 'mynet_save_ai_credentials' );
$credentials = mynet_sanitize_credentials( $_POST['mynet_ai_credentials'] );
update_site_option( 'wp_ai_client_provider_credentials', $credentials );
}Expected result: after saving once in Network Admin, every subsite resolves the same credential set, and no subsite administrator can read or change it from their own Settings menu.
Pattern 2: inject credentials from outside the database
The more defensible pattern removes the secret from the database entirely. WordPress exposes filters such as pre_site_option_{$option} that let you short-circuit an option read and return a value from anywhere — a constant, an environment variable, or a secrets manager.
add_filter( 'pre_site_option_wp_ai_client_provider_credentials', function ( $pre ) {
if ( false !== $pre ) {
return $pre;
}
$key = getenv( 'OPENAI_API_KEY' );
if ( ! $key ) {
return $pre; // Fall through to whatever is stored.
}
// The array shape is defined by the plugin — verify it before relying on it.
return array( 'openai' => array( 'api_key' => $key ) );
} );Two cautions apply. The exact structure of the credentials array is defined by the plugin, so confirm it against the plugin source or documentation rather than assuming the shape above. And the silent fall-through matters: if the environment variable is missing, the filter returns $pre and the site quietly uses whatever is in the database. That is convenient in development and dangerous in production, where a missing variable should fail loudly rather than fall back to a stale key.
The storage-hook route
A more general version of the same idea is a plugin-provided filter that lets an integrator supply the entire storage mechanism. That is the direction proposed in PR #45, titled Add storage hooks for custom credential management, which was raised in January 2026 and referenced from issue #44 (issue #44). If your host or agency maintains a central secret store, a hook of this kind is the cleanest integration point, because it avoids mirroring options between sites.
Verifying which credential source is actually in use
Credential bugs are usually silent. A site does not error when it reads an empty key; it simply fails at request time with an authentication message from the provider. To check the storage layer directly, use WP-CLI. In a multisite install, wp option get targets the current site while wp site option get targets the network:
# Per-site value for the current site
wp option get wp_ai_client_provider_credentials
# Network-wide value
wp site option get wp_ai_client_provider_credentialsBoth commands print the secret to your terminal, so run them on a trusted machine and clear your shell history if that matters to you. A safer routine check is a small must-use plugin that reports only whether a credential is present, never its value:
add_action( 'admin_notices', function () {
if ( ! current_user_can( 'manage_network_options' ) ) {
return;
}
$network = get_site_option( 'wp_ai_client_provider_credentials', array() );
printf(
'<div class="notice notice-info"><p>Network credential set: %s</p></div>',
$network ? 'yes' : 'no'
);
} );Then trigger a real request through the plugin and confirm the provider accepts it. A successful call plus a present network option is the observable proof that the shared path is working.
Hardening the key itself
Where the key lives is only half the problem. Published guidance on WordPress AI connectors treats API keys as privileged credentials because they authorise paid usage, and recommends a set of controls that apply whether the key is shared or per-site (WS Form):
- Set monthly spending limits and usage alerts at the provider, so a leaked key has a ceiling.
- Restrict models, APIs, allowed domains, server IP addresses, and quotas to only what the network needs.
- Store keys in
wp-config.phpor environment variables rather than the database on production sites. - Monitor usage regularly for unexpected spikes, and rotate keys periodically and immediately after any suspected exposure.
- Never commit keys to Git repositories or other public code repositories.
For a shared network key, the IP and domain restrictions do most of the work. If the key can only be used from your network’s egress addresses, an accidental exposure is far less damaging than an unrestricted key that can be spent from anywhere.
Operational traps specific to multisite
Several failure modes are peculiar to networks. A database backup of wp_sitemeta now contains a credential for the whole network, so a single leaked dump is more damaging than a per-site one. A staging environment cloned from production inherits the production key unless you override it, which is exactly the case where an environment-variable approach pays off. Subsite administrators may have access to plugin screens that display masked keys, and masking is not protection if the field can be re-saved or exported. And any code that passes a key to the browser — through a localised script, an AJAX response, or a REST endpoint — has already lost the argument, regardless of where it is stored.
Logging deserves a separate mention. Provider client libraries sometimes include request headers in debug output. If you enable verbose logging to diagnose a failing request, make sure the log destination is not readable from the web and that keys are redacted before the file is shared in a support thread.
What is still unresolved
Network-wide credential storage in wp-ai-client remains an open feature request as of the issue’s last recorded update on 19 March 2026, with assigned maintainers and a related pull request proposing storage hooks (issue #44). The project has also been referenced in a downstream assessment describing a migration as blocked by multisite and credential gaps, which suggests the limitation is affecting real deployments rather than being theoretical.
Separately, the WordPress 7 Connectors system centralises AI provider credential management and implements each connector as its own plugin (WS Form). The supplied source does not document how Connectors behave on a multisite network, so treat any assumption about network-level Connector credentials as unverified until you check the current documentation for your WordPress version.
Next steps
Pick your storage model before you pick your code. If the network is one organisation with one bill, implement network-scoped options with manage_network_options and a nonce-protected save handler, then add provider-side spend limits and IP restrictions. If the network serves independent sites, keep per-site keys and use a filter to inject them from the environment so nothing sensitive is stored in the database at all.
Whichever you choose, verify it end to end with a real provider request rather than assuming the option is being read. If you hit a specific failure — a key that resolves on the main site but not on subsites, or a filter that silently falls back to a stale value — share your WordPress version, multisite configuration, plugin version, and the exact error message in the Ai-Forum.org community so others can compare notes.
FAQ
Does wp-ai-client support network-wide credentials today?
As of the issue's last recorded update on 19 March 2026, network-wide storage is an open feature request, not a shipped feature. The plugin reads credentials as a per-site option. Check the current release notes before relying on any multisite behaviour.
Is one shared API key for an entire network a good idea?
It is a trade-off rather than a rule. A shared key is easier to rotate and bill centrally, but it is a single point of compromise. Published guidance recommends a unique key per site and environment; if you share one, restrict it by IP, domain, model, and quota, and set a monthly spend limit.
Where should AI API keys be stored on a production site?
Security guidance for WordPress AI connectors recommends wp-config.php or environment variables rather than the database. That keeps the key out of database backups and out of staging clones, and lets you override it per environment.
How can I tell whether a subsite is reading a network option or its own option?
In a multisite install, wp option get reads the current site's value while wp site option get reads the network value. Both print the secret, so use them on a trusted machine, or write a must-use plugin that reports only whether a credential is present.