Uploads and limitseasy_svg_max_mb_ceiling

easy_svg_max_mb_ceiling

Raise or lower the highest SVG size, in megabytes, that admins can choose under Icons, Settings. The field, the slider and the saved value follow it.

Filter · Easy SVG · Status: Stable

Under Icons → Settings an administrator picks the "Maximum SVG size (MB)". That choice has an upper end, 20 MB by default, so nobody sets a value that would let one file slow the server down. This filter moves that upper end: the field, the slider and the value that is actually stored all follow it.

Usage

apply_filters( 'easy_svg_max_mb_ceiling', int $ceiling )

Applied in includes/settings.php, inside easy_svg_max_mb_ceiling(). The result is cast to an integer and raised to at least 1.

When to use it

  • Your site really needs larger SVGs than 20 MB (large technical drawings, detailed maps) and you want the site administrator to decide the exact size in the settings screen.
  • You run sites for clients and want to lower the highest choice, for example to 5 MB, so nobody can set more by accident.
  • You build an add-on that offers larger files as a feature. Gate it on EASY_SVG_PANEL_API: this filter belongs to the panel contract.

Do not use it when:

  • You want to set the limit itself from code. The ceiling only decides what can be chosen. Use easy_svg_max_bytes for the effective limit.
  • You need less than 1 MB. The setting works in whole megabytes from 1 upwards, whatever the ceiling.

Parameters

body
$ceilingint
Required

The highest value, in whole megabytes, the setting may hold. Default 20.

Return value

returnint

The new ceiling in megabytes. The value is cast with (int), so 2.5 becomes 2. Anything below 1 (including 0, negative numbers and null) is treated as 1.

Default

20

Examples

Allow up to 50 MB

/**
 * Let administrators choose up to 50 MB under Icons, Settings.
 */
function mysite_svg_max_mb_ceiling( $ceiling ) {
	return 50;
}
add_filter( 'easy_svg_max_mb_ceiling', 'mysite_svg_max_mb_ceiling' );

After this, the field and slider on the Settings tab go up to 50 and the help text says "Allowed: 1 to 50 MB."

Lock client sites to at most 5 MB

function mysite_svg_max_mb_ceiling_client( $ceiling ) {
	return min( (int) $ceiling, 5 );
}
add_filter( 'easy_svg_max_mb_ceiling', 'mysite_svg_max_mb_ceiling_client', 20 );

min() keeps another plugin from raising it again, as long as your callback runs later (priority 20).

In an add-on, only where the plugin understands it

function myaddon_raise_svg_ceiling( $ceiling ) {
	return max( (int) $ceiling, 100 );
}

function myaddon_boot() {
	if ( ! defined( 'EASY_SVG_PANEL_API' ) ) {
		return; // Easy SVG missing or too old: nothing to raise.
	}
	add_filter( 'easy_svg_max_mb_ceiling', 'myaddon_raise_svg_ceiling' );
}
add_action( 'plugins_loaded', 'myaddon_boot' );

max() respects a site that already raised the ceiling higher than your add-on would.

How it works

The ceiling is read in three places:

  1. Every time the settings are read. easy_svg_settings() passes the stored option through easy_svg_sanitize_settings(), which clamps max_mb to the range 1 up to the ceiling. That happens on every page load where Easy SVG checks a setting, and every time the size limit is needed.
  2. When the settings are saved. The Settings tab saves through POST /wp-json/easy-svg/v1/settings. A number above the ceiling is not rejected: it is clamped, saved, and the panel shows "The size cap was saved as 50 MB, the nearest allowed value (1 to 50)." A number below 1 is rejected by the route with a 400 error.
  3. When the Icons screen loads. The value is handed to the panel as maxMbCeiling, so the number field, the slider and the "Allowed: 1 to N MB." text end exactly where the server clamps.

The ceiling only limits the setting. The filter easy_svg_max_bytes runs after it and is not clamped, so code can still set any limit in bytes.

Pitfalls

  • Lowering it lowers what is already saved, at once. The clamp runs on every read. A site that stored 50 MB uses 20 MB as soon as your raising filter is gone, for example when the add-on that added it is deactivated.
  • Raising it again can bring the old value back. The database still holds 50 until somebody saves the Settings tab. Reactivate the add-on before any save, and the site is back at 50 MB. After a save, the clamped value is what is stored.
  • Register it on every request, not only in wp-admin. The panel saves through the REST API, where is_admin() is false. A callback wrapped in if ( is_admin() ) is missing during the save, so the value is clamped back to 20. The same goes for uploads from the block editor, which also use the REST API.
  • It runs often. Every settings read applies the filter. Keep the callback cheap: no remote calls, no heavy queries.
  • The server limit still applies. A ceiling of 100 MB does not help when PHP's upload_max_filesize is 8 MB.
A large ceiling lets an administrator allow files whose cleaning keeps a PHP worker busy for a long time. Raise it only on servers that can afford it, and keep the structure bounds (easy_svg_max_use_tags, easy_svg_max_php_tags) at their defaults.