graphql_init_settings

Action that fires when settings are being initialized

do_action( 'graphql_init_settings', WPGraphQL\Admin\Settings\SettingsRegistry $registry );

Params

  • $registry (WPGraphQL\Admin\Settings\SettingsRegistry): The instance of the SettingsRegistry class

Source

File: wp-graphql/src/Admin/Settings/SettingsRegistry.php

Examples

Registers a GraphQL Settings Section

/**
 * Registers a GraphQL Settings Section
 *
 * @param string $slug   The slug of the group being registered
 * @param array  $config Array configuring the section. Should include: title
 */
function register_graphql_settings_section( $slug, $config ) {
	add_action( 'graphql_init_settings', function( \WPGraphQL\Admin\Settings\SettingsRegistry $registry ) use ( $slug, $config ) {
		$registry->register_section( $slug, $config );
	} );
}

Registers a GraphQL Settings Field

/**
 * Registers a GraphQL Settings Field
 *
 * @param string $group  The name of the group to register a setting field to
 * @param array  $config The config for the settings field being registered
 */
function register_graphql_settings_field( $group, $config ) {
	add_action( 'graphql_init_settings', function( \WPGraphQL\Admin\Settings\SettingsRegistry $registry ) use ( $group, $config ) {
		$registry->register_field( $group, $config );
	} );
}