Add auto-delete for ACF JSON on field group removal
This commit is contained in:
parent
08a1040b59
commit
22eb09e82c
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user