Guest User

Untitled

a guest
Feb 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <?php
  2.  
  3. // NOTE: You'd have to create /acf-json/components/ foler in the theme manually first,
  4. // just like how you'd manutally create the acf-json folder
  5.  
  6.  
  7. /**
  8. * In /includes/json.php:17, is where the acf_json write the local json file.
  9. * So this hook has to be 9, just before acf write the file.
  10. */
  11. add_action('acf/update_field_group', 'maybe_switch_json_location_just_before_saving', 9);
  12. add_action('acf/duplicate_field_group', 'maybe_switch_json_location_just_before_saving', 9);
  13. add_action('acf/untrash_field_group', 'maybe_switch_json_location_just_before_saving', 9);
  14. add_action('acf/trash_field_group', 'maybe_switch_json_location_just_before_saving', 9);
  15. add_action('acf/delete_field_group', 'maybe_switch_json_location_just_before_saving', 9);
  16. function maybe_switch_json_location_just_before_saving($field_group) {
  17. if ($field_group['is_acf_component']) {
  18. acf_update_setting('save_json', get_stylesheet_directory() . '/acf-json/components/');
  19. }
  20. }
  21.  
  22. /**
  23. * In /includes/json.php:17, is where the acf_json write the local json file.
  24. * So this hook has to be 11, just after acf finished writing the file.
  25. */
  26. add_action('acf/update_field_group', 'switch_json_location_back_after_saving', 11);
  27. add_action('acf/duplicate_field_group', 'switch_json_location_back_after_saving', 11);
  28. add_action('acf/untrash_field_group', 'switch_json_location_back_after_saving', 11);
  29. add_action('acf/trash_field_group', 'switch_json_location_back_after_saving', 11);
  30. add_action('acf/delete_field_group', 'switch_json_location_back_after_saving', 11);
  31. function switch_json_location_back_after_saving() {
  32. acf_update_setting('save_json', get_stylesheet_directory() . '/acf-json/');
  33. }
  34.  
  35. /**
  36. * In case of new install for initial syncing, we need to tell acf to look
  37. * into the component folder as well
  38. */
  39. add_filter('acf/settings/load_json', 'maybe_load_component_from_json_location');
  40. function maybe_load_component_from_json_location($paths) {
  41. $paths[] = get_stylesheet_directory() . '/acf-json/components/';
  42.  
  43. return $paths;
  44. }
Add Comment
Please, Sign In to add comment