Last active
March 3, 2020 15:29
-
-
Save benedict-w/7801843ac5442d75bb5c1dcfab3683dc to your computer and use it in GitHub Desktop.
Auto generated acf-json from Advanced Custom Fields JSON export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Auto generated acf-json from Advanced Custom Fields JSON export | |
* How to use: | |
* | |
* 1. Export ACF fields to JSON. | |
* 2. Rename file "acf-export.json". | |
* 3. Place in theme root. | |
* 4. Add this script to functions.php, run once. Check scripts are added to acf-json folder (needs write permissions). | |
* 5. Remove after successful use! | |
*/ | |
add_action('init', function() { | |
if($json = json_decode(file_get_contents(get_stylesheet_directory() . '/acf-export.json'))) { | |
$path = get_stylesheet_directory() . '/acf-json'; | |
foreach ($json as &$item) { | |
$fp = fopen(sprintf('%s/%s.json', $path, $item->key), 'w'); | |
fwrite($fp, json_encode($item)); | |
fclose($fp); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment