WPSEO_Image_Utils::has_usable_file_size
Checks a size version of an image to see if it's not too heavy.
Метод класса: WPSEO_Image_Utils{}
Хуки из метода
Возвращает
true|false. True when the image is within limits, false if not.
Использование
$result = WPSEO_Image_Utils::has_usable_file_size( $image );
- $image(массив) (обязательный)
- Image to check the file size of.
Код WPSEO_Image_Utils::has_usable_file_size() WPSEO Image Utils::has usable file size Yoast 28.0
public static function has_usable_file_size( $image ) {
if ( ! is_array( $image ) || $image === [] ) {
return false;
}
/**
* Filter: 'wpseo_image_image_weight_limit' - Determines what the maximum weight
* (in bytes) of an image is allowed to be, default is 2 MB.
*
* @param int $max_bytes The maximum weight (in bytes) of an image.
*/
$max_size = apply_filters( 'wpseo_image_image_weight_limit', 2_097_152 );
// We cannot check without a path, so assume it's fine.
if ( ! isset( $image['path'] ) ) {
return true;
}
return ( self::get_file_size( $image ) <= $max_size );
}