| 1 |
/** |
| 2 |
* WP Reset |
| 3 |
* https://wpreset.com/ |
| 4 |
* (c) WebFactory Ltd, 2017-2023 |
| 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({ |
| 289 |
icon: 'success', |
| 290 |
title: msg, |
| 291 |
timer: 2000, |
| 292 |
timerProgressBar: true, |
| 293 |
showConfirmButton: true, |
| 294 |
}); |
| 295 |
}); |
| 296 |
|
| 297 |
return false; |
| 298 |
}); // delete local data |
| 299 |
|
| 300 |
// compare snapshot |
| 301 |
$('#wpr-snapshots').on('click', '.compare-snapshot', 'click', function (e) { |
| 302 |
e.preventDefault(); |
| 303 |
uid = $(this).data('ss-uid'); |
| 304 |
button = $(this); |
| 305 |
|
| 306 |
block_ui($(button).data('wait-msg')); |
| 307 |
$.get({ |
| 308 |
url: ajaxurl, |
| 309 |
data: { |
| 310 |
action: 'wp_reset_run_tool', |
| 311 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 312 |
tool: 'compare_snapshots', |
| 313 |
extra_data: uid, |
| 314 |
}, |
| 315 |
}) |
| 316 |
.always(function (data) { |
| 317 |
wpr_swal.close(); |
| 318 |
}) |
| 319 |
.done(function (data) { |
| 320 |
if (data.success) { |
| 321 |
msg = $(button).data('title').replace('%s', $(button).data('name')); |
| 322 |
wpr_swal.fire({ |
| 323 |
width: '90%', |
| 324 |
title: msg, |
| 325 |
html: data.data, |
| 326 |
showConfirmButton: false, |
| 327 |
allowEnterKey: false, |
| 328 |
focusConfirm: false, |
| 329 |
showCloseButton: true, |
| 330 |
customClass: 'compare-snapshots', |
| 331 |
}); |
| 332 |
} else { |
| 333 |
wpr_swal.fire({ |
| 334 |
icon: 'error', |
| 335 |
title: wp_reset.documented_error + ' ' + data.data, |
| 336 |
}); |
| 337 |
} |
| 338 |
}) |
| 339 |
.fail(function (data) { |
| 340 |
wpr_swal.fire({ icon: 'error', title: wp_reset.undocumented_error }); |
| 341 |
}); |
| 342 |
|
| 343 |
return false; |
| 344 |
}); // compare snapshot |
| 345 |
|
| 346 |
// restore snapshot |
| 347 |
$('#wpr-snapshots').on('click', '.restore-snapshot', 'click', function (e) { |
| 348 |
e.preventDefault(); |
| 349 |
uid = $(this).data('ss-uid'); |
| 350 |
|
| 351 |
run_tool(this, 'restore_snapshot', uid); |
| 352 |
|
| 353 |
return false; |
| 354 |
}); // restore snapshot |
| 355 |
|
| 356 |
// download snapshot |
| 357 |
$('#wpr-snapshots').on('click', '.download-snapshot', 'click', function (e) { |
| 358 |
e.preventDefault(); |
| 359 |
uid = $(this).data('ss-uid'); |
| 360 |
button = this; |
| 361 |
|
| 362 |
block_ui($(this).data('wait-msg')); |
| 363 |
$.get({ |
| 364 |
url: ajaxurl, |
| 365 |
data: { |
| 366 |
action: 'wp_reset_run_tool', |
| 367 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 368 |
tool: 'download_snapshot', |
| 369 |
extra_data: uid, |
| 370 |
}, |
| 371 |
}) |
| 372 |
.always(function (data) { |
| 373 |
wpr_swal.close(); |
| 374 |
}) |
| 375 |
.done(function (data) { |
| 376 |
if (data.success) { |
| 377 |
msg = $(button).data('success-msg').replace('%s', data.data); |
| 378 |
wpr_swal.fire({ icon: 'success', title: msg }); |
| 379 |
} else { |
| 380 |
wpr_swal.fire({ |
| 381 |
icon: 'error', |
| 382 |
title: wp_reset.documented_error + ' ' + data.data, |
| 383 |
}); |
| 384 |
} |
| 385 |
}) |
| 386 |
.fail(function (data) { |
| 387 |
wpr_swal.fire({ icon: 'error', title: wp_reset.undocumented_error }); |
| 388 |
}); |
| 389 |
|
| 390 |
return false; |
| 391 |
}); // download snapshot |
| 392 |
|
| 393 |
// delete snapshot |
| 394 |
$('#wpr-snapshots').on('click', '.delete-snapshot', 'click', function (e) { |
| 395 |
e.preventDefault(); |
| 396 |
uid = $(this).data('ss-uid'); |
| 397 |
|
| 398 |
run_tool(this, 'delete_snapshot', uid); |
| 399 |
|
| 400 |
return false; |
| 401 |
}); // delete snapshot |
| 402 |
|
| 403 |
// create snapshot |
| 404 |
$('.tools_page_wp-reset').on('click', '.create-new-snapshot', function (e) { |
| 405 |
e.preventDefault(); |
| 406 |
|
| 407 |
description = $(this).data('description') || ''; |
| 408 |
|
| 409 |
wpr_swal |
| 410 |
.fire({ |
| 411 |
title: wp_reset.snapshot_title, |
| 412 |
icon: 'question', |
| 413 |
text: wp_reset.snapshot_text, |
| 414 |
input: 'text', |
| 415 |
inputValue: description, |
| 416 |
inputPlaceholder: wp_reset.snapshot_placeholder, |
| 417 |
showCancelButton: true, |
| 418 |
focusConfirm: false, |
| 419 |
confirmButtonText: wp_reset.snapshot_confirm, |
| 420 |
cancelButtonText: wp_reset.cancel_button, |
| 421 |
width: 600, |
| 422 |
}) |
| 423 |
.then((result) => { |
| 424 |
if (typeof result.value != 'undefined') { |
| 425 |
block = block_ui(wp_reset.snapshot_wait); |
| 426 |
$.get({ |
| 427 |
url: ajaxurl, |
| 428 |
data: { |
| 429 |
action: 'wp_reset_run_tool', |
| 430 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 431 |
tool: 'create_snapshot', |
| 432 |
extra_data: result.value, |
| 433 |
}, |
| 434 |
}) |
| 435 |
.always(function (data) { |
| 436 |
wpr_swal.close(); |
| 437 |
}) |
| 438 |
.done(function (data) { |
| 439 |
if (data.success) { |
| 440 |
wpr_swal |
| 441 |
.fire({ |
| 442 |
icon: 'success', |
| 443 |
title: wp_reset.snapshot_success, |
| 444 |
timer: 2000, |
| 445 |
timerProgressBar: true, |
| 446 |
showConfirmButton: true, |
| 447 |
}) |
| 448 |
.then((result) => { |
| 449 |
location.reload(); |
| 450 |
}); |
| 451 |
} else { |
| 452 |
wpr_swal.fire({ |
| 453 |
icon: 'error', |
| 454 |
title: wp_reset.documented_error + ' ' + data.data, |
| 455 |
}); |
| 456 |
} |
| 457 |
}) |
| 458 |
.fail(function (data) { |
| 459 |
wpr_swal.fire({ |
| 460 |
icon: 'error', |
| 461 |
title: wp_reset.undocumented_error, |
| 462 |
}); |
| 463 |
}); |
| 464 |
} // if confirmed |
| 465 |
}); |
| 466 |
|
| 467 |
return false; |
| 468 |
}); // create snapshot |
| 469 |
|
| 470 |
// show/hide extra table info in snapshot diff |
| 471 |
$('body.tools_page_wp-reset').on('click', '.header-row', function (e) { |
| 472 |
e.preventDefault(); |
| 473 |
|
| 474 |
parent = $(this).parents('div.wpr-table-container > table > tbody'); |
| 475 |
$(' > tr:not(.header-row)', parent).toggleClass('hidden'); |
| 476 |
|
| 477 |
$('span.dashicons', parent).toggleClass('dashicons-arrow-down-alt2').toggleClass('dashicons-arrow-up-alt2'); |
| 478 |
|
| 479 |
return false; |
| 480 |
}); // show hide extra info in diff |
| 481 |
|
| 482 |
// standard way of running a tool, with confirmation, loading and success message |
| 483 |
function run_tool(button, tool_name, extra_data) { |
| 484 |
var confirm_title = $(button).data('confirm-title') || wp_reset.confirm_title; |
| 485 |
|
| 486 |
wpr_close_dropdowns(); |
| 487 |
|
| 488 |
confirm_action( |
| 489 |
confirm_title, |
| 490 |
$(button).data('text-confirm'), |
| 491 |
$(button).data('btn-confirm'), |
| 492 |
wp_reset.cancel_button |
| 493 |
).then((result) => { |
| 494 |
if (result.value) { |
| 495 |
block = block_ui($(button).data('text-wait')); |
| 496 |
$.get({ |
| 497 |
url: ajaxurl, |
| 498 |
data: { |
| 499 |
action: 'wp_reset_run_tool', |
| 500 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 501 |
tool: tool_name, |
| 502 |
extra_data: extra_data, |
| 503 |
}, |
| 504 |
}) |
| 505 |
.always(function (data) { |
| 506 |
wpr_swal.close(); |
| 507 |
}) |
| 508 |
.done(function (data) { |
| 509 |
if (data.success) { |
| 510 |
if (data.data == 1) { |
| 511 |
msg = $(button).data('text-done-singular'); |
| 512 |
} else { |
| 513 |
msg = $(button).data('text-done').replace('%n', data.data); |
| 514 |
} |
| 515 |
wpr_swal |
| 516 |
.fire({ |
| 517 |
icon: 'success', |
| 518 |
title: msg, |
| 519 |
timer: 2000, |
| 520 |
timerProgressBar: true, |
| 521 |
}) |
| 522 |
.then(() => { |
| 523 |
if (tool_name == 'restore_snapshot') { |
| 524 |
location.reload(); |
| 525 |
} |
| 526 |
}); |
| 527 |
if (tool_name == 'delete_snapshot') { |
| 528 |
$('#wpr-ss-' + extra_data).remove(); |
| 529 |
if ($('#wpr-snapshots tr').length <= 1) { |
| 530 |
$('#wpr-snapshots').hide(); |
| 531 |
$('#ss-no-snapshots').show(); |
| 532 |
} |
| 533 |
} |
| 534 |
} else { |
| 535 |
wpr_swal.fire({ |
| 536 |
icon: 'error', |
| 537 |
title: wp_reset.documented_error + ' ' + data.data, |
| 538 |
}); |
| 539 |
} |
| 540 |
}) |
| 541 |
.fail(function (data) { |
| 542 |
wpr_swal.fire({ |
| 543 |
icon: 'error', |
| 544 |
title: wp_reset.undocumented_error, |
| 545 |
}); |
| 546 |
}); |
| 547 |
} // if confirmed |
| 548 |
}); |
| 549 |
} // run_tool |
| 550 |
|
| 551 |
// display a message while an action is performed |
| 552 |
function block_ui(message) { |
| 553 |
tmp = wpr_swal.fire({ |
| 554 |
text: message, |
| 555 |
type: false, |
| 556 |
imageUrl: wp_reset.icon_url, |
| 557 |
onOpen: () => { |
| 558 |
$(wpr_swal.getImage()).addClass('rotating'); |
| 559 |
}, |
| 560 |
imageWidth: 100, |
| 561 |
imageHeight: 100, |
| 562 |
imageAlt: message, |
| 563 |
allowOutsideClick: false, |
| 564 |
allowEscapeKey: false, |
| 565 |
allowEnterKey: false, |
| 566 |
showConfirmButton: false, |
| 567 |
}); |
| 568 |
|
| 569 |
return tmp; |
| 570 |
} // block_ui |
| 571 |
|
| 572 |
// display dialog to confirm action |
| 573 |
function confirm_action(title, question, btn_confirm, btn_cancel) { |
| 574 |
tmp = wpr_swal.fire({ |
| 575 |
title: title, |
| 576 |
icon: 'question', |
| 577 |
html: question, |
| 578 |
showCancelButton: true, |
| 579 |
focusConfirm: false, |
| 580 |
focusCancel: true, |
| 581 |
confirmButtonText: btn_confirm, |
| 582 |
cancelButtonText: btn_cancel, |
| 583 |
confirmButtonColor: '#dd3036', |
| 584 |
width: 650, |
| 585 |
}); |
| 586 |
|
| 587 |
return tmp; |
| 588 |
} // confirm_action |
| 589 |
|
| 590 |
$('#wp_reset_form').on('submit', function (e, confirmed) { |
| 591 |
if (!confirmed) { |
| 592 |
$('#wp_reset_submit').trigger('click'); |
| 593 |
e.preventDefault(); |
| 594 |
return false; |
| 595 |
} |
| 596 |
|
| 597 |
$reset_form = $(this); |
| 598 |
|
| 599 |
$.get({ |
| 600 |
url: ajaxurl, |
| 601 |
data: { |
| 602 |
action: 'wp_reset_run_tool', |
| 603 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 604 |
tool: 'before_reset' |
| 605 |
}, |
| 606 |
}).done(function (data) { |
| 607 |
if (data.success) { |
| 608 |
$reset_form.off('submit').submit(); |
| 609 |
} else { |
| 610 |
wpr_swal.fire({ |
| 611 |
icon: 'error', |
| 612 |
title: wp_reset.undocumented_error, |
| 613 |
}); |
| 614 |
} |
| 615 |
}).fail(function (data) { |
| 616 |
wpr_swal.fire({ |
| 617 |
icon: 'error', |
| 618 |
title: wp_reset.undocumented_error, |
| 619 |
}); |
| 620 |
}); |
| 621 |
|
| 622 |
return false; |
| 623 |
}); // bypass default submit behaviour |
| 624 |
|
| 625 |
$('#wp_reset_submit').click(function (e) { |
| 626 |
if ($('#wp_reset_confirm').val() !== 'reset') { |
| 627 |
wpr_swal.fire({ |
| 628 |
title: wp_reset.invalid_confirmation_title, |
| 629 |
text: wp_reset.invalid_confirmation, |
| 630 |
icon: 'error', |
| 631 |
confirmButtonText: wp_reset.ok_button, |
| 632 |
}); |
| 633 |
|
| 634 |
e.preventDefault(); |
| 635 |
return false; |
| 636 |
} // wrong confirmation code |
| 637 |
|
| 638 |
message = wp_reset.confirm1 + '<br>' + wp_reset.confirm2; |
| 639 |
wpr_swal |
| 640 |
.fire({ |
| 641 |
title: wp_reset.confirm_title_reset, |
| 642 |
icon: 'question', |
| 643 |
html: message, |
| 644 |
showCancelButton: true, |
| 645 |
focusConfirm: false, |
| 646 |
focusCancel: true, |
| 647 |
confirmButtonText: wp_reset.confirm_button, |
| 648 |
cancelButtonText: wp_reset.cancel_button, |
| 649 |
confirmButtonColor: '#dd3036', |
| 650 |
width: 600, |
| 651 |
}) |
| 652 |
.then((result) => { |
| 653 |
if (result.value === true) { |
| 654 |
block_ui(wp_reset.doing_reset); |
| 655 |
$('#wp_reset_form').trigger('submit', true); |
| 656 |
} |
| 657 |
}); |
| 658 |
|
| 659 |
e.preventDefault(); |
| 660 |
return false; |
| 661 |
}); // reset submit |
| 662 |
|
| 663 |
// collapse / expand card |
| 664 |
$('.tools_page_wp-reset').on('click', '.toggle-card', function (e, skip_anim) { |
| 665 |
e.preventDefault(); |
| 666 |
|
| 667 |
card = $(this).parents('.card').toggleClass('collapsed'); |
| 668 |
$('.dashicons', this).toggleClass('dashicons-arrow-up-alt2').toggleClass('dashicons-arrow-down-alt2'); |
| 669 |
$(this).blur(); |
| 670 |
|
| 671 |
if (typeof skip_anim != 'undefined' && skip_anim) { |
| 672 |
$(card).find('.card-body').toggle(); |
| 673 |
} else { |
| 674 |
$(card).find('.card-body').slideToggle(500); |
| 675 |
} |
| 676 |
|
| 677 |
cards = localStorage.getItem('wp-reset-cards'); |
| 678 |
if (cards == null) { |
| 679 |
cards = new Object(); |
| 680 |
} else { |
| 681 |
cards = JSON.parse(cards); |
| 682 |
} |
| 683 |
|
| 684 |
card_id = card.attr('id') || $('h4', card).attr('id') || ''; |
| 685 |
|
| 686 |
if (card.hasClass('collapsed')) { |
| 687 |
cards[card_id] = 'collapsed'; |
| 688 |
} else { |
| 689 |
cards[card_id] = 'expanded'; |
| 690 |
} |
| 691 |
localStorage.setItem('wp-reset-cards', JSON.stringify(cards)); |
| 692 |
|
| 693 |
return false; |
| 694 |
}); // toggle-card |
| 695 |
|
| 696 |
// handle saved and preset cards' state |
| 697 |
cards_state = localStorage.getItem('wp-reset-cards'); |
| 698 |
if (cards_state != null) { |
| 699 |
cards_state = JSON.parse(cards_state); |
| 700 |
} else { |
| 701 |
cards_state = new Object(); |
| 702 |
} |
| 703 |
|
| 704 |
cards = $('.card'); |
| 705 |
$.each(cards, function (index, card) { |
| 706 |
card_name = $('h4', card).attr('id'); |
| 707 |
if (!card_name) { |
| 708 |
return; |
| 709 |
} |
| 710 |
|
| 711 |
if (typeof cards_state == 'object' && cards_state.hasOwnProperty(card_name)) { |
| 712 |
if (cards_state[card_name] == 'collapsed') { |
| 713 |
$('a.toggle-card', card).trigger('click', true); |
| 714 |
} |
| 715 |
} else { |
| 716 |
if ($(card).hasClass('default-collapsed')) { |
| 717 |
$('a.toggle-card', card).trigger('click', true); |
| 718 |
} |
| 719 |
} |
| 720 |
}); |
| 721 |
|
| 722 |
// dismiss notice / pointer |
| 723 |
$('.wpr-dismiss-notice').on('click', function (e) { |
| 724 |
notice_name = $(this).data('notice'); |
| 725 |
if (!notice_name) { |
| 726 |
return true; |
| 727 |
} |
| 728 |
|
| 729 |
$.get(ajaxurl, { |
| 730 |
notice_name: notice_name, |
| 731 |
_ajax_nonce: wp_reset.nonce_dismiss_notice, |
| 732 |
action: 'wp_reset_dismiss_notice', |
| 733 |
}); |
| 734 |
|
| 735 |
$(this).parents('.notice-wrapper').fadeOut(); |
| 736 |
|
| 737 |
e.preventDefault(); |
| 738 |
return false; |
| 739 |
}); // dismiss notice |
| 740 |
|
| 741 |
// open upsell |
| 742 |
$('.tools_page_wp-reset').on('click', '.button-pro-feature, .pro-feature', function (e) { |
| 743 |
e.preventDefault(); |
| 744 |
this.blur(); |
| 745 |
|
| 746 |
tool_id = $(this).data('feature') || $('.pro-feature', this).data('feature'); |
| 747 |
|
| 748 |
open_upsell(tool_id); |
| 749 |
|
| 750 |
return false; |
| 751 |
}); |
| 752 |
|
| 753 |
function clean_feature(feature) { |
| 754 |
feature = feature || 'free-plugin-unknown'; |
| 755 |
feature = feature.toLowerCase().trim(); |
| 756 |
feature = feature.replace(' ', '-'); |
| 757 |
|
| 758 |
return feature; |
| 759 |
} |
| 760 |
|
| 761 |
function open_upsell(feature) { |
| 762 |
feature = clean_feature(feature); |
| 763 |
|
| 764 |
$('#wpreset-pro-dialog').dialog('open'); |
| 765 |
|
| 766 |
$('#wpreset-pro-table .button-buy').each(function(ind, el) { |
| 767 |
tmp = $(el).data('href-org'); |
| 768 |
tmp = tmp.replace('pricing-table', feature); |
| 769 |
$(el).attr('href', tmp); |
| 770 |
}); |
| 771 |
} // open_upsell |
| 772 |
|
| 773 |
$('#wpreset-pro-dialog').dialog({ |
| 774 |
dialogClass: 'wp-dialog wpreset-pro-dialog', |
| 775 |
modal: true, |
| 776 |
resizable: false, |
| 777 |
width: 800, |
| 778 |
height: 'auto', |
| 779 |
show: 'fade', |
| 780 |
hide: 'fade', |
| 781 |
close: function (event, ui) { |
| 782 |
}, |
| 783 |
open: function (event, ui) { |
| 784 |
$(this).siblings().find('span.ui-dialog-title').html('WP Reset PRO'); |
| 785 |
wpr_fix_dialog_close(event, ui); |
| 786 |
}, |
| 787 |
autoOpen: false, |
| 788 |
closeOnEscape: true, |
| 789 |
}); |
| 790 |
|
| 791 |
if (window.localStorage.getItem('wpreset_upsell_shown') != 'true') { |
| 792 |
open_upsell('welcome'); |
| 793 |
window.localStorage.setItem('wpreset_upsell_shown', 'true'); |
| 794 |
window.localStorage.setItem('wpreset_upsell_shown_timestamp', new Date().getTime()); |
| 795 |
} |
| 796 |
|
| 797 |
if (window.location.hash == '#open-pro-dialog') { |
| 798 |
open_upsell('url-hash'); |
| 799 |
window.location.hash = ''; |
| 800 |
} |
| 801 |
|
| 802 |
$('#show-table-details').on('click', function (e) { |
| 803 |
e.preventDefault(); |
| 804 |
|
| 805 |
$.get({ |
| 806 |
url: ajaxurl, |
| 807 |
data: { |
| 808 |
action: 'wp_reset_run_tool', |
| 809 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 810 |
tool: 'get_table_details', |
| 811 |
}, |
| 812 |
}) |
| 813 |
.done(function (data) { |
| 814 |
if (data.success) { |
| 815 |
$('#wpr-table-details').html(data.data); |
| 816 |
} else { |
| 817 |
wpr_swal.fire({ |
| 818 |
type: 'error', |
| 819 |
title: wp_reset.documented_error + ' ' + data.data, |
| 820 |
}); |
| 821 |
} |
| 822 |
}) |
| 823 |
.fail(function (data) { |
| 824 |
wpr_swal.fire({ type: 'error', title: wp_reset.undocumented_error }); |
| 825 |
}); |
| 826 |
|
| 827 |
return false; |
| 828 |
}); // show table details |
| 829 |
|
| 830 |
$('#wpr-save-license').on('click', function (e) { |
| 831 |
e.preventDefault(); |
| 832 |
|
| 833 |
button = this; |
| 834 |
safe_refresh = true; |
| 835 |
|
| 836 |
block = block_ui($(button).data('text-wait')); |
| 837 |
wf_licensing_verify_licence_ajax('wpr', $('#wpr-license-key').val(), button); |
| 838 |
|
| 839 |
return; |
| 840 |
}); // license activation button |
| 841 |
|
| 842 |
$('#wpr-keyless-activation').on('click', function (e) { |
| 843 |
e.preventDefault(); |
| 844 |
|
| 845 |
button = this; |
| 846 |
safe_refresh = true; |
| 847 |
|
| 848 |
block = block_ui($(button).data('text-wait')); |
| 849 |
wf_licensing_verify_licence_ajax('wpr', 'keyless', button); |
| 850 |
|
| 851 |
return; |
| 852 |
}); // keyless license activation button |
| 853 |
|
| 854 |
$('#wpr-deactivate-license').on('click', function (e) { |
| 855 |
e.preventDefault(); |
| 856 |
|
| 857 |
button = this; |
| 858 |
safe_refresh = true; |
| 859 |
|
| 860 |
block = block_ui($(button).data('text-wait')); |
| 861 |
wf_licensing_deactivate_licence_ajax('wpr', $('#wpr-license-key').val(), button); |
| 862 |
|
| 863 |
return; |
| 864 |
}); // deactivate license button |
| 865 |
|
| 866 |
$('#wpr-license-key').on('keypress', function (e) { |
| 867 |
if (e.keyCode == 13) { |
| 868 |
e.preventDefault(); |
| 869 |
$('#wpr-save-license').trigger('click'); |
| 870 |
} |
| 871 |
}); // trigger license save on enter |
| 872 |
|
| 873 |
// Collections |
| 874 |
// for demo purposes only |
| 875 |
var collections_ajax_queue = []; |
| 876 |
var collections_ajax_queue_count = 0; |
| 877 |
var collections_ajax_queue_index = 0; |
| 878 |
var collections_errors = []; |
| 879 |
var collections_retried = false; |
| 880 |
wp_reset.collections = []; |
| 881 |
wp_reset.collections[1] = { |
| 882 |
id: 1, |
| 883 |
name: 'Must Have WordPress Plugins', |
| 884 |
created: '2020-04-01', |
| 885 |
items: [], |
| 886 |
}; |
| 887 |
wp_reset.collections[1].items[10] = { |
| 888 |
id: '10', |
| 889 |
type: 'plugin', |
| 890 |
source: 'repo', |
| 891 |
note: '', |
| 892 |
slug: 'eps-301-redirects', |
| 893 |
name: '301 Redirects', |
| 894 |
version: '0.4', |
| 895 |
}; |
| 896 |
|
| 897 |
wp_reset.collections[1].items[11] = { |
| 898 |
id: '11', |
| 899 |
type: 'plugin', |
| 900 |
source: 'repo', |
| 901 |
note: '', |
| 902 |
slug: 'classic-editor', |
| 903 |
name: 'Classic Editor', |
| 904 |
version: '0.4', |
| 905 |
}; |
| 906 |
|
| 907 |
wp_reset.collections[1].items[12] = { |
| 908 |
id: '12', |
| 909 |
type: 'plugin', |
| 910 |
source: 'repo', |
| 911 |
note: '', |
| 912 |
slug: 'simple-author-box', |
| 913 |
name: 'Simple Author Box', |
| 914 |
version: '0.4', |
| 915 |
}; |
| 916 |
|
| 917 |
wp_reset.collections[1].items[13] = { |
| 918 |
id: '13', |
| 919 |
type: 'plugin', |
| 920 |
source: 'repo', |
| 921 |
note: '', |
| 922 |
slug: 'sticky-menu-or-anything-on-scroll', |
| 923 |
name: 'Sticky Menu (or Anything!) on Scroll', |
| 924 |
version: '0.4', |
| 925 |
}; |
| 926 |
|
| 927 |
wp_reset.collections[1].items[14] = { |
| 928 |
id: '14', |
| 929 |
type: 'plugin', |
| 930 |
source: 'repo', |
| 931 |
note: '', |
| 932 |
slug: 'under-construction-page', |
| 933 |
name: 'UnderConstructionPage', |
| 934 |
version: '0.4', |
| 935 |
}; |
| 936 |
|
| 937 |
wp_reset.collections[1].items[15] = { |
| 938 |
id: '15', |
| 939 |
type: 'plugin', |
| 940 |
source: 'repo', |
| 941 |
note: '', |
| 942 |
slug: 'wp-external-links', |
| 943 |
name: 'WP External Links', |
| 944 |
version: '0.4', |
| 945 |
}; |
| 946 |
|
| 947 |
$(document).on('click', '.install-collection', function (e) { |
| 948 |
do_delete = $(this).data('delete'); |
| 949 |
do_activate = $(this).data('activate'); |
| 950 |
collection_id = $(this).parents('.card').data('collection-id'); |
| 951 |
show_install_collection(collection_id, do_delete, do_activate); |
| 952 |
}); |
| 953 |
|
| 954 |
// install collection item |
| 955 |
$('.tools_page_wp-reset').on('click', '.install-collection-item', function (e) { |
| 956 |
e.preventDefault(); |
| 957 |
|
| 958 |
wpr_close_dropdowns(); |
| 959 |
|
| 960 |
collection_id = $(this).parents('.card').data('collection-id'); |
| 961 |
collection_item_id = $(this).parents('tr').data('collection-item-id'); |
| 962 |
do_activate = $(this).data('activate'); |
| 963 |
|
| 964 |
item_data = wp_reset.collections[collection_id]['items'][collection_item_id]; |
| 965 |
|
| 966 |
wpr_swal |
| 967 |
.fire({ |
| 968 |
title: 'Installing <br />' + item_data['name'], |
| 969 |
html: '<div class="wpr-collections-installer"></div>', |
| 970 |
width: 600, |
| 971 |
onRender: function () { |
| 972 |
collections_ajax_queue.push({ |
| 973 |
slug: item_data.slug, |
| 974 |
name: item_data.name, |
| 975 |
extra_data: { |
| 976 |
source: item_data.source, |
| 977 |
collection_id: collection_id, |
| 978 |
collection_item_id: collection_item_id, |
| 979 |
}, |
| 980 |
action: 'install_' + item_data.type, |
| 981 |
}); |
| 982 |
collections_ajax_queue.push({ |
| 983 |
slug: item_data.slug, |
| 984 |
name: item_data.name, |
| 985 |
action: 'check_install_' + item_data.type, |
| 986 |
}); |
| 987 |
|
| 988 |
$('.wpr-collections-installer').append( |
| 989 |
'<div class="wpr-collections-installer-message" data-action="' + |
| 990 |
item_data.slug + |
| 991 |
'_install_' + |
| 992 |
item_data.type + |
| 993 |
'"><span class="dashicons"></span>' + |
| 994 |
wp_reset.installing + |
| 995 |
' ' + |
| 996 |
item_data.name + |
| 997 |
'</div>' |
| 998 |
); |
| 999 |
|
| 1000 |
if (do_activate) { |
| 1001 |
collections_ajax_queue.push({ |
| 1002 |
slug: item_data.slug, |
| 1003 |
name: item_data.name, |
| 1004 |
action: 'activate_' + item_data.type, |
| 1005 |
extra_data: { |
| 1006 |
source: item_data.source, |
| 1007 |
collection_id: collection_id, |
| 1008 |
collection_item_id: collection_item_id, |
| 1009 |
}, |
| 1010 |
}); |
| 1011 |
collections_ajax_queue.push({ |
| 1012 |
slug: item_data.slug, |
| 1013 |
name: item_data.name, |
| 1014 |
action: 'check_activate_' + item_data.type, |
| 1015 |
}); |
| 1016 |
|
| 1017 |
$('.wpr-collections-installer').append( |
| 1018 |
'<div class="wpr-collections-installer-message" data-action="' + |
| 1019 |
item_data.slug + |
| 1020 |
'_activate_' + |
| 1021 |
item_data.type + |
| 1022 |
'"><span class="dashicons"></span>' + |
| 1023 |
wp_reset.activating + |
| 1024 |
' ' + |
| 1025 |
item_data.name + |
| 1026 |
'</div>' |
| 1027 |
); |
| 1028 |
} |
| 1029 |
collections_do_ajax(); |
| 1030 |
}, |
| 1031 |
allowOutsideClick: false, |
| 1032 |
allowEscapeKey: false, |
| 1033 |
allowEnterKey: false, |
| 1034 |
showCancelButton: true, |
| 1035 |
confirmButtonText: 'OK', |
| 1036 |
}) |
| 1037 |
.then((result) => { |
| 1038 |
collections_ajax_queue = []; |
| 1039 |
}); |
| 1040 |
|
| 1041 |
return false; |
| 1042 |
}); // install collection item |
| 1043 |
|
| 1044 |
// show install collection popup |
| 1045 |
function show_install_collection(collection_id, do_delete, do_activate) { |
| 1046 |
wpr_swal |
| 1047 |
.fire({ |
| 1048 |
title: 'Installing collection<br />' + wp_reset.collections[collection_id]['name'], |
| 1049 |
html: '<div class="wpr-collections-installer"></div>', |
| 1050 |
width: 600, |
| 1051 |
onRender: function () { |
| 1052 |
install_collection(collection_id, do_activate, do_delete); |
| 1053 |
}, |
| 1054 |
allowOutsideClick: false, |
| 1055 |
allowEscapeKey: false, |
| 1056 |
allowEnterKey: false, |
| 1057 |
showCancelButton: true, |
| 1058 |
showConfirmButton: false, |
| 1059 |
confirmButtonText: 'OK', |
| 1060 |
}) |
| 1061 |
.then((result) => { |
| 1062 |
collections_ajax_queue = []; |
| 1063 |
}); |
| 1064 |
} // show install collection popup |
| 1065 |
|
| 1066 |
// create install collection queue and add popup content |
| 1067 |
function install_collection(collection_id, do_activate, do_delete) { |
| 1068 |
collections_ajax_queue = []; |
| 1069 |
collections_ajax_queue_count = 0; |
| 1070 |
collections_ajax_queue_index = 0; |
| 1071 |
collections_errors = []; |
| 1072 |
|
| 1073 |
for (item in wp_reset.collections[collection_id]['items']) { |
| 1074 |
item_data = wp_reset.collections[collection_id]['items'][item]; |
| 1075 |
collections_ajax_queue.push({ |
| 1076 |
slug: item_data.slug, |
| 1077 |
name: item_data.name, |
| 1078 |
extra_data: { |
| 1079 |
source: item_data.source, |
| 1080 |
collection_id: collection_id, |
| 1081 |
collection_item_id: item_data.id, |
| 1082 |
}, |
| 1083 |
action: 'install_' + item_data.type, |
| 1084 |
}); |
| 1085 |
collections_ajax_queue.push({ |
| 1086 |
slug: item_data.slug, |
| 1087 |
name: item_data.name, |
| 1088 |
action: 'check_install_' + item_data.type, |
| 1089 |
}); |
| 1090 |
|
| 1091 |
if (do_activate) { |
| 1092 |
collections_ajax_queue.push({ |
| 1093 |
slug: item_data.slug, |
| 1094 |
name: item_data.name, |
| 1095 |
action: 'activate_' + item_data.type, |
| 1096 |
extra_data: { |
| 1097 |
source: item_data.source, |
| 1098 |
collection_id: collection_id, |
| 1099 |
collection_item_id: item_data.id, |
| 1100 |
}, |
| 1101 |
}); |
| 1102 |
collections_ajax_queue.push({ |
| 1103 |
slug: item_data.slug, |
| 1104 |
name: item_data.name, |
| 1105 |
action: 'check_activate_' + item_data.type, |
| 1106 |
}); |
| 1107 |
} |
| 1108 |
} |
| 1109 |
|
| 1110 |
for (ci in collections_ajax_queue) { |
| 1111 |
var message = false; |
| 1112 |
collections_ajax_queue_count++; |
| 1113 |
|
| 1114 |
switch (collections_ajax_queue[ci].action) { |
| 1115 |
case 'deactivate_plugin': |
| 1116 |
message = wp_reset.deactivating; |
| 1117 |
break; |
| 1118 |
case 'delete_plugin': |
| 1119 |
case 'delete_theme': |
| 1120 |
message = wp_reset.deleting; |
| 1121 |
break; |
| 1122 |
case 'install_plugin': |
| 1123 |
case 'install_theme': |
| 1124 |
message = wp_reset.installing; |
| 1125 |
break; |
| 1126 |
case 'activate_plugin': |
| 1127 |
case 'activate_theme': |
| 1128 |
message = wp_reset.activating; |
| 1129 |
break; |
| 1130 |
case 'activate_license_plugin': |
| 1131 |
case 'activate_license_theme': |
| 1132 |
message = wp_reset.activating_license; |
| 1133 |
break; |
| 1134 |
} |
| 1135 |
|
| 1136 |
if (message !== false) { |
| 1137 |
$('.wpr-collections-installer').append( |
| 1138 |
'<div class="wpr-collections-installer-message" data-action="' + |
| 1139 |
collections_ajax_queue[ci].slug + |
| 1140 |
'_' + |
| 1141 |
collections_ajax_queue[ci].action + |
| 1142 |
'"><span class="dashicons"></span> ' + |
| 1143 |
message + |
| 1144 |
' ' + |
| 1145 |
collections_ajax_queue[ci].name + |
| 1146 |
'</div>' |
| 1147 |
); |
| 1148 |
} |
| 1149 |
} |
| 1150 |
|
| 1151 |
collections_ajax_queue_count = collections_ajax_queue.length; |
| 1152 |
collections_do_ajax(); |
| 1153 |
} // create install collection queue |
| 1154 |
|
| 1155 |
// run collection ajax |
| 1156 |
function collections_do_ajax() { |
| 1157 |
collection_item = collections_ajax_queue[collections_ajax_queue_index]; |
| 1158 |
message_id = collection_item.slug + '_' + collection_item.action.replace('check_', ''); |
| 1159 |
|
| 1160 |
$('[data-action="' + message_id + '"]').addClass('wpr-collections-installer-loading'); |
| 1161 |
|
| 1162 |
var query_data_type = 'text'; |
| 1163 |
if ( |
| 1164 |
collection_item.action == 'check_deactivate_plugin' || |
| 1165 |
collection_item.action == 'check_delete_plugin' || |
| 1166 |
collection_item.action == 'check_install_plugin' || |
| 1167 |
collection_item.action == 'check_activate_plugin' || |
| 1168 |
collection_item.action == 'check_install_theme' || |
| 1169 |
collection_item.action == 'check_activate_theme' || |
| 1170 |
collection_item.action == 'check_delete_theme' || |
| 1171 |
collection_item.action == 'check_activate_license_plugin' || |
| 1172 |
collection_item.action == 'check_activate_license_theme' |
| 1173 |
) { |
| 1174 |
query_data_type = 'json'; |
| 1175 |
} |
| 1176 |
|
| 1177 |
if (!('extra_data' in collection_item)) { |
| 1178 |
collection_item.extra_data = {}; |
| 1179 |
} |
| 1180 |
|
| 1181 |
$.ajax({ |
| 1182 |
url: ajaxurl, |
| 1183 |
type: 'get', |
| 1184 |
dataType: query_data_type, |
| 1185 |
data: { |
| 1186 |
action: 'wp_reset_run_tool', |
| 1187 |
_ajax_nonce: wp_reset.nonce_run_tool, |
| 1188 |
tool: collection_item.action, |
| 1189 |
slug: collection_item.slug, |
| 1190 |
extra_data: collection_item.extra_data, |
| 1191 |
}, |
| 1192 |
complete: function (data) { |
| 1193 |
if (typeof data.responseJSON == 'undefined') { |
| 1194 |
data = false; |
| 1195 |
} else { |
| 1196 |
data = data.responseJSON; |
| 1197 |
} |
| 1198 |
var do_next_called = false; |
| 1199 |
if ( |
| 1200 |
collection_item.action == 'check_deactivate_plugin' || |
| 1201 |
collection_item.action == 'check_delete_plugin' || |
| 1202 |
collection_item.action == 'check_install_plugin' || |
| 1203 |
collection_item.action == 'check_activate_plugin' || |
| 1204 |
collection_item.action == 'check_install_theme' || |
| 1205 |
collection_item.action == 'check_activate_theme' || |
| 1206 |
collection_item.action == 'check_delete_theme' || |
| 1207 |
collection_item.action == 'check_activate_license_plugin' || |
| 1208 |
collection_item.action == 'check_activate_license_theme' |
| 1209 |
) { |
| 1210 |
if (data == false && collections_retried == false) { |
| 1211 |
collections_retried = true; |
| 1212 |
collections_do_ajax(); |
| 1213 |
return false; |
| 1214 |
} |
| 1215 |
if ( |
| 1216 |
(collection_item.action == 'check_deactivate_plugin' && data.data == 'inactive') || |
| 1217 |
(collection_item.action == 'check_delete_plugin' && data.data == 'deleted') || |
| 1218 |
(collection_item.action == 'check_install_plugin' && (data.data == 'inactive' || data.data == 'active')) || |
| 1219 |
(collection_item.action == 'check_activate_plugin' && data.data == 'active') || |
| 1220 |
(collection_item.action == 'check_install_theme' && (data.data == 'inactive' || data.data == 'active')) || |
| 1221 |
(collection_item.action == 'check_activate_theme' && data.data == 'active') || |
| 1222 |
(collection_item.action == 'check_delete_theme' && data.data == 'deleted') || |
| 1223 |
(collection_item.action == 'check_activate_license_plugin' && data.data == 'license_active') || |
| 1224 |
(collection_item.action == 'check_activate_license_theme' && data.data == 'license_active') |
| 1225 |
) { |
| 1226 |
$('[data-action="' + message_id + '"]').addClass('wpr-collections-installer-success'); |
| 1227 |
} else { |
| 1228 |
var error = false; |
| 1229 |
switch (collection_item.action) { |
| 1230 |
case 'check_deactivate_plugin': |
| 1231 |
error = wp_reset.deactivate_failed + ' ' + collection_item.name; |
| 1232 |
break; |
| 1233 |
case 'check_delete_plugin': |
| 1234 |
case 'check_delete_theme': |
| 1235 |
error = wp_reset.delete_failed + ' ' + collection_item.name; |
| 1236 |
break; |
| 1237 |
case 'check_install_plugin': |
| 1238 |
case 'check_install_theme': |
| 1239 |
if (data.data == 'active') { |
| 1240 |
error = collection_item.name + ' ' + wp_reset.install_failed_existing; |
| 1241 |
} else if (data.data == 'deleted') { |
| 1242 |
error = wp_reset.install_failed + ' ' + collection_item.name; |
| 1243 |
} else { |
| 1244 |
error = data.data; |
| 1245 |
} |
| 1246 |
break; |
| 1247 |
case 'check_activate_plugin': |
| 1248 |
case 'check_activate_theme': |
| 1249 |
error = wp_reset.activate_failed + ' ' + collection_item.name; |
| 1250 |
break; |
| 1251 |
case 'check_activate_license_plugin': |
| 1252 |
case 'check_activate_license_theme': |
| 1253 |
if (data.data == 'unknown') { |
| 1254 |
error = wp_reset.activating_license_unknown + ' ' + collection_item.name; |
| 1255 |
} else { |
| 1256 |
error = wp_reset.activating_license_failed + ' ' + collection_item.name; |
| 1257 |
} |
| 1258 |
break; |
| 1259 |
default: |
| 1260 |
error = false; |
| 1261 |
} |
| 1262 |
|
| 1263 |
if (error != false) { |
| 1264 |
$('[data-action="' + message_id + '"]').append('<div class="wpr-collections-error">' + error + '</div>'); |
| 1265 |
collections_errors.push(error); |
| 1266 |
} |
| 1267 |
|
| 1268 |
$('[data-action="' + message_id + '"]').addClass('wpr-collections-installer-error'); |
| 1269 |
} |
| 1270 |
|
| 1271 |
$('[data-action="' + message_id + '"]').removeClass('wpr-collections-installer-loading'); |
| 1272 |
$('[data-action="' + message_id + '"]').addClass('wpr-collections-installer-done'); |
| 1273 |
} |
| 1274 |
|
| 1275 |
collections_retried = false; |
| 1276 |
collections_ajax_queue_index++; |
| 1277 |
|
| 1278 |
if (collections_ajax_queue.length == 0) { |
| 1279 |
wpr_swal.close(); |
| 1280 |
return false; |
| 1281 |
} |
| 1282 |
|
| 1283 |
if (do_next_called == false && typeof collections_ajax_queue[collections_ajax_queue_index] !== 'undefined') { |
| 1284 |
if (typeof $('.wpr-collections-installer div.wpr-collections-installer-done:last').offset() !== 'undefined') { |
| 1285 |
var scroll_top = |
| 1286 |
$('.wpr-collections-installer div.wpr-collections-installer-done:last').offset().top - |
| 1287 |
$('.wpr-collections-installer').offset().top + |
| 1288 |
$('.wpr-collections-installer').scrollTop() - |
| 1289 |
60; |
| 1290 |
$('.wpr-collections-installer').animate({ scrollTop: scroll_top }, 600, function () { |
| 1291 |
collections_do_ajax(); |
| 1292 |
}); |
| 1293 |
} else { |
| 1294 |
collections_do_ajax(); |
| 1295 |
} |
| 1296 |
} else { |
| 1297 |
wpr_swal.close(); |
| 1298 |
|
| 1299 |
$('.wpr-collections-installer').css('padding', '0px 40px'); |
| 1300 |
$('.wpr-collections-installer').css('height', '236px'); |
| 1301 |
|
| 1302 |
if (collections_errors.length > 0) { |
| 1303 |
var errors_html = ''; |
| 1304 |
for (e in collections_errors) { |
| 1305 |
errors_html += |
| 1306 |
'<div class="wpr-collections-installer-message wpr-collections-installer-error"><span class="dashicons"></span> ' + |
| 1307 |
collections_errors[e] + |
| 1308 |
'</div>'; |
| 1309 |
} |
| 1310 |
wpr_swal |
| 1311 |
.fire({ |
| 1312 |
icon: 'error', |
| 1313 |
title: 'Collection was installed, but the following errors occured!', |
| 1314 |
html: '<div class="wpr-collections-installer-errors">' + errors_html + '</div>', |
| 1315 |
showConfirmButton: true, |
| 1316 |
}) |
| 1317 |
.then((result) => { |
| 1318 |
location.reload(); |
| 1319 |
}); |
| 1320 |
} else { |
| 1321 |
wpr_swal |
| 1322 |
.fire({ |
| 1323 |
icon: 'success', |
| 1324 |
title: 'Collection was installed successfully!', |
| 1325 |
showConfirmButton: true, |
| 1326 |
timer: 2000, |
| 1327 |
timerProgressBar: true, |
| 1328 |
}) |
| 1329 |
.then((result) => { |
| 1330 |
location.reload(); |
| 1331 |
}); |
| 1332 |
} |
| 1333 |
} |
| 1334 |
}, |
| 1335 |
}); |
| 1336 |
} //run collection ajax |
| 1337 |
|
| 1338 |
function wpr_position_sidebar_ads() { |
| 1339 |
pos_left = Math.round($('#wp_reset_form nav').width()) + 260; |
| 1340 |
pos_top = Math.round($('#wp_reset_form #logo-icon').offset().top); |
| 1341 |
if($('body').hasClass('rtl')){ |
| 1342 |
$('#wpr-sidebar-ads').css('top', pos_top + 'px').css('right', pos_left + 'px'); |
| 1343 |
} else { |
| 1344 |
$('#wpr-sidebar-ads').css('top', pos_top + 'px').css('left', pos_left + 'px'); |
| 1345 |
} |
| 1346 |
$('#wpr-sidebar-ads').show(); |
| 1347 |
} // wpr_position_sidebar_ads |
| 1348 |
|
| 1349 |
wpr_position_sidebar_ads(); |
| 1350 |
$(window).on('resize', function() { |
| 1351 |
wpr_position_sidebar_ads(); |
| 1352 |
}) |
| 1353 |
|
| 1354 |
$('.install-wpfssl').on('click',function(e){ |
| 1355 |
if (!confirm('The free WP Force SSL plugin will be installed & activated from the official WordPress repository.')) { |
| 1356 |
return; |
| 1357 |
} |
| 1358 |
|
| 1359 |
jQuery('body').append('<div style="width:550px;height:450px; position:fixed;top:10%;left:50%;margin-left:-275px; color:#444; background-color: #fbfbfb;border:1px solid #DDD; border-radius:4px;box-shadow: 0px 0px 0px 4000px rgba(0, 0, 0, 0.85);z-index: 9999999;"><iframe src="' + wp_reset.wpfssl_install_url + '" style="width:100%;height:100%;border:none;" /></div>'); |
| 1360 |
jQuery('#wpwrap').css('pointer-events', 'none'); |
| 1361 |
|
| 1362 |
e.preventDefault(); |
| 1363 |
return false; |
| 1364 |
}); |
| 1365 |
}); // onload |
| 1366 |
|
| 1367 |
function wpr_clear_local(clear_cookies, clear_storage) { |
| 1368 |
var cnt = 0; |
| 1369 |
|
| 1370 |
if (clear_cookies) { |
| 1371 |
var cookies = Cookies.get(); |
| 1372 |
cnt += Object.keys(cookies).length; |
| 1373 |
for (cookie in cookies) { |
| 1374 |
Cookies.remove(cookie); |
| 1375 |
} |
| 1376 |
} |
| 1377 |
|
| 1378 |
if (clear_storage) { |
| 1379 |
cnt += localStorage.length + sessionStorage.length; |
| 1380 |
localStorage.clear(); |
| 1381 |
sessionStorage.clear(); |
| 1382 |
} |
| 1383 |
|
| 1384 |
return cnt; |
| 1385 |
} // wpr_clear_local |
| 1386 |
|
| 1387 |
function wpr_close_dropdowns() { |
| 1388 |
jQuery('.dropdown').removeClass('show'); |
| 1389 |
jQuery('.dropdown-menu').removeClass('show'); |
| 1390 |
} // wpr_close_dropdowns |
| 1391 |
|
| 1392 |
function wpr_fix_dialog_close(event, ui) { |
| 1393 |
jQuery('.ui-widget-overlay').bind('click', function () { |
| 1394 |
jQuery('#' + event.target.id).dialog('close'); |
| 1395 |
}); |
| 1396 |
} // wpr_fix_dialog_close |
| 1397 |
|