<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mammoth WP</title>
    <description>The latest articles on DEV Community by Mammoth WP (@mammothwp).</description>
    <link>https://dev.to/mammothwp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4219468%2Fb4b2cd89-7b04-4d10-aa32-67e018082a81.png</url>
      <title>DEV Community: Mammoth WP</title>
      <link>https://dev.to/mammothwp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mammothwp"/>
    <language>en</language>
    <item>
      <title>Keep key-shaped strings out of your test fixtures</title>
      <dc:creator>Mammoth WP</dc:creator>
      <pubDate>Wed, 02 Dec 2026 15:08:13 +0000</pubDate>
      <link>https://dev.to/mammothwp/keep-key-shaped-strings-out-of-your-test-fixtures-44ni</link>
      <guid>https://dev.to/mammothwp/keep-key-shaped-strings-out-of-your-test-fixtures-44ni</guid>
      <description>&lt;p&gt;Our support package for WordPress plugins has a redactor: before a site report leaves the site, it strips things like email addresses, IP addresses, JWTs and long tokens. Its tests need inputs that look like real credentials, or they prove nothing.&lt;/p&gt;

&lt;p&gt;That is a problem. Secret scanners flag anything shaped like a Stripe, GitHub, AWS, Slack or Google key, a JWT or a PEM private key block, even when it is obviously fake. A fake key committed to a public repository still sets off alerts, and teaches everyone to ignore them.&lt;/p&gt;

&lt;p&gt;So the rule in our &lt;code&gt;tests/README.md&lt;/code&gt; is: never commit key-shaped literals, in source, docs or fixtures. Build them at runtime, so no contiguous key-shaped string exists in the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Joined at runtime: the file never holds the full key shape.&lt;/span&gt;
&lt;span class="nv"&gt;$fake_stripe_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;implode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'_'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'sk'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'live'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;str_repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'x'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;assertStringNotContainsString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nv"&gt;$fake_stripe_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Redactor&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;redact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"key=$fake_stripe_key"&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The redactor still sees the real shape. The scanner sees three harmless strings.&lt;/p&gt;

&lt;p&gt;(The snippet shows the idea; adapt the class and method names to your own redactor.)&lt;/p&gt;

&lt;p&gt;Two habits that go with it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write the rule down where contributors look first, next to the tests.&lt;/li&gt;
&lt;li&gt;Don't silence the scanner for the test folder. Then a real key pasted into a fixture by mistake still gets caught.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Guide: &lt;a href="https://mammothwp.com/guides/wordpress-plugin-support-screen-mammothwp-support/" rel="noopener noreferrer"&gt;https://mammothwp.com/guides/wordpress-plugin-support-screen-mammothwp-support/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>testing</category>
      <category>security</category>
    </item>
    <item>
      <title>Test only the pages your WordPress plugin owns, with a JSON list</title>
      <dc:creator>Mammoth WP</dc:creator>
      <pubDate>Wed, 25 Nov 2026 19:07:24 +0000</pubDate>
      <link>https://dev.to/mammothwp/test-only-the-pages-your-wordpress-plugin-owns-with-a-json-list-42o1</link>
      <guid>https://dev.to/mammothwp/test-only-the-pages-your-wordpress-plugin-owns-with-a-json-list-42o1</guid>
      <description>&lt;p&gt;Crawling every wp-admin menu page is a good smoke test. On a WooCommerce site it also means your plugin's test can fail on screens it doesn't own.&lt;/p&gt;

&lt;p&gt;wp-self-test has a second browser mode for that: &lt;code&gt;mmwp-e2e pages&lt;/code&gt;. You describe the pages you care about in &lt;code&gt;browser-pages.json&lt;/code&gt;, admin and frontend, and it checks only those.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"pages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"area"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Settings"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/wp-admin/admin.php?page=my-plugin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"as"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"expect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"#my-plugin-form"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"area"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Product"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/wp-admin/post.php?post=${PRODUCT_ID}&amp;amp;action=edit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"as"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"admin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"expect_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"action=edit"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"area"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"frontend"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Shop"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/shop/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"as"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"guest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"expect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;".products"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"area"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"frontend"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Old URL"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/old/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"as"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"guest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"expect_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"/new/"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What the keys do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;path&lt;/code&gt; and &lt;code&gt;as&lt;/code&gt; are required. &lt;code&gt;as: "admin"&lt;/code&gt; reuses the logged-in session; &lt;code&gt;as: "guest"&lt;/code&gt; has no cookies.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;${PRODUCT_ID}&lt;/code&gt; comes from a &lt;code&gt;--vars&lt;/code&gt; JSON file. An unknown variable fails that page with a clear message, instead of loading the wrong URL.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;expect&lt;/code&gt; is a CSS selector that must exist, &lt;code&gt;expect_url&lt;/code&gt; a substring the final URL must contain after redirects, &lt;code&gt;expect_text&lt;/code&gt; text that must be visible on the page.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;status&lt;/code&gt; is the expected HTTP status, 200 by default. A page you removed on purpose can expect 410 and still pass.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every page gets a fresh browser context, so a cart or session from one page never leaks into the next. Each page also gets the same checks as the full crawl: PHP fatals, warnings and notices in the markup, critical-error pages, console errors, responses of 500 or more, and REST or admin-ajax responses of 400 or more.&lt;/p&gt;

