diff --git a/docs/hooks.md b/docs/hooks.md index a8fecd2..a6dbf86 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -14,11 +14,13 @@ - [GraphQL](#graphql) - [`snapwp_helper/graphql/init/registered_{type}_classes`](#snapwp_helpergraphqlinitregistered_type_classes) - [`snapwp_helper/graphql/resolve_template_uri`](#snapwp_helpergraphqlresolvetemplateuri) - - [Lifecycle](#lifecycle) + - [Lifecycle](#lifecycle) - [`snapwp_helper/init/module_classes`](#snapwp_helperinitmodule_classes) - [`snapwp_helper/dependencies/registered_dependencies`](#snapwp_helperdependenciesregistered_dependencies) - - [Plugin Updater](#plugin-updater) - - [`snapwp_helper/plugin_updater/plugins`](#snapwp_helperplugin_updaterplugins) + - [Environment Variables](#environment-variables) + - [`snapwp_helper/env/variables`](#snapwp_helperenvvariables) + - [Plugin Updater](#plugin-updater) + - [`snapwp_helper/plugin_updater/plugins`](#snapwp_helperplugin_updaterplugins) ## Action Hooks @@ -141,6 +143,24 @@ apply_filters( 'snapwp_helper/dependencies/registered_dependencies', array $depe - `name` _(string)_: The pretty name of the dependency used in the admin notice. - `check_callback` _(`callable(): true|\WP_Error`)_: A callable that returns true if the dependency is met, or a `WP_Error` object (with an explicit error message) if the dependency is not met. +### Environment Variables + +#### `snapwp_helper/env/variables` + +This filter allows you to modify the list of environment variables used by SnapWP's frontend framework. + +```php +apply_filters( 'snapwp_helper/env/variables', array $variables ); +``` + +##### Parameters + +- `$variables` _(array)_: This array contains the details of the environment variables, keyed to the variable name. Each item provides the following information: + + - `description` _(string)_: A brief explanation of what the variable controls or configures. + - `default` _(string)_: The default value assigned to the variable if not set explicitly. + - `required` _(bool)_: Whether the variable is mandatory for proper functionality. + ### Plugin Updater #### `snapwp_helper/plugin_updater/plugins` diff --git a/src/Modules/EnvGenerator/VariableRegistry.php b/src/Modules/EnvGenerator/VariableRegistry.php index cc584db..5a2c876 100644 --- a/src/Modules/EnvGenerator/VariableRegistry.php +++ b/src/Modules/EnvGenerator/VariableRegistry.php @@ -14,6 +14,8 @@ class VariableRegistry { /** * Array of environment variables. * + * @todo Support conditional variables. + * * @var array */ private const VARIABLES = [ @@ -50,8 +52,12 @@ class VariableRegistry { * Constructor */ public function __construct() { - // @todo make filterable and allow for conditionals. - $this->variables = self::VARIABLES; + /** + * Filters the list of environment variables recognized by SnapWP. + * + * @param array $variables The default environment variables, keyed by name. + */ + $this->variables = (array) apply_filters( 'snapwp_helper/env/variables', self::VARIABLES ); } /**