Add auto-delete for ACF JSON on field group removal

This commit is contained in:
Dekart Deploy Bot 2026-05-07 21:34:07 +03:00
parent 08a1040b59
commit 22eb09e82c

View File

@ -919,3 +919,19 @@ add_filter('acf/settings/load_json', function($paths) {
$paths[] = get_stylesheet_directory() . '/acf-json'; $paths[] = get_stylesheet_directory() . '/acf-json';
return $paths; 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);
}
}