ACF_Local_JSON::get_filenamepublicACF 6.3

Gets the filename for an ACF JSON file.

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

Хуки из метода

Возвращает

Строку|true|false.

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

$ACF_Local_JSON = new ACF_Local_JSON();
$ACF_Local_JSON->get_filename( $key, $post );
$key(строка) (обязательный)
The ACF post key.
$post(массив) (обязательный)
The main ACF post array.

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

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

Код ACF_Local_JSON::get_filename() ACF 6.4.2

public function get_filename( $key, $post ) {
	$load_path = '';

	if ( is_array( $this->files ) && isset( $this->files[ $key ] ) ) {
		$load_path = $this->files[ $key ];
	}

	/**
	 * Filters the filename used when saving JSON.
	 *
	 * @since 6.2
	 *
	 * @param string $filename  The default filename.
	 * @param array  $post      The main post array for the item being saved.
	 * @param string $load_path The path that the item was loaded from.
	 */
	$filename = apply_filters( 'acf/json/save_file_name', $key . '.json', $post, $load_path );

	if ( ! is_string( $filename ) ) {
		return false;
	}

	$filename = sanitize_file_name( $filename );

	// sanitize_file_name() can potentially remove all characters.
	if ( empty( $filename ) ) {
		return false;
	}

	return $filename;
}