add wp_toggle_dev_plugins example#153
Conversation
|
Heyo! @davidneedham @mcdwayne @ataylorme , any chance any of you fine gentlemen can take a gander? |
|
Looks very useful. Maybe reduce duplication by combining |
|
Good old switch case :) |
|
In the example, there is one plugin Hello Dolly ( $plugins_to_activate_and_deactivate = array (
'dev' => array (
'hello' => true,
),
'test' => array (
'hello' => true,
),
'live' => array (
'hello' => false,
),
);
if ( ! empty( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {
echo "Toggle developer plugins: Activating/deactivating plugins for the " . $_ENV['PANTHEON_ENVIRONMENT'] . " environment... \n";
if( isset( $plugins_to_activate_and_deactivate[ $_ENV['PANTHEON_ENVIRONMENT'] ] ) ) {
foreach( $plugins_to_activate_and_deactivate[ $_ENV['PANTHEON_ENVIRONMENT'] ] as $plugin_active ){
$plugin_name = key($plugin_active);
if( $plugin_active ) {
echo "Toggle developer plugins: activating $plugin_name ... \n";
passthru('wp plugin activate $plugin_name');
} else {
echo "Toggle developer plugins: deactivating $plugin_name ... \n";
passthru('wp plugin deactivate $plugin_name');
}
}
} else {
echo "Toggle developer plugins: No active/deactive plugin definitions found for the " . $_ENV['PANTHEON_ENVIRONMENT'] . " environment";
}
} |
|
@mcdwayne debug bar plugin(s) are likely candidates for being selective of running in production, depending on how many extensions one is running. |
|
I think @ataylorme 's new scheme would actually be pretty inconvenient unless you map every multidev environment to Without ^^, you'd have to keep re-registering the same set of dev modules every time you made a new multidev. |
|
thanks for the contributions @greg-1-anderson @ataylorme! this code is close to working but won't run in live. something about the while loop and $plugin_active equalling 1. $plugins_to_toggle = array (
'dev' => array (
'debug-bar' => true,
'debug-bar-slow-actions' => true,
'debug-bar-list-dependencies' => true
),
'test' => array (
'debug-bar' => true,
'debug-bar-slow-actions' => true,
'debug-bar-list-dependencies' => true
),
'live' => array (
'debug-bar' => false,
'debug-bar-slow-actions' => false,
'debug-bar-list-dependencies' => false
),
);
if ( ! empty( $_ENV['PANTHEON_ENVIRONMENT'] ) ) {
echo "Toggle developer plugins: Activating/deactivating plugins for the " . $_ENV['PANTHEON_ENVIRONMENT'] . " environment... \n";
$env_name = isset($plugins_to_toggle[ $_ENV['PANTHEON_ENVIRONMENT'] ]) ? $_ENV['PANTHEON_ENVIRONMENT'] : 'dev';
if( isset( $plugins_to_toggle[ $env_name ] ) ) {
while ($plugin_active = current($plugins_to_toggle[ $env_name ])) {
$plugin_name = key($plugins_to_toggle[ $env_name ]);
if ($plugin_active) {
echo "Toggle developer plugins: activating $plugin_name ... \n";
passthru('wp plugin activate '.$plugin_name);
} else {
echo "Toggle developer plugins: deactivating $plugin_name ... \n";
passthru('wp plugin deactivate '.$plugin_name);
}
next($plugins_to_toggle[ $env_name ]);
}
} else {
echo "Toggle developer plugins: No plugin definitions found for the " . $_ENV['PANTHEON_ENVIRONMENT'] . " environment";
}
} |
This example will show how you can automatically activate and deactivate plugins based on environment on deploy. This will ease development and potentially improve performance on Live.