Skip to content

Instantly share code, notes, and snippets.

@larodiel
Last active December 13, 2022 01:51
Show Gist options
  • Save larodiel/ff9acaf67e9b8c88246f65e4bf89fa7e to your computer and use it in GitHub Desktop.
Save larodiel/ff9acaf67e9b8c88246f65e4bf89fa7e to your computer and use it in GitHub Desktop.
Add the colors that are on WP theme.json on ACF Color pick
<?php
add_action('acf/input/admin_footer', function() {
$themeJsonFile = get_stylesheet_directory() . '/theme.json';
if(file_exists($themeJsonFile)) {
$themeJson = json_decode(file_get_contents($themeJsonFile));
$colorsArray = [];
$colorsJson = '';
foreach($themeJson->settings->color->palette as $color) {
$colorsArray[] = $color->color;
}
$colorsJson = json_encode($colorsArray);
echo "
<script>
if(typeof acf !== 'undefined' && acf?.add_filter !== undefined) {
acf.add_filter('color_picker_args', function(args){
args.palettes = {$colorsJson};
return args;
});
}
</script>
";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment