=== SilverStream PHP Snippets ===
Contributors: silverstreamdigital
Tags: snippets, php, shortcode, code, javascript
Requires at least: 5.8
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

The lightweight, fast, and powerful code snippet manager for WordPress. Run PHP, HTML, CSS and JavaScript snippets safely — without touching your theme files.

== Description ==

**SilverStream PHP Snippets** is a clean, modern, and lightweight code snippet manager built for WordPress administrators and developers who want full control over their custom code — without the risk of editing theme files.

Whether you're adding Google Analytics, injecting custom CSS, running PHP functions, or managing JavaScript across your site, SilverStream PHP Snippets gives you one organised, safe place to do it all.

> No theme file editing. No code lost on theme updates. No white screen of death.

= ⚡ Lightweight & Fast =

SilverStream PHP Snippets is built with performance in mind:

* No bloated JavaScript frameworks
* No unnecessary database queries on the front end
* CSS and JS snippets injected efficiently via native WordPress hooks
* Only loads admin assets on plugin pages — zero front-end overhead
* Stores snippets in a single, optimised custom database table

= 🛡️ Safe by Design =

* **Recovery Mode** — if a PHP snippet causes a fatal error, the plugin automatically disables it and notifies you in the admin. Your site stays up, always.
* **Nonce protection** on every admin action
* **Capability checks** — only administrators can create, edit, or delete snippets
* **Snippet code never comes from URL parameters** — only from the plugin's own secured database table
* Works independently of your theme — snippets survive theme switches and updates

= 🔤 Multi-Language Support =

Write snippets in any of four languages:

* **PHP** — server-side execution with full WordPress function support. Supports code with or without opening `<?php` tags
* **HTML** — output raw HTML anywhere via shortcode
* **CSS** — injected at the end of the page after all theme styles, so your rules always win
* **JavaScript** — injected in the footer after all scripts have loaded

= 🎯 Four Run Modes =

Choose exactly how and when each snippet runs:

* **Manual Shortcode** — place `[sss tag="your-tag"]` anywhere: posts, pages, widgets, or page builder modules (Divi, Elementor, Beaver Builder, and more)
* **Header** — fires automatically on `wp_head` on every page load
* **Footer** — fires automatically on `wp_footer` on every page load
* **Execute on Demand** — call `<?php echo ss_run('your-tag'); ?>` from any theme template file

= 📋 Clean Snippet Management =

* **Search** — instantly filter snippets by name, tag, or description
* **Categories** — organise snippets into groups and filter by category
* **Active/Inactive toggle** — enable or disable any snippet with one click, both from the list and the edit form
* **Language badges** — colour-coded PHP, HTML, CSS, JS labels on every row
* **Full-width admin UI** — spacious, readable list with no clutter
* **Scrollable table** — handles large snippet libraries without losing the header

= 🌐 Global Header & Footer Scripts =

A dedicated **Header & Footer** page lets you paste scripts that run sitewide without creating a named snippet:

* Scripts in Header (`wp_head`) — perfect for Google Analytics, AdSense, Facebook Pixel, Search Console verification, custom meta tags
* Scripts in Footer (`wp_footer`) — perfect for chat widgets, conversion tracking, deferred scripts

= 🔄 One-Click Migration =

Already using another snippet plugin? SilverStream PHP Snippets scans your database and imports your existing snippets in one click. Currently supports:

* **Insert PHP Code Snippet** by xyzscripts (xyz-ips)
* **Insert PHP Code Snippet** by Patrick Bender

Existing `[xyz-ips snippet="..."]` shortcodes continue to work after migration — no page editing required.

= 🧩 Works Everywhere =

* **Divi** ✅
* **Elementor** ✅
* **Beaver Builder** ✅
* **Gutenberg / Block Editor** ✅
* **Classic Editor** ✅
* **Any WordPress theme** ✅

= 🚀 Upgrade to Pro =

