Configurations
In HivePress, configurations are defined as PHP arrays of parameters. For example, the post_types
configuration contains parameters for registering the custom post types. Configuration files are stored in the includes/configs
subdirectory of HivePress and its extensions. You can retrieve or extend configurations via the HivePress API.
Creating configurations
If you are developing a custom HivePress extension, you may need to create a new configuration. To do this, create a new {config-name}.php
file (use lowercase letters, numbers, and hyphens only) in the includes/configs
extension subdirectory and HivePress will load it automatically. Pick a name unique enough to avoid conflicts with other HivePress configurations. For this example, we will name it foo-bar.php
.
After the file is created, add the return
statement with an array of parameters:
Retrieving configurations
To retrieve a configuration, call the core get_config
method with the configuration name:
The configuration name is the same as its filename but with underscores instead of hyphens. In the same way, you can retrieve any of the available configurations. For example, you can get an array of post types registered by HivePress:
Extending configurations
To extend the configuration array, use the hivepress/v1/{config_name}
filter hook. The code below adds a new array item to the foo_bar
configuration:
Also, if you create a configuration file with the name of an existing one, HivePress will merge both automatically. For example, if you want to register a custom post type for your extension, simply create the post-types.php
file in the includes/configs
subdirectory, add an array of post type parameters, and HivePress will register it automatically.
Last updated