=== Snipfire ===
Contributors: papaman
Tags: code snippets, functions, custom css, custom javascript, header footer code
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 0.15.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Safe, fast code snippets for PHP, CSS, JS and HTML: a real code editor, conditions, crash protection and one-click import from other plugins.

== Description ==

Snipfire lets you add PHP, CSS, JavaScript and HTML to your site without editing theme files, and without the risk of locking yourself out.

= It can't take your site down =

* Every snippet is checked before it's saved: syntax errors and functions or classes that already exist are caught first.
* Switching a PHP or HTML snippet on test-loads your site. If it crashes, it's switched straight back off.
* A snippet that causes a fatal error later is switched off automatically, and the error is shown with its line.
* Safe mode: a private link (or one line in wp-config.php) stops all snippets so you can log in and fix things.
* Snipfire's own screens never run snippets, so you can always get back in.

= A proper code editor =

* The editor behind VS Code, with autocomplete for WordPress, WooCommerce and PHP functions and hooks.
* Pick a hook in add_action() or add_filter() and Snipfire writes the callback with its parameters.
* Hover documentation, parameter hints, live error checking, Emmet for HTML and CSS, one-click formatting.
* Folders, search, filters, bulk actions, dark and light themes, and version history with side-by-side comparison.
* A classic screen that works without JavaScript is always there too.

= Fast by design =

Snippets are stored as files and loaded from one compiled index, with no database queries. CSS and JavaScript can be printed inline or served as cached files.

= Runs exactly where you want =

Each snippet runs automatically on a hook of your choice, as a shortcode, or only when you click Run. Conditions decide where: page type (including WooCommerce shop, product, cart, checkout and thank-you pages), post type, post or page, taxonomy term, URL, query parameters such as UTM tags, cookies, logged-in users and roles, device, date range, time of day, day of the week, site environment and active plugins.

= Switch in two clicks =

Import from WPCode, Code Snippets, FluentSnippets, Header Footer Code Manager, Simple Custom CSS and JS, Post Snippets, Woody Code Snippets or the Customizer's Additional CSS. The other plugin doesn't even need to be active. Then switch over: Snipfire switches the snippets off there and on here, and test-loads your site. Old shortcodes keep working.

= A library of ready-made snippets =

70 snippets in 10 packs, each tested with the current WordPress and WooCommerce: harden WordPress, clean up the page head, turn off what you don't use (comments, feeds, search, the block editor…), admin and login touches, content and media, WooCommerce essentials, privacy, analytics codes, and a Greek e-shop pack (receipt or invoice with a checked VAT number, Greek phone and postcode checks, a cash on delivery fee, greeklish addresses). Install one or a whole pack; they arrive switched off in a Library folder so you can read them first. When a library snippet improves, Snipfire offers the update and keeps the settings you changed. The library comes with the plugin: nothing is downloaded.

= For developers =

A REST API and WP-CLI commands (wp snipfire …) for automation and deployment, and JSON export and import.

= Snipfire Pro =

