_wp_register_default_connector_settings()

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Registers default connector settings.

Source

function _wp_register_default_connector_settings(): void {
	$registered_settings = get_registered_settings();

	foreach ( wp_get_connectors() as $connector_data ) {
		$auth = $connector_data['authentication'];
		if ( 'api_key' !== $auth['method'] && 'application_password' !== $auth['method'] ) {
			continue;
		}

		if ( empty( $auth['setting_name'] ) || isset( $registered_settings[ $auth['setting_name'] ] ) ) {
			continue;
		}
		$setting_name = $auth['setting_name'];

		if ( ! isset( $connector_data['plugin']['is_active'] ) || ! is_callable( $connector_data['plugin']['is_active'] ) ) {
			continue;
		}

		if ( ! call_user_func( $connector_data['plugin']['is_active'] ) ) {
			continue;
		}

		if ( 'api_key' === $auth['method'] ) {
			register_setting(
				'connectors',
				$setting_name,
				array(
					'type'              => 'string',
					'label'             => sprintf(
						/* translators: %s: Connector name. */
						__( '%s API Key' ),
						$connector_data['name']
					),
					'description'       => sprintf(
						/* translators: %s: Connector name. */
						__( 'API key for the %s connector.' ),
						$connector_data['name']
					),
					'default'           => '',
					'show_in_rest'      => true,
					'sanitize_callback' => 'sanitize_text_field',
				)
			);
		} elseif ( 'application_password' === $auth['method'] ) {
			register_setting(
				'connectors',
				$setting_name,
				array(
					'type'              => 'object',
					'label'             => sprintf(
						/* translators: %s: Connector name. */
						__( '%s Credentials' ),
						$connector_data['name']
					),
					'description'       => sprintf(
						/* translators: %s: Connector name. */
						__( 'Application password credentials for the %s connector.' ),
						$connector_data['name']
					),
					'default'           => array(
						'username' => '',
						'password' => '',
					),
					'show_in_rest'      => array(
						'schema' => array(
							'type'                 => 'object',
							'properties'           => array(
								'username' => array(
									'type' => 'string',
								),
								'password' => array(
									'type' => 'string',
								),
							),
							'additionalProperties' => false,
						),
					),
					'sanitize_callback' => static function ( $value ) use ( $setting_name ) {
						return wp_connectors_sanitize_application_password_credentials( $value, $setting_name );
					},
				)
			);
		}
	}
}

Changelog

VersionDescription
7.0.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.