<?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();
}

function bpsPro_arq_ajax_admin_notices() {
	
	if ( current_user_can('manage_options') ) { 
		bpsPro_wordpress_update_core_manual();
		bpsPro_wordpress_update_core_manual_about_failsafe();
		bpsPro_wordpress_update_core_manual_about_failsafe_message();
		bpsPro_wordpress_update_core_manual_about();
	}
}

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

// AutoRestore: Backward compatibility for WP 4.5.3 or below. Turn Off AutoRestore if user is updating WP or installing or updating Themes.
// WP Updates page > WP Core Update > WP Core Re-Install > Bulk Plugin or Theme Installations and Updates
// When the redirect occurs to the about.php page in the about function all website files are backed up. 
function bpsPro_wordpress_update_core_manual() {
	
	if ( current_user_can( 'update_core' ) ) {
	
		global $pagenow, $wp_version;
		
		// 12: Backward compatibility based on WP version. Less than or equal to WP version 4.5.3
		if ( version_compare( $wp_version, '4.5.3', '<=' ) ) {
		
			// Check that MU POST values, pages and Query strings are the same as a single site too
			if ( 'update-core.php' == $pagenow && isset( $_POST['upgrade'] ) || 'update.php' == $pagenow && preg_match_all( '/action=upgrade-theme|action=update-selected-themes|action=install-theme|action=upload-theme/', esc_html($_SERVER['QUERY_STRING']), $matches ) ) {
		
				$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
				$gmt_offset = get_option( 'gmt_offset' ) * 3600;
				$timeNow = time();
				$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);
				$fh = @fopen($bpsProLog, 'a');
				
				$blank_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/blank.txt';
				$arq_failsafe_file = WP_CONTENT_DIR . '/bps-backup/master-backups/arq-failsafe.txt';
		
				if ( copy($blank_file, $arq_failsafe_file) ) {
					@fwrite($fh, "\r\n".'[Internal Usage: WP <= 4.5.3 bpsPro_wordpress_update_core_manual function: ARQ FS File Copy: Successful | '.$timestamp."]\r\n");
				}

				$ARQoptions = get_option('bulletproof_security_options_ARCM');

				$ARQ_status_Options = array( 
				'bps_arq_status' 			=> $ARQoptions['bps_autorestore_cron'], 
				'bps_arq_status_timestamp' 	=> time() 
				);
			
				foreach( $ARQ_status_Options as $key => $value ) {
					update_option('bulletproof_security_options_ARQ_status', $ARQ_status_Options);
				}
			
				$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			
				if ( $ARQ_status['bps_arq_status'] == 'Off' ) {
					@fwrite($fh, '[Internal Usage: WP <= 4.5.3 bpsPro_wordpress_update_core_manual function: ARQ Cron will not be turned back On | '.$timestamp."]\r\n");
					@fwrite($fh, '[Internal Usage: WP <= 4.5.3 bpsPro_wordpress_update_core_manual function: ARQ Cron was turned Off prior to update or installation | '.$timestamp."]\r\n");
			
				} else {
					@fwrite($fh, '[Internal Usage: WP <= 4.5.3 bpsPro_wordpress_update_core_manual function: Prior ARQ Cron Status: '.$ARQ_status['bps_arq_status'].' | '.$timestamp."]\r\n");
				}	

				$BPS_arq_upgrade = array( 'bps_arq_upgrade' => 'install_upgrade' );	
	
				foreach( $BPS_arq_upgrade as $key => $value ) {
					update_option('bulletproof_security_options_ARQ_upgrade', $BPS_arq_upgrade);
				}	
		
				$ARQoptions2 = ! $ARQoptions['bps_autorestore_cron_frequency'] ? '2' : $ARQoptions['bps_autorestore_cron_frequency'];
				$ARQoptions3 = ! $ARQoptions['bps_autorestore_cron_forced'] ? '1' : $ARQoptions['bps_autorestore_cron_forced'];
				$ARQoptions4 = ! $ARQoptions['bps_autorestore_cron_override'] ? 'Off' : $ARQoptions['bps_autorestore_cron_override'];
				$ARQoptions5 = ! $ARQoptions['bps_autorestore_cron_filecheck'] ? 'Off' : $ARQoptions['bps_autorestore_cron_filecheck'];
				$ARQoptions6 = ! $ARQoptions['bps_autorestore_cron_end'] ? '' : $ARQoptions['bps_autorestore_cron_end'];		
		
				$ARQ_Options = array(
				'bps_autorestore_cron' 				=> 'Off', 
				'bps_autorestore_cron_frequency' 	=> $ARQoptions2, 
				'bps_autorestore_cron_forced' 		=> $ARQoptions3, 
				'bps_autorestore_cron_override' 	=> $ARQoptions4, 
				'bps_autorestore_cron_filecheck' 	=> $ARQoptions5, 
				'bps_autorestore_cron_end' 			=> $ARQoptions6
				);	

				foreach( $ARQ_Options as $key => $value ) {
					update_option('bulletproof_security_options_ARCM', $ARQ_Options);
				}
				
				@fwrite($fh, '[Internal Usage: WP <= 4.5.3 bpsPro_wordpress_update_core_manual function: ARQ Cron was turned Off | '.$timestamp."]\r\n");
				@fclose($fh);
			}
		}
	}
}

