mkdir( WPMU_PLUGIN_DIR ) ) { Health_Check::display_notice( esc_html__( 'We were unable to create the mu-plugins directory.', 'health-check' ), 'error' ); return false; } } // Remove instances of the old plugin, to avoid collisions. if ( Health_Check_Troubleshoot::old_mu_plugin_exists() ) { if ( ! $wp_filesystem->delete( trailingslashit( WPMU_PLUGIN_DIR ) . 'health-check-disable-plugins.php' ) ) { Health_Check::display_notice( esc_html__( 'We could not remove the old must-use plugin.', 'health-check' ), 'error' ); return false; } } // Copy the must-use plugin to the local directory. if ( ! $wp_filesystem->copy( trailingslashit( HEALTH_CHECK_PLUGIN_DIRECTORY ) . 'assets/mu-plugin/health-check-troubleshooting-mode.php', trailingslashit( WPMU_PLUGIN_DIR ) . 'health-check-troubleshooting-mode.php' ) ) { Health_Check::display_notice( esc_html__( 'We were unable to copy the plugin file required to enable the Troubleshooting Mode.', 'health-check' ), 'error' ); return false; } if ( $redirect ) { Health_Check_Troubleshoot::session_started(); } return true; } /** * Check if our Must-Use plugin needs updating, and do so if necessary. * * @global $wp_filesystem * * @uses Health_Check_Troubleshoot::mu_plugin_exists() * @uses Health_Check::get_filesystem_credentials() * @uses get_plugin_data() * @uses trailingslashit() * @uses version_compare() * @uses WP_Filesystem::copy() * @uses esc_html__() * * @return bool */ static function maybe_update_must_use_plugin() { if ( ! Health_Check_Troubleshoot::mu_plugin_exists() ) { return false; } if ( ! Health_Check::get_filesystem_credentials() ) { return false; } $current = get_plugin_data( trailingslashit( HEALTH_CHECK_PLUGIN_DIRECTORY ) . 'assets/mu-plugin/health-check-troubleshooting-mode.php' ); $active = get_plugin_data( trailingslashit( WPMU_PLUGIN_DIR ) . 'health-check-troubleshooting-mode.php' ); $current_version = ( isset( $current['Version'] ) ? $current['Version'] : '0.0' ); $active_version = ( isset( $active['Version'] ) ? $active['Version'] : '0.0' ); if ( version_compare( $current_version, $active_version, '>' ) ) { global $wp_filesystem; if ( ! $wp_filesystem->copy( trailingslashit( HEALTH_CHECK_PLUGIN_DIRECTORY ) . 'assets/mu-plugin/health-check-troubleshooting-mode.php', trailingslashit( WPMU_PLUGIN_DIR ) . 'health-check-troubleshooting-mode.php', true ) ) { Health_Check::display_notice( esc_html__( 'We were unable to replace the plugin file required to enable the Troubleshooting Mode.', 'health-check' ), 'error' ); return false; } } return true; } /** * Output a notice if our Troubleshooting Mode has been initiated. * * @uses Health_Check::display_notice() * @uses sprintf() * @uses esc_html__() * @uses esc_url() * @uses admin_url() * * @return void */ static function session_started() { Health_Check::display_notice( sprintf( '%s
%s', esc_html__( 'You have successfully enabled Troubleshooting Mode, all plugins will appear inactive until you disable Troubleshooting Mode, or log out and back in again.', 'health-check' ), sprintf( '%2$s', esc_url( admin_url( '/' ) ), esc_html__( 'Return to the Dashboard', 'health-check' ) ) ) ); } /** * Display the form for enabling troubleshooting mode. * * @uses printf() * @uses esc_html__() * @uses Health_Check_Troubleshoot::mu_plugin_exists() * @uses Health_Check_Troubleshoot::maybe_update_must_use_plugin() * @uses Health_Check_Troubleshoot::session_started() * @uses Health_Check::get_filesystem_credentials() * @uses Health_Check_Troubleshoot::setup_must_use_plugin() * @uses esc_html_e() * * @return void */ /** * Display the form for enabling troubleshooting mode. * * @uses printf() * @uses esc_html__() * @uses Health_Check_Troubleshoot::mu_plugin_exists() * @uses Health_Check_Troubleshoot::maybe_update_must_use_plugin() * @uses Health_Check_Troubleshoot::session_started() * @uses Health_Check::get_filesystem_credentials() * @uses Health_Check_Troubleshoot::setup_must_use_plugin() * @uses Health_Check_Troubleshooting_MU::is_troubleshooting() * @uses esc_url() * @uses add_query_arg() * @uses esc_html_e() * * @return void */ static function show_enable_troubleshoot_form() { if ( isset( $_POST['health-check-troubleshoot-mode'] ) ) { if ( Health_Check_Troubleshoot::mu_plugin_exists() ) { if ( ! Health_Check_Troubleshoot::maybe_update_must_use_plugin() ) { return; } Health_Check_Troubleshoot::session_started(); } else { if ( ! Health_Check::get_filesystem_credentials() ) { return; } else { Health_Check_Troubleshoot::setup_must_use_plugin(); } } } ?>
is_troubleshooting() ) : ?>