| @@ -1,109 +1,111 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Anonimization code |
| 4 | -add_filter( 'wpdbbkp_process_db_fields','bkpforwp_anonimize_database',10,3); | |
| 4 | +add_filter('wpdbbkp_process_db_fields', 'bkpforwp_anonimize_database', 10, 3); | |
| 5 | 5 | |
| 6 | -function bkpforwp_anonimize_database($value,$table,$column){ | |
| 7 | - $enable_anonymization = get_option('bkpforwp_enable_anonymization',false); | |
| 8 | - $anonymization_type = get_option('bkpforwp_anonymization_type',false); | |
| 9 | - $enable_backup_encryption = get_option('bkpforwp_enable_backup_encryption',false); | |
| 10 | - $anonymization_pass = get_option('bkpforwp_anonymization_pass',''); | |
| 6 | +function bkpforwp_anonimize_database($value, $table, $column) | |
| 7 | +{ | |
| 8 | + $enable_anonymization = get_option('bkpforwp_enable_anonymization', false); | |
| 9 | + $anonymization_type = get_option('bkpforwp_anonymization_type', false); | |
| 10 | + $enable_backup_encryption = get_option('bkpforwp_enable_backup_encryption', false); | |
| 11 | + $anonymization_pass = get_option('bkpforwp_anonymization_pass', ''); | |
| 11 | 12 | |
| 12 | 13 | |
| 13 | - if(isset($enable_anonymization) && $enable_anonymization==1){ | |
| 14 | - global $wpdb; | |
| 15 | - $bkpforwp_process_table = array($wpdb->prefix.'options',$wpdb->prefix.'users',$wpdb->prefix.'usermeta',$wpdb->prefix.'wc_customer_lookup',$wpdb->prefix.'edd_customers',$wpdb->prefix.'edd_customermeta'); | |
| 16 | - $bkpforwp_process_cols = array('mailserver_pass','mailserver_login','user_email','email','user_url','nickname','name','twitter','facebook','instagram','phone','mobile','address','city','zip','pincode','user_login','postcode','state','user_ip','ip_address'); | |
| 14 | + if (isset($enable_anonymization) && $enable_anonymization == 1) { | |
| 15 | + global $wpdb; | |
| 16 | + $bkpforwp_process_table = array($wpdb->prefix . 'options', $wpdb->prefix . 'users', $wpdb->prefix . 'usermeta', $wpdb->prefix . 'wc_customer_lookup', $wpdb->prefix . 'edd_customers', $wpdb->prefix . 'edd_customermeta'); | |
| 17 | + $bkpforwp_process_cols = array('mailserver_pass', 'mailserver_login', 'user_email', 'email', 'user_url', 'nickname', 'name', 'twitter', 'facebook', 'instagram', 'phone', 'mobile', 'address', 'city', 'zip', 'pincode', 'user_login', 'postcode', 'state', 'user_ip', 'ip_address'); | |
| 17 | 18 | |
| 18 | - //Masking Logic | |
| 19 | - if(isset($anonymization_type) && $anonymization_type =='masked_data'){ | |
| 20 | - if(in_array($table,$bkpforwp_process_table)){ | |
| 21 | - $check_str= implode(',',$bkpforwp_process_cols); | |
| 22 | - if(stripos($check_str,$column)!==false){ | |
| 23 | - return str_replace($value,str_repeat('*',strlen($value)),$value); | |
| 24 | - } | |
| 25 | - } | |
| 19 | + //Masking Logic | |
| 20 | + if (isset($anonymization_type) && $anonymization_type == 'masked_data') { | |
| 21 | + if (in_array($table, $bkpforwp_process_table)) { | |
| 22 | + $check_str = implode(',', $bkpforwp_process_cols); | |
| 23 | + if (stripos($check_str, $column) !== false) { | |
| 24 | + return str_replace($value, str_repeat('*', strlen($value)), $value); | |
| 26 | 25 | } |
| 27 | - //FakeData Logic | |
| 26 | + } | |
| 27 | + } | |
| 28 | + //FakeData Logic | |
| 28 | 29 | |
| 29 | - if(isset($anonymization_type) && $anonymization_type=='fake_data'){ | |
| 30 | - if(function_exists('wp_privacy_anonymize_data')){ | |
| 31 | - $bkpforwp_process_email = implode(',',array('email','user_email')); | |
| 32 | - $bkpforwp_process_url = implode(',',array('url','user_url','twitter','facebook','instagram')); | |
| 33 | - $bkpforwp_process_ip = implode(',',array('user_ip','ip_address')); | |
| 34 | - $bkpforwp_process_text = implode(',',array('nickname','name','address','phone','mobile','city','zip','pincode','user_login','postcode','state')); | |
| 30 | + if (isset($anonymization_type) && $anonymization_type == 'fake_data') { | |
| 31 | + if (function_exists('wp_privacy_anonymize_data')) { | |
| 32 | + $bkpforwp_process_email = implode(',', array('email', 'user_email')); | |
| 33 | + $bkpforwp_process_url = implode(',', array('url', 'user_url', 'twitter', 'facebook', 'instagram')); | |
| 34 | + $bkpforwp_process_ip = implode(',', array('user_ip', 'ip_address')); | |
| 35 | + $bkpforwp_process_text = implode(',', array('nickname', 'name', 'address', 'phone', 'mobile', 'city', 'zip', 'pincode', 'user_login', 'postcode', 'state')); | |
| 35 | 36 | |
| 36 | - if(in_array($table,$bkpforwp_process_table)){ | |
| 37 | + if (in_array($table, $bkpforwp_process_table)) { | |
| 37 | 38 | |
| 38 | - //For email | |
| 39 | - if(stripos($bkpforwp_process_email,$column)!==false){ | |
| 40 | - return str_replace($value,wp_privacy_anonymize_data('email',$value),$value); | |
| 41 | - } | |
| 39 | + //For email | |
| 40 | + if (stripos($bkpforwp_process_email, $column) !== false) { | |
| 41 | + return str_replace($value, wp_privacy_anonymize_data('email', $value), $value); | |
| 42 | + } | |
| 42 | 43 | |
| 43 | - if(stripos($bkpforwp_process_url,$column)!==false){ | |
| 44 | - return str_replace($value,wp_privacy_anonymize_data('url',$value),$value); | |
| 45 | - } | |
| 44 | + if (stripos($bkpforwp_process_url, $column) !== false) { | |
| 45 | + return str_replace($value, wp_privacy_anonymize_data('url', $value), $value); | |
| 46 | + } | |
| 46 | 47 | |
| 47 | - if(stripos($bkpforwp_process_ip,$column)!==false){ | |
| 48 | - return str_replace($value,wp_privacy_anonymize_data('ip',$value),$value); | |
| 49 | - } | |
| 48 | + if (stripos($bkpforwp_process_ip, $column) !== false) { | |
| 49 | + return str_replace($value, wp_privacy_anonymize_data('ip', $value), $value); | |
| 50 | + } | |
| 50 | 51 | |
| 51 | - if(stripos($bkpforwp_process_text,$column)!==false){ | |
| 52 | - return str_replace($value,wp_privacy_anonymize_data('text',$value),$value); | |
| 53 | - } | |
| 52 | + if (stripos($bkpforwp_process_text, $column) !== false) { | |
| 53 | + return str_replace($value, wp_privacy_anonymize_data('text', $value), $value); | |
| 54 | + } | |
| 54 | 55 | |
| 55 | - } | |
| 56 | + } | |
| 56 | 57 | |
| 57 | - return $value; | |
| 58 | - | |
| 59 | - } | |
| 60 | - else{ | |
| 61 | - if(in_array($table,$bkpforwp_process_table)){ | |
| 62 | - $check_str= implode(',',$bkpforwp_process_cols); | |
| 63 | - if(stripos($check_str,$column)!==false){ | |
| 64 | - return str_replace($value,str_repeat('*',strlen($value)),$value); | |
| 65 | - } | |
| 66 | - } | |
| 67 | - } | |
| 58 | + return $value; | |
| 68 | 59 | |
| 60 | + } else { | |
| 61 | + if (in_array($table, $bkpforwp_process_table)) { | |
| 62 | + $check_str = implode(',', $bkpforwp_process_cols); | |
| 63 | + if (stripos($check_str, $column) !== false) { | |
| 64 | + return str_replace($value, str_repeat('*', strlen($value)), $value); | |
| 65 | + } | |
| 69 | 66 | } |
| 67 | + } | |
| 70 | 68 | |
| 71 | - if(isset($anonymization_type) && $anonymization_type=='encrypted_data' && !empty($anonymization_pass)){ | |
| 72 | - require_once 'class-symmetric-encryption.php'; | |
| 73 | - | |
| 74 | - if(in_array($table,$bkpforwp_process_table)){ | |
| 75 | - $check_str= implode(',',$bkpforwp_process_cols); | |
| 76 | - if(stripos($check_str,$column)!==false){ | |
| 77 | - $enc_pass = $anonymization_pass; | |
| 78 | - $encryption = new SymmetricEncryption(); | |
| 79 | - return str_replace($value,'<==>'.$encryption->encrypt($value,$enc_pass,$enc_pass).'<==>',$value); | |
| 80 | - } | |
| 69 | + } | |
| 81 | 70 | |
| 82 | - } | |
| 71 | + if (isset($anonymization_type) && $anonymization_type == 'encrypted_data' && !empty($anonymization_pass)) { | |
| 72 | + require_once 'class-symmetric-encryption.php'; | |
| 83 | 73 | |
| 74 | + if (in_array($table, $bkpforwp_process_table)) { | |
| 75 | + $check_str = implode(',', $bkpforwp_process_cols); | |
| 76 | + if (stripos($check_str, $column) !== false) { | |
| 77 | + $enc_pass = $anonymization_pass; | |
| 78 | + $encryption = new SymmetricEncryption(); | |
| 79 | + return str_replace($value, '<==>' . $encryption->encrypt($value, $enc_pass, $enc_pass) . '<==>', $value); | |
| 84 | 80 | } |
| 85 | 81 | |
| 86 | - } | |
| 87 | - return $value; | |
| 82 | + } | |
| 83 | + | |
| 84 | + } | |
| 85 | + | |
| 86 | + } | |
| 87 | + return $value; | |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | -add_filter('wpdbbkp_sql_query_restore','bkpforwp_sql_query_restore',1); | |
| 91 | -function bkpforwp_sql_query_restore($sql_query){ | |
| 92 | - $anonymization_type = get_option('bkpforwp_anonymization_type',false); | |
| 93 | - $anonymization_pass = get_option('bkpforwp_anonymization_pass',''); | |
| 94 | - if(isset($anonymization_type) && $anonymization_type=='encrypted_data' && !empty($anonymization_pass)){ | |
| 90 | +add_filter('wpdbbkp_sql_query_restore', 'bkpforwp_sql_query_restore', 1); | |
| 91 | +function bkpforwp_sql_query_restore($sql_query) | |
| 92 | +{ | |
| 93 | + $anonymization_type = get_option('bkpforwp_anonymization_type', false); | |
| 94 | + $anonymization_pass = get_option('bkpforwp_anonymization_pass', ''); | |
| 95 | + if (isset($anonymization_type) && $anonymization_type == 'encrypted_data' && !empty($anonymization_pass)) { | |
| 95 | 96 | |
| 96 | 97 | $pattern = '/<==>(.*?)<==>/i'; |
| 97 | - return preg_replace_callback($pattern, 'bkpforwp_sql_restore_replace', $sql_query); | |
| 98 | + return preg_replace_callback($pattern, 'bkpforwp_sql_restore_replace', $sql_query); | |
| 98 | 99 | } |
| 99 | 100 | return $sql_query; |
| 100 | 101 | } |
| 101 | 102 | |
| 102 | -function bkpforwp_sql_restore_replace($matches){ | |
| 103 | - $anonymization_pass = get_option('bkpforwp_anonymization_pass',''); | |
| 104 | - $enc_pass = isset($anonymization_pass)?$anonymization_pass:false; | |
| 105 | - if($enc_pass){ | |
| 103 | +function bkpforwp_sql_restore_replace($matches) | |
| 104 | +{ | |
| 105 | + $anonymization_pass = get_option('bkpforwp_anonymization_pass', ''); | |
| 106 | + $enc_pass = isset($anonymization_pass) ? $anonymization_pass : false; | |
| 107 | + if ($enc_pass) { | |
| 106 | 108 | require_once 'class-symmetric-encryption.php'; |
| 107 | 109 | $encryption = new SymmetricEncryption(); |
| 108 | 110 | return $encryption->decrypt($matches[0], $enc_pass, $enc_pass); |
| 109 | 111 | } |
| @@ -109,121 +111,178 @@ | ||
| 109 | 111 | } |
| 110 | 112 | return $matches[0]; |
| 111 | 113 | } |
| 112 | 114 | |
| 113 | -add_action('wpdbbkp_database_backup_options','bkpforwp_database_backup_options'); | |
| 114 | -function bkpforwp_database_backup_options(){ | |
| 115 | - $settings = get_option( 'wp_db_backup_options' ); | |
| 116 | - $autobackup_days = isset($settings['autobackup_days'])?implode(',',$settings['autobackup_days']):','; | |
| 117 | - $autobackup_time = isset($settings['autobackup_time'])?$settings['autobackup_time']:''; | |
| 118 | - $autobackup_date = isset($settings['autobackup_date'])?$settings['autobackup_date']:''; | |
| 119 | -?> | |
| 115 | +add_action('wpdbbkp_database_backup_options', 'bkpforwp_database_backup_options'); | |
| 116 | +function bkpforwp_database_backup_options() | |
| 117 | +{ | |
| 118 | + $settings = get_option('wp_db_backup_options'); | |
| 119 | + $autobackup_days = isset($settings['autobackup_days']) ? implode(',', $settings['autobackup_days']) : ','; | |
| 120 | + $autobackup_time = isset($settings['autobackup_time']) ? $settings['autobackup_time'] : ''; | |
| 121 | + $autobackup_date = isset($settings['autobackup_date']) ? $settings['autobackup_date'] : ''; | |
| 122 | + ?> | |
| 120 | 123 | |
| 121 | 124 | |
| 122 | -<div class="row form-group autobackup_frequency_pro" style="display:none"><label class="col-sm-12 autobackup_daily_pro" >We will automatically backup at 00:00 AM daily. <b><a href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div> | |
| 123 | -<div class="row form-group autobackup_frequency_pro" style="display:none"><label class="col-sm-12 autobackup_weekly_pro" >We will automatically backup every Sunday on weekly basis. <b><a href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div> | |
| 124 | -<div class="row form-group autobackup_frequency_pro" style="display:none"><label class="col-sm-12 autobackup_monthly_pro" >We will automatically backup on 1st on Monday on monthly basis. <b><a href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div> | |
| 125 | - | |
| 125 | + <div class="row form-group autobackup_frequency_pro" style="display:none"><label | |
| 126 | + class="col-sm-12 autobackup_daily_pro">We will automatically backup at 00:00 AM daily. <b><a | |
| 127 | + href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div> | |
| 128 | + <div class="row form-group autobackup_frequency_pro" style="display:none"><label | |
| 129 | + class="col-sm-12 autobackup_weekly_pro">We will automatically backup every Sunday on weekly basis. <b><a | |
| 130 | + href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div> | |
| 131 | + <div class="row form-group autobackup_frequency_pro" style="display:none"><label | |
| 132 | + class="col-sm-12 autobackup_monthly_pro">We will automatically backup on 1st on Monday on monthly basis. <b><a | |
| 133 | + href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div> | |
| 126 | 134 | |
| 127 | -<div class="row form-group autobackup_days database_autobackup" style="display:none"> | |
| 128 | - <label class="col-sm-3" for="autobackup_days"><?php esc_html_e('Database Backup Days','backupforwp-pro');?></label> | |
| 129 | - <div class="col-sm-9"> | |
| 130 | - <select id="autobackup_days" class="form-control bkpforwp_multiselect" name="wp_db_backup_options[autobackup_days][]" multiple> | |
| 131 | - <option value="Mon" <?php if(strpos($autobackup_days,'Mon')!==false){ echo 'selected';} ?> ><?php esc_html_e('Monday','backupforwp-pro');?></option> | |
| 132 | - <option value="Tue" <?php if(strpos($autobackup_days,'Tue')!==false){ echo 'selected';} ?>><?php esc_html_e('Tuesday','backupforwp-pro');?></option> | |
| 133 | - <option value="Wed" <?php if(strpos($autobackup_days,'Wed')!==false){ echo 'selected';} ?>><?php esc_html_e('Wednesday','backupforwp-pro');?></option> | |
| 134 | - <option value="Thu" <?php if(strpos($autobackup_days,'Thu')!==false){ echo 'selected';} ?>><?php esc_html_e('Thursday','backupforwp-pro');?></option> | |
| 135 | - <option value="Fri" <?php if(strpos($autobackup_days,'Fri')!==false){ echo 'selected';} ?>><?php esc_html_e('Friday','backupforwp-pro');?></option> | |
| 136 | - <option value="Sat" <?php if(strpos($autobackup_days,'Sat')!==false){ echo 'selected';} ?>><?php esc_html_e('Saturday','backupforwp-pro');?></option> | |
| 137 | - <option value="Sun" <?php if(strpos($autobackup_days,'Sun')!==false){ echo 'selected';} ?>><?php esc_html_e('Sunday','backupforwp-pro');?></option> | |
| 135 | + | |
| 136 | + <div class="row form-group autobackup_days database_autobackup" style="display:none"> | |
| 137 | + <label class="col-sm-3" for="autobackup_days"><?php esc_html_e('Database Backup Days', 'wpdbbkp'); ?></label> | |
| 138 | + <div class="col-sm-9"> | |
| 139 | + <select id="autobackup_days" class="form-control bkpforwp_multiselect" | |
| 140 | + name="wp_db_backup_options[autobackup_days][]" multiple> | |
| 141 | + <option value="Mon" <?php if (strpos($autobackup_days, 'Mon') !== false) { | |
| 142 | + echo 'selected'; | |
| 143 | + } ?>> | |
| 144 | + <?php esc_html_e('Monday', 'wpdbbkp'); ?></option> | |
| 145 | + <option value="Tue" <?php if (strpos($autobackup_days, 'Tue') !== false) { | |
| 146 | + echo 'selected'; | |
| 147 | + } ?>> | |
| 148 | + <?php esc_html_e('Tuesday', 'wpdbbkp'); ?></option> | |
| 149 | + <option value="Wed" <?php if (strpos($autobackup_days, 'Wed') !== false) { | |
| 150 | + echo 'selected'; | |
| 151 | + } ?>> | |
| 152 | + <?php esc_html_e('Wednesday', 'wpdbbkp'); ?></option> | |
| 153 | + <option value="Thu" <?php if (strpos($autobackup_days, 'Thu') !== false) { | |
| 154 | + echo 'selected'; | |
| 155 | + } ?>> | |
| 156 | + <?php esc_html_e('Thursday', 'wpdbbkp'); ?></option> | |
| 157 | + <option value="Fri" <?php if (strpos($autobackup_days, 'Fri') !== false) { | |
| 158 | + echo 'selected'; | |
| 159 | + } ?>> | |
| 160 | + <?php esc_html_e('Friday', 'wpdbbkp'); ?></option> | |
| 161 | + <option value="Sat" <?php if (strpos($autobackup_days, 'Sat') !== false) { | |
| 162 | + echo 'selected'; | |
| 163 | + } ?>> | |
| 164 | + <?php esc_html_e('Saturday', 'wpdbbkp'); ?></option> | |
| 165 | + <option value="Sun" <?php if (strpos($autobackup_days, 'Sun') !== false) { | |
| 166 | + echo 'selected'; | |
| 167 | + } ?>> | |
| 168 | + <?php esc_html_e('Sunday', 'wpdbbkp'); ?></option> | |
| 138 | 169 | </select> |
| 139 | 170 | </div> |
| 140 | 171 | </div> |
| 141 | 172 | <div class="row form-group autobackup_date database_autobackup" style="display:none"> |
| 142 | - <label class="col-sm-3" for="autobackup_date"><?php esc_html_e('Database Backup Date','backupforwp-pro');?></label> | |
| 143 | - <div class="col-sm-9"> | |
| 144 | - <input type="date" id="autobackup_date" value="<?php echo esc_attr($autobackup_date);?>" class="form-control bkpforwp_multiselect" name="wp_db_backup_options[autobackup_date]"> | |
| 173 | + <label class="col-sm-3" for="autobackup_date"><?php esc_html_e('Database Backup Date', 'wpdbbkp'); ?></label> | |
| 174 | + <div class="col-sm-9"> | |
| 175 | + <input type="date" id="autobackup_date" value="<?php echo esc_attr($autobackup_date); ?>" | |
| 176 | + class="form-control bkpforwp_multiselect" name="wp_db_backup_options[autobackup_date]"> | |
| 145 | 177 | </div> |
| 146 | 178 | </div> |
| 147 | 179 | <div class="row form-group autobackup_time database_autobackup" style="display:none"> |
| 148 | - <label class="col-sm-3" for="autobackup_time"><?php esc_html_e('Database Backup Time','backupforwp-pro');?></label> | |
| 149 | - <div class="col-sm-9"> | |
| 150 | - <input type="time" id="autobackup_time" value="<?php echo esc_attr($autobackup_time);?>" class="form-control bkpforwp_multiselect" name="wp_db_backup_options[autobackup_time]"> | |
| 180 | + <label class="col-sm-3" for="autobackup_time"><?php esc_html_e('Database Backup Time', 'wpdbbkp'); ?></label> | |
| 181 | + <div class="col-sm-9"> | |
| 182 | + <input type="time" id="autobackup_time" value="<?php echo esc_attr($autobackup_time); ?>" | |
| 183 | + class="form-control bkpforwp_multiselect" name="wp_db_backup_options[autobackup_time]"> | |
| 151 | 184 | </div> |
| 152 | 185 | </div> |
| 153 | 186 | |
| 154 | -<?php | |
| 187 | + <?php | |
| 155 | 188 | } |
| 156 | 189 | |
| 157 | -add_action('wpdbbkp_full_backup_options','bkpforwp_full_backup_options'); | |
| 158 | -function bkpforwp_full_backup_options(){ | |
| 159 | - | |
| 160 | - $settings = get_option( 'wp_db_backup_options' ); | |
| 161 | - $autobackup_days = isset($settings['autobackup_full_days'])?implode(',',$settings['autobackup_full_days']):','; | |
| 162 | - $autobackup_time = isset($settings['autobackup_full_time'])?$settings['autobackup_full_time']:''; | |
| 163 | - $autobackup_date = isset($settings['autobackup_full_date'])?$settings['autobackup_full_date']:''; | |
| 164 | - $autobackup_date = isset($settings['autobackup_full_date'])?$settings['autobackup_full_date']:''; | |
| 165 | - $senable_exact_backup_time = get_option( 'bkpforwp_enable_exact_backup_time',false); | |
| 166 | - if($senable_exact_backup_time){ | |
| 167 | - ?> | |
| 168 | -<div class="row form-group autobackup_full_days full_autobackup" style="display:none"> | |
| 169 | - <label class="col-sm-3" for="autobackup_full_days"><?php esc_html_e('Full Backup Days','backupforwp-pro');?></label> | |
| 170 | - <div class="col-sm-9"> | |
| 171 | - <select id="autobackup_full_days" class="form-control bkpforwp_multiselect" name="wp_db_backup_options[autobackup_full_days][]" multiple> | |
| 172 | - <option value="Mon" <?php if(strpos($autobackup_days,'Mon')!==false){ echo 'selected';} ?> ><?php esc_html_e('Monday','backupforwp-pro');?></option> | |
| 173 | - <option value="Tue" <?php if(strpos($autobackup_days,'Tue')!==false){ echo 'selected';} ?>><?php esc_html_e('Tuesday','backupforwp-pro');?></option> | |
| 174 | - <option value="Wed" <?php if(strpos($autobackup_days,'Wed')!==false){ echo 'selected';} ?>><?php esc_html_e('Wednesday','backupforwp-pro');?></option> | |
| 175 | - <option value="Thu" <?php if(strpos($autobackup_days,'Thu')!==false){ echo 'selected';} ?>><?php esc_html_e('Thursday','backupforwp-pro');?></option> | |
| 176 | - <option value="Fri" <?php if(strpos($autobackup_days,'Fri')!==false){ echo 'selected';} ?>><?php esc_html_e('Friday','backupforwp-pro');?></option> | |
| 177 | - <option value="Sat" <?php if(strpos($autobackup_days,'Sat')!==false){ echo 'selected';} ?>><?php esc_html_e('Saturday','backupforwp-pro');?></option> | |
| 178 | - <option value="Sun" <?php if(strpos($autobackup_days,'Sun')!==false){ echo 'selected';} ?>><?php esc_html_e('Sunday','backupforwp-pro');?></option> | |
| 179 | - </select> | |
| 190 | +add_action('wpdbbkp_full_backup_options', 'bkpforwp_full_backup_options'); | |
| 191 | +function bkpforwp_full_backup_options() | |
| 192 | +{ | |
| 193 | + | |
| 194 | + $settings = get_option('wp_db_backup_options'); | |
| 195 | + $autobackup_days = isset($settings['autobackup_full_days']) ? implode(',', $settings['autobackup_full_days']) : ','; | |
| 196 | + $autobackup_time = isset($settings['autobackup_full_time']) ? $settings['autobackup_full_time'] : ''; | |
| 197 | + $autobackup_date = isset($settings['autobackup_full_date']) ? $settings['autobackup_full_date'] : ''; | |
| 198 | + $autobackup_date = isset($settings['autobackup_full_date']) ? $settings['autobackup_full_date'] : ''; | |
| 199 | + $senable_exact_backup_time = get_option('bkpforwp_enable_exact_backup_time', false); | |
| 200 | + if ($senable_exact_backup_time) { | |
| 201 | + ?> | |
| 202 | + <div class="row form-group autobackup_full_days full_autobackup" style="display:none"> | |
| 203 | + <label class="col-sm-3" for="autobackup_full_days"><?php esc_html_e('Full Backup Days', 'wpdbbkp'); ?></label> | |
| 204 | + <div class="col-sm-9"> | |
| 205 | + <select id="autobackup_full_days" class="form-control bkpforwp_multiselect" | |
| 206 | + name="wp_db_backup_options[autobackup_full_days][]" multiple> | |
| 207 | + <option value="Mon" <?php if (strpos($autobackup_days, 'Mon') !== false) { | |
| 208 | + echo 'selected'; | |
| 209 | + } ?>> | |
| 210 | + <?php esc_html_e('Monday', 'wpdbbkp'); ?></option> | |
| 211 | + <option value="Tue" <?php if (strpos($autobackup_days, 'Tue') !== false) { | |
| 212 | + echo 'selected'; | |
| 213 | + } ?>> | |
| 214 | + <?php esc_html_e('Tuesday', 'wpdbbkp'); ?></option> | |
| 215 | + <option value="Wed" <?php if (strpos($autobackup_days, 'Wed') !== false) { | |
| 216 | + echo 'selected'; | |
| 217 | + } ?>> | |
| 218 | + <?php esc_html_e('Wednesday', 'wpdbbkp'); ?></option> | |
| 219 | + <option value="Thu" <?php if (strpos($autobackup_days, 'Thu') !== false) { | |
| 220 | + echo 'selected'; | |
| 221 | + } ?>> | |
| 222 | + <?php esc_html_e('Thursday', 'wpdbbkp'); ?></option> | |
| 223 | + <option value="Fri" <?php if (strpos($autobackup_days, 'Fri') !== false) { | |
| 224 | + echo 'selected'; | |
| 225 | + } ?>> | |
| 226 | + <?php esc_html_e('Friday', 'wpdbbkp'); ?></option> | |
| 227 | + <option value="Sat" <?php if (strpos($autobackup_days, 'Sat') !== false) { | |
| 228 | + echo 'selected'; | |
| 229 | + } ?>> | |
| 230 | + <?php esc_html_e('Saturday', 'wpdbbkp'); ?></option> | |
| 231 | + <option value="Sun" <?php if (strpos($autobackup_days, 'Sun') !== false) { | |
| 232 | + echo 'selected'; | |
| 233 | + } ?>> | |
| 234 | + <?php esc_html_e('Sunday', 'wpdbbkp'); ?></option> | |
| 235 | + </select> | |
| 236 | + </div> | |
| 180 | 237 | </div> |
| 181 | - </div> | |
| 182 | - <div class="row form-group autobackup_full_date full_autobackup" style="display:none"> | |
| 183 | - <label class="col-sm-3" for="autobackup_full_date"><?php esc_html_e('Full Backup Date','backupforwp-pro');?></label> | |
| 184 | - <div class="col-sm-9"> | |
| 185 | - <input type="date" id="autobackup_full_date" value="<?php echo esc_attr($autobackup_date);?>" class="form-control" name="wp_db_backup_options[autobackup_full_date]"> | |
| 238 | + <div class="row form-group autobackup_full_date full_autobackup" style="display:none"> | |
| 239 | + <label class="col-sm-3" for="autobackup_full_date"><?php esc_html_e('Full Backup Date', 'wpdbbkp'); ?></label> | |
| 240 | + <div class="col-sm-9"> | |
| 241 | + <input type="date" id="autobackup_full_date" value="<?php echo esc_attr($autobackup_date); ?>" class="form-control" | |
| 242 | + name="wp_db_backup_options[autobackup_full_date]"> | |
| 243 | + </div> | |
| 186 | 244 | </div> |
| 187 | - </div> | |
| 188 | - <div class="row form-group autobackup_full_time full_autobackup" style="display:none"> | |
| 189 | - <label class="col-sm-3" for="autobackup_full_time"><?php esc_html_e('Full Backup Time','backupforwp-pro');?></label> | |
| 190 | - <div class="col-sm-9"> | |
| 191 | - <input type="time" id="autobackup_full_time" value="<?php echo esc_attr($autobackup_time);?>" class="form-control" name="wp_db_backup_options[autobackup_full_time]"> | |
| 245 | + <div class="row form-group autobackup_full_time full_autobackup" style="display:none"> | |
| 246 | + <label class="col-sm-3" for="autobackup_full_time"><?php esc_html_e('Full Backup Time', 'wpdbbkp'); ?></label> | |
| 247 | + <div class="col-sm-9"> | |
| 248 | + <input type="time" id="autobackup_full_time" value="<?php echo esc_attr($autobackup_time); ?>" class="form-control" | |
| 249 | + name="wp_db_backup_options[autobackup_full_time]"> | |
| 250 | + </div> | |
| 192 | 251 | </div> |
| 193 | - </div> | |
| 194 | -<?php | |
| 252 | + <?php | |
| 195 | 253 | } |
| 196 | 254 | } |
| 197 | 255 | |
| 198 | -add_filter( 'wpdbbkp_fullback_cron_condition', 'bkpforwp_fullback_cron_condition'); | |
| 199 | -function bkpforwp_fullback_cron_condition($value){ | |
| 200 | - $options_settings = get_option('wp_db_backup_options',false); | |
| 256 | +add_filter('wpdbbkp_fullback_cron_condition', 'bkpforwp_fullback_cron_condition'); | |
| 257 | +function bkpforwp_fullback_cron_condition($value) | |
| 258 | +{ | |
| 259 | + $options_settings = get_option('wp_db_backup_options', false); | |
| 201 | 260 | |
| 202 | - $senable_exact_backup_time = get_option( 'bkpforwp_enable_exact_backup_time',false); | |
| 203 | - if(!$senable_exact_backup_time){ | |
| 261 | + $senable_exact_backup_time = get_option('bkpforwp_enable_exact_backup_time', false); | |
| 262 | + if (!$senable_exact_backup_time) { | |
| 204 | 263 | return $value; |
| 205 | 264 | } |
| 206 | - if(wp_doing_cron() && $options_settings && isset($options_settings['enable_autobackups']) && $options_settings['enable_autobackups']==1 && isset($options_settings['full_autobackup_frequency'])){ | |
| 207 | - if($options_settings['full_autobackup_frequency']=='daily' && isset($options_settings['autobackup_full_time']) && $options_settings['autobackup_full_time']){ | |
| 208 | - if($options_settings['autobackup_full_time'] < gmdate("H:i") || $options_settings['autobackup_full_time'] > gmdate("H:i",strtotime('+30 minutes', gmdate("H:i")))){ | |
| 209 | - $value= false; | |
| 265 | + if (wp_doing_cron() && $options_settings && isset($options_settings['enable_autobackups']) && $options_settings['enable_autobackups'] == 1 && isset($options_settings['full_autobackup_frequency'])) { | |
| 266 | + if ($options_settings['full_autobackup_frequency'] == 'daily' && isset($options_settings['autobackup_full_time']) && $options_settings['autobackup_full_time']) { | |
| 267 | + if ($options_settings['autobackup_full_time'] < gmdate("H:i") || $options_settings['autobackup_full_time'] > gmdate("H:i", strtotime('+30 minutes', gmdate("H:i")))) { | |
| 268 | + $value = false; | |
| 210 | 269 | } |
| 211 | 270 | } |
| 212 | - if($options_settings['full_autobackup_frequency']=='weekly' && isset($options_settings['autobackup_full_time']) && $options_settings['autobackup_full_time'] && isset($options_settings['autobackup_full_days'])){ | |
| 213 | - $current_day=gmdate('M'); | |
| 214 | - $current_time=gmdate('H:i'); | |
| 215 | - $allowed_days= $options_settings['autobackup_full_days']; | |
| 216 | - if(!in_array($current_day,$allowed_days) || ($options_settings['autobackup_full_time'] < $current_time) || $options_settings['autobackup_full_time'] > gmdate("H:i",strtotime('+30 minutes', $current_time))){ | |
| 217 | - $value= false; | |
| 271 | + if ($options_settings['full_autobackup_frequency'] == 'weekly' && isset($options_settings['autobackup_full_time']) && $options_settings['autobackup_full_time'] && isset($options_settings['autobackup_full_days'])) { | |
| 272 | + $current_day = gmdate('M'); | |
| 273 | + $current_time = gmdate('H:i'); | |
| 274 | + $allowed_days = $options_settings['autobackup_full_days']; | |
| 275 | + if (!in_array($current_day, $allowed_days) || ($options_settings['autobackup_full_time'] < $current_time) || $options_settings['autobackup_full_time'] > gmdate("H:i", strtotime('+30 minutes', $current_time))) { | |
| 276 | + $value = false; | |
| 218 | 277 | } |
| 219 | 278 | } |
| 220 | - if($options_settings['full_autobackup_frequency']=='monthly' && isset($options_settings['autobackup_full_time']) && $options_settings['autobackup_full_time'] && isset($options_settings['autobackup_full_date'])){ | |
| 221 | - $current_date=gmdate('d'); | |
| 222 | - $current_time=gmdate('H:i'); | |
| 223 | - $allowed_date=gmdate('d',strtotime($options_settings['autobackup_full_date'])); | |
| 224 | - if(($allowed_date!=$current_date) || ($options_settings['autobackup_full_time'] < $current_time || $options_settings['autobackup_full_time'] > gmdate("H:i",strtotime('+30 minutes', $current_time)))){ | |
| 225 | - $value= false; | |
| 279 | + if ($options_settings['full_autobackup_frequency'] == 'monthly' && isset($options_settings['autobackup_full_time']) && $options_settings['autobackup_full_time'] && isset($options_settings['autobackup_full_date'])) { | |
| 280 | + $current_date = gmdate('d'); | |
| 281 | + $current_time = gmdate('H:i'); | |
| 282 | + $allowed_date = gmdate('d', strtotime($options_settings['autobackup_full_date'])); | |
| 283 | + if (($allowed_date != $current_date) || ($options_settings['autobackup_full_time'] < $current_time || $options_settings['autobackup_full_time'] > gmdate("H:i", strtotime('+30 minutes', $current_time)))) { | |
| 284 | + $value = false; | |
| 226 | 285 | } |
| 227 | 286 | } |
| 228 | 287 | } |
| 229 | 288 | return $value; |
| @@ -228,31 +287,32 @@ | ||
| 228 | 287 | } |
| 229 | 288 | return $value; |
| 230 | 289 | } |
| 231 | 290 | |
| 232 | -add_filter( 'wpdbbkp_dbback_cron_condition', 'bkpforwp_dbback_cron_condition'); | |
| 233 | -function bkpforwp_dbback_cron_condition($value){ | |
| 234 | - $options_settings = get_option('wp_db_backup_options',false); | |
| 235 | - if(wp_doing_cron() && $options_settings && isset($options_settings['enable_autobackups']) && $options_settings['enable_autobackups']==1 && isset($options_settings['autobackup_frequency'])){ | |
| 236 | - if($options_settings['autobackup_frequency']=='daily' && isset($options_settings['autobackup_time'])){ | |
| 237 | - if($options_settings['autobackup_time'] < gmdate("H:i") || $options_settings['autobackup_time'] > gmdate("H:i",strtotime('+30 minutes', gmdate("H:i")))){ | |
| 238 | - $value= false; | |
| 291 | +add_filter('wpdbbkp_dbback_cron_condition', 'bkpforwp_dbback_cron_condition'); | |
| 292 | +function bkpforwp_dbback_cron_condition($value) | |
| 293 | +{ | |
| 294 | + $options_settings = get_option('wp_db_backup_options', false); | |
| 295 | + if (wp_doing_cron() && $options_settings && isset($options_settings['enable_autobackups']) && $options_settings['enable_autobackups'] == 1 && isset($options_settings['autobackup_frequency'])) { | |
| 296 | + if ($options_settings['autobackup_frequency'] == 'daily' && isset($options_settings['autobackup_time'])) { | |
| 297 | + if ($options_settings['autobackup_time'] < gmdate("H:i") || $options_settings['autobackup_time'] > gmdate("H:i", strtotime('+30 minutes', gmdate("H:i")))) { | |
| 298 | + $value = false; | |
| 239 | 299 | } |
| 240 | 300 | } |
| 241 | - if($options_settings['autobackup_frequency']=='weekly' && isset($options_settings['autobackup_time']) && isset($options_settings['autobackup_days'])){ | |
| 242 | - $current_day=gmdate('M'); | |
| 243 | - $current_time=gmdate('H:i'); | |
| 244 | - $allowed_days=$options_settings['autobackup_days']; | |
| 245 | - if(!in_array($current_day,$allowed_days) || ($options_settings['autobackup_time'] < $current_time || $options_settings['autobackup_time'] > gmdate("H:i",strtotime('+30 minutes', $current_time)))){ | |
| 246 | - $value= false; | |
| 301 | + if ($options_settings['autobackup_frequency'] == 'weekly' && isset($options_settings['autobackup_time']) && isset($options_settings['autobackup_days'])) { | |
| 302 | + $current_day = gmdate('M'); | |
| 303 | + $current_time = gmdate('H:i'); | |
| 304 | + $allowed_days = $options_settings['autobackup_days']; | |
| 305 | + if (!in_array($current_day, $allowed_days) || ($options_settings['autobackup_time'] < $current_time || $options_settings['autobackup_time'] > gmdate("H:i", strtotime('+30 minutes', $current_time)))) { | |
| 306 | + $value = false; | |
| 247 | 307 | } |
| 248 | 308 | } |
| 249 | - if($options_settings['autobackup_frequency']=='monthly' && isset($options_settings['autobackup_time']) && isset($options_settings['autobackup_date'])){ | |
| 250 | - $current_date=gmdate('d'); | |
| 251 | - $current_time=gmdate('H:i'); | |
| 252 | - $allowed_date=gmdate('d',strtotime($options_settings['autobackup_date'])); | |
| 253 | - if(($allowed_date!=$current_date) || ($options_settings['autobackup_time'] < $current_time || $options_settings['autobackup_time'] > gmdate("H:i",strtotime('+30 minutes', $current_time)))){ | |
| 254 | - $value= false; | |
| 309 | + if ($options_settings['autobackup_frequency'] == 'monthly' && isset($options_settings['autobackup_time']) && isset($options_settings['autobackup_date'])) { | |
| 310 | + $current_date = gmdate('d'); | |
| 311 | + $current_time = gmdate('H:i'); | |
| 312 | + $allowed_date = gmdate('d', strtotime($options_settings['autobackup_date'])); | |
| 313 | + if (($allowed_date != $current_date) || ($options_settings['autobackup_time'] < $current_time || $options_settings['autobackup_time'] > gmdate("H:i", strtotime('+30 minutes', $current_time)))) { | |
| 314 | + $value = false; | |
| 255 | 315 | } |
| 256 | 316 | } |
| 257 | 317 | } |
| 258 | 318 | return $value; |
| @@ -257,16 +317,69 @@ | ||
| 257 | 317 | } |
| 258 | 318 | return $value; |
| 259 | 319 | } |
| 260 | 320 | |
| 261 | -add_filter( 'wpdbbkp_dbback_cron_frequency', 'bkpforwp_dbback_cron_frequency'); | |
| 321 | +add_filter('wpdbbkp_dbback_cron_frequency', 'bkpforwp_dbback_cron_frequency'); | |
| 262 | 322 | |
| 263 | -function bkpforwp_dbback_cron_frequency($value){ | |
| 264 | - if(wp_doing_cron()) | |
| 265 | - { | |
| 266 | - $options = get_option( 'wp_db_backup_options' ); | |
| 267 | - if(isset($options['autobackup_full_time']) && !empty($options['autobackup_full_time'])){ | |
| 323 | +function bkpforwp_dbback_cron_frequency($value) | |
| 324 | +{ | |
| 325 | + if (wp_doing_cron()) { | |
| 326 | + $options = get_option('wp_db_backup_options'); | |
| 327 | + if (isset($options['autobackup_full_time']) && !empty($options['autobackup_full_time'])) { | |
| 268 | 328 | $value = 'thirty_minutes'; |
| 269 | 329 | } |
| 270 | 330 | } |
| 271 | 331 | return $value; |
| 272 | -} | |
| 332 | +} | |
| 333 | + | |
| 334 | +/** | |
| 335 | + * Function to force the new .htaccess file to fix the backup folder protection | |
| 336 | + */ | |
| 337 | +function wpdbbkp_fix_htaccess_on_update() | |
| 338 | +{ | |
| 339 | + static $wpdbbkp_htaccess_fix = false; | |
| 340 | + | |
| 341 | + if (!$wpdbbkp_htaccess_fix && version_compare(WPDB_VERSION, '7.4', '>=')) { | |
| 342 | + $wpdbbkp_htaccess_fix = true; | |
| 343 | + $option_name = 'wpdbbkp_htaccess_fix'; | |
| 344 | + if (get_option($option_name, false)) { | |
| 345 | + return; // Exit if already fixed | |
| 346 | + } | |
| 347 | + | |
| 348 | + // Initialize WP Filesystem | |
| 349 | + global $wp_filesystem; | |
| 350 | + | |
| 351 | + if (!function_exists('WP_Filesystem')) { | |
| 352 | + require_once ABSPATH . 'wp-admin/includes/file.php'; | |
| 353 | + } | |
| 354 | + | |
| 355 | + if (!WP_Filesystem()) { | |
| 356 | + return; | |
| 357 | + } | |
| 358 | + // Define the .htaccess content | |
| 359 | + $htaccess_content = " | |
| 360 | +# Disable public access to this folder | |
| 361 | +<IfModule mod_authz_core.c> | |
| 362 | + Require all denied | |
| 363 | +</IfModule> | |
| 364 | + | |
| 365 | +<IfModule !mod_authz_core.c> | |
| 366 | + Deny from all | |
| 367 | +</IfModule> | |
| 368 | +"; | |
| 369 | + | |
| 370 | + $path_info = wp_upload_dir(); | |
| 371 | + $backup_folder = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/'; | |
| 372 | + $htaccess_file = trailingslashit($backup_folder) . '.htaccess'; | |
| 373 | + | |
| 374 | + if ($wp_filesystem->exists($htaccess_file)) { | |
| 375 | + $wp_filesystem->delete($htaccess_file); | |
| 376 | + } | |
| 377 | + | |
| 378 | + if (!$wp_filesystem->put_contents($htaccess_file, $htaccess_content, FS_CHMOD_FILE)) { | |
| 379 | + return; | |
| 380 | + } | |
| 381 | + update_option($option_name, time(), false); | |
| 382 | + } | |
| 383 | +} | |
| 384 | + | |
| 385 | +add_action('admin_init', 'wpdbbkp_fix_htaccess_on_update'); | |