Thanks so much Kevin! I hope that each of those options might be helpful to someone reading this thread in the future.
I’ll check with my hosting provider regarding that mu-plugins option.
Thanks for the improved code for the bypass option! Much appreciated.
For me, the “deactivate plugin programmatically” option would only help if there were also an else which activated it when copying down from the production site (where it would be deactivated) to the staging site. Deactivate when copying up to production, activate when copying down to staging. ( I also think I should check to be sure the plugin is installed, no?) Something like:
<?php
// Disable or enable 'Force Login' plugin for production or staging
$force_login_plugin = '/wp-force-login/wp-force-login.php';
// Make sure the plugin is installed
$plugin_file = WP_PLUGIN_DIR . $force_login_plugin;
$is_installed = file_exists( $plugin_file );
if ( $is_installed && 'productiondomain.com' === $_SERVER['HTTP_HOST'] && is_plugin_active( $force_login_plugin ) ) {
deactivate_plugins( $force_login_plugin );
}
elseif ( $is_installed && 'stagingdomain.com' === $_SERVER['HTTP_HOST'] && is_plugin_inactive( $force_login_plugin ) ) {
activate_plugins( $force_login_plugin );
}
?>
Or for clarity, perhaps:
<?php
// Disable or enable 'Force Login' plugin for production or staging
// Conditions:
// Where are we?
$environment_domain = $_SERVER['HTTP_HOST'];
// plugin is:
$force_login_plugin = '/wp-force-login/wp-force-login.php';
// Make sure the plugin is installed
$plugin_file = WP_PLUGIN_DIR . $force_login_plugin;
$is_installed = file_exists( $plugin_file );
// Active state
$is_active = is_plugin_active( $force_login_plugin );
if ( 'productiondomain.com' === $environment_domain && $is_installed && $is_active ) {
deactivate_plugins( $force_login_plugin );
}
elseif ( 'stagingdomain.com' === $environment_domain && $is_installed && !$is_active ) {
activate_plugins( $force_login_plugin );
}
?>
What problems do those present?
That said, the bypass option seems much simpler than either of these. Are there any real advantages of using an activate/deactivate solution instead of a bypass solution?
Thanks again for your help with this!