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,iconorcapability(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_tabsor raises the ceiling througheasy_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
Today 3. What each level covers:
- 1: the action
easy_svg_panel_enqueue, the filtereasy_svg_panel_menu_tabswithtab id => label, the filtereasy_svg_max_mb_ceiling, andwindow.EasySvgPanel.registerTab()with anidand arenderfunction. - 2: a tab may also name its
area(one of the five labelled areas of the panel), bring its ownicon, and require acapability. Menu entries can bearray( 'label' => ..., 'capability' => ... )beside the plain label. The oldergroupkey still works as an alias forarea. - 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 wheneasy-svg.phploads, on every request, whether or not any feature is switched on.- On the Icons screen, the panel script
easy-svg-panelreceivesEasySvgPanelData.panelApiwith(int) EASY_SVG_PANEL_API. The PHP and the JavaScript side read the same constant, so they cannot disagree. window.EasySvgPanel.apiisNumber( 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_enqueuefires with the handleeasy-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_loadedor the panel actions instead of checking at file load. - Looking for it in JavaScript outside the Icons screen.
window.EasySvgPanelandEasySvgPanelDataare 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.