&lt;p&gt;Run it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;MMWP_E2E_ALLOW_PASSWORD_LOGIN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 \
npx mmwp-e2e pages --url=&lt;span class="s2"&gt;"$WP_SITE_URL"&lt;/span&gt; --file=browser-pages.json --vars=vars.json \
    --user=admin --password=&lt;span class="s2"&gt;"$WP_ADMIN_PASSWORD"&lt;/span&gt; --json=mmwp-e2e-results.json --junit=junit-browser.xml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It exits 1 when any page fails, and the JUnit file drops straight into a CI test report. A missing or invalid &lt;code&gt;path&lt;/code&gt; or &lt;code&gt;as&lt;/code&gt; stops the run before a browser starts.&lt;/p&gt;

&lt;p&gt;Guide: &lt;a href="https://mammothwp.com/guides/wordpress-plugin-self-test-wp-self-test/" rel="noopener noreferrer"&gt;https://mammothwp.com/guides/wordpress-plugin-self-test-wp-self-test/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>testing</category>
      <category>e2e</category>
    </item>
    <item>
      <title>One missing slash in .distignore can strip files from your plugin's dependencies</title>
      <dc:creator>Mammoth WP</dc:creator>
      <pubDate>Sun, 22 Nov 2026 10:06:07 +0000</pubDate>
      <link>https://dev.to/mammothwp/one-missing-slash-in-distignore-can-strip-files-from-your-plugins-dependencies-d0e</link>
      <guid>https://dev.to/mammothwp/one-missing-slash-in-distignore-can-strip-files-from-your-plugins-dependencies-d0e</guid>
      <description>&lt;p&gt;If you build your WordPress plugin zip with rsync and a &lt;code&gt;.distignore&lt;/code&gt; file, this line looks harmless:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;rsync treats an exclude pattern without a leading slash as "match this name at any depth". So &lt;code&gt;tests&lt;/code&gt; removes your own &lt;code&gt;/tests&lt;/code&gt; folder and also every &lt;code&gt;tests&lt;/code&gt; folder inside &lt;code&gt;vendor/&lt;/code&gt;. The same goes for &lt;code&gt;docs&lt;/code&gt;, &lt;code&gt;bin&lt;/code&gt;, &lt;code&gt;README.md&lt;/code&gt; and &lt;code&gt;composer.lock&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The worst case is a bare &lt;code&gt;vendor&lt;/code&gt; line. Your runtime Composer packages disappear from the zip, and Plugin Check does not notice.&lt;/p&gt;

&lt;p&gt;The fix is one character per line. Anchor each entry to the plugin root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/tests
/docs
/node_modules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now each pattern matches only the folder at the top of your plugin.&lt;/p&gt;

&lt;p&gt;We added a check for this to wp-release, our open-source release tool. &lt;code&gt;mmwp-release build&lt;/code&gt; warns about unanchored &lt;code&gt;tests&lt;/code&gt;, &lt;code&gt;docs&lt;/code&gt;, &lt;code&gt;bin&lt;/code&gt;, &lt;code&gt;README.md&lt;/code&gt;, &lt;code&gt;composer.lock&lt;/code&gt; or &lt;code&gt;vendor&lt;/code&gt; entries, and fails the build when you run it with &lt;code&gt;--strict&lt;/code&gt;. It also fails when your plugin requires runtime packages and their &lt;code&gt;vendor/&lt;/code&gt; directories are missing from the zip.&lt;/p&gt;

