Configurar el plugin
Configurar el pluginConfigurar el plugin mediante la página de Ajustes, variables de entorno, wp-config y hooks

Configurar el plugin mediante la página de Ajustes, variables de entorno, wp-config y hooks

Hay varias formas de configurar las opciones del plugin.

La página de Ajustes

La página de Ajustes permite configurar el plugin en el administrador de WordPress.

Para abrirla, haz clic en el enlace "Settings" en el menú del plugin:

Apertura de la página de Ajustes

Los ajustes se organizan por pestañas, donde cada pestaña corresponde a un módulo:

Página de Ajustes

Tras actualizar una opción, haz clic en el botón Save Changes para almacenar y aplicar el nuevo valor.

Mediante variables de entorno y constantes de wp-config

Todas las opciones de la página de Ajustes también pueden establecerse mediante variables de entorno y constantes definidas en el archivo wp-config.php.

La prioridad para elegir el valor de la opción es la siguiente:

  1. Si existe la variable de entorno correspondiente, se utiliza
  2. Si existe la constante correspondiente definida en wp-config.php, se utiliza
  3. En caso contrario, se utiliza el valor de la página de Ajustes

Tras añadir o modificar una variable de entorno o constante de wp-config, la configuración del plugin debe regenerarse. Para ello, ve a la página de Ajustes y haz clic en Save Changes.

Variables de entorno

MóduloOpciónVariable de entorno
Schema Editing AccessEditing Access SchemeEDITING_ACCESS_SCHEME
Single EndpointEndpoint PathGRAPHQL_API_ENDPOINT
Custom EndpointsEndpoint PathCUSTOM_ENDPOINT_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
Public Private SchemaEnable GranularENABLE_INDIVIDUAL_CONTROL_FOR_PUBLIC_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
Cache ControlDefault Max AgeDEFAULT_CACHE_CONTROL_MAX_AGE
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

Constantes de wp-config

El nombre de la constante en el archivo wp-config.php es el mismo que el de la variable de entorno, anteponiéndole GATOGRAPHQL_.

Por ejemplo, la variable de entorno EDITING_ACCESS_SCHEME debe definirse como GATOGRAPHQL_EDITING_ACCESS_SCHEME en wp-config.php.

Mediante hooks

Podemos sobrescribir el valor de una opción a través de un hook.

Cada opción dispara su propio hook:

use PoP\ComponentModel\ComponentConfiguration\ComponentConfigurationHelpers;
 
$hookName = ComponentConfigurationHelpers::getHookName(
    $componentConfigurationClass,
    $envVariable
);
add_filter($hookName, 'myFunctionToOverrideSettingsValue', PHP_INT_MAX);

Para obtener el nombre del hook, debemos proporcionar:

  • $componentConfigurationClass: La clase ComponentConfiguration del paquete donde se define la opción
  • $envVariable: El nombre de la variable de entorno a establecer

Consulta un ejemplo sobre cómo definir un hook.