easy_svg_pro_import_max_total_bytes
Cap the total bytes Easy SVG Pro reads from one ZIP import, so an archive that claims to be small cannot use up the memory of your server.
Filter · Easy SVG Pro · Status: Stable
A ZIP can claim its files are small and still unpack to a lot of data. Easy SVG Pro therefore counts the real bytes it reads from an archive and stops at 16 MB. This filter sets that number.
Usage
apply_filters( 'easy_svg_pro_import_max_total_bytes', int $bytes )
Applied in includes/editor/set-import.php, inside zip_entries_from_path(). The result is cast to an integer.
When to use it
- A large set (many detailed icons) stops before its last icons and you have memory to spare.
- You want a lower ceiling on a host with a small PHP memory limit.
- You raised
easy_svg_pro_import_max_entriesand need room for the extra files.
Do not use it when:
- One file is rejected for its own size. That is the free plugin's per file limit,
easy_svg_max_bytes, set under Icons → Settings. - The upload itself fails. PHP's
upload_max_filesizeandpost_max_sizestop the request before this code runs.
Parameters
The total number of bytes read from one archive, counted on what was actually read, not on what the ZIP declares. 16777216 by default.
Return value
The total byte limit. Not clamped: 0 means the first entry already passes the limit and nothing is imported.
Default
16777216 (16 MB).
Examples
Room for a large set on a generous host
/**
* 32 MB of icons. The host has a 512 MB memory limit.
*/
function acme_import_max_total_bytes( $bytes ) {
return max( $bytes, 32 * MB_IN_BYTES );
}
add_filter( 'easy_svg_pro_import_max_total_bytes', 'acme_import_max_total_bytes' );
Follow the memory limit
/**
* Allow at most a quarter of the memory limit, because the bytes are held about three times.
*/
function acme_import_max_total_bytes_by_memory( $bytes ) {
$limit = wp_convert_hr_to_bytes( (string) ini_get( 'memory_limit' ) );
if ( $limit <= 0 ) {
// -1 means unlimited. Keep the default.
return $bytes;
}
return max( MB_IN_BYTES, min( $bytes * 4, (int) floor( $limit / 4 ) ) );
}
add_filter( 'easy_svg_pro_import_max_total_bytes', 'acme_import_max_total_bytes_by_memory' );
Raise both limits together
function acme_big_imports( $value ) {
return 'easy_svg_pro_import_max_entries' === current_filter() ? 6000 : 48 * MB_IN_BYTES;
}
add_filter( 'easy_svg_pro_import_max_entries', 'acme_big_imports' );
add_filter( 'easy_svg_pro_import_max_total_bytes', 'acme_big_imports' );
How it works
The limit lives in the one ZIP reader every import path shares: set import, pack upload under Icons → Packs, the Font Awesome import, preset installs and wp easy-svg pack import.
The reader goes through the archive in order. It reads each .svg file and manifest.json that passes the per entry checks, then adds the length of what it really read to a running total. When that total passes your limit, the entry that crossed the line is dropped and reading stops. Everything read up to then is imported normally.
The default is 16 MB, not more, because the bytes are held about three times during an import: raw, with labels, and prepared after sanitizing. 64 MB of icons was measured at about 192 MB of memory, against a WordPress default memory limit of 40 MB.
Pitfalls
- The stop is silent. Entries after the limit are never read, so they are not listed as refused. The import looks complete, just smaller.
- Three times the memory. A limit of 64 MB needs roughly 200 MB of PHP memory during the import.
- Zero blocks every import. Return a positive number.
- Not the upload limit. If the browser upload fails, raise PHP's upload settings, not this filter.