Quick StartGlobal settings with per-site overrides

Global settings with per-site overrides

A must-use plugin that sets Easy SVG and Easy SVG Pro switches on every site from code, with exceptions per site, per environment and per multisite network.

Both plugins keep their switches in three WordPress options. A must-use plugin filters them, so every site gets the same values and the code is the single place to change them.

OptionWhat is in it
easy_svg_settingsFree plugin: svg_upload, icons, max_mb
easy_svg_pro_featuresPro feature switches, for example collections, editor, sources, cli, presets
easy_svg_pro_settingsPro settings: size_enabled, max_mb, tags_enabled, extra_tags, extra_attrs

1. The must-use plugin

<?php
/**
 * Plugin Name: Agency Easy SVG settings
 * Description: Easy SVG and Easy SVG Pro switches for every site.
 */

defined( 'ABSPATH' ) || exit;

/**
 * Code defaults, then the network's values, then this site's values.
 */
function agency_easy_svg_config(): array {
	$config = array(
		'easy_svg_settings'     => array(
			'svg_upload' => true,
			'icons'      => true,
			'max_mb'     => 2,
		),
		'easy_svg_pro_features' => array(
			'collections' => true,
			'editor'      => true,
			'sources'     => true,
			'cli'         => true,
			'presets'     => true,
		),
		'easy_svg_pro_settings' => array(
			'tags_enabled' => false,
		),
	);

	// Example: never fetch preset sets on a local copy.
	if ( 'local' === wp_get_environment_type() ) {
		$config['easy_svg_pro_features']['presets'] = false;
	}

	if ( is_multisite() ) {
		$network = get_site_option( 'agency_easy_svg', array() );
		$config  = array_replace_recursive( $config, is_array( $network ) ? $network : array() );
	}

	$site = get_option( 'agency_easy_svg', array() );
	return array_replace_recursive( $config, is_array( $site ) ? $site : array() );
}

/**
 * Lay the configured keys over whatever the site has stored.
 */
function agency_easy_svg_force( $value, $option ) {
	$forced = agency_easy_svg_config()[ $option ] ?? array();
	return array_replace( is_array( $value ) ? $value : array(), $forced );
}

add_filter( 'option_easy_svg_settings', 'agency_easy_svg_force', 10, 2 );
add_filter( 'default_option_easy_svg_settings', 'agency_easy_svg_force', 10, 2 );
add_filter( 'option_easy_svg_pro_features', 'agency_easy_svg_force', 10, 2 );
add_filter( 'default_option_easy_svg_pro_features', 'agency_easy_svg_force', 10, 2 );
add_filter( 'option_easy_svg_pro_settings', 'agency_easy_svg_force', 10, 2 );
add_filter( 'default_option_easy_svg_pro_settings', 'agency_easy_svg_force', 10, 2 );

Keys you put in the config are fixed. Keys you leave out stay editable on each site under Icons → Features, Icons → Settings and Icons → Configurator.

2. Override one value on one site

wp option update agency_easy_svg '{"easy_svg_pro_features":{"presets":false}}' --format=json

Remove an override with wp option delete agency_easy_svg (or wp site option delete agency_easy_svg).

When it worked

  • Icons → Features shows the configured switches on, on every site.
  • wp option get easy_svg_pro_features --format=json prints your values, also on a site that never saved its settings.

Pitfalls

It has to be a must-use plugin. The free plugin reads its switches while it loads, before normal plugins and before init. Filters added in a normal plugin or inside a hook come too late for SVG uploads.
  • Fixed means fixed. A forced key still has its switch in wp-admin. Flipping it there saves, but the next page load shows your code's value again. Tell clients which switches are yours.
  • The license still decides. A forced Pro switch does nothing until the site's license is active. On multisite one seat covers the whole network.
  • Limits are still checked. max_mb is clamped to 1 to 20 MB, whatever you set. Unsafe names in extra_tags and extra_attrs (such as script or onclick) are dropped.