WordPress Database Reset - Version 2.0

Version Description

  • Added functionality to be able to select which tables you want to reset, rather than having to reset the entire database.
  • Added bsmSelect for the multiple select.
  • Modified screenshot-1.png.
  • Fixed redirect bug
  • 'Reactivate current plugins after reset' only shows if the options table is selected from the dropdown.
Download this release

Release Info

Developer mousesports
Plugin Icon 128x128 WordPress Database Reset
Version 2.0
Comparing to
See all releases

Code changes from version 1.4 to 2.0

css/i/ajax-loader.gif ADDED
Binary file
css/jquery.bsmselect.css ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .bsmContainer {
2
+ /* container that surrounds entire bsmSelect widget */
3
+ color: #555;
4
+ }
5
+
6
+ .bsmSelect {
7
+ /* the newly created regular 'select' */
8
+ display: inline;
9
+ }
10
+
11
+ .bsmOptionDisabled {
12
+ /* disabled options in new select */
13
+ color: #999;
14
+ }
15
+
16
+ .bsmHighlight {
17
+ /* the highlight span */
18
+ float: right;
19
+ padding: 0;
20
+ margin: 0 0 0 1em;
21
+ }
22
+
23
+ .bsmList {
24
+ /* html list that contains selected items */
25
+ border-color: #DFDFDF;
26
+ margin: 0.25em 0 1.5em 0;
27
+ position: relative;
28
+ display: block;
29
+ padding-left: 0;
30
+ list-style: none;
31
+ width: 287px;
32
+ }
33
+
34
+ .bsmListItem {
35
+ /* li item from the html list above */
36
+ position: relative;
37
+ margin-left: 0;
38
+ padding-left: 0;
39
+ list-style: none;
40
+ background: #FCFCFC;
41
+ border: 1px solid #DFDFDF;
42
+ width: 100%;
43
+ margin: 0 0 -1px 0;
44
+ line-height: 1em;
45
+ }
46
+
47
+ .bsmListItem:hover {
48
+ background-color: #F0F0F0;
49
+ }
50
+
51
+ .bsmListItemLabel {
52
+ /* this is a span that surrounds the text in the item, except for the remove link */
53
+ padding: 5px;
54
+ display: block;
55
+ }
56
+
57
+ .bsmListSortable .bsmListItemLabel {
58
+ cursor: move;
59
+ }
60
+
61
+ .bsmListItemRemove {
62
+ /* the remove link in each list item */
63
+ text-decoration: none;
64
+ position: absolute;
65
+ right: 0;
66
+ top: 0;
67
+ padding: 5px;
68
+ }
69
+
70
+ .bsmListItemRemove:hover {
71
+ text-decoration: underline;
72
+ }
73
+
74
+ #bsmListbsmContainer0 {
75
+ margin-top: 12px;
76
+ }
css/wp-reset.css ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #select-buttons {
2
+ width: 208px;
3
+ }
4
+
5
+ #select-all {
6
+ float: right;
7
+ margin-top: 4px;
8
+ }
9
+
10
+ #loader {
11
+ position: absolute;
12
+ margin-left: 10px;
13
+ margin-top: 1px;
14
+ }
15
+
16
+ #reactivate {color: #21759B}
js/jquery.bsmselect.compatibility.js ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Better Select Multiple Compatibility Plugin - jQuery Plugin
3
+ *
4
+ * Copyright (c) 2010 by Victor Berchet - http://www.github.com/vicb
5
+ *
6
+ * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
7
+ *
8
+ * version: v1.0.0 - 2010-09-05
9
+ */
10
+ (function($) {
11
+ $.bsmSelect.plugins.compatibility = function()
12
+ {
13
+ if (!(this instanceof arguments.callee)) {
14
+ return new arguments.callee();
15
+ }
16
+ }
17
+
18
+ $.extend($.bsmSelect.plugins.compatibility.prototype, {
19
+ init: function(bsm) {
20
+
21
+ var o = bsm.options;
22
+
23
+ if (typeof o.animate != 'undefined')
24
+ {
25
+ if (o.animate === true) {
26
+ o.showEffect = $.bsmSelect.effects.verticalListAdd;
27
+ o.hideEffect = $.bsmSelect.effects.verticalListRemove;
28
+ } else if ($.isFunction(o.animate.add)) {
29
+ o.showEffect = o.animate.add;
30
+ } else if (typeof(o.animate.add) == 'string' && $.isFunction($.bsmSelect.effects[o.animate.add])) {
31
+ o.showEffect = $.bsmSelect.effects[o.animate.add];
32
+ } else {
33
+ o.showEffect = $.bsmSelect.effects.show;
34
+ }
35
+
36
+ if ($.isFunction(o.animate.drop)) {
37
+ o.hideEffect = o.animate.drop;
38
+ } else if (typeof(o.animate.drop) == 'string' && $.isFunction($.bsmSelect.effects[o.animate.drop])) {
39
+ o.hideEffect = $.bsmSelect.effects[o.animate.drop];
40
+ } else {
41
+ o.hideEffect = $.bsmSelect.effects.remove;
42
+ }
43
+ }
44
+
45
+ if (typeof o.highlight != 'undefined')
46
+ {
47
+ if (o.highlight === true) {
48
+ o.highlightEffect = $.bsmSelect.effects.highlight;
49
+ } else if ($.isFunction(o.highlight)) {
50
+ o.highlightEffect = o.highlight;
51
+ } else if (typeof(o.highlight) == 'string' && $.isFunction($.bsmSelect.effects[o.highlight])) {
52
+ o.highlightEffect = $.bsmSelect.effects[o.highlight];
53
+ }
54
+ }
55
+
56
+ }
57
+
58
+ });
59
+ })(jQuery);
60
+
js/jquery.bsmselect.js ADDED
@@ -0,0 +1,381 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Better Select Multiple - jQuery Plugin
3
+ *
4
+ * based on Alternate Select Multiple (asmSelect) 1.0.4a beta (http://www.ryancramer.com/projects/asmselect/)
5
+ *
6
+ * Copyright (c) 2009 by Ryan Cramer - http://www.ryancramer.com
7
+ * Copyright (c) 2010 by Victor Berchet - http://www.github.com/vicb
8
+ *
9
+ * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
10
+ *
11
+ * bsmSelect version: v1.4.3 - 2011-05-05
12
+ */
13
+
14
+ (function($) {
15
+
16
+ function BsmSelect(target, options)
17
+ {
18
+ this.$original = $(target); // the original select multiple
19
+ this.buildingSelect = false; // is the new select being constructed right now?
20
+ this.ieClick = false; // in IE, has a click event occurred? ignore if not
21
+ this.ignoreOriginalChangeEvent = false; // originalChangeEvent bypassed when this is true
22
+ this.options = options;
23
+ this.buildDom();
24
+ }
25
+
26
+ BsmSelect.prototype = {
27
+ /**
28
+ * Generate an UID
29
+ */
30
+ generateUid: function(index) {
31
+ return (this.uid = this.options.containerClass + index);
32
+ },
33
+
34
+ /**
35
+ * Build the DOM for bsmSelect
36
+ */
37
+ buildDom: function() {
38
+ var self = this, o = this.options;
39
+
40
+ if (o.addItemTarget === 'original') {
41
+ $('option', this.$original).each(function(i, o) {
42
+ if ($(o).data('bsm-order') === null) { $(o).data('bsm-order', i); }
43
+ });
44
+ }
45
+
46
+ for (var index = 0; $('#' + this.generateUid(index)).size(); index++) {}
47
+
48
+ this.$select = $('<select>', {
49
+ 'class': o.selectClass,
50
+ name: o.selectClass + this.uid,
51
+ id: o.selectClass + this.uid,
52
+ change: $.proxy(this.selectChangeEvent, this),
53
+ click: $.proxy(this.selectClickEvent, this)
54
+ });
55
+
56
+ this.$list = $.isFunction(o.listType)
57
+ ? o.listType(this.$original)
58
+ : $('<' + o.listType + '>', { id: o.listClass + this.uid });
59
+
60
+ this.$list.addClass(o.listClass);
61
+
62
+ this.$container = $('<div>', { 'class': o.containerClass, id: this.uid });
63
+
64
+ this.buildSelect();
65
+
66
+ this.$original.change($.proxy(this.originalChangeEvent, this)).wrap(this.$container).before(this.$select);
67
+
68
+ // if the list isn't already in the document, add it (it might be inserted by a custom callback)
69
+ if (!this.$list.parent().length) { this.$original.before(this.$list); }
70
+
71
+ if (this.$original.attr('id')) {
72
+ $('label[for=' + this.$original.attr('id') + ']').attr('for', this.$select.attr('id'));
73
+ }
74
+
75
+ // set up remove event (may be a link, or the list item itself)
76
+ this.$list.delegate('.' + o.removeClass, 'click', function() {
77
+ self.dropListItem($(this).closest('li'));
78
+ return false;
79
+ });
80
+
81
+ $.each(o.plugins, function() { this.init(self); });
82
+ },
83
+
84
+ /**
85
+ * Triggered when an item has been selected
86
+ * Check to make sure it's not an IE screwup, and add it to the list
87
+ */
88
+ selectChangeEvent: function() {
89
+ if ($.browser.msie && $.browser.version < 7 && !this.ieClick) { return; }
90
+ var bsmOpt = $('option:selected:eq(0)', this.$select);
91
+ if (bsmOpt.data('orig-option')) {
92
+ this.addListItem(bsmOpt);
93
+ this.triggerOriginalChange(bsmOpt.data('orig-option'), 'add');
94
+ }
95
+ this.ieClick = false;
96
+ },
97
+
98
+ /**
99
+ * IE6 lets you scroll around in a select without it being pulled down
100
+ * making sure a click preceded the change() event reduces the chance
101
+ * if unintended items being added. there may be a better solution?
102
+ */
103
+ selectClickEvent: function() {
104
+ this.ieClick = true;
105
+ },
106
+
107
+ /**
108
+ * Rebuild bsmSelect when the 'change' event is triggered on the original select
109
+ */
110
+ originalChangeEvent: function() {
111
+ if (this.ignoreOriginalChangeEvent) {
112
+ // We don't want to rebuild everything when an item is added / droped
113
+ this.ignoreOriginalChangeEvent = false;
114
+ } else {
115
+ this.buildSelect();
116
+ // opera has an issue where it needs a force redraw, otherwise
117
+ // the items won't appear until something else forces a redraw
118
+ if ($.browser.opera) { this.$list.hide().show(); }
119
+ }
120
+ },
121
+
122
+ /**
123
+ * Build the DOM for the new select
124
+ */
125
+ buildSelect: function() {
126
+ var self = this;
127
+
128
+ this.buildingSelect = true;
129
+
130
+ // add a first option to be the home option / default selectLabel
131
+ this.$select.empty().prepend($('<option value=""></option>').text(this.$original.attr('title') || this.options.title));
132
+ this.$list.empty();
133
+
134
+ this.$original.children().each(function() {
135
+ if ($(this).is('option')) {
136
+ self.addSelectOption(self.$select, $(this));
137
+ } else if ($(this).is('optgroup')) {
138
+ self.addSelectOptionGroup(self.$select, $(this));
139
+ }
140
+ });
141
+
142
+ if (!this.options.debugMode) { this.$original.hide(); }
143
+ this.selectFirstItem();
144
+ this.buildingSelect = false;
145
+ },
146
+
147
+ /**
148
+ * Append an option to the new select
149
+ *
150
+ * @param {jQuery} $parent Where to append the option
151
+ * @param {jQuery} $origOpt Option from the original select
152
+ */
153
+ addSelectOption: function ($parent, $origOpt) {
154
+ var $bsmOpt = $('<option>', {
155
+ text: $origOpt.text(),
156
+ val: $origOpt.val() }).appendTo($parent).data('orig-option', $origOpt),
157
+ isSelected = $origOpt.is(':selected'),
158
+ isDisabled = $origOpt.is(':disabled');
159
+ $origOpt.data('bsm-option', $bsmOpt);
160
+ if (isSelected && !isDisabled) {
161
+ this.addListItem($bsmOpt);
162
+ this.disableSelectOption($bsmOpt);
163
+ } else if (!isSelected && isDisabled) {
164
+ this.disableSelectOption($bsmOpt);
165
+ }
166
+ },
167
+
168
+ /**
169
+ * Append an option group to the new select
170
+ *
171
+ * @param {jQuery} $parent Where to append the group
172
+ * @param {jQuery} $group Model group from the original select
173
+ */
174
+ addSelectOptionGroup: function($parent, $group)
175
+ {
176
+ var self = this,
177
+ $G = $('<optgroup>', { label: $group.attr('label')} ).appendTo($parent);
178
+ if ($group.is(':disabled')) { $G.attr('disabled', 'disabled'); }
179
+ $('option', $group).each(function() { self.addSelectOption($G, $(this)); });
180
+ },
181
+
182
+ /**
183
+ * Select the first item of the new select
184
+ */
185
+ selectFirstItem: function() {
186
+ $('option:eq(0)', this.$select).attr('selected', 'selected');
187
+ },
188
+
189
+ /**
190
+ * Make an option disabled, indicating that it's already been selected
191
+ * because safari is the only browser that makes disabled items look 'disabled'
192
+ * we apply a class that reproduces the disabled look in other browsers
193
+ *
194
+ * @param {jQuery} $bsmOpt Option from the new select
195
+ */
196
+ disableSelectOption: function($bsmOpt) {
197
+ $bsmOpt.addClass(this.options.optionDisabledClass)
198
+ .removeAttr('selected')
199
+ .attr('disabled', 'disabled')
200
+ .toggle(!this.options.hideWhenAdded);
201
+ if ($.browser.msie && $.browser.version < 8) { this.$select.hide().show(); } // this forces IE to update display
202
+ },
203
+
204
+ /**
205
+ * Enable a select option
206
+ *
207
+ * @param {jQuery} $bsmOpt Option from the new select
208
+ */
209
+ enableSelectOption: function($bsmOpt) {
210
+ $bsmOpt.removeClass(this.options.optionDisabledClass)
211
+ .removeAttr('disabled')
212
+ .toggle(!this.options.hideWhenAdded);
213
+ if ($.browser.msie && $.browser.version < 8) { this.$select.hide().show(); } // this forces IE to update display
214
+ },
215
+
216
+ /**
217
+ * Append an item corresponding to the option to the list
218
+ *
219
+ * @param {jQuery} $bsmOpt Option from the new select
220
+ */
221
+ addListItem: function($bsmOpt) {
222
+ var $item,
223
+ $origOpt = $bsmOpt.data('orig-option'),
224
+ o = this.options;
225
+
226
+ if (!$origOpt) { return; } // this is the first item, selectLabel
227
+
228
+ if (!this.buildingSelect) {
229
+ if ($origOpt.is(':selected')) { return; } // already have it
230
+ $origOpt.attr('selected', 'selected');
231
+ }
232
+
233
+ $item = $('<li>', { 'class': o.listItemClass })
234
+ .append($('<span>', { 'class': o.listItemLabelClass, html: o.extractLabel($bsmOpt, o)}))
235
+ .append($('<a>', { href: '#', 'class': o.removeClass, html: o.removeLabel }))
236
+ .data('bsm-option', $bsmOpt);
237
+
238
+ this.disableSelectOption($bsmOpt.data('item', $item));
239
+
240
+ switch (o.addItemTarget) {
241
+ case 'bottom':
242
+ this.$list.append($item.hide());
243
+ break;
244
+ case 'original':
245
+ var order = $origOpt.data('bsm-order'), inserted = false;
246
+ $('.' + o.listItemClass, this.$list).each(function() {
247
+ if (order < $(this).data('bsm-option').data('orig-option').data('bsm-order')) {
248
+ $item.hide().insertBefore(this);
249
+ inserted = true;
250
+ return false;
251
+ }
252
+ });
253
+ if (!inserted) { this.$list.append($item.hide()); }
254
+ break;
255
+ default:
256
+ this.$list.prepend($item.hide());
257
+ }
258
+
259
+ if (this.buildingSelect) {
260
+ $.bsmSelect.effects.show($item);
261
+ } else {
262
+ o.showEffect($item);
263
+ o.highlightEffect(this.$select, $item, o.highlightAddedLabel, this.options);
264
+ this.selectFirstItem();
265
+ }
266
+ },
267
+
268
+ /**
269
+ * Remove an item from the list of selection
270
+ *
271
+ * @param {jQuey} $item A list item
272
+ */
273
+ dropListItem: function($item) {
274
+ var $bsmOpt = $item.data('bsm-option'), o = this.options;
275
+ $bsmOpt.removeData('item').data('orig-option').removeAttr('selected');
276
+ (this.buildingSelect ? $.bsmSelect.effects.remove : o.hideEffect)($item);
277
+ this.enableSelectOption($bsmOpt);
278
+ o.highlightEffect(this.$select, $item, o.highlightRemovedLabel, o);
279
+ this.triggerOriginalChange($bsmOpt.data('orig-option'), 'drop');
280
+ },
281
+
282
+ /**
283
+ * Trigger a change event on the original select multiple
284
+ * so that other scripts can pick them up
285
+ *
286
+ * @param {jQuery} $origOpt The option from the original select
287
+ * @param {String} type Event type
288
+ */
289
+ triggerOriginalChange: function($origOpt, type) {
290
+ this.ignoreOriginalChangeEvent = true;
291
+ this.$original.trigger('change', [{
292
+ option: $origOpt,
293
+ value: $origOpt.val(),
294
+ item: $origOpt.data('bsm-option').data('item'),
295
+ type: type
296
+ }]);
297
+ }
298
+ };
299
+
300
+ $.fn.bsmSelect = function(customOptions) {
301
+ var options = $.extend({}, $.bsmSelect.conf, customOptions);
302
+ return this.each(function() {
303
+ var bsm = $(this).data("bsmSelect");
304
+ if (!bsm) {
305
+ bsm = new BsmSelect($(this), options);
306
+ $(this).data("bsmSelect", bsm);
307
+ }
308
+ });
309
+ };
310
+
311
+ $.bsmSelect = {};
312
+ $.extend($.bsmSelect, {
313
+ effects: {
314
+ show: function($el) { $el.show(); },
315
+
316
+ remove: function($el) { $el.remove(); },
317
+
318
+ highlight: function ($select, $item, label, conf) {
319
+ var $highlight,
320
+ id = $select.attr('id') + conf.highlightClass;
321
+ $('#' + id).remove();
322
+ $highlight = $('<span>', {
323
+ 'class': conf.highlightClass,
324
+ id: id,
325
+ html: label + $item.children('.' + conf.listItemLabelClass).first().text()
326
+ }).hide();
327
+ $select.after($highlight.fadeIn('fast').delay(50).fadeOut('slow', function() { $(this).remove(); }));
328
+ },
329
+
330
+ verticalListAdd: function ($el) {
331
+ $el.animate({ opacity: 'show', height: 'show' }, 100, function() {
332
+ $(this).animate({ height: '+=2px' }, 100, function() {
333
+ $(this).animate({ height: '-=2px' }, 100);
334
+ });
335
+ });
336
+ },
337
+
338
+ verticalListRemove: function($el) {
339
+ $el.animate({ opacity: 'hide', height: 'hide' }, 100, function() {
340
+ $(this).prev('li').animate({ height: '-=2px' }, 100, function() {
341
+ $(this).animate({ height: '+=2px' }, 100);
342
+ });
343
+ $(this).remove();
344
+ });
345
+ }
346
+ },
347
+ plugins: {
348
+ }
349
+ });
350
+
351
+ // Default configuration
352
+ $.bsmSelect.conf = {
353
+ listType: 'ol', // Ordered list 'ol', or unordered list 'ul'
354
+
355
+ showEffect: $.bsmSelect.effects.show,
356
+ hideEffect: $.bsmSelect.effects.remove,
357
+ highlightEffect: $.noop,
358
+
359
+ addItemTarget: 'bottom', // Where to place new selected items in list: top or bottom
360
+ hideWhenAdded: false, // Hide the option when added to the list? works only in FF
361
+ debugMode: false, // Debug mode keeps original select visible
362
+
363
+ title: 'Select...', // Text used for the default select label
364
+ removeLabel: 'remove', // HTML used for the 'remove' link
365
+ highlightAddedLabel: 'Added: ', // Text that precedes highlight of added item
366
+ highlightRemovedLabel: 'Removed: ', // Text that precedes highlight of removed item
367
+ extractLabel: function($o) { return $o.html(); },
368
+
369
+ plugins: [], // An array of plugin objects to enable
370
+
371
+ containerClass: 'bsmContainer', // Class for container that wraps this widget
372
+ selectClass: 'bsmSelect', // Class for the newly created <select>
373
+ optionDisabledClass: 'bsmOptionDisabled', // Class for items that are already selected / disabled
374
+ listClass: 'bsmList', // Class for the list ($list)
375
+ listItemClass: 'bsmListItem', // Class for the <li> list items
376
+ listItemLabelClass: 'bsmListItemLabel', // Class for the label text that appears in list items
377
+ removeClass: 'bsmListItemRemove', // Class given to the 'remove' link
378
+ highlightClass: 'bsmHighlight' // Class given to the highlight <span>
379
+ };
380
+
381
+ })(jQuery);
js/jquery.bsmselect.sortable.js ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Better Select Multiple Sortable Plugin
3
+ *
4
+ * Copyright (c) 2010 by Victor Berchet - http://www.github.com/vicb
5
+ *
6
+ * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses.
7
+ *
8
+ * version: v1.1.1 - 2010-11-17
9
+ */
10
+ (function($) {
11
+ $.bsmSelect.plugins.sortable = function(sortConfig, options)
12
+ {
13
+ if (!(this instanceof arguments.callee)) {
14
+ return new arguments.callee(sortConfig, options);
15
+ }
16
+ this.sortConfig = sortConfig;
17
+ this.options = $.extend({}, this.defaultOpt, options || {});
18
+ }
19
+
20
+ $.extend($.bsmSelect.plugins.sortable.prototype, {
21
+ defaultOpt: {
22
+ listSortableClass: 'bsmListSortable'
23
+ },
24
+
25
+ init: function(bsm) {
26
+ var o = $.extend({}, this.options, bsm.options),
27
+ config = $.extend({}, this.sortConfig, { items: '.' + o.listItemClass }),
28
+ self = this;
29
+ bsm.$list.addClass(o.listSortableClass).sortable(config);
30
+ bsm.$original.bind('change', function(e, info) { self.onChange.call(self, bsm, e, info); } );
31
+ bsm.$list.bind('sortupdate', function(e, ui) { self.onSort.call(self, bsm, e, ui); } );
32
+ },
33
+
34
+ onChange: function(bsm, e, info) {
35
+ if (info && info.type == 'add' && !bsm.buildingSelect) {
36
+ info.option.detach()[bsm.options.addItemTarget == 'top' ? 'prependTo' : 'appendTo'](bsm.$original);
37
+ bsm.$list.sortable('refresh');
38
+ }
39
+ },
40
+
41
+ onSort: function(bsm, e, ui) {
42
+ $('.' + bsm.options.listItemClass, bsm.$list).each(function() {
43
+ $(this).data('bsm-option').data('orig-option').detach().appendTo(bsm.$original);
44
+ });
45
+ bsm.triggerOriginalChange($(ui.item).data('bsm-option').data('orig-option'), 'sort');
46
+ }
47
+ });
48
+ })(jQuery);
49
+
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: wordpress, database, database-reset, default-settings, default, wp-reset,
5
  License: GPL2
6
  Requires at least: 3.0
7
  Tested up to: 3.2.1
8
- Stable tag: 1.4
9
 
10
  A secure and easy way to reinitialize the WordPress database to its default settings.
11
 
@@ -32,6 +32,13 @@ I wanted a simple and painless way to obtain a fresh clean database without actu
32
  1. The plugin page - a more secure way of resetting your database.
33
 
34
  == Changelog ==
 
 
 
 
 
 
 
35
  = 1.4 =
36
  * Made quite a few changes to the translation files
37
  * Renamed french translation file for plugin format, not theme format
5
  License: GPL2
6
  Requires at least: 3.0
7
  Tested up to: 3.2.1
8
+ Stable tag: 2.0
9
 
10
  A secure and easy way to reinitialize the WordPress database to its default settings.
11
 
32
  1. The plugin page - a more secure way of resetting your database.
33
 
34
  == Changelog ==
35
+ = 2.0 =
36
+ * Added functionality to be able to select which tables you want to reset, rather than having to reset the entire database.
37
+ * Added bsmSelect for the multiple select.
38
+ * Modified screenshot-1.png.
39
+ * Fixed redirect bug
40
+ * 'Reactivate current plugins after reset' only shows if the options table is selected from the dropdown.
41
+
42
  = 1.4 =
43
  * Made quite a few changes to the translation files
44
  * Renamed french translation file for plugin format, not theme format
screenshot-1.jpg ADDED
Binary file
screenshot-1.png DELETED
Binary file
wp-reset.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WordPress Database Reset
4
  Plugin URI: https://github.com/chrisberthe/wordpress-database-reset
5
  Description: A plugin that allows you to reset the database to WordPress's initial state.
6
- Version: 1.4
7
  Author: Chris Berthe
8
  Author URI: https://github.com/chrisberthe
9
  License: GNU General Public License
@@ -23,6 +23,16 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
23
  */
24
  private $_active_plugins;
25
 
 
 
 
 
 
 
 
 
 
 
26
  /**
27
  * Loads default options
28
  *
@@ -33,6 +43,7 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
33
  add_action('init', array($this, 'init_language'));
34
  add_action('admin_init', array($this, 'wp_reset_init'));
35
  add_action('admin_init', array($this, '_redirect_user'));
 
36
  add_action('admin_footer', array($this, 'add_admin_javascript'));
37
  add_action('admin_menu', array($this, 'add_admin_menu'));
38
  add_filter('contextual_help', array($this, 'add_contextual_help'), 10, 2);
@@ -49,16 +60,39 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
49
  {
50
  global $wpdb, $current_user, $pagenow;
51
 
 
 
 
 
52
  if ( isset($_POST['wp-random-value'], $_POST['wp-reset-input']) && $_POST['wp-random-value'] == $_POST['wp-reset-input']
53
  && check_admin_referer('wp-nonce-submit', $this->_nonce) )
54
- {
55
- require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
 
 
 
 
 
 
56
 
 
57
  $blog_title = get_option('blogname');
58
  $public = get_option('blog_public');
 
 
 
59
 
60
- $admin_user = get_userdatabylogin('admin');
61
- $user = ( ! $admin_user || ! user_can( $admin_user->ID, 'update_core' ) ) ? $current_user : $admin_user;
 
 
 
 
 
 
 
 
 
62
 
63
  // Grab the currently active plugins
64
  if ( isset($_POST['wp-reset-check']) && $_POST['wp-reset-check'] == 'true' )
@@ -69,19 +103,31 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
69
  // Run through the database columns and drop all the tables
70
  if ( $db_tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}%'") )
71
  {
72
- foreach ( $db_tables as $db_table )
73
  {
74
  $wpdb->query("DROP TABLE {$db_table}");
75
  }
76
-
77
  // Return user keys and import variables
78
- $keys = wp_install($blog_title, $user->user_login, $user->user_email, $public);
79
  $this->_wp_update_user($user, $keys);
80
  }
 
 
 
 
 
 
 
 
 
 
 
81
 
82
- // Reactivate the plugins after reinstalling
83
- if ( $this->_reactivate_plugins() )
84
  {
 
 
85
  wp_redirect(admin_url($pagenow) . '?page=wp-reset&reset=success'); exit();
86
  }
87
 
@@ -108,6 +154,8 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
108
  ?>
109
  <?php if ( isset($_POST['wp-random-value'], $_POST['wp-reset-input']) && $_POST['wp-random-value'] != $_POST['wp-reset-input'] ) : ?>
110
  <div class="error"><p><strong><?php _e('You entered the wrong value - please try again', 'wp-reset') ?>.</strong></p></div>
 
 
111
  <?php elseif ( isset($_GET['reset']) && $_GET['reset'] == 'success' ) : ?>
112
  <div class="updated"><p><strong><?php _e('The WordPress database has been reset successfully', 'wp-reset') ?>.</strong></p></div>
113
  <?php endif ?>
@@ -115,21 +163,33 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
115
  <div class="wrap">
116
  <?php screen_icon() ?>
117
  <h2><?php _e('Database Reset', 'wp-reset') ?></h2>
118
- <p><?php _e('Please type in (or copy/paste) the generated value into the text box', 'wp-reset') ?>:&nbsp;&nbsp;<strong><?php echo $random_string ?></strong></p>
119
  <form action="" method="POST" id="wp-reset-form">
 
 
 
 
 
 
 
 
 
 
120
  <?php wp_nonce_field('wp-nonce-submit', $this->_nonce) ?>
121
  <input type="hidden" name="wp-random-value" value="<?php echo $random_string ?>" id="wp-random-value" />
122
  <input type="text" name="wp-reset-input" value="" id="wp-reset-input" />
123
  <input type="submit" name="wp-reset-submit" value="<?php _e('Reset Database', 'wp-reset') ?>" id="wp-reset-submit" class="button-primary" />
124
- <p>
125
- <label for="wp-reset-check">
126
- <input type="checkbox" name="wp-reset-check" id="wp-reset-check" checked="checked" value="true" />
127
- <?php _e('Reactivate current plugins after reset?', 'wp-reset') ?>
128
- </label>
129
- </p>
 
 
 
130
  </form>
131
 
132
- <?php if ( ! $admin_user || ! user_can( $admin_user->ID, 'update_core' ) ) : ?>
133
  <p style="margin-top: 25px"><?php printf(__('The default user <strong><u>admin</u></strong> was never created for this WordPress install. So <strong><u>%s</u></strong> will be recreated with its current password instead', 'wp-reset'), $current_user->user_login) ?>.</p>
134
  <?php else : ?>
135
  <p><?php _e('The default user <strong><u>admin</u></strong> will be recreated with its current password upon resetting', 'wp-reset') ?>.</p>
@@ -149,15 +209,34 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
149
  {
150
  ?>
151
  <script type="text/javascript">
152
- /* <![CDATA[ */
153
- jQuery('#wp-reset-submit').click(function() {
154
- var message = "<?php _e('Clicking OK will result in your database being reset to its initial settings. Continue?', 'wp-reset') ?>";
155
- var reset = confirm(message);
 
 
 
156
 
157
- if ( reset ) {
158
- jQuery('#wp-reset-form').submit();
159
- } else {
160
  return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  }
162
  });
163
  /* ]]> */
@@ -173,7 +252,7 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
173
  */
174
  function add_admin_menu()
175
  {
176
- if ( current_user_can( 'update_core' ) )
177
  {
178
  $this->_hook = add_submenu_page('tools.php', 'Database Reset', 'Database Reset', 'update_core', 'wp-reset', array($this, 'show_admin_page'));
179
  }
@@ -199,6 +278,22 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
199
  return $contextual_help;
200
  }
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  /**
203
  * Load language path
204
  *
@@ -248,7 +343,7 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
248
  function _fix_mail($mail)
249
  {
250
  $subject = __('WordPress Database Reset', 'wp-reset');
251
- $message = __('The WordPress database has been successfully reset to its default settings:', 'wp-reset');
252
  $password = __('Password: The password you chose during the install.', 'wp-reset');
253
 
254
  if ( stristr($mail['message'], 'Your new WordPress site has been successfully set up at:') )
@@ -262,27 +357,56 @@ if ( ! class_exists('cb_wp_reset') && is_admin() ) :
262
  }
263
 
264
  /**
265
- * Reactivates the plugins after reset
 
 
266
  *
267
  * @access private
268
- * @return TRUE on plugin reactivation, FALSE otherwise
269
  */
270
- function _reactivate_plugins()
271
  {
272
  global $wpdb;
273
 
274
- if ( ! empty($this->_active_plugins) )
275
  {
276
- // Replace the list of plugins with the 'old' list after the reset
277
- $query = $wpdb->prepare("UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", $this->_active_plugins, 'active_plugins');
278
-
279
- if ( $wpdb->query($query) )
280
  {
281
- return TRUE;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  }
283
  }
284
 
285
- return FALSE;
286
  }
287
 
288
  /**
3
  Plugin Name: WordPress Database Reset
4
  Plugin URI: https://github.com/chrisberthe/wordpress-database-reset
5
  Description: A plugin that allows you to reset the database to WordPress's initial state.
6
+ Version: 2.0
7
  Author: Chris Berthe
8
  Author URI: https://github.com/chrisberthe
9
  License: GNU General Public License
23
  */
24
  private $_active_plugins;
25
 
26
+ /**
27
+ * Tables to preserve
28
+ */
29
+ private $_tables;
30
+
31
+ /**
32
+ * WordPress database tables
33
+ */
34
+ private $_wp_tables;
35
+
36
  /**
37
  * Loads default options
38
  *
43
  add_action('init', array($this, 'init_language'));
44
  add_action('admin_init', array($this, 'wp_reset_init'));
45
  add_action('admin_init', array($this, '_redirect_user'));
46
+ add_action('admin_init', array($this, 'add_plugin_styles_and_scripts'));
47
  add_action('admin_footer', array($this, 'add_admin_javascript'));
48
  add_action('admin_menu', array($this, 'add_admin_menu'));
49
  add_filter('contextual_help', array($this, 'add_contextual_help'), 10, 2);
60
  {
61
  global $wpdb, $current_user, $pagenow;
62
 
63
+ // Grab the WordPress database tables
64
+ $this->_wp_tables = $wpdb->tables();
65
+
66
+ // Check for valid input - goes ahead and drops / resets tables
67
  if ( isset($_POST['wp-random-value'], $_POST['wp-reset-input']) && $_POST['wp-random-value'] == $_POST['wp-reset-input']
68
  && check_admin_referer('wp-nonce-submit', $this->_nonce) )
69
+ {
70
+ require_once(ABSPATH . '/wp-admin/includes/upgrade.php');
71
+
72
+ // No tables were selected
73
+ if ( ! isset($_POST['tables']) && empty($_POST['tables']) )
74
+ {
75
+ wp_redirect(admin_url($pagenow) . '?page=wp-reset&reset=no-select'); exit();
76
+ }
77
 
78
+ // Get current options
79
  $blog_title = get_option('blogname');
80
  $public = get_option('blog_public');
81
+
82
+ $admin_user = get_userdatabylogin('admin');
83
+ $user = ( ! $admin_user || ! user_can($admin_user->ID, 'update_core') ) ? $current_user : $admin_user;
84
 
85
+ // Get the selected tables
86
+ $tables = (isset($_POST['tables'])) ? array_flip($_POST['tables']) : array();
87
+
88
+ // Compare the selected tables against the ones in the database
89
+ $this->_tables = array_diff_key($this->_wp_tables, $tables);
90
+
91
+ // Preserve the data from the tables that are unique
92
+ if ( count($this->_tables) > 0 )
93
+ {
94
+ $backup_tables = $this->_backup_tables($this->_tables);
95
+ }
96
 
97
  // Grab the currently active plugins
98
  if ( isset($_POST['wp-reset-check']) && $_POST['wp-reset-check'] == 'true' )
103
  // Run through the database columns and drop all the tables
104
  if ( $db_tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}%'") )
105
  {
106
+ foreach ($db_tables as $db_table)
107
  {
108
  $wpdb->query("DROP TABLE {$db_table}");
109
  }
110
+
111
  // Return user keys and import variables
112
+ $keys = wp_install($blog_title, $user->user_login, $user->user_email, $public);
113
  $this->_wp_update_user($user, $keys);
114
  }
115
+
116
+ // Delete and replace tables with the backed up table data
117
+ if ( count($this->_tables) > 0 )
118
+ {
119
+ foreach ($this->_tables as $table)
120
+ {
121
+ $wpdb->query("DELETE FROM " . $table);
122
+ }
123
+
124
+ $this->_backup_tables($backup_tables, 'reset');
125
+ }
126
 
127
+ if ( ! empty($this->_active_plugins) )
 
128
  {
129
+ $wpdb->update($wpdb->options, array('option_value' => $this->_active_plugins), array('option_name' => 'active_plugins'));
130
+
131
  wp_redirect(admin_url($pagenow) . '?page=wp-reset&reset=success'); exit();
132
  }
133
 
154
  ?>
155
  <?php if ( isset($_POST['wp-random-value'], $_POST['wp-reset-input']) && $_POST['wp-random-value'] != $_POST['wp-reset-input'] ) : ?>
156
  <div class="error"><p><strong><?php _e('You entered the wrong value - please try again', 'wp-reset') ?>.</strong></p></div>
157
+ <?php elseif ( isset($_GET['reset']) && $_GET['reset'] == 'no-select') : ?>
158
+ <div class="error"><p><strong><?php _e('You did not select any database tables', 'wp-reset') ?>.</strong></p></div>
159
  <?php elseif ( isset($_GET['reset']) && $_GET['reset'] == 'success' ) : ?>
160
  <div class="updated"><p><strong><?php _e('The WordPress database has been reset successfully', 'wp-reset') ?>.</strong></p></div>
161
  <?php endif ?>
163
  <div class="wrap">
164
  <?php screen_icon() ?>
165
  <h2><?php _e('Database Reset', 'wp-reset') ?></h2>
 
166
  <form action="" method="POST" id="wp-reset-form">
167
+ <p><?php _e('Please choose from the following database tables the ones you would like to reset', 'wp-reset') ?>:</p>
168
+ <div id="select-buttons">
169
+ <span><a href='#' id="select-all"><?php _e('Select All', 'wp-reset') ?></a></span>
170
+ <select id="wp-tables" multiple="multiple" name="tables[]" onchange="changeHandler()">
171
+ <?php foreach ($this->_wp_tables as $key => $value) : ?>
172
+ <option><?php echo $key ?></option>
173
+ <?php endforeach ?>
174
+ </select>
175
+ </div>
176
+ <p><?php _e('Type in (or copy/paste) the generated value into the text box', 'wp-reset') ?>:&nbsp;&nbsp;<strong><?php echo $random_string ?></strong></p>
177
  <?php wp_nonce_field('wp-nonce-submit', $this->_nonce) ?>
178
  <input type="hidden" name="wp-random-value" value="<?php echo $random_string ?>" id="wp-random-value" />
179
  <input type="text" name="wp-reset-input" value="" id="wp-reset-input" />
180
  <input type="submit" name="wp-reset-submit" value="<?php _e('Reset Database', 'wp-reset') ?>" id="wp-reset-submit" class="button-primary" />
181
+ <img src="<?php echo plugins_url('css/i/ajax-loader.gif', __FILE__) ?>" alt="loader" id="loader" style="display: none" />
182
+ <div id="reactivate" style="display: none">
183
+ <p>
184
+ <label for="wp-reset-check">
185
+ <input type="checkbox" name="wp-reset-check" id="wp-reset-check" checked="checked" value="true" />
186
+ <?php _e('Reactivate current plugins after reset?', 'wp-reset') ?>
187
+ </label>
188
+ </p>
189
+ </div>
190
  </form>
191
 
192
+ <?php if ( ! $admin_user || ! user_can($admin_user->ID, 'update_core') ) : ?>
193
  <p style="margin-top: 25px"><?php printf(__('The default user <strong><u>admin</u></strong> was never created for this WordPress install. So <strong><u>%s</u></strong> will be recreated with its current password instead', 'wp-reset'), $current_user->user_login) ?>.</p>
194
  <?php else : ?>
195
  <p><?php _e('The default user <strong><u>admin</u></strong> will be recreated with its current password upon resetting', 'wp-reset') ?>.</p>
209
  {
210
  ?>
211
  <script type="text/javascript">
212
+ /* <![CDATA[ */
213
+ jQuery(function($) {
214
+ $('#wp-tables').bsmSelect({
215
+ animate: true,
216
+ title: "<?php _e('Select Table', 'wp-reset') ?>",
217
+ plugins: [$.bsmSelect.plugins.compatibility()]
218
+ });
219
 
220
+ $("#select-all").click(function() {
221
+ $("#wp-tables").children().attr("selected", "selected").end().change();
 
222
  return false;
223
+ });
224
+
225
+ $('#wp-reset-submit').click(function() {
226
+ var message = "<?php _e('Clicking OK will result in your database being reset to its initial settings. Continue?', 'wp-reset') ?>";
227
+ var reset = confirm(message);
228
+
229
+ if (reset) {
230
+ $('#wp-reset-form').submit();
231
+ $('#loader').show();
232
+ } else {
233
+ return false;
234
+ }
235
+ });
236
+
237
+ window.changeHandler = function() {
238
+ var op = $("#wp-tables option[value='options']:selected");
239
+ $('#reactivate').toggle(op.length > 0);
240
  }
241
  });
242
  /* ]]> */
252
  */
253
  function add_admin_menu()
254
  {
255
+ if ( current_user_can('update_core') )
256
  {
257
  $this->_hook = add_submenu_page('tools.php', 'Database Reset', 'Database Reset', 'update_core', 'wp-reset', array($this, 'show_admin_page'));
258
  }
278
  return $contextual_help;
279
  }
280
 
281
+ /**
282
+ * Adds any plugin styles to our page
283
+ *
284
+ * @access public
285
+ * @return void
286
+ */
287
+ function add_plugin_styles_and_scripts()
288
+ {
289
+ wp_enqueue_style('wordpress-reset-css', plugins_url('css/wp-reset.css', __FILE__));
290
+ wp_enqueue_style('bsmselect-css', plugins_url('css/jquery.bsmselect.css', __FILE__));
291
+
292
+ wp_enqueue_script('bsmselect', plugins_url('js/jquery.bsmselect.js', __FILE__));
293
+ wp_enqueue_script('bsmselect-compatibility', plugins_url('js/jquery.bsmselect.compatibility.js', __FILE__));
294
+ wp_enqueue_script('bsmselect-sortable', plugins_url('js/jquery.bsmselect.sortable.js', __FILE__));
295
+ }
296
+
297
  /**
298
  * Load language path
299
  *
343
  function _fix_mail($mail)
344
  {
345
  $subject = __('WordPress Database Reset', 'wp-reset');
346
+ $message = __('The tables you selected have been successfully reset to their default settings:', 'wp-reset');
347
  $password = __('Password: The password you chose during the install.', 'wp-reset');
348
 
349
  if ( stristr($mail['message'], 'Your new WordPress site has been successfully set up at:') )
357
  }
358
 
359
  /**
360
+ * Preserves all the results from the tables the user
361
+ * did not select from the drop-down. Also resets these
362
+ * results back after reinstalling WordPress.
363
  *
364
  * @access private
365
+ * @return array Backed up data if type backup, void if reset
366
  */
367
+ function _backup_tables($tables, $type = 'backup')
368
  {
369
  global $wpdb;
370
 
371
+ if ( is_array($tables) )
372
  {
373
+ switch ($type)
 
 
 
374
  {
375
+ case 'backup':
376
+ $backup_tables = array();
377
+
378
+ foreach ($tables as $table)
379
+ {
380
+ $backup_tables[$table] = $wpdb->get_results("SELECT * FROM " . $table);
381
+ }
382
+
383
+ return $backup_tables;
384
+ break;
385
+
386
+ case 'reset':
387
+ // Outer array of tables
388
+ foreach ($tables as $table_name => $table_data)
389
+ {
390
+ // Array of table rows
391
+ foreach ($table_data as $row)
392
+ {
393
+ $columns = $values = array();
394
+
395
+ // Loop through current object row
396
+ foreach ($row as $column => $value)
397
+ {
398
+ $columns[] = $column;
399
+ $values[] = $wpdb->escape($value);
400
+ }
401
+
402
+ $wpdb->query("INSERT INTO $table_name (" . implode(', ', $columns) . ") VALUES ('" . implode("', '", $values) . "')");
403
+ }
404
+ }
405
+ break;
406
  }
407
  }
408
 
409
+ return;
410
  }
411
 
412
  /**