wpseek.com
A WordPress-centric search engine for devs and theme authors



_wp_connectors_preload_paths › WordPress Function

Since7.2.0
Deprecatedn/a
› _wp_connectors_preload_paths ( $preload_paths )
Access:
  • private
Parameters:
  • ((string|string[])[]) $preload_paths Paths already queued for preloading.
    Required: Yes
Returns:
  • ((string|string[])[]) Paths with the Connectors-specific requests appended.
Defined at:
Codex:

Preloads the REST API responses the Connectors UI fetches on mount.

Without this, the page does a network round-trip for site settings, plugin capability discovery, and each connector's plugin record after the JS hydrates, which noticeably delays first paint.


Source

function _wp_connectors_preload_paths( array $preload_paths ): array {
	// getEntityRecord( 'root', 'site' ) in use-connector-plugin.ts / ai-plugin-callout.tsx.
	$preload_paths[] = '/wp/v2/settings';

	// canUser( 'create', { kind: 'root', name: 'plugin' } ) in stage.tsx.
	$preload_paths[] = array( '/wp/v2/plugins', 'OPTIONS' );

	// AiPluginCallout in routes/connectors-home/ai-plugin-callout.tsx queries this
	// hardcoded ID to check whether the WP AI plugin is installed/active.
	$preload_paths[] = '/wp/v2/plugins/ai/ai?context=edit';

	// getEntityRecord( 'root', 'plugin', <basename> ) per connector in use-connector-plugin.ts.
	foreach ( wp_get_connectors() as $connector_data ) {
		if ( empty( $connector_data['plugin']['file'] ) ) {
			continue;
		}
		// core-data's plugin entity uses the basename with `.php` stripped
		// as the record key (see routes/connectors-home/use-connector-plugin.ts).
		$basename        = preg_replace( '/\.php$/', '', plugin_basename( $connector_data['plugin']['file'] ) );
		$preload_paths[] = '/wp/v2/plugins/' . $basename . '?context=edit';
	}

	return $preload_paths;
}