&lt;p&gt;Full guide: &lt;a href="https://mammothwp.com/guides/build-check-deploy-wordpress-plugin-wp-release/" rel="noopener noreferrer"&gt;https://mammothwp.com/guides/build-check-deploy-wordpress-plugin-wp-release/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance and reviewed by the MammothWP team.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>devops</category>
      <category>plugins</category>
    </item>
    <item>
      <title>The Secrets API is out of WordPress 7.2. What that means for your plugin</title>
      <dc:creator>Mammoth WP</dc:creator>
      <pubDate>Thu, 19 Nov 2026 09:54:46 +0000</pubDate>
      <link>https://dev.to/mammothwp/the-secrets-api-is-out-of-wordpress-72-what-that-means-for-your-plugin-25h4</link>
      <guid>https://dev.to/mammothwp/the-secrets-api-is-out-of-wordpress-72-what-that-means-for-your-plugin-25h4</guid>
      <description>&lt;p&gt;The Secrets API was announced for WordPress 7.2 with a dev note on 11 November. Before RC1, core reverted it in changeset 65538.&lt;/p&gt;

&lt;p&gt;The commit message gives two reasons. Feedback on the dev note questioned whether writing secrets belongs in the same API as reading secrets a host provides. A review also found that the new &lt;code&gt;manage_secrets&lt;/code&gt; and &lt;code&gt;manage_network_secrets&lt;/code&gt; capabilities were not checked when a secret was set. Rather than rework it late in the cycle, it was pulled so the design can be revisited. No later release has been named yet.&lt;/p&gt;

&lt;p&gt;If you maintain a plugin that stores API keys:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep your current storage for 7.2. Don't migrate keys to an API that won't ship.&lt;/li&gt;
&lt;li&gt;If you already wrote code for &lt;code&gt;wp_get_secret()&lt;/code&gt;, make sure nothing calls it on a site where it doesn't exist.&lt;/li&gt;
&lt;li&gt;Test against 7.2 RC1, not an earlier beta that still had the API.&lt;/li&gt;
&lt;li&gt;Watch the core channels for the redesign. The read side and the write side may come back as different things.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We posted a Secrets API tip on 17 November. This is our correction.&lt;/p&gt;

&lt;p&gt;Changeset: &lt;a href="https://core.trac.wordpress.org/changeset/65538" rel="noopener noreferrer"&gt;https://core.trac.wordpress.org/changeset/65538&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance and reviewed by the MammothWP team.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>security</category>
      <category>plugins</category>
    </item>
    <item>
      <title>Moving an API key from wp_options to the WordPress 7.2 Secrets API</title>
      <dc:creator>Mammoth WP</dc:creator>
      <pubDate>Sun, 15 Nov 2026 20:28:27 +0000</pubDate>
      <link>https://dev.to/mammothwp/moving-an-api-key-from-wpoptions-to-the-wordpress-72-secrets-api-44ad</link>
      <guid>https://dev.to/mammothwp/moving-an-api-key-from-wpoptions-to-the-wordpress-72-secrets-api-44ad</guid>
      <description>&lt;p&gt;WordPress 7.2 (final release scheduled for 8 December) adds a Secrets API. Credentials such as API keys are stored encrypted, with one previous version kept for rotation. The Make Core dev note is the reference; these are the points that matter when you move an existing key out of a plain option.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Check availability first.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nf"&gt;wp_is_secrets_api_available&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Keep the existing storage.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It returns false when the &lt;code&gt;secrets.php&lt;/code&gt; drop-in failed to load, when &lt;code&gt;WP_SECRETS_KEY&lt;/code&gt; is missing or unusable, or when the key can't decrypt the root key already stored.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Respect host-managed secrets.&lt;/strong&gt; On a read-only provider, &lt;code&gt;wp_secrets_provider_is_writable()&lt;/code&gt; returns false and &lt;code&gt;wp_set_secret()&lt;/code&gt; returns a &lt;code&gt;WP_Error&lt;/code&gt;. Show a notice instead of an input field, and don't fall back to an option.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Import, then clean up.&lt;/strong&gt; &lt;code&gt;wp_import_option_as_secret()&lt;/code&gt; copies the option into a secret. It leaves the option for you to delete and flags the secret for rotation, because the old value has already been through your backups.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Name it &lt;code&gt;plugin-slug/secret-name&lt;/code&gt;.&lt;/strong&gt; Lowercase letters, digits, hyphens and underscores, one slash. The prefix stops plugins from overwriting each other's secrets. It is not access control: any code on the site can read any secret.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Keep null and WP_Error apart.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$secret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_get_secret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'my-plugin/api-key'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$secret&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;WP_Secret&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;authenticate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$secret&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;reveal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;elseif&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$secret&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Never stored: ask the admin for it.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// WP_Error: stored but unreadable right now. Don't ask for a new one.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Call &lt;code&gt;reveal()&lt;/code&gt; where you use the value.&lt;/strong&gt; A &lt;code&gt;WP_Secret&lt;/code&gt; prints as a placeholder when logged or JSON-encoded, and serializing or cloning it throws. Don't cache the object.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Check capabilities yourself.&lt;/strong&gt; The functions don't, because they have to work from cron and REST. Check wherever a user enters or manages a value.&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://make.wordpress.org/core/2026/11/11/the-secrets-api-in-wordpress-7-2/" rel="noopener noreferrer"&gt;The Secrets API in WordPress 7.2&lt;/a&gt;, Make WordPress Core, 11 Nov 2026 (updated 13 Nov).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance and reviewed by the MammothWP team.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>security</category>
      <category>plugins</category>
    </item>
    <item>
      <title>Strict Plugin Check with a narrow allow-list</title>
      <dc:creator>Mammoth WP</dc:creator>
      <pubDate>Fri, 13 Nov 2026 08:29:01 +0000</pubDate>
      <link>https://dev.to/mammothwp/strict-plugin-check-with-a-narrow-allow-list-3327</link>
      <guid>https://dev.to/mammothwp/strict-plugin-check-with-a-narrow-allow-list-3327</guid>
      <description>&lt;p&gt;Running Plugin Check in strict mode (fail on any WARNING, not just ERRORs) is a good release gate. The catch: sometimes a warning is known and accepted, and you still want strict mode for everything else.&lt;/p&gt;

