feat: add flush cache button to branch settings page
- Button 'Сбросить кэш' under Настройки филиала - AJAX handler dekart_ajax_flush_cache(): - my_cache_bump_version() (MU-plugin versioned cache) - wp_cache_flush() (Memcached/Redis drop-in) - DELETE all _transient_* options - Shows success/error notice inline, no page reload
This commit is contained in:
parent
a6222a31ab
commit
c2125d7dcc
@ -2301,6 +2301,62 @@ function dekart_branch_settings_page() {
|
||||
|
||||
<?php submit_button('Сохранить настройки филиала'); ?>
|
||||
</form>
|
||||
|
||||
<hr style="max-width:800px;margin:30px 0;border:none;border-top:1px solid #c3c4c7">
|
||||
|
||||
<div style="max-width:800px">
|
||||
<h2 style="margin-bottom:12px">🗄️ Кеширование</h2>
|
||||
<p class="desc" style="margin-bottom:16px;color:#646970;font-size:12px">Сброс кеша полностью очищает объектный кеш (Memcached/Redis), инвалидирует versioned cache ключи и сбрасывает все буферы плагинов.</p>
|
||||
<button type="button" id="dekart-flush-cache-btn" class="button button-secondary" style="display:inline-flex;align-items:center;gap:6px">
|
||||
<span class="dashicons dashicons-update" style="font-size:16px;width:16px;height:16px"></span> Сбросить кэш
|
||||
</button>
|
||||
<span id="dekart-flush-cache-status" style="margin-left:12px;display:none"></span>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
var btn = document.getElementById('dekart-flush-cache-btn');
|
||||
var status = document.getElementById('dekart-flush-cache-status');
|
||||
if (!btn) return;
|
||||
btn.addEventListener('click', function() {
|
||||
if (btn.disabled) return;
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<span style="display:inline-block;animation:spin 1s linear infinite">↻</span> Сброс...';
|
||||
status.style.display = 'inline';
|
||||
status.innerHTML = '⏳';
|
||||
status.style.color = '#646970';
|
||||
|
||||
var data = new FormData();
|
||||
data.set('action', 'dekart_flush_cache');
|
||||
data.set('nonce', '<?php echo wp_create_nonce( 'dekart_flush_cache_nonce' ); ?>');
|
||||
|
||||
fetch(ajaxurl, { method: 'POST', body: data })
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(j) {
|
||||
if (j.success) {
|
||||
status.innerHTML = '✅ ' + (j.data.message || 'Кэш сброшен');
|
||||
status.style.color = '#00a32a';
|
||||
} else {
|
||||
status.innerHTML = '❌ ' + (j.data.message || 'Ошибка');
|
||||
status.style.color = '#d63638';
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
status.innerHTML = '❌ Ошибка соединения';
|
||||
status.style.color = '#d63638';
|
||||
})
|
||||
.finally(function() {
|
||||
btn.disabled = false;
|
||||
btn.innerHTML = '<span class="dashicons dashicons-update" style="font-size:16px;width:16px;height:16px"></span> Сбросить кэш';
|
||||
setTimeout(function() { status.style.display = 'none'; }, 5000);
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
</style>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
@ -2352,3 +2408,41 @@ function dekart_get_teacher_options() {
|
||||
// ACF: Отзывы (Лагерь) — группа полей
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
// 🗄️ AJAX: Сброс кеша (кнопка в Настройки филиала)
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
add_action( 'wp_ajax_dekart_flush_cache', 'dekart_ajax_flush_cache' );
|
||||
function dekart_ajax_flush_cache() {
|
||||
check_ajax_referer( 'dekart_flush_cache_nonce', 'nonce' );
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_send_json_error( array( 'message' => 'Нет прав' ) );
|
||||
}
|
||||
|
||||
$messages = array();
|
||||
|
||||
// 1. Versioned cache bump (MU-плагин)
|
||||
if ( function_exists( 'my_cache_bump_version' ) ) {
|
||||
my_cache_bump_version();
|
||||
$messages[] = 'version bumped';
|
||||
}
|
||||
|
||||
// 2. WP object cache flush (Memcached/Redis drop-in)
|
||||
if ( function_exists( 'wp_cache_flush' ) ) {
|
||||
wp_cache_flush();
|
||||
$messages[] = 'wp_cache_flush';
|
||||
}
|
||||
|
||||
// 3. Transients — все сразу
|
||||
global $wpdb;
|
||||
$wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE '_transient_%' OR option_name LIKE '_transient_timeout_%'" );
|
||||
|
||||
$messages[] = 'transients clean';
|
||||
|
||||
// 4. CSS/JS кеш — сброс через filemtime (версии ассетов обновятся сами)
|
||||
|
||||
wp_send_json_success( array(
|
||||
'message' => 'Кэш сброшен: ' . implode( ', ', $messages ),
|
||||
'actions' => $messages,
|
||||
) );
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user