<?php
#  ________         ____________      _____ ________                       ________      
#  ___  __ )____  _____  /___  /_____ __  /____  __ \______________ ______ ___  __/      
#  __  __  |_  / / /__  / __  / _  _ \_  __/__  /_/ /__  ___/_  __ \_  __ \__  /_        
#  _  /_/ / / /_/ / _  /  _  /  /  __// /_  _  ____/ _  /    / /_/ // /_/ /_  __/        
#  /_____/  \__,_/  /_/   /_/   \___/ \__/  /_/      /_/     \____/ \____/ /_/           
#  ________                             _____ _____              ________                
#  __  ___/_____ ___________  _____________(_)__  /______  __    ___  __ \______________ 
#  _____ \ _  _ \_  ___/_  / / /__  ___/__  / _  __/__  / / /    __  /_/ /__  ___/_  __ \
#  ____/ / /  __// /__  / /_/ / _  /    _  /  / /_  _  /_/ /     _  ____/ _  /    / /_/ /
#  /____/  \___/ \___/  \__,_/  /_/     /_/   \__/  _\__, /      /_/      /_/     \____/ 
#                                                   /____/                               
# 42756C6C657450726F6F66 5365637572697479 50726F 
#
/*	The Copyright, AITpro Software Products License Information must remain
	intact or all BulletProof Security Pro warranties, guarantees, liabilities are void.
	
	Copyright (C) Edward Alexander, AIT-pro.com. All rights reserved.

	AITpro Software Products License Information:
	BY DOWNLOADING, INSTALLING, COPYING, ACCESSING, OR USING BulletProof Security Pro YOU AGREE TO THE TERMS OF THIS AGREEMENT. 
	IF YOU 	ARE ACCEPTING THESE TERMS ON BEHALF OF ANOTHER PERSON OR A COMPANY OR OTHER LEGAL ENTITY, YOU REPRESENT AND WARRANT
	THAT YOU HAVE FULL AUTHORITY TO BIND THAT PERSON, COMPANY, OR LEGAL ENTITY TO THESE TERMS. IF YOU DO NOT AGREE TO THESE TERMS,
	* DO NOT DOWNLOAD, INSTALL, COPY, ACCESS, OR USE BulletProof Security Pro; AND
	* PROMPTLY RETURN BulletProof Security Pro TO THE PARTY FROM WHOM YOU ACQUIRED IT. IF YOU DOWNLOADED BulletProof Security Pro
	FROM THE AITPRO WEBSITE, CONTACT AITPRO FOR A REFUND IF APPLICABLE.
	
	AITpro Software Products License Information continued:
	You agree to keep the AITpro Software Products License for BulletProof Security Pro, unmodified or altered in any way,
	with the original copy of BulletProof Security Pro that you have and any and all copies or partial copies of BulletProof
	Security Pro that You make. 
*/
// Direct calls to this file are Forbidden when core files are not present 
if ( ! function_exists ('add_action') ) {
		header('Status: 403 Forbidden');
		header('HTTP/1.1 403 Forbidden');
		exit();
}

// jQuery ScrollTop Animation based on Browser User Agent
// Opera uses the Chromium Rendering engine & the UA is Chrome
function bpsPro_Browser_UA_scroll_animation() {
	
	$user_agent = esc_html($_SERVER['HTTP_USER_AGENT']);

	if ( preg_match( '/Chrome/i', $user_agent, $matches ) ) { ?>
		
		<script type="text/javascript">
		/* <![CDATA[ */
		jQuery(document).ready(function($){
	
			$("html, body").animate({ scrollTop: "50px" }, 400, function(){
 				$("html, body").animate({ scrollTop: "0px" });
				// essential for the jQuery UI Tabs framework hash anchors
				$( this ).css( "background", "url('') no-repeat left top" );
    		});
			return false;
		});
		/* ]]> */
		</script>

<?php } elseif ( preg_match( '/Firefox/i', $user_agent, $matches ) ) { ?>

		<script type="text/javascript">
		/* <![CDATA[ */
		jQuery(document).ready(function($){
	
			$("html, body").animate({ scrollTop: "50px" }, 600, function(){
 				$("html, body").animate({ scrollTop: "0px" });
				// essential for the jQuery UI Tabs framework hash anchors
				$( this ).css( "background", "url('') no-repeat left top" );
			});
			return false;
		});
		/* ]]> */
		</script>

<?php } elseif ( preg_match( '/Safari/i', $user_agent, $matches ) ) { ?>

		<script type="text/javascript">
		/* <![CDATA[ */
		jQuery(document).ready(function($){
	
			$("html, body").animate({ scrollTop: "100px" }, 600, function(){
 				$("html, body").animate({ scrollTop: "0px" });
				// essential for the jQuery UI Tabs framework hash anchors
				$( this ).css( "background", "url('') no-repeat left top" );
			});
			return false;
		});
		/* ]]> */
		</script>

<?php } elseif ( preg_match( '/MSIE/i', $user_agent, $matches ) || preg_match( '/Trident/i', $user_agent, $matches ) ) { ?>

		<script type="text/javascript">
		/* <![CDATA[ */
		jQuery(document).ready(function($){
	
			$("html, body").animate({ scrollTop: "350px" }, 400, function(){
 				$("html, body").animate({ scrollTop: "0px" });
				// essential for the jQuery UI Tabs framework hash anchors
				$( this ).css( "background", "url('') no-repeat left top" );
			});
			return false;
		});
		/* ]]> */
		</script>

<?php } else { ?>

		<script type="text/javascript">
		/* <![CDATA[ */
		jQuery(document).ready(function($){
	
			$("html, body").animate({ scrollTop: "50px" }, 400, function(){
 				$("html, body").animate({ scrollTop: "0px" });
				// essential for the jQuery UI Tabs framework hash anchors
				$( this ).css( "background", "url('') no-repeat left top" );
    		});
			return false;
		});
		/* ]]> */
		</script>
<?php
	}
}

// Displays Initial, Peak and Total Memory usage
function bpsPro_memory_resource_usage() {
	
	if ( is_admin() && current_user_can('manage_options') ) {

	$memory_usage_peak = memory_get_peak_usage();
	$mbytes_peak = number_format( $memory_usage_peak / ( 1024 * 1024 ), 2 );
	$kbytes_peak = number_format( $memory_usage_peak / ( 1024 ) );	
	
	$memory_usage = memory_get_usage();
	$mbytes = number_format( $memory_usage / ( 1024 * 1024 ), 2 );
	$kbytes = number_format( $memory_usage / ( 1024 ) );
	
	$mbytes_total = number_format( $memory_usage_peak / ( 1024 * 1024 ) - $memory_usage / ( 1024 * 1024 ), 2 );
	$kbytes_total = number_format( $memory_usage_peak / ( 1024 ) - $memory_usage / ( 1024 ) );	
	
	$usage = '<strong>'.__('Peak Memory Usage: ', 'bulletproof-security').'</strong>'. $mbytes_peak . __('MB|', 'bulletproof-security').$kbytes_peak.__('KB', 'bulletproof-security').'<br><strong>'.__('Initial Memory in Use: ', 'bulletproof-security').'</strong>'. $mbytes . __('MB|', 'bulletproof-security').$kbytes.__('KB', 'bulletproof-security').'<br><strong>'.__('Total Memory Used: ', 'bulletproof-security').'</strong>'. $mbytes_total . __('MB|', 'bulletproof-security').$kbytes_total.__('KB', 'bulletproof-security').'<br>';

	return $usage;
	}
}

// Logs Initial, Peak and Total Memory usage
function bpsPro_memory_resource_usage_logging() {
	
	$memory_usage_peak = memory_get_peak_usage();
	$mbytes_peak = number_format( $memory_usage_peak / ( 1024 * 1024 ), 2 );
	$kbytes_peak = number_format( $memory_usage_peak / ( 1024 ) );	
	
	$memory_usage = memory_get_usage();
	$mbytes = number_format( $memory_usage / ( 1024 * 1024 ), 2 );
	$kbytes = number_format( $memory_usage / ( 1024 ) );
	
	$mbytes_total = number_format( $memory_usage_peak / ( 1024 * 1024 ) - $memory_usage / ( 1024 * 1024 ), 2 );
	$kbytes_total = number_format( $memory_usage_peak / ( 1024 ) - $memory_usage / ( 1024 ) );	
	
	$usage = __('Peak Memory Usage: ', 'bulletproof-security'). $mbytes_peak . __('MB|', 'bulletproof-security').$kbytes_peak.__('KB', 'bulletproof-security')."\r\n".__('Initial Memory in Use: ', 'bulletproof-security'). $mbytes . __('MB|', 'bulletproof-security').$kbytes.__('KB', 'bulletproof-security')."\r\n".__('Total Memory Used: ', 'bulletproof-security'). $mbytes_total . __('MB|', 'bulletproof-security').$kbytes_total.__('KB', 'bulletproof-security');

	return $usage;
}

