acf_get_image_mime_types()ACF 6.8.7

Returns allowed MIME types restricted to images.

Returns

Array.

Usage

acf_get_image_mime_types( $field );
$field(array|false)
Optional field array for field-specific filtering.
Default: false

Changelog

Since 6.8.7 Introduced.

acf_get_image_mime_types() code ACF 6.8.8

function acf_get_image_mime_types( $field = false ) {
	static $image_mimes = null;

	if ( null === $image_mimes ) {
		$image_mimes   = array();
		$allowed_mimes = get_allowed_mime_types();

		foreach ( $allowed_mimes as $ext => $mime ) {
			if ( wp_match_mime_types( 'image', $mime ) ) {
				$image_mimes[ $ext ] = $mime;
			}
		}

		/**
		 * Filters the image MIME types allowed for image and gallery fields.
		 *
		 * @since 6.8.7
		 *
		 * @param array $image_mimes The allowed image MIME types keyed by extension.
		 */
		$image_mimes = apply_filters( 'acf/get_image_mime_types', $image_mimes );
	}

	if ( ! is_array( $field ) || empty( $field['type'] ) ) {
		return $image_mimes;
	}

	/**
	 * Filters the image MIME types allowed for a specific field.
	 *
	 * @since 6.8.7
	 *
	 * @param array $image_mimes The allowed image MIME types keyed by extension.
	 * @param array $field         The field array.
	 */
	$field_type = acf_maybe_get( $field, 'type', '' );
	$field_name = acf_maybe_get( $field, '_name', '' );
	$field_key  = acf_maybe_get( $field, 'key', '' );

	$field_mimes = apply_filters( "acf/get_image_mime_types/type={$field_type}", $image_mimes, $field );
	$field_mimes = apply_filters( "acf/get_image_mime_types/name={$field_name}", $field_mimes, $field );
	$field_mimes = apply_filters( "acf/get_image_mime_types/key={$field_key}", $field_mimes, $field );

	return $field_mimes;
}