&lt;p&gt;Our release tool, wp-release, handles that with an allow-list. The rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only WARNINGs can be allowed. ERRORs can never be allowed.&lt;/li&gt;
&lt;li&gt;Each rule is a bare PCRE body, matched (with the u flag) against the string "&amp;lt;code&amp;gt;: &amp;lt;message&amp;gt;". An invalid regex stops the run with exit code 2.&lt;/li&gt;
&lt;li&gt;Nothing is allowed by default. Rules come from --allow (repeatable), the MMWP_PCP_ALLOW environment variable, or "allow" in mmwp-release.json, and they are merged.&lt;/li&gt;
&lt;li&gt;Allowed findings stay visible. They are listed as "ALLOWED: &amp;lt;code&amp;gt;: &amp;lt;message&amp;gt; (rule: &amp;lt;regex&amp;gt;)", the summary reads "N error(s), M warning(s), K allowed", and plugin-check.json records them. They just don't count toward the strict failure or the deploy gate.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our own case: Plugin Check flags the "wp" in "MammothWP" as trademarked_term. The rule we use matches only that code, and only when the quoted name contains mammothwp, so the same warning about any other name still fails the build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mmwp-release check --strict --allow=&lt;span class="s1"&gt;'(?i)^trademarked_term: (?=.*(?&amp;lt;![a-z0-9])mammothwp)(?=.*restricted term \W?wp\W)'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The lesson that carries over to any CI setup: when you silence a check, scope the exception to the exact finding, keep it in the report, and never let it cover the severe level.&lt;/p&gt;

&lt;p&gt;wp-release is GPLv2 or later. Build, check and deploy guide: &lt;a href="https://mammothwp.com/guides/build-check-deploy-wordpress-plugin-wp-release/" rel="noopener noreferrer"&gt;https://mammothwp.com/guides/build-check-deploy-wordpress-plugin-wp-release/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance and reviewed by the MammothWP team.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>ci</category>
      <category>plugins</category>
    </item>
    <item>
      <title>Declare a WordPress feature once: REST route, WP-CLI command and Ability with wp-kit</title>
      <dc:creator>Mammoth WP</dc:creator>
      <pubDate>Thu, 12 Nov 2026 13:00:06 +0000</pubDate>
      <link>https://dev.to/mammothwp/declare-a-wordpress-feature-once-rest-route-wp-cli-command-and-ability-with-wp-kit-1p1a</link>
      <guid>https://dev.to/mammothwp/declare-a-wordpress-feature-once-rest-route-wp-cli-command-and-ability-with-wp-kit-1p1a</guid>
      <description>&lt;p&gt;This is a cross-post of our guide on &lt;a href="https://mammothwp.com/guides/declare-once-rest-wp-cli-ability-wp-kit/" rel="noopener noreferrer"&gt;mammothwp.com&lt;/a&gt;. The code and behaviour below are taken from that page.&lt;/p&gt;

