Configuring the plugin via the Settings page, environment variables, wp-config, and hooks

There are several ways to configure the options in the plugin.

The Settings page permalink

The Settings page enables to configure the plugin in the WordPress admin.

To open it, click on link "Settings" on the plugin's menu:

Opening the Settings page
Opening the Settings page

The settings are organized by tabs, where every tab corresponds to a module:

Settings page
Settings page

After updating an option, click on button Save Changes to store and apply the new value.

By environment variables and wp-config constants permalink

All the options from the Settings page can also be set via environment variables, and constants defined in the wp-config.php file.

The priority to choose the option value from, is the following:

  1. If there is the corresponding environment variable, it is used
  2. If there is the corresponding constant defined in wp-config.php, it is used
  3. Otherwise, the value from the Settings page is used

After adding or modifying an environment value or wp-config constant, the plugin configuration must be regenerated. For that, go to the Settings page, and click on Save Changes.

Environment variables permalink

ModuleOptionEnvironment value
Schema Editing AccessEditing Access SchemeEDITING_ACCESS_SCHEME
Single EndpointEndpoint PathGRAPHQL_API_ENDPOINT
Custom EndpointsEndpoint PathENDPOINT_SLUG_BASE
Persisted QueriesEndpoint PathPERSISTED_QUERY_SLUG_BASE
Graphiql For Single EndpointClient PathGRAPHIQL_CLIENT_ENDPOINT
Interactive Schema For Single EndpointClient PathVOYAGER_CLIENT_ENDPOINT
Public Private SchemaModeUSE_PRIVATE_SCHEMA_MODE
Schema NamespacingUse NamespacingNAMESPACE_TYPES_AND_INTERFACES
Nested MutationsEnable Nested MutationsENABLE_NESTED_MUTATIONS
Nested MutationsDisable redundant root type fieldsDISABLE_REDUNDANT_ROOT_TYPE_MUTATION_FIELDS
Schema Generic Custom PostsList Default LimitGENERIC_CUSTOMPOST_LIST_DEFAULT_LIMIT
Schema Generic Custom PostsCustom Post TypesGENERIC_CUSTOMPOST_TYPES
Schema PostsList Default LimitPOST_LIST_DEFAULT_LIMIT
Schema PostsList Max LimitPOST_LIST_MAX_LIMIT
Schema PostsAdd Type To Custom Post Union TypeADD_POST_TYPE_TO_CUSTOMPOST_UNION_TYPES
Schema UsersList Default LimitUSER_LIST_DEFAULT_LIMIT
Schema UsersList Max LimitUSER_LIST_MAX_LIMIT
Schema TagsList Default LimitTAG_LIST_DEFAULT_LIMIT
Schema TagsList Max LimitTAG_LIST_MAX_LIMIT
Schema PagesList Default LimitPAGE_LIST_DEFAULT_LIMIT
Schema PagesList Max LimitPAGE_LIST_MAX_LIMIT
Schema PagesAdd Type To Custom Post Union TypeADD_PAGE_TYPE_TO_CUSTOMPOST_UNION_TYPES
Schema Custom PostsList Default LimitCUSTOMPOST_LIST_DEFAULT_LIMIT
Schema Custom PostsList Max LimitCUSTOMPOST_LIST_MAX_LIMIT
Schema Custom PostsUse Single Type Instead Of Union TypeUSE_SINGLE_TYPE_INSTEAD_OF_CUSTOMPOST_UNION_TYPE

wp-config constants permalink

The name of the constant in the wp-config.php file is the same as the environment variable, prepending it with GRAPHQL_API_.

For instance, environment variable EDITING_ACCESS_SCHEME must be defined as GRAPHQL_API_EDITING_ACCESS_SCHEME in wp-config.php.

Via hooks permalink

We can override the value of an option via a hook.

Every option triggers its own hook:

use PoP\ComponentModel\ComponentConfiguration\ComponentConfigurationHelpers;

$hookName = ComponentConfigurationHelpers::getHookName(
add_filter($hookName, 'myFunctionToOverrideSettingsValue', PHP_INT_MAX);

To obtain the hook name, we need to provide:

  • $componentConfigurationClass: The ComponentConfiguration class from the package, where the option is defined
  • $envVariable: The name of the environment variable to set

Please check an example on setting a hook.

Share on 🐦 Twitter | πŸ‘ŽπŸΎ Facebook