ACF_Local_JSON::scan_field_groups
Scans for JSON field groups.
Method of the class: ACF_Local_JSON{}
No Hooks.
Returns
Array.
Usage
$ACF_Local_JSON = new ACF_Local_JSON(); $ACF_Local_JSON->scan_field_groups();
Changelog
| Since 5.9.0 | Introduced. |
ACF_Local_JSON::scan_field_groups() ACF Local JSON::scan field groups code ACF 6.0.4
function scan_field_groups() {
$json_files = array();
// Loop over "local_json" paths and parse JSON files.
$paths = (array) acf_get_setting( 'load_json' );
foreach ( $paths as $path ) {
if ( is_dir( $path ) ) {
$files = scandir( $path );
if ( $files ) {
foreach ( $files as $filename ) {
// Ignore hidden files.
if ( $filename[0] === '.' ) {
continue;
}
// Ignore sub directories.
$file = untrailingslashit( $path ) . '/' . $filename;
if ( is_dir( $file ) ) {
continue;
}
// Ignore non JSON files.
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
if ( $ext !== 'json' ) {
continue;
}
// Read JSON data.
$json = json_decode( file_get_contents( $file ), true );
if ( ! is_array( $json ) || ! isset( $json['key'] ) ) {
continue;
}
// Append data.
$json_files[ $json['key'] ] = $file;
}
}
}
}
// Store data and return.
$this->files = $json_files;
return $json_files;
}