ACF_Local_JSON::scan_field_groups()publicACF 5.9.0

Scans for JSON field groups.

{} Это метод класса: ACF_Local_JSON{}

Хуков нет.

Возвращает

Массив.

Использование

$ACF_Local_JSON = new ACF_Local_JSON();
$ACF_Local_JSON->scan_field_groups();

Список изменений

С версии 5.9.0 Введена.

Код ACF_Local_JSON::scan_field_groups() ACF 5.10.2

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;
}