Plugin
PHP Code Snippets
Run PHP snippets without editing your theme — syntax-checked before saving, and switched off automatically if one breaks the site.
/**
Plugin header
- Plugin name:
- PHP Code Snippets – EPAS
- Version:
- 1.0.0
- Requires at least:
- 6.4
- Requires PHP:
- 7.4
- Languages:
- English, Lietuvių
- License:
- GPL-2.0-or-later
- Download size:
- 37 KB
*/
What it does
- Checked before it is saved: every snippet is compiled to verify its syntax, and code that cannot compile is rejected with the parser's own message — nothing is stored.
- Switched off if it breaks: a snippet that crashes a request is deactivated automatically, with the error recorded and shown in the admin. The next page load is healthy again.
- An escape hatch that always works:
define( 'EPAS_SNIPPETS_DISABLE', true );inwp-config.phpstops every snippet while they stay saved and editable. - Per-snippet control over where it runs (everywhere, front end only, admin only) and when:
plugins_loaded,init,wp_head,wp_footeroradmin_init, at your chosen priority. - WordPress's own bundled CodeMirror in PHP mode — syntax highlighting and line numbers, nothing loaded from anywhere else.
Questions
What happens if my snippet has a typo?
If it cannot compile, saving is refused and you see the parser error — nothing is stored. If it compiles but fails while running, the plugin deactivates that snippet, records why, and tells you in the admin. Your site keeps working.
Who is allowed to add PHP?
Only users with both manage_options and unfiltered_html — administrators on a single site, and on multisite super admins only. That is narrower than WordPress's own bar for the same power: anyone who can install a plugin can already run PHP.
Is this safer than editing functions.php?
For small tweaks, yes: a child theme's functions.php has no syntax check and no recovery, so one typo means a white screen. Here the same typo is refused before it reaches your site, and a runtime failure switches only that snippet off.
Do I need the <?php tag?
No. Write plain PHP; a pasted opening tag (or a trailing closing tag) is removed when saving. Tags inside the snippet — dropping into HTML inside a hook callback — are left untouched.
How to get it
This plugin is finished and being prepared for the WordPress.org plugin directory. Until it is published there, email us and we will send you the current zip.