- Add the helper under
app/acf.php
- Add
acf
into the "Sage required files" section ofresources/functions.php
Last active
July 23, 2019 15:10
-
-
Save kauhat/e835ec961d233fc025654ba9dd43f79a to your computer and use it in GitHub Desktop.
Sage Advanced Custom Fields helpers
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
<?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; | |
}); |
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
<?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