// WordPress Manual Update FailSafe function:
// This function creates a file: that is used in other functions to check whether ARQ can be turned back On or display a message that ARQ Automation failed.
// Scenario: If the AJAX functions fail/are not processed then ARQ will NOT be turned Off and the $ARQ_upgrade values will not be updated.
// Example: bpsPro_ajax_arq_automation_wp_core_update() is supposed to turn ARQ Off and update the db with this value: wp_core_update
// The bpsPro_wordpress_update_core_manual_about() function will NOT backup files and turn ARQ back On if this problem occurs.
// A message will be displayed if this problem occurs: ARQ is turned Off and to run the Wizards again.
// 12.5: FailSafe function created
// 12.6: Simplified this function so that it only does 1 simple thing: creates/copies the arq-failsafe.txt, which is checked in the ARQ Fire function.
// If the file exists then the ARQ Crons will exit. There were too many complications with adding variable checks  
// & DB value updating in this function - sequence timing complications.
function bpsPro_wordpress_update_core_manual_about_failsafe() {
global $pagenow;
		
	// Check that Network POST values & pages are the same as a single site
	// The Form POST name value for both Update Now and Re-Install Now is: upgrade
	if ( 'update-core.php' == $pagenow && isset( $_POST['upgrade'] ) ) {		
		
		$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
		$timeNow = time();
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;
		$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);
		$fh = @fopen($bpsProLog, 'a');

		$blank_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/blank.txt';
		$arq_failsafe_file = WP_CONTENT_DIR . '/bps-backup/master-backups/arq-failsafe.txt';
		
		if ( copy($blank_file, $arq_failsafe_file) ) {
			@fwrite($fh, '[Internal Usage: ARQ FailSafe Function: ARQ FS File Copy: Successful | '.$timestamp."]\r\n");
		}
		@fclose($fh);
	}
}

