Skip to content

Latest commit

 

History

History
74 lines (51 loc) · 2.42 KB

README.md

File metadata and controls

74 lines (51 loc) · 2.42 KB

WordPress Environment Switcher

Coding Standards

Easily switch between different site environments from the WordPress admin bar.

Props to WordPress Stage Switcher for the inspiration.

Installation

You can install the package via Composer:

composer require alleyinteractive/wp-environment-switcher

Usage

Activate the plugin in WordPress and you will see the switcher appear in the top right admin bar:

Screenshot of plugin

The plugin reads the current WordPress environment from the current hosting provider (Pantheon and WordPress VIP supported) and falls back to wp_get_environment_type() which can be set by defining WP_ENVIRONMENT_TYPE in your wp-config.php file. You can override the current environment by using the wp_environment_switcher_current_environment filter:

add_filter(
	'wp_environment_switcher_current_environment',
	fn () => 'my-custom-environment'
);

You can define the available environments by using the wp_environment_switcher_environments filter:

add_filter(
	'wp_environment_switcher_environments',
	fn () => [
		'production' => 'https://example.org',
		'staging'    => 'https://staging.example.org',
		'local'      => 'https://example.test',
	]
);

The plugin will automatically detect the current environment and highlight it in the switcher. By default, the plugin will show the switcher to anybody with the manage_options capability. You can change this by modifying the capability mapped to the view_environment_switcher capability with map_meta_cap.

Testing

Run composer test to run tests against PHPStan/PHPCS.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

This project is actively maintained by Alley Interactive. Like what you see? Come work with us.

License

The GNU General Public License (GPL) license. Please see License File for more information.