ACF_Local_JSON::scan_files
Scans for JSON files.
Метод класса: ACF_Local_JSON{}
Хуков нет.
Возвращает
Массив
.
Использование
$ACF_Local_JSON = new ACF_Local_JSON(); $ACF_Local_JSON->scan_files( $post_type );
- $post_type(строка)
- The ACF post type to scan for.
По умолчанию: 'acf-field-group'
Список изменений
С версии 6.1 | Введена. |
Код ACF_Local_JSON::scan_files() ACF Local JSON::scan files ACF 6.4.2
function scan_files( $post_type = 'acf-field-group' ) { $json_files = array(); // Loop over "local_json" paths and parse JSON files. foreach ( $this->get_load_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 $this->get_files( $post_type ); }