// WordPress Manual Update FailSafe Message function:
function bpsPro_wordpress_update_core_manual_about_failsafe_message() {
global $pagenow;

	if ( 'update-core.php' == $pagenow || 'about.php' == $pagenow || 'theme-install.php' == $pagenow ) {
		return;
	}
		
	if ( isset ( $_POST['Submit-Setup-Wizard-Preinstallation'] ) && $_POST['Submit-Setup-Wizard-Preinstallation'] == true ) {
		return;
	}

	$arq_failsafe_file = WP_CONTENT_DIR . '/bps-backup/master-backups/arq-failsafe.txt';
	$ARQoptions = get_option('bulletproof_security_options_ARCM');
			
	if ( file_exists($arq_failsafe_file) ) {

		if ( $ARQoptions['bps_autorestore_cron_override'] != 'On' ) {
		
		echo '<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);">';
		$text = '<strong><font color="#fb0101">'.__('AutoRestore Automation Error', 'bulletproof-security').'</font><br>'.__('AutoRestore Automation failed to backup all WP Core files during the WordPress Upgrade. AutoRestore is currently turned Off to prevent new WP Core files from being quarantined. ', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/wizard/wizard.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the Setup Wizard page. Click the Pre-installation Wizard button and the Setup Wizard button to complete the WordPress Core file backup and to turn AutoRestore back On again.', 'bulletproof-security').'</strong>';
		echo $text;	
		echo '</div>';
		}

		if ( $ARQoptions['bps_autorestore_cron_override'] == 'On' ) {
		
		echo '<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);">';
		$text = '<strong><font color="blue">'.__('ARQ Cron Override is Turned On', 'bulletproof-security').'</font><br>'.__('This is just a reminder message. When the ARQ Cron Override option is turned On, AutoRestore is not automatically turned back On during WordPress, Theme and Plugin upgrades. ', 'bulletproof-security').'</font><br><a href="'.admin_url( 'admin.php?page=bulletproof-security/admin/wizard/wizard.php' ).'">'.__('Click Here', 'bulletproof-security').'</a>'.__(' to go to the Setup Wizard page. Click the Pre-installation Wizard button and the Setup Wizard button to clear/remove this reminder message and to clear/remove the AutoRestore is Off email notifications.', 'bulletproof-security').'</strong>';
		echo $text;	
		echo '</div>';
		}
	}		
}

// WP Updates page > WP Core Update > WP Core Re-Install > Works for all WP versions.
// There is an AJAX function for Manual WP Core Bulk Updates > bpsPro_ajax_arq_automation_wp_core_update()
// When the redirect occurs to the about.php page all website files are backed up. 
// AutoRestore - Backup files, turn AutoRestore back on, lock index.php & wp-blog-header.php if they were previously locked, clear php error log alert
// Do not display the ARQ upgrade message on the about.php page
function bpsPro_wordpress_update_core_manual_about() {
	
	if ( current_user_can( 'update_core' ) ) {
	
		global $pagenow, $wp_version;

		if ( 'about.php' == $pagenow ) {
		
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			$ARQ_upgrade = get_option('bulletproof_security_options_ARQ_upgrade');  
			$successTextBegin = '<font color="green"><strong>';
			$successTextEnd = '</strong></font><br>';
			$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
			$timeNow = time();
			$gmt_offset = get_option( 'gmt_offset' ) * 3600;
			$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);

			if ( $ARQoptions['bps_autorestore_cron'] == 'Off' ) {
			
				// If ARQ is Off & someone visits the about.php page then only continue ARQ processing if someone has performed a WP Core update/upgrade, otherwise do nothing. 
				// Add all relevent bps_arq_upgrade values
				// install_upgrade is for WP versions <= 4.5.3
				if ( $ARQ_upgrade['bps_arq_upgrade'] == 'install_upgrade' || $ARQ_upgrade['bps_arq_upgrade'] == 'wp_core_update' ) {
			
					set_time_limit(300);
					$fh = @fopen($bpsProLog, 'a');
				?>
			
					<style>
					<!--
					#message {display:none;}
					.wrap h2 {display:none;}
					#bps-container {display:none;}
					-->
					</style>

				<?php
					require_once ( WP_PLUGIN_DIR . '/bulletproof-security/admin/wizard/swizard-arq-functions.php' );
					
					$source = '';
					$dest = '';
					
					echo '<div style="display:none;">';
					bpsSetupWizard_ARQ_root_backup($source, $dest);
					bpsSetupWizard_ARQ_wpadmin_backup($source, $dest);
					bpsSetupWizard_ARQ_wpincludes_backup($source, $dest);
					bpsSetupWizard_ARQ_wpcontent_backup($source, $dest);	
					echo '</div>';
	
					$arq_failsafe_file = WP_CONTENT_DIR . '/bps-backup/master-backups/arq-failsafe.txt';
			
					if ( file_exists($arq_failsafe_file) && $ARQoptions['bps_autorestore_cron_override'] != 'On' ) {
						unlink($arq_failsafe_file);
					}

					@fwrite($fh, "[Internal Usage: WP Core Manual Update|Re-install function: Backup performed: $timestamp]\r\n");
						
					$FlockOptions = get_option('bulletproof_security_options_flock');
					$index = ABSPATH . 'index.php';
					$wpblogheader = ABSPATH . 'wp-blog-header.php';

					// Lock the index.php and wp-blog-header.php files if they were previously locked		
					$fl_override_options = get_option('bulletproof_security_options_flock_eol');
					
					if ( $fl_override_options['bps_file_lock_override'] == 'On' ) {

						if ( $FlockOptions['bps_lock_index_php'] == 'yes' ) {
							@chmod($index, 0400);
						}
						if ( $FlockOptions['bps_lock_wpblog_header'] == 'yes' ) {
							@chmod($wpblogheader, 0400);
						}		
					}
					
					// Sync php error log alert time
					$gmt_offset = get_option( 'gmt_offset' ) * 3600;
					$optionsElogLocation = get_option('bulletproof_security_options2');
					$Elogfile = $optionsElogLocation['bps_error_log_location'];
					$last_modified_time_file = date("F d Y H:i:s", filemtime($Elogfile) + $gmt_offset);
					$Elog_time_db = 'bulletproof_security_options_elog';
				
					$BPS_db_Elog = array( 'bps_error_log_date_mod' => $last_modified_time_file );	
				
					foreach ( $BPS_db_Elog as $key => $value ) {
						update_option('bulletproof_security_options_elog', $BPS_db_Elog);
					}

					// Turn ARQ back On if ARQ Cron Override is not set to On
					if ( $ARQoptions['bps_autorestore_cron_override'] != 'On' ) {
	
						$ARQoptions2 = ! $ARQoptions['bps_autorestore_cron_frequency'] ? '2' : $ARQoptions['bps_autorestore_cron_frequency'];
						$ARQoptions3 = ! $ARQoptions['bps_autorestore_cron_forced'] ? '1' : $ARQoptions['bps_autorestore_cron_forced'];
						$ARQoptions4 = ! $ARQoptions['bps_autorestore_cron_override'] ? 'Off' : $ARQoptions['bps_autorestore_cron_override'];
						$ARQoptions5 = ! $ARQoptions['bps_autorestore_cron_filecheck'] ? 'Off' : $ARQoptions['bps_autorestore_cron_filecheck'];
						$ARQoptions6 = ! $ARQoptions['bps_autorestore_cron_end'] ? '' : $ARQoptions['bps_autorestore_cron_end'];		
		
						$ARQ_Options = array(
						'bps_autorestore_cron' 				=> 'On', 
						'bps_autorestore_cron_frequency' 	=> $ARQoptions2, 
						'bps_autorestore_cron_forced' 		=> $ARQoptions3, 
						'bps_autorestore_cron_override' 	=> $ARQoptions4, 
						'bps_autorestore_cron_filecheck' 	=> $ARQoptions5, 
						'bps_autorestore_cron_end' 			=> $ARQoptions6
						);	

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

						@fwrite($fh, "[Internal Usage: WP Core Manual Update|Re-install function: ARQ Cron was turned On: $timestamp]\r\n");

						echo '<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);">';
						echo $successTextBegin.__('BPS Pro AutoRestore file backup completed successfully. AutoRestore has been turned back On.', 'bulletproof-security').$successTextEnd;
						echo '</div>';	
					}

					if ( $ARQoptions['bps_autorestore_cron_override'] == 'On' ) {		
						echo '<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);">';
						echo $successTextBegin.__('BPS Pro ARQ Cron Override is turned On.', 'bulletproof-security').$successTextEnd;
						echo '</div>';	
					}
		
					// Update BPS DB option so that the WordPress 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';	

					$WPver_Options = array( 
					'bps_wp_version' 					=> $wp_version, 
					'bps_wp_version_last_modified_time' => date("F d Y H:i", filemtime($versionphp) + $gmt_offset + 900) 
					);	
	
					foreach ( $WPver_Options as $key => $value ) {
						update_option('bulletproof_security_options_wp_version', $WPver_Options);
					}	

					// 12.6: changed this from '' blank to $ARQoptions['bps_autorestore_cron'] which is ARQ On or Off. Status should be On at this point.
					$ARQ_status_Options = array( 
					'bps_arq_status' 			=> $ARQoptions['bps_autorestore_cron'], 
					'bps_arq_status_timestamp' 	=> time() 
					);
	
					foreach( $ARQ_status_Options as $key => $value ) {
						update_option('bulletproof_security_options_ARQ_status', $ARQ_status_Options);
					}					

					@fclose($fh);
				}
			}
		}
	}
}

