/** * Creates DB und updates settings */ public static function activate() { //convert inactive version to active if ($incative_version = get_site_option('backwpup_version')) { update_site_option('backwpup_version', str_replace('-inactive', '', $incative_version)); } //changes for version before 3.0.0 if (!get_site_option('backwpup_version') && get_option('backwpup') && get_option('backwpup_jobs')) { self::upgrade_from_version_two(); } //changes for version before 3.0.14 if (version_compare('3.0.13', get_site_option('backwpup_version'), '>') && version_compare('3.0', get_site_option('backwpup_version'), '<')) { $upload_dir = wp_upload_dir(); $logfolder = get_site_option('backwpup_cfg_logfolder'); if (empty($logfolder)) { $old_log_folder = trailingslashit(str_replace('\\', '/', $upload_dir['basedir'])) . 'backwpup-' . substr(md5(md5(SECURE_AUTH_KEY)), 9, 5) . '-logs/'; update_site_option('backwpup_cfg_logfolder', $old_log_folder); } } //changes for 3.2 $no_translation = get_site_option('backwpup_cfg_jobnotranslate'); if ($no_translation) { update_site_option('backwpup_cfg_loglevel', 'normal'); delete_site_option('backwpup_cfg_jobnotranslate'); } //create new options if (is_multisite()) { add_site_option('backwpup_jobs', array()); } else { add_option('backwpup_jobs', array(), NULL, 'no'); } //remove old schedule wp_clear_scheduled_hook('backwpup_cron'); //make new schedule $activejobs = BackWPup_Option::get_job_ids('activetype', 'wpcron'); if (!empty($activejobs)) { foreach ($activejobs as $id) { $cron_next = BackWPup_Cron::cron_next(BackWPup_Option::get($id, 'cron')); wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $id)); } } $activejobs = BackWPup_Option::get_job_ids('activetype', 'easycron'); if (!empty($activejobs)) { foreach ($activejobs as $id) { BackWPup_EasyCron::update($id); } } //add check Cleanup schedule wp_clear_scheduled_hook('backwpup_check_cleanup'); wp_schedule_event(time(), 'twicedaily', 'backwpup_check_cleanup'); //add capabilities to administrator role $role = get_role('administrator'); if (is_object($role) && method_exists($role, 'add_cap')) { $role->add_cap('backwpup'); $role->add_cap('backwpup_jobs'); $role->add_cap('backwpup_jobs_edit'); $role->add_cap('backwpup_jobs_start'); $role->add_cap('backwpup_backups'); $role->add_cap('backwpup_backups_download'); $role->add_cap('backwpup_backups_delete'); $role->add_cap('backwpup_logs'); $role->add_cap('backwpup_logs_delete'); $role->add_cap('backwpup_settings'); } //add/overwrite roles add_role('backwpup_admin', __('BackWPup Admin', 'backwpup'), array('read' => TRUE, 'backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => TRUE, 'backwpup_jobs_start' => TRUE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => TRUE, 'backwpup_backups_delete' => TRUE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => TRUE, 'backwpup_settings' => TRUE)); add_role('backwpup_check', __('BackWPup jobs checker', 'backwpup'), array('read' => TRUE, 'backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => FALSE, 'backwpup_jobs_start' => FALSE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => FALSE, 'backwpup_backups_delete' => FALSE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => FALSE, 'backwpup_settings' => FALSE)); add_role('backwpup_helper', __('BackWPup jobs helper', 'backwpup'), array('read' => TRUE, 'backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => FALSE, 'backwpup_jobs_start' => TRUE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => TRUE, 'backwpup_backups_delete' => TRUE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => TRUE, 'backwpup_settings' => FALSE)); //add default options BackWPup_Option::default_site_options(); //update version update_site_option('backwpup_version', BackWPup::get_plugin_data('Version')); }
/** * Save settings form data */ public static function save_post_form() { if (!current_user_can('backwpup_settings')) { return; } //set default options if button clicked if (isset($_POST['default_settings']) && $_POST['default_settings']) { delete_site_option('backwpup_cfg_showadminbar'); delete_site_option('backwpup_cfg_showfoldersize'); delete_site_option('backwpup_cfg_jobstepretry'); delete_site_option('backwpup_cfg_jobmaxexecutiontime'); delete_site_option('backwpup_cfg_jobziparchivemethod'); delete_site_option('backwpup_cfg_loglevel'); delete_site_option('backwpup_cfg_jobwaittimems'); delete_site_option('backwpup_cfg_jobrunauthkey'); delete_site_option('backwpup_cfg_jobdooutput'); delete_site_option('backwpup_cfg_maxlogs'); delete_site_option('backwpup_cfg_gzlogs'); delete_site_option('backwpup_cfg_protectfolders'); delete_site_option('backwpup_cfg_authentication'); delete_site_option('backwpup_cfg_logfolder'); delete_site_option('backwpup_cfg_dropboxappkey'); delete_site_option('backwpup_cfg_dropboxappsecret'); delete_site_option('backwpup_cfg_dropboxsandboxappkey'); delete_site_option('backwpup_cfg_dropboxsandboxappsecret'); delete_site_option('backwpup_cfg_sugarsynckey'); delete_site_option('backwpup_cfg_sugarsyncsecret'); delete_site_option('backwpup_cfg_sugarsyncappid'); BackWPup_Option::default_site_options(); BackWPup_Admin::message(__('Settings reset to default', 'backwpup')); return; } update_site_option('backwpup_cfg_showadminbar', isset($_POST['showadminbar']) ? 1 : 0); update_site_option('backwpup_cfg_showfoldersize', isset($_POST['showfoldersize']) ? 1 : 0); if (100 > $_POST['jobstepretry'] && 0 < $_POST['jobstepretry']) { $_POST['jobstepretry'] = abs((int) $_POST['jobstepretry']); } if (empty($_POST['jobstepretry']) or !is_int($_POST['jobstepretry'])) { $_POST['jobstepretry'] = 3; } update_site_option('backwpup_cfg_jobstepretry', $_POST['jobstepretry']); $max_exe_time = abs((int) $_POST['jobmaxexecutiontime']); if (!is_int($max_exe_time) || $max_exe_time < 0) { $max_exe_time = 0; } elseif ($max_exe_time > 300) { $max_exe_time = 300; } update_site_option('backwpup_cfg_jobmaxexecutiontime', $max_exe_time); update_site_option('backwpup_cfg_jobziparchivemethod', $_POST['jobziparchivemethod'] == '' || $_POST['jobziparchivemethod'] == 'PclZip' || $_POST['jobziparchivemethod'] == 'ZipArchive' ? $_POST['jobziparchivemethod'] : ''); update_site_option('backwpup_cfg_loglevel', in_array($_POST['loglevel'], array('normal_translated', 'normal', 'debug_translated', 'debug')) ? $_POST['loglevel'] : 'normal_translated'); update_site_option('backwpup_cfg_jobwaittimems', $_POST['jobwaittimems']); update_site_option('backwpup_cfg_jobdooutput', isset($_POST['jobdooutput']) ? 1 : 0); update_site_option('backwpup_cfg_maxlogs', abs((int) $_POST['maxlogs'])); update_site_option('backwpup_cfg_gzlogs', isset($_POST['gzlogs']) ? 1 : 0); update_site_option('backwpup_cfg_protectfolders', isset($_POST['protectfolders']) ? 1 : 0); $_POST['jobrunauthkey'] = preg_replace('/[^a-zA-Z0-9]/', '', trim($_POST['jobrunauthkey'])); update_site_option('backwpup_cfg_jobrunauthkey', $_POST['jobrunauthkey']); $_POST['logfolder'] = trailingslashit(str_replace('\\', '/', trim(stripslashes($_POST['logfolder'])))); //set def. folders if (empty($_POST['logfolder']) || $_POST['logfolder'] === '/') { delete_site_option('backwpup_cfg_logfolder'); BackWPup_Option::default_site_options(); } else { update_site_option('backwpup_cfg_logfolder', $_POST['logfolder']); } $authentication = get_site_option('backwpup_cfg_authentication', array('method' => '', 'basic_user' => '', 'basic_password' => '', 'user_id' => 0, 'query_arg' => '')); $authentication['method'] = in_array($_POST['authentication_method'], array('user', 'basic', 'query_arg')) ? $_POST['authentication_method'] : ''; $authentication['basic_user'] = $_POST['authentication_basic_user']; $authentication['basic_password'] = BackWPup_Encryption::encrypt($_POST['authentication_basic_password']); $authentication['query_arg'] = $_POST['authentication_query_arg']; $authentication['user_id'] = (int) $_POST['authentication_user_id']; update_site_option('backwpup_cfg_authentication', $authentication); delete_site_transient('backwpup_cookies'); do_action('backwpup_page_settings_save'); BackWPup_Admin::message(__('Settings saved', 'backwpup')); }
/** * Save settings form data */ public static function save_post_form() { if (!current_user_can('backwpup_settings')) { return; } //set default options if button clicked if (isset($_POST['default_settings']) && $_POST['default_settings']) { delete_site_option('backwpup_cfg_showadminbar'); delete_site_option('backwpup_cfg_showfoldersize'); delete_site_option('backwpup_cfg_jobstepretry'); delete_site_option('backwpup_cfg_jobmaxexecutiontime'); delete_site_option('backwpup_cfg_jobziparchivemethod'); delete_site_option('backwpup_cfg_jobnotranslate'); delete_site_option('backwpup_cfg_jobwaittimems'); delete_site_option('backwpup_cfg_jobrunauthkey'); delete_site_option('backwpup_cfg_maxlogs'); delete_site_option('backwpup_cfg_gzlogs'); delete_site_option('backwpup_cfg_protectfolders'); delete_site_option('backwpup_cfg_httpauthuser'); delete_site_option('backwpup_cfg_httpauthpassword'); delete_site_option('backwpup_cfg_logfolder'); delete_site_option('backwpup_cfg_dropboxappkey'); delete_site_option('backwpup_cfg_dropboxappsecret'); delete_site_option('backwpup_cfg_dropboxsandboxappkey'); delete_site_option('backwpup_cfg_dropboxsandboxappsecret'); delete_site_option('backwpup_cfg_sugarsynckey'); delete_site_option('backwpup_cfg_sugarsyncsecret'); delete_site_option('backwpup_cfg_sugarsyncappid'); BackWPup_Option::default_site_options(); BackWPup_Admin::message(__('Settings reset to default', 'backwpup')); return; } update_site_option('backwpup_cfg_showadminbar', isset($_POST['showadminbar']) ? 1 : 0); update_site_option('backwpup_cfg_showfoldersize', isset($_POST['showfoldersize']) ? 1 : 0); if (100 > $_POST['jobstepretry'] && 0 < $_POST['jobstepretry']) { $_POST['jobstepretry'] = abs((int) $_POST['jobstepretry']); } if (empty($_POST['jobstepretry']) or !is_int($_POST['jobstepretry'])) { $_POST['jobstepretry'] = 3; } update_site_option('backwpup_cfg_jobstepretry', $_POST['jobstepretry']); $max_exe_time = abs((int) $_POST['jobmaxexecutiontime']); if (!is_int($max_exe_time) || $max_exe_time < 0) { $max_exe_time = 0; } elseif ($max_exe_time > 300) { $max_exe_time = 300; } update_site_option('backwpup_cfg_jobmaxexecutiontime', $max_exe_time); update_site_option('backwpup_cfg_jobziparchivemethod', $_POST['jobziparchivemethod'] == '' || $_POST['jobziparchivemethod'] == 'PclZip' || $_POST['jobziparchivemethod'] == 'ZipArchive' ? $_POST['jobziparchivemethod'] : ''); update_site_option('backwpup_cfg_jobnotranslate', isset($_POST['jobnotranslate']) ? 1 : 0); update_site_option('backwpup_cfg_jobwaittimems', $_POST['jobwaittimems']); update_site_option('backwpup_cfg_maxlogs', abs((int) $_POST['maxlogs'])); update_site_option('backwpup_cfg_gzlogs', isset($_POST['gzlogs']) ? 1 : 0); update_site_option('backwpup_cfg_protectfolders', isset($_POST['protectfolders']) ? 1 : 0); update_site_option('backwpup_cfg_httpauthuser', $_POST['httpauthuser']); update_site_option('backwpup_cfg_httpauthpassword', BackWPup_Encryption::encrypt($_POST['httpauthpassword'])); $_POST['jobrunauthkey'] = preg_replace('/[^a-zA-Z0-9]/', '', trim($_POST['jobrunauthkey'])); update_site_option('backwpup_cfg_jobrunauthkey', $_POST['jobrunauthkey']); $_POST['logfolder'] = trailingslashit(str_replace('\\', '/', trim(stripslashes($_POST['logfolder'])))); if ($_POST['logfolder'][0] == '.' || $_POST['logfolder'][0] != '/' && !preg_match('#^[a-zA-Z]:/#', $_POST['logfolder'])) { $_POST['logfolder'] = trailingslashit(str_replace('\\', '/', ABSPATH)) . $_POST['logfolder']; } //set def. folders if (empty($_POST['logfolder']) || $_POST['logfolder'] == '/') { delete_site_option('backwpup_cfg_logfolder'); BackWPup_Option::default_site_options(); } else { update_site_option('backwpup_cfg_logfolder', $_POST['logfolder']); } do_action('backwpup_page_settings_save'); BackWPup_Admin::message(__('Settings saved', 'backwpup')); }
/** * Creates DB und updates settings */ public static function activate() { //convert inactive version to active if ($incative_version = get_site_option('backwpup_version')) { update_site_option('backwpup_version', str_replace('-inactive', '', $incative_version)); } //changes for version before 3.0.0 if (!get_site_option('backwpup_version') && get_option('backwpup') && get_option('backwpup_jobs')) { self::upgrade_from_version_two(); } //changes for version before 3.0.14 if (version_compare('3.0.13', get_site_option('backwpup_version'), '>') && version_compare('3.0', get_site_option('backwpup_version'), '<')) { $upload_dir = wp_upload_dir(); $logfolder = get_site_option('backwpup_cfg_logfolder'); if (empty($logfolder)) { $old_log_folder = trailingslashit(str_replace('\\', '/', $upload_dir['basedir'])) . 'backwpup-' . substr(md5(md5(SECURE_AUTH_KEY)), 9, 5) . '-logs/'; update_site_option('backwpup_cfg_logfolder', $old_log_folder); } } //changes for version before 3.1.2 if (version_compare('3.1.2', get_site_option('backwpup_version'), '>')) { BackWPup_Job::check_folder(get_site_option('backwpup_cfg_logfolder'), TRUE); } //create new options if (is_multisite()) { add_site_option('backwpup_jobs', array()); } else { add_option('backwpup_jobs', array(), NULL, 'no'); } //remove old schedule wp_clear_scheduled_hook('backwpup_cron'); //make new schedule $activejobs = BackWPup_Option::get_job_ids('activetype', 'wpcron'); if (!empty($activejobs)) { foreach ($activejobs as $id) { $cron_next = BackWPup_Cron::cron_next(BackWPup_Option::get($id, 'cron')); wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $id)); } } //add check Cleanup schedule wp_clear_scheduled_hook('backwpup_check_cleanup'); wp_schedule_event(time(), 'twicedaily', 'backwpup_check_cleanup'); //remove old roles pre v.3.0.9 $role = get_role('administrator'); $role->remove_cap('backwpup'); $role->remove_cap('backwpup_jobs'); $role->remove_cap('backwpup_jobs_edit'); $role->remove_cap('backwpup_jobs_start'); $role->remove_cap('backwpup_backups'); $role->remove_cap('backwpup_backups_download'); $role->remove_cap('backwpup_backups_delete'); $role->remove_cap('backwpup_logs'); $role->remove_cap('backwpup_logs_delete'); $role->remove_cap('backwpup_settings'); //add/overwrite roles add_role('backwpup_admin', __('BackWPup Admin', 'backwpup'), array('backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => TRUE, 'backwpup_jobs_start' => TRUE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => TRUE, 'backwpup_backups_delete' => TRUE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => TRUE, 'backwpup_settings' => TRUE)); add_role('backwpup_check', __('BackWPup jobs checker', 'backwpup'), array('backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => FALSE, 'backwpup_jobs_start' => FALSE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => FALSE, 'backwpup_backups_delete' => FALSE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => FALSE, 'backwpup_settings' => FALSE)); add_role('backwpup_helper', __('BackWPup jobs helper', 'backwpup'), array('backwpup' => TRUE, 'backwpup_jobs' => TRUE, 'backwpup_jobs_edit' => FALSE, 'backwpup_jobs_start' => TRUE, 'backwpup_backups' => TRUE, 'backwpup_backups_download' => TRUE, 'backwpup_backups_delete' => TRUE, 'backwpup_logs' => TRUE, 'backwpup_logs_delete' => TRUE, 'backwpup_settings' => FALSE)); //add role to admin user if no one $users_backwpup = get_users(array('blog_id' => 1, 'role' => 'backwpup_admin')); if (empty($users_backwpup)) { /* @var WP_User $user */ $users = get_users(array('blog_id' => 1, 'role' => 'administrator', 'fields' => 'all_with_meta')); foreach ($users as $user) { $user->add_role('backwpup_admin'); } } //add default options BackWPup_Option::default_site_options(); //update version update_site_option('backwpup_version', BackWPup::get_plugin_data('Version')); }