[SilverStream PHP Snippets Pro](https://silverstreamdigital.co.za/silverstream-php-snippets-pro) adds powerful features for developers and agencies:

* **Backup & Restore** — export all snippets to JSON and restore on any site
* **Snippet Library** — 10+ ready-made snippets (Google Analytics, Disable XML-RPC, Allow SVG, and more)
* **Duplicate Snippet** — clone any snippet with a pre-filled form
* **Export as PHP** — download all active PHP snippets as a standalone PHP file for child themes
* **Export Individual Snippets** — export any single snippet as JSON
* **Execution Priority** — control the exact order snippets run (1-999)
* **Who Last Edited** — track which user last saved each snippet
* **Dark Mode** — full charcoal dark theme for the plugin UI
* **Database Cleanup** — delete inactive snippets, clear error logs, reset all data

**Pro Pricing**

| Plan | Annual | Lifetime |
|------|--------|----------|
| Single Site | R299/year | R799 |
| 3 Sites | R599/year | R1499 |
| Unlimited | R999/year | R2499 |

[Get Pro Now →](https://silverstreamdigital.co.za/silverstream-php-snippets-pro)

== Installation ==

1. Upload the plugin folder to `/wp-content/plugins/silverstream-php-snippets/` or install via **Plugins → Add New** in your WordPress dashboard.
2. Activate the plugin through the **Plugins** menu.
3. Navigate to **PHP Snippets** in your admin sidebar to add your first snippet.
4. If you have existing snippets in another plugin, go to **PHP Snippets → Migrate from Plugin** for a one-click import.

== Frequently Asked Questions ==

= Is it safe to run PHP snippets through this plugin? =

Yes. Snippets can only be saved by administrators with the `manage_options` capability. All admin actions are protected by WordPress nonces. Snippet code is executed only from the plugin's own secured database table — never from URL parameters or untrusted input. Recovery Mode automatically disables any snippet that causes a fatal error.

= Does it work with Divi, Elementor, and other page builders? =

Yes. CSS and JS are injected via `wp_head` and `wp_footer` — WordPress core hooks that fire on every page regardless of page builder. PHP and HTML shortcodes work in any module that supports shortcode rendering.

= How do I write PHP snippets? =

You can write PHP with or without opening `<?php` tags — both work. Just write your code and save. No `?>` closing tag is needed.

= Why isn't my CSS showing? =

If a theme or plugin has highly specific CSS rules, your snippet CSS may be overridden. Add `!important` to your CSS rules to ensure they take priority. Example: `body { background: red !important; }`

= What happens if a PHP snippet breaks my site? =

Recovery Mode catches the fatal error, automatically disables the offending snippet, and shows you a notice in the WordPress admin with the error details and a link to fix the snippet. Your site stays online.

= Can I use this for Google Analytics? =

Yes. Go to **PHP Snippets → Header & Footer** and paste your GA4 gtag.js code into the **Scripts in Header** box. Save — done.

= What happens to my snippets if I deactivate the plugin? =

Deactivating does NOT delete your data. Your snippets remain safely in the database and will continue working when you reactivate.

= What happens if I delete the plugin? =

Your snippet data is preserved in the database even after deleting the plugin files. Upgrade to Pro for database cleanup and uninstall options.

= Will my snippets survive WordPress and theme updates? =

Yes. Snippets are stored in a custom database table that is completely independent of WordPress core, your theme, and any other plugins. Updates to any of these will never affect your snippets.

= Does it support multisite? =

The free version supports standard WordPress installations. Multisite support is on the Pro roadmap.

= Can I migrate from WPCode or Code Snippets? =

Currently the importer supports Insert PHP Code Snippet (xyzscripts and Patrick Bender versions). WPCode and Code Snippets importers are on the roadmap.

== Screenshots ==

1. Main snippet list — full-width, scrollable, with search and category filter
2. Add/Edit snippet form with multi-language support and run mode selection
3. Global Header & Footer scripts page
4. Migrate from Plugin — one-click importer
5. Settings page with plugin information and Pro upgrade

== Changelog ==

= 1.0.0 =
* Initial release
* PHP, HTML, CSS, and JavaScript snippet support
* Shortcode, Header/Footer, and On-Demand run modes
* Active/Inactive toggle per snippet
* Category system with search and filter
* Global Header & Footer scripts page
* Recovery Mode — auto-disables snippets that cause fatal PHP errors
* One-click migration from xyz-ips and compatible plugins
* Backward-compatible `[xyz-ips snippet="..."]` shortcode support
* Full-width admin UI with scrollable table
* Works with Divi, Elementor, and all WordPress themes and page builders

== Upgrade Notice ==

= 1.0.0 =
Initial release. Install and start managing your code snippets safely without touching theme files.
