wppaste
WordPress

_wp_connectors_rest_settings_dispatch( WP_REST_Response $response, WP_REST_Server $server, WP_REST_Request $request ): WP_REST_Response

Since
7.0.0
Source
wp-includes/connectors.php:697
Masks and validates connector credentials in REST responses.

Description

On every /wp/v2/settings response, masks connector API key values and the password field of default application-password credential objects.

On POST or PUT requests, validates each updated AI provider API key before masking. If validation fails, the key is reverted to an empty string.
Application password values are masked but not validated.

Compatibility

WordPress
since 7.0.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 2 of the 5 tracked releases, added in 7.0.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$responseWP_REST_Response
The response object.
$serverWP_REST_Server
The server instance.
$requestWP_REST_Request
The request object.

Return value

WP_REST_Response
The modified response with masked/validated keys.

Performance profile

How much work a call to _wp_connectors_rest_settings_dispatch() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads stored settings via update_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
9–30

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 104.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • optionoption read or writeupdate_option()called directly
  • hookthird-party callbacksapply_filters()one call below _wp_connectors_rest_settings_dispatch()
  • serializeserialisationmaybe_serialize()one call below _wp_connectors_rest_settings_dispatch()
  • cacheobject cachewp_cache_get()one call below _wp_connectors_rest_settings_dispatch()

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 4 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost _wp_connectors_rest_settings_dispatch() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always9->get_route()
!is_array($data)14->get_route(), ->get_data()
is_array($data)26–27->get_route(), ->get_data(), ->get_method(), wp_get_connectors(), ->set_data()
is_array($data)29–30->get_route(), ->get_data(), ->get_method(), ->get_method(), wp_get_connectors(), ->set_data()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 104 instructions, 9–30 executed per call, 22 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 4

Source code

function _wp_connectors_rest_settings_dispatch( WP_REST_Response $response, WP_REST_Server $server, WP_REST_Request $request ): WP_REST_Response {	if ( '/wp/v2/settings' !== $request->get_route() ) {		return $response;	} 	$data = $response->get_data();	if ( ! is_array( $data ) ) {		return $response;	} 	$is_update = 'POST' === $request->get_method() || 'PUT' === $request->get_method(); 	foreach ( wp_get_connectors() as $connector_id => $connector_data ) {		$auth = $connector_data['authentication']; 		if ( 'application_password' === $auth['method'] && ! empty( $auth['setting_name'] ) ) {			$setting_name = $auth['setting_name'];			if ( array_key_exists( $setting_name, $data ) && is_array( $data[ $setting_name ] ) ) {				$password = $data[ $setting_name ]['password'] ?? '';				if ( is_string( $password ) && '' !== $password ) {					$data[ $setting_name ]['password'] = str_repeat( "\u{2022}", 16 );				}			}			continue;		} 		if ( 'api_key' !== $auth['method'] || empty( $auth['setting_name'] ) ) {			continue;		} 		$setting_name = $auth['setting_name'];		if ( ! array_key_exists( $setting_name, $data ) ) {			continue;		} 		$value = $data[ $setting_name ]; 		// On update, validate AI provider keys before masking.		// Non-AI connectors accept keys as-is; the service plugin handles its own validation.		if ( $is_update && is_string( $value ) && '' !== $value && 'ai_provider' === $connector_data['type'] ) {			if ( true !== _wp_connectors_is_ai_api_key_valid( $value, $connector_id ) ) {				update_option( $setting_name, '' );				$data[ $setting_name ] = '';				continue;			}		} 		// Mask the key in the response.		if ( is_string( $value ) && '' !== $value ) {			$data[ $setting_name ] = _wp_connectors_mask_api_key( $value );		}	} 	$response->set_data( $data );	return $response;}

Changelog

Introduced in 7.0.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 7.1.0

Signature, return type and hooks compared across 2 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/connectors.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.