add actual version
This commit is contained in:
@@ -56,12 +56,31 @@ function clear_template_cache ( $template ) {
|
||||
}
|
||||
|
||||
|
||||
// Функция очистки главной страницы
|
||||
function clear_index_cache () {
|
||||
|
||||
$index_file = '/var/www/profile/html/wp-content/uploads/fpcache/regenerate/index.html';
|
||||
|
||||
if (file_exists($index_file)) {
|
||||
return unlink($index_file);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Общая функция для сброса кеша на основе условий поста
|
||||
*
|
||||
* @param WP_Post $post Объект поста (уже содержит ID)
|
||||
*/
|
||||
function clear_post_cache_based_on_conditions( $post_id, $post ) {
|
||||
|
||||
$fpc_signal = WP_CONTENT_DIR . '/uploads/fpcache/.last_modified';
|
||||
|
||||
// Обновляем сигнальный файл если вдруг прервется выполнение
|
||||
touch($fpc_signal);
|
||||
|
||||
// Кеш по типу поста
|
||||
if ($post->post_type == 'profile_article') {
|
||||
@@ -78,6 +97,7 @@ function clear_post_cache_based_on_conditions( $post_id, $post ) {
|
||||
if ($main_item === 'true' || $main_item === '1') {
|
||||
clear_template_cache('template-parts/home/main-item');
|
||||
clear_template_cache('template-parts/home/list-items');
|
||||
clear_index_cache(); // на всякий случай сбросим главную
|
||||
}
|
||||
|
||||
// Сброс колонки
|
||||
@@ -85,10 +105,10 @@ function clear_post_cache_based_on_conditions( $post_id, $post ) {
|
||||
if ($colon_item === 'true' || $colon_item === '1') {
|
||||
clear_template_cache('template-parts/home/colon-item');
|
||||
clear_template_cache('template-parts/home/list-items');
|
||||
clear_index_cache(); // на всякий случай сбросим главную
|
||||
}
|
||||
|
||||
// Обновляем сигнальный файл
|
||||
$fpc_signal = WP_CONTENT_DIR . '/uploads/fpcache/.last_modified';
|
||||
// Обновляем сигнальный файл по завершению
|
||||
touch($fpc_signal);
|
||||
|
||||
}
|
||||
@@ -97,7 +117,7 @@ function clear_post_cache_based_on_conditions( $post_id, $post ) {
|
||||
add_action('save_post', function($post_id, $post, $update) {
|
||||
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
|
||||
if (wp_is_post_revision($post_id)) return;
|
||||
if (!current_user_can('edit_post', $post_id)) return;
|
||||
//if (!current_user_can('edit_post', $post_id)) return;
|
||||
if ($post->post_status !== 'publish') return;
|
||||
|
||||
clear_post_cache_based_on_conditions($post_id, $post); // Передаем только $post
|
||||
@@ -105,8 +125,8 @@ add_action('save_post', function($post_id, $post, $update) {
|
||||
|
||||
// Хук для запланированных публикаций
|
||||
add_action('transition_post_status', function($new_status, $old_status, $post) {
|
||||
|
||||
if ($new_status !== 'publish') return;
|
||||
if (!current_user_can('edit_post', $post->ID)) return; // Используем $post->ID
|
||||
|
||||
clear_post_cache_based_on_conditions($post->ID, $post); // Передаем только $post
|
||||
|
||||
}, 10, 3);
|
||||
Reference in New Issue
Block a user