From 22eb09e82ced4f48f492c0163ff1eb1bf7202f26 Mon Sep 17 00:00:00 2001 From: Dekart Deploy Bot Date: Thu, 7 May 2026 21:34:07 +0300 Subject: [PATCH] Add auto-delete for ACF JSON on field group removal --- wp-content/themes/dekart/functions.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/wp-content/themes/dekart/functions.php b/wp-content/themes/dekart/functions.php index 9eeb758..072fa4d 100644 --- a/wp-content/themes/dekart/functions.php +++ b/wp-content/themes/dekart/functions.php @@ -919,3 +919,19 @@ add_filter('acf/settings/load_json', function($paths) { $paths[] = get_stylesheet_directory() . '/acf-json'; return $paths; }); + +// Автоматическое удаление JSON при удалении группы полей +add_action('trashed_post', 'dekart_acf_delete_json', 10, 1); +add_action('deleted_post', 'dekart_acf_delete_json', 10, 1); +function dekart_acf_delete_json($post_id) { + if (get_post_type($post_id) !== 'acf-field-group') { + return; + } + + $key = get_post_field('post_name', $post_id); + $json_file = get_stylesheet_directory() . '/acf-json/' . $key . '.json'; + + if (file_exists($json_file)) { + unlink($json_file); + } +}