-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgam-db-backup-template.php
257 lines (205 loc) · 8.62 KB
/
gam-db-backup-template.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
/*
* This file use for setings at admin site for GAM DB Backup.
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* GAM_DB_Backup_Settings class.
*/
class GAM_DB_Backup_Settings {
/**
* __construct function.
*
* @access public
* @return void
*/
public function __construct() {
$this->settings_group = 'db_backup';
add_action( 'admin_init', array( $this, 'register_settings' ) );
}
/**
* init_settings function.
*
* @access protected
* @return void
*/
protected function init_settings() {
// Prepare roles option
$this->settings = apply_filters( 'db_backup_settings',
array(
'db_backup_details' => array(
__( 'Database Detail', 'gam-db-backup' ),
array(
array(
'name' => 'gam_db_backup_host_name',
'std' => DB_HOST,
'label' => __( 'Host name', 'gam-db-backup' ),
'desc' => __( '', 'gam-db-backup' ),
'type' => 'label',
'attributes' => array()
),
array(
'name' => 'gam_db_backup_db_name',
'std' => DB_NAME,
'label' => __( 'Database name', 'gam-db-backup' ),
'desc' => __( '', 'gam-db-backup' ),
'type' => 'label',
'attributes' => array()
),
array(
'name' => 'gam_db_backup_user_name',
'std' => DB_USER,
'label' => __( 'Database User name', 'gam-db-backup' ),
'desc' => __( '', 'gam-db-backup' ),
'type' => 'label',
'attributes' => array()
),
array(
'name' => 'gam_db_backup_user_password',
'std' => '******',
'label' => __( 'Password', 'gam-db-backup' ),
'desc' => __( '', 'gam-db-backup' ),
'type' => 'label',
'attributes' => array()
),
),
),
'db_backup_now' => array(
__( 'Backup Now', 'gam-db-backup' ),
array(
array(
'name' => 'gam_db_backup_start_backup',
'std' => 'Backup',
'label' => __( 'Backup', 'gam-db-backup' ),
'value' => 'Start Backup',
'id' =>'gam_db_backup_start_backup',
'type' => 'button'
),
array(
'name' => 'gam_db_backup_download_file',
'std' => '',
'label' => __( 'Download', 'gam-db-backup' ),
'value' => 'Download File',
'id' =>'gam_db_backup_download_file',
'type' => 'anchor'
)
)
),
'db_backup_schedules' => array(
__( 'Schedule Setting', 'gam-db-backup' ),
array(
array(
'name' => 'gam_db_backup_schedules_options',
'std' => '',
'label' => __('Auto Backup Frequency', 'gam-db-backup' ),
'type' => 'radio',
'required' => false,
'priority' => 1,
'options' => array(
'daily' => __( 'Once Daily', 'gam-db-backup' ),
'weekly' => __( 'Once Weekly', 'gam-db-backup' ),
'monthly' =>__('Once Monthly', 'gam-db-backup' ),
'none' =>__('No Schedule', 'gam-db-backup' )
)
),
array(
'name' => 'gam_db_backup_schedules_options_save',
'id' =>'gam_db_backup_schedules_options_save',
'std' => '',
'label' => '',
'value' =>__( 'Save', 'gam-db-backup' ),
'type' => 'button'
)
)
)
)
);
}
/**
* register_settings function.
*
* @access public
* @return void
*/
public function register_settings() {
$this->init_settings();
foreach ( $this->settings as $section ) {
foreach ( $section[1] as $option ) {
if ( isset( $option['std'] ) )
add_option( $option['name'], $option['std'] );
register_setting( $this->settings_group, $option['name'] );
}
}
}
/**
* output function.
*
* @access public
* @return void
*/
public function output() {
$this->init_settings();
?>
<h2 class="nav-tab-wrapper">
<?php
foreach ( $this->settings as $key => $section ) {
echo '<a href="#settings-' . sanitize_title( $key ) . '" class="nav-tab">' . esc_html( $section[0] ) . '</a>';
}
?>
</h2>
<?php
foreach ( $this->settings as $key => $section ) {
echo '<div id="settings-' . sanitize_title( $key ) . '" class="settings_panel">';
echo '<table class="form-table">';
foreach ( $section[1] as $option ) {
$placeholder = ( ! empty( $option['placeholder'] ) ) ? 'placeholder="' . $option['placeholder'] . '"' : '';
$class = ! empty( $option['class'] ) ? $option['class'] : '';
$value = get_option( $option['name'] );
$option['type'] = ! empty( $option['type'] ) ? $option['type'] : '';
$attributes = array();
if ( ! empty( $option['attributes'] ) && is_array( $option['attributes'] ) )
foreach ( $option['attributes'] as $attribute_name => $attribute_value )
$attributes[] = esc_attr( $attribute_name ) . '="' . esc_attr( $attribute_value ) . '"';
echo '<tr valign="top" class="' . $class . '"><th scope="row"><label for="setting-' . $option['name'] . '">' . $option['label'] . '</a></th><td>';
switch ( $option['type'] ) {
case "" :
case "input" :
case "label" :
?> <label for="<?php esc_attr_e( $option['name'] ); ?>"> : <?php echo $option['std']; ?></label><?php
if ( $option['desc'] ) {
echo ' <p class="description">' . $option['desc'] . '</p>';
}
break;
case "button" :
?> <input type="submit" name="<?php echo $option['name'] ?>" value="<?php echo $option['value']; ?>" id="<?php echo $option['id']; ?>" /><?php
break;
case "anchor" :
?> <a id="<?php echo $option['id']; ?>" href="" target="_blank" download><?php echo $option['value']; ?></a><?php
break;
case "radio" :
$selected_schedule_option = get_option('gam_db_backup_schedules_options');
foreach($option['options'] as $key=>$value)
{
?>
<input type="radio" name="<?php echo $option['name']; ?>" id="<?php echo $option['name'] . '_' . $key; ?>" value="<?php echo $key; ?>" <?php if($selected_schedule_option == $key){ echo 'checked="checked" '; } ?> /> <?php echo $value ;
}
if ( !empty($selected_schedule_option) && $selected_schedule_option !='none')
{
echo "<br/><br/><p class='description'>";
printf( __( 'For once %s : database will store at wp-contents/uploads/gam-db-backup/%s/', 'gam-event-manager-email' ), $selected_schedule_option, $selected_schedule_option );
echo "</p>";
}
break;
default :
do_action( 'gam_db_backup_admin_field_' . $option['type'], $option, $attributes, $value, $placeholder );
break;
}
echo '</td></tr>';
}
echo '</table></div>';
}
?>
</div>
<?php
}
}