dotenv

By Brad Parbs

20+ active installationsVersion 1.0.4

A WordPress plugin to set WordPress options from a .env file.

Description

Any WPENV_ prefixed variables in the .env will be used to override the WordPress options. For example, if you’d like to set a specific environment to “Discourage search engines from indexing this site”, you can add WPENV_BLOG_PUBLIC=0 to your .env file.

  • Any option in the wp_options table or retrieved by get_option() can be set this way.

  • You can define keys either as WPENV_BLOGDESCRIPTION or as WPENV_blogdescription, both will work.

  • If you’d like to define the location of your .env file, rather than the plugin looking for it, you can filter dotenv_location to be a directory path.

  • You can also change the WPENV_ prefix by filtering dotenv_key_prefix to be a different prefix.

Installation

  • Install the plugin.
    • Add a .env file either in the root of your site or one level above.
    • Add any WordPress options keys to filter with the prefix WPENV_

Changelog

1.0.4

  • Fixed uppercase keys like WPENV_BLOGDESCRIPTION not setting the option.
  • Added the dotenv_key_prefix filter. The misspelled wpdotev_key_prefix filter still works.
  • An invalid .env file no longer causes a fatal error.
  • Updated phpdotenv to 5.8.
  • Requires WordPress 6.0 and PHP 7.4, tested up to WordPress 7.1.