acf_get_image_sizes()ACF 5.0.0

acf_get_image_sizes

This function will return an array of available image sizes

@type    function
Хуки из функции

Возвращает

(Массив).

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

acf_get_image_sizes();

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

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

Код acf_get_image_sizes() ACF 5.10.2

function acf_get_image_sizes() {

	// vars
	$sizes = array(
		'thumbnail' => __( 'Thumbnail', 'acf' ),
		'medium'    => __( 'Medium', 'acf' ),
		'large'     => __( 'Large', 'acf' ),
	);

	// find all sizes
	$all_sizes = get_intermediate_image_sizes();

	// add extra registered sizes
	if ( ! empty( $all_sizes ) ) {

		foreach ( $all_sizes as $size ) {

			// bail early if already in array
			if ( isset( $sizes[ $size ] ) ) {

				continue;

			}

			// append to array
			$label          = str_replace( '-', ' ', $size );
			$label          = ucwords( $label );
			$sizes[ $size ] = $label;

		}
	}

	// add sizes
	foreach ( array_keys( $sizes ) as $s ) {

		// vars
		$data = acf_get_image_size( $s );

		// append
		if ( $data['width'] && $data['height'] ) {

			$sizes[ $s ] .= ' (' . $data['width'] . ' x ' . $data['height'] . ')';

		}
	}

	// add full end
	$sizes['full'] = __( 'Full Size', 'acf' );

	// filter for 3rd party customization
	$sizes = apply_filters( 'acf/get_image_sizes', $sizes );

	// return
	return $sizes;

}