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); + } +}