| 1 |
/** |
| 2 |
* WP Reset |
| 3 |
* https://wpreset.com/ |
| 4 |
* (c) WebFactory Ltd, 2017-2021 |
| 5 |
*/ |
| 6 |
|
| 7 |
jQuery(document).ready(function ($) { |
| 8 |
// init tabs |
| 9 |
$('#wp-reset-tabs') |
| 10 |
.tabs({ |
| 11 |
create: function () { |
| 12 |
$('#loading-tabs').remove(); |
| 13 |
}, |
| 14 |
activate: function (event, ui) { |
| 15 |
localStorage.setItem('wp-reset-tabs', $('#wp-reset-tabs').tabs('option', 'active')); |
| 16 |
}, |
| 17 |
active: localStorage.getItem('wp-reset-tabs') || 0, |
| 18 |
}) |
| 19 |
.show(); |
| 20 |
|
| 21 |
// helper for swithcing tabs & linking anchors in different tabs |
| 22 |
$('.tools_page_wp-reset').on('click', '.change-tab', function (e) { |
| 23 |
e.preventDefault(); |
| 24 |
|
| 25 |
$('#wp-reset-tabs').tabs('option', 'active', $(this).data('tab')); |
| 26 |
|
| 27 |
// get the link anchor and scroll to it |
| 28 |
target = this.href.split('#')[1]; |
| 29 |
if (target) { |
| 30 |
$.scrollTo('#' + target, 500, { offset: { top: -50, left: 0 } }); |
| 31 |
} |
| 32 |
|
| 33 |
$(this).blur(); |
| 34 |
return false; |
| 35 |
}); // jump to tab/anchor helper |
| 36 |
|
| 37 |
// init tooltips |
| 38 |
$('.tooltip').tooltipster({ |
| 39 |
theme: ['tooltipster-punk', 'tooltipster-wpr'], |
| 40 |
delay: 0, |
| 41 |
}); |
| 42 |
|
| 43 |
// helper for scrolling to anchor |
| 44 |
$('.tools_page_wp-reset').on('click', '.scrollto', function (e) { |
| 45 |
e.preventDefault(); |
| 46 |
|
| 47 |
// get the link anchor and scroll to it |
| 48 |
target = this.href.split('#')[1]; |
| 49 |
if (target) { |
| 50 |
$.scrollTo('#' + target, 500, { offset: { top: -50, left: 0 } }); |
| 51 |
} |
| 52 |
|
| 53 |
$(this).blur(); |
| 54 |
return false; |
| 55 |
}); // scroll to anchor helper |
| 56 |
|
| 57 |
// toggle button dropdown menu |
| 58 |
$('.tools_page_wp-reset').on('click', '.button.dropdown-toggle', function (e) { |
| 59 |
e.preventDefault(); |
| 60 |
|
| 61 |
parent_dropdown = $(this).parent('.dropdown'); |
| 62 |
sibling_menu = $(this).siblings('.dropdown-menu'); |
| 63 |
|
| 64 |
$('.dropdown').not(parent_dropdown).removeClass('show'); |
| 65 |
$('.dropdown-menu').not(sibling_menu).removeClass('show'); |
| 66 |
|
| 67 |
$(parent_dropdown).toggleClass('show'); |
| 68 |
$(sibling_menu).toggleClass('show'); |
| 69 |
|
| 70 |
return false; |
| 71 |
}); // toggle button dropdown menu |
| 72 |
|
| 73 |
$(document).on('click', ':not(.dropdown-toggle), .dropdown-item', function () { |
| 74 |
wpr_close_dropdowns(); |
| 75 |
}); |
| 76 |
|
| 77 |
// delete transients |
| 78 |
$('.tools_page_wp-reset').on('click', '#delete-transients', function (e) { |
| 79 |
e.preventDefault(); |
| 80 |
|
| 81 |
run_tool(this, 'delete_transients'); |
| 82 |
|
| 83 |
return false; |
| 84 |
}); // delete transients |
| 85 |
|
| 86 |
// purge cache |
| 87 |
$('.tools_page_wp-reset').on('click', '#purge-cache', function (e) { |
| 88 |
e.preventDefault(); |
| 89 |
|
| 90 |
run_tool(this, 'purge_cache'); |
| 91 |
|
| 92 |
return false; |
| 93 |
}); // purge cache |
| 94 |
|
| 95 |
// delete uploads |
| 96 |
$('.tools_page_wp-reset').on('click', '#delete-uploads', function (e) { |
| 97 |
e.preventDefault(); |
| 98 |
|
| 99 |
run_tool(this, 'delete_uploads'); |
| 100 |
|
| 101 |
return false; |
| 102 |
}); // delete uploads |
| 103 |
|
| 104 |
// reset theme options (mods) |
| 105 |
$('.tools_page_wp-reset').on('click', '#reset-theme-options', function (e) { |
| 106 |
e.preventDefault(); |
| 107 |
|
| 108 |
run_tool(this, 'reset_theme_options'); |
| 109 |
|
| 110 |
return false; |
| 111 |
}); // reset theme options |
| 112 |
|
| 113 |
// delete themes |
| 114 |
$('.tools_page_wp-reset').on('click', '#delete-themes', function (e) { |
| 115 |
e.preventDefault(); |
| 116 |
|
| 117 |
run_tool(this, 'delete_themes'); |
| 118 |
|
| 119 |
return false; |
| 120 |
}); // delete themes |
| 121 |
|
| 122 |
// delete plugins |
| 123 |
$('.tools_page_wp-reset').on('click', '#delete-plugins', function (e) { |
| 124 |
e.preventDefault(); |
| 125 |
|
| 126 |
var button = this; |
| 127 |
var confirm_title = $(button).data('confirm-title') || wp_reset.confirm_title; |
| 128 |
|
| 129 |
var tools = [ |
| 130 |
{ |
| 131 |
tool: 'deactivate_plugins', |
| 132 |
description: 'Deactivating plugins.', |
| 133 |
extra_data: { keep_default_theme: 0, keep_current_theme: 0 }, |
| 134 |
}, |
| 135 |
{ |
| 136 |
tool: 'delete_plugins', |
| 137 |
description: 'Deleting plugins.', |
| 138 |
extra_data: { |
| 139 |
keep_wp_reset: 1, |
| 140 |
silent_deactivate: 0, |
| 141 |
}, |
| 142 |
}, |
| 143 |
]; |
| 144 |
var looper = $.Deferred().resolve(); |
| 145 |
|
| 146 |
confirm_action( |
| 147 |
confirm_title, |
| 148 |
$(button).data('text-confirm'), |
| 149 |
$(button).data('btn-confirm') || $(button).text(), |
| 150 |
wp_reset.cancel_button |
| 151 |
).then((result) => { |
| 152 |
if (!result.value) { |
| 153 |
return false; |
| 154 |
} |
| 155 |
|
| 156 |
wpr_swal.fire({ |
| 157 |
title: $(button).data('text-wait'), |
| 158 |
text: ' ', |
| 159 |
type: false, |
| 160 |
allowOutsideClick: false, |
| 161 |
allowEscapeKey: false, |
| 162 |
allowEnterKey: false, |
| 163 |
showConfirmButton: false, |
| 164 |
imageUrl: wp_reset.icon_url, |
| 165 |
onOpen: () => { |
| 166 |
$(wpr_swal.getImage()).addClass('wpr_rotating'); |
| 167 |
}, |
| 168 |
imageWidth: 100, |
| 169 |
imageHeight: 100, |
| 170 |
imageAlt: $(button).data('text-wait'), |
| 171 |
}); |
| 172 |
|
| 173 |
var failed = false; |
| 174 |
$.each(tools, function (i, data) { |
| 175 |
looper = looper.then(function () { |
| 176 |
if (failed) { |
| 177 |
return false; |
| 178 |
} |
| 179 |
wpr_swal.getContent().querySelector('#swal2-content').textContent = |
| 180 |
i + 1 + '/' + tools.length + ' - ' + data.description; |
| 181 |
return $.ajax({ |
| 182 |
data: { |
| 183 |
action: 'wp_reset_run_tool', |
| 184 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 185 |
tool: data.tool, |
| 186 |
extra_data: data.extra_data, |
| 187 |
}, |
| 188 |
url: ajaxurl, |
| 189 |
}) |
| 190 |
.done(function (response) { |
| 191 |
if (response.success) { |
| 192 |
failed = false; |
| 193 |
if (i == tools.length - 1) { |
| 194 |
if (response.data == 1) { |
| 195 |
msg = $(button).data('text-done-singular'); |
| 196 |
} else { |
| 197 |
msg = $(button).data('text-done').replace('%n', response.data); |
| 198 |
} |
| 199 |
wpr_swal_params = { icon: 'success', title: msg }; |
| 200 |
|
| 201 |
wpr_swal.fire(wpr_swal_params); |
| 202 |
} |
| 203 |
} else { |
| 204 |
wpr_swal.close(); |
| 205 |
wpr_swal.fire({ |
| 206 |
icon: 'error', |
| 207 |
title: wp_reset.documented_error, |
| 208 |
text: response.data, |
| 209 |
}); |
| 210 |
failed = true; |
| 211 |
return false; |
| 212 |
} |
| 213 |
}) |
| 214 |
.error(function (response) { |
| 215 |
wpr_swal.close(); |
| 216 |
wpr_swal.fire({ |
| 217 |
icon: 'error', |
| 218 |
title: wp_reset.undocumented_error, |
| 219 |
}); |
| 220 |
failed = true; |
| 221 |
return false; |
| 222 |
}); |
| 223 |
}); |
| 224 |
}); |
| 225 |
}); // confirm ok |
| 226 |
|
| 227 |
return false; |
| 228 |
}); // delete plugins |
| 229 |
|
| 230 |
// drop custom tables |
| 231 |
$('.tools_page_wp-reset').on('click', '#drop-custom-tables', function (e) { |
| 232 |
e.preventDefault(); |
| 233 |
|
| 234 |
run_tool(this, 'drop_custom_tables'); |
| 235 |
|
| 236 |
return false; |
| 237 |
}); // drop custom tables |
| 238 |
|
| 239 |
// truncate custom tables |
| 240 |
$('.tools_page_wp-reset').on('click', '#truncate-custom-tables', function (e) { |
| 241 |
e.preventDefault(); |
| 242 |
|
| 243 |
run_tool(this, 'truncate_custom_tables'); |
| 244 |
|
| 245 |
return false; |
| 246 |
}); // truncate custom tables |
| 247 |
|
| 248 |
// delete htaccess file |
| 249 |
$('.tools_page_wp-reset').on('click', '#delete-htaccess', function (e) { |
| 250 |
e.preventDefault(); |
| 251 |
|
| 252 |
run_tool(this, 'delete_htaccess'); |
| 253 |
|
| 254 |
return false; |
| 255 |
}); // delete htaccess file |
| 256 |
|
| 257 |
// delete auth cookies |
| 258 |
$('.tools_page_wp-reset').on('click', '#delete-wp-cookies', function (e) { |
| 259 |
e.preventDefault(); |
| 260 |
|
| 261 |
run_tool(this, 'delete_wp_cookies'); |
| 262 |
|
| 263 |
return false; |
| 264 |
}); // delete auth cookies |
| 265 |
|
| 266 |
// delete local data |
| 267 |
$('.tools_page_wp-reset').on('click', '#delete-local-data', function (e) { |
| 268 |
e.preventDefault(); |
| 269 |
var button = this; |
| 270 |
var confirm_title = $(button).data('confirm-title') || wp_reset.confirm_title; |
| 271 |
|
| 272 |
confirm_action( |
| 273 |
confirm_title, |
| 274 |
$(button).data('text-confirm'), |
| 275 |
$(button).data('btn-confirm'), |
| 276 |
wp_reset.cancel_button |
| 277 |
).then((result) => { |
| 278 |
if (!result.value) { |
| 279 |
return false; |
| 280 |
} |
| 281 |
|
| 282 |
cnt = wpr_clear_local(true, true); |
| 283 |
if (cnt == 1) { |
| 284 |
msg = $(button).data('text-done-singular'); |
| 285 |
} else { |
| 286 |
msg = $(button).data('text-done').replace('%n', cnt); |
| 287 |
} |
| 288 |
wpr_swal.fire({ icon: 'success', title: msg }); |
| 289 |
}); |
| 290 |
|
| 291 |
return false; |
| 292 |
}); // delete local data |
| 293 |
|
| 294 |
// compare snapshot |
| 295 |
$('#wpr-snapshots').on('click', '.compare-snapshot', 'click', function (e) { |
| 296 |
e.preventDefault(); |
| 297 |
uid = $(this).data('ss-uid'); |
| 298 |
button = $(this); |
| 299 |
|
| 300 |
block_ui($(button).data('wait-msg')); |
| 301 |
$.get({ |
| 302 |
url: ajaxurl, |
| 303 |
data: { |
| 304 |
action: 'wp_reset_run_tool', |
| 305 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 306 |
tool: 'compare_snapshots', |
| 307 |
extra_data: uid, |
| 308 |
}, |
| 309 |
}) |
| 310 |
.always(function (data) { |
| 311 |
wpr_swal.close(); |
| 312 |
}) |
| 313 |
.done(function (data) { |
| 314 |
if (data.success) { |
| 315 |
msg = $(button).data('title').replace('%s', $(button).data('name')); |
| 316 |
wpr_swal.fire({ |
| 317 |
width: '90%', |
| 318 |
title: msg, |
| 319 |
html: data.data, |
| 320 |
showConfirmButton: false, |
| 321 |
allowEnterKey: false, |
| 322 |
focusConfirm: false, |
| 323 |
showCloseButton: true, |
| 324 |
customClass: 'compare-snapshots', |
| 325 |
}); |
| 326 |
} else { |
| 327 |
wpr_swal.fire({ |
| 328 |
icon: 'error', |
| 329 |
title: wp_reset.documented_error + ' ' + data.data, |
| 330 |
}); |
| 331 |
} |
| 332 |
}) |
| 333 |
.fail(function (data) { |
| 334 |
wpr_swal.fire({ icon: 'error', title: wp_reset.undocumented_error }); |
| 335 |
}); |
| 336 |
|
| 337 |
return false; |
| 338 |
}); // compare snapshot |
| 339 |
|
| 340 |
// restore snapshot |
| 341 |
$('#wpr-snapshots').on('click', '.restore-snapshot', 'click', function (e) { |
| 342 |
e.preventDefault(); |
| 343 |
uid = $(this).data('ss-uid'); |
| 344 |
|
| 345 |
run_tool(this, 'restore_snapshot', uid); |
| 346 |
|
| 347 |
return false; |
| 348 |
}); // restore snapshot |
| 349 |
|
| 350 |
// download snapshot |
| 351 |
$('#wpr-snapshots').on('click', '.download-snapshot', 'click', function (e) { |
| 352 |
e.preventDefault(); |
| 353 |
uid = $(this).data('ss-uid'); |
| 354 |
button = this; |
| 355 |
|
| 356 |
block_ui($(this).data('wait-msg')); |
| 357 |
$.get({ |
| 358 |
url: ajaxurl, |
| 359 |
data: { |
| 360 |
action: 'wp_reset_run_tool', |
| 361 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 362 |
tool: 'download_snapshot', |
| 363 |
extra_data: uid, |
| 364 |
}, |
| 365 |
}) |
| 366 |
.always(function (data) { |
| 367 |
wpr_swal.close(); |
| 368 |
}) |
| 369 |
.done(function (data) { |
| 370 |
if (data.success) { |
| 371 |
msg = $(button).data('success-msg').replace('%s', data.data); |
| 372 |
wpr_swal.fire({ icon: 'success', title: msg }); |
| 373 |
} else { |
| 374 |
wpr_swal.fire({ |
| 375 |
icon: 'error', |
| 376 |
title: wp_reset.documented_error + ' ' + data.data, |
| 377 |
}); |
| 378 |
} |
| 379 |
}) |
| 380 |
.fail(function (data) { |
| 381 |
wpr_swal.fire({ icon: 'error', title: wp_reset.undocumented_error }); |
| 382 |
}); |
| 383 |
|
| 384 |
return false; |
| 385 |
}); // download snapshot |
| 386 |
|
| 387 |
// delete snapshot |
| 388 |
$('#wpr-snapshots').on('click', '.delete-snapshot', 'click', function (e) { |
| 389 |
e.preventDefault(); |
| 390 |
uid = $(this).data('ss-uid'); |
| 391 |
|
| 392 |
run_tool(this, 'delete_snapshot', uid); |
| 393 |
|
| 394 |
return false; |
| 395 |
}); // delete snapshot |
| 396 |
|
| 397 |
// create snapshot |
| 398 |
$('.tools_page_wp-reset').on('click', '.create-new-snapshot', function (e) { |
| 399 |
e.preventDefault(); |
| 400 |
|
| 401 |
description = $(this).data('description') || ''; |
| 402 |
|
| 403 |
wpr_swal |
| 404 |
.fire({ |
| 405 |
title: wp_reset.snapshot_title, |
| 406 |
icon: 'question', |
| 407 |
text: wp_reset.snapshot_text, |
| 408 |
input: 'text', |
| 409 |
inputValue: description, |
| 410 |
inputPlaceholder: wp_reset.snapshot_placeholder, |
| 411 |
showCancelButton: true, |
| 412 |
focusConfirm: false, |
| 413 |
confirmButtonText: wp_reset.snapshot_confirm, |
| 414 |
cancelButtonText: wp_reset.cancel_button, |
| 415 |
width: 600, |
| 416 |
}) |
| 417 |
.then((result) => { |
| 418 |
if (typeof result.value != 'undefined') { |
| 419 |
block = block_ui(wp_reset.snapshot_wait); |
| 420 |
$.get({ |
| 421 |
url: ajaxurl, |
| 422 |
data: { |
| 423 |
action: 'wp_reset_run_tool', |
| 424 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 425 |
tool: 'create_snapshot', |
| 426 |
extra_data: result.value, |
| 427 |
}, |
| 428 |
}) |
| 429 |
.always(function (data) { |
| 430 |
wpr_swal.close(); |
| 431 |
}) |
| 432 |
.done(function (data) { |
| 433 |
if (data.success) { |
| 434 |
wpr_swal |
| 435 |
.fire({ |
| 436 |
icon: 'success', |
| 437 |
title: wp_reset.snapshot_success, |
| 438 |
timer: 2000, |
| 439 |
timerProgressBar: true, |
| 440 |
showConfirmButton: true, |
| 441 |
}) |
| 442 |
.then((result) => { |
| 443 |
location.reload(); |
| 444 |
}); |
| 445 |
} else { |
| 446 |
wpr_swal.fire({ |
| 447 |
icon: 'error', |
| 448 |
title: wp_reset.documented_error + ' ' + data.data, |
| 449 |
}); |
| 450 |
} |
| 451 |
}) |
| 452 |
.fail(function (data) { |
| 453 |
wpr_swal.fire({ |
| 454 |
icon: 'error', |
| 455 |
title: wp_reset.undocumented_error, |
| 456 |
}); |
| 457 |
}); |
| 458 |
} // if confirmed |
| 459 |
}); |
| 460 |
|
| 461 |
return false; |
| 462 |
}); // create snapshot |
| 463 |
|
| 464 |
// show/hide extra table info in snapshot diff |
| 465 |
$('body.tools_page_wp-reset').on('click', '.header-row', function (e) { |
| 466 |
e.preventDefault(); |
| 467 |
|
| 468 |
parent = $(this).parents('div.wpr-table-container > table > tbody'); |
| 469 |
$(' > tr:not(.header-row)', parent).toggleClass('hidden'); |
| 470 |
|
| 471 |
$('span.dashicons', parent).toggleClass('dashicons-arrow-down-alt2').toggleClass('dashicons-arrow-up-alt2'); |
| 472 |
|
| 473 |
return false; |
| 474 |
}); // show hide extra info in diff |
| 475 |
|
| 476 |
// standard way of running a tool, with confirmation, loading and success message |
| 477 |
function run_tool(button, tool_name, extra_data) { |
| 478 |
var confirm_title = $(button).data('confirm-title') || wp_reset.confirm_title; |
| 479 |
|
| 480 |
wpr_close_dropdowns(); |
| 481 |
|
| 482 |
confirm_action( |
| 483 |
confirm_title, |
| 484 |
$(button).data('text-confirm'), |
| 485 |
$(button).data('btn-confirm'), |
| 486 |
wp_reset.cancel_button |
| 487 |
).then((result) => { |
| 488 |
if (result.value) { |
| 489 |
block = block_ui($(button).data('text-wait')); |
| 490 |
$.get({ |
| 491 |
url: ajaxurl, |
| 492 |
data: { |
| 493 |
action: 'wp_reset_run_tool', |
| 494 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 495 |
tool: tool_name, |
| 496 |
extra_data: extra_data, |
| 497 |
}, |
| 498 |
}) |
| 499 |
.always(function (data) { |
| 500 |
wpr_swal.close(); |
| 501 |
}) |
| 502 |
.done(function (data) { |
| 503 |
if (data.success) { |
| 504 |
if (data.data == 1) { |
| 505 |
msg = $(button).data('text-done-singular'); |
| 506 |
} else { |
| 507 |
msg = $(button).data('text-done').replace('%n', data.data); |
| 508 |
} |
| 509 |
wpr_swal |
| 510 |
.fire({ |
| 511 |
icon: 'success', |
| 512 |
title: msg, |
| 513 |
timer: 2000, |
| 514 |
timerProgressBar: true, |
| 515 |
}) |
| 516 |
.then(() => { |
| 517 |
if (tool_name == 'restore_snapshot') { |
| 518 |
location.reload(); |
| 519 |
} |
| 520 |
}); |
| 521 |
if (tool_name == 'delete_snapshot') { |
| 522 |
$('#wpr-ss-' + extra_data).remove(); |
| 523 |
if ($('#wpr-snapshots tr').length <= 1) { |
| 524 |
$('#wpr-snapshots').hide(); |
| 525 |
$('#ss-no-snapshots').show(); |
| 526 |
} |
| 527 |
} |
| 528 |
} else { |
| 529 |
wpr_swal.fire({ |
| 530 |
icon: 'error', |
| 531 |
title: wp_reset.documented_error + ' ' + data.data, |
| 532 |
}); |
| 533 |
} |
| 534 |
}) |
| 535 |
.fail(function (data) { |
| 536 |
wpr_swal.fire({ |
| 537 |
icon: 'error', |
| 538 |
title: wp_reset.undocumented_error, |
| 539 |
}); |
| 540 |
}); |
| 541 |
} // if confirmed |
| 542 |
}); |
| 543 |
} // run_tool |
| 544 |
|
| 545 |
// display a message while an action is performed |
| 546 |
function block_ui(message) { |
| 547 |
tmp = wpr_swal.fire({ |
| 548 |
text: message, |
| 549 |
type: false, |
| 550 |
imageUrl: wp_reset.icon_url, |
| 551 |
onOpen: () => { |
| 552 |
$(wpr_swal.getImage()).addClass('rotating'); |
| 553 |
}, |
| 554 |
imageWidth: 100, |
| 555 |
imageHeight: 100, |
| 556 |
imageAlt: message, |
| 557 |
allowOutsideClick: false, |
| 558 |
allowEscapeKey: false, |
| 559 |
allowEnterKey: false, |
| 560 |
showConfirmButton: false, |
| 561 |
}); |
| 562 |
|
| 563 |
return tmp; |
| 564 |
} // block_ui |
| 565 |
|
| 566 |
// display dialog to confirm action |
| 567 |
function confirm_action(title, question, btn_confirm, btn_cancel) { |
| 568 |
tmp = wpr_swal.fire({ |
| 569 |
title: title, |
| 570 |
icon: 'question', |
| 571 |
html: question, |
| 572 |
showCancelButton: true, |
| 573 |
focusConfirm: false, |
| 574 |
focusCancel: true, |
| 575 |
confirmButtonText: btn_confirm, |
| 576 |
cancelButtonText: btn_cancel, |
| 577 |
confirmButtonColor: '#dd3036', |
| 578 |
width: 650, |
| 579 |
}); |
| 580 |
|
| 581 |
return tmp; |
| 582 |
} // confirm_action |
| 583 |
|
| 584 |
$('#wp_reset_form').on('submit', function (e, confirmed) { |
| 585 |
if (!confirmed) { |
| 586 |
$('#wp_reset_submit').trigger('click'); |
| 587 |
e.preventDefault(); |
| 588 |
return false; |
| 589 |
} |
| 590 |
|
| 591 |
$(this).off('submit').submit(); |
| 592 |
return true; |
| 593 |
}); // bypass default submit behaviour |
| 594 |
|
| 595 |
$('#wp_reset_submit').click(function (e) { |
| 596 |
if ($('#wp_reset_confirm').val() !== 'reset') { |
| 597 |
wpr_swal.fire({ |
| 598 |
title: wp_reset.invalid_confirmation_title, |
| 599 |
text: wp_reset.invalid_confirmation, |
| 600 |
icon: 'error', |
| 601 |
confirmButtonText: wp_reset.ok_button, |
| 602 |
}); |
| 603 |
|
| 604 |
e.preventDefault(); |
| 605 |
return false; |
| 606 |
} // wrong confirmation code |
| 607 |
|
| 608 |
message = wp_reset.confirm1 + '<br>' + wp_reset.confirm2; |
| 609 |
wpr_swal |
| 610 |
.fire({ |
| 611 |
title: wp_reset.confirm_title_reset, |
| 612 |
icon: 'question', |
| 613 |
html: message, |
| 614 |
showCancelButton: true, |
| 615 |
focusConfirm: false, |
| 616 |
focusCancel: true, |
| 617 |
confirmButtonText: wp_reset.confirm_button, |
| 618 |
cancelButtonText: wp_reset.cancel_button, |
| 619 |
confirmButtonColor: '#dd3036', |
| 620 |
width: 600, |
| 621 |
}) |
| 622 |
.then((result) => { |
| 623 |
if (result.value === true) { |
| 624 |
block_ui(wp_reset.doing_reset); |
| 625 |
$('#wp_reset_form').trigger('submit', true); |
| 626 |
} |
| 627 |
}); |
| 628 |
|
| 629 |
e.preventDefault(); |
| 630 |
return false; |
| 631 |
}); // reset submit |
| 632 |
|
| 633 |
// collapse / expand card |
| 634 |
$('.tools_page_wp-reset').on('click', '.toggle-card', function (e, skip_anim) { |
| 635 |
e.preventDefault(); |
| 636 |
|
| 637 |
card = $(this).parents('.card').toggleClass('collapsed'); |
| 638 |
$('.dashicons', this).toggleClass('dashicons-arrow-up-alt2').toggleClass('dashicons-arrow-down-alt2'); |
| 639 |
$(this).blur(); |
| 640 |
|
| 641 |
if (typeof skip_anim != 'undefined' && skip_anim) { |
| 642 |
$(card).find('.card-body').toggle(); |
| 643 |
} else { |
| 644 |
$(card).find('.card-body').slideToggle(500); |
| 645 |
} |
| 646 |
|
| 647 |
cards = localStorage.getItem('wp-reset-cards'); |
| 648 |
if (cards == null) { |
| 649 |
cards = new Object(); |
| 650 |
} else { |
| 651 |
cards = JSON.parse(cards); |
| 652 |
} |
| 653 |
|
| 654 |
card_id = card.attr('id') || $('h4', card).attr('id') || ''; |
| 655 |
|
| 656 |
if (card.hasClass('collapsed')) { |
| 657 |
cards[card_id] = 'collapsed'; |
| 658 |
} else { |
| 659 |
cards[card_id] = 'expanded'; |
| 660 |
} |
| 661 |
localStorage.setItem('wp-reset-cards', JSON.stringify(cards)); |
| 662 |
|
| 663 |
return false; |
| 664 |
}); // toggle-card |
| 665 |
|
| 666 |
// handle saved and preset cards' state |
| 667 |
cards_state = localStorage.getItem('wp-reset-cards'); |
| 668 |
if (cards_state != null) { |
| 669 |
cards_state = JSON.parse(cards_state); |
| 670 |
} else { |
| 671 |
cards_state = new Object(); |
| 672 |
} |
| 673 |
|
| 674 |
cards = $('.card'); |
| 675 |
$.each(cards, function (index, card) { |
| 676 |
card_name = $('h4', card).attr('id'); |
| 677 |
if (!card_name) { |
| 678 |
return; |
| 679 |
} |
| 680 |
|
| 681 |
if (typeof cards_state == 'object' && cards_state.hasOwnProperty(card_name)) { |
| 682 |
if (cards_state[card_name] == 'collapsed') { |
| 683 |
$('a.toggle-card', card).trigger('click', true); |
| 684 |
} |
| 685 |
} else { |
| 686 |
if ($(card).hasClass('default-collapsed')) { |
| 687 |
$('a.toggle-card', card).trigger('click', true); |
| 688 |
} |
| 689 |
} |
| 690 |
}); |
| 691 |
|
| 692 |
// dismiss notice / pointer |
| 693 |
$('.wpr-dismiss-notice').on('click', function (e) { |
| 694 |
notice_name = $(this).data('notice'); |
| 695 |
if (!notice_name) { |
| 696 |
return true; |
| 697 |
} |
| 698 |
|
| 699 |
$.get(ajaxurl, { |
| 700 |
notice_name: notice_name, |
| 701 |
_ajax_nonce: wp_reset.nonce_dismiss_notice, |
| 702 |
action: 'wp_reset_dismiss_notice', |
| 703 |
}); |
| 704 |
|
| 705 |
$(this).parents('.notice-wrapper').fadeOut(); |
| 706 |
|
| 707 |
e.preventDefault(); |
| 708 |
return false; |
| 709 |
}); // dismiss notice |
| 710 |
|
| 711 |
// turn questions into checkboxes |
| 712 |
$('.question-wrapper').on('click', function (e) { |
| 713 |
if ($(this).hasClass('selected')) { |
| 714 |
$(this).removeClass('selected'); |
| 715 |
} else { |
| 716 |
if ($('.question-wrapper.selected').length >= 2) { |
| 717 |
wpr_swal.fire({ |
| 718 |
icon: 'error', |
| 719 |
allowOutsideClick: false, |
| 720 |
text: 'You can choose only up to 2 features at a time.', |
| 721 |
}); |
| 722 |
} else { |
| 723 |
$(this).addClass('selected'); |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
e.preventDefault(); |
| 728 |
return false; |
| 729 |
}); |
| 730 |
|
| 731 |
// todo: not finished |
| 732 |
$('.tools_page_wp-reset').on('click', '.button-pro-feature, .pro-feature', function (e) { |
| 733 |
e.preventDefault(); |
| 734 |
this.blur(); |
| 735 |
|
| 736 |
tool_id = $(this).data('feature') || $('.pro-feature', this).data('feature'); |
| 737 |
if (!tool_id) { |
| 738 |
$('#wp-reset-tabs').tabs('option', 'active', 5); |
| 739 |
$.scrollTo($('#pro-pricing'), 500, { offset: { top: -50, left: 0 } }); |
| 740 |
return; |
| 741 |
} |
| 742 |
|
| 743 |
details = $('#pro-feature-details-' + tool_id); |
| 744 |
if (details.length != 1) { |
| 745 |
$('#wp-reset-tabs').tabs('option', 'active', 5); |
| 746 |
$.scrollTo($('#pro-pricing'), 500, { offset: { top: -50, left: 0 } }); |
| 747 |
return; |
| 748 |
} |
| 749 |
|
| 750 |
wpr_swal |
| 751 |
.fire({ |
| 752 |
title: tool_id, |
| 753 |
html: 'Dialog content', |
| 754 |
footer: |
| 755 |
'See everything WP Reset PRO offers on <a target="_blank" href="https://wpreset.com">wpreset.com</a>', |
| 756 |
icon: '', |
| 757 |
showCloseButton: true, |
| 758 |
focusConfirm: true, |
| 759 |
confirmButtonText: 'Grab the 30% discount', |
| 760 |
}) |
| 761 |
.then((result) => { |
| 762 |
if (result.value) { |
| 763 |
$('#wp-reset-tabs').tabs('option', 'active', 5); |
| 764 |
$.scrollTo($('#pro-pricing'), 500, { |
| 765 |
offset: { top: -50, left: 0 }, |
| 766 |
}); |
| 767 |
} |
| 768 |
}); |
| 769 |
|
| 770 |
return false; |
| 771 |
}); |
| 772 |
|
| 773 |
$('#show-table-details').on('click', function (e) { |
| 774 |
e.preventDefault(); |
| 775 |
|
| 776 |
$.get({ |
| 777 |
url: ajaxurl, |
| 778 |
data: { |
| 779 |
action: 'wp_reset_run_tool', |
| 780 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 781 |
tool: 'get_table_details', |
| 782 |
}, |
| 783 |
}) |
| 784 |
.done(function (data) { |
| 785 |
if (data.success) { |
| 786 |
$('#wpr-table-details').html(data.data); |
| 787 |
} else { |
| 788 |
wpr_swal.fire({ |
| 789 |
type: 'error', |
| 790 |
title: wp_reset.documented_error + ' ' + data.data, |
| 791 |
}); |
| 792 |
} |
| 793 |
}) |
| 794 |
.fail(function (data) { |
| 795 |
wpr_swal.fire({ type: 'error', title: wp_reset.undocumented_error }); |
| 796 |
}); |
| 797 |
|
| 798 |
return false; |
| 799 |
}); // show table details |
| 800 |
|
| 801 |
$('#wpr-save-license').on('click', function (e) { |
| 802 |
e.preventDefault(); |
| 803 |
|
| 804 |
button = this; |
| 805 |
safe_refresh = true; |
| 806 |
|
| 807 |
block = block_ui($(button).data('text-wait')); |
| 808 |
wf_licensing_verify_licence_ajax('wpr', $('#wpr-license-key').val(), button); |
| 809 |
|
| 810 |
return; |
| 811 |
}); // license activation button |
| 812 |
|
| 813 |
$('#wpr-keyless-activation').on('click', function (e) { |
| 814 |
e.preventDefault(); |
| 815 |
|
| 816 |
button = this; |
| 817 |
safe_refresh = true; |
| 818 |
|
| 819 |
block = block_ui($(button).data('text-wait')); |
| 820 |
wf_licensing_verify_licence_ajax('wpr', 'keyless', button); |
| 821 |
|
| 822 |
return; |
| 823 |
}); // keyless license activation button |
| 824 |
|
| 825 |
$('#wpr-deactivate-license').on('click', function (e) { |
| 826 |
e.preventDefault(); |
| 827 |
|
| 828 |
button = this; |
| 829 |
safe_refresh = true; |
| 830 |
|
| 831 |
block = block_ui($(button).data('text-wait')); |
| 832 |
wf_licensing_deactivate_licence_ajax('wpr', $('#wpr-license-key').val(), button); |
| 833 |
|
| 834 |
return; |
| 835 |
}); // deactivate license button |
| 836 |
|
| 837 |
$('#wpr-license-key').on('keypress', function (e) { |
| 838 |
if (e.keyCode == 13) { |
| 839 |
e.preventDefault(); |
| 840 |
$('#wpr-save-license').trigger('click'); |
| 841 |
} |
| 842 |
}); // trigger license save on enter |
| 843 |
|
| 844 |
// Collections |
| 845 |
// for demo purposes only |
| 846 |
var collections_ajax_queue = []; |
| 847 |
var collections_ajax_queue_count = 0; |
| 848 |
var collections_ajax_queue_index = 0; |
| 849 |
var collections_errors = []; |
| 850 |
var collections_retried = false; |
| 851 |
wp_reset.collections = []; |
| 852 |
wp_reset.collections[1] = { |
| 853 |
id: 1, |
| 854 |
name: 'Must-have WordPress Plugins', |
| 855 |
created: '2020-04-01', |
| 856 |
items: [], |
| 857 |
}; |
| 858 |
wp_reset.collections[1].items[10] = { |
| 859 |
id: '10', |
| 860 |
type: 'plugin', |
| 861 |
source: 'repo', |
| 862 |
note: '', |
| 863 |
slug: 'eps-301-redirects', |
| 864 |
name: '301 Redirects', |
| 865 |
version: '0.4', |
| 866 |
}; |
| 867 |
|
| 868 |
wp_reset.collections[1].items[11] = { |
| 869 |
id: '11', |
| 870 |
type: 'plugin', |
| 871 |
source: 'repo', |
| 872 |
note: '', |
| 873 |
slug: 'classic-editor', |
| 874 |
name: 'Classic Editor', |
| 875 |
version: '0.4', |
| 876 |
}; |
| 877 |
|
| 878 |
wp_reset.collections[1].items[12] = { |
| 879 |
id: '12', |
| 880 |
type: 'plugin', |
| 881 |
source: 'repo', |
| 882 |
note: '', |
| 883 |
slug: 'simple-author-box', |
| 884 |
name: 'Simple Author Box', |
| 885 |
version: '0.4', |
| 886 |
}; |
| 887 |
|
| 888 |
wp_reset.collections[1].items[13] = { |
| 889 |
id: '13', |
| 890 |
type: 'plugin', |
| 891 |
source: 'repo', |
| 892 |
note: '', |
| 893 |
slug: 'sticky-menu-or-anything-on-scroll', |
| 894 |
name: 'Sticky Menu (or Anything!) on Scroll', |
| 895 |
version: '0.4', |
| 896 |
}; |
| 897 |
|
| 898 |
wp_reset.collections[1].items[14] = { |
| 899 |
id: '14', |
| 900 |
type: 'plugin', |
| 901 |
source: 'repo', |
| 902 |
note: '', |
| 903 |
slug: 'under-construction-page', |
| 904 |
name: 'UnderConstructionPage', |
| 905 |
version: '0.4', |
| 906 |
}; |
| 907 |
|
| 908 |
wp_reset.collections[1].items[15] = { |
| 909 |
id: '15', |
| 910 |
type: 'plugin', |
| 911 |
source: 'repo', |
| 912 |
note: '', |
| 913 |
slug: 'wp-external-links', |
| 914 |
name: 'WP External Links', |
| 915 |
version: '0.4', |
| 916 |
}; |
| 917 |
|
| 918 |
$(document).on('click', '.install-collection', function (e) { |
| 919 |
do_delete = $(this).data('delete'); |
| 920 |
do_activate = $(this).data('activate'); |
| 921 |
collection_id = $(this).parents('.card').data('collection-id'); |
| 922 |
show_install_collection(collection_id, do_delete, do_activate); |
| 923 |
}); |
| 924 |
|
| 925 |
// install collection item |
| 926 |
$('.tools_page_wp-reset').on('click', '.install-collection-item', function (e) { |
| 927 |
e.preventDefault(); |
| 928 |
|
| 929 |
wpr_close_dropdowns(); |
| 930 |
|
| 931 |
collection_id = $(this).parents('.card').data('collection-id'); |
| 932 |
collection_item_id = $(this).parents('tr').data('collection-item-id'); |
| 933 |
do_activate = $(this).data('activate'); |
| 934 |
|
| 935 |
item_data = wp_reset.collections[collection_id]['items'][collection_item_id]; |
| 936 |
|
| 937 |
wpr_swal |
| 938 |
.fire({ |
| 939 |
title: 'Installing <br />' + item_data['name'], |
| 940 |
html: '<div class="wpr-collections-installer"></div>', |
| 941 |
width: 600, |
| 942 |
onRender: function () { |
| 943 |
collections_ajax_queue.push({ |
| 944 |
slug: item_data.slug, |
| 945 |
name: item_data.name, |
| 946 |
extra_data: { |
| 947 |
source: item_data.source, |
| 948 |
collection_id: collection_id, |
| 949 |
collection_item_id: collection_item_id, |
| 950 |
}, |
| 951 |
action: 'install_' + item_data.type, |
| 952 |
}); |
| 953 |
collections_ajax_queue.push({ |
| 954 |
slug: item_data.slug, |
| 955 |
name: item_data.name, |
| 956 |
action: 'check_install_' + item_data.type, |
| 957 |
}); |
| 958 |
|
| 959 |
$('.wpr-collections-installer').append( |
| 960 |
'<div class="wpr-collections-installer-message" data-action="' + |
| 961 |
item_data.slug + |
| 962 |
'_install_' + |
| 963 |
item_data.type + |
| 964 |
'"><span class="dashicons"></span>' + |
| 965 |
wp_reset.installing + |
| 966 |
' ' + |
| 967 |
item_data.name + |
| 968 |
'</div>' |
| 969 |
); |
| 970 |
|
| 971 |
if (do_activate) { |
| 972 |
collections_ajax_queue.push({ |
| 973 |
slug: item_data.slug, |
| 974 |
name: item_data.name, |
| 975 |
action: 'activate_' + item_data.type, |
| 976 |
extra_data: { |
| 977 |
source: item_data.source, |
| 978 |
collection_id: collection_id, |
| 979 |
collection_item_id: collection_item_id, |
| 980 |
}, |
| 981 |
}); |
| 982 |
collections_ajax_queue.push({ |
| 983 |
slug: item_data.slug, |
| 984 |
name: item_data.name, |
| 985 |
action: 'check_activate_' + item_data.type, |
| 986 |
}); |
| 987 |
|
| 988 |
$('.wpr-collections-installer').append( |
| 989 |
'<div class="wpr-collections-installer-message" data-action="' + |
| 990 |
item_data.slug + |
| 991 |
'_activate_' + |
| 992 |
item_data.type + |
| 993 |
'"><span class="dashicons"></span>' + |
| 994 |
wp_reset.activating + |
| 995 |
' ' + |
| 996 |
item_data.name + |
| 997 |
'</div>' |
| 998 |
); |
| 999 |
} |
| 1000 |
collections_do_ajax(); |
| 1001 |
}, |
| 1002 |
allowOutsideClick: false, |
| 1003 |
allowEscapeKey: false, |
| 1004 |
allowEnterKey: false, |
| 1005 |
showCancelButton: true, |
| 1006 |
confirmButtonText: 'OK', |
| 1007 |
}) |
| 1008 |
.then((result) => { |
| 1009 |
collections_ajax_queue = []; |
| 1010 |
}); |
| 1011 |
|
| 1012 |
return false; |
| 1013 |
}); // install collection item |
| 1014 |
|
| 1015 |
// show install collection popup |
| 1016 |
function show_install_collection(collection_id, do_delete, do_activate) { |
| 1017 |
wpr_swal |
| 1018 |
.fire({ |
| 1019 |
title: 'Installing collection<br />' + wp_reset.collections[collection_id]['name'], |
| 1020 |
html: '<div class="wpr-collections-installer"></div>', |
| 1021 |
width: 600, |
| 1022 |
onRender: function () { |
| 1023 |
install_collection(collection_id, do_activate, do_delete); |
| 1024 |
}, |
| 1025 |
allowOutsideClick: false, |
| 1026 |
allowEscapeKey: false, |
| 1027 |
allowEnterKey: false, |
| 1028 |
showCancelButton: true, |
| 1029 |
showConfirmButton: false, |
| 1030 |
confirmButtonText: 'OK', |
| 1031 |
}) |
| 1032 |
.then((result) => { |
| 1033 |
collections_ajax_queue = []; |
| 1034 |
}); |
| 1035 |
} // show install collection popup |
| 1036 |
|
| 1037 |
// create install collection queue and add popup content |
| 1038 |
function install_collection(collection_id, do_activate, do_delete) { |
| 1039 |
collections_ajax_queue = []; |
| 1040 |
collections_ajax_queue_count = 0; |
| 1041 |
collections_ajax_queue_index = 0; |
| 1042 |
collections_errors = []; |
| 1043 |
|
| 1044 |
console.log(wp_reset.collections[collection_id]); |
| 1045 |
|
| 1046 |
for (item in wp_reset.collections[collection_id]['items']) { |
| 1047 |
item_data = wp_reset.collections[collection_id]['items'][item]; |
| 1048 |
collections_ajax_queue.push({ |
| 1049 |
slug: item_data.slug, |
| 1050 |
name: item_data.name, |
| 1051 |
extra_data: { |
| 1052 |
source: item_data.source, |
| 1053 |
collection_id: collection_id, |
| 1054 |
collection_item_id: item_data.id, |
| 1055 |
}, |
| 1056 |
action: 'install_' + item_data.type, |
| 1057 |
}); |
| 1058 |
collections_ajax_queue.push({ |
| 1059 |
slug: item_data.slug, |
| 1060 |
name: item_data.name, |
| 1061 |
action: 'check_install_' + item_data.type, |
| 1062 |
}); |
| 1063 |
|
| 1064 |
if (do_activate) { |
| 1065 |
collections_ajax_queue.push({ |
| 1066 |
slug: item_data.slug, |
| 1067 |
name: item_data.name, |
| 1068 |
action: 'activate_' + item_data.type, |
| 1069 |
extra_data: { |
| 1070 |
source: item_data.source, |
| 1071 |
collection_id: collection_id, |
| 1072 |
collection_item_id: item_data.id, |
| 1073 |
}, |
| 1074 |
}); |
| 1075 |
collections_ajax_queue.push({ |
| 1076 |
slug: item_data.slug, |
| 1077 |
name: item_data.name, |
| 1078 |
action: 'check_activate_' + item_data.type, |
| 1079 |
}); |
| 1080 |
} |
| 1081 |
} |
| 1082 |
|
| 1083 |
for (ci in collections_ajax_queue) { |
| 1084 |
var message = false; |
| 1085 |
collections_ajax_queue_count++; |
| 1086 |
|
| 1087 |
switch (collections_ajax_queue[ci].action) { |
| 1088 |
case 'deactivate_plugin': |
| 1089 |
message = wp_reset.deactivating; |
| 1090 |
break; |
| 1091 |
case 'delete_plugin': |
| 1092 |
case 'delete_theme': |
| 1093 |
message = wp_reset.deleting; |
| 1094 |
break; |
| 1095 |
case 'install_plugin': |
| 1096 |
case 'install_theme': |
| 1097 |
message = wp_reset.installing; |
| 1098 |
break; |
| 1099 |
case 'activate_plugin': |
| 1100 |
case 'activate_theme': |
| 1101 |
message = wp_reset.activating; |
| 1102 |
break; |
| 1103 |
case 'activate_license_plugin': |
| 1104 |
case 'activate_license_theme': |
| 1105 |
message = wp_reset.activating_license; |
| 1106 |
break; |
| 1107 |
} |
| 1108 |
|
| 1109 |
if (message !== false) { |
| 1110 |
$('.wpr-collections-installer').append( |
| 1111 |
'<div class="wpr-collections-installer-message" data-action="' + |
| 1112 |
collections_ajax_queue[ci].slug + |
| 1113 |
'_' + |
| 1114 |
collections_ajax_queue[ci].action + |
| 1115 |
'"><span class="dashicons"></span> ' + |
| 1116 |
message + |
| 1117 |
' ' + |
| 1118 |
collections_ajax_queue[ci].name + |
| 1119 |
'</div>' |
| 1120 |
); |
| 1121 |
} |
| 1122 |
} |
| 1123 |
|
| 1124 |
collections_ajax_queue_count = collections_ajax_queue.length; |
| 1125 |
collections_do_ajax(); |
| 1126 |
} // create install collection queue |
| 1127 |
|
| 1128 |
// run collection ajax |
| 1129 |
function collections_do_ajax() { |
| 1130 |
collection_item = collections_ajax_queue[collections_ajax_queue_index]; |
| 1131 |
message_id = collection_item.slug + '_' + collection_item.action.replace('check_', ''); |
| 1132 |
|
| 1133 |
$('[data-action="' + message_id + '"]').addClass('wpr-collections-installer-loading'); |
| 1134 |
|
| 1135 |
var query_data_type = 'text'; |
| 1136 |
if ( |
| 1137 |
collection_item.action == 'check_deactivate_plugin' || |
| 1138 |
collection_item.action == 'check_delete_plugin' || |
| 1139 |
collection_item.action == 'check_install_plugin' || |
| 1140 |
collection_item.action == 'check_activate_plugin' || |
| 1141 |
collection_item.action == 'check_install_theme' || |
| 1142 |
collection_item.action == 'check_activate_theme' || |
| 1143 |
collection_item.action == 'check_delete_theme' || |
| 1144 |
collection_item.action == 'check_activate_license_plugin' || |
| 1145 |
collection_item.action == 'check_activate_license_theme' |
| 1146 |
) { |
| 1147 |
query_data_type = 'json'; |
| 1148 |
} |
| 1149 |
|
| 1150 |
if (!('extra_data' in collection_item)) { |
| 1151 |
collection_item.extra_data = {}; |
| 1152 |
} |
| 1153 |
|
| 1154 |
$.ajax({ |
| 1155 |
url: ajaxurl, |
| 1156 |
type: 'get', |
| 1157 |
dataType: query_data_type, |
| 1158 |
data: { |
| 1159 |
action: 'wp_reset_run_tool', |
| 1160 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 1161 |
tool: collection_item.action, |
| 1162 |
slug: collection_item.slug, |
| 1163 |
extra_data: collection_item.extra_data, |
| 1164 |
}, |
| 1165 |
complete: function (data) { |
| 1166 |
if (typeof data.responseJSON == 'undefined') { |
| 1167 |
data = false; |
| 1168 |
} else { |
| 1169 |
data = data.responseJSON; |
| 1170 |
} |
| 1171 |
var do_next_called = false; |
| 1172 |
if ( |
| 1173 |
collection_item.action == 'check_deactivate_plugin' || |
| 1174 |
collection_item.action == 'check_delete_plugin' || |
| 1175 |
collection_item.action == 'check_install_plugin' || |
| 1176 |
collection_item.action == 'check_activate_plugin' || |
| 1177 |
collection_item.action == 'check_install_theme' || |
| 1178 |
collection_item.action == 'check_activate_theme' || |
| 1179 |
collection_item.action == 'check_delete_theme' || |
| 1180 |
collection_item.action == 'check_activate_license_plugin' || |
| 1181 |
collection_item.action == 'check_activate_license_theme' |
| 1182 |
) { |
| 1183 |
if (data == false && collections_retried == false) { |
| 1184 |
collections_retried = true; |
| 1185 |
collections_do_ajax(); |
| 1186 |
return false; |
| 1187 |
} |
| 1188 |
if ( |
| 1189 |
(collection_item.action == 'check_deactivate_plugin' && data.data == 'inactive') || |
| 1190 |
(collection_item.action == 'check_delete_plugin' && data.data == 'deleted') || |
| 1191 |
(collection_item.action == 'check_install_plugin' && (data.data == 'inactive' || data.data == 'active')) || |
| 1192 |
(collection_item.action == 'check_activate_plugin' && data.data == 'active') || |
| 1193 |
(collection_item.action == 'check_install_theme' && (data.data == 'inactive' || data.data == 'active')) || |
| 1194 |
(collection_item.action == 'check_activate_theme' && data.data == 'active') || |
| 1195 |
(collection_item.action == 'check_delete_theme' && data.data == 'deleted') || |
| 1196 |
(collection_item.action == 'check_activate_license_plugin' && data.data == 'license_active') || |
| 1197 |
(collection_item.action == 'check_activate_license_theme' && data.data == 'license_active') |
| 1198 |
) { |
| 1199 |
$('[data-action="' + message_id + '"]').addClass('wpr-collections-installer-success'); |
| 1200 |
} else { |
| 1201 |
var error = false; |
| 1202 |
switch (collection_item.action) { |
| 1203 |
case 'check_deactivate_plugin': |
| 1204 |
error = wp_reset.deactivate_failed + ' ' + collection_item.name; |
| 1205 |
break; |
| 1206 |
case 'check_delete_plugin': |
| 1207 |
case 'check_delete_theme': |
| 1208 |
error = wp_reset.delete_failed + ' ' + collection_item.name; |
| 1209 |
break; |
| 1210 |
case 'check_install_plugin': |
| 1211 |
case 'check_install_theme': |
| 1212 |
if (data.data == 'active') { |
| 1213 |
error = collection_item.name + ' ' + wp_reset.install_failed_existing; |
| 1214 |
} else if (data.data == 'deleted') { |
| 1215 |
error = wp_reset.install_failed + ' ' + collection_item.name; |
| 1216 |
} else { |
| 1217 |
error = data.data; |
| 1218 |
} |
| 1219 |
break; |
| 1220 |
case 'check_activate_plugin': |
| 1221 |
case 'check_activate_theme': |
| 1222 |
error = wp_reset.activate_failed + ' ' + collection_item.name; |
| 1223 |
break; |
| 1224 |
case 'check_activate_license_plugin': |
| 1225 |
case 'check_activate_license_theme': |
| 1226 |
if (data.data == 'unknown') { |
| 1227 |
error = wp_reset.activating_license_unknown + ' ' + collection_item.name; |
| 1228 |
} else { |
| 1229 |
error = wp_reset.activating_license_failed + ' ' + collection_item.name; |
| 1230 |
} |
| 1231 |
break; |
| 1232 |
default: |
| 1233 |
error = false; |
| 1234 |
} |
| 1235 |
|
| 1236 |
if (error != false) { |
| 1237 |
$('[data-action="' + message_id + '"]').append('<div class="wpr-collections-error">' + error + '</div>'); |
| 1238 |
collections_errors.push(error); |
| 1239 |
} |
| 1240 |
|
| 1241 |
$('[data-action="' + message_id + '"]').addClass('wpr-collections-installer-error'); |
| 1242 |
} |
| 1243 |
|
| 1244 |
$('[data-action="' + message_id + '"]').removeClass('wpr-collections-installer-loading'); |
| 1245 |
$('[data-action="' + message_id + '"]').addClass('wpr-collections-installer-done'); |
| 1246 |
} |
| 1247 |
|
| 1248 |
collections_retried = false; |
| 1249 |
collections_ajax_queue_index++; |
| 1250 |
|
| 1251 |
if (collections_ajax_queue.length == 0) { |
| 1252 |
wpr_swal.close(); |
| 1253 |
return false; |
| 1254 |
} |
| 1255 |
|
| 1256 |
if (do_next_called == false && typeof collections_ajax_queue[collections_ajax_queue_index] !== 'undefined') { |
| 1257 |
if (typeof $('.wpr-collections-installer div.wpr-collections-installer-done:last').offset() !== 'undefined') { |
| 1258 |
var scroll_top = |
| 1259 |
$('.wpr-collections-installer div.wpr-collections-installer-done:last').offset().top - |
| 1260 |
$('.wpr-collections-installer').offset().top + |
| 1261 |
$('.wpr-collections-installer').scrollTop() - |
| 1262 |
60; |
| 1263 |
$('.wpr-collections-installer').animate({ scrollTop: scroll_top }, 600, function () { |
| 1264 |
collections_do_ajax(); |
| 1265 |
}); |
| 1266 |
} else { |
| 1267 |
collections_do_ajax(); |
| 1268 |
} |
| 1269 |
} else { |
| 1270 |
wpr_swal.close(); |
| 1271 |
|
| 1272 |
$('.wpr-collections-installer').css('padding', '0px 40px'); |
| 1273 |
$('.wpr-collections-installer').css('height', '236px'); |
| 1274 |
|
| 1275 |
if (collections_errors.length > 0) { |
| 1276 |
var errors_html = ''; |
| 1277 |
for (e in collections_errors) { |
| 1278 |
errors_html += |
| 1279 |
'<div class="wpr-collections-installer-message wpr-collections-installer-error"><span class="dashicons"></span> ' + |
| 1280 |
collections_errors[e] + |
| 1281 |
'</div>'; |
| 1282 |
} |
| 1283 |
wpr_swal |
| 1284 |
.fire({ |
| 1285 |
icon: 'error', |
| 1286 |
title: 'Collection was installed, but the following errors occured!', |
| 1287 |
html: '<div class="wpr-collections-installer-errors">' + errors_html + '</div>', |
| 1288 |
showConfirmButton: true, |
| 1289 |
}) |
| 1290 |
.then((result) => { |
| 1291 |
location.reload(); |
| 1292 |
}); |
| 1293 |
} else { |
| 1294 |
wpr_swal |
| 1295 |
.fire({ |
| 1296 |
icon: 'success', |
| 1297 |
title: 'Collection was installed successfully!', |
| 1298 |
showConfirmButton: true, |
| 1299 |
timer: 2000, |
| 1300 |
timerProgressBar: true, |
| 1301 |
}) |
| 1302 |
.then((result) => { |
| 1303 |
location.reload(); |
| 1304 |
}); |
| 1305 |
} |
| 1306 |
} |
| 1307 |
}, |
| 1308 |
}); |
| 1309 |
} //run collection ajax |
| 1310 |
}); // onload |
| 1311 |
|
| 1312 |
function wpr_clear_local(clear_cookies, clear_storage) { |
| 1313 |
var cnt = 0; |
| 1314 |
|
| 1315 |
if (clear_cookies) { |
| 1316 |
var cookies = Cookies.get(); |
| 1317 |
cnt += Object.keys(cookies).length; |
| 1318 |
for (cookie in cookies) { |
| 1319 |
Cookies.remove(cookie); |
| 1320 |
} |
| 1321 |
} |
| 1322 |
|
| 1323 |
if (clear_storage) { |
| 1324 |
cnt += localStorage.length + sessionStorage.length; |
| 1325 |
localStorage.clear(); |
| 1326 |
sessionStorage.clear(); |
| 1327 |
} |
| 1328 |
|
| 1329 |
return cnt; |
| 1330 |
} // wpr_clear_local |
| 1331 |
|
| 1332 |
function wpr_close_dropdowns() { |
| 1333 |
jQuery('.dropdown').removeClass('show'); |
| 1334 |
jQuery('.dropdown-menu').removeClass('show'); |
| 1335 |
} // wpr_close_dropdowns |
| 1336 |
|