Skip to content

Commit

Permalink
dev : Add snapwp_helper/env/variables filter (#49)
Browse files Browse the repository at this point in the history
* chore : added an apply_filter to the VariableRegistry vars

* fix : format of naming filter, add comment for filter.

* docs : add docs for env vars filter.

* chore : address PR feedbacks

* chore: cleanup

---------

Co-authored-by: Dovid Levine <[email protected]>
  • Loading branch information
Ta5r and justlevine authored Jan 6, 2025
1 parent e95b8c2 commit 7d52e4e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
26 changes: 23 additions & 3 deletions docs/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<string,array{description:string,default:string,required:bool}>)_: 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`
Expand Down
10 changes: 8 additions & 2 deletions src/Modules/EnvGenerator/VariableRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class VariableRegistry {
/**
* Array of environment variables.
*
* @todo Support conditional variables.
*
* @var array<string,array{description:string,default:string,required:bool}>
*/
private const VARIABLES = [
Expand Down Expand Up @@ -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<string,array{description:string,default:string,required:bool}> $variables The default environment variables, keyed by name.
*/
$this->variables = (array) apply_filters( 'snapwp_helper/env/variables', self::VARIABLES );
}

/**
Expand Down

0 comments on commit 7d52e4e

Please sign in to comment.