Snipfire is complete on its own. [Snipfire Pro](https://snipfirewp.com) is a separate add-on that adds SCSS and LESS with shared partials, scripts that wait for cookie consent (Complianz, CookieYes, Cookiebot and more), a testing mode with a shareable preview link, a visual hook finder, team access by role, an activity log, two-way Git sync with GitHub and GitLab, and visitor country, referrer, language and WooCommerce cart and customer conditions.

== Installation ==

1. Install Snipfire from Plugins > Add New, or upload the plugin folder to /wp-content/plugins/.
2. Activate it. You'll find it under Snipfire in the admin menu.
3. Open Tools & Safe Mode and bookmark your safe mode link.

== Frequently Asked Questions ==

= What if a snippet breaks my site? =

Snipfire switches off a snippet that causes a fatal error, usually before anyone notices. If you can't reach the admin, open your safe mode link (from Snipfire > Tools & Safe Mode), or add define( 'SNIPFIRE_SAFE_MODE', true ); to wp-config.php. Snippets stop running and you can fix the one that broke.

= Where are snippets stored? =

As files in wp-content/snipfire/, protected against direct access. Compiled CSS and JavaScript files go to wp-content/uploads/snipfire/.

= Will I lose my snippets if I uninstall? =

No. Settings are removed, but your snippet files stay unless you define SNIPFIRE_DELETE_DATA as true in wp-config.php before deleting the plugin.

= Does Snipfire contact any outside service? =

No. The only request it makes is to your own site, to test-load it when you switch a snippet on. The snippet library comes with the plugin. A few library snippets add a service's code to your pages (Google Analytics, Google Tag Manager, Meta Pixel, Microsoft Clarity): they only run once you add your own ID and switch them on, and then your visitors' browsers load that service, as with any tracking code.

== Changelog ==

= 0.15.0 =
* New: the snippet library. 70 ready-made, tested snippets in 10 packs, including a Greek e-shop pack. Install from Snipfire > Snippet library, the classic screen, `wp snipfire library` or the REST API. Updates keep the settings you changed.
* New: WordPress abilities to list and install library snippets.

= 0.14.0 =
* Renamed to Snipfire. The shortcode is [snipfire], the WP-CLI command `wp snipfire`, the REST API `snipfire/v1`, and snippets are stored in wp-content/snipfire/.

= 0.13.0 =
* New HTML locations: before or after paragraph N, before or after the excerpt, and in post lists before or after post N or between posts (block and classic themes).
* Header & Footer screen: three boxes for code in the head, after <body> and in the footer, each a snippet with history and conditions.
* Files: ads.txt, app-ads.txt, llms.txt and /.well-known/security.txt served by WordPress, and extra robots.txt lines. WP-CLI: `wp snipfire files`.
* Shortcode finder: see where snippet shortcodes are used, spot ones that print nothing, and rewrite other plugins' shortcodes to Snipfire's. WP-CLI: `wp snipfire shortcodes`.
* See who else has a snippet open, and get asked before a save overwrites someone else's newer version.
* WordPress abilities (WordPress 6.9+) for AI assistants and the MCP adapter: list, read, check, save and switch snippets. Off for outside tools until you switch them on in Tools.
* `SNIPFIRE_DISABLE_PHP` in wp-config.php turns off PHP snippets for everyone; `DISALLOW_UNFILTERED_HTML` makes Snipfire view-only.
* Import from Post Snippets and Woody Code Snippets. WPCode's paragraph, excerpt and post-list locations now come across exactly.
* WP-CLI: `wp snipfire list` takes --folder, --hook and --fields; `create` and `update` take --position.

= 0.12.0 =
* Every snippet has a permanent ID that travels with it in exports, so the same snippet is recognised on other sites (used by Snipfire Pro's Git sync).
* WP-CLI: `wp snipfire create` and `update` take --folder, --description and --tags.
* Copies are named "Copy of …" in your language.

= 0.11.0 =
* Snipfire is now the free core; SCSS/LESS, cookie consent, testing mode, the hook finder, team access, the activity log and the visitor, language and WooCommerce cart conditions move to the Snipfire Pro add-on.
* The editor runs on WordPress's own React, so it loads faster.
* Snippet settings that need Pro are kept, and fail safely without it: a snippet waiting for cookie consent doesn't run, one in testing mode runs for nobody, and SCSS keeps its last compiled CSS.
* The history keeps the last 10 versions of each snippet.

= 0.10.0 =
* Translation ready: every screen, message and label can be translated, and Greek is included.
* Each person sees Snipfire in their own profile language.
* The editor toolbar wraps instead of overflowing when labels are longer.

= 0.9.0 =
* Team access: give each WordPress role no access, view only, CSS/JS/HTML without PHP, or full access. Administrators always have full access.
* Activity log: see who created, edited, switched on or off, deleted or restored each snippet, which snippets were switched off after an error, and who changed settings. Filter it by snippet, person or kind of change.
* WP-CLI: `wp snipfire access`, `wp snipfire log`.

= 0.8.0 =
* Visual hook finder: click "Hooks" in the admin bar on any page to see every WordPress, WooCommerce, plugin and theme hook labelled right where it fires.
* Click a hook to see what it passes, what's already attached at which priority, and which snippets run there, then add HTML or PHP on it in one click.
* The side panel also lists hooks in the page head, actions that run before the page (init, template_redirect…) and the filters used on the page.

= 0.7.0 =
* Cookie consent: JS and HTML snippets can wait until the visitor accepts cookies (statistics, marketing, preferences or functional). They run the moment the visitor accepts, without a reload, and it works with page caches.
* Works with Complianz, CookieYes, Cookiebot, Borlabs Cookie, the WP Consent API and Google Consent Mode v2 (Real Cookie Banner and most other consent tools).
* New "Cookie consent given" condition for PHP snippets.
* Tools > Cookie consent shows the consent tool Snipfire found and what happens without one. WP-CLI: `wp snipfire consent`, `--consent` on create/update.

= 0.6.0 =
* WooCommerce conditions: cart subtotal, items in cart, cart contains product or category, customer has bought a product, customer's paid orders (first-time buyers), and the order-received (thank you) page.
* Visitor conditions: referrer, country (from Cloudflare and other CDN/host headers, or WooCommerce geolocation) and language (WPML, Polylang or the site language).
* The rule picker is grouped (Visitor, Page, WooCommerce, Date & time, Site) and each new rule explains what it checks.
* WPCode referrer rules are now imported.

= 0.5.0 =
* History: every change to a snippet keeps the previous version. Compare any version side by side with what's in the editor, load it into the editor, or restore it in one click (the version it replaces is kept too).
* Testing mode: set a snippet to "Only testers" and it runs only for admins and people you send the preview link to. Visitors don't see it until you click Go live.
* Admin bar item listing the snippets in testing; preview visitors see a small badge with an exit link. Preview pages are never cached.
* WP-CLI: `wp snipfire revisions`, `wp snipfire restore`, `wp snipfire preview`, and `--mode=test` on create/update.

= 0.4.0 =
* SCSS and LESS: CSS snippets can be written in SCSS or LESS and are compiled when you save. Errors show on the right line, live while you type.
* Partials: pull other SCSS/LESS snippets in by name (`@use 'variables';`, `@import 'mixins';`). Changing a partial recompiles every snippet that uses it.
* `@use 'sass:math'`, `sass:map`, `sass:color` and the other built-in modules work, as do `@use ... with (...)` and `@forward`.
* A typo in a live SCSS/LESS stylesheet doesn't take your styles off the site: the last version that compiled stays live until it's fixed.
* WPCode SCSS snippets are imported as SCSS source instead of compiled CSS.

= 0.3.0 =
* Import from WPCode (including its global header/footer boxes), Code Snippets, FluentSnippets, Header Footer Code Manager, Simple Custom CSS and JS, the Customizer's Additional CSS, and WPCodeBox (beta). Locations, priorities, tags and conditions are carried over; anything that can't be matched exactly is flagged for review.
* One-click switch over: snippets are switched off in the other plugin and on in Snipfire, and the site is test-loaded. The other plugin's shortcodes keep working.
* WP-CLI: `wp snipfire import-from <plugin> [--dry-run] [--switch]`.

= 0.2.0 =
* New editor app: Monaco (VS Code) editor with WordPress, WooCommerce and PHP autocomplete, hover docs, parameter hints, hook callbacks, Emmet, Prettier formatting and live error checking.
* Folders, search, filters, drag and drop, bulk actions, duplicate, export from the editor.
* Fix: fatal errors before any output now switch the snippet off too.

= 0.1.0 =
* First development version: core engine, basic admin screens, REST API and WP-CLI.

== Credits ==

The editor uses Monaco Editor (MIT), Prettier (MIT) and emmet-monaco-es (MIT). Hook data comes from wp-hooks/wordpress-core (GPL). The editor app's source is included in the app/ folder (build it with npm run build).