// S-Monitor - PHP Error Log Path/Location Check - Check if the php error log path is valid - WP Only
// ini_set Options Checks & auto-update wp-config.php & add the 3 new ini_set options.
// 15.3: 
function bps_smonitor_phpini_wp() {

	if ( current_user_can('manage_options') ) {
	
		if ( isset ( $_POST['Submit-PELL'] ) ) {
			return;
		}

		$options = get_option('bulletproof_security_options_monitor');
		$options3 = get_option('bulletproof_security_options2');	
		$ElogPathSet = ! isset($options3['bps_error_log_location']) ? '' : $options3['bps_error_log_location'];	
		
		if ( isset($options['bps_PHP_ELogLoc_set']) && $options['bps_PHP_ELogLoc_set'] == 'wpOn' && $ElogPathSet != '' ) { 
	
			$wpconfig_file = ABSPATH . 'wp-config.php';
			
			if ( ! file_exists($wpconfig_file) ) {
				$wpconfig_file_moved = __('The wp-config.php file has been moved to another hosting account folder. ', 'bulletproof-security');
			} else {
				$wpconfig_file_moved = '';
			
				$subject = file_get_contents($wpconfig_file);
				$pattern = '/\/\*\* BEGIN BPS Pro ini_set Settings \*\*\/(.*?)\/\*\* END BPS Pro ini_set Settings \*\*\//s';
				
				if ( ! preg_match($pattern, $subject ) ) {
					$ini_set_code_missing = __('The BPS ini_set Options code does not exist in the wp-config.php file.', 'bulletproof-security');
				} else {
					$ini_set_code_missing = '';
				}
			}
			
			$ini_get_error_log = ini_get('error_log');
			
			if ( $ini_get_error_log == '' ) {
				$ElogPathServer = 'blank/none';
			} else {
				$ElogPathServer = ini_get('error_log');
			}
			
			if ( $ElogPathServer == 'blank/none' && $wpconfig_file_moved == '' && $ini_set_code_missing == '' ) {
				$host_config_problem = __('Web host PHP server configuration problem.', 'bulletproof-security');
			} else {
				$host_config_problem = '';
			}
			
			$ElogPathServerXampp = addslashes( ini_get('error_log') );
			$sapi_type = php_sapi_name();
			
			// Linux
			if ( substr($sapi_type, 0, 6) != 'apache' ) {

				if ( strcmp($ElogPathServer, $ElogPathSet) != 0 ) { // 0 is equal - != 0 means that the paths do not match
					$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('PHP Error Log Path Does Not Match', 'bulletproof-security').'</font><br>'.__('The "PHP Error Log Location Set To" value does not match the "Error Log Path Seen by Server" value.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/php/php-options.php#bps-tabs-5' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the PHP Error Log page.', 'bulletproof-security').'<br>'.__('Copy the "Error Log Path Seen by Server" value: ', 'bulletproof-security').'<font color="blue">'.$ElogPathServer.'</font>'.__(' into the "PHP Error Log Location Set To" text box and click the Set Error Log Location button to fix this unless you see "blank/none" for the value.', 'bulletproof-security').'<br>'.__('If you see "blank/none" for the value click this forum link: ', 'bulletproof-security').'<a href="https://forum.ait-pro.com/forums/topic/php-error-log-path-does-not-match-error-log-path-seen-by-server-blank-none/" target="_blank" title="Link opens in a new Browser window">'.__('PHP Error Log Path Does Not Match', 'bulletproof-security').'</a>'.__(' for how to fix this problem.', 'bulletproof-security').'<br><font color="#fb0101">'.__('Cause of the problem: ', 'bulletproof-security').'</font>'.$wpconfig_file_moved.$ini_set_code_missing.$host_config_problem.'</div>';
					echo $text;
				}
			
			} else {
				
				// XAMPP, MAMP, WAMP, etc.
				if ( strcmp($ElogPathServerXampp, $ElogPathSet) != 0 ) { // 0 is equal - != 0 means that the paths do not match
					$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('PHP Error Log Path Does Not Match', 'bulletproof-security').'</font><br>'.__('The "PHP Error Log Location Set To" value does not match the "Error Log Path Seen by Server" value.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/php/php-options.php#bps-tabs-5' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the PHP Error Log page.', 'bulletproof-security').'<br>'.__('Copy the "Error Log Path Seen by Server" value: ', 'bulletproof-security').'<font color="blue">'.$ElogPathServerXampp.'</font>'.__(' into the "PHP Error Log Location Set To" text box and click the Set Error Log Location button to fix this unless you see "blank/none" for the value.', 'bulletproof-security').'<br>'.__('If you see "blank/none" for the value click this forum link: ', 'bulletproof-security').'<a href="https://forum.ait-pro.com/forums/topic/php-error-log-path-does-not-match-error-log-path-seen-by-server-blank-none/" target="_blank" title="Link opens in a new Browser window">'.__('PHP Error Log Path Does Not Match', 'bulletproof-security').'</a>'.__(' for how to fix this problem.', 'bulletproof-security').'<br><font color="#fb0101">'.__('Cause of the problem: ', 'bulletproof-security').'</font>'.$wpconfig_file_moved.$ini_set_code_missing.$host_config_problem.'</div>';
					echo $text;
				}
			}
		}

		if ( isset($options['bps_phpini_created']) && $options['bps_phpini_created'] == 'wpOn' ) { 
		
			$ini_set_options = get_option('bulletproof_security_options_iniSet');
		
			if ( ! isset($ini_set_options['bps_iniSet_ErrorReporting']) ) { 
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('ini_set Options Need To Be Saved & The PHP Error Log Path/Location Needs To Be Set', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/php/php-options.php#bps-tabs-2' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the P-Security ini_set Options page. Enter a php error log path in the ini_set PHP Error Log Location Set To: text box (see the Recommended Setting/path to the right of this text box) and click the Save|Enable Options button. Click the ini_set Options Read Me Help button if you need additional help info.', 'bulletproof-security').'</div>';
				echo $text;
			}
		}
	}
}

add_action('admin_notices', 'bps_smonitor_phpini_wp');

// ARQ Deactivate FailSafe - checks that class.php master backup file exists - if not ARQ DB option is set to Off
function bpsClassBackup() {

	if ( current_user_can('manage_options') ) {
	
	$bps_classphp = WP_CONTENT_DIR . '/bps-backup/master-backups/class.php';
	
	if ( ! file_exists($bps_classphp) ) {
		
		$options = get_option('bulletproof_security_options_exclude_folder');
		$ARQoptions = get_option('bulletproof_security_options_ARCM');
		
		if ( ! isset($options['bpsexclude_input_1']) ) {
			return;
		}

		if ( $options['bpsexclude_input_1'] != '' || $options['bpsexclude_input_2'] != '' || $options['bpsexclude_input_3'] != '' || $options['bpsexclude_input_4'] != '' || $options['bpsexclude_input_5'] != '' || $options['bpsexclude_input_6'] != '' || $options['bpsexclude_input_7'] != '' || $options['bpsexclude_input_8'] != '' || $options['bpsexclude_input_9'] != '' || $options['bpsexclude_input_10'] != '' || $options['bpsexclude_input_11'] != '' || $options['bpsexclude_input_12'] != '' || $options['bpsexclude_input_13'] != '' || $options['bpsexclude_input_14'] != '' || $options['bpsexclude_input_15'] != '' || $options['bpsexclude_input_16'] != '' || $options['bpsexclude_input_17'] != '' || $options['bpsexclude_input_18'] != '' || $options['bpsexclude_input_19'] != '' || $options['bpsexclude_input_20'] != '') {
			
		$bps_option_name = 'bulletproof_security_options_ARCM';
	
		if ( ! isset($ARQoptions['bps_autorestore_cron_frequency']) ) {
			$bps_new_value_1 = '2';	
		} else {
			$bps_new_value_1 = $ARQoptions['bps_autorestore_cron_frequency'];
		}	
	
		$bps_new_value_2 = 'Off';

		if ( ! isset($ARQoptions['bps_autorestore_cron_override']) ) {
			$bps_new_value_3 = 'Off';
		} else {
			$bps_new_value_3 = $ARQoptions['bps_autorestore_cron_override'];
		}

		if ( ! isset($ARQoptions['bps_autorestore_cron_filecheck']) ) {
			$bps_new_value_3a = 'On';	
		} else {
			$bps_new_value_3a = $ARQoptions['bps_autorestore_cron_filecheck'];
		}

		if ( ! isset($ARQoptions['bps_autorestore_cron_forced']) ) {
			$bps_new_value_4 = '1';	
		} else {
			$bps_new_value_4 = $ARQoptions['bps_autorestore_cron_forced'];
		}	
	
		if ( ! isset($ARQoptions['bps_autorestore_cron_end']) ) {
			$bps_new_value_5 = '';	
		} else {
			$bps_new_value_5 = $ARQoptions['bps_autorestore_cron_end'];
		}

		$BPS_Options = array(
		'bps_autorestore_cron_frequency' 	=> $bps_new_value_1, 
		'bps_autorestore_cron' 				=> $bps_new_value_2, 
		'bps_autorestore_cron_override' 	=> $bps_new_value_3, 
		'bps_autorestore_cron_filecheck' 	=> $bps_new_value_3a, 
		'bps_autorestore_cron_forced' 		=> $bps_new_value_4, 
		'bps_autorestore_cron_end' 			=> $bps_new_value_5
		);	
	
		if ( ! get_option( $bps_option_name ) ) {	
		
			foreach( $BPS_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARCM', $BPS_Options);
			}
	
		} else {

			foreach( $BPS_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARCM', $BPS_Options);
			}	
		}

			$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('ARQ FailSafe Procedural Shutdown', 'bulletproof-security').'</font><br>'.__('This procedural ARQ FailSafe Shutdown happens when ARQ is turned On and you are creating Exclude Rules.', 'bulletproof-security').'<br>'.__('This FailSafe ensures that no files are accidentally sent to Quarantine while you are creating your Exclude Rules.', 'bulletproof-security').'<br>'.__('Once you have completed creating your Exclude Rules you can turn ARQ back On by selecting your Cron Check Frequency, selecting Turn On ARQ Cron and clicking the Save ARQ Cron Options button.', 'bulletproof-security').'<br>'.__('If you are going to manually modify any of your website files be sure to click the appropriate ARQ Backup Files button before turning ARQ back On.', 'bulletproof-security').'</div>';
			echo $text;
		}
	}
	}
}
add_action( 'admin_notices', 'bpsClassBackup' );

// Automated Uploads Folder BulletProof Mode
// Note: the way I did this is instead of using a uaeg db option to check against is I created a renamed uaeg htaccess file to check against. 
// Very funky. Change this at some point to make things simpler. When UAEG is deactivated it creates this file: manual_uploads-litespeed.htaccess.
// if a manual renamed uaeg file exists in the /htaccess/ folder then this function will not create a new uaeg file in the /uploads/ folder.
// Note: A copy of the .htaccess file does not need to be copied to bps-backup since the /uploads is not checked by ARQ
// 10.9|11: replace old UAEG htaccess files with new IfModule conditional htaccess files
// 11.2: UAEG Custom Code added - added a UAEG condition to "return" if UAEG Custom Code is being used
// 11.6: New sapi check for LiteSpeed to create the new LiteSpeed mod_rewrite UAEG htaccess file version.
// not going to automatically change the UAEG htaccess file and instead I will be adding a UAEG Reset button, which
// will do this manually if needed. The main reason for the new LS UAEG htaccess file is because of the SetEnvIf limitation for LiteSpeed.
function bps_Uploads_Folder_Lockdown() {

	if ( current_user_can('update_core') ) {

		$HFiles_options = get_option('bulletproof_security_options_htaccess_files');

		if ( isset( $HFiles_options['bps_htaccess_files'] ) && $HFiles_options['bps_htaccess_files'] == 'disabled' ) {
			return;
		}

		$bps_Uploads_Dir = wp_upload_dir();
		$UploadsHtaccess = $bps_Uploads_Dir['basedir'] . '/.htaccess';
		$UAEG_CC_options = get_option('bulletproof_security_options_customcode_UAEG');
		$sapi_type = php_sapi_name();
		
		if ( file_exists($UploadsHtaccess) ) {
			$check_string = @file_get_contents($UploadsHtaccess);
		} else {
			$check_string = '';
		}
	
		// LiteSpeed UAEG htaccess file creation
		if ( @substr($sapi_type, 0, 9) == 'litespeed' ) {
			
			$UploadsHtaccessLSMaster = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/uploads-litespeed.htaccess';
			$UploadsHtaccessLSRenamed = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/manual_uploads-litespeed.htaccess';	

			if ( is_dir( $bps_Uploads_Dir['basedir'] ) && ! file_exists($UploadsHtaccess) && ! file_exists($UploadsHtaccessLSRenamed) ) { 

				if ( @!copy($UploadsHtaccessLSMaster, $UploadsHtaccess) ) {
					$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Failed to Activate Uploads Folder BulletProof Mode', 'bulletproof-security').'</font><br>'.__('Unable to automatically Copy and Rename the ', 'bulletproof-security').$UploadsHtaccessLSMaster.__(' file to /', 'bulletproof-security').$bps_uploads_dir.__('/.htaccess.', 'bulletproof-security').'<br>'.__('If your Server API is DSO and not CGI/suPHP then you will have to manually activate the Uploads Folder BulletProof Mode on the Security Modes page.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the B-Core Security Modes page.', 'bulletproof-security').'</div>';
					echo $text;		
				}	
			}
		
		} else {

			if ( is_dir( $bps_Uploads_Dir['basedir'] ) && file_exists($UploadsHtaccess) && strpos( $check_string, "BPS mod_authz_core IfModule BC" ) || strpos( $check_string, "BPS mod_access_compat" ) || isset($UAEG_CC_options['bps_customcode_uaeg']) && $UAEG_CC_options['bps_customcode_uaeg'] != '' ) {
				return;
			}

			// Note: for the new Reset Form create dupes of these files and add -master in the filename.
			$UploadsHtaccessRenamed = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/manual_uploads.htaccess';
			$UploadsHtaccessRenamedIfmodule = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/manual_uploads_ifmodule.htaccess';
			$UploadsHtaccessMaster = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/uploads.htaccess';
			$UploadsHtaccessMasterIfmodule = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/uploads-ifmodule.htaccess';
			$bps_uploads_dir = str_replace( ABSPATH, '', $bps_Uploads_Dir['basedir'] );
			$bps_wpcontent_dir = str_replace( ABSPATH, '', WP_CONTENT_DIR );
			$Apache_Mod_options = get_option('bulletproof_security_options_apache_modules');
			
			if ( file_exists($UploadsHtaccess) ) {
				$stringReplace = @file_get_contents($UploadsHtaccess);
			} else {
				$stringReplace = '';
			}
			
			// this is very old code that should no longer affect anything and the pattern no longer matches anything.
			$pattern_uaeg = '/<FilesMatch(.*)\(7z\|as\|bat\|bin\|cgi\|chm\|chml\|class\|cmd\|com\|command\|dat\|db\|db2\|db3\|dba\|dll\|DS_Store\|exe\|gz\|hta\|htaccess\|htc\|htm\|html\|html5\|htx\|idc\|ini\|ins\|isp\|jar\|jav\|java\|js\|jse\|jsfl\|json\|jsp\|jsx\|lib\|lnk\|out\|php\|phps\|php5\|php4\|php3\|phtml\|phpt\|pl\|py\|pyd\|pyc\|pyo\|rar\|shtm\|shtml\|sql\|swf\|sys\|tar\|taz\|tgz\|tpl\|vb\|vbe\|vbs\|war\|ws\|wsf\|xhtml\|xml\|z\)\$\">\s*Order Deny,Allow\s*Deny from all\s*#Allow from example.com\s*<\/FilesMatch>/';

			// 10.9|11: replace the old UAEG htaccess file on BPS upgrade if UAEG is not deactivated & if the old htaccess file has not been customized
			if ( file_exists($UploadsHtaccess) && preg_match( $pattern_uaeg, $stringReplace, $matches ) && ! file_exists($UploadsHtaccessRenamed) && ! file_exists($UploadsHtaccessRenamedIfmodule) ) {
			
				if ( $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'Yes' && ! strpos( $check_string, "BPS mod_authz_core IfModule BC" ) ) {
					@copy($UploadsHtaccessMasterIfmodule, $UploadsHtaccess);
				} elseif ( $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'No' && ! strpos( $check_string, "BPS mod_access_compat" ) ) {
					@copy($UploadsHtaccessMaster, $UploadsHtaccess);
				}		
			}

			// new installations create the UAEG htaccess file. Also only create UAEG htaccess file if UAEG is not deactivated
			if ( isset($Apache_Mod_options['bps_apache_mod_ifmodule']) && $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'No' && is_dir( $bps_Uploads_Dir['basedir'] ) && ! file_exists($UploadsHtaccess) && ! file_exists($UploadsHtaccessRenamed ) ) {
			if ( @!copy($UploadsHtaccessMaster, $UploadsHtaccess) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Failed to Activate Uploads Folder BulletProof Mode', 'bulletproof-security').'</font><br>'.__('Unable to automatically Copy and Rename the ', 'bulletproof-security').$UploadsHtaccessMaster.__(' file to /', 'bulletproof-security').$bps_uploads_dir.__('/.htaccess.', 'bulletproof-security').'<br>'.__('If your Server API is DSO and not CGI/suPHP then you will have to manually activate the Uploads Folder BulletProof Mode on the Security Modes page.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the B-Core Security Modes page.', 'bulletproof-security').'</div>';
				echo $text;		
			}
			}
	
			if ( isset($Apache_Mod_options['bps_apache_mod_ifmodule']) && $Apache_Mod_options['bps_apache_mod_ifmodule'] == 'Yes' && is_dir( $bps_Uploads_Dir['basedir'] ) && ! file_exists($UploadsHtaccess) && ! file_exists($UploadsHtaccessRenamedIfmodule ) ) {
			if ( @!copy($UploadsHtaccessMasterIfmodule, $UploadsHtaccess) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Failed to Activate Uploads Folder BulletProof Mode', 'bulletproof-security').'</font><br>'.__('Unable to automatically Copy and Rename the ', 'bulletproof-security').$UploadsHtaccessMasterIfmodule.__(' file to /', 'bulletproof-security').$bps_uploads_dir.__('/.htaccess.', 'bulletproof-security').'<br>'.__('If your Server API is DSO and not CGI/suPHP then you will have to manually activate the Uploads Folder BulletProof Mode on the Security Modes page.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the B-Core Security Modes page.', 'bulletproof-security').'</div>';
				echo $text;		
			}
			}	
		} // if ( @substr($sapi_type, 0, 9) == 'litespeed' ) { 
	} // end if user can update core
}

add_action('admin_notices', 'bps_Uploads_Folder_Lockdown');

// BPS Master htaccess File Editing - file checks and get contents for editor
function bps_get_secure_htaccess() {
$secure_htaccess_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/secure.htaccess';

	if ( file_exists($secure_htaccess_file) ) {
		$bpsString = file_get_contents($secure_htaccess_file);
		echo $bpsString;
	} else {
		$bps_plugin_dir = str_replace( ABSPATH, '', WP_PLUGIN_DIR );
		_e('The secure.htaccess file either does not exist or is not named correctly. Check the /', 'bulletproof-security').$bps_plugin_dir.__('/bulletproof-security/admin/htaccess/ folder to make sure the secure.htaccess file exists and is named secure.htaccess.', 'bulletproof-security');
	}
}

function bps_get_default_htaccess() {
$default_htaccess_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/default.htaccess';

	if ( file_exists($default_htaccess_file) ) {
		$bpsString = file_get_contents($default_htaccess_file);
		echo $bpsString;
	} else {
		$bps_plugin_dir = str_replace( ABSPATH, '', WP_PLUGIN_DIR );
		_e('The default.htaccess file either does not exist or is not named correctly. Check the /', 'bulletproof-security').$bps_plugin_dir.__('/bulletproof-security/admin/htaccess/ folder to make sure the default.htaccess file exists and is named default.htaccess.', 'bulletproof-security');
	}
}

function bps_get_plugins_htaccess() {
$file = WP_PLUGIN_DIR . '/.htaccess';
	
	if ( file_exists($file) ) {
		$bpsString = file_get_contents($file);
		echo $bpsString;
	} else {
		$bps_plugin_dir = str_replace( ABSPATH, '', WP_PLUGIN_DIR );
		_e('An htaccess file was not found in your /', 'bulletproof-security').$bps_plugin_dir.__(' folder.', 'bulletproof-security');
	}
}

function bps_get_uploads_htaccess() {
$bps_Uploads_Dir = wp_upload_dir();
$UploadsHtaccess = $bps_Uploads_Dir['basedir'] . '/.htaccess'; // for both single and Multisite is the standard /uploads folder
	
	if ( file_exists($UploadsHtaccess) ) {
		$bpsString = file_get_contents($UploadsHtaccess);
		echo $bpsString;
	} else {
		_e('An htaccess file was not found in your /uploads folder.', 'bulletproof-security');
	}
}

function bps_get_wpadmin_htaccess() {
$wpadmin_htaccess_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/wpadmin-secure.htaccess';

	if ( file_exists($wpadmin_htaccess_file) ) {
		$bpsString = file_get_contents($wpadmin_htaccess_file);
		echo $bpsString;
	} else {
		$bps_plugin_dir = str_replace( ABSPATH, '', WP_PLUGIN_DIR );
		_e('The wpadmin-secure.htaccess file either does not exist or is not named correctly. Check the /', 'bulletproof-security').$bps_plugin_dir.__('/bulletproof-security/admin/htaccess/ folder to make sure the wpadmin-secure.htaccess file exists and is named wpadmin-secure.htaccess.', 'bulletproof-security');
	}
}

// The current active root htaccess file - file check
function bps_get_root_htaccess() {
$root_htaccess_file = ABSPATH . '.htaccess';
	
	if ( file_exists($root_htaccess_file) ) {
		$bpsString = file_get_contents($root_htaccess_file);
		echo $bpsString;
	} else {
		_e('An htaccess file was not found in your website root folder.', 'bulletproof-security');
	}
}

// The current active wp-admin htaccess file - file check
function bps_get_current_wpadmin_htaccess_file() {
$current_wpadmin_htaccess_file = ABSPATH . 'wp-admin/.htaccess';
	
	if ( file_exists($current_wpadmin_htaccess_file) ) {
		$bpsString = file_get_contents($current_wpadmin_htaccess_file);
		echo $bpsString;
	} else {
		_e('An htaccess file was not found in your wp-admin folder.', 'bulletproof-security');
	}
}

// File write checks for editor
function bps_secure_htaccess_file_check() {
$secure_htaccess_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/secure.htaccess';
	
	if ( ! is_writable($secure_htaccess_file) ) {
		$text = '<font color="#fb0101"><strong>'.__('Cannot write to the secure.htaccess file. Cause: file Permission or file Ownership problem.', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	}
}

// File write checks for editor
function bps_default_htaccess_file_check() {
$default_htaccess_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/default.htaccess';
	
	if ( ! is_writable($default_htaccess_file) ) {
		$text = '<font color="#fb0101"><strong>'.__('Cannot write to the default.htaccess file. Cause: file Permission or file Ownership problem.', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	}
}

// File write checks for editor
function bps_wpadmin_htaccess_file_check() {
$wpadmin_htaccess_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/wpadmin-secure.htaccess';
	
	if ( ! is_writable($wpadmin_htaccess_file) ) {
		$text = '<font color="#fb0101"><strong>'.__('Cannot write to the wpadmin-secure.htaccess file. Cause: file Permission or file Ownership problem.', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	}
}

// File write checks for editor
function bps_root_htaccess_file_check() {
$root_htaccess_file = ABSPATH . '.htaccess';
	
	if ( ! is_writable($root_htaccess_file) ) {
		$text = '<font color="#fb0101"><strong>'.__('Cannot write to the Root htaccess file. Cause: file Permission or file Ownership problem.', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	}
}

// File write checks for editor
function bps_current_wpadmin_htaccess_file_check() {
$current_wpadmin_htaccess_file = ABSPATH . 'wp-admin/.htaccess';
	
	if ( ! is_writable($current_wpadmin_htaccess_file) ) {
		$text = '<font color="#fb0101"><strong>'.__('Cannot write to the wp-admin htaccess file. Cause: file Permission or file Ownership problem.', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	}
}

// File and Folder Permission Checking
function bps_check_perms($path, $perm) {
clearstatcache();
$current_perms = @substr(sprintf('%o', fileperms($path)), -4);
$stat = @stat($path);

	echo '<table style="width:100%;background-color:#fff;">';
	echo '<tr>';
    echo '<td style="color:#000;background-color:#fff;padding:2px;width:40%;">' . $path . '</td>';
    echo '<td style="color:#000;background-color:#fff;padding:2px;width:15%;">' . $perm . '</td>';
    echo '<td style="color:#000;background-color:#fff;padding:2px;width:15%;">' . $current_perms . '</td>';
    echo '<td style="color:#000;background-color:#fff;padding:2px;width:15%;">' . $stat['uid'] . '</td>';
    echo '<td style="color:#000;background-color:#fff;padding:2px;width:15%;">' . @fileowner( $path ) . '</td>';
    echo '</tr>';
	echo '</table>';
}

// Display Root or Subfolder Installation Type
function bps_wp_get_root_folder_display_type() {
$site_root = parse_url(get_option('siteurl'));
	if ( isset( $site_root['path'] ) )
		$site_root = trailingslashit($site_root['path']);
	else
		$site_root = '/';
	if ( preg_match('/[a-zA-Z0-9]/', $site_root) ) {
		echo __('Subfolder Installation', 'bulletproof-security');
	} else {
		echo __('Root Folder Installation', 'bulletproof-security');
	}
}

// System Info page - Check for GWIOD
function bps_gwiod_site_type_check() {
$WordPress_Address_url = get_option('home');
$Site_Address_url = get_option('siteurl');
	
	if ( $WordPress_Address_url == $Site_Address_url ) {
		echo __('Standard WP Site Type', 'bulletproof-security');
	} else {
		echo __('GWIOD WP Site Type', 'bulletproof-security').'<br>';
		echo __('WordPress Address (URL): ', 'bulletproof-security').$WordPress_Address_url.'<br>';
		echo __('Site Address (URL): ', 'bulletproof-security').$Site_Address_url;
	}	
}

// System Info page - Check for BuddyPress
function bps_buddypress_site_type_check() {

	if ( function_exists('bp_is_active') ) {
		echo __('BuddyPress is installed|enabled', 'bulletproof-security');
	} else {
		echo __('BuddyPress is not installed|enabled', 'bulletproof-security');
	}
}

// System Info page - Check for bbPress
function bps_bbpress_site_type_check() {

	if ( function_exists('is_bbpress') ) {
		echo __('bbPress is installed|enabled', 'bulletproof-security');
	} else {
		echo __('bbPress is not installed|enabled', 'bulletproof-security');
	}
}

// System Info page - Check for Multisite/Subdirectory/Subdomain
function bps_multisite_check() {  
	
	if ( ! is_multisite() ) { 
		$text = __('Network|Multisite is not installed|enabled', 'bulletproof-security');
		echo $text;	
	
	} else {
		
		if ( ! is_subdomain_install() ) {
			$text = __('Subdirectory Site Type', 'bulletproof-security');
			echo $text;
		} else {
			$text = __('Subdomain Site Type', 'bulletproof-security');
			echo $text;			
		}
	}
}

// Get SQL Mode from WPDB
function bps_get_sql_mode() {
global $wpdb;
$sql_mode_var = 'sql_mode';
$mysqlinfo = $wpdb->get_results( $wpdb->prepare( "SHOW VARIABLES LIKE %s", $sql_mode_var ) );	
	
	if ( is_array( $mysqlinfo ) ) { 
		$sql_mode = $mysqlinfo[0]->Value;
		if ( empty( $sql_mode ) ) { 
			$sql_mode = __('Not Set', 'bulletproof-security');
		} else {
			$sql_mode = __('Off', 'bulletproof-security');
		}
	}
}

// Show DB errors should already be set to false in /includes/wp-db.php
// Extra function insurance show_errors = false
function bps_wpdb_errors_off() {
global $wpdb;
$wpdb->show_errors = false;
	
	if ( $wpdb->show_errors != false ) {
		$text = '<font color="#fb0101"><strong>'.__('DB Show Errors: On. DB errors will be displayed', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	} else {
		$text = '<strong>'.__('DB Show Errors: ', 'bulletproof-security').'</strong>'.__('Off', 'bulletproof-security').'<br>';
		echo $text;
	}	
}

// AutoRestore Cron Off displayed message on AutoRestore page
function bpsProAutoRestoreOff() {
$options = get_option('bulletproof_security_options_ARCM');
	
	if ( isset($options['bps_autorestore_cron_override']) && $options['bps_autorestore_cron_override'] == 'On' ) {
		$text = '<font color="blue"><strong>'.__('AutoRestore|Quarantine Override is Turned On', 'bulletproof-security').'<br>'.__('ARQ is turned Off.', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	return;
	}

	if ( isset($options['bps_autorestore_cron']) && $options['bps_autorestore_cron'] == 'Off' ) {
		$text = '<font color="#fb0101"><strong>'.__('AutoRestore|Quarantine Cron is Turned Off', 'bulletproof-security').'<br>'.__('and Scheduled Cron Jobs Have Been Removed.', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	}
}

// AutoRestore Cron On displayed message on AutoRestore page
function bpsProAutoRestoreOn() {
	
	if ( ! get_option('bulletproof_security_options_ARCM') ) {
		$text = '<font color="#fb0101"><strong>'.__('You have not selected your ARQ Cron Options', 'bulletproof-security').'<br>'.__('and clicked Save ARQ Cron Options yet.', 'bulletproof-security').'</strong></font><br>';
		echo $text;
	
	} else {
	
		$options = get_option('bulletproof_security_options_ARCM');
	
	if ( $options['bps_autorestore_cron'] == 'On' && $options['bps_autorestore_cron_override'] != 'On' ) {
	
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;
		$bpsCronCheck = wp_get_schedule( 'bpsPro_AutoRestore_check' );
		$ARQ_cron_time = wp_next_scheduled( 'bpsPro_AutoRestore_check' );
		$arq_next_check = date_i18n( get_option('time_format'), $ARQ_cron_time + $gmt_offset );

	if ( $bpsCronCheck == 'minutes_1' ) {
		$text = '<font color="green"><strong>'.__('AutoRestore|Quarantine ARQ Cron is On', 'bulletproof-security').'<br>'.__('Check files every 60 seconds. Next Check: ', 'bulletproof-security').$arq_next_check.'</strong></font><br>';
		echo $text;
	}
	
	if ( $bpsCronCheck == 'minutes_2' ) {
		$text = '<font color="green"><strong>'.__('AutoRestore|Quarantine ARQ Cron is On', 'bulletproof-security').'<br>'.__('Check files every 2 minutes. Next Check: ', 'bulletproof-security').$arq_next_check.'</strong></font><br>';
		echo $text;
	}

	if ( $bpsCronCheck == 'minutes_3' ) {
		$text = '<font color="green"><strong>'.__('AutoRestore|Quarantine ARQ Cron is On', 'bulletproof-security').'<br>'.__('Check files every 3 minutes. Next Check: ', 'bulletproof-security').$arq_next_check.'</strong></font><br>';
		echo $text;
	}

	if ( $bpsCronCheck == 'minutes_4' ) {
		$text = '<font color="green"><strong>'.__('AutoRestore|Quarantine ARQ Cron is On', 'bulletproof-security').'<br>'.__('Check files every 4 minutes. Next Check: ', 'bulletproof-security').$arq_next_check.'</strong></font><br>';
		echo $text;
	}

	if ( $bpsCronCheck == 'minutes_5' ) {
		$text = '<font color="green"><strong>'.__('AutoRestore|Quarantine ARQ Cron is On', 'bulletproof-security').'<br>'.__('Check files every 5 minutes. Next Check: ', 'bulletproof-security').$arq_next_check.'</strong></font><br>';
		echo $text;	
	}
	
	if ( $bpsCronCheck == 'minutes_10' ) {
		$text = '<font color="green"><strong>'.__('AutoRestore|Quarantine ARQ Cron is On', 'bulletproof-security').'<br>'.__('Check files every 10 minutes. Next Check: ', 'bulletproof-security').$arq_next_check.'</strong></font><br>';
		echo $text;
	}
	
	if ( $bpsCronCheck == 'minutes_15' ) {
		$text = '<font color="green"><strong>'.__('AutoRestore|Quarantine ARQ Cron is On', 'bulletproof-security').'<br>'.__('Check files every 15 minutes. Next Check: ', 'bulletproof-security').$arq_next_check.'</strong></font><br>';
		echo $text;
	}
	if ( $bpsCronCheck == 'minutes_30' ) {
		$text = '<font color="green"><strong>'.__('AutoRestore|Quarantine ARQ Cron is On', 'bulletproof-security').'<br>'.__('Check files every 30 minutes. Next Check: ', 'bulletproof-security').$arq_next_check.'</strong></font><br>';
		echo $text;
	}
	if ( $bpsCronCheck == 'minutes_60' ) {
		$text = '<font color="green"><strong>'.__('AutoRestore|Quarantine ARQ Cron is On', 'bulletproof-security').'<br>'.__('Check files every 60 minutes. Next Check: ', 'bulletproof-security').$arq_next_check.'</strong></font><br>';
		echo $text;
	}
	}
	}
}

// F-Lock - Check if F-Lock options saved - F-Lock Lock / Unlock File Status & actual file permissions 404 or 400 - WP Only
function bps_smonitor_flock_wp() {
	
	if ( current_user_can('manage_options') ) {
	
		$fl_override_options = get_option('bulletproof_security_options_flock_eol');
		
		if ( isset($fl_override_options['bps_file_lock_override']) && $fl_override_options['bps_file_lock_override'] == 'Off' ) {
			return;
		}

		$options = get_option('bulletproof_security_options_monitor');

		if ( isset($options['bps_flock_status']) && $options['bps_flock_status'] == 'Off' ) {
			return;
		}
	
		if ( ! get_option('bulletproof_security_options_flock') ) {
		if ( isset($options['bps_flock_status']) && $options['bps_flock_status'] == 'wpOn' ) { 
			$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);">'.__('BPS Pro F-Lock Notification', 'bulletproof-security').'<br>'.__('F-Lock options have not been saved yet.', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the F-Lock page to choose and save your File Lock|Unlock options.', 'bulletproof-security').'</div>';
			echo $text;
		}
		}

		if ( isset($options['bps_flock_status']) && @$options['bps_flock_status'] == 'wpOn' ) { 
	
			if ( isset ( $_POST['bpsFlockSubmit'] ) && $_POST['bpsFlockSubmit'] == true ) {
				return;
			}
	
			clearstatcache();
	
			$open_basedir = ini_get('open_basedir');
	
			$fileRH = ABSPATH . '.htaccess';
			$fileWPC = ABSPATH . 'wp-config.php';
			$fileRI = ABSPATH . 'index.php';
			$fileBH = ABSPATH . 'wp-blog-header.php';
			$fileDRH = $_SERVER['DOCUMENT_ROOT'] . '/.htaccess';
			$fileDRI = $_SERVER['DOCUMENT_ROOT'] . '/index.php';
			$fileHGWIOD = dirname(ABSPATH) . '/.htaccess';
			$fileIGWIOD = dirname(ABSPATH) . '/index.php';
	
			if ( file_exists($fileRH) ) {
				$permsRH = @substr(sprintf('%o', fileperms($fileRH)), -4);
			}
			if ( file_exists($fileWPC) ) {
				$permsWPC = @substr(sprintf('%o', fileperms($fileWPC)), -4);
			}
			if ( file_exists($fileRI) ) {		
				$permsRI = @substr(sprintf('%o', fileperms($fileRI)), -4);
			}
			if ( file_exists($fileBH) ) {			
				$permsBH = @substr(sprintf('%o', fileperms($fileBH)), -4);
			}
			if ( file_exists($fileDRH) ) {
				$permsDRH = @substr(sprintf('%o', fileperms($fileDRH)), -4);
			}
			if ( file_exists($fileDRI) ) {
				$permsDRI = @substr(sprintf('%o', fileperms($fileDRI)), -4);
			}
			
			# Quick Fix: do more with this later
			if ( $open_basedir == '' ) {
				
				if ( file_exists($fileHGWIOD) ) {
					$permsHGWIOD = @substr(sprintf('%o', fileperms($fileHGWIOD)), -4);
				}
				if ( file_exists($fileIGWIOD) ) {
					$permsIGWIOD = @substr(sprintf('%o', fileperms($fileIGWIOD)), -4);
				}
			}
			
			$options2 = get_option('bulletproof_security_options_flock'); 
			$GDMW_options = get_option('bulletproof_security_options_GDMW');
	
			if ( $options2['bps_lock_root_htaccess'] == 'off' || !$options2['bps_lock_root_htaccess'] ) { 
				echo '';
			}	
			elseif ( $options2['bps_lock_root_htaccess'] == 'no' || file_exists($fileRH) && $permsRH != '0404' ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your Root htaccess File is not Locked', 'bulletproof-security').'</font><br>'.__('To Lock your Root htaccess file ', 'bulletproof-security').'<a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>.</div>';
				echo $text;
			}
			if ( $options2['bps_lock_wpconfig'] == 'off' || !$options2['bps_lock_wpconfig'] ) {
				echo '';
			}
			elseif ( $options2['bps_lock_wpconfig'] == 'no' || $permsWPC != '0400' && file_exists($fileWPC) ) { 
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your wp-config.php File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your wp-config.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_index_php'] == 'off' || !$options2['bps_lock_index_php'] || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) { 
				echo '';
			}	
			elseif ( $options2['bps_lock_index_php'] == 'no' || $permsRI != '0400' ) { 
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your WP Root index.php File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your WP Root index.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_wpblog_header'] == 'off' || !$options2['bps_lock_wpblog_header'] || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_wpblog_header'] == 'no' || $permsBH != '0400' ) { 
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your wp-blog-header.php File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your wp-blog-header.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_root_htaccess_dr'] == 'off' || !$options2['bps_lock_root_htaccess_dr'] ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_root_htaccess_dr'] == 'no' || $permsDRH != '0404' && file_exists($fileDRH) ) { 
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your DR Root htaccess File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your DR Root htaccess file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_index_php_dr'] == 'off' || !$options2['bps_lock_index_php_dr'] || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_index_php_dr'] == 'no' || $permsDRI != '0400' && file_exists($fileDRI) ) { 
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your DR WP index.php File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your DR WP index.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_root_htaccess_gwiod'] == 'off' || !$options2['bps_lock_root_htaccess_gwiod'] ) { 
				echo '';
			}
			elseif ( $options2['bps_lock_root_htaccess_gwiod'] == 'no' || $permsHGWIOD != '0404' && file_exists($fileHGWIOD) ) { 
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your GWIOD Root htaccess File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your GWIOD Root htaccess file.', 'bulletproof-security').'</div>';
				echo $text;
			}
			if ( $options2['bps_lock_index_php_gwiod'] == 'off' || !$options2['bps_lock_index_php_gwiod'] || $GDMW_options['bps_gdmw_hosting'] == 'yes' ) { 
			echo '';
			}
			elseif ( $options2['bps_lock_index_php_gwiod'] == 'no' || $permsIGWIOD != '0400' && file_exists($fileIGWIOD) ) { 
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="#fb0101">'.__('Your GWIOD WP index.php File is not Locked', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/lock/flock.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' To Lock your GWIOD WP index.php file.', 'bulletproof-security').'</div>';
				echo $text;
			}
		}
	}
}
add_action('admin_notices', 'bps_smonitor_flock_wp');

// Maintenance Mode On Dashboard Alert
function bpsPro_mmode_dashboard_alert() {

if ( current_user_can('manage_options') ) {

	$MMoptions = get_option('bulletproof_security_options_maint_mode');

	if ( ! is_multisite() ) {
		
	if ( ! get_option('bulletproof_security_options_maint_mode') || $MMoptions['bps_maint_on_off'] == 'Off' ) {
	return;
	}	
	
		$indexPHP = ABSPATH . 'index.php';
		
		if ( file_exists($indexPHP) ) {
			$check_string_index = @file_get_contents($indexPHP);			
		}

		$wpadminHtaccess = ABSPATH . 'wp-admin/.htaccess';		
		
		if ( file_exists($wpadminHtaccess) ) {
			$check_string_wpadmin = @file_get_contents($wpadminHtaccess);			
		}

		if ( $MMoptions['bps_maint_on_off'] == 'On' && $MMoptions['bps_maint_dashboard_reminder'] == '1' ) {	
	
			if ( strpos( $check_string_index, "BEGIN BPS MAINTENANCE MODE IP" ) && ! strpos( $check_string_wpadmin, "BEGIN BPS MAINTENANCE MODE IP" ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend Maintenance Mode is Turned On.', 'bulletproof-security').'</font></div>';
				echo $text;				
			} elseif ( ! strpos( $check_string_index, "BEGIN BPS MAINTENANCE MODE IP" ) && strpos( $check_string_wpadmin, "BEGIN BPS MAINTENANCE MODE IP" ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Backend Maintenance Mode is Turned On.', 'bulletproof-security').'</font></div>';
				echo $text;	
			} elseif ( strpos( $check_string_index, "BEGIN BPS MAINTENANCE MODE IP" ) && strpos( $check_string_wpadmin, "BEGIN BPS MAINTENANCE MODE IP" ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend & Backend Maintenance Modes are Turned On.', 'bulletproof-security').'</font></div>';
				echo $text;				
			}
		}
	}
	
	if ( is_multisite() ) {
		global $current_blog, $blog_id;
		
		$root_folder_maintenance_values = ABSPATH . 'bps-maintenance-values.php';
		if ( file_exists($root_folder_maintenance_values) ) {		
			$check_string_values = @file_get_contents($root_folder_maintenance_values);			
		}
		
		$indexPHP = ABSPATH . 'index.php';
		if ( file_exists($indexPHP) ) {
			$check_string_index = @file_get_contents($indexPHP);
		}
		
		$wpadminHtaccess = ABSPATH . 'wp-admin/.htaccess';
		if ( file_exists($wpadminHtaccess) ) {		
			$check_string_wpadmin = @file_get_contents($wpadminHtaccess);
		}
		
		if ( $blog_id == 1 && $MMoptions['bps_maint_dashboard_reminder'] == '1' ) {

			if ( strpos( $check_string_values, '$all_sites = \'1\';' ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend Maintenance Mode is Turned On for The Primary Site and All Subsites.', 'bulletproof-security').'</font></div>';
				echo $text;	
			}
		
			if ( strpos( $check_string_values, '$all_subsites = \'1\';' ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend Maintenance Mode is Turned On for All Subsites, but Not The Primary Site.', 'bulletproof-security').'</font></div>';
				echo $text;	
			}	
	
		if ( $MMoptions['bps_maint_on_off'] == 'On' ) {

			if ( strpos( $check_string_index, '$primary_site_status = \'On\';' ) && ! strpos( $check_string_wpadmin, "BEGIN BPS MAINTENANCE MODE IP" ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend Maintenance Mode is Turned On.', 'bulletproof-security').'</font></div>';
				echo $text;				
			} elseif ( !strpos($check_string_index, '$primary_site_status = \'On\';') && strpos($check_string_wpadmin, "BEGIN BPS MAINTENANCE MODE IP") ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Backend Maintenance Mode is Turned On.', 'bulletproof-security').'</font></div>';
				echo $text;	
			} elseif ( strpos($check_string_index, '$primary_site_status = \'On\';') && strpos($check_string_wpadmin, "BEGIN BPS MAINTENANCE MODE IP") ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend & Backend Maintenance Modes are Turned On.', 'bulletproof-security').'</font></div>';
				echo $text;				
			}
		}
		}
	
		if ( $blog_id != 1 ) {
		
			if ( is_subdomain_install() ) {
		
				$subsite_remove_slashes = str_replace( '.', "-", $current_blog->domain );	
	
			} else {
	
				$subsite_remove_slashes = str_replace( '/', "", $current_blog->path );
			}			
			
			$subsite_maintenance_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/bps-maintenance-'.$subsite_remove_slashes.'.php';		

			if ( strpos( $check_string_values, '$all_sites = \'1\';' ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend Maintenance Mode is Turned On for The Primary Site and All Subsites.', 'bulletproof-security').'</font></div>';
				echo $text;	
			}
		
			if ( strpos( $check_string_values, '$all_subsites = \'1\';' ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend Maintenance Mode is Turned On for All Subsites, but Not The Primary Site.', 'bulletproof-security').'</font></div>';
				echo $text;	
			}		
		
		if ( $MMoptions['bps_maint_on_off'] == 'On' && $MMoptions['bps_maint_dashboard_reminder'] == '1' ) {

			if ( file_exists($subsite_maintenance_file) && ! strpos( $check_string_wpadmin, "BEGIN BPS MAINTENANCE MODE IP" ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend Maintenance Mode is Turned On.', 'bulletproof-security').'</font></div>';
				echo $text;				
			} elseif ( ! file_exists($subsite_maintenance_file) && strpos( $check_string_wpadmin, "BEGIN BPS MAINTENANCE MODE IP" ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Backend Maintenance Mode is Turned On.', 'bulletproof-security').'</font></div>';
				echo $text;	
			} elseif ( file_exists($subsite_maintenance_file) && strpos( $check_string_wpadmin, "BEGIN BPS MAINTENANCE MODE IP" ) ) {
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('Reminder: Frontend & Backend Maintenance Modes are Turned On.', 'bulletproof-security').'</font></div>';
				echo $text;				
			}		
		}
		}
	} // end is multisite
}
}

add_action('admin_notices', 'bpsPro_mmode_dashboard_alert');

// Login Security Disable Password Reset notice: Displays a message that backend password reset has been disabled
function bpsPro_login_security_password_reset_disabled_notice() {

	if ( current_user_can( 'update_core' ) ) {
	
		global $pagenow;	

		if ( 'profile.php' == $pagenow || 'user-edit.php' == $pagenow || 'user-new.php' == $pagenow ) {
		
			$BPSoptions = get_option('bulletproof_security_options_login_security');		
		
			if ( $BPSoptions['bps_login_security_OnOff'] == 'On' && $BPSoptions['bps_login_security_pw_reset'] == 'disable' ) {
		
				$text = '<div class="update-nag" style="background-color:#dfecf2;border:1px solid #999;font-size:1em;font-weight:600;padding:2px 5px;margin-top:2px;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><font color="blue">'.__('BPS Login Security Disable Password Reset Frontend & Backend is turned On.', 'bulletproof-security').'</font><br>'.__('Backend Password Reset has been disabled. To enable Backend Password Reset click ', 'bulletproof-security').'<br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/login/login.php' ).'">'.__('here', 'bulletproof-security').'</a></div>';
				echo $text;
			}
		}
	}
}

add_action('admin_notices', 'bpsPro_login_security_password_reset_disabled_notice');
add_action('network_admin_notices', 'bpsPro_login_security_password_reset_disabled_notice');

// One time manual htaccess code update added in BPS Pro 9.8
// NOTE: Instead of automating old BPS version root htaccess correction, it needs to be done manually.
// New/current versions of BPS root htaccess files are automatically corrected.
// "Always On" flush_rewrite_rules code correction: Unfortunately this needs to be an "Always On" check in order for it to be 100% effective
// 11.4: added additional check for the BULLETPROOF string in the root htaccess file, otherwise on a new install the WP standard rewrite code will be deleted.
// 11.5: unlock the root htaccess file, autofix, backup to ARQ and lock the root htaccess file again.
function bpsPro_htaccess_manual_update_notice() {
	
	if ( current_user_can('manage_options') ) {

		$filename = ABSPATH . '.htaccess';
		$filename_ARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/root-files/auto_.htaccess';		
		
		if ( file_exists($filename) ) {

			$check_string = @file_get_contents($filename);
			$pattern = '/#\sBEGIN\sWordPress\s*<IfModule\smod_rewrite\.c>\s*RewriteEngine\sOn\s*RewriteBase(.*)\s*RewriteRule(.*)\s*RewriteCond((.*)\s*){2}RewriteRule(.*)\s*<\/IfModule>\s*#\sEND\sWordPress/';

			if ( strpos( $check_string, "BULLETPROOF" ) && preg_match( $pattern, $check_string, $flush_matches ) ) {
				
				$root_perms = @substr(sprintf('%o', fileperms($filename)), -4);
				$sapi_type = php_sapi_name();
				$autolock = get_option('bulletproof_security_options_autolock');
	
				if 	( @$root_perms == '0404') {
					$lock = '0404';			
				}

				if ( @substr( $sapi_type, 0, 6 ) != 'apache' || @$root_perms != '0666' || @$root_perms != '0777' ) { // Windows IIS, XAMPP, etc
					@chmod($filename, 0644);
				}
				
				$stringReplace = preg_replace('/#\sBEGIN\sWordPress\s*<IfModule\smod_rewrite\.c>\s*RewriteEngine\sOn\s*RewriteBase(.*)\s*RewriteRule(.*)\s*RewriteCond((.*)\s*){2}RewriteRule(.*)\s*<\/IfModule>\s*#\sEND\sWordPress/', "", $check_string);

				if ( file_put_contents($filename, $stringReplace) ) {
					
					if ( $autolock['bps_root_htaccess_autolock'] == 'On' || @$lock == '0404' ) {	
						@chmod($filename, 0404);
					}					
					
					@copy($filename, $filename_ARQ);
				}
			}				
		
			global $pagenow;

			// manual steps if version of BPS root htaccess file is very old
			if ( 'plugins.php' == $pagenow || preg_match( '/page=bulletproof-security\/admin\/core\/core\.php/', esc_html( $_SERVER['REQUEST_URI'] ) ) ) {

				$pos = strpos( $check_string, 'IMPORTANT!!! DO NOT DELETE!!! - B E G I N Wordpress' );
			
				if ( $pos === false ) {
    		
					return;
			
				} else {
    		
					echo '<div id="message" class="updated" style="background-color:#dfecf2;border:1px solid #999;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><p>';
					$text = '<strong><font color="blue">'.__('BPS Pro Notice: One-time Update Steps Required', 'bulletproof-security').'</font><br>'.__('Significant changes were made to the root and wp-admin htaccess files that require doing the one-time Update Steps below.', 'bulletproof-security').'<br>'.__('All future BPS upgrades will not require these one-time Update Steps to be performed.', 'bulletproof-security').'<br><a href="https://forum.ait-pro.com/forums/topic/root-and-wp-admin-htaccess-file-significant-changes/" target="_blank" title="Link opens in a new Browser window" style="text-decoration:underline;">'.__('Click Here', 'bulletproof-security').'</a>'.__(' If you would like to know what changes were made to the root and wp-admin htaccess files.', 'bulletproof-security').'<br>'.__('This Notice will go away automatically after doing all of the steps below.', 'bulletproof-security').'<br><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/core/core.php' ).'" style="text-decoration:underline;">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the BPS Pro Security Modes page.', 'bulletproof-security').'<br>'.__('1. Activate Root Folder BulletProof Mode.', 'bulletproof-security').'<br>'.__('2. Activate wp-admin Folder BulletProof Mode.', 'bulletproof-security').'</strong>';
					echo $text;
					echo '</p></div>';	
				}
			}
		}
	}
}

add_action('admin_notices', 'bpsPro_htaccess_manual_update_notice');

## 14.9: This function is no longer used. Pending deletion.
function bpsPro_presave_ui_theme_skin_options() {
	
	$ui_theme_skin_options = 'bulletproof_security_options_theme_skin';	
	$bps_ui_theme_skin = array( 'bps_ui_theme_skin' => 'blue' );
			
	if ( ! get_option( $ui_theme_skin_options ) ) {			
		
		foreach( $bps_ui_theme_skin as $key => $value ) {
			update_option('bulletproof_security_options_theme_skin', $bps_ui_theme_skin);
		}
	}	
}

## 14: Pre-Save the SLF filter options. Used in the Pre-Installation Wizard. 
## The default is now set to On. New option added to use to check against for BPS upgrades: bps_slf_filter_new
## 14.9: this function is no longer used. Pending deletion.
function bpsPro_presave_ui_theme_skin_SLF_options() {
	
	$bpsPro_SLF_options = get_option('bulletproof_security_options_SLF');
	
	if ( $bpsPro_SLF_options['bps_slf_filter_new'] != '14' ) {
	
		$BPS_SLF_Options = array( 
		'bps_slf_filter' 		=> 'On', 
		'bps_slf_filter_new' 	=> '14'
		);	

		foreach( $BPS_SLF_Options as $key => $value ) {
			update_option('bulletproof_security_options_SLF', $BPS_SLF_Options);
		}
	}	
}

// 11.4: POST Request Attack Protection code correction|addition
// 11.5: Condition added to allow commenting out wp-admin URI whitelist rule
function bpsPro_post_request_protection_check() {

	$pattern1 = '/BPS\sPOST\sRequest\sAttack\sProtection/';
	$pattern2 = '/#\sNEVER\sCOMMENT\sOUT\sTHIS\sLINE\sOF\sCODE\sBELOW\sFOR\sANY\sREASON(\s*){1}RewriteCond\s%\{REQUEST_URI\}\s\!\^\.\*\/wp-admin\/\s\[NC\]/';
	$pattern3 = '/#\sNEVER\sCOMMENT\sOUT\sTHIS\sLINE\sOF\sCODE\sBELOW\sFOR\sANY\sREASON(\s*){1}#{1,}(\s|){1,}RewriteCond\s%\{REQUEST_URI\}\s\!\^\.\*\/wp-admin\/\s\[NC\]/';

	$CC_options = get_option('bulletproof_security_options_customcode');
	
	if ( preg_match( $pattern3, htmlspecialchars_decode( $CC_options['bps_customcode_three'], ENT_QUOTES ), $matches ) ) {
		return;
	}
	
	if ( preg_match( $pattern1, htmlspecialchars_decode( $CC_options['bps_customcode_three'], ENT_QUOTES ), $matches ) && ! preg_match( $pattern2, htmlspecialchars_decode( $CC_options['bps_customcode_three'], ENT_QUOTES ), $matches ) ) {
		
		$bps_customcode_three = preg_replace('/RewriteCond\s%\{REQUEST_METHOD\}\sPOST\s\[NC\]/s', "RewriteCond %{REQUEST_METHOD} POST [NC]\n# NEVER COMMENT OUT THIS LINE OF CODE BELOW FOR ANY REASON\nRewriteCond %{REQUEST_URI} !^.*/wp-admin/ [NC]\n# Whitelist the WordPress Theme Customizer\nRewriteCond %{HTTP_REFERER} !^.*/wp-admin/customize.php", htmlspecialchars_decode( $CC_options['bps_customcode_three'], ENT_QUOTES ) );

	if ( ! is_multisite() ) {

		$Root_CC_Options = array(
		'bps_customcode_one' 				=> $CC_options['bps_customcode_one'], 
		'bps_customcode_server_signature' 	=> $CC_options['bps_customcode_server_signature'], 
		'bps_customcode_directory_index' 	=> $CC_options['bps_customcode_directory_index'], 
		'bps_customcode_server_protocol' 	=> $CC_options['bps_customcode_server_protocol'], 
		'bps_customcode_error_logging' 		=> $CC_options['bps_customcode_error_logging'], 
		'bps_customcode_deny_dot_folders' 	=> $CC_options['bps_customcode_deny_dot_folders'], 
		'bps_customcode_admin_includes' 	=> $CC_options['bps_customcode_admin_includes'], 
		'bps_customcode_wp_rewrite_start' 	=> $CC_options['bps_customcode_wp_rewrite_start'], 
		'bps_customcode_request_methods' 	=> $CC_options['bps_customcode_request_methods'], 
		'bps_customcode_two' 				=> $CC_options['bps_customcode_two'], 
		'bps_customcode_timthumb_misc' 		=> $CC_options['bps_customcode_timthumb_misc'], 
		'bps_customcode_bpsqse' 			=> $CC_options['bps_customcode_bpsqse'], 
		'bps_customcode_deny_files' 		=> $CC_options['bps_customcode_deny_files'], 
		'bps_customcode_three' 				=> $bps_customcode_three 
		);
				
	} else {
					
		$Root_CC_Options = array(
		'bps_customcode_one' 				=> $CC_options['bps_customcode_one'], 
		'bps_customcode_server_signature' 	=> $CC_options['bps_customcode_server_signature'], 
		'bps_customcode_directory_index' 	=> $CC_options['bps_customcode_directory_index'], 
		'bps_customcode_server_protocol' 	=> $CC_options['bps_customcode_server_protocol'], 
		'bps_customcode_error_logging' 		=> $CC_options['bps_customcode_error_logging'], 
		'bps_customcode_deny_dot_folders' 	=> $CC_options['bps_customcode_deny_dot_folders'], 
		'bps_customcode_admin_includes' 	=> $CC_options['bps_customcode_admin_includes'], 
		'bps_customcode_wp_rewrite_start' 	=> $CC_options['bps_customcode_wp_rewrite_start'], 
		'bps_customcode_request_methods' 	=> $CC_options['bps_customcode_request_methods'], 
		'bps_customcode_two' 				=> $CC_options['bps_customcode_two'], 
		'bps_customcode_timthumb_misc' 		=> $CC_options['bps_customcode_timthumb_misc'], 
		'bps_customcode_bpsqse' 			=> $CC_options['bps_customcode_bpsqse'], 
		'bps_customcode_wp_rewrite_end' 	=> $CC_options['bps_customcode_wp_rewrite_end'], 
		'bps_customcode_deny_files' 		=> $CC_options['bps_customcode_deny_files'], 
		'bps_customcode_three' 				=> $bps_customcode_three 
		);					
	}

		foreach( $Root_CC_Options as $key => $value ) {
			update_option('bulletproof_security_options_customcode', $Root_CC_Options);
		}
	}
}

// Check if WordPress Debugging & Debug Logging is turned on and display a message
// Note: cannot check defined('WP_DEBUG_DISPLAY') && true == WP_DEBUG_DISPLAY because it is turned On and is true by default.
function bpsPro_wp_debug_check() {

	if ( preg_match( '/page=bulletproof-security\/admin\/wizard\/wizard.php/', esc_html($_SERVER['QUERY_STRING']) ) ) {
		
		if ( defined('WP_DEBUG') && true == WP_DEBUG || defined('WP_DEBUG_LOG') && true == WP_DEBUG_LOG ) {
			echo '<div id="message" class="updated" style="background-color:#dfecf2;border:1px solid #999;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><p>';
		}

		if ( defined('WP_DEBUG') && true == WP_DEBUG ) {
	
			$text = '<strong><font color="blue">'.__('WordPress Debugging is turned On in your wp-config.php file', 'bulletproof-security').'</font><br>'.__('Turn Off WordPress Debugging before running the Pre-Installation Wizard and the Setup Wizard.', 'bulletproof-security').'<br>'.__('You are currently using ', 'bulletproof-security').'define(\'WP_DEBUG\', true)'.__(' in your wp-config.php file. To turn WP Debugging Off, change true to false in your wp-config.php file.', 'bulletproof-security').'</strong><br>';
			echo $text;
		}

		if ( defined('WP_DEBUG_LOG') && true == WP_DEBUG_LOG ) {
	
			$bpsPro_error_log_string = ini_get('error_log');
			$debug_log_wp = 'debug.log';
			$debug_log_pos = strpos( $bpsPro_error_log_string, $debug_log_wp );

			if ( $debug_log_pos !== false ) {
   			
				$text = '<strong><font color="blue">'.__('WordPress Debug Logging is turned On in your wp-config.php file', 'bulletproof-security').'</font><br>'.__('Turn Off WordPress Debug Logging before running the Pre-Installation Wizard and the Setup Wizard.', 'bulletproof-security').'<br>'.__('You are currently using ', 'bulletproof-security').'define(\'WP_DEBUG_LOG\', true)'.__(' in your wp-config.php file. To turn WP Debug Logging Off, change true to false in your wp-config.php file.', 'bulletproof-security').'</strong><br>';
				echo $text;
			 
			}		
		}

		if ( defined('WP_DEBUG') && true == WP_DEBUG || defined('WP_DEBUG_LOG') && true == WP_DEBUG_LOG ) {
			echo '</p></div>';
		}

	} elseif ( preg_match( '/page=bulletproof-security/', esc_html($_SERVER['QUERY_STRING']) ) ) {
		
		if ( defined('WP_DEBUG') && true == WP_DEBUG || defined('WP_DEBUG_LOG') && true == WP_DEBUG_LOG ) {
			echo '<div id="message" class="updated" style="background-color:#dfecf2;border:1px solid #999;-moz-border-radius-topleft:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-left-radius:3px;border-top-left-radius:3px;-moz-border-radius-topright:3px;-webkit-border-top-right-radius:3px;-khtml-border-top-right-radius:3px;border-top-right-radius:3px;-webkit-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);-moz-box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);box-shadow: 3px 3px 5px -1px rgba(153,153,153,0.7);"><p>';
		}

		if ( defined('WP_DEBUG') && true == WP_DEBUG ) {
	
			$text = '<strong><font color="blue">'.__('WordPress Debugging is turned On in your wp-config.php file', 'bulletproof-security').'</font><br>'.__('You are currently using ', 'bulletproof-security').'define(\'WP_DEBUG\', true)'.__(' in your wp-config.php file. To turn WP Debugging Off, change true to false in your wp-config.php file.', 'bulletproof-security').'</strong><br>';
			echo $text;
		}

		if ( defined('WP_DEBUG_LOG') && true == WP_DEBUG_LOG ) {
	
			$bpsPro_error_log_string = ini_get('error_log');
			$debug_log_wp = 'debug.log';
			$debug_log_pos = strpos( $bpsPro_error_log_string, $debug_log_wp );

			if ( $debug_log_pos !== false ) {
   			
				$text = '<strong><font color="blue">'.__('WordPress Debug Logging is turned On in your wp-config.php file', 'bulletproof-security').'</font><br>'.__('You are currently using ', 'bulletproof-security').'define(\'WP_DEBUG_LOG\', true)'.__(' in your wp-config.php file to log errors to the WordPress ', 'bulletproof-security').$bpsPro_error_log_string.__(' file instead of the BPS Pro php error log. The "PHP Error Log Path Does Not Match" error message and this message will go away automatically once WordPress Debug Logging is turned Off (set to false) in your wp-config.php file.', 'bulletproof-security').'</strong><br>';
				echo $text;
			 
			}
		}

		if ( defined('WP_DEBUG') && true == WP_DEBUG || defined('WP_DEBUG_LOG') && true == WP_DEBUG_LOG ) {
			echo '</p></div>';
		}
	}
}

add_action('admin_notices', 'bpsPro_wp_debug_check');

// 11.8: Reset php handler dismiss notice if Wordfence WAF disaster code is detected.
// Note: Has the extra added benefit of checking if the code was put in the correct CC text box.
function bpsPro_php_handler_dismiss_notice_reset() {
global $current_user;
$user_id = $current_user->ID;
$file = ABSPATH . '.htaccess';		
	
	if ( file_exists($file) ) {		

		$file_contents = @file_get_contents($file);
		$CustomCodeoptions = get_option('bulletproof_security_options_customcode');
		preg_match( '/Wordfence WAF/', $CustomCodeoptions['bps_customcode_one'], $DBmatches );

		if ( stripos( $file_contents, "Wordfence WAF" ) && ! $DBmatches[0] ) {
			
			delete_user_meta($user_id, 'bps_ignore_PhpiniHandler_notice');
		}
	}
}

// 13: Add R to the dumb downed Request Methods Filtered 405 htaccess code in Root Custom Code.
// 13.2: Revert: Remove R from the dumbed downed Request Methods Filtered 405 htaccess code in Root Custom Code.
// Add additional https scheme conditions to 3 htaccess security rules and combine 2 rules into 1 rule in Root and wp-admin Custom Code.
// Note: htmlspecialchars_decode() is not necessary.
// 14.4: removed the obsolete RMF code
function bpsPro_upgrade_CC_automatic_fix() {
	
	$CC_Options_root = get_option('bulletproof_security_options_customcode');
	$bps_get_wp_root_secure = bps_wp_get_root_folder();
	$bps_plugin_dir = str_replace( ABSPATH, '', WP_PLUGIN_DIR );
	//$pattern1 = '/RewriteRule\s\^\(\.\*\)\$(.*)\/bulletproof-security\/405\.php\s\[R,L\]/';
	$pattern2 = '/RewriteCond\s%\{THE_REQUEST\}\s\(\\\?.*%2a\)\+\(%20.*HTTP\(:\/.*\[NC,OR\]/';
	$pattern3 = '/RewriteCond\s%\{QUERY_STRING\}\s\[a-zA-Z0-9_\]=http:\/\/\s\[NC,OR\]/';
	$pattern4 = '/RewriteCond\s%\{QUERY_STRING\}\s\^\(\.\*\)cPath=http:\/\/\(\.\*\)\$\s\[NC,OR\]/';
	$pattern5 = '/RewriteCond\s%\{QUERY_STRING\}\shttp\\\:\s\[NC,OR\](.*\s*){1}.*RewriteCond\s%\{QUERY_STRING\}\shttps\\\:\s\[NC,OR\]/';

	/* the variable was wrong in this condition.
	if ( $CC_Options_root['bps_customcode_bpsqse'] != '' ) {

		if ( preg_match( $pattern1, $CC_Options_root['bps_customcode_request_methods'] ) ) {
			$bps_customcode_request_methods = preg_replace( $pattern1, "RewriteRule ^(.*)$ " . $bps_get_wp_root_secure . $bps_plugin_dir . "/bulletproof-security/405.php [L]", $CC_Options_root['bps_customcode_request_methods']);
		}
	
	} else {
		$bps_customcode_request_methods = $CC_Options_root['bps_customcode_request_methods'];
	}
	*/

	if ( $CC_Options_root['bps_customcode_bpsqse'] != '' ) {

		if ( preg_match( $pattern2, $CC_Options_root['bps_customcode_bpsqse'], $matches ) ) {			
			$p2 = array($pattern2);
			$r2 = array("RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)(http|https)(:/|/) [NC,OR]");
		} else {
			$p2 = array();
			$r2 = array();
		}

		if ( preg_match( $pattern3, $CC_Options_root['bps_customcode_bpsqse'], $matches ) ) {			
			$p3 = array($pattern3);
			$r3 = array("RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(http|https):// [NC,OR]");
		} else {
			$p3 = array();
			$r3 = array();
		}

		if ( preg_match( $pattern4, $CC_Options_root['bps_customcode_bpsqse'], $matches ) ) {			
			$p4 = array($pattern4);
			$r4 = array("RewriteCond %{QUERY_STRING} ^(.*)cPath=(http|https)://(.*)$ [NC,OR]");
		} else {
			$p4 = array();
			$r4 = array();
		}

		if ( preg_match( $pattern5, $CC_Options_root['bps_customcode_bpsqse'], $matches ) ) {			
			$p5 = array($pattern5);
			$r5 = array("RewriteCond %{QUERY_STRING} (http|https)\: [NC,OR]");
		} else {
			$p5 = array();
			$r5 = array();
		}

		$pattern_array = array_merge($p2, $p3, $p4, $p5);
		$replace_array = array_merge($r2, $r3, $r4, $r5);
		$bps_customcode_bpsqse_replace = preg_replace($pattern_array, $replace_array, $CC_Options_root['bps_customcode_bpsqse']);
	
	} else {
		$bps_customcode_bpsqse_replace = $CC_Options_root['bps_customcode_bpsqse'];
	}

	if ( ! is_multisite() ) {

		$Root_CC_Options = array(
		'bps_customcode_one' 				=> $CC_Options_root['bps_customcode_one'], 
		'bps_customcode_server_signature' 	=> $CC_Options_root['bps_customcode_server_signature'], 
		'bps_customcode_directory_index' 	=> $CC_Options_root['bps_customcode_directory_index'], 
		'bps_customcode_server_protocol' 	=> $CC_Options_root['bps_customcode_server_protocol'], 
		'bps_customcode_error_logging' 		=> $CC_Options_root['bps_customcode_error_logging'], 
		'bps_customcode_deny_dot_folders' 	=> $CC_Options_root['bps_customcode_deny_dot_folders'], 
		'bps_customcode_admin_includes' 	=> $CC_Options_root['bps_customcode_admin_includes'], 
		'bps_customcode_wp_rewrite_start' 	=> $CC_Options_root['bps_customcode_wp_rewrite_start'], 
		'bps_customcode_request_methods' 	=> $CC_Options_root['bps_customcode_request_methods'], 
		'bps_customcode_two' 				=> $CC_Options_root['bps_customcode_two'], 
		'bps_customcode_timthumb_misc' 		=> $CC_Options_root['bps_customcode_timthumb_misc'], 
		'bps_customcode_bpsqse' 			=> $bps_customcode_bpsqse_replace, 
		'bps_customcode_deny_files' 		=> $CC_Options_root['bps_customcode_deny_files'], 
		'bps_customcode_three' 				=> $CC_Options_root['bps_customcode_three'] 
		);
				
	} else {
					
		$Root_CC_Options = array(
		'bps_customcode_one' 				=> $CC_Options_root['bps_customcode_one'], 
		'bps_customcode_server_signature' 	=> $CC_Options_root['bps_customcode_server_signature'], 
		'bps_customcode_directory_index' 	=> $CC_Options_root['bps_customcode_directory_index'], 
		'bps_customcode_server_protocol' 	=> $CC_Options_root['bps_customcode_server_protocol'], 
		'bps_customcode_error_logging' 		=> $CC_Options_root['bps_customcode_error_logging'], 
		'bps_customcode_deny_dot_folders' 	=> $CC_Options_root['bps_customcode_deny_dot_folders'], 
		'bps_customcode_admin_includes' 	=> $CC_Options_root['bps_customcode_admin_includes'], 
		'bps_customcode_wp_rewrite_start' 	=> $CC_Options_root['bps_customcode_wp_rewrite_start'], 
		'bps_customcode_request_methods' 	=> $CC_Options_root['bps_customcode_request_methods'], 
		'bps_customcode_two' 				=> $CC_Options_root['bps_customcode_two'], 
		'bps_customcode_timthumb_misc' 		=> $CC_Options_root['bps_customcode_timthumb_misc'], 
		'bps_customcode_bpsqse' 			=> $bps_customcode_bpsqse_replace, 
		'bps_customcode_wp_rewrite_end' 	=> $CC_Options_root['bps_customcode_wp_rewrite_end'], 
		'bps_customcode_deny_files' 		=> $CC_Options_root['bps_customcode_deny_files'], 
		'bps_customcode_three' 				=> $CC_Options_root['bps_customcode_three'] 
		);					
	}

	foreach( $Root_CC_Options as $key => $value ) {
		update_option('bulletproof_security_options_customcode', $Root_CC_Options);
	}

	$CC_Options_wpadmin = get_option('bulletproof_security_options_customcode_WPA');
	
	if ( $CC_Options_wpadmin['bps_customcode_bpsqse_wpa'] != '' ) {

		if ( preg_match( $pattern2, $CC_Options_wpadmin['bps_customcode_bpsqse_wpa'], $matches ) ) {			
			$p2 = array($pattern2);
			$r2 = array("RewriteCond %{THE_REQUEST} (\?|\*|%2a)+(%20+|\\\\\s+|%20+\\\\\s+|\\\\\s+%20+|\\\\\s+%20+\\\\\s+)(http|https)(:/|/) [NC,OR]");
		} else {
			$p2 = array();
			$r2 = array();
		}

		if ( preg_match( $pattern3, $CC_Options_wpadmin['bps_customcode_bpsqse_wpa'], $matches ) ) {			
			$p3 = array($pattern3);
			$r3 = array("RewriteCond %{QUERY_STRING} [a-zA-Z0-9_]=(http|https):// [NC,OR]");
		} else {
			$p3 = array();
			$r3 = array();
		}

		if ( preg_match( $pattern4, $CC_Options_wpadmin['bps_customcode_bpsqse_wpa'], $matches ) ) {			
			$p4 = array($pattern4);
			$r4 = array("RewriteCond %{QUERY_STRING} ^(.*)cPath=(http|https)://(.*)$ [NC,OR]");
		} else {
			$p4 = array();
			$r4 = array();
		}

		if ( preg_match( $pattern5, $CC_Options_wpadmin['bps_customcode_bpsqse_wpa'], $matches ) ) {			
			$p5 = array($pattern5);
			$r5 = array("RewriteCond %{QUERY_STRING} (http|https)\: [NC,OR]");
		} else {
			$p5 = array();
			$r5 = array();
		}

		$pattern_array = array_merge($p2, $p3, $p4, $p5);
		$replace_array = array_merge($r2, $r3, $r4, $r5);
		$bps_customcode_bpsqse_wpa_replace = preg_replace($pattern_array, $replace_array, $CC_Options_wpadmin['bps_customcode_bpsqse_wpa']);
	
	} else {
		$bps_customcode_bpsqse_wpa_replace = $CC_Options_wpadmin['bps_customcode_bpsqse_wpa'];
	}

	$wpadmin_CC_Options = array(
	'bps_customcode_deny_files_wpa' => $CC_Options_wpadmin['bps_customcode_deny_files_wpa'], 
	'bps_customcode_one_wpa' 		=> $CC_Options_wpadmin['bps_customcode_one_wpa'], 
	'bps_customcode_two_wpa' 		=> $CC_Options_wpadmin['bps_customcode_two_wpa'], 
	'bps_customcode_bpsqse_wpa' 	=> $bps_customcode_bpsqse_wpa_replace 
	);
			
	foreach( $wpadmin_CC_Options as $key => $value ) {
		update_option('bulletproof_security_options_customcode_WPA', $wpadmin_CC_Options);
	}
}

// Copies the new version of BPS Pro MU Tools must-use plugin to the /mu-plugins/ folder on BPS upgrade
function bpsPro_mu_tools_plugin_copy() {
	
	$BPS_MU_tools = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/bps-pro-mu-tools.php';
	$BPS_MU_tools_copy = WP_CONTENT_DIR . '/mu-plugins/bps-pro-mu-tools.php';
	$BPS_MU_tools_ARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/mu-plugins/bps-pro-mu-tools.php';

	if ( file_exists($BPS_MU_tools_copy) ) {
		
		// last version, not the current version
		$check_string = @file_get_contents($BPS_MU_tools_copy);
		$pos1 = strpos( $check_string, 'BPS Pro MU Tools Version: 1.0' );
		$pos2 = strpos( $check_string, 'Version: 2.0' );
		$pos3 = strpos( $check_string, 'Version: 3.0' );
		$pos4 = strpos( $check_string, 'Version: 4.0' );		
		$pos5 = strpos( $check_string, 'Version: 5.0' );
		$pos6 = strpos( $check_string, 'Version: 6.0' );
		$pos7 = strpos( $check_string, 'Version: 7.0' );
		$pos8 = strpos( $check_string, 'Version: 8.0' );
		$pos9 = strpos( $check_string, 'Version: 9.0' );
		$pos10 = strpos( $check_string, 'Version: 10.0' );
		$pos11 = strpos( $check_string, 'Version: 11.0' );
		$pos12 = strpos( $check_string, 'Version: 12.0' );
								
		if ( $pos1 !== false || $pos2 !== false || $pos3 !== false || $pos4 !== false || $pos5 !== false || $pos6 !== false || $pos7 !== false || $pos8 !== false || $pos9 !== false || $pos10 !== false || $pos11 !== false || $pos12 !== false ) {
			@copy($BPS_MU_tools, $BPS_MU_tools_ARQ);
			@copy($BPS_MU_tools, $BPS_MU_tools_copy);			
		}
	}
}

// Get any new dirs that have been created and remove any old dirs from the bps_mscan_dirs db option.
// Also used in Setup Wizard: need to add setup wizard condition to display saved or updated db options etc.
// Note: MScan Status db options do not need to be pre-saved. 
// 13.3.2: open_basedir "fix" added
// 13.4.1: mscan delete /tmp files default setting changed to Off
// This function is run in the BPS upgrade function and in the Setup Wizard ONLY.
// 15.4: Change the default max file size limit to: 1000KB if the max file size is less than 1000KB.
// 15.4: MScan now does 2 dir iterations: ABSPATH and Home directory and merges the results.
function bpsPro_presave_mscan_options() {
	
	$MScan_options = get_option('bulletproof_security_options_MScan'); 
	$wp_abspath_forward_slashes = str_replace( '\\', '/', ABSPATH );
	$wp_install_folder = str_replace( array( get_home_path(), '/', ), "", $wp_abspath_forward_slashes );
	$wp_includes_forward_slashes = $wp_abspath_forward_slashes . WPINC;
	$wp_includes_folder = str_replace( $wp_abspath_forward_slashes, "", $wp_includes_forward_slashes );
	
	$source = $wp_abspath_forward_slashes;
	$dir_array = array();
	
	if ( is_dir($source) ) {
		
		$iterator = new DirectoryIterator($source);	
		
		foreach ( $iterator as $files ) {
			try {			
				if ( $files->isDir() && ! $files->isDot() ) {
	
					if ( ! empty( $files ) ) {
						$dir_array[] = $files->getFilename();
					}
				}
			} catch (RuntimeException $e) {   
				
			}
		}
	}

	$get_home_path = get_home_path();
	$home_dir_array = array();
	
	if ( $wp_abspath_forward_slashes != $get_home_path ) {

		if ( is_dir($get_home_path) ) {
			
			$iterator = new DirectoryIterator($get_home_path);	
			
			foreach ( $iterator as $files ) {
				try {			
					if ( $files->isDir() && ! $files->isDot() ) {
						
						if ( $wp_install_folder != $files->getFilename() && $bps_wpcontent_dir != $files->getFilename() && $wp_includes_folder != $files->getFilename() && 'wp-admin' != $files->getFilename()) {
		
							if ( ! empty( $files ) ) {
								$home_dir_array[] = $files->getFilename();
							}
						}
					}
				} catch (RuntimeException $e) {   
					
				}
			}
		}
	}
	
	$dir_array_merge = array_merge($dir_array, $home_dir_array);
	$dir_flip = array_flip($dir_array_merge);
		
	// replace values in all dirs found except for other WP site folders.
	$mscan_actual_dirs = array();
	$pattern = '/define\((\s|)\'WP_USE_THEMES/';
	
	foreach ( $dir_flip as $key => $value ) {
			
		$wp_index_file = $source . $key . '/index.php';
		$wp_blog_header_file = $source . $key . '/wp-blog-header.php';
		$wp_cron_file = $source . $key . '/wp-cron.php';
		$wp_load_file = $source . $key . '/wp-load.php';
		$wp_login_file = $source . $key . '/wp-login.php';
		$wp_settings_file = $source . $key . '/wp-settings.php';
		
		$home_wp_index_file = $get_home_path . $key . '/index.php';
		$home_wp_blog_header_file = $get_home_path . $key . '/wp-blog-header.php';
		$home_wp_cron_file = $get_home_path . $key . '/wp-cron.php';
		$home_wp_load_file = $get_home_path . $key . '/wp-load.php';
		$home_wp_login_file = $get_home_path . $key . '/wp-login.php';
		$home_wp_settings_file = $get_home_path . $key . '/wp-settings.php';

		if ( file_exists($wp_index_file) ) {
			$check_string = file_get_contents($wp_index_file);
		}
				
		if ( file_exists($home_wp_index_file) ) {
			$home_check_string = file_get_contents($home_wp_index_file);
		}

		if ( file_exists($wp_index_file) && preg_match( $pattern, $check_string ) && file_exists($wp_blog_header_file) && file_exists($wp_cron_file) && file_exists($wp_load_file) && file_exists($wp_login_file) && file_exists($wp_settings_file) || file_exists($home_wp_index_file) && preg_match( $pattern, $home_check_string ) && file_exists($home_wp_blog_header_file) && file_exists($home_wp_cron_file) && file_exists($home_wp_load_file) && file_exists($home_wp_login_file) && file_exists($home_wp_settings_file) ) {
			$mscan_actual_dirs[$key] = preg_replace( '/\d+/', "", $value );
		} else {
			$mscan_actual_dirs[$key] = preg_replace( '/\d+/', "1", $value );
		}
	}
				
	// This is not a mistake/redundant. See the else condition.
	if ( ! empty($MScan_options['bps_mscan_dirs']) ) {
	
		$mscan_dirs_options_inner_array = array();
			
		foreach ( $MScan_options['bps_mscan_dirs'] as $key => $value ) {			
			
			$wp_index_file = $source . $key . '/index.php';
			$home_wp_index_file = $get_home_path . $key . '/index.php';
			
			if ( file_exists($wp_index_file) ) {
				$check_string = file_get_contents($wp_index_file);
			}
					
			if ( file_exists($home_wp_index_file) ) {
				$home_check_string = file_get_contents($home_wp_index_file);
			}

			if ( file_exists($wp_index_file) && preg_match( $pattern, $check_string ) || file_exists($home_wp_index_file) && preg_match( $pattern, $home_check_string ) ) {
				$mscan_dirs_options_inner_array[$key] = '';
			} else {
				$mscan_dirs_options_inner_array[$key] = $value;
			}
		}

		// get new dirs found that do not exist in the bps_mscan_dirs db option. ie a new dir has been created.
		$mscan_diff_key_dir = array_diff_key($mscan_actual_dirs, $mscan_dirs_options_inner_array);

		// get old dirs that still exist in the bps_mscan_dirs db option. ie a dir has been deleted.
		$mscan_diff_key_options = array_diff_key($mscan_dirs_options_inner_array, $dir_flip);

		if ( ! empty($mscan_diff_key_options) ) {
	
			foreach ( $mscan_diff_key_options as $key => $value ) {
				unset($mscan_dirs_options_inner_array[$key]);
			}

			// merge any new dirs found
			$mscan_array_merge = array_merge( $mscan_diff_key_dir, $mscan_dirs_options_inner_array );
			ksort($mscan_array_merge);

		} else {
	
			// merge any new dirs found
			$mscan_array_merge = array_merge( $mscan_diff_key_dir, $mscan_dirs_options_inner_array );
			ksort($mscan_array_merge);		
		}

	} else {
		$mscan_array_merge = $mscan_actual_dirs;
		ksort($mscan_array_merge);
	}

	if ( ! isset($MScan_options['mscan_file_size_limit_hidden']) ) {
		$mscan_max_file_size = '1000';
		$mscan_file_size_limit_hidden = '14';
	} else {
		$mscan_max_file_size = $MScan_options['mscan_max_file_size'];
		$mscan_file_size_limit_hidden = '14';
	}
	
	$mscan_max_time_limit = ! isset($MScan_options['mscan_max_time_limit']) ? '300' : $MScan_options['mscan_max_time_limit'];
	$mscan_scan_database = ! isset($MScan_options['mscan_scan_database']) ? 'On' : $MScan_options['mscan_scan_database'];
	$mscan_scan_skipped_files = ! isset($MScan_options['mscan_scan_skipped_files']) ? 'Off' : $MScan_options['mscan_scan_skipped_files'];
	$mscan_scan_delete_tmp_files = ! isset($MScan_options['mscan_scan_delete_tmp_files']) ? 'Off' : $MScan_options['mscan_scan_delete_tmp_files'];
	$mscan_scan_frequency = ! isset($MScan_options['mscan_scan_frequency']) ? 'Off' : $MScan_options['mscan_scan_frequency'];
	$mscan_exclude_dirs = ! isset($MScan_options['mscan_exclude_dirs']) ? '' : $MScan_options['mscan_exclude_dirs'];
	$mscan_exclude_tmp_files = ! isset($MScan_options['mscan_exclude_tmp_files']) ? '' : $MScan_options['mscan_exclude_tmp_files'];
	
	$MS_Options = array(
	'bps_mscan_dirs' 				=> $mscan_array_merge, 
	'mscan_max_file_size' 			=> $mscan_max_file_size, 
	'mscan_max_time_limit' 			=> $mscan_max_time_limit, 
	'mscan_scan_database' 			=> $mscan_scan_database, 
	'mscan_scan_images' 			=> 'Off', 
	'mscan_scan_skipped_files' 		=> $mscan_scan_skipped_files, 
	'mscan_scan_delete_tmp_files' 	=> $mscan_scan_delete_tmp_files, 
	'mscan_scan_frequency' 			=> $mscan_scan_frequency, 
	'mscan_exclude_dirs' 			=> $mscan_exclude_dirs, 
	'mscan_exclude_tmp_files' 		=> $mscan_exclude_tmp_files, 
	'mscan_file_size_limit_hidden' 	=> $mscan_file_size_limit_hidden 
	);	

	$mscan_successMessage = __(' DB Option created or updated Successfully!', 'bulletproof-security');
	$mscan_dir_successMessage = __(' Hosting Account Root Folder Option setup or updated Successfully!', 'bulletproof-security');
	$successTextBegin = '<font color="green"><strong>';
	$successTextEnd = '</strong></font><br>';

	foreach( $MS_Options as $key => $value ) {
		update_option('bulletproof_security_options_MScan', $MS_Options);
		
		if ( esc_html($_SERVER['QUERY_STRING']) == 'page=bulletproof-security/admin/wizard/wizard.php' ) {
			//echo $successTextBegin.$key.$mscan_successMessage.$successTextEnd;
		}
	}

	if ( esc_html($_SERVER['QUERY_STRING']) == 'page=bulletproof-security/admin/wizard/wizard.php' ) {
		$MScan_options = get_option('bulletproof_security_options_MScan');
		
		if ( $MScan_options['bps_mscan_dirs'] != '' ) {
			
			foreach ( $MScan_options['bps_mscan_dirs'] as $key => $value ) {			
				//echo $successTextBegin.$key.$mscan_dir_successMessage.$successTextEnd;
			}
		}
	}
}

// 14.2: Add new ico file extension to the PFW htaccess file.
function bpsPro_PFW_new_file_extension() {

	$pfw_pattern = '/\|htx\|idc\|ini\|ins\|isp\|jar\|jav\|java\|/';
	$PluginsHtaccess = WP_PLUGIN_DIR . '/.htaccess';
	$PluginsHtaccessMaster = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/plugins.htaccess';
	$PluginsHtaccessARQ = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/bulletproof-security/admin/htaccess/plugins.htaccess';
	$PluginsHtaccessARQplugins = WP_CONTENT_DIR . '/bps-backup/autorestore/wp-content/plugins/.htaccess';
	
	// 14.2: Add new ico file extension to the PFW htaccess file.
	if ( file_exists($PluginsHtaccess) ) {
		
		$master_check_string = file_get_contents($PluginsHtaccessMaster);
			
		if ( preg_match( $pfw_pattern, $master_check_string, $matches ) ) {		
			
			$stringReplaceMaster = preg_replace( $pfw_pattern, "|htx|ico|idc|ini|ins|isp|jar|jav|java|", $master_check_string );
			
			if ( file_put_contents($PluginsHtaccessMaster, $stringReplaceMaster) ) {
				@copy($PluginsHtaccessMaster, $PluginsHtaccessARQ);
			}
		}			

		$live_check_string = file_get_contents($PluginsHtaccess);
			
		if ( preg_match( $pfw_pattern, $live_check_string, $matches ) ) {		
			
			$stringReplaceLive = preg_replace( $pfw_pattern, "|htx|ico|idc|ini|ins|isp|jar|jav|java|", $live_check_string );
			
			if ( file_put_contents($PluginsHtaccess, $stringReplaceLive) ) {
				@copy($PluginsHtaccess, $PluginsHtaccessARQplugins);
			}
		}			
	}
}

// 14.9: Remove |js file type from the UAEG htaccess file and UAEG Custom Code.
// Note: If someone still wants to block js files they can add |js at the end of the file type condition in UAEG Custom Code.
function bpsPro_UAEG_js_fix() {
	
	$bps_Uploads_Dir = wp_upload_dir();
	$UploadsHtaccess = $bps_Uploads_Dir['basedir'] . '/.htaccess';
	$pattern_uaeg = '/\|js\|jse\|jsfl\|json\|/';
	
	if ( file_exists($UploadsHtaccess) ) {
		$stringReplace = @file_get_contents($UploadsHtaccess);
		
		if ( preg_match( $pattern_uaeg, $stringReplace, $matches ) ) {
		
			$stringReplace = preg_replace( $pattern_uaeg, "|jse|jsfl|json|", $stringReplace);
			file_put_contents($UploadsHtaccess, $stringReplace );
		}
	}
	
	$UAEG_CC_options = get_option('bulletproof_security_options_customcode_UAEG');
	
	if ( ! empty( $UAEG_CC_options['bps_customcode_uaeg'] ) ) {
		
		$UAEG_CC_options_DB = htmlspecialchars_decode( $UAEG_CC_options['bps_customcode_uaeg'], ENT_QUOTES );
		
		if ( preg_match( $pattern_uaeg, $UAEG_CC_options_DB, $matches ) ) {
			
			$UAEG_CC_options_DB = preg_replace( $pattern_uaeg, "|jse|jsfl|json|", $UAEG_CC_options_DB);
			
			$UAEG_CC_array = array( 'bps_customcode_uaeg' => $UAEG_CC_options_DB );
	
			foreach( $UAEG_CC_array as $key => $value ) {
				update_option('bulletproof_security_options_customcode_UAEG', $UAEG_CC_array);
			}
		}
	}
}

// 15: BugFix: Remove the whitespace between WP and Rocket skip/bypass rule if it exists so that the HUD AutoFix function does not detect it.
// Root htaccess file and Custom Code.
// Note: This BPS upgrade function fires right before the root htaccess file is unlocked in the root htaccess file upgrade function.
function bpsPro_wp_rocket_marker_fix() {
	
	$rootHtaccess = ABSPATH . '.htaccess';			
		
	if ( file_exists($rootHtaccess) ) {
		
		$sapi_type = php_sapi_name();
		$lock = '';
		$permsRootHtaccess = @substr(sprintf('%o', fileperms($rootHtaccess)), -4);
		
		if 	( @$permsRootHtaccess == '0404') {
			$lock = '0404';			
		}
		
		if ( @substr($sapi_type, 0, 6) != 'apache' || @$permsRootHtaccess != '0666' || @$permsRootHtaccess != '0777' ) {
			chmod( $rootHtaccess, 0644 );
		}
		
		$root_htaccess_file_contents = @file_get_contents($rootHtaccess);	
	
		if ( preg_match( '/#\sWP\sRocket\splugin\sskip\/bypass\srule(\s*){1}RewriteCond(.*)wp-rocket\/\s\[NC\](\s*){1}RewriteRule\s\.\s\-\s\[S=\d{1,2}\]/s', $root_htaccess_file_contents, $matches ) ) {
			
			$root_htaccess_file_contents = preg_replace( '/#\sWP\sRocket\splugin\sskip\/bypass\srule/s', "# WPRocket plugin skip/bypass rule", $root_htaccess_file_contents);
		}				
		
		file_put_contents($rootHtaccess, $root_htaccess_file_contents);			
	
		$Root_Autolock = get_option('bulletproof_security_options_autolock');
		
		if ( isset($Root_Autolock['bps_root_htaccess_autolock']) && $Root_Autolock['bps_root_htaccess_autolock'] == 'On' || @$lock == '0404' ) {
			@chmod($rootHtaccess, 0404);
		}		
	}

	$CC_Options_root = get_option('bulletproof_security_options_customcode');
	$bps_customcode_two = htmlspecialchars_decode( $CC_Options_root['bps_customcode_two'], ENT_QUOTES );
	$pattern = '/WP\sRocket/';
	
	if ( preg_match( $pattern, $bps_customcode_two ) ) {
		
		$bps_customcode_two_preg_replace = preg_replace('/#\sWP\sRocket\splugin\sskip\/bypass\srule/', "# WPRocket plugin skip/bypass rule", $bps_customcode_two);
	
		if ( ! is_multisite() ) {

			$Root_CC_Options = array(
			'bps_customcode_one' 				=> $CC_Options_root['bps_customcode_one'], 
			'bps_customcode_server_signature' 	=> $CC_Options_root['bps_customcode_server_signature'], 
			'bps_customcode_directory_index' 	=> $CC_Options_root['bps_customcode_directory_index'], 
			'bps_customcode_server_protocol' 	=> $CC_Options_root['bps_customcode_server_protocol'], 
			'bps_customcode_error_logging' 		=> $CC_Options_root['bps_customcode_error_logging'], 
			'bps_customcode_deny_dot_folders' 	=> $CC_Options_root['bps_customcode_deny_dot_folders'], 
			'bps_customcode_admin_includes' 	=> $CC_Options_root['bps_customcode_admin_includes'], 
			'bps_customcode_wp_rewrite_start' 	=> $CC_Options_root['bps_customcode_wp_rewrite_start'], 
			'bps_customcode_request_methods' 	=> $CC_Options_root['bps_customcode_request_methods'], 
			'bps_customcode_two' 				=> $bps_customcode_two_preg_replace, 
			'bps_customcode_timthumb_misc' 		=> $CC_Options_root['bps_customcode_timthumb_misc'], // not sure if i should attempt this one or not
			'bps_customcode_bpsqse' 			=> $CC_Options_root['bps_customcode_bpsqse'], 
			'bps_customcode_deny_files' 		=> $CC_Options_root['bps_customcode_deny_files'], 
			'bps_customcode_three' 				=> $CC_Options_root['bps_customcode_three'] 
			);
					
		} else {
						
			$Root_CC_Options = array(
			'bps_customcode_one' 				=> $CC_Options_root['bps_customcode_one'], 
			'bps_customcode_server_signature' 	=> $CC_Options_root['bps_customcode_server_signature'], 
			'bps_customcode_directory_index' 	=> $CC_Options_root['bps_customcode_directory_index'], 
			'bps_customcode_server_protocol' 	=> $CC_Options_root['bps_customcode_server_protocol'], 
			'bps_customcode_error_logging' 		=> $CC_Options_root['bps_customcode_error_logging'], 
			'bps_customcode_deny_dot_folders' 	=> $CC_Options_root['bps_customcode_deny_dot_folders'], 
			'bps_customcode_admin_includes' 	=> $CC_Options_root['bps_customcode_admin_includes'], 
			'bps_customcode_wp_rewrite_start' 	=> $CC_Options_root['bps_customcode_wp_rewrite_start'], 
			'bps_customcode_request_methods' 	=> $CC_Options_root['bps_customcode_request_methods'], 
			'bps_customcode_two' 				=> $bps_customcode_two_preg_replace, 
			'bps_customcode_timthumb_misc' 		=> $CC_Options_root['bps_customcode_timthumb_misc'], 
			'bps_customcode_bpsqse' 			=> $CC_Options_root['bps_customcode_bpsqse'], 
			'bps_customcode_wp_rewrite_end' 	=> $CC_Options_root['bps_customcode_wp_rewrite_end'], 
			'bps_customcode_deny_files' 		=> $CC_Options_root['bps_customcode_deny_files'], 
			'bps_customcode_three' 				=> $CC_Options_root['bps_customcode_three'] 
			);
		}
	
		foreach( $Root_CC_Options as $key => $value ) {
			update_option('bulletproof_security_options_customcode', $Root_CC_Options);
		}
	}
}

// BPS Pro upgrade: adds/updates/saves any new S-Monitor options, log options, other new db options, does cleanup & does everything else.
// This function is executed in this function: bpsPro_new_feature_autoupdate() which is executed ONLY during BPS upgrades in functions.php and inpage-functions.php.
// 11.5: This function has been completely changed: literally checks if a DB option exists and has a value using ternary operations.
// if a DB option does not exist then update it with a default value else resave existing DB option values.
// NOTE: All DB options will not be added here. Only critical new DB options. For every other situation an uninstall/reinstall & Setup Wizard rerun is required.
function bpsPro_new_version_db_options_files_autoupdate() {
	
	if ( current_user_can('manage_options') ) {
		global $bpspro_version, $bpspro_last_version, $wp_version, $wpdb, $aitpro_bullet, $pagenow, $current_user;
		
		$user_id = $current_user->ID;
		
		// 15.8: Delete the DB Backup Log file if it contains: Zip Backup File Name
		// Note: A new blank DB Backup Log file is automatically created on page load.
		$bpsProDBBLogARQ = WP_CONTENT_DIR . '/bps-backup/logs/db_backup_log.txt';
	
		if ( file_exists($bpsProDBBLogARQ) ) {
			
			$check_string = @file_get_contents($bpsProDBBLogARQ);
			$pos = strpos( $check_string, 'Zip Backup File Name' );
					
			if ( $pos !== false ) {
				@unlink($bpsProDBBLogARQ);			
			}
		}

		// 15.6: Pre-Save the AutoRestore > Add Files > Root hosting account folder text box option w/blank value.
		if ( ! get_option('bulletproof_security_options_arq_host_root') ) {
			
			$bps_arq_host_root_folder = array( 'bps_arq_host_root_folder' => '' );
			
			foreach( $bps_arq_host_root_folder as $key => $value ) {
				update_option('bulletproof_security_options_arq_host_root', $bps_arq_host_root_folder);
			}
		}		
		
		// 15.4: MScan new feature Dismiss Notice - only displayed to people who have upgraded BPS. Not new installations of BPS.
		if ( ! get_option('bulletproof_security_options_new_feature') ) {
			
			$bps_mscan_rebuild = array( 'bps_mscan_rebuild' => 'upgrade' );
			
			foreach( $bps_mscan_rebuild as $key => $value ) {
				update_option('bulletproof_security_options_new_feature', $bps_mscan_rebuild);
			}
		}
		
		// 15.2: New Feature: Force Strong Passwords: Pre-save option settings
		if ( ! get_option('bulletproof_security_options_fsp') ) {

			$FSP_Message = 'Password must contain 1 lowercase letter, 1 uppercase letter, 1 number, 1 special character and be a minimum of 12 characters long.';
		
			$BPS_FSP_Options = array(
			'bps_fsp_on_off' 		=> 'Off', 
			'bps_fsp_char_length' 	=> '12', 
			'bps_fsp_lower_case' 	=> '1', 
			'bps_fsp_upper_case' 	=> '1', 
			'bps_fsp_number' 		=> '1', 
			'bps_fsp_special_char' 	=> '1', 
			'bps_fsp_message' 		=> $FSP_Message  
			);
			
			foreach( $BPS_FSP_Options as $key => $value ) {
				update_option('bulletproof_security_options_fsp', $BPS_FSP_Options);
			}
		}		

		/* Pre-saving db options for MU subsites does not work - look at this later
		if ( is_multisite() ) {
			require_once ( WP_PLUGIN_DIR . '/bulletproof-security/admin/wizard/wizard.php' );
			echo '<div style="display:none;">';
			bpsPro_network_subsites_fsp_settings();
			echo '</div>';
		}
		*/

		// 15.1: Removed the PFW Roles Network|Multisite Dismiss Notice
		delete_user_meta($user_id, 'bps_ignore_PFW_roles_notice');
		
		// 15.1: Pre-save the PFW Roles for Administrator, Editor, Author and Contributor only if the new hidden form input value does not = 14.
		$PFW_Roles_Options = get_option('bulletproof_security_options_pfirewall_roles');
		
		if ( $PFW_Roles_Options['bps_pfw_roles_hidden'] != '14' ) {

			$pfw_roles1 = ! isset($PFW_Roles_Options['bps_pfw_administrator']) ? '1' : $PFW_Roles_Options['bps_pfw_administrator'];
			$pfw_roles2 = ! isset($PFW_Roles_Options['bps_pfw_editor']) ? '1' : $PFW_Roles_Options['bps_pfw_editor'];
			$pfw_roles3 = ! isset($PFW_Roles_Options['bps_pfw_author']) ? '1' : $PFW_Roles_Options['bps_pfw_author'];
			$pfw_roles4 = ! isset($PFW_Roles_Options['bps_pfw_contributor']) ? '1' : $PFW_Roles_Options['bps_pfw_contributor'];
			$pfw_roles5 = ! isset($PFW_Roles_Options['bps_pfw_roles_hidden']) ? '14' : $PFW_Roles_Options['bps_pfw_roles_hidden'];	
			$pfw_roles6 = ! isset($PFW_Roles_Options['bps_pfw_custom_roles']) ? array( 'bps', '' ) : $PFW_Roles_Options['bps_pfw_custom_roles'];
	
			$PFW_Roles = array( 
			'bps_pfw_administrator' => $pfw_roles1, 
			'bps_pfw_editor' 		=> $pfw_roles2, 	
			'bps_pfw_author' 		=> $pfw_roles3, 	
			'bps_pfw_contributor' 	=> $pfw_roles4, 
			'bps_pfw_roles_hidden' 	=> $pfw_roles5, 
			'bps_pfw_custom_roles' 	=> $pfw_roles6  
			);
			
			foreach( $PFW_Roles as $key => $value ) {
				update_option('bulletproof_security_options_pfirewall_roles', $PFW_Roles);
			}
		}
		
		// 15: Parse phpinfo() and save the PHP memory_limit Local Value to new DB option: bps_php_memory_limit
		bpsPro_phpinfo_memory_limit_array();		
		
		// 15: Update the bps_iniSet_MemoryLimit DB option with the PHP memory_limit Local Value
		$bps_php_memory_limit = get_option('bulletproof_security_options_php_memory_limit');
		$memoryLimit = $bps_php_memory_limit['bps_php_memory_limit'];
		$pos_memory_limit = strpos( $memoryLimit, 'Unable to get the PHP memory_limit value from the server' );
		
		if ( $pos_memory_limit !== false ) {
			$memory_limit_value = '256M';
		} else {
			$memory_limit_value = $bps_php_memory_limit['bps_php_memory_limit'];
		}
		
		// Note: This DB option is used in older code farther down this function.
		$ini_set_options = get_option('bulletproof_security_options_iniSet');  
	
		$BPS_Options_iniset = array(
		'bps_iniSet_ErrorReporting' 			=> $ini_set_options['bps_iniSet_ErrorReporting'], 
		'bps_iniSet_LogErrors' 					=> $ini_set_options['bps_iniSet_LogErrors'], 
		'bps_iniSet_ErrorLog' 					=> $ini_set_options['bps_iniSet_ErrorLog'], 
		'bps_iniSet_LogErrorsMaxLen' 			=> $ini_set_options['bps_iniSet_LogErrorsMaxLen'], 
		'bps_iniSet_MemoryLimit' 				=> $memory_limit_value, 
		'bps_iniSet_session_cookie_httponly' 	=> $ini_set_options['bps_iniSet_session_cookie_httponly'], 
		'bps_iniSet_session_use_only_cookies' 	=> $ini_set_options['bps_iniSet_session_use_only_cookies'], 
		'bps_iniSet_session_cookie_secure' 		=> $ini_set_options['bps_iniSet_session_cookie_secure'], 
		'bps_iniSet_IgnoreRepeatedErrors' 		=> $ini_set_options['bps_iniSet_IgnoreRepeatedErrors'], 
		'bps_iniSet_IgnoreRepeatedSource' 		=> $ini_set_options['bps_iniSet_IgnoreRepeatedSource'], 
		'bps_iniSet_AllowUrlInclude' 			=> $ini_set_options['bps_iniSet_AllowUrlInclude'], 
		'bps_iniSet_DefineSyslogVar' 			=> $ini_set_options['bps_iniSet_ErrorReporting'], 
		'bps_iniSet_DisplayErrors' 				=> $ini_set_options['bps_iniSet_DefineSyslogVar'], 
		'bps_iniSet_DisplayStartupErrors' 		=> $ini_set_options['bps_iniSet_DisplayStartupErrors'], 
		'bps_iniSet_ImplicitFlush' 				=> $ini_set_options['bps_iniSet_ImplicitFlush'], 
		'bps_iniSet_MagicQuotesRuntime' 		=> $ini_set_options['bps_iniSet_MagicQuotesRuntime'], 
		'bps_iniSet_MaxExecutionTime' 			=> $ini_set_options['bps_iniSet_MaxExecutionTime'], 
		'bps_iniSet_MysqlConnectTimeout' 		=> $ini_set_options['bps_iniSet_MysqlConnectTimeout'], 
		'bps_iniSet_MysqlTraceMode' 			=> $ini_set_options['bps_iniSet_MysqlTraceMode'], 
		'bps_iniSet_ReportMemleaks' 			=> $ini_set_options['bps_iniSet_ReportMemleaks'] 
		);

		foreach( $BPS_Options_iniset as $key => $value ) {
			update_option('bulletproof_security_options_iniSet', $BPS_Options_iniset);
		}
		
		// 15: BugFix: Remove the whitespace between WP and Rocket skip/bypass rule if it exists so that the HUD AutoFix function does not detect it.
		// Note: This BPS upgrade function fires right before the root htaccess file is unlocked in the root htaccess file upgrade function.
		bpsPro_wp_rocket_marker_fix();

		// 14.9: Pre-save the new File Lock Override option. The default setting is: Off. 
		// The hidden value is: 14. This is only used as a condition to update the options, unlock files and turn Off checking & alerts BPS Pro upgrade ONCE.
		// Unlock the wp-config.php, wp-blog-header.php and index.php files if they are locked with 400 permissions.
		// Set the File Lock Checking & Alerts option settings to: Off
		$fl_override_options = get_option('bulletproof_security_options_flock_eol');
		
		if ( ! isset($fl_override_options['bps_file_lock_override_hidden']) || isset($fl_override_options['bps_file_lock_override_hidden']) && $fl_override_options['bps_file_lock_override_hidden'] != '14' ) {
		
			$bpsWpConfig = ABSPATH . 'wp-config.php';
			$bpsIndexPhp = ABSPATH . 'index.php';
			$bpsWpBlogHeader = ABSPATH . 'wp-blog-header.php';
			$bpsIndexPhpDR = $_SERVER['DOCUMENT_ROOT'] . '/index.php';
			$bpsIndexPhpGWIOD = dirname(ABSPATH) . '/index.php';

			$perms_wpconfig = @substr(sprintf('%o', fileperms($bpsWpConfig)), -4);
			$perms_index = @substr(sprintf('%o', fileperms($bpsIndexPhp)), -4);
			$perms_wpblogheader = @substr(sprintf('%o', fileperms($bpsWpBlogHeader)), -4);			
			$perms_index_dr = @substr(sprintf('%o', fileperms($bpsIndexPhpDR)), -4);
			if ( file_exists($bpsIndexPhpGWIOD) ) {
			$perms_index_gwiod = @substr(sprintf('%o', fileperms($bpsIndexPhpGWIOD)), -4);
			}
			if ( file_exists($bpsWpConfig) && $perms_wpconfig == '0400' ) {
				@chmod($bpsWpConfig, 0644);
			}
			if ( file_exists($bpsIndexPhp) && $perms_index == '0400' ) {
				@chmod($bpsIndexPhp, 0644);
			}
			if ( file_exists($bpsWpBlogHeader) && $perms_wpblogheader == '0400' ) {
				@chmod($bpsWpBlogHeader, 0644);
			}
			if ( file_exists($bpsIndexPhpDR) && $perms_index_dr == '0400' ) {
				@chmod($bpsIndexPhpDR, 0644);
			}
			if ( file_exists($bpsIndexPhpGWIOD ) && $perms_index_gwiod == '0400' ) {
				@chmod($bpsIndexPhpGWIOD, 0644);
			}
		
			$BPS_FL_Options = array( 
			'bps_lock_root_htaccess' 		=> 'off', 
			'bps_lock_wpconfig' 			=> 'off', 
			'bps_lock_index_php' 			=> 'off', 
			'bps_lock_wpblog_header' 		=> 'off', 
			'bps_lock_root_htaccess_dr' 	=> 'off', 
			'bps_lock_index_php_dr' 		=> 'off', 
			'bps_lock_root_htaccess_gwiod' 	=> 'off', 
			'bps_lock_index_php_gwiod' 		=> 'off' 
			);	
	
			foreach( $BPS_FL_Options as $key => $value ) {
				update_option('bulletproof_security_options_flock', $BPS_FL_Options);
			}

			$BPS_FLO_Options = array( 
			'bps_file_lock_override' 			=> 'Off', 
			'bps_file_lock_override_hidden' 	=> '14' 
			);	
	
			foreach( $BPS_FLO_Options as $key => $value ) {
				update_option('bulletproof_security_options_flock_eol', $BPS_FLO_Options);
			}
		}

		//14.9: Pre-save the new PFW new installation DB options with "completed" value: Yes
		$bps_option_pfw_new_install = 'bulletproof_security_options_pfw_new_install';
		
		$BPS_pfw_new_install = array(
		'bps_pfw_new_install_start' 	=> time(), 
		'bps_pfw_new_install_end' 		=> time(), 
		'bps_pfw_new_install_completed' => 'Yes'
		);
	
			if ( ! get_option( $bps_option_pfw_new_install ) ) {	
			
				foreach( $BPS_pfw_new_install as $key => $value ) {
					update_option('bulletproof_security_options_pfw_new_install', $BPS_pfw_new_install);
				}
			}

		// 14.9: Remove |js file type from the UAEG htaccess file and UAEG Custom Code.
		bpsPro_UAEG_js_fix();
		
		// 14.9: Pre-save all UI|UX option settings except for SLF - already done further below. 
		// Note: Avoids having to do additional Form coding work for PHP 7.4.9 Notice errors.
		// Theme Skin
		$UITSoptions = get_option('bulletproof_security_options_theme_skin');
		$uits = ! isset($UITSoptions['bps_ui_theme_skin']) ? 'blue' : $UITSoptions['bps_ui_theme_skin'];
		$uits_options = array('bps_ui_theme_skin' => $uits);

		foreach( $uits_options as $key => $value ) {
			update_option('bulletproof_security_options_theme_skin', $uits_options);
		}

		// Processing Spinner
		$UISpinneroptions = get_option('bulletproof_security_options_spinner');
		$uips = ! isset($UISpinneroptions['bps_spinner']) ? 'On' : $UISpinneroptions['bps_spinner'];
		$uips_options = array('bps_spinner' => $uips);

		foreach( $uips_options as $key => $value ) {
			update_option('bulletproof_security_options_spinner', $uips_options);
		}

		// ScrollTop Animation
		$ScrollTopoptions = get_option('bulletproof_security_options_scrolltop');
		$uist = ! isset($ScrollTopoptions['bps_scrolltop']) ? 'On' : $ScrollTopoptions['bps_scrolltop'];
		$uist_options = array('bps_scrolltop' => $uist);

		foreach( $uist_options as $key => $value ) {
			update_option('bulletproof_security_options_scrolltop', $uist_options);
		}
		
		// WP Toolbar Functionality in BPS plugin pages		
		$UIWPToptions = get_option('bulletproof_security_options_wpt_nodes');
		$uiwpt = ! isset($UIWPToptions['bps_wpt_nodes']) ? 'allnodes' : $UIWPToptions['bps_wpt_nodes'];
		$uiwpt_options = array('bps_wpt_nodes' => $uiwpt);

		foreach( $uiwpt_options as $key => $value ) {
			update_option('bulletproof_security_options_wpt_nodes', $uiwpt_options);
		}		

		// BPS UI|UX|AutoFix Debug
		$UIDebug_options = get_option('bulletproof_security_options_debug');
		$uidb = ! isset($UIDebug_options['bps_debug']) ? 'Off' : $UIDebug_options['bps_debug'];
		$uidb_options = array('bps_debug' => $uidb);

		foreach( $uidb_options as $key => $value ) {
			update_option('bulletproof_security_options_debug', $uidb_options);
		}

		// 14.9: Pre-save all Setup Wizard Options DB option settings. 
		// Note: Avoids having to do additional Form coding work for PHP 7.4.9 Notice errors.
		// AutoFix
		$AutoFix_Options = get_option('bulletproof_security_options_wizard_autofix');
		$swoaf = ! isset($AutoFix_Options['bps_wizard_autofix']) ? 'On' : $AutoFix_Options['bps_wizard_autofix'];
		$SWOAF_options = array('bps_wizard_autofix' => $swoaf);

		foreach( $SWOAF_options as $key => $value ) {
			update_option('bulletproof_security_options_wizard_autofix', $SWOAF_options);
		}		
		
		// GDPR Compliance
		$GDPR_Options = get_option('bulletproof_security_options_gdpr');	
		$swgdpr = ! isset($GDPR_Options['bps_gdpr_on_off']) ? 'Off' : $GDPR_Options['bps_gdpr_on_off'];
		$SWGDPR_options = array('bps_gdpr_on_off' => $swgdpr);

		foreach( $SWGDPR_options as $key => $value ) {
			update_option('bulletproof_security_options_gdpr', $SWGDPR_options);
		}		
		
		// cURL Scan & DB Monitor
		$CURL_options = get_option('bulletproof_security_options_wizard_curl');
		$swcurl1 = ! isset($CURL_options['bps_wizard_curl_scan']) ? 'Off' : $CURL_options['bps_wizard_curl_scan'];
		$swcurl2 = ! isset($CURL_options['bps_wizard_dbm_settings']) ? 'On' : $CURL_options['bps_wizard_dbm_settings'];
		$SWCURL_options = array(
		'bps_wizard_curl_scan' 		=> $swcurl1, 
		'bps_wizard_dbm_settings' 	=> $swcurl2
		);

		foreach( $SWCURL_options as $key => $value ) {
			update_option('bulletproof_security_options_wizard_curl', $SWCURL_options);
		}		
		
		// GDMW 
		$GDMW_options = get_option('bulletproof_security_options_GDMW');
		$swgdmw = ! isset($GDMW_options['bps_gdmw_hosting']) ? 'no' : $GDMW_options['bps_gdmw_hosting'];
		$SWGDMW_options = array('bps_gdmw_hosting' => $swgdmw);

		foreach( $SWGDMW_options as $key => $value ) {
			update_option('bulletproof_security_options_GDMW', $SWGDMW_options);
		}		
		
		// Enable|Disable htaccess files
		$HFiles_options = get_option('bulletproof_security_options_htaccess_files');		
		$swhf = ! isset($HFiles_options['bps_htaccess_files']) ? 'enabled' : $HFiles_options['bps_htaccess_files'];
		$SWHF_options = array('bps_htaccess_files' => $swhf);

		foreach( $SWHF_options as $key => $value ) {
			update_option('bulletproof_security_options_htaccess_files', $SWHF_options);
		}		
					
		// Enable|Disable wp-admin BulletProof Mode
		$BPS_wpadmin_Options = get_option('bulletproof_security_options_htaccess_res');
		$swwhf = ! isset($BPS_wpadmin_Options['bps_wpadmin_restriction']) ? 'enabled' : $BPS_wpadmin_Options['bps_wpadmin_restriction'];
		$SWWHF_options = array('bps_wpadmin_restriction' => $swwhf);

		foreach( $SWWHF_options as $key => $value ) {
			update_option('bulletproof_security_options_htaccess_res', $SWWHF_options);
		}

		// Zip File Download Fix
		$Zip_download_Options = get_option('bulletproof_security_options_zip_fix');
		$swzd = ! isset($Zip_download_Options['bps_zip_download_fix']) ? 'Off' : $Zip_download_Options['bps_zip_download_fix'];
		$SWZD_options = array('bps_zip_download_fix' => $swzd);

		foreach( $SWZD_options as $key => $value ) {
			update_option('bulletproof_security_options_zip_fix', $SWZD_options);
		}		

		// Multisite Hide|Display System Info Page for Subsites
		$Mu_Sysinfo_page_options = get_option('bulletproof_security_options_mu_sysinfo');
		$swmus = ! isset($Mu_Sysinfo_page_options['bps_sysinfo_hide_display']) ? 'display' : $Mu_Sysinfo_page_options['bps_sysinfo_hide_display'];
		$SWMUS_options = array('bps_sysinfo_hide_display' => $swmus);

		foreach( $SWMUS_options as $key => $value ) {
			update_option('bulletproof_security_options_mu_sysinfo', $SWMUS_options);
		}		

		// 14.7: ini_set max execution value automatic update from 30 to 120.
		// Important: Only update the value to 120 if the value is 30.
		//$ini_set_options = get_option('bulletproof_security_options_iniSet');  // this DB option is used in another section higher up in this function.
	
		if ( $ini_set_options['bps_iniSet_MaxExecutionTime'] == '30' ) {
			
			$bps_iniSet_MaxExecutionTime = '120';
			
			$BPS_Options_iniset = array(
			'bps_iniSet_ErrorReporting' 			=> $ini_set_options['bps_iniSet_ErrorReporting'], 
			'bps_iniSet_LogErrors' 					=> $ini_set_options['bps_iniSet_LogErrors'], 
			'bps_iniSet_ErrorLog' 					=> $ini_set_options['bps_iniSet_ErrorLog'], 
			'bps_iniSet_LogErrorsMaxLen' 			=> $ini_set_options['bps_iniSet_LogErrorsMaxLen'], 
			'bps_iniSet_MemoryLimit' 				=> $ini_set_options['bps_iniSet_MemoryLimit'], 
			'bps_iniSet_session_cookie_httponly' 	=> $ini_set_options['bps_iniSet_session_cookie_httponly'], 
			'bps_iniSet_session_use_only_cookies' 	=> $ini_set_options['bps_iniSet_session_use_only_cookies'], 
			'bps_iniSet_session_cookie_secure' 		=> $ini_set_options['bps_iniSet_session_cookie_secure'], 
			'bps_iniSet_IgnoreRepeatedErrors' 		=> $ini_set_options['bps_iniSet_IgnoreRepeatedErrors'], 
			'bps_iniSet_IgnoreRepeatedSource' 		=> $ini_set_options['bps_iniSet_IgnoreRepeatedSource'], 
			'bps_iniSet_AllowUrlInclude' 			=> $ini_set_options['bps_iniSet_AllowUrlInclude'], 
			'bps_iniSet_DefineSyslogVar' 			=> $ini_set_options['bps_iniSet_ErrorReporting'], 
			'bps_iniSet_DisplayErrors' 				=> $ini_set_options['bps_iniSet_DefineSyslogVar'], 
			'bps_iniSet_DisplayStartupErrors' 		=> $ini_set_options['bps_iniSet_DisplayStartupErrors'], 
			'bps_iniSet_ImplicitFlush' 				=> $ini_set_options['bps_iniSet_ImplicitFlush'], 
			'bps_iniSet_MagicQuotesRuntime' 		=> $ini_set_options['bps_iniSet_MagicQuotesRuntime'], 
			'bps_iniSet_MaxExecutionTime' 			=> $bps_iniSet_MaxExecutionTime, 
			'bps_iniSet_MysqlConnectTimeout' 		=> $ini_set_options['bps_iniSet_MysqlConnectTimeout'], 
			'bps_iniSet_MysqlTraceMode' 			=> $ini_set_options['bps_iniSet_MysqlTraceMode'], 
			'bps_iniSet_ReportMemleaks' 			=> $ini_set_options['bps_iniSet_ReportMemleaks'] 
			);
	
			foreach( $BPS_Options_iniset as $key => $value ) {
				update_option('bulletproof_security_options_iniSet', $BPS_Options_iniset);
			}
		}
		
		// 14.2: Add new ico file extension to the PFW htaccess file.
		bpsPro_PFW_new_file_extension();
		
		// 14.1: BugFix for PFW On|Off check in Setup Wizard
		$PluginsHtaccess = WP_PLUGIN_DIR . '/.htaccess';
		
		if ( file_exists($PluginsHtaccess) ) {
			$bps_pfw_on_off = 'On';
		} else {
			$bps_pfw_on_off = 'Off';
		}

		$BPS_PFW_OnOff = array( 'bps_pfw_on_off' => $bps_pfw_on_off );		
			
		foreach( $BPS_PFW_OnOff as $key => $value ) {
			update_option('bulletproof_security_options_pfw', $BPS_PFW_OnOff);
		}		

		// 14: Pre-save the SLF option. The default is now set to On. New option added to use to check against for BPS upgrades: bps_slf_filter_new
		$bpsPro_SLF_options = get_option('bulletproof_security_options_SLF');
		
		if ( $bpsPro_SLF_options['bps_slf_filter_new'] != '14' ) {
		
			$BPS_SLF_Options = array( 
			'bps_slf_filter' 		=> 'On', 
			'bps_slf_filter_new' 	=> '14'
			);	
	
			foreach( $BPS_SLF_Options as $key => $value ) {
				update_option('bulletproof_security_options_SLF', $BPS_SLF_Options);
			}
		}
		
		// 13.5: VCheck - [defunct code deleted in 13.6]

		// 13.4.1: BPS Pro plugin 30 day review/rating request Dismiss Notice
		$bps_rate_options = 'bulletproof_security_options_rate_pro';
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;
		$bps_pro_rate_review = mktime(0, 0, 0, date("m")+1, date("d")+1, date("Y"));
	
		$BPS_Rate_Option = array( 'bps_pro_rate_review' => $bps_pro_rate_review + $gmt_offset );

		if ( ! get_option( $bps_rate_options ) ) {	
		
			foreach( $BPS_Rate_Option as $key => $value ) {
				update_option('bulletproof_security_options_rate_pro', $BPS_Rate_Option);
			}
		}

		// 13.3: moved this function into general-functions.php
		bpsPro_mu_tools_plugin_copy();
		// 13.3|15.4: Pre-save MScan Options
		bpsPro_presave_mscan_options();
		
		// 13: New SBC Dismiss Notice check created: checks for redundant Browser caching code & the BPS NOCHECK Marker in BPS Custom Code
		delete_user_meta($user_id, 'bpsPro_ignore_speed_boost_notice');
		// 13: New Endurance Page Cache Dismiss Notice check created: A dismiss notice will only be displayed if: EPC is enabled and Cache level is 1,2,3,4
		// 13.7: No longer offering Setup Wizard AutoFix for the EPC plugin.
		delete_user_meta($user_id, 'bpsPro_ignore_EPC_plugin_notice');
		// 13: Delete these old Dismiss Notices permanently that are no longer being used
		delete_user_meta($user_id, 'bps_ignore_BLC_notice');
		delete_user_meta($user_id, 'bps_ignore_jetpack_notice');
		delete_user_meta($user_id, 'bps_ignore_woocommerce_notice');

		// 13|13.2 BugFix: Changed the default option setting to: Do Not Log POST Request Body Data on new BPS installations & upgrades.
		// This will only update the db options 1 time if the bps_security_log_post_none DB option does not exist.
		// 11.2: Set Security Log Limit POST Request Body Data option to checked/limited by default
		if ( ! get_option('bulletproof_security_options_sec_log_post_limit') ) {

			$SecLog_post_limit_settings = array( 
			'bps_security_log_post_limit' 	=> '', 
			'bps_security_log_post_none' 	=> '1', 
			'bps_security_log_post_max' 	=> '' 
			);
			
			foreach( $SecLog_post_limit_settings as $key => $value ) {
				update_option('bulletproof_security_options_sec_log_post_limit', $SecLog_post_limit_settings);
			}
		}
		
		// 13|13.2: Revert: Remove R from the dumbed downed Request Methods Filtered 405 htaccess code in Root Custom Code.
		// Add additional https scheme conditions to 3 htaccess security rules and combine 2 rules into 1 rule in Root and wp-admin Custom Code.
		bpsPro_upgrade_CC_automatic_fix();
		
		// 13: Hopefully will prevent the MU Tools email alerts from being sent when BPS Pro is upgraded.
		// Note: May not work in this version of BPS Pro, but should work in the next version of BPS Pro.
		// BugFix: The enable|disable value was being saved as "N" on new BPS installations.
		$MUTools_Options = get_option('bulletproof_security_options_MU_tools');
		
		if ( $MUTools_Options['bps_mu_tools_enable_disable'] != 'enable' && $MUTools_Options['bps_mu_tools_enable_disable'] != 'disable' ) {
			
			$MUTools_Option_settings = array( 
			'bps_mu_tools_timestamp' 		=> time() + 300,
			'bps_mu_tools_enable_disable' 	=> 'enable' 
			);	

			foreach ( $MUTools_Option_settings as $key => $value ) {
				update_option('bulletproof_security_options_MU_tools', $MUTools_Option_settings);
			}		
		
		} else {
		
			$MUTools_Option_settings = array( 
			'bps_mu_tools_timestamp' 		=> time() + 300,
			'bps_mu_tools_enable_disable' 	=> $MUTools_Options['bps_mu_tools_enable_disable'] 
			);	

			foreach ( $MUTools_Option_settings as $key => $value ) {
				update_option('bulletproof_security_options_MU_tools', $MUTools_Option_settings);
			}
		}

		// 12.9: Reverting back to old Military time timestamps due to a problem with certain Timezone settings.
		// 12.8: Update all Logging DB timestamps so that they synched to the new GMT i18n file timestamps
		// This is just a note: update is done in function: bpsPro_sync_time_gmt() and only occurs one time.
		
		// 12.9: Save the Activation DB options - new option added to check if/when the domain URL is changed
		$ACT_options = get_option('bulletproof_security_options_activation');
		
		$BPS_ACT_Options = array(
		'bps_pro_activation' 		=> $ACT_options['bps_pro_activation'], 
		'delete_paypal_email' 		=> $ACT_options['delete_paypal_email'], 
		'bps_pro_key' 				=> $ACT_options['bps_pro_key'], 
		'bps_api_key' 				=> $ACT_options['bps_api_key'], 
		'bps_domain_url' 			=> get_bloginfo('url') 
		);	
	
		foreach( $BPS_ACT_Options as $key => $value ) {
			update_option('bulletproof_security_options_activation', $BPS_ACT_Options);
		}

		// 12.8: New Sucuri Dismiss Notice check created. Delete the user_meta for this Dismiss Notice.
		delete_user_meta($user_id, 'bps_ignore_sucuri_notice');
		// 12.8: New WP-Cron Control plugin Dismiss Notice check created. Delete the user_meta for this Dismiss Notice.
		delete_user_meta($user_id, 'bpsPro_ignore_wp_cron_control_plugin_notice');

		// 12.6: BugFix: pre-save bps_isl_custom_roles as an array
		// 12.5: Added Custom User Roles. bps_isl_uri_exclusions was not added/updated in previous BPS version.
		// 11.9: Add/Update new ISL DB options. conditional on whether someone is using ISL or not.
		$isl_options = get_option('bulletproof_security_options_idle_session');
		
		if ( isset($isl_options['bps_isl']) && $isl_options['bps_isl'] == 'On' || isset($isl_options['bps_isl']) && $isl_options['bps_isl'] == 'Off' ) {

		if ( ! isset($isl_options['bps_isl_custom_roles']) ) {
			$isl_options18 = array( 'bps', '' );
		
		} else {

			foreach ( $isl_options as $key => $value ) {
		
				if ( $key == 'bps_isl_custom_roles' ) {
					
					if ( ! is_array($value) ) {
						$isl_options18 = array( 'bps', '' );
					} else { 
						$isl_options18 = $isl_options['bps_isl_custom_roles'];
					}
				}
			}	
		}

		$isl_db_options = array(
		'bps_isl' 							=> $isl_options['bps_isl'], 
		'bps_isl_timeout' 					=> $isl_options['bps_isl_timeout'], 
		'bps_isl_logout_url' 				=> $isl_options['bps_isl_logout_url'], 
		'bps_isl_login_url' 				=> $isl_options['bps_isl_login_url'], 
		'bps_isl_custom_message' 			=> $isl_options['bps_isl_custom_message'], 
		'bps_isl_custom_css_1' 				=> $isl_options['bps_isl_custom_css_1'], 
		'bps_isl_custom_css_2' 				=> $isl_options['bps_isl_custom_css_2'], 
		'bps_isl_custom_css_3' 				=> $isl_options['bps_isl_custom_css_3'], 
		'bps_isl_custom_css_4' 				=> $isl_options['bps_isl_custom_css_4'], 
		'bps_isl_user_account_exceptions'	=> $isl_options['bps_isl_user_account_exceptions'],  
		'bps_isl_administrator' 			=> $isl_options['bps_isl_administrator'], 
		'bps_isl_editor' 					=> $isl_options['bps_isl_editor'], 
		'bps_isl_author' 					=> $isl_options['bps_isl_author'], 
		'bps_isl_contributor' 				=> $isl_options['bps_isl_contributor'], 
		'bps_isl_subscriber' 				=> $isl_options['bps_isl_subscriber'], 
		'bps_isl_tinymce' 					=> $isl_options['bps_isl_tinymce'], 
		'bps_isl_uri_exclusions' 			=> $isl_options['bps_isl_uri_exclusions'], 
		'bps_isl_custom_roles' 				=> $isl_options18 
		);

		foreach( $isl_db_options as $key => $value ) {
			update_option('bulletproof_security_options_idle_session', $isl_db_options);
		}
		}

		// 12.6: BugFix: pre-save ACE db options.
		$ace_options = get_option('bulletproof_security_options_auth_cookie');  
	
		if ( isset($ace_options['bps_ace']) && $ace_options['bps_ace'] == 'On' || isset($ace_options['bps_ace']) && $ace_options['bps_ace'] == 'Off' ) {
			
		if ( ! isset($ace_options['bps_ace_custom_roles']) ) {
			$ace_options11 = array( 'bps', '' );
		
		} else {
			
			foreach ( $ace_options as $key => $value ) {
		
				if ( $key == 'bps_ace_custom_roles' ) {
					
					if ( ! is_array($value) ) {
						$ace_options11 = array( 'bps', '' );
					} else { 
						$ace_options11 = $ace_options['bps_ace_custom_roles'];
					}
				}
			}	
		}
		
		$ace_db_options = array(
		'bps_ace' 							=> $ace_options['bps_ace'], 
		'bps_ace_expiration' 				=> $ace_options['bps_ace_expiration'], 
		'bps_ace_rememberme_expiration' 	=> $ace_options['bps_ace_rememberme_expiration'], 
		'bps_ace_user_account_exceptions' 	=> $ace_options['bps_ace_user_account_exceptions'], 
		'bps_ace_administrator' 			=> $ace_options['bps_ace_administrator'], 
		'bps_ace_editor' 					=> $ace_options['bps_ace_editor'], 
		'bps_ace_author' 					=> $ace_options['bps_ace_author'], 
		'bps_ace_contributor' 				=> $ace_options['bps_ace_contributor'], 
		'bps_ace_subscriber' 				=> $ace_options['bps_ace_subscriber'], 
		'bps_ace_rememberme_disable'		=> $ace_options['bps_ace_rememberme_disable'],  
		'bps_ace_custom_roles' 				=> $ace_options11 
		);

		foreach( $ace_db_options as $key => $value ) {
			update_option('bulletproof_security_options_auth_cookie', $ace_db_options);
		}
		}
		
		// 13.5: Added new JTC option: bps_jtc_mu_register_form. On upgrade save the db option with a blank value/not enabled/turned On.
		// 13.4.1: Added new JTC option: bps_jtc_custom_form_error. Defaults to standard JTC CAPTCHA error message.
		// 13.2: BugFix: Enable JTC for WooCommerce option being reset on upgrade. Only enable once if the option does not exist.
		// 12.6: pre-save JTC db options & New Enable JTC for WooCommerce option added
		$jtc_options = get_option('bulletproof_security_options_login_security_jtc');
		$woo_plugin = 'woocommerce/woocommerce.php';
		$woo_plugin_active = in_array( $woo_plugin, apply_filters('active_plugins', get_option('active_plugins')));
	
		if ( isset($jtc_options['bps_tooltip_captcha_logging']) && $jtc_options['bps_tooltip_captcha_logging'] == 'On' || isset($jtc_options['bps_tooltip_captcha_logging']) && $jtc_options['bps_tooltip_captcha_logging'] == 'Off' ) {

		if ( ! isset($jtc_options['bps_jtc_custom_roles']) ) {
			$jtc_options19 = array( 'bps', '' );
		
		} else {

			foreach ( $jtc_options as $key => $value ) {
		
				if ( $key == 'bps_jtc_custom_roles' ) {
					
					if ( ! is_array($value) ) {
						$jtc_options19 = array( 'bps', '' );
					} else { 
						$jtc_options19 = $jtc_options['bps_jtc_custom_roles'];
					}
				}
			}	
		}
		
		if ( $woo_plugin_active == 1 || is_plugin_active_for_network( $woo_plugin ) ) {
			if ( $jtc_options['bps_enable_jtc_woocommerce'] == '' || $jtc_options['bps_enable_jtc_woocommerce'] == '1' ) {
				$bps_enable_jtc_woocommerce = $jtc_options['bps_enable_jtc_woocommerce'];
			} elseif ( ! isset($jtc_options['bps_enable_jtc_woocommerce']) ) {
				$bps_enable_jtc_woocommerce = '1';
			}
		} else {
			$bps_enable_jtc_woocommerce = '';
		}

		$bps_jtc_custom_form_error = ! isset($jtc_options['bps_jtc_custom_form_error']) ? '' : $jtc_options['bps_jtc_custom_form_error'];

		$jtc_db_options = array(
		'bps_tooltip_captcha_key' 			=> $jtc_options['bps_tooltip_captcha_key'], 
		'bps_tooltip_captcha_hover_text' 	=> $jtc_options['bps_tooltip_captcha_hover_text'], 
		'bps_tooltip_captcha_title' 		=> $jtc_options['bps_tooltip_captcha_title'], 
		'bps_tooltip_captcha_logging' 		=> $jtc_options['bps_tooltip_captcha_logging'], 
		'bps_jtc_login_form' 				=> $jtc_options['bps_jtc_login_form'], 
		'bps_jtc_register_form' 			=> $jtc_options['bps_jtc_register_form'], 
		'bps_jtc_lostpassword_form' 		=> $jtc_options['bps_jtc_lostpassword_form'], 
		'bps_jtc_comment_form' 				=> $jtc_options['bps_jtc_comment_form'], 
		'bps_jtc_mu_register_form' 			=> $jtc_options['bps_jtc_mu_register_form'], 
		'bps_jtc_buddypress_register_form' 	=> $jtc_options['bps_jtc_buddypress_register_form'], 
		'bps_jtc_buddypress_sidebar_form' 	=> $jtc_options['bps_jtc_buddypress_sidebar_form'], 
		'bps_jtc_administrator' 			=> $jtc_options['bps_jtc_administrator'], 
		'bps_jtc_editor' 					=> $jtc_options['bps_jtc_editor'], 
		'bps_jtc_author' 					=> $jtc_options['bps_jtc_author'], 
		'bps_jtc_contributor' 				=> $jtc_options['bps_jtc_contributor'], 
		'bps_jtc_subscriber' 				=> $jtc_options['bps_jtc_subscriber'], 
		'bps_jtc_comment_form_error' 		=> $jtc_options['bps_jtc_comment_form_error'], 
		'bps_jtc_comment_form_label' 		=> $jtc_options['bps_jtc_comment_form_label'], 
		'bps_jtc_comment_form_input' 		=> $jtc_options['bps_jtc_comment_form_input'], 
		'bps_jtc_custom_roles' 				=> $jtc_options19, 
		'bps_enable_jtc_woocommerce' 		=> $bps_enable_jtc_woocommerce, 
		'bps_jtc_custom_form_error' 		=> $bps_jtc_custom_form_error 
		);

		foreach( $jtc_db_options as $key => $value ) {
			update_option('bulletproof_security_options_login_security_jtc', $jtc_db_options);
		}		
		}
		
		// 13.2: BugFix: Enable Login Security for WooCommerce option being reset on upgrade. Only enable once if the option does not exist.
		// 12.6: New Enable LSM for WooCommerce option added
		// 10.2: New Login Security Attempts Remaining option added
		$lsm = get_option('bulletproof_security_options_login_security');	
	
		if ( $woo_plugin_active == 1 || is_plugin_active_for_network( $woo_plugin ) ) {
			if ( $lsm['bps_enable_lsm_woocommerce'] == '' || $lsm['bps_enable_lsm_woocommerce'] == '1' ) {
				$bps_enable_lsm_woocommerce = $lsm['bps_enable_lsm_woocommerce'];
			} elseif ( ! isset($lsm['bps_enable_lsm_woocommerce']) ) {
				$bps_enable_lsm_woocommerce = '1';
			} 
		} else {
			$bps_enable_lsm_woocommerce = '';
		}

		$lsm1 = ! isset($lsm['bps_max_logins']) ? '3' : $lsm['bps_max_logins'];
		$lsm2 = ! isset($lsm['bps_lockout_duration']) ? '15' : $lsm['bps_lockout_duration'];
		$lsm3 = ! isset($lsm['bps_manual_lockout_duration']) ? '60' : $lsm['bps_manual_lockout_duration'];
		$lsm4 = ! isset($lsm['bps_max_db_rows_display']) ? '' : $lsm['bps_max_db_rows_display'];
		$lsm5 = ! isset($lsm['bps_login_security_OnOff']) ? 'On' : $lsm['bps_login_security_OnOff'];
		$lsm6 = ! isset($lsm['bps_login_security_logging']) ? 'logLockouts' : $lsm['bps_login_security_logging'];
		$lsm7 = ! isset($lsm['bps_login_security_errors']) ? 'wpErrors' : $lsm['bps_login_security_errors'];
		$lsm8 = ! isset($lsm['bps_login_security_remaining']) ? 'On' : $lsm['bps_login_security_remaining'];
		$lsm9 = ! isset($lsm['bps_login_security_pw_reset']) ? 'enable' : $lsm['bps_login_security_pw_reset'];
		$lsm10 = ! isset($lsm['bps_login_security_sort']) ? 'ascending' : $lsm['bps_login_security_sort'];

		$lsm_options = array(
		'bps_max_logins' 				=> $lsm1, 
		'bps_lockout_duration' 			=> $lsm2, 
		'bps_manual_lockout_duration' 	=> $lsm3, 
		'bps_max_db_rows_display' 		=> $lsm4, 
		'bps_login_security_OnOff' 		=> $lsm5, 
		'bps_login_security_logging' 	=> $lsm6, 
		'bps_login_security_errors' 	=> $lsm7, 
		'bps_login_security_remaining' 	=> $lsm8, 
		'bps_login_security_pw_reset' 	=> $lsm9, 
		'bps_login_security_sort' 		=> $lsm10, 
		'bps_enable_lsm_woocommerce' 	=> $bps_enable_lsm_woocommerce 
		);

		foreach( $lsm_options as $key => $value ) {
			update_option('bulletproof_security_options_login_security', $lsm_options);
		}

		// 11.9.1: Custom default.htacces File
		// If a /bps-backup/master-backups/default.htaccess exists then copy it to /htaccess/default.htaccess
		$custom_default_htaccess = WP_CONTENT_DIR . '/bps-backup/master-backups/default.htaccess';
		$DefaultHtaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/default.htaccess';
		if ( file_exists($custom_default_htaccess) ) {
			copy($custom_default_htaccess, $DefaultHtaccess);
		}
		
		// 11.9: Add/Update new Hidden|Empty Plugin Folders|Files Cron DB options.
		$hpf_cron = get_option('bulletproof_security_options_hpf_cron');

		$hpf_cron1 = ! isset($hpf_cron['bps_hidden_plugins_cron']) ? 'On' : $hpf_cron['bps_hidden_plugins_cron'];
		$hpf_cron2 = ! isset($hpf_cron['bps_hidden_plugins_cron_frequency']) ? '15' : $hpf_cron['bps_hidden_plugins_cron_frequency'];
		$hpf_cron3 = ! isset($hpf_cron['bps_hidden_plugins_cron_email']) ? '' : $hpf_cron['bps_hidden_plugins_cron_email'];
		$hpf_cron4 = ! isset($hpf_cron['bps_hidden_plugins_cron_alert']) ? '' : $hpf_cron['bps_hidden_plugins_cron_alert'];	
		
		$hpf_cron_options = array(
		'bps_hidden_plugins_cron' 			=> $hpf_cron1, 
		'bps_hidden_plugins_cron_frequency' => $hpf_cron2, 
		'bps_hidden_plugins_cron_email' 	=> $hpf_cron3, 
		'bps_hidden_plugins_cron_alert' 	=> $hpf_cron4 
		);

		foreach( $hpf_cron_options as $key => $value ) {
			update_option('bulletproof_security_options_hpf_cron', $hpf_cron_options);
		}
		
		// 11.9: Add/Update new Hidden|Empty Plugin Folders|Files Ignore Hidden Plugin Folders & Files DB options.
		$hpf_check = get_option('bulletproof_security_options_hidden_plugins');
		$hpf_check1 = ! isset($hpf_check['bps_hidden_plugins_check']) ? '' : $hpf_check['bps_hidden_plugins_check'];
		
		$hpf_check_options = array( 'bps_hidden_plugins_check' => $hpf_check1 );

		foreach( $hpf_check_options as $key => $value ) {
			update_option('bulletproof_security_options_hidden_plugins', $hpf_check_options);
		}

		// 13.3: Add new & Update all S-Monitor email alert options.
		// 11.9: Add new & Update all S-Monitor email alert options. 
		// 11.7: Add new & Update all S-Monitor email alert options.
		// 11.5: Add new & Update all S-Monitor email alert options.
		// 14.9: BugFix & Now using isset(). 
		$sme = get_option('bulletproof_security_options_email');
		$admin_email = get_option('admin_email');

		$sme1 = ! isset($sme['bps_send_email_to']) ? $admin_email : $sme['bps_send_email_to'];
		$sme2 = ! isset($sme['bps_send_email_from']) ? $admin_email : $sme['bps_send_email_from'];
		$sme3 = ! isset($sme['bps_send_email_cc']) ? '' : $sme['bps_send_email_cc'];
		$sme4 = ! isset($sme['bps_send_email_bcc']) ? '' : $sme['bps_send_email_bcc'];
		$sme5 = ! isset($sme['bps_login_security_email']) ? 'lockoutOnly' : $sme['bps_login_security_email'];
		$sme6 = ! isset($sme['bps_autorestore_email']) ? 'yes' : $sme['bps_autorestore_email'];
		$sme7 = ! isset($sme['bps_arq_log_size']) ? '500KB' : $sme['bps_arq_log_size'];
		$sme8 = ! isset($sme['bps_arq_log_email']) ? 'email' : $sme['bps_arq_log_email'];
		$sme9 = ! isset($sme['bps_security_log_email']) ? 'no' : $sme['bps_security_log_email'];
		$sme10 = ! isset($sme['bps_security_log_size']) ? '500KB' : $sme['bps_security_log_size'];
		$sme11 = ! isset($sme['bps_security_log_emailL']) ? 'email' : $sme['bps_security_log_emailL'];
		$sme12 = ! isset($sme['bps_error_log_email']) ? 'no' : $sme['bps_error_log_email'];
		$sme13 = ! isset($sme['bps_php_log_size']) ? '500KB' : $sme['bps_php_log_size'];
		$sme14 = ! isset($sme['bps_php_log_email']) ? 'email' : $sme['bps_php_log_email'];
		$sme15 = ! isset($sme['bps_upgrade_email']) ? 'yes' : $sme['bps_upgrade_email'];	
		$sme16 = ! isset($sme['bps_dbm_email']) ? 'no' : $sme['bps_dbm_email'];
		$sme17 = ! isset($sme['bps_dbm_log_email']) ? 'email' : $sme['bps_dbm_log_email'];
		$sme18 = ! isset($sme['bps_dbm_log_size']) ? '500KB' : $sme['bps_dbm_log_size'];
		$sme19 = ! isset($sme['bps_dbb_log_email']) ? 'email' : $sme['bps_dbb_log_email'];
		$sme20 = ! isset($sme['bps_dbb_log_size']) ? '500KB' : $sme['bps_dbb_log_size'];
		$sme21 = ! isset($sme['bps_flock_email']) ? 'yes' : $sme['bps_flock_email'];	
		$sme22 = ! isset($sme['bps_arq_cron_frequency_email']) ? '15' : $sme['bps_arq_cron_frequency_email'];
		$sme23 = ! isset($sme['bps_arq_cron_next_email']) ? '0' : $sme['bps_arq_cron_next_email'];
		## 15.9: BugFix for these 4 options. These 4 options were saved with blank values in a previous BPS version.
		if ( isset($sme['bps_hpf_email']) && $sme['bps_hpf_email'] == '' ) {
			$sme24 = 'yes';
		} else {
			$sme24 = ! isset($sme['bps_hpf_email']) ? 'yes' : $sme['bps_hpf_email'];
		}
		if ( isset($sme['bps_mscan_email']) && $sme['bps_mscan_email'] == '' ) {
			$sme25 = 'yes';
		} else {
			$sme25 = ! isset($sme['bps_mscan_email']) ? 'yes' : $sme['bps_mscan_email'];
		}		
		if ( isset($sme['bps_mscan_log_size']) && $sme['bps_mscan_log_size'] == '' ) {
			$sme26 = '500KB';
		} else {
			$sme26 = ! isset($sme['bps_mscan_log_size']) ? '500KB' : $sme['bps_mscan_log_size'];
		}
		if ( isset($sme['bps_mscan_log_email']) && $sme['bps_mscan_log_email'] == '' ) {
			$sme27 = 'email';
		} else {
			$sme27 = ! isset($sme['bps_mscan_log_email']) ? 'email' : $sme['bps_mscan_log_email'];
		}

		$sme28 = ! isset($sme['bps_plugin_updates_frequency']) ? '1Hour' : $sme['bps_plugin_updates_frequency'];
		$sme29 = ! isset($sme['bps_plugin_updates_email']) ? 'no' : $sme['bps_plugin_updates_email'];
		$sme30 = ! isset($sme['bps_theme_updates_frequency']) ? '1Hour' : $sme['bps_theme_updates_frequency'];
		$sme31 = ! isset($sme['bps_theme_updates_email']) ? 'no' : $sme['bps_theme_updates_email'];				

		$sme_options = array(
		'bps_send_email_to' 			=> $sme1, 
		'bps_send_email_from' 			=> $sme2, 
		'bps_send_email_cc' 			=> $sme3, 
		'bps_send_email_bcc' 			=> $sme4, 
		'bps_login_security_email' 		=> $sme5, 
		'bps_autorestore_email' 		=> $sme6, 
		'bps_arq_log_size' 				=> $sme7, 
		'bps_arq_log_email' 			=> $sme8, 
		'bps_security_log_email' 		=> $sme9, 
		'bps_security_log_size' 		=> $sme10, 
		'bps_security_log_emailL' 		=> $sme11, 
		'bps_error_log_email' 			=> $sme12,  
		'bps_php_log_size' 				=> $sme13, 
		'bps_php_log_email' 			=> $sme14,  
		'bps_upgrade_email' 			=> $sme15,  
		'bps_dbm_email' 				=> $sme16, 
		'bps_dbm_log_email' 			=> $sme17, 
		'bps_dbm_log_size' 				=> $sme18,  
		'bps_dbb_log_email' 			=> $sme19, 
		'bps_dbb_log_size' 				=> $sme20, 
		'bps_flock_email' 				=> $sme21, 
		'bps_arq_cron_frequency_email' 	=> $sme22, 
		'bps_arq_cron_next_email' 		=> $sme23, 
		'bps_hpf_email' 				=> $sme24, 
		'bps_mscan_email' 				=> $sme25, 		
		'bps_mscan_log_size' 			=> $sme26, 
		'bps_mscan_log_email' 			=> $sme27, 
		'bps_plugin_updates_frequency' 	=> $sme28, 
		'bps_plugin_updates_email' 		=> $sme29,
		'bps_theme_updates_frequency' 	=> $sme30,
		'bps_theme_updates_email' 		=> $sme31 
		);

		foreach( $sme_options as $key => $value ) {
			update_option('bulletproof_security_options_email', $sme_options);
		}

		// 11.8: Wordfence WAF disaster - Reset php handler dismiss notice.
		bpsPro_php_handler_dismiss_notice_reset();
		
		// 13.3: Add new & Update all S-Monitor dashboard status & alert options.		
		// 11.7: Add new & Update all S-Monitor dashboard status & alert options. Code moved from 11.5 update section.
		// 11.5: Add new & Update all S-Monitor dashboard status & alert options.
		// 13.3: added new bps_autorestore_alerts option 
		// Note: bps_upgrade_notice DB option is obsolete and not included here.
		$sm = get_option('bulletproof_security_options_monitor');

		$sm1 = ! isset($sm['bps_first_launch']) ? 'Off' : $sm['bps_first_launch'];
		$sm2 = ! isset($sm['bps_security_status']) ? 'wpOn' : $sm['bps_security_status'];
		$sm3 = ! isset($sm['bps_SecLog_entry']) ? 'Off' : $sm['bps_SecLog_entry'];
		$sm4 = ! isset($sm['bps_autorestore_status']) ? 'wpOn' : $sm['bps_autorestore_status'];
		$sm4b = ! isset($sm['bps_autorestore_alerts']) ? 'wpOn' : $sm['bps_autorestore_alerts'];
		$sm5 = ! isset($sm['bps_plugin_firewall_status']) ? 'wpOn' : $sm['bps_plugin_firewall_status'];
		$sm6 = ! isset($sm['bps_UAEG_status']) ? 'wpOn' : $sm['bps_UAEG_status'];
		$sm7 = ! isset($sm['bps_login_security_status']) ? 'wpOn' : $sm['bps_login_security_status'];
		$sm8 = ! isset($sm['bps_flock_status']) ? 'wpOn' : $sm['bps_flock_status'];
		$sm9 = ! isset($sm['bps_HUD_alerts']) ? 'wpOn' : $sm['bps_HUD_alerts'];
		$sm10 = ! isset($sm['bps_PHP_ELogLoc_set']) ? 'wpOn' : $sm['bps_PHP_ELogLoc_set'];
		$sm11 = ! isset($sm['bps_PHP_ELog_error']) ? 'wpOn' : $sm['bps_PHP_ELog_error'];
		$sm12 = ! isset($sm['bps_phpini_created']) ? 'wpOn' : $sm['bps_phpini_created'];
		$sm13 = ! isset($sm['bps_login_security_alerts']) ? 'wpOn' : $sm['bps_login_security_alerts'];
		$sm14 = ! isset($sm['bps_jtc_antispam_status']) ? 'wpOn' : $sm['bps_jtc_antispam_status'];
		$sm15 = ! isset($sm['bps_dbm_status']) ? 'wpOn' : $sm['bps_dbm_status'];
		$sm16 = ! isset($sm['bps_dbm_alerts']) ? 'Off' : $sm['bps_dbm_alerts'];
		$sm17 = ! isset($sm['bps_dbb_status']) ? 'wpOn' : $sm['bps_dbb_status'];
		$sm18 = ! isset($sm['bps_flock_FL_alerts']) ? 'wpOn' : $sm['bps_flock_FL_alerts'];
		$sm19 = ! isset($sm['bps_isl_status']) ? 'Off' : $sm['bps_isl_status'];
		$sm20 = ! isset($sm['bps_ace_status']) ? 'Off' : $sm['bps_ace_status'];
		$sm21 = ! isset($sm['bps_mscan_status_display']) ? 'wpOn' : $sm['bps_mscan_status_display'];

		$sm_options = array(
		'bps_first_launch' 				=> $sm1, 
		'bps_security_status' 			=> $sm2, 
		'bps_SecLog_entry' 				=> $sm3, 
		'bps_autorestore_status' 		=> $sm4, 
		'bps_autorestore_alerts' 		=> $sm4b, 
		'bps_plugin_firewall_status' 	=> $sm5, 
		'bps_UAEG_status' 				=> $sm6, 
		'bps_login_security_status' 	=> $sm7, 
		'bps_flock_status' 				=> $sm8, 
		'bps_HUD_alerts' 				=> $sm9, 
		'bps_PHP_ELogLoc_set' 			=> $sm10, 
		'bps_PHP_ELog_error' 			=> $sm11, 
		'bps_phpini_created' 			=> $sm12, 
		'bps_login_security_alerts' 	=> $sm13, 
		'bps_jtc_antispam_status' 		=> $sm14, 
		'bps_dbm_status' 				=> $sm15, 
		'bps_dbm_alerts' 				=> $sm16, 
		'bps_dbb_status' 				=> $sm17, 
		'bps_flock_FL_alerts' 			=> $sm18, 
		'bps_isl_status' 				=> $sm19, 		
		'bps_ace_status' 				=> $sm20, 
		'bps_mscan_status_display' 		=> $sm21 
		);

		foreach( $sm_options as $key => $value ) {
			update_option('bulletproof_security_options_monitor', $sm_options);
		}

	// 11.6: delete the Folder Lock usermeta db option
	delete_user_meta($user_id, 'bps_ignore_folder_lock_notice');
	// 11.6: delete the JTC Feature Setup usermeta db option
	delete_user_meta($user_id, 'bps_ignore_JTC_notice');

	// 11.5: Condition added to allow commenting out wp-admin URI whitelist rule
	// 11.4: POST Request Attack Protection code correction|addition
	bpsPro_post_request_protection_check();

	// 11.5: Add/Update new Folder Lock DB options.
	$flock = get_option('bulletproof_security_options_flock_FL');

	$flock1 = ! isset($flock['bps_folder_lock_cron']) ? 'Off' : $flock['bps_folder_lock_cron'];
	$flock2 = ! isset($flock['bps_folder_lock_cron_frequency']) ? '2' : $flock['bps_folder_lock_cron_frequency'];
	$flock3 = ! isset($flock['bps_folder_lock_cron_end']) ? time() + 120 : $flock['bps_folder_lock_cron_end'];
	
	$flock_options = array(
	'bps_folder_lock_cron' 				=> $flock1, 
	'bps_folder_lock_cron_frequency' 	=> $flock2, 
	'bps_folder_lock_cron_end' 			=> $flock3 
	);

	foreach( $flock_options as $key => $value ) {
		update_option('bulletproof_security_options_flock_FL', $flock_options);
	}	

	// 11.5: Add/Update new Folder Lock Last Modified Time DB Reset option.
	$fl_alert = get_option('bulletproof_security_options_flock_FL_alerts');
	$fl_alert1 = ! isset($fl_alert['bps_folderlock_db_mod_time']) ? bps_getFolderLockResetFileLastMod_secs() : $fl_alert['bps_folderlock_db_mod_time'];
	$fl_alert_options = array( 'bps_folderlock_db_mod_time' => $fl_alert1 );
			
	foreach( $fl_alert_options as $key => $value ) {
		update_option('bulletproof_security_options_flock_FL_alerts', $fl_alert_options);
	}

	// 11.5: Folder Lock Hosting Account Root folder scan
	require_once ( WP_PLUGIN_DIR . '/bulletproof-security/admin/wizard/swizard-folder-lock.php' );
	bpsPro_SWizard_flock_folder_scan();

	// 11.2: Pre-Save UAEG Custom Code db option for Export|Import tools if it does not exist
	$ccu = get_option('bulletproof_security_options_customcode_UAEG');
	$ccu1 = ! isset($ccu['bps_customcode_uaeg']) ? '' : $ccu['bps_customcode_uaeg'];
	$ccu_options = array( 'bps_customcode_uaeg' => $ccu1 );
			
	foreach( $ccu_options as $key => $value ) {
		update_option('bulletproof_security_options_customcode_UAEG', $ccu_options);
	}

	// 11.1: Pre-save UI Theme Skin with Blue Theme if DB option does not exist
	bpsPro_presave_ui_theme_skin_options();

	// 11: Create new Plugin Firewall htaccess file
	$PluginsHtaccess = WP_PLUGIN_DIR . '/.htaccess';
	if ( file_exists($PluginsHtaccess) ) {
		$check_string_pfw = @file_get_contents($PluginsHtaccess);
	}
	$PFW_autopilot_options = get_option('bulletproof_security_options_pfw_autopilot');
	
	if ( file_exists($PluginsHtaccess) && ! strpos( $check_string_pfw, "BPS Pro 11 mod_rewrite" ) && $PFW_autopilot_options['bps_pfw_autopilot_cron'] == 'On' ) {		
	
		require_once ( WP_PLUGIN_DIR . '/bulletproof-security/admin/wizard/swizard-functions.php' );		
		bpsSetupWizardPluginFirewall_File();
	}
	
	// 11: delete the LiteSpeed Dismiss Notice user meta value so that the new LiteSpeed Dismiss Notice is displayed
	// bps_hud_pfw_litespeed_notice() has a new condition that checks strpos "BPS Pro 11 mod_rewrite" so that it will only be displayed once
	$sapi_type = php_sapi_name();

	if ( @substr($sapi_type, 0, 9) == 'litespeed' ) {
		global $current_user;
		$user_id = $current_user->ID;	
		delete_user_meta($user_id, 'bps_ignore_PFW_litespeed_notice');
	}
	
	// 10.8: If Custom Code db options do not exist yet, create blank values
	$ccr = get_option('bulletproof_security_options_customcode');
	
	$ccr1 = ! isset($ccr['bps_customcode_one']) ? '' : $ccr['bps_customcode_one'];
	$ccr2 = ! isset($ccr['bps_customcode_server_signature']) ? '' : $ccr['bps_customcode_server_signature'];
	$ccr3 = ! isset($ccr['bps_customcode_directory_index']) ? '' : $ccr['bps_customcode_directory_index'];
	$ccr4 = ! isset($ccr['bps_customcode_server_protocol']) ? '' : $ccr['bps_customcode_server_protocol'];
	$ccr5 = ! isset($ccr['bps_customcode_error_logging']) ? '' : $ccr['bps_customcode_error_logging'];
	$ccr6 = ! isset($ccr['bps_customcode_deny_dot_folders']) ? '' : $ccr['bps_customcode_deny_dot_folders'];
	$ccr7 = ! isset($ccr['bps_customcode_admin_includes']) ? '' : $ccr['bps_customcode_admin_includes'];
	$ccr8 = ! isset($ccr['bps_customcode_wp_rewrite_start']) ? '' : $ccr['bps_customcode_wp_rewrite_start'];
	$ccr9 = ! isset($ccr['bps_customcode_request_methods']) ? '' : $ccr['bps_customcode_request_methods'];
	$ccr10 = ! isset($ccr['bps_customcode_two']) ? '' : $ccr['bps_customcode_two'];
	$ccr11 = ! isset($ccr['bps_customcode_timthumb_misc']) ? '' : $ccr['bps_customcode_timthumb_misc'];
	$ccr12 = ! isset($ccr['bps_customcode_bpsqse']) ? '' : $ccr['bps_customcode_bpsqse'];
	$ccr12m = @! isset($ccr['bps_customcode_wp_rewrite_end']) ? '' : $ccr['bps_customcode_wp_rewrite_end'];
	$ccr13 = ! isset($ccr['bps_customcode_deny_files']) ? '' : $ccr['bps_customcode_deny_files'];
	$ccr14 = ! isset($ccr['bps_customcode_three']) ? '' : $ccr['bps_customcode_three'];

	if ( ! is_multisite() ) {

		$ccr_options = array(
		'bps_customcode_one' 				=> $ccr1, 
		'bps_customcode_server_signature' 	=> $ccr2, 
		'bps_customcode_directory_index' 	=> $ccr3, 
		'bps_customcode_server_protocol' 	=> $ccr4, 
		'bps_customcode_error_logging' 		=> $ccr5, 
		'bps_customcode_deny_dot_folders' 	=> $ccr6, 
		'bps_customcode_admin_includes' 	=> $ccr7, 
		'bps_customcode_wp_rewrite_start' 	=> $ccr8, 
		'bps_customcode_request_methods' 	=> $ccr9, 
		'bps_customcode_two' 				=> $ccr10, 
		'bps_customcode_timthumb_misc' 		=> $ccr11, 
		'bps_customcode_bpsqse' 			=> $ccr12, 
		'bps_customcode_deny_files' 		=> $ccr13, 
		'bps_customcode_three' 				=> $ccr14
		);
				
	} else {
					
		$ccr_options = array(
		'bps_customcode_one' 				=> $ccr1, 
		'bps_customcode_server_signature' 	=> $ccr2, 
		'bps_customcode_directory_index' 	=> $ccr3, 
		'bps_customcode_server_protocol' 	=> $ccr4, 
		'bps_customcode_error_logging' 		=> $ccr5, 
		'bps_customcode_deny_dot_folders' 	=> $ccr6, 
		'bps_customcode_admin_includes' 	=> $ccr7, 
		'bps_customcode_wp_rewrite_start' 	=> $ccr8, 
		'bps_customcode_request_methods' 	=> $ccr9, 
		'bps_customcode_two' 				=> $ccr10, 
		'bps_customcode_timthumb_misc' 		=> $ccr11, 
		'bps_customcode_bpsqse' 			=> $ccr12, 
		'bps_customcode_wp_rewrite_end' 	=> $ccr12m, 
		'bps_customcode_deny_files' 		=> $ccr13, 
		'bps_customcode_three' 				=> $ccr14
		);					
	}

	foreach( $ccr_options as $key => $value ) {
		update_option('bulletproof_security_options_customcode', $ccr_options);
	}

	$ccw = get_option('bulletproof_security_options_customcode_WPA');
	
	$ccw1 = ! isset($ccw['bps_customcode_deny_files_wpa']) ? '' : $ccw['bps_customcode_deny_files_wpa'];
	$ccw2 = ! isset($ccw['bps_customcode_one_wpa']) ? '' : $ccw['bps_customcode_one_wpa'];
	$ccw3 = ! isset($ccw['bps_customcode_two_wpa']) ? '' : $ccw['bps_customcode_two_wpa'];
	$ccw4 = ! isset($ccw['bps_customcode_bpsqse_wpa']) ? '' : $ccw['bps_customcode_bpsqse_wpa'];
	
	$ccw_options = array(
	'bps_customcode_deny_files_wpa' => $ccw1, 
	'bps_customcode_one_wpa' 		=> $ccw2, 
	'bps_customcode_two_wpa' 		=> $ccw3, 
	'bps_customcode_bpsqse_wpa' 	=> $ccw4
	);
			
	foreach( $ccw_options as $key => $value ) {
		update_option('bulletproof_security_options_customcode_WPA', $ccw_options);
	}

	$dbm = get_option('bulletproof_security_options_db_monitor');	
	
	$dbm1 = ! isset($dbm['bps_db_monitor_cron']) ? 'On' : $dbm['bps_db_monitor_cron'];	
	$dbm2 = ! isset($dbm['bps_db_monitor_cron_frequency']) ? '15' : $dbm['bps_db_monitor_cron_frequency'];		
	$dbm3 = ! isset($dbm['bps_db_monitor_cron_table_created_check']) ? 'On' : $dbm['bps_db_monitor_cron_table_created_check'];		
	$dbm4 = ! isset($dbm['bps_db_monitor_cron_end']) ? time() + 900 : $dbm['bps_db_monitor_cron_end'];		
	
	$dbm_options = array( 
	'bps_db_monitor_cron' 						=> $dbm1, 
	'bps_db_monitor_cron_frequency' 			=> $dbm2, 
	'bps_db_monitor_cron_table_created_check' 	=> $dbm3, 
	'bps_db_monitor_cron_end' 					=> $dbm4
	);
	
	foreach( $dbm_options as $key => $value ) {
		update_option('bulletproof_security_options_db_monitor', $dbm_options);
	}

	$pfwap = get_option('bulletproof_security_options_pfw_autopilot');	
	
	$pfwap1 = ! isset($pfwap['bps_pfw_autopilot_cron']) ? 'On' : $pfwap['bps_pfw_autopilot_cron'];		
	$pfwap2 = ! isset($pfwap['bps_pfw_autopilot_cron_frequency']) ? '10' : $pfwap['bps_pfw_autopilot_cron_frequency'];
	$pfwap3 = ! isset($pfwap['bps_pfw_autopilot_cron_end']) ? time() + 900 : $pfwap['bps_pfw_autopilot_cron_end'];

	$pfwap_options = array( 
	'bps_pfw_autopilot_cron' 			=> $pfwap1,  
	'bps_pfw_autopilot_cron_frequency' 	=> $pfwap2,  	
	'bps_pfw_autopilot_cron_end' 		=> $pfwap3 
	);

	foreach( $pfwap_options as $key => $value ) {
		update_option('bulletproof_security_options_pfw_autopilot', $pfwap_options);
	}

	$bps_option_name_dbm = 'bulletproof_security_options_DBM_log';
	$bps_new_value_dbm = bpsPro_DBM_LogLastMod_wp_secs();
	$BPS_Options_dbm = array( 'bps_dbm_log_date_mod' => $bps_new_value_dbm );

	if ( ! get_option( $bps_option_name_dbm ) ) {	
		foreach( $BPS_Options_dbm as $key => $value ) {
			update_option('bulletproof_security_options_DBM_log', $BPS_Options_dbm);
		}
	}	
	
	$bps_option_name_dbb = 'bulletproof_security_options_DBB_log';
	$bps_new_value_dbb = bpsPro_DBB_LogLastMod_wp_secs();
	$BPS_Options_dbb = array( 'bps_dbb_log_date_mod' => $bps_new_value_dbb );

	if ( ! get_option( $bps_option_name_dbb ) ) {	
		foreach( $BPS_Options_dbb as $key => $value ) {
			update_option('bulletproof_security_options_DBB_log', $BPS_Options_dbb);
		}
	}

	$bps_option_name_mscan = 'bulletproof_security_options_MScan_log';
	$bps_new_value_mscan = bpsPro_MScan_LogLastMod_wp_secs();
	$BPS_Options_mscan = array( 'bps_mscan_log_date_mod' => $bps_new_value_mscan );

	if ( ! get_option( $bps_option_name_mscan ) ) {	
		foreach( $BPS_Options_mscan as $key => $value ) {
			update_option('bulletproof_security_options_MScan_log', $BPS_Options_mscan);
		}
	}

	// Misc cleanup, etc.
	// Delete all the old plugin api junk content in this transient
	delete_transient( 'bulletproof-security_info' );
	// Delete the BPS free Setup Wizard DB option
	delete_option('bulletproof_security_options_wizard_free');
	// Delete Test Mode DB option if it exists
	delete_option('bulletproof_security_options_pfirewall_TMode');
	// Delete PFW dismiss notice option if it exists
	delete_option('bulletproof_security_options_pfirewall_plugins'); 	
	// Delete Plugin Firewall Override DB Table if it exists
	$Ptable_name = $wpdb->prefix . "bpspro_pfw_override";
	$wpdb->query("DROP TABLE IF EXISTS $Ptable_name");
	// Delete PFW-TestMode.php file if it exists
	$PFWTestMode = WP_CONTENT_DIR . '/bps-backup/test-mode/PFW-TestMode.php';
	if ( file_exists($PFWTestMode) ) {
		unlink($PFWTestMode);
	}
		
	// Update BPS DB option - WP version matches the current version of WP & reset the last modified time in DB
	$gmt_offset = get_option( 'gmt_offset' ) * 3600;
	$versionphp = ABSPATH . 'wp-includes/version.php';	
	$last_modified_time_versionphp = date("F d Y H:i", filemtime($versionphp) + $gmt_offset);
	$bps_option_name12 = 'bulletproof_security_options_wp_version';
	$bps_new_value12 = $wp_version;	
	$bps_new_value12_1 = date("F d Y H:i", filemtime($versionphp) + $gmt_offset + 900);	
			
	$BPS_Options12 = array( 'bps_wp_version' => $bps_new_value12, 'bps_wp_version_last_modified_time' => $bps_new_value12_1 );	
	
	if ( ! get_option( $bps_option_name12 ) ) {	
		
		foreach( $BPS_Options12 as $key => $value ) {
			update_option('bulletproof_security_options_wp_version', $BPS_Options12);
		}
			
	} else {

		foreach( $BPS_Options12 as $key => $value ) {
			update_option('bulletproof_security_options_wp_version', $BPS_Options12);
		}	
	}
	}
}

?>