Easily switch between different site environments from the WordPress admin bar.
Props to WordPress Stage Switcher for the inspiration.
You can install the package via Composer:
composer require alleyinteractive/wp-environment-switcher
Activate the plugin in WordPress and you will see the switcher appear in the top right admin bar:
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
.
Run composer test
to run tests against PHPStan/PHPCS.
Please see CHANGELOG for more information on what has changed recently.
This project is actively maintained by Alley Interactive. Like what you see? Come work with us.
The GNU General Public License (GPL) license. Please see License File for more information.