Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

All docs

Network snippets (multisite) Agency plan

Agency · Network snippets are part of the Agency plan (and its free trial), on multisite networks. Plans

On a multisite network, each site has its own snippets. Network snippets are written once, by a super admin, and run on every site of the network: a security tweak for all sites, a shared tracking script, one admin notice for everyone.

Set up

  1. Network-activate both Snipfire and Snipfire Pro (Network Admin → Plugins). Network snippets only run on sites where both are active; the network settings warn you if they aren't network-activated.
  2. Go to Network Admin → Snipfire. It's the same editor as on a site, labelled Network.

Without the Agency plan (or without an active licence), Network Admin → Snipfire says what's needed, with Upgrade to Agency or Activate your licence.

Create snippets as on a site: PHP, HTML, CSS, JavaScript (and SCSS or LESS), with locations, conditions, folders, history, Run, bulk actions and settings forms.

Not available for network snippets, because they're about one site: testing mode, cookie consent, schedules and snippet performance. The snippet library, the importers, the generators and exporting as a plugin are only on each site's own screen.

Where and when they run

  • On every site of the network, unless a condition says otherwise.
  • Before the site's own snippets: at the same location and priority, the network snippet runs first.
  • Use the Site of the network condition (in the Site group) to run one only on some sites (is), or on every site but some (is not).
  • A site's own shortcode with the same tag wins over a network snippet's on that site. [snipfire id="…"] always means the site's own snippet.
  • Their CSS and JavaScript files are served from the main site's uploads folder.

The safety net

Network snippets get the same protection as a site's own, across the network:

  • Saving checks the code (syntax, functions that already exist among network snippets).
  • Switching one on test-loads the main site and up to two other sites (or up to three of the sites the Site of the network condition allows). The network settings list which sites.
  • If a network snippet crashes on any site, it's switched off on every site, and the error is recorded with the site it happened on: The error below happened on … The snippet was switched off on every site. It's also in the network's activity log.

A site's own snippet that declares the same function as a network snippet crashes on that site, and the site's snippet is the one switched off (it loads second). The save check only compares network snippets with each other.

Network safe mode

Stops every network snippet on every site, for when one breaks the network. The sites' own snippets keep running.

  • Network settings & safe mode (at the bottom of the network screen's sidebar) → Switch network safe mode on.

  • Or, in wp-config.php:

    define( 'SNIPFIRE_NETWORK_SAFE_MODE', true );
    
  • Or wp snipfire network safe-mode on.

A site's own safe mode (its link, or SNIPFIRE_SAFE_MODE) stops network snippets on that site too. SNIPFIRE_DISABLE_PHP applies to network snippets as everywhere.

On each site: "From the network"

A site's editor lists the network snippets under its own, as From the network, read-only: click one to see its settings in words and its code. Edit on the network screen takes super admins there.

People with full Snipfire access on the site can Switch off for this site (and Switch back on for this site), unless the super admin marked the snippet Required. On multisite, full access means super admins: site administrators get at most CSS, JS and HTML access, so in practice only super admins switch network snippets off per site.

On the network screen, each snippet has:

  • Required (sites can't switch it off),
  • Sites that switched it off, with Switch back on there.

Changes are recorded in the network's activity log and in the site's.

Who can do what

  • Only super admins manage network snippets. Team access on a site never gives network rights.
  • Anyone with view access on a site can read the network snippets' code there. Keep API keys out of the code: use the secrets vault. snipfire_secret() in a network snippet reads the vault of the site it's running on.
  • With DISALLOW_UNFILTERED_HTML, the network screen is read-only.

Good to know

  • Storage: wp-content/snipfire/network/ (snippets, history, activity, and which sites switched what off), so running network snippets costs no database query. CSS and JavaScript files: the main site's uploads/snipfire-network/.
  • Snippets on this page, in the block editor panel, lists only the site's own snippets.
  • Without the Agency plan or Snipfire Pro, network snippets don't run; the sites' own snippets are unaffected.
  • Deleting a site deletes its own snippet folder and its network choices.
  • Nothing of this exists on a single site.
  • The network screen needs JavaScript: there's no classic (no-JavaScript) version, unlike a site's Snipfire screens.

From the command line

wp snipfire network list
wp snipfire network create --title="Hide the WordPress version" --file=hide-version.php --required --active
wp snipfire network create --title="Shop banner" --type=html --hook=wp_body_open \
  --conditions='[[{"type":"site","op":"is","value":["2","3"]}]]' --file=banner.html
wp snipfire network update 4 --no-required
wp snipfire network overrides                              # which sites switched what off
wp snipfire network overrides 3 --site=example.com/shop --off
wp snipfire network safe-mode on

They work the same whatever --url says. See WP-CLI and the REST API.

Something unclear or missing? Tell us