// AJAX Shiny Plugin Update & New Installation:
// IMPORTANT: On occaison AJAX Actions are not triggered. Clearing Google Chrome Browser cache fixes that problem. I may need to add additional code for that problem.
// Flow|Sequence: Update or Install Now button clicked > AJAX Action Function Triggered & ARQ Turned Off > upgrader_pre_install Filter Triggered - ARQ Turned Off FailSafe > 
// upgrader_post_install Filter Triggered - performs backup > AFS Cron FailSafe - Turns ARQ On. 
// Note: The AFS Cron does a /languages/ folder backup - language translation files are installed "late" "after the fact" after ARQ backup has already occurred.
// 12.8: Race condition added.
function bpsPro_ajax_arq_automation_plugin() {

	global $wp_version;
		
	if ( version_compare( $wp_version, '4.5.3', '<=' ) ) {
		// do nothing
	} else {
	
		if ( isset( $_POST['post_var'] ) && $_POST['post_var'] == 'arq_auto_plugin_shiny_update' || isset( $_POST['post_var'] ) && $_POST['post_var'] == 'arq_auto_plugin_shiny_install' ) {

			$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
			$timeNow = time();
			$gmt_offset = get_option( 'gmt_offset' ) * 3600;
			$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);
			$fh = @fopen($bpsProLog, 'a');
				
			if ( $_POST['post_var'] == 'arq_auto_plugin_shiny_update' ) {
				$BPS_arq_upgrade = array( 'bps_arq_upgrade' => 'arq_auto_plugin_shiny_update' );
				@fwrite($fh, "\r\n".'[Internal Usage: AJAX Shiny Plugin Update: post_var: arq_auto_plugin_shiny_update | '.$timestamp."]\r\n");
				@fwrite($fh, '[Internal Usage: AJAX Shiny Plugin Update: bps_arq_upgrade value: arq_auto_plugin_shiny_update | '.$timestamp."]\r\n");			
			
			} elseif ( $_POST['post_var'] == 'arq_auto_plugin_shiny_install' ) {
				$BPS_arq_upgrade = array( 'bps_arq_upgrade' => 'arq_auto_plugin_shiny_install' );
				@fwrite($fh, "\r\n".'[Internal Usage: AJAX Shiny Plugin Install: post_var: arq_auto_plugin_shiny_install | '.$timestamp."]\r\n");
				@fwrite($fh, '[Internal Usage: AJAX Shiny Plugin Install: bps_arq_upgrade value: arq_auto_plugin_shiny_install | '.$timestamp."]\r\n");
			}				
				
			foreach ( $BPS_arq_upgrade as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_upgrade', $BPS_arq_upgrade);
			}
			
			// The ARQ Status timestamp needs to be updated on every call, but not the ARQ Status value if the ARQ Status value == On already.
			// The reason for that is if plugins are updated in rapid succession then the ARQ Status will incorrectly be changed to Off.
			// Normal scenario: ARQ is turned On and ARQ Status value is blank. The ARQ Status value will be updated with ARQ Status == On.
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			$blank_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/blank.txt';
			$arq_failsafe_file = WP_CONTENT_DIR . '/bps-backup/master-backups/arq-failsafe.txt';
			
			if ( $ARQoptions['bps_autorestore_cron_override'] == 'On' ) {
				if ( copy($blank_file, $arq_failsafe_file) ) {
					@fwrite($fh, '[Internal Usage: ARQ Cron Override On: ARQ FS File Copy: Successful | '.$timestamp."]\r\n");
				}
			}

			if ( $ARQ_status['bps_arq_status'] == 'On' ) {
				$bps_arq_status = 'On';
			} else {
				$bps_arq_status = $ARQoptions['bps_autorestore_cron'];
			}
			
			$ARQ_status_Options = array( 
			'bps_arq_status' 			=> $bps_arq_status, 
			'bps_arq_status_timestamp' 	=> time() 
			);
			
			foreach( $ARQ_status_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_status', $ARQ_status_Options);
			}
			
			$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			
			if ( $ARQ_status['bps_arq_status'] == 'Off' ) {
				@fwrite($fh, '[Internal Usage: AJAX Shiny Plugin Update|Install: ARQ Cron will not be turned back On | '.$timestamp."]\r\n");
				@fwrite($fh, '[Internal Usage: AJAX Shiny Plugin Update|Install Reason: ARQ Cron was turned Off prior to update or installation | '.$timestamp."]\r\n");
			
			} else {
				@fwrite($fh, '[Internal Usage: AJAX Shiny Plugin Update|Install: Prior ARQ Cron Status: '.$ARQ_status['bps_arq_status'].' | '.$timestamp."]\r\n");
			}		

			$BPS_Options = array(
			'bps_autorestore_cron' 				=> 'Off', 
			'bps_autorestore_cron_frequency' 	=> $ARQoptions['bps_autorestore_cron_frequency'], 
			'bps_autorestore_cron_override' 	=> $ARQoptions['bps_autorestore_cron_override'], 
			'bps_autorestore_cron_filecheck' 	=> $ARQoptions['bps_autorestore_cron_filecheck'], 
			'bps_autorestore_cron_forced' 		=> $ARQoptions['bps_autorestore_cron_forced'], 
			'bps_autorestore_cron_end' 			=> $ARQoptions['bps_autorestore_cron_end'] 
			);	

			foreach ( $BPS_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARCM', $BPS_Options);
			}
		
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			@fwrite($fh, '[Internal Usage: AJAX Shiny Plugin Update|Install: ARQ Cron was turned '.$ARQoptions['bps_autorestore_cron'].' | '.$timestamp."]\r\n");
			@fclose($fh);
		}
	}
	wp_die();
}

add_action('wp_ajax_bps_arq_automation_plugin', 'bpsPro_ajax_arq_automation_plugin');

