Skip to content

Instantly share code, notes, and snippets.

@aubreypwd
Last active November 13, 2017 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aubreypwd/20b030952f41b1fe8e41fe5db9fb8aad to your computer and use it in GitHub Desktop.
Save aubreypwd/20b030952f41b1fe8e41fe5db9fb8aad to your computer and use it in GitHub Desktop.
This helps protect production sites from leaving compatibility mode in WP Migrate DB Pro on which can cause ill-desired consequences.
<?php
/**
* Plugin Name: WDS WP Migrate DB Pro No Compat on Production
* Plugin URI:
* Description: This helps protect production sites from leaving compatibility mode in WP Migrate DB Pro on which can cause ill-desired consequences.
* Version: 1.0.0
* Author: WebDevStudios
* License: GPL2
*
* @source https://gist.github.com/aubreypwd/20b030952f41b1fe8e41fe5db9fb8aad
* @since 1.0.0
* @package WDS\WPMigrateDBProNoCompat
*/
/**
* The notice that shows when WP Migrate DB Pro compat mode is enabled on production.
*
* @author Aubrey Portwood
* @since 1.0.0
*/
function wds_migrate_db_pro_disable_compat_mode_on_production_notice() {
?>
<div class="notice notice-warning is-dismissible">
<p><?php _e( sprintf( '%sWP Migrate DB Pro compatibility mode is active on a production site!%s During a pull, this can cause the site to go down and plugins to become in-active. Only ignore if you know what you are doing.', '<strong>', '</strong>' ) ); // @codingStandardsIgnoreLine. ?></p>
</div>
<?php
}
/**
* Checks to see if WP Migrate DB Pro compat mode is enabled on production.
*
* @author Aubrey Portwood
* @since 1.0.0
*/
function wds_migrate_db_pro_disable_compat_mode_on_production() {
// When WP_DEBUG is not set, assume production.
$maybe_production = ( ! defined( 'WP_DEBUG' ) || true !== WP_DEBUG );
// Is the compat mu-plugin installed?
$plugin_dir = WPMU_PLUGIN_DIR;
$wp_migrate_db_pro_compat_mode = in_array( "{$plugin_dir}/wp-migrate-db-pro-compatibility.php", wp_get_mu_plugins(), true );
if ( $maybe_production && $wp_migrate_db_pro_compat_mode ) {
add_action( 'admin_notices', 'wds_migrate_db_pro_disable_compat_mode_on_production_notice' );
add_action( 'network_admin_notices', 'wds_migrate_db_pro_disable_compat_mode_on_production_notice' );
}
}
add_action( 'muplugins_loaded', 'wds_migrate_db_pro_disable_compat_mode_on_production', 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment