agentleFS
pabloirracionalpabloirracional/claude-skills/skills/building-wordpress-plugins/SKILL.md

building-wordpress-plugins

Skill0 starsChanged 4 months agoMITView on GitHub

Builds WordPress plugins following core conventions - hooks, Settings API, nonces, and sanitization - with a real plugin file checked by php -l and a concrete sanitization test against an XSS payload. Use whenever the user wants to build, extend, or debug a WordPress plugin, or mentions actions, filters, shortcodes, or custom post types.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use hooks, not direct core modification: - every customization goes through add_action/add_filter.

    line 12
  2. Distinctive:

    Not just "this looks right" - actually parsed by PHP 8.3 without errors.

    line 25
  3. Distinctive:

    Check the target WordPress and PHP version before using newer language features - many production sites lag behind (confirmed PHP 8.3 here.

    line 55

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Building WordPress plugins

Builds a WordPress plugin using core patterns, checked with the real PHP linter rather than eyeballed for syntax.

Workflow

  1. Use hooks, not direct core modification - every customization goes through add_action/add_filter.
  2. Namespace everything: prefix functions, options, and post meta keys with a unique plugin prefix - see DFW_ / dfw_ throughout the tested example below.
  3. Security on every input/output boundary: sanitize on input, escape on output, nonce every state-changing action - see the concrete sanitization test below.
  4. Use the Settings API for options pages rather than hand-rolling form handling.
  5. register_activation_hook/register_deactivation_hook for setup/teardown - never run setup code on every page load.

Tested: full plugin passes php -l

scripts/demo-plugin/demo-feedback-widget.php is a complete, working example (activation hook, footer-rendered form, nonce-protected submission handler, Settings API page) - checked with the real PHP linter:

$ php -l demo-feedback-widget.php
No syntax errors detected in demo-feedback-widget.php

Not just "this looks right" - actually parsed by PHP 8.3 without errors.

Tested: sanitization actually removes the dangerous part of a real payload

Ran the sanitize-on-input step against a real XSS-style payload, not a hypothetical:

RAW INPUT:        <script>alert(1)</script>Hello  there

friend
AFTER sanitize:    alert(1)Hello there friend
PASS - script tag removed by sanitization

The <script> tags are stripped and whitespace/newlines are collapsed to single spaces - which is what sanitize_text_field() does in WordPress core. The takeaway to apply when reviewing someone's plugin code: sanitizing on input (before it's stored) still requires escaping on output too (esc_html, esc_attr) - sanitization strips dangerous tags, but doesn't make a string safe to echo raw in every possible HTML context (attribute vs body vs URL each need their own escaping function).

Nonce pattern (in the tested example)

// Render: embed a nonce field tied to a specific action name
wp_nonce_field('dfw_submit_feedback', 'dfw_nonce');

// Handle: verify that exact action name before doing anything state-changing
if (!wp_verify_nonce($_POST['dfw_nonce'], 'dfw_submit_feedback')) {
    wp_die('Security check failed.');
}

The action name ('dfw_submit_feedback') must match exactly between the two calls - a common bug is using a generic nonce action name shared across multiple forms, which weakens the protection nonces are meant to provide.

Notes

  • This was checked with PHP's own linter (php -l) and a standalone sanitization test, not against a running WordPress installation - wp_verify_nonce, get_option, etc. are real WordPress core functions used correctly per their documented signatures, but weren't executed against live WP core here (that would need a full WP install with database, which this environment doesn't have).
  • Check the target WordPress and PHP version before using newer language features - many production sites lag behind (confirmed PHP 8.3 here; some hosts still run 7.4).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.