This commit is contained in:
2026-07-02 15:54:39 -06:00
commit 9883323161
17470 changed files with 4470592 additions and 0 deletions
@@ -0,0 +1,91 @@
/**
* Pressable Cache Management - Flush cache for individual page column
* Branded modal popup replaces browser alert()
*/
if (window.attachEvent) {
window.attachEvent('onload', flush_object_cache_column_button_action);
} else {
if (window.onload) {
var curronload_1 = window.onload;
var newonload_1 = function(evt) { curronload_1(evt); flush_object_cache_column_button_action(evt); };
window.onload = newonload_1;
} else {
window.onload = flush_object_cache_column_button_action;
}
}
/* ── Branded modal (injected once) ─────────────────────────────────────── */
function pcmEnsureModal() {
if (document.getElementById('pcm-col-modal-overlay')) return;
var overlay = document.createElement('div');
overlay.id = 'pcm-col-modal-overlay';
overlay.style.cssText =
'display:none;position:fixed;inset:0;background:rgba(4,0,36,.45);'
+ 'z-index:999999;align-items:center;justify-content:center;';
overlay.innerHTML =
'<div style="background:#fff;border-radius:12px;padding:28px 32px;max-width:420px;width:90%;'
+ 'box-shadow:0 8px 40px rgba(4,0,36,.18);font-family:sans-serif;position:relative;">'
+ '<div style="width:48px;height:4px;background:#03fcc2;border-radius:4px;margin-bottom:16px;"></div>'
+ '<p id="pcm-col-modal-msg" style="margin:0 0 22px;font-size:14px;color:#040024;line-height:1.6;"></p>'
+ '<button id="pcm-col-modal-ok" style="background:#dd3a03;color:#fff;border:none;border-radius:8px;'
+ 'padding:10px 28px;font-size:13.5px;font-weight:700;cursor:pointer;font-family:sans-serif;'
+ 'transition:background .2s;">OK</button>'
+ '</div>';
document.body.appendChild(overlay);
overlay.style.display = 'flex'; overlay.style.display = 'none'; // force style parse
document.getElementById('pcm-col-modal-ok').addEventListener('click', function() {
overlay.style.display = 'none';
});
overlay.addEventListener('click', function(e) {
if (e.target === overlay) overlay.style.display = 'none';
});
// hover on OK button
var okBtn = document.getElementById('pcm-col-modal-ok');
okBtn.addEventListener('mouseenter', function() { okBtn.style.background = '#b82f00'; });
okBtn.addEventListener('mouseleave', function() { okBtn.style.background = '#dd3a03'; });
}
function pcmShowColumnModal(msg) {
pcmEnsureModal();
document.getElementById('pcm-col-modal-msg').textContent = msg;
document.getElementById('pcm-col-modal-overlay').style.display = 'flex';
}
function flush_object_cache_column_button_action() {
jQuery(document).ready(function($) {
$("a[id^='flush-object-cache-url']").on('click', function(e) {
e.preventDefault();
var post_id = $(e.currentTarget).attr('data-id');
var nonce = $(e.currentTarget).attr('data-nonce');
$('#flush-object-cache-url-' + post_id).css('cursor', 'wait');
$.ajax({
type: 'GET',
url: ajaxurl,
data: { action: 'pcm_flush_object_cache_column', id: post_id, nonce: nonce },
dataType: 'json',
cache: false,
success: function(data) {
$('#flush-object-cache-url-' + post_id).css('cursor', 'pointer');
if (typeof data.success !== 'undefined' && data.success === true) {
pcmShowColumnModal('Batcache flushed successfully \u2705');
} else {
pcmShowColumnModal('Something went wrong while trying to flush the cache for this page.');
}
},
error: function() {
$('#flush-object-cache-url-' + post_id).css('cursor', 'pointer');
pcmShowColumnModal('Request failed. Please try again.');
}
});
return false;
});
});
}
@@ -0,0 +1,89 @@
/**
* Pressable Cache Management — Toolbar JS
*
* Handles the combined "Flush Cache for This Page" admin bar button.
*
* Bug fixes vs previous version:
* 1. data-edge on <li> is unsupported by WP add_menu() meta — now uses pcmToolbarData.flushEdge
* passed via wp_localize_script() which works on both admin and frontend.
* 2. Event delegation now targets document.body and checks closest('li').attr('id') correctly,
* rather than querying a non-existent '#wp-admin-bar-*-default' wrapper selector.
* 3. pcm_nonce was only available on frontend (wp_footer). Now comes from pcmToolbarData.nonce
* which is always present via wp_localize_script.
* 4. AJAX handlers now return wp_send_json_success() so jQuery parses valid JSON.
*/
jQuery(document).ready(function($) {
// Ensure the loader overlay exists once
if ( !$('#revert-loader-toolbar').length ) {
$('body').append('<div id="revert-loader-toolbar"></div>');
}
// Resolve AJAX URL: prefer localized value, fall back to WP global
var ajaxUrl = ( typeof pcmToolbarData !== 'undefined' && pcmToolbarData.ajaxurl )
? pcmToolbarData.ajaxurl
: ( typeof ajaxurl !== 'undefined' ? ajaxurl : '' );
// Nonce: from wp_localize_script (works on both admin + frontend)
var nonce = ( typeof pcmToolbarData !== 'undefined' ) ? pcmToolbarData.nonce : '';
// Whether edge cache flush should also fire (passed from PHP via wp_localize_script)
var flushEdge = ( typeof pcmToolbarData !== 'undefined' && pcmToolbarData.flushEdge === '1' );
// ── IDs for both branding variants ───────────────────────────────────────
var combinedIds = [
'wp-admin-bar-pcm-toolbar-parent-flush-cache-of-this-page',
'wp-admin-bar-pcm-toolbar-parent-remove-branding-flush-cache-of-this-page',
];
// ── Fire a single AJAX GET, returns a jQuery deferred ────────────────────
function sendRequest( action ) {
return $.ajax({
type : 'GET',
url : ajaxUrl,
data : { action: action, path: window.location.pathname, nonce: nonce },
dataType: 'json',
cache : false,
});
}
// ── Sequential flush: Batcache first, then Edge Cache if active ───────────
function flushCurrentPage() {
$('#revert-loader-toolbar').show();
sendRequest('pcm_delete_current_page_cache')
.always(function() {
if ( flushEdge ) {
sendRequest('pcm_purge_current_page_edge_cache')
.always(done);
} else {
done();
}
});
}
function done() {
if ( typeof pcmCacheStatics !== 'undefined' ) {
pcmCacheStatics.update();
} else {
$('#revert-loader-toolbar').hide();
}
}
// ── Event delegation on body — catches clicks anywhere inside the <li> ───
// We delegate from body because the admin bar is injected late and the
// submenu UL wrapper varies by WP version. Matching by the <li> id directly
// is the most reliable approach and avoids the broken '-default' suffix.
$('body').on('click', function(e) {
// Walk up from the clicked element to find the nearest <li>
var $li = $(e.target).closest('li');
var id = $li.attr('id') || '';
if ( combinedIds.indexOf(id) !== -1 ) {
e.preventDefault();
flushCurrentPage();
}
});
});
@@ -0,0 +1,6 @@
/**
* Pressable Cache Management — toolbar_remove_branding.js
* This file is intentionally empty.
* The branding-off toolbar handler is now consolidated in toolbar.js
* (PCM_TOOLBAR_REMOVE_BRANDING object) to avoid duplicate AJAX calls.
*/