// AJAX Shiny Theme Update: Theme update on themes.php page by clicking the update now link on theme screenshots & other WP areas.
// Flow|Sequence: Update or Install Now button clicked > AJAX Action Function Triggered & ARQ Turned Off > upgrader_pre_install Filter Triggered - ARQ Turned Off FailSafe > 
// upgrader_post_install Filter Triggered - performs backup > AFS Cron FailSafe - Turns ARQ On.
// Note: The AFS Cron does a /languages/ folder backup - language translation files are installed "late" "after the fact" after ARQ backup has already occurred.
function bpsPro_ajax_arq_automation_theme() {

  	global $wp_version;
		
	if ( version_compare( $wp_version, '4.5.3', '<=' ) ) {
		// do nothing
	} else {

		if ( isset( $_POST['post_var'] ) && $_POST['post_var'] == 'arq_auto_theme_shiny_update' ) {

			$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
			$timeNow = time();
			$gmt_offset = get_option( 'gmt_offset' ) * 3600;
			$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);
			$fh = @fopen($bpsProLog, 'a');
			
			@fwrite($fh, "\r\n".'[Internal Usage: AJAX Shiny Theme Update|Install: post_var: arq_auto_theme_shiny_update | '.$timestamp."]\r\n");
			@fwrite($fh, '[Internal Usage: AJAX Shiny Theme Update|Install: bps_arq_upgrade value: arq_auto_theme_shiny_update | '.$timestamp."]\r\n");

			$BPS_arq_upgrade = array( 'bps_arq_upgrade' => 'arq_auto_theme_shiny_update' );	
	
			foreach ( $BPS_arq_upgrade as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_upgrade', $BPS_arq_upgrade);
			}

			@fwrite($fh, '[Internal Usage: AJAX Shiny Theme Update|Install: bps_arq_upgrade value: arq_auto_theme'.' | '.$timestamp."]\r\n");

			// The ARQ Status timestamp needs to be updated on every call, but not the ARQ Status value if the ARQ Status value == On already.
			// The reason for that is if themes are updated in rapid succession then the ARQ Status will incorrectly be changed to Off.
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			$blank_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/blank.txt';
			$arq_failsafe_file = WP_CONTENT_DIR . '/bps-backup/master-backups/arq-failsafe.txt';
			
			if ( $ARQoptions['bps_autorestore_cron_override'] == 'On' ) {
				if ( copy($blank_file, $arq_failsafe_file) ) {
					@fwrite($fh, '[Internal Usage: ARQ Cron Override On: ARQ FS File Copy: Successful | '.$timestamp."]\r\n");
				}
			}

			if ( $ARQ_status['bps_arq_status'] == 'On' ) {
				$bps_arq_status = 'On';
			} else {
				$bps_arq_status = $ARQoptions['bps_autorestore_cron'];
			}
			
			$ARQ_status_Options = array( 
			'bps_arq_status' 			=> $bps_arq_status, 
			'bps_arq_status_timestamp' 	=> time() 
			);
			
			foreach( $ARQ_status_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_status', $ARQ_status_Options);
			}

			$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			
			if ( $ARQ_status['bps_arq_status'] == 'Off' ) {
				@fwrite($fh, '[Internal Usage: AJAX Shiny Theme Update|Install: ARQ Cron will not be turned back On | '.$timestamp."]\r\n");
				@fwrite($fh, '[Internal Usage: AJAX Shiny Theme Update|Install Reason: ARQ Cron was turned Off prior to update or installation | '.$timestamp."]\r\n");
			
			} else {
				@fwrite($fh, '[Internal Usage: AJAX Shiny Theme Update|Install: Prior ARQ Cron Status: '.$ARQ_status['bps_arq_status'].' | '.$timestamp."]\r\n");
			}					
			
			$BPS_Options = array(
			'bps_autorestore_cron' 				=> 'Off', 
			'bps_autorestore_cron_frequency' 	=> $ARQoptions['bps_autorestore_cron_frequency'], 
			'bps_autorestore_cron_override' 	=> $ARQoptions['bps_autorestore_cron_override'], 
			'bps_autorestore_cron_filecheck' 	=> $ARQoptions['bps_autorestore_cron_filecheck'], 
			'bps_autorestore_cron_forced' 		=> $ARQoptions['bps_autorestore_cron_forced'], 
			'bps_autorestore_cron_end' 			=> $ARQoptions['bps_autorestore_cron_end'] 
			);	

			foreach ( $BPS_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARCM', $BPS_Options);
			}
		
			// Get new updated ARQ Cron DB option values
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			@fwrite($fh, '[Internal Usage: AJAX Shiny Theme Update|Install: ARQ Cron was turned '.$ARQoptions['bps_autorestore_cron'].' | '.$timestamp."]\r\n");
			@fclose($fh);
		}
	}
	wp_die();
}

add_action('wp_ajax_bps_arq_automation_theme', 'bpsPro_ajax_arq_automation_theme');