&lt;p&gt;A plugin feature often needs more than one entry point. The admin screen calls a REST route, deploy scripts call a WP-CLI command, and with the Abilities API the same feature can also be registered as an Ability. Written by hand, each copy gets its own parameter list, permission check and validation, and over time they stop matching.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://packagist.org/packages/mammothwp/wp-kit" rel="noopener noreferrer"&gt;mammothwp/wp-kit&lt;/a&gt; takes a different approach. You declare the operation once, with its fields, capability and output, and three adapters register it on REST, WP-CLI and the Abilities API from that single definition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require mammothwp/wp-kit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;wp-kit is a runtime dependency, because the adapters register routes, commands and abilities inside WordPress, so ship &lt;code&gt;vendor/&lt;/code&gt; with your plugin. It requires PHP 7.4 or newer. Composer's &lt;code&gt;autoload.files&lt;/code&gt; loads &lt;code&gt;bootstrap.php&lt;/code&gt;. Several active plugins can each include their own copy, and the newest copy boots on &lt;code&gt;plugins_loaded&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short example
&lt;/h2&gt;

&lt;p&gt;The service is plain PHP. wp-kit calls its methods and passes declared fields to parameters with the same name.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Things_Service&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nv"&gt;$instance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$instance&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nv"&gt;$instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;list_items&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_posts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'numberposts'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$limit&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'items'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;array_map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="no"&gt;ID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'title'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;post_title&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'status'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$post&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;post_status&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$posts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resource is the one definition. Put it in its own file, &lt;code&gt;includes/Things_Resource.php&lt;/code&gt;, and load it with a Composer classmap in your plugin's &lt;code&gt;composer.json&lt;/code&gt;, then run &lt;code&gt;composer dump-autoload&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"autoload"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"classmap"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"includes/"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The kit's classes exist only after &lt;code&gt;plugins_loaded&lt;/code&gt;, so a class that extends &lt;code&gt;Resource&lt;/code&gt; cannot be declared while your main plugin file loads. The classmap loads it on first use, inside &lt;code&gt;Kit::on_ready()&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;MammothWP&lt;/span&gt;\&lt;span class="nc"&gt;WpKit&lt;/span&gt;\&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Operation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Resource&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;final&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Things_Resource&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Resource&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;             &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'things'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;service&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Things_Service&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;rest_namespace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;   &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'my-plugin/v1'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;cli_base&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;         &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'my-plugin things'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ability_category&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'my-plugin-things'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ability_category_args&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'label'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Things'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'description'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Abilities for things.'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;operations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'list'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Operation&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'list_items'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'List things'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;description&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'List things.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
                    &lt;span class="nc"&gt;Field&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'limit'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;default_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Rows to return.'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;rest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'GET'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;cli&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'list'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'columns'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'status'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;ability&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'list-things'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Register the adapters inside &lt;code&gt;Kit::on_ready()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;\&lt;span class="nc"&gt;MammothWP&lt;/span&gt;\&lt;span class="nc"&gt;WpKit&lt;/span&gt;\&lt;span class="nc"&gt;Kit&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;on_ready&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$registry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; \&lt;span class="nc"&gt;MammothWP&lt;/span&gt;\&lt;span class="nc"&gt;WpKit&lt;/span&gt;\&lt;span class="nc"&gt;Registry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Things_Resource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$registry&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$resource&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; \&lt;span class="nc"&gt;MammothWP&lt;/span&gt;\&lt;span class="nc"&gt;WpKit&lt;/span&gt;\&lt;span class="nc"&gt;Adapters&lt;/span&gt;\&lt;span class="nc"&gt;Rest_Adapter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$resource&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; \&lt;span class="nc"&gt;MammothWP&lt;/span&gt;\&lt;span class="nc"&gt;WpKit&lt;/span&gt;\&lt;span class="nc"&gt;Adapters&lt;/span&gt;\&lt;span class="nc"&gt;Cli_Adapter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$resource&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; \&lt;span class="nc"&gt;MammothWP&lt;/span&gt;\&lt;span class="nc"&gt;WpKit&lt;/span&gt;\&lt;span class="nc"&gt;Adapters&lt;/span&gt;\&lt;span class="nc"&gt;Ability_Adapter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$resource&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WordPress requires a description on every ability and on its category, which is why the example sets both.&lt;/p&gt;

&lt;p&gt;From that one declaration, the &lt;code&gt;limit&lt;/code&gt; field becomes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a REST argument of type integer with &lt;code&gt;default&lt;/code&gt; 50 and &lt;code&gt;maximum&lt;/code&gt; 200,&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;[--limit=&amp;lt;limit&amp;gt;]&lt;/code&gt; flag in the WP-CLI synopsis and in &lt;code&gt;wp help&lt;/code&gt;,&lt;/li&gt;
&lt;li&gt;the same constraints in the Ability input schema.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Ability adapter only registers when the Abilities API is available, and the CLI adapter only when WP-CLI is loaded. The capability defaults to &lt;code&gt;manage_options&lt;/code&gt;. Override &lt;code&gt;capability()&lt;/code&gt; on the resource, or call &lt;code&gt;-&amp;gt;capability()&lt;/code&gt; on one operation.&lt;/p&gt;

&lt;h2&gt;
  
  
  One execution path
&lt;/h2&gt;

&lt;p&gt;Every surface calls &lt;code&gt;Operation::run()&lt;/code&gt;, which:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;normalises the input against the fields and applies defaults,&lt;/li&gt;
&lt;li&gt;validates it (&lt;code&gt;mmwp_invalid_param&lt;/code&gt;, 400),&lt;/li&gt;
&lt;li&gt;checks the capability (&lt;code&gt;mmwp_forbidden&lt;/code&gt;, 403),&lt;/li&gt;
&lt;li&gt;asks for confirmation on destructive calls where required,&lt;/li&gt;
&lt;li&gt;calls your service method.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Operations come in three kinds: &lt;code&gt;Operation::read()&lt;/code&gt;, &lt;code&gt;Operation::write()&lt;/code&gt; and &lt;code&gt;Operation::destructive()&lt;/code&gt;. By default, a destructive operation needs &lt;code&gt;confirm: true&lt;/code&gt; when it is called as an Ability.&lt;/p&gt;

&lt;p&gt;Every ability the kit registers is marked &lt;code&gt;meta.mcp.public = true&lt;/code&gt;, so an MCP server built on &lt;code&gt;wordpress/mcp-adapter&lt;/code&gt; can list it as a tool, and the call still goes through the same checks. To keep a resource off MCP, return &lt;code&gt;false&lt;/code&gt; from &lt;code&gt;mcp()&lt;/code&gt; on the resource.&lt;/p&gt;

&lt;p&gt;If an operation should not exist on one surface, say so with &lt;code&gt;Operation::surfaces()&lt;/code&gt; or by overriding &lt;code&gt;Resource::surfaces()&lt;/code&gt;, and give a reason. &lt;code&gt;Inventory::export()&lt;/code&gt; carries that reason, so a test can tell a deliberate omission from a missing registration.&lt;/p&gt;

&lt;h2&gt;
  
  
  In a real plugin
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://wordpress.org/plugins/mammoth-acceptance-logs/" rel="noopener noreferrer"&gt;MammothWP Acceptance Logs&lt;/a&gt; on wordpress.org ships wp-kit in its &lt;code&gt;vendor/&lt;/code&gt; directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Your plugin exposes the same feature over REST and WP-CLI, or you plan to add Abilities.&lt;/li&gt;
&lt;li&gt;You want parameters, permission checks and validation defined in one place.&lt;/li&gt;
&lt;li&gt;You want a test to check that every operation is registered on each surface it should be.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  When not to
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The feature only needs a single REST route or a single command, and you have no plans for other surfaces.&lt;/li&gt;
&lt;li&gt;Your route or command needs request handling that does not fit an operation with declared fields.&lt;/li&gt;
&lt;li&gt;You cannot ship Composer dependencies inside your plugin.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Guide: &lt;a href="https://mammothwp.com/guides/declare-once-rest-wp-cli-ability-wp-kit/" rel="noopener noreferrer"&gt;https://mammothwp.com/guides/declare-once-rest-wp-cli-ability-wp-kit/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Packagist: &lt;a href="https://packagist.org/packages/mammothwp/wp-kit" rel="noopener noreferrer"&gt;https://packagist.org/packages/mammothwp/wp-kit&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;License: GPLv2 or later&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Questions or corrections are welcome in the comments. We make wp-kit at Mammoth WP.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Drafted with AI assistance and reviewed by the MammothWP team.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>wpcli</category>
      <category>composer</category>
    </item>
  </channel>
</rss>
