-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbackup-restore-divi-theme-options.php
executable file
·90 lines (81 loc) · 3.57 KB
/
backup-restore-divi-theme-options.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
/**
* Plugin Name: Backup/Restore Divi Theme Options
* Description: Backup & Restore your Divi Theme Options.
* Theme URI: https://github.com/DiviSpace/backup-restore-divi-theme-options
* Author: Divi Space
* Author URI: http://www.DiviSpace.com
* Version: 1.0.3
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Tags: divi, theme options, theme settings, divi theme options, divi options, divi theme settings, divi settings
* Text Domain: backup-restore-divi-theme-options
*/
class backup_restore_divi_theme_options {
function backup_restore_divi_theme_options() {
add_action('admin_menu', array(&$this, 'admin_menu'));
}
function admin_menu() {
$page = add_submenu_page('tools.php', 'Backup/Restore Theme Options', 'Backup/Restore Theme Options', 'manage_options', 'backup-restore-divi-theme-options', array(&$this, 'options_page'));
add_action("load-{$page}", array(&$this, 'import_export'));
add_submenu_page( 'et_divi_options',__( 'Backup/Restore Theme Options', 'Divi' ), __( 'Backup/Restore Theme Options', 'Divi' ), 'manage_options', 'tools.php?page=backup-restore-divi-theme-options', 'backup-restore-divi-theme-options' );
}
function import_export() {
if (isset($_GET['action']) && ($_GET['action'] == 'download')) {
header("Cache-Control: public, must-revalidate");
header("Pragma: hack");
header("Content-Type: text/plain");
header('Content-Disposition: attachment; filename="divi-theme-options-'.date("dMy").'.dat"');
echo serialize($this->_get_options());
die();
}
if (isset($_POST['upload']) && check_admin_referer('shapeSpace_restoreOptions', 'shapeSpace_restoreOptions')) {
if ($_FILES["file"]["error"] > 0) {
// error
} else {
$options = unserialize(file_get_contents($_FILES["file"]["tmp_name"]));
if ($options) {
foreach ($options as $option) {
update_option($option->option_name, unserialize($option->option_value));
}
}
}
wp_redirect(admin_url('tools.php?page=backup-restore-divi-theme-options'));
exit;
}
}
function options_page() { ?>
<div class="wrap">
<?php screen_icon(); ?>
<h2>Backup/Restore Theme Options</h2>
<form action="" method="POST" enctype="multipart/form-data">
<style>#backup-restore-divi-theme-options td { display: block; margin-bottom: 20px; }</style>
<table id="backup-restore-divi-theme-options">
<tr>
<td>
<h3>Backup/Export</h3>
<p>Here are the stored settings for the current theme:</p>
<p><textarea disabled class="widefat code" rows="20" cols="100" onclick="this.select()"><?php echo serialize($this->_get_options()); ?></textarea></p>
<p><a href="?page=backup-restore-divi-theme-options&action=download" class="button-secondary">Download as file</a></p>
</td>
<td>
<h3>Restore/Import</h3>
<p><label class="description" for="upload">Restore a previous backup</label></p>
<p><input type="file" name="file" /> <input type="submit" name="upload" id="upload" class="button-primary" value="Upload file" /></p>
<?php if (function_exists('wp_nonce_field')) wp_nonce_field('shapeSpace_restoreOptions', 'shapeSpace_restoreOptions'); ?>
</td>
</tr>
</table>
</form>
</div>
<?php }
function _display_options() {
$options = unserialize($this->_get_options());
}
function _get_options() {
global $wpdb;
return $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name = 'et_divi'"); // edit 'shapeSpace_options' to match theme options
}
}
new backup_restore_divi_theme_options();
?>