// AJAX Bulk Theme Update and New Theme Install: WP Updates page > Bulk Update Themes & Themes Add New|Add Themes page: theme-install.php
// Flow|Sequence: Update Themes or Add New button clicked > AJAX Action Function Triggered & ARQ Turned Off > upgrader_pre_install Filter Triggered - ARQ Turned Off FailSafe > 
// upgrader_post_install Filter Triggered - performs backup > AFS Cron FailSafe - Turns ARQ On.
// Note: The AFS Cron does a /languages/ folder backup - language translation files are installed "late" "after the fact" after ARQ backup has already occurred.
function bpsPro_ajax_arq_automation_bulk_update_theme() {

	global $wp_version;
		
	if ( version_compare( $wp_version, '4.5.3', '<=' ) ) {
		// do nothing
	} else {

		if ( isset( $_POST['post_var'] ) && $_POST['post_var'] == 'arq_auto_bulk_update_theme' || isset( $_POST['post_var'] ) && $_POST['post_var'] == 'arq_auto_bulk_update_theme_install' ) {

			$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
			$timeNow = time();
			$gmt_offset = get_option( 'gmt_offset' ) * 3600;
			$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);
			$fh = @fopen($bpsProLog, 'a');
				
			if ( $_POST['post_var'] == 'arq_auto_bulk_update_theme' ) {
				$BPS_arq_upgrade = array( 'bps_arq_upgrade' => 'bulk_update_themes' );
				@fwrite($fh, "\r\n".'[Internal Usage: AJAX Bulk Theme Update: post_var: arq_auto_bulk_update_theme | '.$timestamp."]\r\n");
				@fwrite($fh, '[Internal Usage: AJAX Bulk Theme Update: bps_arq_upgrade value: bulk_update_themes | '.$timestamp."]\r\n");			
			
			} elseif ( $_POST['post_var'] == 'arq_auto_bulk_update_theme_install' ) {
				$BPS_arq_upgrade = array( 'bps_arq_upgrade' => 'install_themes' );
				@fwrite($fh, "\r\n".'[Internal Usage: AJAX Theme New Install: post_var: arq_auto_bulk_update_theme_install | '.$timestamp."]\r\n");
				@fwrite($fh, '[Internal Usage: AJAX Theme New Install: bps_arq_upgrade value: install_themes | '.$timestamp."]\r\n");
			}
	
			foreach ( $BPS_arq_upgrade as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_upgrade', $BPS_arq_upgrade);
			}	
	
			// The ARQ Status timestamp needs to be updated on every call, but not the ARQ Status value if the ARQ Status value == On already.
			// The reason for that is if themes are updated in rapid succession then the ARQ Status will incorrectly be changed to Off.
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			$blank_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/blank.txt';
			$arq_failsafe_file = WP_CONTENT_DIR . '/bps-backup/master-backups/arq-failsafe.txt';
			
			if ( $ARQoptions['bps_autorestore_cron_override'] == 'On' ) {
				if ( copy($blank_file, $arq_failsafe_file) ) {
					@fwrite($fh, '[Internal Usage: ARQ Cron Override On: ARQ FS File Copy: Successful | '.$timestamp."]\r\n");
				}
			}			

			if ( $ARQ_status['bps_arq_status'] == 'On' ) {
				$bps_arq_status = 'On';
			} else {
				$bps_arq_status = $ARQoptions['bps_autorestore_cron'];
			}
			
			$ARQ_status_Options = array( 
			'bps_arq_status' 			=> $bps_arq_status, 
			'bps_arq_status_timestamp' 	=> time() 
			);
			
			foreach( $ARQ_status_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_status', $ARQ_status_Options);
			}

			$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			
			if ( $ARQ_status['bps_arq_status'] == 'Off' ) {
				@fwrite($fh, '[Internal Usage: AJAX Bulk Theme Update|New Install: ARQ Cron will not be turned back On | '.$timestamp."]\r\n");
				@fwrite($fh, '[Internal Usage: AJAX Bulk Theme Update|New Install Reason: ARQ Cron was turned Off prior to update or installation | '.$timestamp."]\r\n");
			
			} else {
				@fwrite($fh, '[Internal Usage: AJAX Bulk Theme Update|New Install: Prior ARQ Cron Status: '.$ARQ_status['bps_arq_status'].' | '.$timestamp."]\r\n");
			}
			
			$BPS_Options = array(
			'bps_autorestore_cron' 				=> 'Off', 
			'bps_autorestore_cron_frequency' 	=> $ARQoptions['bps_autorestore_cron_frequency'], 
			'bps_autorestore_cron_override' 	=> $ARQoptions['bps_autorestore_cron_override'], 
			'bps_autorestore_cron_filecheck' 	=> $ARQoptions['bps_autorestore_cron_filecheck'], 
			'bps_autorestore_cron_forced' 		=> $ARQoptions['bps_autorestore_cron_forced'], 
			'bps_autorestore_cron_end' 			=> $ARQoptions['bps_autorestore_cron_end'] 
			);	

			foreach ( $BPS_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARCM', $BPS_Options);
			}
					
			// Get new updated ARQ Cron DB option values
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			@fwrite($fh, '[Internal Usage: AJAX Bulk Theme Update|New Install: ARQ Cron was turned '.$ARQoptions['bps_autorestore_cron'].' | '.$timestamp."]\r\n");
			@fclose($fh);
		}
	}
	wp_die();
}

add_action('wp_ajax_bps_arq_automation_bulk_update_theme', 'bpsPro_ajax_arq_automation_bulk_update_theme');

