PluginProbe
WP Reset / 2.05
WP Reset v2.05
trunk 1.0 1.1 1.11 1.20 1.25 1.30 1.35 1.40 1.45 1.50 1.55 1.60 1.65 1.70 1.75 1.77 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.90 All 42 releases
← All changes | wp-reset-cli.php +104 -95 1.552.05 View file →
@@ -1,15 +1,16 @@
1 1 <?php
2 +
2 3 /**
3 4 * WP Reset
4 5 * https://wpreset.com/
5 - * (c) WebFactory Ltd, 2017-2019
6 + * (c) WebFactory Ltd, 2017-2023
6 7 */
7 8
8 9
9 10 // include only file
10 11 if (!defined('ABSPATH')) {
11 - wp_die(__('Do not open this file directly.', 'wp-error'));
12 + die('Do not open this file directly.');
12 13 }
13 14
14 15
15 16 /**
@@ -18,34 +19,31 @@
18 19 class WP_Reset_CLI extends WP_CLI_Command
19 20 {
20 21
21 22 /**
22 - * Reset the site database to default values. No files are modified.
23 - *
24 - * ## OPTIONS
25 - *
26 - * [--reactivate-theme]
27 - * : Reactivate currently active theme after reset.
28 - *
29 - * [--reactivate-plugins]
30 - * : Reactivate all currently active plugins after reset.
31 - *
32 - * [--reactivate-webhooks]
33 - * : Reactivate WP Webhooks plugin after reset.
34 - *
35 - * [--deactivate-wp-reset]
36 - * : Deactivate WP Reset plugin after reset. By default it will stay active after reset.
37 - *
38 - * [--yes]
39 - * : Answer yes to the confirmation message.
40 - *
41 - * ## EXAMPLES
42 - *
43 - * $ wp reset reset --yes
44 - * Success: Database has been reset.
45 - *
46 - * @when after_wp_load
47 - */
23 + * Reset the site database to default values. No files are modified.
24 + *
25 + * ## OPTIONS
26 + *
27 + * [--reactivate-theme]
28 + * : Reactivate currently active theme after reset.
29 + *
30 + * [--reactivate-plugins]
31 + * : Reactivate all currently active plugins after reset.
32 + *
33 + * [--deactivate-wp-reset]
34 + * : Deactivate WP Reset plugin after reset. By default it will stay active after reset.
35 + *
36 + * [--yes]
37 + * : Answer yes to the confirmation message.
38 + *
39 + * ## EXAMPLES
40 + *
41 + * $ wp reset reset --yes
42 + * Success: Database has been reset.
43 + *
44 + * @when after_wp_load
45 + */
48 46 function reset($args, $assoc_args)
49 47 {
50 48 WP_CLI::confirm('Are you sure you want to reset the site? There is NO UNDO!', $assoc_args);
51 49
@@ -62,11 +60,8 @@
62 60 }
63 61 if (!empty($assoc_args['reactivate-plugins'])) {
64 62 $params['reactivate_plugins'] = true;
65 63 }
66 - if (!empty($assoc_args['reactivate-webhooks'])) {
67 - $params['reactivate_webhooks'] = true;
68 - }
69 64
70 65 $result = $wp_reset->do_reinstall($params);
71 66 if (is_wp_error($result)) {
72 67 WP_CLI::error($result->get_error_message);
@@ -76,12 +71,12 @@
76 71 } // reset
77 72
78 73
79 74 /**
80 - * Display WP Reset version.
81 - *
82 - * @when after_wp_load
83 - */
75 + * Display WP Reset version.
76 + *
77 + * @when after_wp_load
78 + */
84 79 function version($args, $assoc_args)
85 80 {
86 81 global $wp_reset;
87 82
@@ -89,34 +84,34 @@
89 84 } // version
90 85
91 86
92 87 /**
93 - * Delete selected WordPress objects.
94 - *
95 - * ## OPTIONS
96 - *
97 - * <plugins|themes|transients|uploads|custom-tables|htaccess>
98 - * : WP objects to delete.
99 - *
100 - * [--yes]
101 - * : Answer yes to the confirmation message.
102 - *
103 - * [--empty]
104 - * : Empty (truncate) custom tables instead of deleting (dropping) them.
105 - *
106 - * ## EXAMPLES
107 - *
108 - * $ wp reset delete themes --yes
109 - * Success: 3 themes have been deleted.
110 - *
111 - * $ wp reset delete custom-tables --truncate --yes
112 - * Success: 3 custom tables have been emptied.
113 - *
114 - * $ wp reset delete htaccess --yes
115 - * Success: Htaccess file has been deleted.
116 - *
117 - * @when after_wp_load
118 - */
88 + * Delete selected WordPress objects.
89 + *
90 + * ## OPTIONS
91 + *
92 + * <plugins|themes|transients|uploads|custom-tables|htaccess|theme-options>
93 + * : WP objects to delete.
94 + *
95 + * [--yes]
96 + * : Answer yes to the confirmation message.
97 + *
98 + * [--empty]
99 + * : Empty (truncate) custom tables instead of deleting (dropping) them.
100 + *
101 + * ## EXAMPLES
102 + *
103 + * $ wp reset delete themes --yes
104 + * Success: 3 themes have been deleted.
105 + *
106 + * $ wp reset delete custom-tables --truncate --yes
107 + * Success: 3 custom tables have been emptied.
108 + *
109 + * $ wp reset delete htaccess --yes
110 + * Success: Htaccess file has been deleted.
111 + *
112 + * @when after_wp_load
113 + */
119 114 function delete($args, $assoc_args)
120 115 {
121 116 global $wp_reset, $wpdb;
122 117
@@ -122,10 +117,10 @@
122 117
123 118 if (empty($args[0])) {
124 119 WP_CLI::error('Please choose a subcommand: plugins, themes, transients, uploads, htaccess or custom-tables.');
125 120 return;
126 - } elseif (false == in_array($args[0], array('themes', 'plugins', 'transients', 'uploads', 'htaccess', 'custom-tables'))) {
127 - WP_CLI::error('Unknown subcommand. Please choose from: plugins, themes, transients, uploads, htaccess or custom tables.');
121 + } elseif (false == in_array($args[0], array('themes', 'plugins', 'transients', 'uploads', 'htaccess', 'custom-tables', 'theme-options'))) {
122 + WP_CLI::error('Unknown subcommand. Please choose from: plugins, themes, transients, uploads, htaccess, custom tables or theme-options.');
128 123 } else {
129 124 $subcommand = $args[0];
130 125 }
131 126
@@ -169,11 +164,16 @@
169 164 } else {
170 165 WP_CLI::error('Htaccess file has not been deleted. ' . $tmp->get_error_message());
171 166 }
172 167 break;
168 + case 'theme-options':
169 + WP_CLI::confirm('Are you sure you want to reset all options (mods) for all themes?', $assoc_args);
170 + $cnt = $wp_reset->do_reset_theme_options();
171 + WP_CLI::success('Options for ' . $cnt . ' themes have been reset.');
172 + break;
173 173 default:
174 174 // should never come to this but can't hurt
175 - WP_CLI::error('Unknown subcommand. Please choose from: plugins, themes, transients, uploads, htaccess or custom-tables.');
175 + WP_CLI::error('Unknown subcommand. Please choose from: plugins, themes, transients, uploads, htaccess, custom-tables or theme-options.');
176 176 return;
177 177 }
178 178 } // delete
179 179
@@ -178,37 +178,37 @@
178 178 } // delete
179 179
180 180
181 181 /**
182 - * List and manipulate DB snapshots.
183 - *
184 - * ## OPTIONS
185 - *
186 - * <list|create|restore|export|delete>
187 - * : Action to perform with snapshot.
188 - *
189 - * [--yes]
190 - * : Answer yes to the confirmation message.
191 - *
192 - * [--id=<snapshot-id>]
193 - * : Specify snapshot ID when doing restore, export and delete.
194 - *
195 - * [--name=<snapshot-name>]
196 - * : When creating a new snapshot specify an optional name.
197 - *
198 - * ## EXAMPLES
199 - *
200 - * wp reset snapshots create --yes
201 - * Success: New snapshot with ID 089bea has been created.
202 - *
203 - * $ wp reset snapshots delete --id=123456
204 - * Success: Snapshot has been deleted.
205 - *
206 - * $ wp reset snapshots export --id=123456
207 - * Success: Snapshot has been exported and saved to: https://test.site/wp-content/wp-reset-snapshots-export/wp-reset-snapshot-123456.sql.gz
208 - *
209 - * @when after_wp_load
210 - */
182 + * List and manipulate DB snapshots.
183 + *
184 + * ## OPTIONS
185 + *
186 + * <list|create|restore|export|delete>
187 + * : Action to perform with snapshot.
188 + *
189 + * [--yes]
190 + * : Answer yes to the confirmation message.
191 + *
192 + * [--id=<snapshot-id>]
193 + * : Specify snapshot ID when doing restore, export and delete.
194 + *
195 + * [--name=<snapshot-name>]
196 + * : When creating a new snapshot specify an optional name.
197 + *
198 + * ## EXAMPLES
199 + *
200 + * wp reset snapshots create --yes
201 + * Success: New snapshot with ID 089bea has been created.
202 + *
203 + * $ wp reset snapshots delete --id=123456
204 + * Success: Snapshot has been deleted.
205 + *
206 + * $ wp reset snapshots export --id=123456
207 + * Success: Snapshot has been exported and saved to: https://test.site/wp-content/wp-reset-snapshots-export/wp-reset-snapshot-123456.sql.gz
208 + *
209 + * @when after_wp_load
210 + */
211 211 function snapshots($args, $assoc_args)
212 212 {
213 213 global $wp_reset;
214 214
@@ -232,9 +232,9 @@
232 232 $tmp['name'] = $ss['name'];
233 233 } else {
234 234 $tmp['name'] = 'n/a';
235 235 }
236 - $tmp['created'] = date(get_option('date_format'), strtotime($ss['timestamp'])) . ' @ ' . date(get_option('time_format'), strtotime($ss['timestamp']));
236 + $tmp['created'] = gmdate(get_option('date_format'), strtotime($ss['timestamp'])) . ' @ ' . gmdate(get_option('time_format'), strtotime($ss['timestamp']));
237 237 $tmp['info'] = $ss['tbl_core'] . ' standard & ';
238 238 if ($ss['tbl_custom']) {
239 239 $tmp['info'] .= $ss['tbl_custom'] . ' custom table' . ($ss['tbl_custom'] == 1 ? '' : 's');
240 240 } else {
@@ -239,9 +239,9 @@
239 239 $tmp['info'] .= $ss['tbl_custom'] . ' custom table' . ($ss['tbl_custom'] == 1 ? '' : 's');
240 240 } else {
241 241 $tmp['info'] .= 'no custom tables';
242 242 }
243 - $tmp['info'] .= ' totaling ' . $wp_reset->format_size($ss['tbl_size']) . ' in ' . number_format($ss['tbl_rows']) . ' rows';
243 + $tmp['info'] .= ' totaling ' . WP_Reset_Utility::format_size($ss['tbl_size']) . ' in ' . number_format($ss['tbl_rows']) . ' rows';
244 244
245 245 $table[] = $tmp;
246 246 } // foreach
247 247 WP_CLI\Utils\format_items('table', $table, array('id', 'name', 'created', 'info'));
@@ -311,7 +311,16 @@
311 311 WP_CLI::error('Unknown subcommand. Please choose from: list, create, restore, export or delete.');
312 312 return;
313 313 }
314 314 } // snapshots
315 +
316 +
317 + /**
318 + * This command is no longer available. Please use "wp reset snapshots create" instead.
319 + */
320 + function backups($args, $assoc_args)
321 + {
322 + WP_CLI::error('This command is no longer available. Please use: wp reset snapshots create');
323 + } // backups
315 324 } // WP_Reset_CLI
316 325
317 326 WP_CLI::add_command('reset', 'WP_Reset_CLI');