public function post_restore() { if (isset($_POST['job_id']) && isset($_POST['backup_uniqid']) && isset($_POST['_wpnonce']) && isset($_POST['method'])) { $nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING); if (!wp_verify_nonce($nonce, 'my-wp-backup-restore-backup')) { wp_die(esc_html__('Nope! Security check failed!', 'my-wp-backup')); } $id = absint($_POST['job_id']); $uniqid = sanitize_key($_POST['backup_uniqid']); $method = filter_input(INPUT_POST, 'method', FILTER_SANITIZE_STRING); $backup = self::get($id, $uniqid); if (!isset($backup['duration'])) { add_settings_error('', '', __('Invalid backup id/uniqid.', 'my-wp-backup')); set_transient('settings_errors', get_settings_errors()); wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1))); } if (!$backup->has_archives()) { // No local copy and no remote copy === DEAD END. if (empty($backup['destinations'])) { add_settings_error('', '', __('Backup files missing.', 'my-wp-backup')); set_transient('settings_errors', get_settings_errors()); wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1))); } if (!isset($backup['destinations'][$method])) { add_settings_error('', '', sprintf(__('No backup files from %s.', 'my-wp-backup'), Job::$destinations[$method])); set_transient('settings_errors', get_settings_errors()); wp_safe_redirect($this->admin->get_page_url('backup', array('settings-updated' => 1))); } } wp_schedule_single_event(time(), 'wp_backup_restore_backup', array(array($id, $uniqid, $method))); wp_safe_redirect($this->admin->get_page_url('backup', array('uniqid' => $uniqid, 'action' => 'viewprogress', 'id' => $id))); } }
protected function __construct() { if (false !== get_transient('_my-wp-backup-activated')) { delete_transient('_my-wp-backup-activated'); wp_redirect(Admin::get_page_url('')); } self::$info = get_file_data(__FILE__, array('name' => 'Plugin Name', 'pluginUri' => 'Plugin URI', 'supportUri' => 'Support URI', 'version' => 'Version', 'description' => 'Description', 'author' => 'Author', 'authorUri' => 'Author URI', 'textDomain' => 'Text Domain', 'domainPath' => 'Domain Path', 'slug' => 'Slug', 'license' => 'License', 'licenseUri' => 'License URI')); Admin::get_instance(); $options = get_site_option('my-wp-backup-options', Admin::$options); self::$info['baseDir'] = plugin_dir_path(__FILE__); self::$info['baseDirUrl'] = plugin_dir_url(__FILE__); self::$info['backup_dir'] = trailingslashit(ABSPATH) . trailingslashit(ltrim($options['backup_dir'], '/')); self::$info['root_dir'] = trailingslashit(ABSPATH); if (defined('WP_CLI') && WP_CLI) { \WP_CLI::add_command('job', new Cli\Job()); \WP_CLI::add_command('backup', new Cli\Backup()); } add_action('wp_backup_run_job', array(Job::get_instance(), 'cron_run')); add_action('wp_backup_restore_backup', array(Backup::get_instance(), 'cron_run')); $version = get_site_option(self::KEY_VERSION); if (!$version || self::$info['version'] !== $version) { if ($this->update_options()) { update_site_option(self::KEY_VERSION, self::$info['version']); } } }
public static function run() { Admin::get_instance(); if (!get_site_option('my-wp-backup-jobs', false)) { update_site_option('my-wp-backup-jobs', array()); } if (!get_site_option('my-wp-backup-options', false)) { update_site_option('my-wp-backup-options', Admin::$options); } if (version_compare(PHP_VERSION, self::MIN_VER, '<')) { self::err(sprintf(__('PHP\'s version is too old. You have %s but My WP Backup requires atleast %s.', 'my-wp-backup'), PHP_VERSION, self::MIN_VER)); } $extensions = array('zlib', 'bz2', 'SPL', 'curl', 'mbstring', 'ftp'); foreach ($extensions as $extension) { if (!extension_loaded($extension)) { self::err(sprintf(__('Error: Your PHP installation does not have the %s extension which is required for this plugin to function correctly.', 'my-wp-backup'), $extension)); } } set_transient('_my-wp-backup-activated', true, 30); }
</strong></li> </ul> <label for="restore-method"><?php esc_html_e('Select where to restore the backup from:', 'my-wp-backup'); ?> </label><br><br> <select name="method" id="restore-method"> <?php wpb_select_options($backup->available_destinations()); ?> </select><br><br> <?php submit_button('Start', null, 'submit', false); ?> <a class="button button-cancel" href="<?php echo esc_attr(Admin::get_page_url('backup')); ?> "><?php esc_html_e('Cancel', 'my-wp-backup'); ?> </a> </form> <?php } elseif ('viewprogress' === $action) { ?> <label for="show-verbose"><input type="checkbox" value="yes" id="show-verbose"><?php esc_html_e('Verbose Output', 'my-wp-backup'); ?> </label>
/** * @param array $attributes * * @return array|void */ public function validate($attributes) { $jobs = get_site_option('my-wp-backup-jobs', array()); $last_job = end($jobs); $new_id = $last_job['id'] + 1; $values = self::$form_defaults; $cron_types = array('simple' => 'simple', 'advanced' => 'advanced'); $shedule_types = array('manual' => 'manual', 'cron' => 'cron'); $id = $values['id'] = isset($attributes['id']) ? '0' !== $attributes['id'] ? absint($attributes['id']) : $new_id : $new_id; if (!$id) { wp_die(esc_html__('Nope! Security check failed!', 'my-wp-backup')); } $job_name = sanitize_text_field($attributes['job_name']); if ('' === $job_name) { $job_name = 'Job ' . $id; } $values['job_name'] = $job_name; $file_name = trim($attributes['filename']); if ('' !== $file_name) { $values['filename'] = $file_name; } if (isset(self::$compression_methods[$attributes['compression']])) { $values['compression'] = $attributes['compression']; } $values['password'] = isset($attributes['password']) ? sanitize_text_field($attributes['password']) : ''; if (isset($attributes['volsize'])) { $volsize = absint($attributes['volsize']); if ($volsize > 0) { $values['volsize'] = $volsize; } } if (isset($attributes['differential']) && '1' === $attributes['differential']) { $values['differential'] = '1'; } if (isset($attributes['schedule_type'])) { $schedule_type = sanitize_text_field($attributes['schedule_type']); if (isset($shedule_types[$schedule_type])) { $values['schedule_type'] = $shedule_types[$schedule_type]; } } if (isset($attributes['cron_type'])) { $cron_type = sanitize_text_field($attributes['cron_type']); if (isset($cron_types[$cron_type])) { $values['cron_type'] = $cron_types[$cron_type]; } } $values['destination'] = isset($attributes['destination']) ? $attributes['destination'] : array(); $values['rep_destination'] = isset($attributes['rep_destination']) ? $attributes['rep_destination'] : array(); $values['backup_files'] = isset($attributes['backup_files']) && '1' === $attributes['backup_files'] ? '1' : '0'; $values['backup_uploads'] = isset($attributes['backup_uploads']) && '1' === $attributes['backup_uploads'] ? '1' : '0'; if (isset($attributes['exclude_files'])) { $values['exclude_files'] = '1' === $attributes['exclude_files'] ? '1' : '0'; } if (isset($attributes['file_filters'])) { $values['file_filters'] = array_filter(preg_split("/\r\n|\n|\r/", $attributes['file_filters']), function ($filter) { $filter = sanitize_text_field($filter); return empty($filter) ? false : $filter; }); } $values['export_db'] = isset($attributes['export_db']) && '1' === $attributes['export_db'] ? '1' : '0'; if (isset($attributes['exclude_tables'])) { $values['exclude_tables'] = '1' === $attributes['exclude_tables'] ? '1' : '0'; } if (isset($attributes['table_filters'])) { if (is_array($attributes['table_filters'])) { $tables = Admin::get_tables(); $values['table_filters'] = array_filter($attributes['table_filters'], function ($filter) use($tables) { return in_array($filter, $tables) ? $filter : false; }); } } if (isset($attributes['delete_local'])) { $values['delete_local'] = '1' === $attributes['delete_local'] ? '1' : '0'; } if (isset($attributes['destination_options']) && is_array($attributes['destination_options'])) { foreach ($attributes['destination_options'] as $destination => $options) { switch ($destination) { case 'ftp': if (isset($options['host'])) { $values['destination_options'][$destination]['host'] = sanitize_text_field($options['host']); } if (isset($options['username'])) { $values['destination_options'][$destination]['username'] = sanitize_text_field($options['username']); } if (isset($options['password'])) { $values['destination_options'][$destination]['password'] = sanitize_text_field($options['password']); } if (isset($options['port'])) { $values['destination_options'][$destination]['port'] = absint($options['port']); } if (isset($options['folder'])) { $values['destination_options'][$destination]['folder'] = sanitize_text_field($options['folder']); } if (isset($options['ssl']) && '1' === $options['ssl']) { $values['destination_options'][$destination]['ssl'] = '1'; } break; case 'dropbox': if (isset($options['token'])) { $values['destination_options'][$destination]['token'] = sanitize_text_field($options['token']); } if (isset($options['folder'])) { $values['destination_options'][$destination]['folder'] = sanitize_text_field($options['folder']); } break; case 'googledrive': if (isset($options['token'])) { $values['destination_options'][$destination]['token'] = sanitize_text_field($options['token']); } if (isset($options['token_json'])) { $values['destination_options'][$destination]['token_json'] = sanitize_text_field($options['token_json']); } if (isset($options['folder'])) { $values['destination_options'][$destination]['folder'] = sanitize_text_field($options['folder']); } break; } } } if (isset($attributes['reporter_options']) && is_array($attributes['reporter_options'])) { foreach ($attributes['reporter_options'] as $reporter => $options) { $reporter = sanitize_key($reporter); $values['reporter_options'][$reporter] = array_map('sanitize_text_field', $options); if ('mail' === $reporter) { $values['reporter_options'][$reporter]['attach'] = isset($attributes['reporter_options'][$reporter]['attach']) ? '1' : '0'; } } } return $values; }
esc_attr_e('Import', 'my-wp-backup'); ?> " class="button-primary" name="Submit"></p> </form> </div> <div id="section-export" class="nav-tab-content"> <table class="form-table"> <tr> <th scope="row"><label for="export"><?php esc_html_e('Copy Code', 'my-wp-backup'); ?> </label></th> <td> <textarea id="export" cols="40" rows="10"><?php echo serialize(\MyWPBackup\Admin\Admin::get_instance()->export()); ?> </textarea> </td> </tr> <tr> <th scope="row"><label for="export-dl"><?php esc_html_e('Download File', 'my-wp-backup'); ?> </label></th> <td> <a id="export-dl" href="<?php echo esc_attr(MyWPBackup\Admin\Admin::get_page_url('settings', array('action' => 'export'))); ?> "><?php esc_html_e('Click here to download', 'my-wp-backup');
function column_date($item) { $actions = array('log' => sprintf('<a href="%s">Review Log</a>', Admin::get_page_url('backup', array('uniqid' => $item['uniqid'], 'action' => 'log', 'id' => $item['job']['id']))), 'list' => sprintf('<a href="%s">List Files</a>', Admin::get_page_url('backup', array('uniqid' => $item['uniqid'], 'action' => 'list', 'id' => $item['job']['id']))), 'delete' => sprintf('<a href="%s">Delete</a>', Admin::get_page_url('backup', array('uniqid' => $item['uniqid'], 'action' => 'delete', 'id' => $item['job']['id']))), 'restore' => sprintf('<a href="%s">Restore</a>', Admin::get_page_url('backup', array('uniqid' => $item['uniqid'], 'action' => 'restore', 'id' => $item['job']['id'])))); return sprintf('%1$s ago %2$s', human_time_diff($item['timestamp'], time()), $this->row_actions($actions)); }
</label></th> <td> <input type="checkbox" class="enable-exclude" name="my-wp-backup-jobs[exclude_tables]" id="enable-exclude-tables" value="1" <?php checked('1', $job['exclude_tables'], true); ?> ><label for="enable-exclude-tables"><?php esc_html_e('Enable', 'my-wp-backup'); ?> </label> <div class="exclude-filters"> <p class="description"><?php esc_html_e('Exclude the following database tables:', 'my-wp-backup'); ?> </p><br> <?php foreach (\MyWPBackup\Admin\Admin::get_tables() as $table) { ?> <input name="my-wp-backup-jobs[table_filters][]" type="checkbox" id="table_<?php echo esc_attr($table); ?> " value="<?php echo esc_attr($table); ?> " <?php checked(true, in_array($table, $job['table_filters']), true); ?> ><label for="table_<?php echo esc_attr($table); ?> "><?php echo esc_html($table);
public function column_name($item) { $delete_link = Admin::get_page_url('jobs', array('action' => 'delete', 'id' => $item['id'])); $run_link = Admin::get_page_url('jobs', array('action' => 'run', 'id' => $item['id'], 'tour' => isset($_GET['tour']) && 'yes' === $_GET['tour'] ? 'yes' : null)); $view_link = Admin::get_page_url('jobs', array('action' => 'view', 'id' => $item['id'], 'uniqid' => $this->running['uniqid'])); $actions = array('edit' => sprintf('<a href="%s">Edit</a>', Admin::get_page_url('jobs', array('action' => 'edit', 'id' => $item['id']))), 'delete' => sprintf('<a href="%s">Delete</a>', $delete_link)); if (false !== $this->running && $this->running['id'] === $item['id']) { $actions['view'] = sprintf('<a href="%s">View Progress</a>', $view_link); } elseif (false === $this->running && 'manual' === $item['schedule_type']) { $actions['run'] = sprintf('<a href="%s">Run Now</a>', $run_link); } return sprintf('%1$s %2$s', $item['job_name'], $this->row_actions($actions)); }
} ?> </div> <div class="row"> <div class="col col-md-4"> <div class="postbox"> <h3 class="hndle"><span><?php esc_html_e('Getting Started', 'my-wp-backup'); ?> </span></h3> <div class="inside"> <p><?php esc_html_e('New to WP Backup?', 'my-wp-backup'); ?> <br><br><a class="button" href="<?php echo esc_attr(\MyWPBackup\Admin\Admin::get_page_url('jobs', array('tour' => 'yes'))); ?> "><?php esc_html_e('Take Tour', 'my-wp-backup'); ?> </a></p> </div> </div> </div> </div> </div>