Skip to content

Instantly share code, notes, and snippets.

@kauhat
Last active July 23, 2019 15:10
Show Gist options
  • Save kauhat/e835ec961d233fc025654ba9dd43f79a to your computer and use it in GitHub Desktop.
Save kauhat/e835ec961d233fc025654ba9dd43f79a to your computer and use it in GitHub Desktop.
Sage Advanced Custom Fields helpers
  1. Add the helper under app/acf.php
  2. Add acf into the "Sage required files" section of resources/functions.php
<?php
namespace App;
/**
* Init
*/
add_action('acf/init', function () {
// Use Google API key from .env
acf_update_setting('google_api_key', GOOGLE_API_KEY);
// Site wide theme options
if(function_exists('acf_add_options_page')) {
acf_add_options_page([
'page_title' => 'Site Settings',
'position' => 40.1
]);
}
});
/**
* Set JSON save/load paths
*/
add_filter('acf/settings/save_json', function ($path) {
// Set Sage friendly path at /resources/assets/acf-json
$path = get_stylesheet_directory() . '/assets/acf-json';
return $path;
});
add_filter('acf/settings/load_json', function ($paths) {
// Append with our path
$paths[] = get_stylesheet_directory() . '/assets/acf-json';
return $paths;
});
<?php
// ...
/**
* Sage required files
*
* The mapped array determines the code library included in your theme.
* Add or remove files to the array as needed. Supports child theme overrides.
*/
array_map(function ($file) use ($sage_error) {
$file = "../app/{$file}.php";
if (!locate_template($file, true, true)) {
$sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file), 'File not found');
}
}, ['helpers', 'setup', 'filters', 'admin', 'acf']); // <-- Update this line
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment