ConstantsEASY_SVG_PANEL_API

EASY_SVG_PANEL_API

Version number of the Icons panel contract in Easy SVG: tabs, menu entries, icon collections and the size ceiling. Check it before you extend the panel.

Constant · Easy SVG · Status: Stable

EASY_SVG_PANEL_API tells an add-on which version of the Icons panel's extension points is installed: adding tabs, menu entries and icon collections to the panel, and raising the size ceiling. A filter cannot be asked whether it exists, so this number is how your code tells an older Easy SVG apart from a newer one.

Usage

define( 'EASY_SVG_PANEL_API', 3 );

Defined in easy-svg.php when the plugin loads. The same number reaches JavaScript on the Icons screen as window.EasySvgPanelData.panelApi and window.EasySvgPanel.api.

When to use it

  • Your add-on registers a tab in the Icons panel and wants to use area, icon or capability (needs 2 or more).
  • Your add-on lists its own icon collections in the Icon library tab with registerCollections() (needs 3).
  • Your add-on adds menu entries through easy_svg_panel_menu_tabs or raises the ceiling through easy_svg_max_mb_ceiling, and should do nothing on a plugin that does not have them.

Do not use it when you only need the sanitizer (EASY_SVG_API) or the icon functions (EASY_SVG_ICONS_API).

Parameters

None: this is a constant, not a function.

Return value

EASY_SVG_PANEL_APIint

Today 3. What each level covers:

  • 1: the action easy_svg_panel_enqueue, the filter easy_svg_panel_menu_tabs with tab id => label, the filter easy_svg_max_mb_ceiling, and window.EasySvgPanel.registerTab() with an id and a render function.
  • 2: a tab may also name its area (one of the five labelled areas of the panel), bring its own icon, and require a capability. Menu entries can be array( 'label' => ..., 'capability' => ... ) beside the plain label. The older group key still works as an alias for area.
  • 3: window.EasySvgPanel.registerCollections(), through which an add-on lists its icon collections in the Icon library tab.

An add-on written for 1 or 2 keeps working on 3.

Default

Not applicable: the constant is missing when Easy SVG is not active. In JavaScript, window.EasySvgPanel.api falls back to 1 when the panel data carries no number.

Examples

Enqueue your panel bundle only where it can work

function myaddon_panel_assets( $panel_handle ) {
	if ( ! defined( 'EASY_SVG_PANEL_API' ) || EASY_SVG_PANEL_API < 2 ) {
		return;
	}

	wp_enqueue_script(
		'myaddon-panel',
		plugins_url( 'build/panel.js', __FILE__ ),
		array( $panel_handle ),
		'1.0.0',
		true
	);
}
add_action( 'easy_svg_panel_enqueue', 'myaddon_panel_assets' );

Making the panel's handle a dependency means your script loads after Easy SVG's, so window.EasySvgPanel is ready.

Check the level in JavaScript

( function () {
	var panel = window.EasySvgPanel;
	if ( ! panel ) {
		return;
	}

	if ( panel.api >= 3 && typeof panel.registerCollections === 'function' ) {
		panel.registerCollections( {
			id: 'myaddon-brand',
			load: function () {
				return Promise.resolve( [] );
			},
		} );
	}
} )();

A menu entry that degrades on older versions

function myaddon_menu_tabs( $tabs ) {
	if ( defined( 'EASY_SVG_PANEL_API' ) && EASY_SVG_PANEL_API >= 2 ) {
		$tabs['myaddon'] = array(
			'label'      => __( 'Brand icons', 'myaddon' ),
			'capability' => 'edit_theme_options',
		);
	} else {
		$tabs['myaddon'] = __( 'Brand icons', 'myaddon' );
	}

	return $tabs;
}
add_filter( 'easy_svg_panel_menu_tabs', 'myaddon_menu_tabs' );

How it works

  • define( 'EASY_SVG_PANEL_API', 3 ) runs when easy-svg.php loads, on every request, whether or not any feature is switched on.
  • On the Icons screen, the panel script easy-svg-panel receives EasySvgPanelData.panelApi with (int) EASY_SVG_PANEL_API. The PHP and the JavaScript side read the same constant, so they cannot disagree.
  • window.EasySvgPanel.api is Number( EasySvgPanelData.panelApi || 1 ). It only exists on the Icons screen, where the panel script is loaded.
  • Right after the panel script is set up, the action easy_svg_panel_enqueue fires with the handle easy-svg-panel. That is the moment to enqueue your own bundle.

Pitfalls

  • Checking too early in PHP. A plugin that loads before Easy SVG (for example from a folder that sorts first, or a must-use plugin) does not see the constant yet. Hook into plugins_loaded or the panel actions instead of checking at file load.
  • Looking for it in JavaScript outside the Icons screen. window.EasySvgPanel and EasySvgPanelData are not on other admin pages.
  • Using === on a level. Later levels keep everything earlier ones offered. Compare with >=.
  • Raising the ceiling without the check. The ceiling filter is part of this contract. On a site without Easy SVG the filter does nothing, so the check only matters when you also change UI or messages based on it.