Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // NOTE: You'd have to create /acf-json/components/ foler in the theme manually first,
- // just like how you'd manutally create the acf-json folder
- /**
- * In /includes/json.php:17, is where the acf_json write the local json file.
- * So this hook has to be 9, just before acf write the file.
- */
- add_action('acf/update_field_group', 'maybe_switch_json_location_just_before_saving', 9);
- add_action('acf/duplicate_field_group', 'maybe_switch_json_location_just_before_saving', 9);
- add_action('acf/untrash_field_group', 'maybe_switch_json_location_just_before_saving', 9);
- add_action('acf/trash_field_group', 'maybe_switch_json_location_just_before_saving', 9);
- add_action('acf/delete_field_group', 'maybe_switch_json_location_just_before_saving', 9);
- function maybe_switch_json_location_just_before_saving($field_group) {
- if ($field_group['is_acf_component']) {
- acf_update_setting('save_json', get_stylesheet_directory() . '/acf-json/components/');
- }
- }
- /**
- * In /includes/json.php:17, is where the acf_json write the local json file.
- * So this hook has to be 11, just after acf finished writing the file.
- */
- add_action('acf/update_field_group', 'switch_json_location_back_after_saving', 11);
- add_action('acf/duplicate_field_group', 'switch_json_location_back_after_saving', 11);
- add_action('acf/untrash_field_group', 'switch_json_location_back_after_saving', 11);
- add_action('acf/trash_field_group', 'switch_json_location_back_after_saving', 11);
- add_action('acf/delete_field_group', 'switch_json_location_back_after_saving', 11);
- function switch_json_location_back_after_saving() {
- acf_update_setting('save_json', get_stylesheet_directory() . '/acf-json/');
- }
- /**
- * In case of new install for initial syncing, we need to tell acf to look
- * into the component folder as well
- */
- add_filter('acf/settings/load_json', 'maybe_load_component_from_json_location');
- function maybe_load_component_from_json_location($paths) {
- $paths[] = get_stylesheet_directory() . '/acf-json/components/';
- return $paths;
- }
Add Comment
Please, Sign In to add comment