// AJAX Bulk Plugin Update: WP Updates page > Bulk Update Plugins & WP Plugins page > Bulk Actions form > Apply button
// Flow|Sequence: Update Plugins or Apply button clicked > AJAX Action Function Triggered & ARQ Turned Off > upgrader_pre_install Filter Triggered - ARQ Turned Off FailSafe > 
// upgrader_post_install Filter Triggered - performs backup > AFS Cron FailSafe - Turns ARQ On.
// Note: The AFS Cron does a /languages/ folder backup - language translation files are installed "late" "after the fact" after ARQ backup has already occurred.
function bpsPro_ajax_arq_automation_bulk_update_plugin() {

	global $wp_version;
		
	if ( version_compare( $wp_version, '4.5.3', '<=' ) ) {
		// do nothing
	} else {

  		if ( isset( $_POST['post_var'] ) && $_POST['post_var'] == 'arq_auto_bulk_update_plugin' ) {

			$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
			$timeNow = time();
			$gmt_offset = get_option( 'gmt_offset' ) * 3600;
			$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);
			$fh = @fopen($bpsProLog, 'a');
			@fwrite($fh, "\r\n".'[Internal Usage: AJAX Bulk Plugin Update: post_var: arq_auto_bulk_update_plugin | '.$timestamp."]\r\n");	
			
			$BPS_arq_upgrade = array( 'bps_arq_upgrade' => 'bulk_update_plugins' );	
	
			foreach ( $BPS_arq_upgrade as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_upgrade', $BPS_arq_upgrade);
			}

			@fwrite($fh, '[Internal Usage: AJAX Bulk Plugin Update: bps_arq_upgrade value: bulk_update_plugins'.' | '.$timestamp."]\r\n");			
			
			// The ARQ Status timestamp needs to be updated on every call, but not the ARQ Status value if the ARQ Status value == On already.
			// The reason for that is if plugins are updated in rapid succession then the ARQ Status will incorrectly be changed to Off.
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			$blank_file = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/blank.txt';
			$arq_failsafe_file = WP_CONTENT_DIR . '/bps-backup/master-backups/arq-failsafe.txt';
			
			if ( $ARQoptions['bps_autorestore_cron_override'] == 'On' ) {
				if ( copy($blank_file, $arq_failsafe_file) ) {
					@fwrite($fh, '[Internal Usage: ARQ Cron Override On: ARQ FS File Copy: Successful | '.$timestamp."]\r\n");
				}
			}			

			if ( $ARQ_status['bps_arq_status'] == 'On' ) {
				$bps_arq_status = 'On';
			} else {
				$bps_arq_status = $ARQoptions['bps_autorestore_cron'];
			}
			
			$ARQ_status_Options = array( 
			'bps_arq_status' 			=> $bps_arq_status, 
			'bps_arq_status_timestamp' 	=> time() 
			);
			
			foreach( $ARQ_status_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_status', $ARQ_status_Options);
			}

			$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			
			if ( $ARQ_status['bps_arq_status'] == 'Off' ) {
				@fwrite($fh, '[Internal Usage: AJAX Bulk Plugin Update: ARQ Cron will not be turned back On | '.$timestamp."]\r\n");
				@fwrite($fh, '[Internal Usage: AJAX Bulk Plugin Update Reason: ARQ Cron was turned Off prior to update or installation | '.$timestamp."]\r\n");
			
			} else {
				@fwrite($fh, '[Internal Usage: AJAX Bulk Plugin Update: Prior ARQ Cron Status: '.$ARQ_status['bps_arq_status'].' | '.$timestamp."]\r\n");
			}			

			$ARQ_wpcontent_folder_exclude_options = get_option('bulletproof_security_options_exclude_folder');
		
			$BPS_Options = array(
			'bps_autorestore_cron' 				=> 'Off', 
			'bps_autorestore_cron_frequency' 	=> $ARQoptions['bps_autorestore_cron_frequency'], 
			'bps_autorestore_cron_override' 	=> $ARQoptions['bps_autorestore_cron_override'], 
			'bps_autorestore_cron_filecheck' 	=> $ARQoptions['bps_autorestore_cron_filecheck'], 
			'bps_autorestore_cron_forced' 		=> $ARQoptions['bps_autorestore_cron_forced'], 
			'bps_autorestore_cron_end' 			=> $ARQoptions['bps_autorestore_cron_end'] 
			);	

			foreach ( $BPS_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARCM', $BPS_Options);
			}
		
			// Get new updated ARQ Cron DB option values
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			@fwrite($fh, '[Internal Usage: AJAX Bulk Plugin Update: ARQ Cron was turned '.$ARQoptions['bps_autorestore_cron'].' | '.$timestamp."]\r\n");
			@fclose($fh);
		}
	}
	wp_die();
}

add_action('wp_ajax_bps_arq_automation_bulk_update_plugin', 'bpsPro_ajax_arq_automation_bulk_update_plugin');

// ARQ Automation Manual WP Update or Re-Install for WP version 4.6+
// WP Updates page > WP Core Update > WP Core Re-Install
// Note: WP Core Updates do not use the pre and post upgrader filter functions and instead use the about page redirect function: bpsPro_wordpress_update_core_manual_about()
// If WP Core is changed to Shiny Updates in the future then this Flow|Sequence will probably need to be changed.
function bpsPro_ajax_arq_automation_wp_core_update() {

	global $wp_version;
		
	if ( version_compare( $wp_version, '4.5.3', '<=' ) ) {
		// do nothing
	} else {

  		if ( isset( $_POST['post_var'] ) && $_POST['post_var'] == 'arq_auto_wp_core' ) {

			$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
			$timeNow = time();
			$gmt_offset = get_option( 'gmt_offset' ) * 3600;
			$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);
			$fh = @fopen($bpsProLog, 'a');
			
			$BPS_arq_upgrade = array( 'bps_arq_upgrade' => 'wp_core_update' );
			
			foreach ( $BPS_arq_upgrade as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_upgrade', $BPS_arq_upgrade);
			}
			
			@fwrite($fh, "\r\n".'[Internal Usage: AJAX Manual WP Core Update: post_var: arq_auto_wp_core | '.$timestamp."]\r\n");			
			@fwrite($fh, '[Internal Usage: AJAX Manual WP Core Update: bps_arq_upgrade value: wp_core_update | '.$timestamp."]\r\n");	

			$ARQoptions = get_option('bulletproof_security_options_ARCM');
		
			$ARQ_status_Options = array( 
			'bps_arq_status' 			=> $ARQoptions['bps_autorestore_cron'], 
			'bps_arq_status_timestamp' 	=> time() 
			);
			
			foreach( $ARQ_status_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARQ_status', $ARQ_status_Options);
			}

			$ARQ_status = get_option('bulletproof_security_options_ARQ_status');
			
			if ( $ARQ_status['bps_arq_status'] == 'Off' ) {
				@fwrite($fh, '[Internal Usage: AJAX Manual WP Core Update: ARQ Cron will not be turned back On | '.$timestamp."]\r\n");
				@fwrite($fh, '[Internal Usage: AJAX Manual WP Core Update Reason: ARQ Cron was turned Off prior to update or installation | '.$timestamp."]\r\n");
			
			} else {
				@fwrite($fh, '[Internal Usage: AJAX Manual WP Core Update: Prior ARQ Cron Status: '.$ARQ_status['bps_arq_status'].' | '.$timestamp."]\r\n");
			}

			$BPS_Options = array(
			'bps_autorestore_cron' 				=> 'Off', 
			'bps_autorestore_cron_frequency' 	=> $ARQoptions['bps_autorestore_cron_frequency'], 
			'bps_autorestore_cron_override' 	=> $ARQoptions['bps_autorestore_cron_override'], 
			'bps_autorestore_cron_filecheck' 	=> $ARQoptions['bps_autorestore_cron_filecheck'], 
			'bps_autorestore_cron_forced' 		=> $ARQoptions['bps_autorestore_cron_forced'], 
			'bps_autorestore_cron_end' 			=> $ARQoptions['bps_autorestore_cron_end'] 
			);	

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

			// Get new updated ARQ Cron DB option values
			if ( $ARQ_status['bps_arq_status'] != 'Off' ) {
				$ARQoptions = get_option('bulletproof_security_options_ARCM');
				@fwrite($fh, '[Internal Usage: AJAX Manual WP Core Update: ARQ Cron was turned '.$ARQoptions['bps_autorestore_cron'].' | '.$timestamp."]\r\n");
			}
			@fclose($fh);
		}
	}
	wp_die();
}

