WP HOOKS
filtrod 2.0.0

upload_mimes

Args 2Plik wp-includes/functions.phpDokumentacja WP ↗

Opis

Zmienia listę dozwolonych typów MIME w bibliotece mediów — np. aby pozwolić na upload SVG.

Przykład użycia

add_filter( 'upload_mimes', ... )php
add_filter( 'upload_mimes', 'wpdocs_allow_svg' );

function wpdocs_allow_svg( $mimes ) {
	$mimes['svg'] = 'image/svg+xml';
	return $mimes;
}

Wskazówka — Pozwolenie na SVG wymaga dodatkowej sanitizacji — pliki SVG mogą zawierać skrypty.

Parametry

ParametrTypOpis
$tarrayMime types keyed by the file extension regex corresponding to those types.
$userint | \WP_User | nullUser ID, User object or null if not provided (indicates current user).

Wywołanie

Rejestracja callbackaphp
// rejestracja funkcji zwrotnej — podaj liczbę argumentów!
add_filter( 'upload_mimes', 'twoja_funkcja', 10, 2 );

function twoja_funkcja($param_1, $param_2) {
	// Twój kod
}

Popularne w tej kategorii