add_action('wp_ajax_bps_arq_automation_wp_core_update', 'bpsPro_ajax_arq_automation_wp_core_update');

// Theme Editor: Themes > Theme Editor > Update File button. 
// This is a self contained function. ARQ is turned Off (if it is On), wp-content files are backed up and ARQ is turned back On (if it was On).
function bpsPro_ajax_arq_automation_theme_editor() {

	if ( isset( $_POST['post_var'] ) && $_POST['post_var'] == 'arq_auto_theme_editor' ) {

		require_once ( WP_PLUGIN_DIR . '/bulletproof-security/admin/wizard/swizard-arq-functions.php' );
		
		$bpsProLog = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt';
		$timeNow = time();
		$gmt_offset = get_option( 'gmt_offset' ) * 3600;
		$timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' - ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset);
		$source = '';
		$dest = '';
		$fh = @fopen($bpsProLog, 'a');
		
		@fwrite($fh, "\r\n".'[Internal Usage: AJAX Theme Editor File Backup: post_var: arq_auto_theme_editor | '.$timestamp."]\r\n");			

		$ARQoptions = get_option('bulletproof_security_options_ARCM');
	
		if ( $ARQoptions['bps_autorestore_cron'] == 'Off' ) {
		
			echo '<div style="display:none;">';
			bpsSetupWizard_ARQ_wpcontent_backup($source, $dest);	
			echo '</div>';			
			
			@fwrite($fh, '[Internal Usage: AJAX Theme Editor File Backup: wp-content folder backup completed | '.$timestamp."]\r\n");		

		} else {
		
			$BPS_Options = array(
			'bps_autorestore_cron' 				=> 'Off', 
			'bps_autorestore_cron_frequency' 	=> $ARQoptions['bps_autorestore_cron_frequency'], 
			'bps_autorestore_cron_override' 	=> $ARQoptions['bps_autorestore_cron_override'], 
			'bps_autorestore_cron_filecheck' 	=> $ARQoptions['bps_autorestore_cron_filecheck'], 
			'bps_autorestore_cron_forced' 		=> $ARQoptions['bps_autorestore_cron_forced'], 
			'bps_autorestore_cron_end' 			=> $ARQoptions['bps_autorestore_cron_end'] 
			);	
	
			foreach ( $BPS_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARCM', $BPS_Options);
			}		
		
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			@fwrite($fh, '[Internal Usage: AJAX Theme Editor File Backup: ARQ Cron was turned '.$ARQoptions['bps_autorestore_cron'].' | '.$timestamp."]\r\n");

			echo '<div style="display:none;">';
			bpsSetupWizard_ARQ_wpcontent_backup($source, $dest);	
			echo '</div>';

			@fwrite($fh, '[Internal Usage: AJAX Theme Editor File Backup: wp-content folder backup completed | '.$timestamp."]\r\n");

			$BPS_Options = array(
			'bps_autorestore_cron' 				=> 'On', 
			'bps_autorestore_cron_frequency' 	=> $ARQoptions['bps_autorestore_cron_frequency'], 
			'bps_autorestore_cron_override' 	=> $ARQoptions['bps_autorestore_cron_override'], 
			'bps_autorestore_cron_filecheck' 	=> $ARQoptions['bps_autorestore_cron_filecheck'], 
			'bps_autorestore_cron_forced' 		=> $ARQoptions['bps_autorestore_cron_forced'], 
			'bps_autorestore_cron_end' 			=> $ARQoptions['bps_autorestore_cron_end'] 
			);	
	
			foreach ( $BPS_Options as $key => $value ) {
				update_option('bulletproof_security_options_ARCM', $BPS_Options);
			}
		
			$ARQoptions = get_option('bulletproof_security_options_ARCM');
			@fwrite($fh, '[Internal Usage: AJAX Theme Editor File Backup: ARQ Cron was turned '.$ARQoptions['bps_autorestore_cron'].' | '.$timestamp."]\r\n");		
		}

		@fclose($fh);
	}
	wp_die();
}

add_action('wp_ajax_bps_arq_automation_theme_editor', 'bpsPro_ajax_arq_automation_theme_editor');

?>