<?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: Md. Zubaer Ahammed</title>
    <description>The latest articles on DEV Community by Md. Zubaer Ahammed (@zubaer).</description>
    <link>https://dev.to/zubaer</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%2F1695453%2Ffcd61f41-28c5-4b93-82a9-e08a4bd71947.png</url>
      <title>DEV Community: Md. Zubaer Ahammed</title>
      <link>https://dev.to/zubaer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zubaer"/>
    <language>en</language>
    <item>
      <title>Fix WordPress 403 Forbidden Error: An Audit Checklist</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Tue, 01 Dec 2026 16:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/fix-wordpress-403-forbidden-error-an-audit-checklist-525f</link>
      <guid>https://dev.to/zubaer/fix-wordpress-403-forbidden-error-an-audit-checklist-525f</guid>
      <description>&lt;p&gt;A WordPress 403 Forbidden error means the server received the request, understood it, and refused to serve it. Nothing crashed, which is what separates it from a 500 error: something between the visitor and WordPress decided the answer is no. To fix a 403 Forbidden error in WordPress, first find out which layer said no (the CDN or firewall in front of the site, the web server, or WordPress itself), because each one is fixed in a different place.&lt;/p&gt;

&lt;p&gt;Every output in this checklist comes from a disposable test server running WordPress 7.1.3 on PHP 8.2 with Apache 2.4.69, where each cause was triggered on purpose and the real response and log line recorded. You need SSH or SFTP access to the site, and for the last step, access to the server's error log.&lt;/p&gt;

&lt;p&gt;From experience · Md. Zubaer Ahammed&lt;/p&gt;

&lt;p&gt;I have run into 403 Forbidden errors many times, both on my own websites and for clients who hired me to fix them. Most of the time the cause was either file permissions or the &lt;code&gt;.htaccess&lt;/code&gt; file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Find out which layer sent the 403
&lt;/h2&gt;

&lt;p&gt;Ask for the response headers only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sI https://example.com/wp-admin/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;Server&lt;/code&gt; header and the page body tell you who answered. A 403 from Apache looks like this, and its page says nothing more than "You don't have permission to access this resource":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/1.1 403 Forbidden
Server: Apache/2.4.69 (Debian)
Content-Type: text/html; charset=iso-8859-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A 403 from Cloudflare says &lt;code&gt;server: cloudflare&lt;/code&gt;, and when a firewall rule issued a challenge it also carries a &lt;code&gt;cf-mitigated&lt;/code&gt; header. This is a real response from the login protection rule on wptutshub.com itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP/2 403
content-type: text/html; charset=UTF-8
cf-mitigated: challenge
server: cloudflare
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use what you see to decide where to start:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;server: cloudflare&lt;/code&gt;&lt;/strong&gt; (or another CDN's name): the request never reached your server. Go to step 4.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An Apache or nginx &lt;code&gt;Server&lt;/code&gt; header with the plain "Forbidden" page&lt;/strong&gt;: the web server refused it. Work through steps 2, 3 and 5.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A page branded by a security plugin, or a JSON body&lt;/strong&gt; such as &lt;code&gt;{"code":"rest_forbidden",...}&lt;/code&gt;: WordPress or a plugin refused it. Go to step 4 and the section on WordPress's own 403s.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 2: Check file and folder permissions
&lt;/h2&gt;

&lt;p&gt;The web server user (&lt;code&gt;www-data&lt;/code&gt; on Debian and Ubuntu, &lt;code&gt;apache&lt;/code&gt; on RHEL-based systems, or your own account on most shared hosting) must be able to read every file it serves and enter every folder on the way to it. The WordPress standard is 755 for folders and 644 for files. Most 403s after a migration, a restore from backup or an FTP upload come from files and folders that lost those modes.&lt;/p&gt;

&lt;p&gt;When a file cannot be read, Apache answers 403 and logs exactly why:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -sI https://example.com/readme.html
HTTP/1.1 403 Forbidden
Server: Apache/2.4.69 (Debian)

[core:error] (13)Permission denied: [client 203.0.113.10:51234] AH00132: file permissions deny server access: /var/www/html/readme.html
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A folder without the execute (&lt;code&gt;x&lt;/code&gt;) bit is worse: it breaks every file inside it, even files that are readable themselves. Apache cannot even look for an &lt;code&gt;.htaccess&lt;/code&gt; file in that folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -sI https://example.com/wp-includes/css/dashicons.min.css
HTTP/1.1 403 Forbidden
Server: Apache/2.4.69 (Debian)

[core:crit] (13)Permission denied: [client 203.0.113.10:51234] AH00529: /var/www/html/wp-includes/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable and that '/var/www/html/wp-includes/' is executable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before changing anything, list what is wrong. Run these from the WordPress root:&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="c"&gt;# Folders that are not 755, and files that are not 644&lt;/span&gt;
find . -type d ! -perm 755 -print
find . -type f ! -perm 644 -print
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the test site, with a theme folder and a core file broken on purpose, the audit printed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ find . -type d ! -perm 755 -print
./wp-content/themes
./wp-content/cache
$ find . -type f ! -perm 644 -print
./wp-includes/version.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fix everything in one pass, then run the audit again. Both lists should come back empty:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find . -type d -exec chmod 755 &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt; +
find . -type f -exec chmod 644 &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt; +
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two cautions. Some hosts deliberately set &lt;code&gt;wp-config.php&lt;/code&gt; to 640 or 600 so other accounts on the server cannot read your database password. If yours was like that, set it back after the bulk fix. And modes are only half the check: if the files belong to the wrong user after a migration, 644 does not help when the web server is neither the owner nor in the group. &lt;code&gt;ls -l&lt;/code&gt; shows the owner. On a VPS, &lt;code&gt;sudo chown -R www-data:www-data /var/www/html&lt;/code&gt; fixes it; on shared hosting, the host's file manager or support does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Audit the .htaccess file
&lt;/h2&gt;

&lt;p&gt;On Apache, &lt;code&gt;.htaccess&lt;/code&gt; rules apply to every request in that folder and below, and several common rules answer with 403. Rename the file to see whether it is involved:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mv .htaccess .htaccess.bak
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the test site, a single &lt;code&gt;Require all denied&lt;/code&gt; line blocked the whole site, and renaming the file brought it back at once:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -sI https://example.com/
HTTP/1.1 403 Forbidden

[authz_core:error] [client 203.0.113.10:51234] AH01630: client denied by server configuration: /var/www/html/

# after renaming .htaccess
HTTP/1.1 200 OK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;AH01630&lt;/code&gt; is the line to look for whenever an access rule is the cause: &lt;code&gt;Require all denied&lt;/code&gt;, a &lt;code&gt;Require ip&lt;/code&gt; list that leaves your own address out, old &lt;code&gt;Order&lt;/code&gt; / &lt;code&gt;Deny from&lt;/code&gt; rules copied from Apache 2.2 tutorials, and the hotlink protection or "block bad bots" snippets some security plugins write into this file.&lt;/p&gt;

&lt;p&gt;If renaming fixed it, start again from the standard WordPress block and add your other rules back one at a time until the 403 returns. That last rule is the culprit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# BEGIN WordPress
&amp;lt;IfModule mod_rewrite.c&amp;gt;
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&amp;lt;/IfModule&amp;gt;
# END WordPress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One rule deserves a special mention. Pretty permalinks depend on &lt;code&gt;mod_rewrite&lt;/code&gt;, and Apache refuses rewrites in a folder where symbolic links are switched off. A line such as &lt;code&gt;Options -FollowSymLinks&lt;/code&gt;, often copied from hardening guides, makes every permalink return 403 while the home page and static files keep working:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -sI https://example.com/sample-page/
HTTP/1.1 403 Forbidden

[rewrite:error] [client 203.0.113.10:51234] AH00670: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions : /var/www/html/sample-page
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want symbolic links restricted, use &lt;code&gt;Options +SymLinksIfOwnerMatch&lt;/code&gt; instead of switching both off.&lt;/p&gt;

&lt;p&gt;A broken &lt;code&gt;.htaccess&lt;/code&gt; usually looks different. A typo or an unknown directive gives a 500 Internal Server Error, not a 403, and the error log says "Invalid command". If you are seeing 500s, that is the line to search for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Rule out the security plugin, the host firewall and the CDN
&lt;/h2&gt;

&lt;p&gt;Security layers return 403 by design, so a false positive looks exactly like a configuration error until you check who answered.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Security plugins.&lt;/strong&gt; Wordfence and similar plugins show their own branded block page, which usually says what was blocked. If you can still log in, the plugin's live traffic or firewall log names the rule, and you can allowlist that action. If you cannot reach wp-admin, rename the plugin's folder over SFTP (for example &lt;code&gt;wp-content/plugins/wordfence&lt;/code&gt; to &lt;code&gt;wordfence.off&lt;/code&gt;), fix the setting, then rename it back.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The host's firewall.&lt;/strong&gt; Many hosts run ModSecurity, which returns its own 403 page with no WordPress involvement. It usually fires on specific requests: saving a post that contains code, uploading a file, or submitting a form with certain words. Your host can look up the rule ID in its logs and exclude that one rule for your site.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloudflare or another CDN.&lt;/strong&gt; If the response says &lt;code&gt;server: cloudflare&lt;/code&gt;, open Security → Events in the Cloudflare dashboard, find the blocked request and see which rule matched. Custom rules, IP access rules and Bot Fight Mode are the usual causes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To check whether the block is tied to your own IP address, load the site over mobile data instead of your usual connection. If it works there, the site is fine and your address is what is being blocked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Check the Apache configuration and the error log
&lt;/h2&gt;

&lt;p&gt;If nothing so far explains it, look at the server configuration itself. On a VPS, the virtual host for a WordPress site should contain a block like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Directory /var/www/html/&amp;gt;
    Options -Indexes +FollowSymLinks
    AllowOverride All
    Require all granted
&amp;lt;/Directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Require all granted&lt;/code&gt; is the line that allows access at all. A &lt;code&gt;&amp;lt;Directory&amp;gt;&lt;/code&gt; block with &lt;code&gt;Require all denied&lt;/code&gt; refuses everything below it, with the same &lt;code&gt;AH01630&lt;/code&gt; line as in step 3. &lt;code&gt;-Indexes&lt;/code&gt; keeps directory listings off, which is right for security, but it also means a folder with no index file returns 403. That one is harmless and often mistaken for a fault:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ curl -sI https://example.com/wp-content/uploads/2026/
HTTP/1.1 403 Forbidden

[autoindex:error] [client 203.0.113.10:51234] AH01276: Cannot serve directory /var/www/html/wp-content/uploads/2026/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;AllowOverride&lt;/code&gt; decides whether &lt;code&gt;.htaccess&lt;/code&gt; is read at all. With &lt;code&gt;AllowOverride None&lt;/code&gt;, Apache ignores the file, so pretty permalinks return 404 rather than 403, and none of the rules you checked in step 3 ever ran.&lt;/p&gt;

&lt;p&gt;Keep the error log open while you reload the failing URL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo tail -f /var/log/apache2/error.log   &lt;span class="c"&gt;# Debian and Ubuntu&lt;/span&gt;
sudo tail -f /var/log/httpd/error_log     &lt;span class="c"&gt;# RHEL, AlmaLinux, Rocky&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;AH&lt;/code&gt; code on the new line tells you which check applies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AH00132 or AH00529&lt;/strong&gt;: permissions (step 2).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AH01630&lt;/strong&gt;: an access rule in &lt;code&gt;.htaccess&lt;/code&gt; or the virtual host (steps 3 and 5).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AH00670&lt;/strong&gt;: symbolic links switched off while rewrites are on (step 3).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;AH01276&lt;/strong&gt;: a folder with no index file (harmless).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nothing logged&lt;/strong&gt;: the 403 came from a plugin, the host's firewall or the CDN (step 4).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On nginx there is no &lt;code&gt;.htaccess&lt;/code&gt;; the same rules live in the server block. Its error log, usually &lt;code&gt;/var/log/nginx/error.log&lt;/code&gt;, says "Permission denied" for permission problems and "directory index of … is forbidden" for folders without an index file.&lt;/p&gt;

&lt;h2&gt;
  
  
  When WordPress itself returns the 403
&lt;/h2&gt;

&lt;p&gt;Not every 403 comes from the server. WordPress returns 403 when a logged-in user lacks the capability for an action, and the REST API returns it with a JSON body when a request fails its checks, for example &lt;code&gt;{"code":"rest_cookie_invalid_nonce","message":"Cookie check failed","data":{"status":403}}&lt;/code&gt; when a nonce has expired. Permissions and &lt;code&gt;.htaccess&lt;/code&gt; have nothing to do with these. If one of your own endpoints is refusing requests, &lt;a href="https://wptutshub.com/secure-custom-rest-api-endpoints-nonces-capability-checks/" rel="noopener noreferrer"&gt;securing custom REST API endpoints with nonces and capability checks&lt;/a&gt; shows what WordPress expects. If a security plugin turned out to be the cause, the guide to the &lt;a href="https://wptutshub.com/best-wordpress-security-plugins/" rel="noopener noreferrer"&gt;best WordPress security plugins&lt;/a&gt; covers which ones are worth keeping.&lt;/p&gt;

&lt;p&gt;My tip · Md. Zubaer Ahammed&lt;/p&gt;

&lt;p&gt;Always make sure your file permissions are correct and that &lt;code&gt;.htaccess&lt;/code&gt; has no unwanted rules that could block access. Those two checks solve most 403 errors before you need to look anywhere else.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist in short
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Run &lt;code&gt;curl -sI&lt;/code&gt; and read the &lt;code&gt;Server&lt;/code&gt; header to see which layer refused.&lt;/li&gt;
&lt;li&gt;Audit permissions with &lt;code&gt;find&lt;/code&gt;: 755 for folders, 644 for files, and the right owner.&lt;/li&gt;
&lt;li&gt;Rename &lt;code&gt;.htaccess&lt;/code&gt;; if that fixes it, rebuild it from the WordPress block one rule at a time.&lt;/li&gt;
&lt;li&gt;Check the security plugin, the host's firewall and the CDN's event log.&lt;/li&gt;
&lt;li&gt;Read the Apache error log and match the &lt;code&gt;AH&lt;/code&gt; code to the cause.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/fix-wordpress-403-forbidden-error/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Fix 'Updating Failed' Invalid JSON in WordPress</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Sun, 29 Nov 2026 16:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/fix-updating-failed-invalid-json-in-wordpress-6ol</link>
      <guid>https://dev.to/zubaer/fix-updating-failed-invalid-json-in-wordpress-6ol</guid>
      <description>&lt;p&gt;“Updating failed. The response is not a valid JSON response.” means the block editor sent a &lt;code&gt;POST&lt;/code&gt; to &lt;code&gt;/wp-json/wp/v2/posts/&amp;lt;id&amp;gt;&lt;/code&gt; and the reply would not parse as JSON. Something answered with HTML, a redirect, a PHP warning printed before the body, or nothing at all. Every fix starts with seeing that raw reply instead of the editor's one-line summary of it.&lt;/p&gt;

&lt;p&gt;You need shell access to the site, permission to write a file into &lt;code&gt;wp-content/mu-plugins/&lt;/code&gt;, and a browser with DevTools. Nothing else.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three ways to see the response the editor is complaining about
&lt;/h2&gt;

&lt;p&gt;Each one answers a different question, and starting with the wrong one is why people end up deactivating plugins at random.&lt;/p&gt;

&lt;h3&gt;
  
  
  DevTools shows what the browser received
&lt;/h3&gt;

&lt;p&gt;Open the editor, press F12, switch to Network, filter by &lt;code&gt;posts&lt;/code&gt;, then make an edit and watch for the red request. The Response tab gives you the status code and the first bytes of the body. It takes ten seconds and needs no server access. What it cannot tell you is why: a fatal error that killed PHP before it wrote anything, and a plugin that printed a warning before the JSON, both look like a short or empty body here.&lt;/p&gt;

&lt;h3&gt;
  
  
  curl separates WordPress from the web server
&lt;/h3&gt;

&lt;p&gt;A terminal request carries no nonce and no cookies, so it cannot reproduce an authenticated save. It can still tell you whether &lt;code&gt;/wp-json/&lt;/code&gt; routes at all, whether the site redirects, and whether the server returns &lt;code&gt;text/html&lt;/code&gt; where JSON is expected. That rules out permalinks, proxies and rewrite rules in one command.&lt;/p&gt;

&lt;h3&gt;
  
  
  A logger on the REST hooks catches the request you cannot reproduce
&lt;/h3&gt;

&lt;p&gt;Hooking &lt;code&gt;rest_post_dispatch&lt;/code&gt; and &lt;code&gt;rest_pre_echo_response&lt;/code&gt; records the real authenticated request, its status, and any bytes printed before the JSON. This is the only one of the three that works when the failure is intermittent, happens only for editors, or comes from a plugin you cannot switch off on a live site.&lt;/p&gt;

&lt;p&gt;Run curl first, because it is one command and eliminates the boring causes. When curl returns clean JSON and the editor still fails, install the logger.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with curl to rule out permalinks and redirects
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Does the REST index answer at all?&lt;/span&gt;
curl -i -s https://example.com/wp-json/ &lt;span class="o"&gt;|&lt;/span&gt; head -n 20

&lt;span class="c"&gt;# 2. The route the editor posts to&lt;/span&gt;
curl -i -s https://example.com/wp-json/wp/v2/posts &lt;span class="o"&gt;|&lt;/span&gt; head -n 20

&lt;span class="c"&gt;# 3. Every hop, if a redirect is in play&lt;/span&gt;
curl -sIL https://example.com/wp-json/wp/v2/posts &lt;span class="o"&gt;|&lt;/span&gt; grep -Ei &lt;span class="s1"&gt;'^(HTTP|location|content-type)'&lt;/span&gt;

&lt;span class="c"&gt;# 4. The same route without rewrite rules&lt;/span&gt;
curl -i -s &lt;span class="s1"&gt;'https://example.com/?rest_route=/wp/v2/posts'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; head -n 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read the status line before anything else. &lt;code&gt;HTTP/2 200&lt;/code&gt; with &lt;code&gt;content-type: application/json; charset=UTF-8&lt;/code&gt; and a body starting with &lt;code&gt;[{"id":&lt;/code&gt; means the route is healthy and the fault is further along. &lt;code&gt;HTTP/2 301&lt;/code&gt; or &lt;code&gt;302&lt;/code&gt; with a &lt;code&gt;location:&lt;/code&gt; header means the editor's POST is being redirected, and the target is an HTML page. &lt;code&gt;HTTP/2 404&lt;/code&gt; with &lt;code&gt;text/html&lt;/code&gt; almost always means the server's rewrite rules are not passing &lt;code&gt;/wp-json/&lt;/code&gt; to WordPress.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;?rest_route=&lt;/code&gt; form is the useful part. It bypasses rewrite rules entirely, so if that URL returns JSON and &lt;code&gt;/wp-json/&lt;/code&gt; returns HTML, the problem is the rewrite setup and nothing else.&lt;/p&gt;

&lt;p&gt;Check the structure with &lt;code&gt;wp option get permalink_structure&lt;/code&gt;. If it prints a pattern such as &lt;code&gt;/%postname%/&lt;/code&gt;, WordPress builds every REST URL as &lt;code&gt;/wp-json/…&lt;/code&gt; and relies on the web server to hand those requests to &lt;code&gt;index.php&lt;/code&gt;. When that hand-off is missing, the editor's save gets the server's own HTML 404 page. On Apache, check that &lt;code&gt;.htaccess&lt;/code&gt; contains the WordPress block and that &lt;code&gt;AllowOverride&lt;/code&gt; is not set to &lt;code&gt;None&lt;/code&gt;; saving Settings → Permalinks once rewrites the file and flushes the rules. On nginx there is no &lt;code&gt;.htaccess&lt;/code&gt;, so the &lt;code&gt;try_files $uri $uri/ /index.php?$args;&lt;/code&gt; line has to cover &lt;code&gt;/wp-json/&lt;/code&gt; like any other permalink.&lt;/p&gt;

&lt;p&gt;If it prints nothing, the site is on Plain permalinks. The editor then sends its requests to &lt;code&gt;?rest_route=&lt;/code&gt; instead of &lt;code&gt;/wp-json/&lt;/code&gt;, so rewrites are not your problem. Switching to Plain is a popular workaround because it sidesteps broken rewrite rules, but it hides the fault rather than fixing it, and it changes every public URL on the site.&lt;/p&gt;

&lt;p&gt;Settings → Permalinks with Post name selected: WordPress now sends REST requests to /wp-json/, which works only if the server's rewrite rules pass them to index.php (test site: WordPress 7.1.3, PHP 8.2)&lt;/p&gt;

&lt;h2&gt;
  
  
  Log the real request with a small mu-plugin
&lt;/h2&gt;

&lt;p&gt;An mu-plugin loads before regular plugins, cannot be deactivated from the admin, and is not touched by updates. Save this as &lt;code&gt;wp-content/mu-plugins/rest-json-logger.php&lt;/code&gt;, creating the directory if it does not exist.&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Plugin Name: REST JSON Response Logger
 * Description: Records the REST response the block editor receives, plus anything printed before it.
 */&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;WPTUTSHUB_REST_LOG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;WP_CONTENT_DIR&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/rest-json.log'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'rest_post_dispatch'&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;$response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$server&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$GLOBALS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'wptutshub_rest_last'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&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;'response'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'request'&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$request&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="nv"&gt;$response&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="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'rest_pre_echo_response'&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;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$server&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$GLOBALS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'wptutshub_rest_last'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="kc"&gt;null&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="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$last&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="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nv"&gt;$request&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$last&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'request'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$last&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'response'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$status&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;WP_REST_Response&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_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="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$method&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_method&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="c1"&gt;// Skip successful reads, or every editor page load fills the file.&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'GET'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$method&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nv"&gt;$status&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;400&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="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nv"&gt;$stray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&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="nf"&gt;ob_get_level&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="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$stray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;ob_get_contents&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;$sent_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&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="nf"&gt;headers_sent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$line&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;$sent_at&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$file&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="nv"&gt;$line&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nv"&gt;$entry&lt;/span&gt; &lt;span class="o"&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;'time'&lt;/span&gt;            &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;gmdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'c'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'method'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'route'&lt;/span&gt;           &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_route&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="s1"&gt;'status'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'user_id'&lt;/span&gt;         &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;get_current_user_id&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="s1"&gt;'stray_bytes'&lt;/span&gt;     &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$stray&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'stray_head'&lt;/span&gt;      &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$stray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'headers_sent_at'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$sent_at&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'body_head'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;wp_json_encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;300&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="nf"&gt;error_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;wp_json_encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$entry&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;WPTUTSHUB_REST_LOG&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="nv"&gt;$data&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="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;2&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;Two hooks do the work. &lt;code&gt;rest_post_dispatch&lt;/code&gt; fires inside &lt;code&gt;dispatch()&lt;/code&gt; with the finished &lt;code&gt;WP_REST_Response&lt;/code&gt;, so it has the status code and the route, and it also fires for internal calls made through &lt;code&gt;rest_do_request()&lt;/code&gt;. &lt;code&gt;rest_pre_echo_response&lt;/code&gt; fires in &lt;code&gt;serve_request()&lt;/code&gt; a few lines before WordPress echoes the JSON, which is the last moment you can look around and see whether something already printed. That second hook never runs for &lt;code&gt;rest_do_request()&lt;/code&gt;, only for real HTTP requests. It is the right tool for editor failures and the wrong one for unit tests.&lt;/p&gt;

&lt;p&gt;The stray-output check has two branches because output escapes in two ways. If a plugin started an output buffer, &lt;code&gt;ob_get_contents()&lt;/code&gt; holds everything printed so far. If nothing is buffering, the bytes went straight to the client and &lt;code&gt;headers_sent()&lt;/code&gt; names the file and line that forced the headers out. Either one explains the editor's message.&lt;/p&gt;

&lt;p&gt;Successful &lt;code&gt;GET&lt;/code&gt; requests are skipped on purpose. The editor makes a lot of them, and a log that grows by a megabyte per editing session is a log nobody reads.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading the log: stray bytes, status codes and the route that failed
&lt;/h2&gt;

&lt;p&gt;Each line is one JSON object. The fields that matter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;stray_bytes&lt;/strong&gt; above zero is the answer. &lt;code&gt;stray_head&lt;/code&gt; shows the text, and &lt;code&gt;headers_sent_at&lt;/code&gt; names the file and line when nothing was buffering. A single blank line after a closing &lt;code&gt;?&amp;gt;&lt;/code&gt; is enough to break the save.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;status&lt;/strong&gt; 401 with &lt;code&gt;user_id&lt;/code&gt; 0 means WordPress did not recognise the user, usually because a proxy stripped the &lt;code&gt;Cookie&lt;/code&gt; header. An expired nonce shows up as a 403 with the code &lt;code&gt;rest_cookie_invalid_nonce&lt;/code&gt; instead. Both replies are valid JSON, so they explain a different editor message, not this one; the last section covers them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;status&lt;/strong&gt; 403 is a permission or firewall answer. If &lt;code&gt;body_head&lt;/code&gt; contains HTML rather than a JSON error object, a security plugin or the host's WAF replied before WordPress did.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;status&lt;/strong&gt; 404 on a route you know exists points back at rewrite rules, or at a &lt;code&gt;siteurl&lt;/code&gt; that does not match the host in the address bar.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No line at all&lt;/strong&gt; while DevTools shows a 500 means PHP died. A fatal error stops the request before either hook runs, so the PHP error log is the next file to open. A 500 that does get logged came from WordPress itself, and &lt;code&gt;body_head&lt;/code&gt; holds its error code and message.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the file stays empty while the editor still fails and DevTools shows anything other than a 500, the request is not reaching WordPress at all. That is what the next section handles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate a WordPress fault from a server fault with WP-CLI
&lt;/h2&gt;

&lt;p&gt;Save this as &lt;code&gt;/tmp/rest-check.php&lt;/code&gt; and run &lt;code&gt;wp eval-file /tmp/rest-check.php&lt;/code&gt; from the site root.&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="c1"&gt;// Dispatch inside PHP. No web server, no proxy, no rewrite rules.&lt;/span&gt;
&lt;span class="nv"&gt;$request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WP_REST_Request&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="s1"&gt;'/wp/v2/posts'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;ob_start&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;$response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;rest_do_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$noise&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ob_get_clean&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="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"internal status: %d\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_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="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"internal items:  %d\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="p"&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="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_data&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="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"output before the body: %d bytes\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$noise&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;On a healthy site it prints this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;internal status: 200
internal items:  10
output before the body: 0 bytes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;rest_do_request()&lt;/code&gt; runs the route inside PHP with no web server, no proxy and no &lt;code&gt;.htaccess&lt;/code&gt;. A 200 with a sensible item count means WordPress and the route are healthy, and the fault sits between the browser and PHP. Anything above 0 bytes on the last line was printed by a plugin or theme while the route ran, which is the same stray output the logger looks for.&lt;/p&gt;

&lt;p&gt;If the internal status is 200 and curl returns HTML, look at the server: a proxy buffering the response, a WAF rule on &lt;code&gt;POST /wp-json/&lt;/code&gt;, or an &lt;code&gt;http&lt;/code&gt; to &lt;code&gt;https&lt;/code&gt; redirect that the editor's fetch follows and then parses as JSON. If the internal status is broken too, the problem is inside WordPress and the log will say which hook did it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fixes for what the log usually shows
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Security rules and proxies that answer JSON with HTML
&lt;/h3&gt;

&lt;p&gt;A 403 whose body starts with &lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/code&gt; did not come from WordPress. Turn off the security plugin's “disable REST API” option first, because several of them block &lt;code&gt;/wp-json/&lt;/code&gt; for logged-out users and forget that the block editor is authenticated but still passes through the same rules. If the body is a generic host error page, ask the host which rule fired and to switch that one rule off for &lt;code&gt;/wp-json/&lt;/code&gt; only. Do not ask for an exemption based on the &lt;code&gt;X-WP-Nonce&lt;/code&gt; header: anyone can send that header, so the exemption would turn the firewall off for every attacker who adds it. On shared hosting the firewall is usually ModSecurity with the OWASP Core Rule Set. Its rule 949110 does the blocking once a request's anomaly score is too high, so ask for the earlier rule that raised the score and exclude that one.&lt;/p&gt;

&lt;p&gt;The same rule applies to routes you write yourself: a route that returns HTML on failure produces this exact editor message, so return &lt;code&gt;WP_Error&lt;/code&gt; and let WordPress encode it. The patterns in &lt;a href="https://wptutshub.com/secure-custom-rest-api-endpoints-nonces-capability-checks/" rel="noopener noreferrer"&gt;securing custom REST API endpoints with nonces and capability checks&lt;/a&gt; cover that side of it, and &lt;a href="https://wptutshub.com/wp-cli-audit-rest-routes-missing-permission-callback/" rel="noopener noreferrer"&gt;auditing REST routes for missing permission callbacks&lt;/a&gt; catches the ones that answer with a fatal instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stray output from a plugin, a BOM or a closing PHP tag
&lt;/h3&gt;

&lt;p&gt;When &lt;code&gt;stray_bytes&lt;/code&gt; is above zero, the text in &lt;code&gt;stray_head&lt;/code&gt; is usually a PHP notice, a debug line someone left behind, or a byte order mark. A BOM is invisible in most editors and arrives when a file is saved by Notepad or by a tool that defaults to UTF-8 with signature. Closing &lt;code&gt;?&amp;gt;&lt;/code&gt; tags are optional in PHP files and any whitespace after one is sent to the browser before WordPress starts, which is why the coding standards tell you to leave them out.&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="c"&gt;# Byte order marks at the top of any PHP file (needs GNU grep, as on most Linux servers)&lt;/span&gt;
grep -rlP --include=&lt;span class="s1"&gt;'*.php'&lt;/span&gt; &lt;span class="s1"&gt;'^\xEF\xBB\xBF'&lt;/span&gt; wp-content/plugins wp-content/themes wp-content/mu-plugins

&lt;span class="c"&gt;# Closing tags in a theme's functions file (remove them, they are optional)&lt;/span&gt;
grep -rn &lt;span class="s1"&gt;'?&amp;gt;'&lt;/span&gt; wp-content/themes/your-theme/functions.php

&lt;span class="c"&gt;# The PHP error log, if WP_DEBUG_LOG is on&lt;/span&gt;
tail -n 40 wp-content/debug.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fix the file the log names, then reload the editor and save again. The log line for the retry should show &lt;code&gt;stray_bytes&lt;/code&gt; at 0 and a 200 status, which is the point where the editor stops complaining.&lt;/p&gt;

&lt;h3&gt;
  
  
  When the editor shows a different message: nonces and cookies
&lt;/h3&gt;

&lt;p&gt;Not every failed save is this error. When the reply is valid JSON, the editor prints WordPress's own message instead, and two of them come up often. “Cookie check failed” is a 403 with the code &lt;code&gt;rest_cookie_invalid_nonce&lt;/code&gt;: the nonce the editor sent has expired. The editor renews its nonce in the background while the tab is open, so this mostly happens after a laptop wakes from sleep or when a plugin has switched off the Heartbeat API, and reloading the editor fixes it. If every editor fails immediately after logging in, check whether a plugin hooks &lt;code&gt;rest_authentication_errors&lt;/code&gt; and returns a &lt;code&gt;WP_Error&lt;/code&gt; for requests it does not recognise; that filter runs before the route's own permission callback and will reject the editor's nonce if the plugin only checks for an application password.&lt;/p&gt;

&lt;p&gt;A 401 with &lt;code&gt;user_id&lt;/code&gt; 0 in the log means the login cookie never reached WordPress, and the editor says you are not allowed to edit the post. A reverse proxy that drops the &lt;code&gt;Cookie&lt;/code&gt; header, a &lt;code&gt;COOKIE_DOMAIN&lt;/code&gt; constant that does not match the current host, or a half-finished domain move will all do it. If the site recently changed address, &lt;a href="https://wptutshub.com/wordpress-replace-old-url-domain-change/" rel="noopener noreferrer"&gt;replacing the old URLs after a domain change&lt;/a&gt; is the step that usually fixes the REST calls too, because &lt;code&gt;siteurl&lt;/code&gt; and &lt;code&gt;home&lt;/code&gt; decide which host the editor talks to.&lt;/p&gt;

&lt;p&gt;Once the log has done its job, delete the mu-plugin. If you would rather keep the diagnostic around, make it self-limiting: rotate the file when it passes a few hundred kilobytes, and have &lt;code&gt;rest_pre_echo_response&lt;/code&gt; return a JSON error response when it detects stray bytes, so the editor shows a real message instead of the generic one. That turns a debugging aid into a guard that survives the next badly written plugin.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/updating-failed-invalid-json-wordpress/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Create a Custom Post Type in WordPress</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Fri, 27 Nov 2026 16:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/create-a-custom-post-type-in-wordpress-41o8</link>
      <guid>https://dev.to/zubaer/create-a-custom-post-type-in-wordpress-41o8</guid>
      <description>&lt;p&gt;To create a custom post type in WordPress you call &lt;code&gt;register_post_type()&lt;/code&gt; on the &lt;code&gt;init&lt;/code&gt; hook with a key, a labels array and a set of arguments that decide where the type shows up. That is a dozen lines. What actually breaks on real sites is everything around it: a type registered before &lt;code&gt;init&lt;/code&gt; fires, a key that collides with a reserved name, labels that leak the word “Post” into the editor, a REST route that 404s, and permalinks that only start resolving after somebody remembers to flush rewrite rules.&lt;/p&gt;

&lt;p&gt;The six checks below are the ones worth running against a site that already ships a custom post type, or against the one you are about to. Each check tells you how to detect the failure with WP-CLI or the browser, then how to fix it in code. The running example is a &lt;code&gt;book&lt;/code&gt; type with a &lt;code&gt;[book_list]&lt;/code&gt; shortcode.&lt;/p&gt;

&lt;p&gt;You need WordPress 6.7 or later, WP-CLI, and write access to &lt;code&gt;wp-content/plugins&lt;/code&gt;. The reference plugin is a single file at &lt;code&gt;wp-content/plugins/book-cpt/book-cpt.php&lt;/code&gt;. Activate it, then work through the checks.&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Plugin Name: Book Library
 * Description: Registers the book custom post type and a [book_list] shortcode.
 * Version:     1.0.0
 * Requires PHP: 7.4
 */&lt;/span&gt;

&lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'ABSPATH'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Registers the book post type on init.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wptb_register_book_post_type&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;$labels&lt;/span&gt; &lt;span class="o"&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;'name'&lt;/span&gt;                  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;_x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Books'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'post type general name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'singular_name'&lt;/span&gt;         &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;_x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'post type singular name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'menu_name'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;_x&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Books'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'admin menu'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'all_items'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'All Books'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'add_new'&lt;/span&gt;               &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Add New'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'add_new_item'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Add New Book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'edit_item'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Edit Book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'new_item'&lt;/span&gt;              &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'New Book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'view_item'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'View Book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'view_items'&lt;/span&gt;            &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'View Books'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'search_items'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Search Books'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'not_found'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'No books found.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'not_found_in_trash'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'No books found in Trash.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'featured_image'&lt;/span&gt;        &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Cover image'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'set_featured_image'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Set cover image'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'remove_featured_image'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Remove cover image'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'use_featured_image'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Use as cover image'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'archives'&lt;/span&gt;              &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Book archives'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'item_published'&lt;/span&gt;        &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Book published.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'item_updated'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Book updated.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&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;$args&lt;/span&gt; &lt;span class="o"&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;'labels'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$labels&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="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Catalogue entries for published books.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'public'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'publicly_queryable'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'show_ui'&lt;/span&gt;            &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'show_in_menu'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'show_in_rest'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'rest_base'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'books'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'menu_icon'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'dashicons-book-alt'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'menu_position'&lt;/span&gt;      &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'has_archive'&lt;/span&gt;        &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'books'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'rewrite'&lt;/span&gt;            &lt;span class="o"&gt;=&amp;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;'slug'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'books'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'with_front'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&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="s1"&gt;'supports'&lt;/span&gt;           &lt;span class="o"&gt;=&amp;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;'title'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'editor'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'excerpt'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'thumbnail'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'author'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'revisions'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'custom-fields'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'taxonomies'&lt;/span&gt;         &lt;span class="o"&gt;=&amp;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;'category'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'post_tag'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'capability_type'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'post'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'map_meta_cap'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&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="nf"&gt;register_post_type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb_register_book_post_type'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Writes the book rewrite rules once, when the plugin is activated.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wptb_book_activate&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="nf"&gt;wptb_register_book_post_type&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="nf"&gt;flush_rewrite_rules&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="nf"&gt;register_activation_hook&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb_book_activate'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Drops the book rules again when the plugin is deactivated.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wptb_book_deactivate&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="nf"&gt;flush_rewrite_rules&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="nf"&gt;register_deactivation_hook&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb_book_deactivate'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * [book_list] — prints the most recent books.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wptb_book_list_shortcode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$atts&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$atts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;shortcode_atts&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;'count'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nv"&gt;$atts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'book_list'&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nv"&gt;$books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WP_Query&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;'post_type'&lt;/span&gt;           &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'post_status'&lt;/span&gt;         &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'publish'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'posts_per_page'&lt;/span&gt;      &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;absint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$atts&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'count'&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="s1"&gt;'ignore_sticky_posts'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'no_found_rows'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$books&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;have_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="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;p class="book-list-empty"&amp;gt;'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;esc_html__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'No books yet.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;/p&amp;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;$items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&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;$books&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;posts&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$book&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$items&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s1"&gt;'&amp;lt;li&amp;gt;&amp;lt;a href="%1$s"&amp;gt;%2$s&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nf"&gt;esc_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;get_permalink&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$book&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="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;get_the_title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$book&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;return&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;h2&amp;gt;'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;esc_html__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Latest books'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;/h2&amp;gt;'&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;ul class="book-list"&amp;gt;'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$items&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;/ul&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;add_shortcode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'book_list'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb_book_list_shortcode'&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;That file is the answer key for the rest of the article. Everything below is either a way to prove one of its decisions is wrong on your site, or the fix when it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 1: Is the post type registered on init, or has it been fired too early?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Detect.&lt;/strong&gt; WordPress does not warn you about an early call, so check the code. Find every call and confirm each one sits inside a function hooked to &lt;code&gt;init&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;grep -rn &lt;span class="s2"&gt;"register_post_type("&lt;/span&gt; wp-content/plugins wp-content/mu-plugins wp-content/themes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A call at the top level of a plugin file, or on a hook that fires before &lt;code&gt;init&lt;/code&gt;, runs before WordPress has finished setting up rewrite rules and translations. The usual symptoms are permalinks that 404 and labels that stay in English on a translated site. The registry check in the next section shows what actually ended up registered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; Move the call into a named function and hook it to &lt;code&gt;init&lt;/code&gt;. Do not use &lt;code&gt;plugins_loaded&lt;/code&gt;, &lt;code&gt;after_setup_theme&lt;/code&gt;, or top-level code in the plugin 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;// Too early: this runs while plugins are still loading.&lt;/span&gt;
&lt;span class="nf"&gt;register_post_type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$args&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Correct: a named callback on init, priority 10.&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wptb_register_book_post_type&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;$args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="cm"&gt;/* ... */&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;register_post_type&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'book'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb_register_book_post_type'&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;Rewrite rules, the REST server and the block editor’s post type schema are all assembled after &lt;code&gt;init&lt;/code&gt;. A type registered later is invisible to them, so you get a menu entry that works but no permalinks and no REST route. Keeping the registration on &lt;code&gt;init&lt;/code&gt; at the default priority also means another plugin can hook &lt;code&gt;init&lt;/code&gt; at priority 11 and still see your type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 2: Does the post type key survive the 20-character and reserved-name rules?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Detect.&lt;/strong&gt; &lt;code&gt;register_post_type()&lt;/code&gt; returns a &lt;code&gt;WP_Error&lt;/code&gt; instead of the object when the key is empty or longer than 20 characters. Ask it directly:&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="c"&gt;# What happens with a key that breaks the rules?&lt;/span&gt;
wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'print_r( register_post_type( "a-very-long-post-type-key", array() ) );'&lt;/span&gt;

&lt;span class="c"&gt;# Every public post type, with its REST base.&lt;/span&gt;
wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'foreach ( get_post_types( array( "public" =&amp;gt; true ), "objects" ) as $pt ) { printf( "%-22s rest=%s\n", $pt-&amp;gt;name, $pt-&amp;gt;show_in_rest ? $pt-&amp;gt;rest_base : "off" ); }'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first command prints a &lt;code&gt;WP_Error&lt;/code&gt; with the code &lt;code&gt;post_type_length_invalid&lt;/code&gt;. Reserved keys are a different trap, because WordPress does not reject them: registering &lt;code&gt;post&lt;/code&gt;, &lt;code&gt;page&lt;/code&gt;, &lt;code&gt;attachment&lt;/code&gt;, &lt;code&gt;revision&lt;/code&gt;, &lt;code&gt;wp_block&lt;/code&gt;, &lt;code&gt;wp_template&lt;/code&gt; or &lt;code&gt;wp_navigation&lt;/code&gt; replaces the settings of the built-in type, which breaks core screens in ways that are hard to trace back.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; Keep the key lowercase, 20 characters or fewer, and prefix it if the plugin might be installed next to another one that also wants &lt;code&gt;book&lt;/code&gt;. Underscores are safer than hyphens because the key ends up in query vars, body classes and capability names. If you need a longer public-facing name, that belongs in &lt;code&gt;rewrite['slug']&lt;/code&gt;, not in the key.&lt;/p&gt;

&lt;p&gt;A failed registration is silent unless &lt;code&gt;WP_DEBUG&lt;/code&gt; is on or you check the return value. The menu item never appears, and the only clue is a missing type, which is easy to blame on caching.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 3: Do the labels read like English on every screen?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Detect.&lt;/strong&gt; Open the post type’s list table and press &lt;em&gt;Add New&lt;/em&gt;. If the button says “Add New Post”, the editor heading says “Edit Post”, or the featured image box says “Featured image” instead of “Cover image”, the labels array is incomplete. The same information is available from the command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'print_r( get_post_type_object( "book" )-&amp;gt;labels );'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; Supply the labels that WordPress does not derive well. &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;singular_name&lt;/code&gt; cover most of the admin, but &lt;code&gt;menu_name&lt;/code&gt;, &lt;code&gt;all_items&lt;/code&gt;, &lt;code&gt;add_new_item&lt;/code&gt;, &lt;code&gt;edit_item&lt;/code&gt;, &lt;code&gt;not_found&lt;/code&gt; and the four featured-image strings are worth setting explicitly. Wrap every string in &lt;code&gt;_x()&lt;/code&gt; or &lt;code&gt;__()&lt;/code&gt; with the same text domain as the plugin.&lt;/p&gt;

&lt;p&gt;The Books list table, showing the custom labels applied to the admin menu and screen (test site: WordPress 7.1.3, PHP 8.2)&lt;/p&gt;

&lt;p&gt;Labels are the only part of the post type an editor ever sees. A type called “Book” whose buttons say “Post” reads as a bug, and translators cannot fix it later if the strings were never passed through a translation function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 4: Is show_in_rest on so the block editor and REST API can see the type?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Detect.&lt;/strong&gt; Two quick tests. First, the registry:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'var_dump( get_post_type_object( "book" )-&amp;gt;show_in_rest );'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second, the route. Request &lt;code&gt;/wp-json/wp/v2/books&lt;/code&gt; in a browser. A &lt;code&gt;rest_no_route&lt;/code&gt; error means the type is not exposed. On the editing screen the symptom looks different: the post type falls back to the classic editor even though &lt;code&gt;supports&lt;/code&gt; includes &lt;code&gt;editor&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; Set &lt;code&gt;'show_in_rest' =&amp;gt; true&lt;/code&gt; and, if you want a cleaner URL than the post type key, &lt;code&gt;'rest_base' =&amp;gt; 'books'&lt;/code&gt;. The default controller is &lt;code&gt;WP_REST_Posts_Controller&lt;/code&gt;, which is what you want unless the type needs custom fields with their own schema.&lt;/p&gt;

&lt;p&gt;Without &lt;code&gt;show_in_rest&lt;/code&gt; the type is invisible to the block editor and to any headless front end. It also blocks &lt;code&gt;register_post_meta()&lt;/code&gt; with &lt;code&gt;show_in_rest&lt;/code&gt;, so custom fields cannot be edited in the block editor sidebar.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 5: Are rewrite rules flushed on activation only?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Detect.&lt;/strong&gt; Publish a book, then open its permalink. A 404 while the post exists in the database is the classic symptom. Confirm with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp rewrite list --match=/books/
wp option get rewrite_rules &lt;span class="o"&gt;|&lt;/span&gt; grep -c books
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the first command lists nothing and the second prints &lt;code&gt;0&lt;/code&gt;, the rules for the type were never generated.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; Flush once, when the plugin is activated, not on every request. The activation callback has to register the type first, because &lt;code&gt;flush_rewrite_rules()&lt;/code&gt; rebuilds the rules from whatever is registered at that moment.&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="nf"&gt;register_activation_hook&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb_book_activate'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wptb_book_activate&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="c1"&gt;// The type has to exist before the rules can be generated for it.&lt;/span&gt;
    &lt;span class="nf"&gt;wptb_register_book_post_type&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="nf"&gt;flush_rewrite_rules&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="nf"&gt;register_deactivation_hook&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wptb_book_deactivate'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wptb_book_deactivate&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="nf"&gt;flush_rewrite_rules&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;For a type registered from a must-use plugin there is no activation hook, so run &lt;code&gt;wp rewrite flush --hard&lt;/code&gt; once after deploying and again after any change to &lt;code&gt;rewrite['slug']&lt;/code&gt; or &lt;code&gt;has_archive&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;flush_rewrite_rules()&lt;/code&gt; writes the &lt;code&gt;rewrite_rules&lt;/code&gt; option. Calling it on &lt;code&gt;init&lt;/code&gt; means a database write on every page load, and on a busy site that is a genuine performance problem. It also masks the real bug: if the rules are rebuilt constantly, a slug collision with a page or another post type never shows up until the flush is removed.&lt;/p&gt;

&lt;p&gt;My tip · Md. Zubaer Ahammed&lt;/p&gt;

&lt;p&gt;Choose the post type key carefully before you publish anything, because it is stored with every post. Labels and the URL slug can be changed at any time; changing the key later means updating the database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 6: Does a WP_Query or shortcode actually return the new posts?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Detect.&lt;/strong&gt; Run the query outside the theme:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'
$q = new WP_Query( array( "post_type" =&amp;gt; "book", "posts_per_page" =&amp;gt; 5 ) );
printf( "found: %d\n", $q-&amp;gt;found_posts );
foreach ( $q-&amp;gt;posts as $p ) {
    printf( " - %s -&amp;gt; %s\n", get_the_title( $p ), get_permalink( $p ) );
}
'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;found: 0&lt;/code&gt; with books in the database almost always means the query is missing &lt;code&gt;'post_type' =&amp;gt; 'book'&lt;/code&gt;, or is using &lt;code&gt;query_posts()&lt;/code&gt; and clobbering the main query. A shortcode that prints “No books yet.” on a page with published books has the same cause.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fix.&lt;/strong&gt; Use a secondary &lt;code&gt;WP_Query&lt;/code&gt; with an explicit &lt;code&gt;post_type&lt;/code&gt;, &lt;code&gt;post_status&lt;/code&gt; and &lt;code&gt;no_found_rows&lt;/code&gt; when you do not need pagination. The &lt;code&gt;[book_list]&lt;/code&gt; shortcode in the reference plugin does exactly that, and it escapes the permalink and the title on output rather than trusting them.&lt;/p&gt;

&lt;p&gt;Run the whole registration through one script to see the state of all six checks at once:&lt;/p&gt;

&lt;p&gt;Registration state of the book post type plus the posts the shortcode will list (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;book post type: registered
show_in_rest: yes
rest_base: books
rewrite slug: books
has_archive: 'books'
menu label: Books
books found: 2
 - Salt and Signal (http://localhost/books/salt-and-signal/)
 - The Quiet Cartographer (http://localhost/books/the-quiet-cartographer/)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then load the page that holds the shortcode. The heading and the book titles come from the query, so if they render, the type, the rewrite rules and the query are all working together:&lt;/p&gt;

&lt;p&gt;The [book_list] shortcode rendering books queried from the new post type (test site: WordPress 7.1.3, PHP 8.2)&lt;/p&gt;

&lt;p&gt;A registered post type that no template queries is dead weight. The shortcode is the cheapest end-to-end proof: it exercises registration, the database, the query and the permalink in a single request.&lt;/p&gt;

&lt;p&gt;To expose the new type's custom fields to the block editor and the REST API, see &lt;a href="https://wptutshub.com/register-rest-field-custom-post-meta-schema-validation/" rel="noopener noreferrer"&gt;adding custom post meta to the REST API with register_rest_field&lt;/a&gt;. For front-end layouts that pull from it, &lt;a href="https://wptutshub.com/custom-gutenberg-block-patterns-dynamic-data/" rel="noopener noreferrer"&gt;custom block patterns with dynamic data&lt;/a&gt; is the next step.&lt;/p&gt;

&lt;p&gt;Once the six checks pass, the next thing worth doing is giving the type its own archive template. In a block theme, add &lt;code&gt;archive-book.html&lt;/code&gt; to the theme's &lt;code&gt;templates&lt;/code&gt; folder or create it in the Site Editor; in a classic theme, add &lt;code&gt;archive-book.php&lt;/code&gt;. The archive then stops borrowing the generic post layout.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/create-custom-post-type-wordpress/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Fix WordPress 504 Gateway Timeout Error</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Wed, 25 Nov 2026 14:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/fix-wordpress-504-gateway-timeout-error-17gk</link>
      <guid>https://dev.to/zubaer/fix-wordpress-504-gateway-timeout-error-17gk</guid>
      <description>&lt;p&gt;A 504 Gateway Timeout is not a WordPress error. It is the process in front of WordPress giving up. Nginx, Apache with &lt;code&gt;mod_proxy&lt;/code&gt;, a load balancer or a CDN opened a connection, PHP did not answer inside the window it allows, and the proxy closed the request. To fix a 504 gateway timeout on WordPress you either make the slow request finish sooner or raise the timeout at the layer that gave up. The checks below tell you which of those you need, in an order that avoids wasted work.&lt;/p&gt;

&lt;p&gt;Two symptoms point in different directions. A 504 on one URL, every time, is a code problem: a loop, an unbounded query, a call to a payment API with no timeout. A 504 that lands on random pages, gets worse in the afternoon and clears after a restart is a capacity problem: PHP workers exhausted, a cron backlog, or a database that cannot keep up.&lt;/p&gt;

&lt;p&gt;From experience · Md. Zubaer Ahammed&lt;/p&gt;

&lt;p&gt;On this site a server cron job calls &lt;code&gt;wp-cron.php&lt;/code&gt; every five minutes, so scheduled posts publish on time and background jobs do not depend on visitors loading pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the status code tells you about the layer that failed
&lt;/h2&gt;

&lt;p&gt;The request passes through several processes, each with its own patience. The browser waits. The CDN waits. The web server waits for PHP-FPM. PHP-FPM waits for a worker, and the worker waits for MySQL or an external API. Whichever of those runs out first writes the error you see, and the status code narrows it down.&lt;/p&gt;

&lt;p&gt;A 502 means the proxy reached the backend and got an invalid or empty reply, which usually points at a crashed or restarted PHP-FPM pool. A 504 means the proxy reached the backend and heard nothing at all before its own clock expired. That distinction matters because raising a timeout on a 502 does nothing, while raising it on a 504 buys you time you may not need if the real problem is a plugin waiting on a dead socket.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Take a snapshot of limits and queues with one WP-CLI command
&lt;/h2&gt;

&lt;p&gt;Before you edit a single config file, collect the numbers. The mu-plugin below adds &lt;code&gt;wp tut504 audit&lt;/code&gt;, which prints the PHP limits, whether WP-Cron is disabled, how many events are queued and which fire next, the size of autoloaded options, and the active plugin list. Those five numbers explain most 504s on an ordinary site, and they take ten seconds to gather.&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Plugin Name: Tuts Hub 504 Audit
 * Description: Prints the limits and queues behind most gateway timeouts.
 */&lt;/span&gt;

&lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'ABSPATH'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&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="o"&gt;!&lt;/span&gt; &lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_CLI'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="no"&gt;WP_CLI&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="p"&gt;}&lt;/span&gt;

&lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;add_command&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'tut504 audit'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;static&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;$limits&lt;/span&gt; &lt;span class="o"&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;'max_execution_time'&lt;/span&gt;     &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'max_execution_time'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'max_input_time'&lt;/span&gt;         &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'max_input_time'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'default_socket_timeout'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'default_socket_timeout'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'memory_limit'&lt;/span&gt;           &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'memory_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="p"&gt;;&lt;/span&gt;

        &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'PHP limits'&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;$limits&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'  %-24s %s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$value&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="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&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="p"&gt;;&lt;/span&gt;
        &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Cron'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'  DISABLE_WP_CRON  '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'DISABLE_WP_CRON'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;DISABLE_WP_CRON&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'true'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'false'&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;$total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$next&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;array&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="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="nf"&gt;_get_cron_array&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;$timestamp&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$hooks&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="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="nv"&gt;$hooks&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$hook&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$queue&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="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="nv"&gt;$queue&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$event&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nv"&gt;$total&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="nv"&gt;$next&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$hook&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$timestamp&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="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'  scheduled events '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$total&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nf"&gt;asort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$next&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="nf"&gt;array_slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$next&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&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;$hook&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$timestamp&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'  %s  %s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;gmdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Y-m-d H:i'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$timestamp&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hook&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;global&lt;/span&gt; &lt;span class="nv"&gt;$wpdb&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$autoload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$wpdb&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"SELECT SUM(LENGTH(option_name) + LENGTH(option_value)) FROM {$wpdb-&amp;gt;options} WHERE autoload IN ('yes','on','auto','auto-on')"&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&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="p"&gt;;&lt;/span&gt;
        &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Autoloaded options: '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;size_format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$autoload&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;$plugins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'active_plugins'&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="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Active plugins: '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nb"&gt;count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$plugins&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;$plugins&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$plugin&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;line&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="nv"&gt;$plugin&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;Drop that in &lt;code&gt;wp-content/mu-plugins/&lt;/code&gt; and run &lt;code&gt;wp tut504 audit&lt;/code&gt;. Read the output against three thresholds. A &lt;code&gt;max_execution_time&lt;/code&gt; of 30 with a proxy timeout of 60 means PHP dies first and you get a 500 rather than a 504, which is worth knowing before you blame the host. A cron event count in the hundreds with &lt;code&gt;DISABLE_WP_CRON&lt;/code&gt; set to false means jobs are running inside visitor requests. Autoloaded options above roughly 1 MB slow every single request on the site.&lt;/p&gt;

&lt;p&gt;The audit command prints PHP limits, the cron backlog, autoload size and the active plugin list in one pass (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PHP limits
  max_execution_time       0
  max_input_time           -1
  default_socket_timeout   60
  memory_limit             -1

Cron
  DISABLE_WP_CRON  true
  scheduled events 12
  2026-11-11 01:56  recovery_mode_clean_expired_keys
  2026-11-11 01:56  wp_privacy_delete_old_export_files
  2026-11-11 01:56  wp_privacy_personal_data_cleanup_requests
  2026-11-11 02:56  wp_version_check
  2026-11-11 03:26  wp_update_plugins

Autoloaded options: 40 KB
Active plugins: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Find the request that actually hangs
&lt;/h2&gt;

&lt;p&gt;Guessing which plugin is slow wastes an afternoon. The access log already knows. Both Nginx and Apache record the status code and the path, so a single grep gives you the URLs that timed out and how often.&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="c"&gt;# Nginx: which paths returned 504, most frequent first&lt;/span&gt;
sudo grep -h &lt;span class="s1"&gt;' 504 '&lt;/span&gt; /var/log/nginx/access.log /var/log/nginx/access.log.1 \
  &lt;span class="o"&gt;|&lt;/span&gt; awk &lt;span class="s1"&gt;'{print $7}'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sort &lt;span class="o"&gt;|&lt;/span&gt; uniq -c &lt;span class="o"&gt;|&lt;/span&gt; sort -rn &lt;span class="o"&gt;|&lt;/span&gt; head -20

&lt;span class="c"&gt;# Apache: same question, different log format&lt;/span&gt;
sudo grep -h &lt;span class="s1"&gt;' 504 '&lt;/span&gt; /var/log/apache2/*access*.log &lt;span class="o"&gt;|&lt;/span&gt; cut -d&lt;span class="s1"&gt;'"'&lt;/span&gt; -f2 &lt;span class="o"&gt;|&lt;/span&gt; sort &lt;span class="o"&gt;|&lt;/span&gt; uniq -c &lt;span class="o"&gt;|&lt;/span&gt; sort -rn

&lt;span class="c"&gt;# Time a suspect URL from the server itself so the proxy is the only variable left&lt;/span&gt;
curl -sS -o /dev/null -w &lt;span class="s1"&gt;'connect %{time_connect} ttfb %{time_starttransfer} total %{time_total} code %{http_code}\n'&lt;/span&gt; \
  https://example.com/wp-admin/admin-ajax.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the log shows &lt;code&gt;admin-ajax.php&lt;/code&gt;, a REST route, or a WooCommerce admin screen, the problem is in PHP and you can reproduce it. If it shows static files or the home page, the problem is upstream of WordPress and no plugin change will help. Enable the PHP-FPM slow log as well, because it names the script and the function stack that was still running when the clock ran out, which the access log never does.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Line up PHP, PHP-FPM and the proxy on the same number
&lt;/h2&gt;

&lt;p&gt;There are three separate clocks and they do not measure the same thing. &lt;code&gt;max_execution_time&lt;/code&gt; counts CPU time only, so on Unix a request blocked on a socket to a payment gateway can outlive a 30 second limit by minutes. &lt;code&gt;request_terminate_timeout&lt;/code&gt; in the FPM pool is a hard kill measured in wall time. &lt;code&gt;fastcgi_read_timeout&lt;/code&gt; in Nginx is the proxy's patience. Set them in ascending order so the innermost layer fails first and writes the useful log line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c1"&gt;; php.ini
&lt;/span&gt;&lt;span class="na"&gt;max_execution_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;
&lt;span class="na"&gt;max_input_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;
&lt;span class="na"&gt;default_socket_timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;

&lt;span class="c1"&gt;; /etc/php/8.2/fpm/pool.d/www.conf
; hard kill slightly above max_execution_time so PHP logs its own error first
&lt;/span&gt;&lt;span class="na"&gt;request_terminate_timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;130s&lt;/span&gt;
&lt;span class="na"&gt;request_slowlog_timeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10s&lt;/span&gt;
&lt;span class="na"&gt;slowlog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;fpm&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;slow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;log&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the proxy, which must sit above the FPM kill so it never gives up before PHP has had the chance to write a stack trace.&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="c"&gt;# /etc/nginx/conf.d/timeouts.conf&lt;/span&gt;
&lt;span class="c"&gt;# fastcgi_read_timeout must be larger than request_terminate_timeout&lt;/span&gt;
fastcgi_read_timeout 150s&lt;span class="o"&gt;;&lt;/span&gt;
fastcgi_send_timeout 150s&lt;span class="o"&gt;;&lt;/span&gt;
proxy_read_timeout 150s&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="c"&gt;# Apache httpd.conf or the vhost block&lt;/span&gt;
&lt;span class="c"&gt;# ProxyTimeout 150&lt;/span&gt;
&lt;span class="c"&gt;# Timeout 150&lt;/span&gt;

&lt;span class="c"&gt;# .htaccess, shared hosting with mod_php only&lt;/span&gt;
&lt;span class="c"&gt;# php_value max_execution_time 120&lt;/span&gt;
&lt;span class="c"&gt;# php_value max_input_time 120&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those &lt;code&gt;php_value&lt;/code&gt; lines are a trap on modern hosting. Under PHP-FPM, &lt;code&gt;.htaccess&lt;/code&gt; is not read by PHP at all, and putting &lt;code&gt;php_value&lt;/code&gt; in it returns a 500 for the whole site. If your host runs FPM, change the limit in the control panel or a local &lt;code&gt;php.ini&lt;/code&gt; instead. Tools, then Site Health, then the Info tab lists the value PHP is actually running with, which is the number that matters rather than the one in the file you edited.&lt;/p&gt;

&lt;p&gt;Tools → Site Health → Info, Server section: the PHP time limit the proxy is actually waiting on (test site: WordPress 7.1.3, PHP 8.2)&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Bisect the plugin or hook that never returns
&lt;/h2&gt;

&lt;p&gt;Once the log points at a PHP request, halve the problem instead of reading code. Deactivate everything, confirm the URL answers, then switch plugins back on in groups. WP-CLI makes this fast enough to do while the site is in maintenance mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp plugin list --status=active --field=name
wp plugin deactivate --all

&lt;span class="c"&gt;# reload the failing URL, then bring groups back&lt;/span&gt;
wp plugin activate woocommerce
wp plugin activate woocommerce-gateway-stripe

&lt;span class="c"&gt;# a plugin that is active but broken will still fatal on load&lt;/span&gt;
wp plugin verify-checksums --all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The classic offender is an external HTTP call inside a loop. &lt;code&gt;wp_remote_get()&lt;/code&gt; defaults to a 5 second timeout, but plenty of code passes &lt;code&gt;'timeout' =&amp;gt; 30&lt;/code&gt;, or omits the argument entirely while looping over 200 products. Twenty calls at 30 seconds each is a 504 no matter what you set in &lt;code&gt;php.ini&lt;/code&gt;. If the slow request is a scheduled job rather than a page, the debugging approach is different and covered in &lt;a href="https://wptutshub.com/using-cron-job-wordpress-schedule-events-wp-cron-part-2/" rel="noopener noreferrer"&gt;WP-Cron Part 2: Single Events, Arguments and Debugging&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Clear the cron and Action Scheduler backlog
&lt;/h2&gt;

&lt;p&gt;WooCommerce does not run subscriptions, webhooks and imports on its own scheduler. It queues them in Action Scheduler, which stores jobs in the database and drains them through WP-Cron. A backlog of a few thousand pending actions means every page load tries to claim and run a batch, and the visitor's request pays for it. That is how a shop ends up with 504s on pages that do almost nothing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp cron event list --fields=hook,next_run_relative,recurrence
wp cron event run --due-now

&lt;span class="c"&gt;# WooCommerce queue: run four batches of 25 actions, then stop&lt;/span&gt;
wp action-scheduler run --batch-size=25 --batches=4

&lt;span class="c"&gt;# then keep cron out of page loads entirely&lt;/span&gt;
&lt;span class="c"&gt;# wp-config.php: define( 'DISABLE_WP_CRON', true );&lt;/span&gt;
&lt;span class="c"&gt;# crontab: */5 * * * * cd /var/www/html &amp;amp;&amp;amp; wp cron event run --due-now &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Disabling WP-Cron without adding the system cron line is worse than leaving it alone, because nothing runs at all. Set both at the same time. The scheduling side of this is covered in &lt;a href="https://wptutshub.com/using-cron-job-in-wordpress-schedule-events-with-wp-cron-part-1/" rel="noopener noreferrer"&gt;WP-Cron Part 1: Schedule Recurring Events in WordPress&lt;/a&gt; if you need the event API rather than the cleanup commands.&lt;/p&gt;

&lt;p&gt;WP-Cron lists the same queue with relative times, which is how you spot a backlog that never drains (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hook    next_run_relative   recurrence
recovery_mode_clean_expired_keys    now 1 day
wp_privacy_delete_old_export_files  now 1 hour
wp_privacy_personal_data_cleanup_requests   now 1 day
wp_version_check    now 12 hours
wp_update_plugins   now 12 hours
wp_update_themes    now 12 hours
wp_site_health_scheduled_check  now 1 week
wp_scheduled_delete now 1 day
delete_expired_transients   now 1 day
wp_update_user_counts   now 12 hours
wp_scheduled_auto_draft_delete  now 1 day
wp_update_comment_type_batch    59 seconds  Non-repeating
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Batch WooCommerce work so it finishes inside the window
&lt;/h2&gt;

&lt;p&gt;When a WooCommerce admin screen or an import times out, the fix is usually to stop doing the work in a web request. Move it to WP-CLI, page through the records, and give the loop a time budget so it can be resumed instead of dying halfway. The loop below recalculates totals in chunks of 50 and stops after 20 seconds, then tells you which page to continue from.&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="c1"&gt;// Start page: pass it as an argument, for example: wp eval-file batch.php 5&lt;/span&gt;
&lt;span class="nv"&gt;$page&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&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;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$args&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$start&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;time&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;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$orders&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wc_get_orders&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;'limit'&lt;/span&gt;   &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'page'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$page&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="s1"&gt;'processing'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'orderby'&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;'order'&lt;/span&gt;   &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'ASC'&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$orders&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="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;success&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Finished at page '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$page&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&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;$orders&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$order&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;calculate_totals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;save&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="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Processed page '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$page&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="nv"&gt;$page&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="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;$start&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="no"&gt;WP_CLI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Time budget reached. Continue with: wp eval-file batch.php '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$page&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&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;Run it with &lt;code&gt;wp eval-file batch.php&lt;/code&gt;. When it stops on its time budget, pass the page it reports as an argument to carry on, for example &lt;code&gt;wp eval-file batch.php 5&lt;/code&gt;. Two details keep this honest. &lt;code&gt;wc_get_orders()&lt;/code&gt; with no &lt;code&gt;limit&lt;/code&gt; loads every matching order into memory, which is its own route to a timeout on a large shop. And if you are mid-migration to custom order tables, the sync between posts and orders adds work to each save, so keep batches small; the order meta side of that is covered in &lt;a href="https://wptutshub.com/woocommerce-hpos-custom-order-meta-migration/" rel="noopener noreferrer"&gt;WooCommerce HPOS migration&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Shrink autoloaded options and slow queries
&lt;/h2&gt;

&lt;p&gt;Autoloaded options load on every request, including REST calls and admin-ajax. A plugin that stores a serialised array of product IDs in an option marked autoload turns a 200 ms request into a 900 ms one, and a request that was already close to the proxy limit tips over. Find the offenders with a direct query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;option_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;LENGTH&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;option_value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;wp_options&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;autoload&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'yes'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'on'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'auto'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s1"&gt;'auto-on'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;bytes&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;
&lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anything over about 100 KB deserves a look. Switch autoload off for options that are only read on their own admin screen, with &lt;code&gt;wp option set-autoload option_name off&lt;/code&gt;, and clear expired transients with &lt;code&gt;wp transient delete --expired&lt;/code&gt;. If the slow log shows queries rather than PHP, check the database itself before blaming the code, since a table that needs repair produces exactly this symptom and is covered in &lt;a href="https://wptutshub.com/fix-wordpress-database-connection-error/" rel="noopener noreferrer"&gt;fixing the WordPress database connection error&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;My tip · Md. Zubaer Ahammed&lt;/p&gt;

&lt;p&gt;Find the URL that times out before you raise any timeout. A higher limit only hides a slow request, and the 504 comes back as soon as traffic grows.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prove the fix with a timed request, not a page refresh
&lt;/h2&gt;

&lt;p&gt;After changing a timeout, measure. The &lt;code&gt;curl -w&lt;/code&gt; line from check 2 prints time to first byte and total time, so you can see whether the request now finishes in 4 seconds or still crawls to 140. If it finishes in 4 seconds, the timeout change was cosmetic and the real fix was the batching or the plugin. If it still crawls, you raised a limit without removing the cause and the 504 will return the moment traffic picks up.&lt;/p&gt;

&lt;p&gt;A useful next step is to log slow requests yourself rather than waiting for the host to notice. Start a timer in a &lt;code&gt;mu-plugin&lt;/code&gt; on &lt;code&gt;init&lt;/code&gt;, compare it against the current time on &lt;code&gt;shutdown&lt;/code&gt;, and append anything over five seconds to a file with the URL and the current user. That log catches the request that is about to become a 504 while it is still a 200, which is the only window where you can fix it quietly.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/fix-504-gateway-timeout-wordpress/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Fix WordPress Mixed Content Error After SSL</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Mon, 23 Nov 2026 16:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/fix-wordpress-mixed-content-error-after-ssl-31ke</link>
      <guid>https://dev.to/zubaer/fix-wordpress-mixed-content-error-after-ssl-31ke</guid>
      <description>&lt;p&gt;To fix the mixed content error WordPress shows after an SSL move, stop guessing and start logging: the browser already knows which asset is still being requested over http://, and a &lt;code&gt;Content-Security-Policy-Report-Only&lt;/code&gt; header can write that list to your server log. This guide compares the short-cut fixes you will find in forum threads, explains when each one actually fits, then implements the recommended workflow in full: a serialisation-safe WP-CLI &lt;code&gt;search-replace&lt;/code&gt;, a small filter for builder JSON and theme CSS, and the proxy settings that stop &lt;code&gt;is_ssl()&lt;/code&gt; returning false long after the certificate is live.&lt;/p&gt;

&lt;p&gt;You will need: shell access with WP-CLI 2.x installed on the server, a database backup (or a staging clone you can break), and permission to drop a file into &lt;code&gt;wp-content/mu-plugins/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;From experience · Md. Zubaer Ahammed&lt;/p&gt;

&lt;p&gt;WP Tuts Hub itself runs behind Cloudflare and a reverse proxy, so PHP never sees the HTTPS connection directly. The forwarded-protocol check from this guide is in this site's own &lt;code&gt;wp-config.php&lt;/code&gt; for exactly that reason.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the padlock still breaks when the site URL already says https://
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;WP_HOME&lt;/code&gt; and &lt;code&gt;WP_SITEURL&lt;/code&gt; only govern the URLs WordPress &lt;em&gt;generates&lt;/em&gt;. Anything typed into post content, pasted into a widget, stored in an options row, baked into a theme stylesheet or serialised inside a page builder's JSON stays exactly as it was written: http:// and all. The browser then refuses to mix an insecure subresource into a secure document.&lt;/p&gt;

&lt;p&gt;The severity differs by asset type. Scripts, stylesheets, iframes and XHR calls are blocked outright, so the page loads with broken layout or dead interactivity. Images and media are usually auto-upgraded to https:// first and only blocked if that upgrade fails, which is why a site can look mostly fine while the Console tab is full of red. Before you change a single row, open DevTools, reload the offending page, and read the Console entries: each one names the exact URL the browser refused.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three routes to a green padlock, and when each one is the right call
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Route 1: a search-replace plugin through wp-admin
&lt;/h3&gt;

&lt;p&gt;Tools such as Better Search Replace run inside a browser request and handle serialised data correctly. They are genuinely useful when you have no shell access and the database is small. The limits appear quickly: a large &lt;code&gt;wp_postmeta&lt;/code&gt; table times out mid-run, the browser gives you no per-table report, and a half-finished replace leaves you guessing which tables were touched. Good for a 20-page brochure site; poor for anything with a builder installed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Route 2: a blanket output buffer that rewrites the final HTML
&lt;/h3&gt;

&lt;p&gt;The tempting one-liner is &lt;code&gt;ob_start()&lt;/code&gt; plus a &lt;code&gt;str_replace()&lt;/code&gt; over the finished page. It hides the symptom and creates new problems: full-page caches store the rewritten HTML while REST responses, feeds and XML sitemaps bypass it; &lt;code&gt;Content-Length&lt;/code&gt; and ETag calculations can go stale; and, most damaging, a block editor or builder that posts its rendered markup back to the server will happily save the rewritten version, or fight your buffer on every autosave. Treat this as a debugging experiment, never a fix.&lt;/p&gt;

&lt;h3&gt;
  
  
  Route 3: log with CSP Report-Only, then replace with WP-CLI
&lt;/h3&gt;

&lt;p&gt;This is the route implemented below. You add a header that reports violations without blocking anything, collect a precise inventory of offending URLs, then repair the database once with a tool that understands serialised arrays. Residual hardcoded strings in theme CSS and builder data get a narrow render-time filter, and proxy setups get an explicit protocol fix. It is more steps, but every step is reversible and observable, which is what you want on a live site.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Log every blocked request with a Report-Only policy
&lt;/h2&gt;

&lt;p&gt;A report-only policy sends the browser's violation reports to an endpoint while letting the page load normally. Register a small REST route to receive them and log the blocked URI with the page it appeared on. Drop this in &lt;code&gt;wp-content/mu-plugins/wpth-csp-report.php&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Plugin Name: WPTH Mixed Content Report Logger
 * Description: Reports http:// subresources without blocking them.
 */&lt;/span&gt;

&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'send_headers'&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;is_admin&lt;/span&gt;&lt;span class="p"&gt;(&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_doing_ajax&lt;/span&gt;&lt;span class="p"&gt;(&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_doing_cron&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$policy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"default-src https: data: blob: 'unsafe-inline' 'unsafe-eval'; "&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'report-uri /wp-json/wpth/v1/csp-report'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Content-Security-Policy-Report-Only: '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$policy&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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'rest_api_init'&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="nf"&gt;register_rest_route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'wpth/v1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/csp-report'&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;'methods'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'POST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'permission_callback'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'__return_true'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'callback'&lt;/span&gt;            &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nc"&gt;WP_REST_Request&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Browsers post reports as application/csp-report, which get_json_params() does not parse.&lt;/span&gt;
            &lt;span class="nv"&gt;$payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;json_decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_body&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="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nv"&gt;$report&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$payload&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'csp-report'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$payload&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'csp-report'&lt;/span&gt;&lt;span class="p"&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="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="o"&gt;!&lt;/span&gt; &lt;span class="nb"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'blocked-uri'&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="nf"&gt;error_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="s1"&gt;'[wpth-csp] %s on %s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nf"&gt;sanitize_text_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'blocked-uri'&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="nf"&gt;esc_url_raw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'document-uri'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'document-uri'&lt;/span&gt;&lt;span class="p"&gt;]&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="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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;WP_REST_Response&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;204&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;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 handler reads the raw request body on purpose. Browsers post these reports as &lt;code&gt;application/csp-report&lt;/code&gt;, which WordPress does not treat as JSON, so &lt;code&gt;get_json_params()&lt;/code&gt; returns &lt;code&gt;null&lt;/code&gt; and nothing would ever be logged.&lt;/p&gt;

&lt;p&gt;Why this beats reading the Console by hand: a real site has dozens of templates, and one visit per page rarely covers logged-in states, archive pages or checkout. The reports arrive while you browse normally. Note that &lt;code&gt;'unsafe-inline'&lt;/code&gt; and &lt;code&gt;'unsafe-eval'&lt;/code&gt; are deliberate: this policy exists to flag http:// subresources, not to audit inline scripts, so keep it permissive and delete the mu-plugin once you are done.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If your site lives in a subdirectory, adjust the &lt;code&gt;report-uri&lt;/code&gt; path to &lt;code&gt;/subdir/wp-json/wpth/v1/csp-report&lt;/code&gt;, or the endpoint will 404 silently.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Step 2: Read the reports and separate your own URLs from third parties
&lt;/h2&gt;

&lt;p&gt;Tail the log while you click through the pages that show the warning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tail -f wp-content/debug.log &lt;span class="o"&gt;|&lt;/span&gt; grep wpth-csp
&lt;span class="c"&gt;# or, without WP_DEBUG_LOG:&lt;/span&gt;
tail -f /var/log/nginx/error.log &lt;span class="o"&gt;|&lt;/span&gt; grep wpth-csp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sort what you see into three buckets. Your own host (&lt;code&gt;http://example.com/wp-content/...&lt;/code&gt;) belongs in the database replace below. Third-party hosts that only offer http:// (an old font CDN, an embedded video, a tracking pixel) must be re-embedded over https:// or removed; no search-replace will help. And a handful of &lt;code&gt;blocked-uri&lt;/code&gt; values will be &lt;code&gt;inline&lt;/code&gt; or &lt;code&gt;eval&lt;/code&gt;, which are policy noise you can ignore.&lt;/p&gt;

&lt;p&gt;The logger's entries after loading one page that still references http:// URLs (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ grep wpth-csp wp-content/debug.log
[11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-content/uploads/2019/04/team.jpg on http://localhost/?pagename=about-us
[11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-content/themes/twentytwentyfive/assets/fonts/manrope/Manrope-VariableFont_wght.woff2 on http://localhost/?pagename=about-us
[11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-content/themes/twentytwentyfive/assets/fonts/fira-code/FiraCode-VariableFont_wght.woff2 on http://localhost/?pagename=about-us
[11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-includes/js/dist/script-modules/interactivity/index.min.js?ver=efaa5193bbad9c60ffd1 on http://localhost/?pagename=about-us
[11-Nov-2026 13:38:52 UTC] [wpth-csp] http://fonts.example-cdn.net/pixel.gif on http://localhost/?pagename=about-us
[11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-includes/js/dist/script-modules/block-library/navigation/view.min.js?ver=1bf28ded04f9f188bdcb on http://localhost/?pagename=about-us
[11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/favicon.ico on http://localhost/?pagename=about-us
[11-Nov-2026 13:38:52 UTC] [wpth-csp] http://localhost/wp-includes/js/wp-emoji-release.min.js?ver=7.1.3 on http://localhost/?pagename=about-us
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Replace the URLs in the database with a serialisation-aware WP-CLI run
&lt;/h2&gt;

&lt;p&gt;Page builders store their layout as a serialised PHP array. Traversing that array naively corrupts it, because a serialised string records its own byte length: change &lt;code&gt;http&lt;/code&gt; to &lt;code&gt;https&lt;/code&gt; and every nested string's length declaration becomes wrong, which is why broken widgets appear after a bad replace. &lt;code&gt;wp search-replace&lt;/code&gt; handles this properly: it unserialises, walks the structure, replaces, and re-serialises with correct lengths.&lt;/p&gt;

&lt;p&gt;Take a backup first, then dry-run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp db &lt;span class="kd"&gt;export&lt;/span&gt; backup-before-https.sql

&lt;span class="c"&gt;# 1. Inventory only — nothing is written.&lt;/span&gt;
wp search-replace &lt;span class="s1"&gt;'http://example.com'&lt;/span&gt; &lt;span class="s1"&gt;'https://example.com'&lt;/span&gt; \
  --all-tables-with-prefix \
  --precise \
  --dry-run \
  --report-changed-only
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read the per-table counts before continuing. If a builder table or a custom plugin table sits outside your prefix, it will not appear: run it separately. Then commit the change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp search-replace &lt;span class="s1"&gt;'http://example.com'&lt;/span&gt; &lt;span class="s1"&gt;'https://example.com'&lt;/span&gt; \
  --all-tables-with-prefix \
  --precise \
  --recurse-objects \
  --skip-columns=guid \
  --report-changed-only \
  --log

&lt;span class="c"&gt;# Tables that ignore the site prefix:&lt;/span&gt;
wp search-replace &lt;span class="s1"&gt;'http://example.com'&lt;/span&gt; &lt;span class="s1"&gt;'https://example.com'&lt;/span&gt; custom_builder_data \
  --precise --log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The flags matter. &lt;code&gt;--precise&lt;/code&gt; forces a PHP-side replace per row (slower, but it validates serialised data instead of doing a raw SQL string swap). &lt;code&gt;--recurse-objects&lt;/code&gt; descends into nested arrays and objects. &lt;code&gt;--skip-columns=guid&lt;/code&gt; leaves post GUIDs alone: changing them re-identifies every post to feed readers and can duplicate entries in some aggregators. Finally, search for protocol-relative leftovers: &lt;code&gt;//example.com&lt;/code&gt; inherits the page protocol, so it is usually safe, but a hardcoded &lt;code&gt;http://&lt;/code&gt; hidden inside base64 or JSON-escaped meta (&lt;code&gt;http:\/\/example.com&lt;/code&gt;) will not match the plain pattern. Run one more pass for the escaped form if the reports persist.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Catch http:// URLs baked into theme CSS and builder JSON
&lt;/h2&gt;

&lt;p&gt;The database is only half the surface. A stylesheet fetched from disk cannot be filtered by PHP, so grep the theme and child theme first and fix those files by hand: ideally by switching to relative paths or &lt;code&gt;home_url()&lt;/code&gt; for assets generated in PHP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;grep -rn &lt;span class="s2"&gt;"http://example.com"&lt;/span&gt; wp-content/themes/my-theme \
  --include=&lt;span class="s2"&gt;"*.css"&lt;/span&gt; --include=&lt;span class="s2"&gt;"*.js"&lt;/span&gt; --include=&lt;span class="s2"&gt;"*.json"&lt;/span&gt; --include=&lt;span class="s2"&gt;"*.php"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For everything that &lt;em&gt;is&lt;/em&gt; generated at render time (Customiser CSS, shortcode output, widget text, builder markup stored in postmeta) a narrow filter is a defensible stopgap while you clean the source data. It targets your own host only, and handles the JSON-escaped slash form builders produce:&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Rewrites this site's own http:// URLs at render time,
 * including JSON-escaped slashes used by page builders.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_upgrade_own_host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$value&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="o"&gt;!&lt;/span&gt; &lt;span class="nf"&gt;is_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$value&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="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_parse_url&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;home_url&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="no"&gt;PHP_URL_HOST&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nv"&gt;$needles&lt;/span&gt; &lt;span class="o"&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;'http://'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'http:\\/\\/'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$host&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;$replacements&lt;/span&gt; &lt;span class="o"&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;'https://'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'https:\\/\\/'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$host&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="nf"&gt;str_replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$needles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$replacements&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$value&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="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'the_content'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_upgrade_own_host'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;99&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'the_excerpt'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_upgrade_own_host'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;99&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'widget_text_content'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_upgrade_own_host'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;99&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'wp_get_custom_css'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_upgrade_own_host'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;99&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;Keep it on a hook layer, never on &lt;code&gt;ob_start()&lt;/code&gt;. After the database replace, regenerate each builder's compiled assets from its own admin screen: Elementor's &lt;em&gt;Regenerate CSS &amp;amp; Data&lt;/em&gt;, Divi's static CSS cache, WPBakery's shortcode cache: otherwise an old compiled stylesheet can keep serving http:// font URLs even though the database is clean.&lt;/p&gt;

&lt;h2&gt;
  
  
  Behind a proxy or CDN, is_ssl() lies and keeps the bug alive
&lt;/h2&gt;

&lt;p&gt;If TLS terminates at Cloudflare, an AWS load balancer or an nginx reverse proxy, PHP sees a plain HTTP connection to the origin. &lt;code&gt;is_ssl()&lt;/code&gt; returns false, and every plugin that builds URLs conditionally (many form, gallery and page-builder modules do) keeps emitting http://. Tell WordPress to trust the forwarded protocol, but only when your proxy is the thing setting that header; trusting it unconditionally lets a client spoof https:&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="c1"&gt;// wp-config.php — trust the proxy's forwarded protocol header.&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'HTTP_X_FORWARDED_PROTO'&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;amp;&amp;amp;&lt;/span&gt; &lt;span class="s1"&gt;'https'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'HTTP_X_FORWARDED_PROTO'&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;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'HTTPS'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'on'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'FORCE_SSL_ADMIN'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&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;Cloudflare's "Automatic HTTPS Rewrites" can clean up links inside HTML, but it cannot rewrite URLs constructed by JavaScript or stored in JSON, and it masks the underlying problem during future migrations. Leave it off while you diagnose, and rely on it afterwards only as belt-and-braces. Also check &lt;code&gt;WP_HOME&lt;/code&gt;/&lt;code&gt;WP_SITEURL&lt;/code&gt; in &lt;code&gt;wp-config.php&lt;/code&gt;: a stale http:// constant overrides the database and silently regenerates insecure links on every request.&lt;/p&gt;

&lt;p&gt;My tip · Md. Zubaer Ahammed&lt;/p&gt;

&lt;p&gt;Run the search-replace with &lt;code&gt;--dry-run&lt;/code&gt; first and read the per-table counts, and export the database before the real run. It is the one step in this guide you cannot undo without a backup.&lt;/p&gt;

&lt;h2&gt;
  
  
  A short verification pass that proves the fix is complete
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Hard-reload each affected template with the browser cache disabled, then filter the Network tab by &lt;code&gt;http://&lt;/code&gt;: the list should be empty.&lt;/li&gt;
&lt;li&gt;View source and search for &lt;code&gt;http://&lt;/code&gt;. &lt;code&gt;http://schema.org&lt;/code&gt; and &lt;code&gt;http://www.w3.org&lt;/code&gt; namespaces are harmless; anything else is suspect.&lt;/li&gt;
&lt;li&gt;Fetch &lt;code&gt;/wp-json/wp/v2/posts?per_page=1&lt;/code&gt; and &lt;code&gt;/feed/&lt;/code&gt; and search both for http://: REST and RSS bypass most page-level fixes.&lt;/li&gt;
&lt;li&gt;Open each builder's edit screen as an administrator; builder canvases render outside the front-end theme and expose residual http:// meta.&lt;/li&gt;
&lt;li&gt;Remove the mu-plugin reporter, purge page cache, CDN cache and object cache, then repeat step 1.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the mixed content appeared after a domain change rather than a switch to SSL, the same search-replace rules apply, and &lt;a href="https://wptutshub.com/wordpress-replace-old-url-domain-change/" rel="noopener noreferrer"&gt;replacing old URLs after a WordPress domain change&lt;/a&gt; covers the serialised-data traps in more detail.&lt;/p&gt;

&lt;p&gt;Once the reports are quiet, a permanent enforced policy of &lt;code&gt;upgrade-insecure-requests&lt;/code&gt; is a sensible next layer: it tells browsers to fetch any remaining http:// subresource over https:// automatically, catching the URL a content editor pastes next month before it ever breaks the padlock. Add it alongside your existing security headers, test on staging first, and keep the original report-only file in version control so you can re-enable logging the moment the warning returns.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/fix-wordpress-mixed-content-error/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>security</category>
      <category>php</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Fix WordPress Emails Not Sending</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Fri, 20 Nov 2026 16:00:33 +0000</pubDate>
      <link>https://dev.to/zubaer/fix-wordpress-emails-not-sending-d52</link>
      <guid>https://dev.to/zubaer/fix-wordpress-emails-not-sending-d52</guid>
      <description>&lt;p&gt;When WordPress emails are not sending, the site rarely tells you why. &lt;code&gt;wp_mail()&lt;/code&gt; returns a boolean, PHP hands the message to whatever local mail binary happens to exist, and the reason for the failure disappears somewhere between the two. This walkthrough compares the three realistic ways to get mail out of WordPress, then implements the one that leaves a trail: an authenticated SMTP relay, a failure logger that survives plugin deactivation, and DNS records that prove the message is allowed to claim your domain.&lt;/p&gt;

&lt;p&gt;You need shell access with WP-CLI, an SMTP relay account, and the ability to edit DNS records for the sending domain. The logging and bisecting steps work without the last two.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a true return from wp_mail() proves almost nothing about delivery
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;wp_mail()&lt;/code&gt; lives in &lt;code&gt;wp-includes/pluggable.php&lt;/code&gt;, which means any plugin can replace it before core loads. The core version builds a &lt;code&gt;PHPMailer&lt;/code&gt; instance and, unless something changes the mailer, leaves &lt;code&gt;$phpmailer-&amp;gt;Mailer&lt;/code&gt; set to &lt;code&gt;mail&lt;/code&gt;. That hands the message to PHP's &lt;code&gt;mail()&lt;/code&gt;, which hands it to a local sendmail-compatible binary.&lt;/p&gt;

&lt;p&gt;Two things follow. On a container or a host with no MTA, the call fails and you get &lt;code&gt;false&lt;/code&gt;, but only if you are looking. On a host with a permissive MTA, the call returns &lt;code&gt;true&lt;/code&gt; and the message is still dropped by the recipient because it carried no authentication, no aligned SPF record and a &lt;code&gt;From&lt;/code&gt; address the receiving server distrusts. The &lt;a href="https://developer.wordpress.org/reference/functions/wp_mail/" rel="noopener noreferrer"&gt;wp_mail() reference&lt;/a&gt; is explicit that the return value means "accepted by the mailer", not "delivered".&lt;/p&gt;

&lt;h2&gt;
  
  
  Three routes out of WordPress, and the one worth wiring up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Local MTA / PHP mail().&lt;/strong&gt; Zero configuration, and occasionally fine on a managed shared host that monitors its own queue. It has no authentication, no TLS, no delivery feedback, and no way to tell you why a message vanished. Fits only when the host provides and monitors the MTA and you control the domain's DNS.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authenticated SMTP relay through phpmailer_init.&lt;/strong&gt; You keep core's &lt;code&gt;wp_mail()&lt;/code&gt; API, so every plugin, including WooCommerce order emails, keeps working unchanged. The relay returns real SMTP codes (535 authentication failed, 550 sender rejected, TLS handshake errors) which the failure logger can capture. Fits almost every site that needs mail to arrive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Transactional HTTP API.&lt;/strong&gt; Replaces SMTP with a provider's REST endpoint, usually via a plugin that hooks &lt;code&gt;pre_wp_mail&lt;/code&gt;. Best deliverability and webhook-based bounce handling, at the cost of a provider SDK, per-message pricing and a hard dependency you carry through every migration. Fits high-volume stores and sites where a missing password reset has a direct financial cost.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rest of this article implements the middle option, because it fixes delivery without changing the API your plugins already call, and it produces error strings you can act on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Log wp_mail failures before you change a single setting
&lt;/h2&gt;

&lt;p&gt;Change the configuration first and you destroy the evidence: the exception message, the recipient and the timestamp are exactly what tells you whether the problem is authentication, DNS or a plugin. Install this as a must-use plugin so it loads before regular plugins and stays active while you deactivate everything during conflict testing.&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Plugin Name: WP Tuts Hub Mail Logger
 * Description: Records wp_mail() failures to a log file and shows the last one to administrators.
 */&lt;/span&gt;

&lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'ABSPATH'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_TUTS_HUB_MAIL_LOG'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wp-tuts-hub-mail-errors.log'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wp_tuts_hub_mail_log_path&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="no"&gt;WP_CONTENT_DIR&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="no"&gt;WP_TUTS_HUB_MAIL_LOG&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'wp_mail_failed'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wp_tuts_hub_log_mail_failure'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wp_tuts_hub_log_mail_failure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$error&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="o"&gt;!&lt;/span&gt; &lt;span class="nf"&gt;is_wp_error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$error&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$data&lt;/span&gt;  &lt;span class="o"&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="nv"&gt;$error&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_error_data&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;$entry&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"[%s] %s | to: %s | subject: %s\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nf"&gt;gmdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'c'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nv"&gt;$error&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_error_message&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="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'to'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&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="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="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'to'&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="s1"&gt;'unknown'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'subject'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'subject'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'unknown'&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;error_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$entry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;wp_tuts_hub_mail_log_path&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="nf"&gt;update_option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'wp_tuts_hub_last_mail_error'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$entry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'admin_notices'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wp_tuts_hub_mail_error_notice'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wp_tuts_hub_mail_error_notice&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;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;current_user_can&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'manage_options'&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$last&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;get_option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'wp_tuts_hub_last_mail_error'&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="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$last&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'&amp;lt;div class="notice notice-error"&amp;gt;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;%s&amp;lt;/strong&amp;gt; %s&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nf"&gt;esc_html__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Mail delivery error (wp_mail_failed):'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wp-tuts-hub'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$last&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 &lt;a href="https://developer.wordpress.org/reference/hooks/wp_mail_failed/" rel="noopener noreferrer"&gt;wp_mail_failed&lt;/a&gt; action fires with a &lt;code&gt;WP_Error&lt;/code&gt; whose data array carries &lt;code&gt;to&lt;/code&gt;, &lt;code&gt;subject&lt;/code&gt;, &lt;code&gt;headers&lt;/code&gt;, &lt;code&gt;attachments&lt;/code&gt; and &lt;code&gt;phpmailer_exception_code&lt;/code&gt;. Writing that to &lt;code&gt;wp-content/wp-tuts-hub-mail-errors.log&lt;/code&gt; keeps the record next to the site instead of in a PHP error log you may not have access to. The dashboard notice exists so a non-technical administrator can report the exact error instead of saying "email is broken".&lt;/p&gt;

&lt;p&gt;Two housekeeping notes: the log file sits inside &lt;code&gt;wp-content&lt;/code&gt;, so exclude it from any public backup or sync, and rotate it by deleting it once you have read it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reproduce the failure from the command line with WP-CLI
&lt;/h2&gt;

&lt;p&gt;Triggering mail through the browser (a password reset, a WooCommerce order) is slow and hides the return value. &lt;a href="https://developer.wordpress.org/cli/commands/eval/" rel="noopener noreferrer"&gt;WP-CLI's eval command&lt;/a&gt; gives you the boolean and the log entry in one repeatable step.&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="c"&gt;# 1. Does wp_mail() reach PHPMailer at all? Prints true or false.&lt;/span&gt;
wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'var_dump( wp_mail( "you@example.com", "WP Tuts Hub test", "Plain text body" ) );'&lt;/span&gt;

&lt;span class="c"&gt;# 2. Force a failure PHPMailer cannot accept, so the logger has something to record.&lt;/span&gt;
wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'var_dump( wp_mail( "not-an-email", "WP Tuts Hub failure test", "Body" ) );'&lt;/span&gt;

&lt;span class="c"&gt;# 3. Read what the logger captured.&lt;/span&gt;
wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'echo file_get_contents( WP_CONTENT_DIR . "/wp-tuts-hub-mail-errors.log" );'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The three commands on a site with no local mail server, and what the logger recorded (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ wp eval 'var_dump( wp_mail( "you@example.com", "WP Tuts Hub test", "Plain text body" ) );'
sh: 1: /usr/sbin/sendmail: not found
bool(false)

$ wp eval 'var_dump( wp_mail( "not-an-email", "WP Tuts Hub failure test", "Body" ) );'
bool(false)

$ wp eval 'echo file_get_contents( WP_CONTENT_DIR . "/wp-tuts-hub-mail-errors.log" );'
[2026-11-11T13:38:15+00:00] Could not instantiate mail function. | to: you@example.com | subject: WP Tuts Hub test
[2026-11-11T13:38:15+00:00] You must provide at least one recipient email address. | to: not-an-email | subject: WP Tuts Hub failure test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second command deliberately passes an address PHPMailer rejects, which guarantees a &lt;code&gt;wp_mail_failed&lt;/code&gt; event even on a host where real mail would otherwise be accepted. The log line records the exception message, the recipient and the subject, so you can tell a rejected address apart from a refused connection.&lt;/p&gt;

&lt;p&gt;The same failure is visible without a terminal: the mu-plugin prints the last recorded error as a dashboard notice for anyone with &lt;code&gt;manage_options&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The dashboard notice the mu-plugin shows after a failed wp_mail() call (test site: WordPress 7.1.3, PHP 8.2)&lt;/p&gt;

&lt;h2&gt;
  
  
  Isolate the plugin that is swallowing your mail
&lt;/h2&gt;

&lt;p&gt;If the logger stays silent while mail still disappears, the message is being stopped before PHPMailer runs. The usual culprit is the &lt;code&gt;pre_wp_mail&lt;/code&gt; filter: return anything other than &lt;code&gt;null&lt;/code&gt; from it and &lt;code&gt;wp_mail()&lt;/code&gt; short-circuits, no exception is thrown, and no failure hook fires. A plugin that declares its own &lt;code&gt;wp_mail()&lt;/code&gt; has the same effect.&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="c"&gt;# What is actually active?&lt;/span&gt;
wp plugin list --status=active --field=name

&lt;span class="c"&gt;# Baseline with every regular plugin off. The mu-plugin logger stays loaded.&lt;/span&gt;
wp plugin deactivate --all
wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'var_dump( wp_mail( "you@example.com", "Baseline", "Body" ) );'&lt;/span&gt;

&lt;span class="c"&gt;# Switch plugins back on in halves and re-run the same test.&lt;/span&gt;
wp plugin activate woocommerce
wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'var_dump( wp_mail( "you@example.com", "After WooCommerce", "Body" ) );'&lt;/span&gt;

&lt;span class="c"&gt;# Is anything short-circuiting wp_mail() before PHPMailer runs?&lt;/span&gt;
wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'global $wp_filter; var_dump( isset( $wp_filter["pre_wp_mail"] ) );'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bisecting in halves matters more than it sounds: deactivating everything proves the problem is plugin-related, but reactivating one at a time on a site with thirty plugins wastes an afternoon. The &lt;code&gt;$wp_filter&lt;/code&gt; check at the end tells you whether anything is registered on &lt;code&gt;pre_wp_mail&lt;/code&gt; at all: if the output is &lt;code&gt;true&lt;/code&gt;, read those callbacks before you touch SMTP settings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Point PHPMailer at an authenticated relay with phpmailer_init
&lt;/h2&gt;

&lt;p&gt;Credentials belong in &lt;code&gt;wp-config.php&lt;/code&gt; or the environment, never in the database where a plugin export or a staging clone will copy them. Define the constants above the "That's all, stop editing" line, because anything below &lt;code&gt;wp-settings.php&lt;/code&gt; is loaded too late to be used.&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;// wp-config.php, above the "stop editing" line.&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_TUTS_SMTP_HOST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'smtp.example-relay.com'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_TUTS_SMTP_PORT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;587&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_TUTS_SMTP_USER'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'SMTP_USER'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_TUTS_SMTP_PASS'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'SMTP_PASS'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_TUTS_SMTP_FROM'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'no-reply@example.com'&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;Then append the mailer configuration to the same mu-plugin. The &lt;a href="https://developer.wordpress.org/reference/hooks/phpmailer_init/" rel="noopener noreferrer"&gt;phpmailer_init&lt;/a&gt; action receives the live &lt;code&gt;PHPMailer&lt;/code&gt; object just before &lt;code&gt;send()&lt;/code&gt;, which is the last safe point to change the transport.&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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'phpmailer_init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wp_tuts_hub_configure_smtp'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wp_tuts_hub_configure_smtp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$phpmailer&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="o"&gt;!&lt;/span&gt; &lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_TUTS_SMTP_HOST'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="no"&gt;WP_TUTS_SMTP_HOST&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;isSMTP&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;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;WP_TUTS_SMTP_HOST&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Port&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="no"&gt;WP_TUTS_SMTP_PORT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;SMTPAuth&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Username&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;WP_TUTS_SMTP_USER&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Password&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;WP_TUTS_SMTP_PASS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;SMTPSecure&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PHPMailer&lt;/span&gt;\&lt;span class="nc"&gt;PHPMailer&lt;/span&gt;\&lt;span class="nc"&gt;PHPMailer&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ENCRYPTION_STARTTLS&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;SMTPAutoTLS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// The envelope sender decides which domain SPF is checked against.&lt;/span&gt;
    &lt;span class="nv"&gt;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Sender&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;WP_TUTS_SMTP_FROM&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// $auto = false: do not throw if a plugin already set a From address.&lt;/span&gt;
    &lt;span class="nv"&gt;$phpmailer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;setFrom&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="no"&gt;WP_TUTS_SMTP_FROM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;get_bloginfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&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;Each line earns its place. &lt;code&gt;isSMTP()&lt;/code&gt; overrides the default &lt;code&gt;mail&lt;/code&gt; transport. &lt;code&gt;ENCRYPTION_STARTTLS&lt;/code&gt; on port 587 upgrades a plain connection; use &lt;code&gt;ENCRYPTION_SMTPS&lt;/code&gt; on port 465 instead, not both. &lt;code&gt;Sender&lt;/code&gt; sets the envelope sender, which is the address SPF is checked against: leave it unset and the relay may use its own bounce domain, breaking DMARC alignment. Passing &lt;code&gt;false&lt;/code&gt; as the third argument to &lt;code&gt;setFrom()&lt;/code&gt; stops PHPMailer throwing when a plugin has already set a &lt;code&gt;From&lt;/code&gt; header, which is common with contact form plugins.&lt;/p&gt;

&lt;p&gt;Never set the From address to a free mailbox you do not own, such as a Gmail address: Gmail publishes &lt;code&gt;p=reject&lt;/code&gt; in its DMARC record, so a relay sending on its behalf is rejected outright. Verify the new path with &lt;code&gt;wp eval 'var_dump( wp_mail( "you@example.com", "SMTP relay test", "Body" ) );'&lt;/code&gt; and read the log if it returns false.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check SPF, DKIM and DMARC against the domain you actually send from
&lt;/h2&gt;

&lt;p&gt;A relay accepting the message is only half the job; the receiving server still scores it. SPF authorises the relay's IP addresses for the envelope domain, DKIM signs the message with a key published under your domain, and DMARC requires at least one of them to align with the &lt;code&gt;From&lt;/code&gt; header. Query the records from the server that sends the mail, not from your laptop.&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="c"&gt;# SPF: is the relay listed as an authorised sender for the envelope domain?&lt;/span&gt;
dig +short TXT example.com &lt;span class="o"&gt;|&lt;/span&gt; tr -d &lt;span class="s1"&gt;'"'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; grep -i &lt;span class="s2"&gt;"v=spf1"&lt;/span&gt;

&lt;span class="c"&gt;# DKIM: the selector is provider-specific (Postmark pm, SendGrid s1, Mailgun smtp).&lt;/span&gt;
dig +short TXT pm._domainkey.example.com

&lt;span class="c"&gt;# DMARC: start at p=none to collect reports, then move to quarantine.&lt;/span&gt;
dig +short TXT _dmarc.example.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alignment is where most setups fail. If the relay rewrites the envelope sender to its own bounce domain, SPF passes for the relay but no longer aligns with your &lt;code&gt;From&lt;/code&gt; domain, so DMARC depends entirely on DKIM being signed with &lt;code&gt;d=example.com&lt;/code&gt;. Most providers offer a custom Return-Path CNAME for exactly this reason; configure it so both mechanisms align. Start DMARC at &lt;code&gt;p=none&lt;/code&gt; with a reporting address, read the aggregate reports for a week, then tighten to &lt;code&gt;quarantine&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The final proof is a real message: send one to a Gmail account, open "Show original", and look for &lt;code&gt;spf=pass&lt;/code&gt;, &lt;code&gt;dkim=pass&lt;/code&gt; and &lt;code&gt;dmarc=pass&lt;/code&gt; in the &lt;code&gt;Authentication-Results&lt;/code&gt; header. A pass there is worth more than any plugin's green tick.&lt;/p&gt;

&lt;h2&gt;
  
  
  When wp_mail_failed never fires and mail still disappears
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Something replaced wp_mail().&lt;/strong&gt; Confirm the loaded function comes from core with &lt;code&gt;wp eval 'echo ( new ReflectionFunction( "wp_mail" ) )-&amp;gt;getFileName();'&lt;/code&gt;. If the path is not &lt;code&gt;wp-includes/pluggable.php&lt;/code&gt;, a plugin owns the function and none of core's hooks run.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Outbound ports are blocked.&lt;/strong&gt; A log entry reading "SMTP connect() failed" or a timeout means the host blocks 587 and 465. Ask for the ports to be opened, or use the provider's alternative port such as 2525.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The message was sent and filtered.&lt;/strong&gt; A silent logger plus a &lt;code&gt;true&lt;/code&gt; return means the relay accepted it. Check the recipient's spam folder and the &lt;code&gt;Authentication-Results&lt;/code&gt; header before changing any code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The From address is rejected.&lt;/strong&gt; A 550 "sender address rejected" is a policy decision at the relay: the domain in &lt;code&gt;WP_TUTS_SMTP_FROM&lt;/code&gt; must be verified in the provider's dashboard.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constants defined too late.&lt;/strong&gt; If &lt;code&gt;WP_TUTS_SMTP_HOST&lt;/code&gt; is defined below &lt;code&gt;require_once ABSPATH . 'wp-settings.php';&lt;/code&gt;, the guard in the hook returns early and the site silently keeps using PHP mail().&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Keep the logger running for the first hundred messages
&lt;/h2&gt;

&lt;p&gt;Mail sent from scheduled events, such as digests and reminders, also depends on WP-Cron running on time. If those emails arrive late or not at all while password resets work, &lt;a href="https://wptutshub.com/using-cron-job-wordpress-schedule-events-wp-cron-part-2/" rel="noopener noreferrer"&gt;debugging WP-Cron single events&lt;/a&gt; is the next place to look.&lt;/p&gt;

&lt;p&gt;The obvious follow-up is to make the log two-sided: hook &lt;code&gt;wp_mail_succeeded&lt;/code&gt; to write a one-line success record with the recipient and subject, then add a weekly cron event that emails you a count of failures against successes. Two weeks of that data tells you whether a relay or DNS change actually fixed delivery, rather than waiting for a customer to report a password reset that never arrived.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/fix-wordpress-emails-not-sending/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Patch PHP for WordPress: November 2026 Security Release</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Thu, 19 Nov 2026 16:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/patch-php-for-wordpress-november-2026-security-release-le9</link>
      <guid>https://dev.to/zubaer/patch-php-for-wordpress-november-2026-security-release-le9</guid>
      <description>&lt;p&gt;The PHP security release of 19 November 2026 fixes 18 vulnerabilities in PHP 8.5 and 12 to 14 in the older branches. Seven are rated critical (CVSS 4.0 score 9.2): all seven affect PHP 8.5, five affect 8.3 and 8.4, and four affect 8.2. The fixed versions are PHP 8.5.13, 8.4.28, 8.3.37 and 8.2.36. Every WordPress site runs on PHP, so this one lands on your server whether or not you use the features involved.&lt;/p&gt;

&lt;p&gt;The good news first: the PHP security team says the critical issues "require either non-default configuration or uncommon setups", and no exploitation in the wild had been reported when this was written. This guide explains which fixes matter for WordPress, how to check your own server in a few minutes, and how to update and confirm the fix. Every output below is real: from this site's own production server (PHP 8.4.27 on PHP-FPM behind nginx) and from a disposable WordPress 7.1.3 test server on Apache with PHP 8.2.35.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which PHP version do you need?
&lt;/h2&gt;

&lt;p&gt;Update to the fixed release for the branch you are on:&lt;/p&gt;

&lt;p&gt;Your branch&lt;br&gt;
Vulnerable up to&lt;br&gt;
Fixed in&lt;br&gt;
Notes&lt;/p&gt;

&lt;p&gt;PHP 8.5&lt;br&gt;
8.5.12&lt;br&gt;
8.5.13&lt;br&gt;
Gets four fixes the other branches do not need&lt;/p&gt;

&lt;p&gt;PHP 8.4&lt;br&gt;
8.4.27&lt;br&gt;
8.4.28&lt;/p&gt;

&lt;p&gt;PHP 8.3&lt;br&gt;
8.3.36&lt;br&gt;
8.3.37&lt;/p&gt;

&lt;p&gt;PHP 8.2&lt;br&gt;
8.2.35&lt;br&gt;
8.2.36&lt;br&gt;
End of life on 31 December 2026: plan the move to 8.4&lt;/p&gt;

&lt;p&gt;PHP 8.1 and older&lt;br&gt;
Every version&lt;br&gt;
No fix&lt;br&gt;
Unsupported; upgrade the branch&lt;/p&gt;

&lt;p&gt;The full list is in the &lt;a href="https://www.php.net/ChangeLog-8.php" rel="noopener noreferrer"&gt;official PHP 8 changelog&lt;/a&gt;, and each fix links to its advisory on GitHub.&lt;/p&gt;
&lt;h2&gt;
  
  
  The fixes that matter for WordPress
&lt;/h2&gt;
&lt;h3&gt;
  
  
  PHP-FPM request smuggling (CVE-2026-129289, critical)
&lt;/h3&gt;

&lt;p&gt;This is the one to understand first, because most WordPress hosting runs PHP-FPM. When the web server keeps a FastCGI connection to PHP-FPM open and reuses it for the next request, bytes left unread in one request body could be read as a &lt;em&gt;new&lt;/em&gt; request that the web server never sent. According to the &lt;a href="https://github.com/php/php-src/security/advisories/GHSA-qc49-hpvq-g2w6" rel="noopener noreferrer"&gt;advisory&lt;/a&gt;, that forged request can change PHP settings and run attacker-supplied PHP code, with a single unauthenticated request and no memory tricks.&lt;/p&gt;

&lt;p&gt;It needs two things: a front end that reuses backend connections (nginx with &lt;code&gt;fastcgi_keep_conn on&lt;/code&gt;, Apache &lt;code&gt;mod_proxy_fcgi&lt;/code&gt; with &lt;code&gt;enablereuse=on&lt;/code&gt;, some HAProxy setups, and LiteSpeed's LSAPI), and an application path that opens &lt;code&gt;php://input&lt;/code&gt; without reading it to the end. Standard nginx and Apache configurations close the connection after each request and are not affected by the demonstrated attack. Checking which one you have takes one command (see step 2 below).&lt;/p&gt;
&lt;h3&gt;
  
  
  Two session bugs that can lead to code execution (CVE-2026-115560 and CVE-2026-126714, critical)
&lt;/h3&gt;

&lt;p&gt;Both end in PHP unserialising data an attacker influenced. The first involves session upload progress, the same feature behind last month's &lt;a href="https://wptutshub.com/php2shell-critical-rce-protect-wordpress/" rel="noopener noreferrer"&gt;PHP2Shell vulnerability&lt;/a&gt;: when two parts of a server read and write the same session files with different &lt;code&gt;session.serialize_handler&lt;/code&gt; settings, part of an upload key can be decoded as an object. The second affects PHP's default &lt;code&gt;files&lt;/code&gt; session handler, which could leave a half-overwritten session file that decodes differently from either session written into it.&lt;/p&gt;

&lt;p&gt;WordPress core does not use PHP sessions, but plenty of plugins and other applications on the same server do. The proof of concept in the advisory used gadget classes from Guzzle and Monolog, two libraries that many WordPress plugins bundle in their &lt;code&gt;vendor&lt;/code&gt; folders. The fix turns session upload progress off by default in the new releases. If you followed the PHP2Shell advice and switched it off already, you removed the first path months early.&lt;/p&gt;
&lt;h3&gt;
  
  
  Timezone cache use-after-free (CVE-2026-129496, critical)
&lt;/h3&gt;

&lt;p&gt;If PHP writes a warning to a PHP error log file while it starts up (an invalid &lt;code&gt;date.timezone&lt;/code&gt; is the confirmed example), a fresh worker can use freed memory when the first request arrives. A crafted request has crashed FPM workers this way, and code execution was shown in lab conditions. The trigger is specific: a startup warning, PHP's own file-based &lt;code&gt;error_log&lt;/code&gt;, and an early warning in a new worker. A server that starts cleanly does not meet it.&lt;/p&gt;
&lt;h3&gt;
  
  
  PHP-FPM local privilege escalation (CVE-2026-129291, high)
&lt;/h3&gt;

&lt;p&gt;With &lt;code&gt;catch_workers_output&lt;/code&gt; switched on, someone who can already run PHP code in an FPM worker (a vulnerable plugin, for example) could execute commands as the FPM master process, which usually runs as root. The official &lt;code&gt;php:*-fpm&lt;/code&gt; Docker images switch this option on in &lt;code&gt;docker.conf&lt;/code&gt;, and on this site's own container the master process does run as root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ grep -Rn catch_workers_output /usr/local/etc/php-fpm.d/docker.conf
15:catch_workers_output = yes
$ grep Uid /proc/1/status
Uid:    0   0   0   0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That turns "a plugin bug in one site" into "root in the container", so Docker-based WordPress hosts should not leave this one for later.&lt;/p&gt;

&lt;h3&gt;
  
  
  The rest
&lt;/h3&gt;

&lt;p&gt;The remaining fixes cover a PHAR signature bypass, two SOAP bugs, a double free in the new DOM XML serialiser, an XSS in the PHP-FPM status page, mixed-case &lt;code&gt;HTTPS://&lt;/code&gt; URLs that could fall back to plain text, a denial of service through folded HTTP response headers, and a memory bug in &lt;code&gt;php-cgi&lt;/code&gt; during &lt;code&gt;PATH_INFO&lt;/code&gt; handling. PHP 8.3 and later also get a fix for a use-after-free after an interrupted session shutdown, which completes a PHP2Shell patch from last month that turned out to be incomplete. PHP 8.5 alone gets two more critical use-after-free fixes in fatal error backtraces, plus two fixes in its new URI extension.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check your server in five minutes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Which PHP version and settings do you run?
&lt;/h3&gt;

&lt;p&gt;Save this as &lt;code&gt;check-php-nov-2026.php&lt;/code&gt; outside your web root and run it with &lt;code&gt;php check-php-nov-2026.php&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="c1"&gt;// Compare this PHP with the 19 November 2026 security releases and print the settings the advisories mention.&lt;/span&gt;
&lt;span class="nv"&gt;$fixed&lt;/span&gt;  &lt;span class="o"&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;'8.2'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'8.2.36'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'8.3'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'8.3.37'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'8.4'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'8.4.28'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'8.5'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'8.5.13'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$branch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;PHP_MAJOR_VERSION&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="no"&gt;PHP_MINOR_VERSION&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"PHP %s (%s)\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PHP_VERSION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PHP_SAPI&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="o"&gt;!&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$fixed&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$branch&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;echo&lt;/span&gt; &lt;span class="s2"&gt;"Branch $branch got no fix in this release: move to a supported branch.\n"&lt;/span&gt;&lt;span class="p"&gt;;&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="nv"&gt;$patched&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;version_compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="no"&gt;PHP_VERSION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$fixed&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$branch&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'&amp;gt;='&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"Fixed in %s: %s\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$fixed&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$branch&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$patched&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'patched'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'UPDATE NEEDED'&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="kt"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'session.upload_progress.enabled'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'session.serialize_handler'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'session.save_handler'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'log_errors'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'error_log'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'date.timezone'&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;$key&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"%-32s %s\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;var_export&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$key&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&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;On this site's production container, before updating:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PHP 8.4.27 (cli)
Fixed in 8.4.28: UPDATE NEEDED
session.upload_progress.enabled  ''
session.serialize_handler        'php'
session.save_handler             'files'
log_errors                       '1'
error_log                        ''
date.timezone                    'UTC'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And on the Apache test server, which still has PHP's old default of upload progress switched on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PHP 8.2.35 (cli)
Fixed in 8.2.36: UPDATE NEEDED
session.upload_progress.enabled  '1'
session.serialize_handler        'php'
session.save_handler             'files'
log_errors                       ''
error_log                        '/dev/stderr'
date.timezone                    'UTC'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command line can read a different &lt;code&gt;php.ini&lt;/code&gt; from PHP-FPM on some systems (Debian and Ubuntu keep separate &lt;code&gt;cli&lt;/code&gt; and &lt;code&gt;fpm&lt;/code&gt; folders under &lt;code&gt;/etc/php/&lt;/code&gt;). To see what the website itself runs, check Tools → Site Health → Info → Server in wp-admin, which shows the PHP version the web server is using.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Does your web server reuse FastCGI connections?
&lt;/h3&gt;

&lt;p&gt;On nginx, print the full configuration and search it. The first command proves PHP is reached over FastCGI; the second must print nothing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ nginx -T 2&amp;gt;/dev/null | grep -c fastcgi_pass
1
$ nginx -T 2&amp;gt;/dev/null | grep -n fastcgi_keep_conn
$
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No output means &lt;code&gt;fastcgi_keep_conn&lt;/code&gt; is not set, so the smuggling attack has no reused connection to ride on. If it prints a line with &lt;code&gt;on&lt;/code&gt;, remove it (or set it to &lt;code&gt;off&lt;/code&gt;), reload nginx, and update PHP before turning it back on.&lt;/p&gt;

&lt;p&gt;On Apache, search the configuration for connection reuse to PHP-FPM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ grep -Rn enablereuse /etc/apache2/
$ apache2ctl -M 2&amp;gt;/dev/null | grep -E "php_module|proxy_fcgi"
 php_module (shared)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The test server runs PHP inside Apache (&lt;code&gt;php_module&lt;/code&gt;) rather than through PHP-FPM, so the smuggling bug does not apply to it at all, but the session and timezone fixes still do. On RHEL-based systems the configuration lives under &lt;code&gt;/etc/httpd/&lt;/code&gt; instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Is session upload progress switched off?
&lt;/h3&gt;

&lt;p&gt;Look at &lt;code&gt;session.upload_progress.enabled&lt;/code&gt; in the step 1 output. An empty value or &lt;code&gt;'0'&lt;/code&gt; means off. If it says &lt;code&gt;'1'&lt;/code&gt; and nothing on the server shows upload progress bars (WordPress does not), switch it off in the PHP configuration, not with &lt;code&gt;ini_set()&lt;/code&gt;, which is too late:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c1"&gt;; php.ini, or an FPM pool file as php_admin_flag[session.upload_progress.enabled] = off
&lt;/span&gt;&lt;span class="na"&gt;session.upload_progress.enabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you do need the feature, every application and pool that shares the same session folder must use the same &lt;code&gt;session.serialize_handler&lt;/code&gt;. The update does not enforce that across separate configurations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 4: Does PHP start without warnings?
&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;php -v&lt;/code&gt;. Anything printed before the version line (a "PHP Warning" or "PHP Deprecated" about a setting) is a startup diagnostic, the trigger for the timezone bug. Fix the setting it names, then restart PHP-FPM and read the start of its log for the same kind of line.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Is catch_workers_output on?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;grep -Rn &lt;span class="s2"&gt;"^catch_workers_output"&lt;/span&gt; /etc/php/*/fpm/ /usr/local/etc/php-fpm.d/ 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it prints &lt;code&gt;yes&lt;/code&gt;, the privilege escalation fix applies to you. The update is the real fix. Switching the option off loses worker output in the PHP-FPM log, so treat that only as a stopgap.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to update
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Debian or Ubuntu with the Ondřej Surý packages&lt;/strong&gt; (the usual source of current PHP versions): &lt;code&gt;sudo apt update &amp;amp;&amp;amp; sudo apt install --only-upgrade 'php8.4*'&lt;/code&gt;, then &lt;code&gt;sudo systemctl restart php8.4-fpm&lt;/code&gt;. Change &lt;code&gt;8.4&lt;/code&gt; to your branch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Distribution packages&lt;/strong&gt; (Debian's or Ubuntu's own PHP): security fixes are backported without changing the upstream version number, so the checker above can say "UPDATE NEEDED" even after you have patched. Read &lt;code&gt;apt changelog php8.4-fpm&lt;/code&gt; for the CVE numbers instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Docker&lt;/strong&gt;: move the image to the fixed tag, for example &lt;code&gt;FROM php:8.4.28-fpm&lt;/code&gt;, then rebuild with &lt;code&gt;docker compose build --pull&lt;/code&gt; and recreate the container. A rebuild without &lt;code&gt;--pull&lt;/code&gt; can reuse the old cached image. The official images usually reach Docker Hub a day or two after a PHP release, and on 19 November the fixed tags were not there yet. Until they are, use the stopgaps at the end of this guide.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Managed WordPress hosting&lt;/strong&gt;: you usually cannot update PHP yourself. Check the version in Site Health, and if it is still on the old release a few days after 19 November, ask support when they will deploy it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Restart PHP-FPM (or Apache, if PHP runs inside it as &lt;code&gt;mod_php&lt;/code&gt;) after any update, so the master process and every worker run the new binary. Workers that are still running the old version stay vulnerable until they are replaced.&lt;/p&gt;

&lt;h2&gt;
  
  
  Confirm the fix
&lt;/h2&gt;

&lt;p&gt;Run the checker again. On a patched server the second line says &lt;code&gt;patched&lt;/code&gt;. Then load a few pages, log in to wp-admin and check Site Health shows the new version, which confirms the web server picked up the restarted PHP rather than only the command line.&lt;/p&gt;

&lt;h2&gt;
  
  
  If you cannot update today
&lt;/h2&gt;

&lt;p&gt;The advisories list stopgaps that reduce the risk until the update is in place:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep FastCGI connection reuse off (&lt;code&gt;fastcgi_keep_conn&lt;/code&gt; unset in nginx, no &lt;code&gt;enablereuse=on&lt;/code&gt; in Apache).&lt;/li&gt;
&lt;li&gt;Set &lt;code&gt;session.upload_progress.enabled = 0&lt;/code&gt; in the PHP configuration.&lt;/li&gt;
&lt;li&gt;Fix any startup warning, or send PHP errors to syslog instead of a file, then restart PHP.&lt;/li&gt;
&lt;li&gt;Never expose a PHP-FPM port directly to the internet.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these replaces the update. This release follows last month's &lt;a href="https://wptutshub.com/php2shell-critical-rce-protect-wordpress/" rel="noopener noreferrer"&gt;PHP2Shell fixes&lt;/a&gt;, and on PHP 8.3 and later it completes one of them. PHP releases security updates every four weeks, so it pays to have an update routine that takes minutes rather than an afternoon. PHP 8.2 gets its last fixes this year: if your site still runs it, this is a good moment to move to 8.4.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/php-security-release-november-2026-wordpress/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>security</category>
      <category>php</category>
      <category>webdev</category>
    </item>
    <item>
      <title>nginx2root: Patch nginx on Your WordPress Server Now</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Thu, 19 Nov 2026 12:00:34 +0000</pubDate>
      <link>https://dev.to/zubaer/nginx2root-patch-nginx-on-your-wordpress-server-now-4266</link>
      <guid>https://dev.to/zubaer/nginx2root-patch-nginx-on-your-wordpress-server-now-4266</guid>
      <description>&lt;p&gt;&lt;strong&gt;nginx2root&lt;/strong&gt; is the name researchers at Xint gave to five nginx vulnerabilities fixed on 18 November 2026 in &lt;strong&gt;nginx 1.31.9&lt;/strong&gt; (mainline) and &lt;strong&gt;nginx 1.30.7&lt;/strong&gt; (stable). The worst of them lets an unauthenticated attacker run code on your server over HTTP/2, which nearly every HTTPS WordPress site on nginx has switched on. Chained with a separate Linux kernel bug, it goes all the way to root. This guide shows WordPress site owners how to check their nginx version and configuration, patch or mitigate, block the kernel route to root, and prove the fix is live.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Every command output in this guide comes from our own tests: disposable, offline Docker containers built from the official &lt;code&gt;nginx&lt;/code&gt; images (1.30.6, 1.30.7, 1.31.8 and 1.31.9), plus one of our own Ubuntu servers for the kernel check. No exploit code was run.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What nginx2root is
&lt;/h2&gt;

&lt;p&gt;nginx2root covers five memory-safety bugs in nginx. Xint reported them to F5, the company behind nginx, and published its write-up on the day the fixes shipped. Every release up to and including &lt;strong&gt;1.31.8&lt;/strong&gt; is affected where the feature in question is in use. The fixed versions are &lt;strong&gt;1.31.9 or later&lt;/strong&gt; and &lt;strong&gt;1.30.7 or later&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;CVE&lt;br&gt;
Bug&lt;br&gt;
Needs&lt;br&gt;
First affected&lt;/p&gt;

&lt;p&gt;CVE-2026-123007&lt;br&gt;
Memory corruption in HTTP/2 flow control&lt;br&gt;
HTTP/2 enabled&lt;br&gt;
1.9.5 (2015)&lt;/p&gt;

&lt;p&gt;CVE-2026-123633&lt;br&gt;
Use-after-free in HTTP/2&lt;br&gt;
HTTP/2, with requests passed to an upstream while workers run low on &lt;code&gt;worker_connections&lt;/code&gt;&lt;br&gt;
1.19.7&lt;/p&gt;

&lt;p&gt;CVE-2026-123634&lt;br&gt;
Use-after-free in the resolver&lt;br&gt;
&lt;code&gt;resolver&lt;/code&gt; plus a &lt;code&gt;proxy_pass&lt;/code&gt; host built from variables, with an SSI or &lt;code&gt;mirror&lt;/code&gt; subrequest&lt;br&gt;
1.13.4&lt;/p&gt;

&lt;p&gt;CVE-2026-121810&lt;br&gt;
Use-after-free in HTTP/3&lt;br&gt;
HTTP/3 (QUIC), with requests passed to an upstream&lt;br&gt;
1.25.0&lt;/p&gt;

&lt;p&gt;CVE-2026-113425&lt;br&gt;
Use-after-free in the mail proxy&lt;br&gt;
Mail proxy with &lt;code&gt;proxy on&lt;/code&gt; and &lt;code&gt;auth_http&lt;/code&gt;&lt;br&gt;
0.5.15&lt;/p&gt;

&lt;p&gt;F5 scores CVE-2026-123007 at &lt;strong&gt;9.2 Critical&lt;/strong&gt; (CVSS 4.0) in the &lt;a href="https://nvd.nist.gov/vuln/detail/CVE-2026-123007" rel="noopener noreferrer"&gt;NVD entry&lt;/a&gt;. On nginx.org it and the mail proxy bug are rated "Major", and the other three "Medium". The same releases fix five further issues that are not part of nginx2root but are still worth having: an endless loop when reading request bodies over TLS 1.3 (CVE-2026-118899, also rated Major), a buffer overflow with &lt;code&gt;alias&lt;/code&gt; and &lt;code&gt;try_files&lt;/code&gt; (CVE-2026-125283), and three bugs in the &lt;code&gt;stream&lt;/code&gt; module and PROXY protocol handling.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Official reference:&lt;/strong&gt; &lt;a href="https://nginx.org/en/security_advisories.html" rel="noopener noreferrer"&gt;nginx security advisories&lt;/a&gt;, the &lt;a href="https://nginx.org/en/CHANGES" rel="noopener noreferrer"&gt;nginx 1.31.9 changelog&lt;/a&gt; and &lt;a href="https://xint.io/blog/nginx2root-remote-code-execution" rel="noopener noreferrer"&gt;Xint's nginx2root write-up&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  How an nginx bug becomes root
&lt;/h2&gt;

&lt;p&gt;F5's own description of CVE-2026-123007 says the bug overflows a heap buffer and usually crashes the worker, and that attackers can execute code where ASLR (address space layout randomisation) is disabled or can be bypassed. According to The Hacker News, researchers at Wiz bypassed ASLR in their tests, and Xint needed nothing more than a reachable HTTP/2 port. So assume code execution is realistic. That code runs as the nginx &lt;em&gt;worker&lt;/em&gt; process.&lt;/p&gt;

&lt;p&gt;On their own, the nginx bugs stop there. Workers run as an unprivileged user such as &lt;code&gt;www-data&lt;/code&gt; or &lt;code&gt;nginx&lt;/code&gt;, so that is serious but not yet full control. On a WordPress server it can still be enough to read &lt;code&gt;wp-config.php&lt;/code&gt; and its database password, or to plant files in a writable uploads folder.&lt;/p&gt;

&lt;p&gt;The second half of the chain is a use-after-free in the Linux kernel's SCTP networking code, which Aikido says dates back to Linux 4.15. Xint used it to climb from the nginx worker to root on the host, and reports that this works from inside a Docker container too. When the research was published there was no CVE number and no kernel fix for this bug, which is why blocking SCTP matters (see below).&lt;/p&gt;

&lt;p&gt;On release day, 18 November, nobody had reported attacks in the wild and CISA had not added the CVE to its Known Exploited Vulnerabilities catalogue. Proof-of-concept code is already public on GitHub, though its notes say it only demonstrates the attack against a freshly started Docker container on the same machine. With a public write-up and a ten-year-old bug in such a widely used feature, expect that picture to change quickly (source: &lt;a href="https://thehackernews.com/2026/11/10-year-old-nginx-http2-flaw-lets.html" rel="noopener noreferrer"&gt;The Hacker News report on nginx2root&lt;/a&gt;).&lt;/p&gt;
&lt;h2&gt;
  
  
  Which WordPress setups are affected
&lt;/h2&gt;

&lt;p&gt;WordPress has no bug here; the flaws are in the web server in front of PHP. Updating plugins, themes or core does nothing for nginx2root.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTTP/2 on HTTPS (most WordPress sites on nginx).&lt;/strong&gt; A &lt;code&gt;listen 443 ssl http2;&lt;/code&gt; line or &lt;code&gt;http2 on;&lt;/code&gt; exposes you to CVE-2026-123007. CVE-2026-123633 needs requests passed to an upstream as well. nginx sends PHP requests to PHP-FPM through &lt;code&gt;fastcgi_pass&lt;/code&gt;, which uses the same upstream machinery, so treat a standard WordPress server as in scope for both.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reverse proxies and asset proxies.&lt;/strong&gt; A &lt;code&gt;resolver&lt;/code&gt; directive combined with something like &lt;code&gt;proxy_pass http://$backend;&lt;/code&gt; brings in CVE-2026-123634. Plain WordPress configs rarely do this, but CDN proxies, multisite domain mapping and headless front ends sometimes do.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTP/3 (QUIC).&lt;/strong&gt; Only if you enabled &lt;code&gt;listen 443 quic;&lt;/code&gt; or &lt;code&gt;http3 on;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mail proxy.&lt;/strong&gt; Rare on WordPress servers, but some control panels set it up.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your hosting type decides who does the work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Managed WordPress hosting:&lt;/strong&gt; the host patches nginx. Your job is to get confirmation (see "Patch nginx" below).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Server panels such as Laravel Forge:&lt;/strong&gt; Forge warns that its automatic security updates &lt;strong&gt;do not&lt;/strong&gt; update nginx, because nginx comes from a separate repository. Older Forge servers also used a PPA that has since been removed. Follow &lt;a href="https://laravel.com/forge/docs/knowledge-base/nginx-to-root" rel="noopener noreferrer"&gt;Forge's nginx2root guide&lt;/a&gt;, and check whether your own panel works the same way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Your own VPS or Docker stack:&lt;/strong&gt; nobody else will patch it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Behind Cloudflare or another CDN:&lt;/strong&gt; visitors speak HTTP/2 to the CDN, not to you. That only protects you if your origin accepts connections from the CDN alone. If the origin IP answers on 443 from anywhere, an attacker can go straight to nginx.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ubuntu 20.04 and older:&lt;/strong&gt; according to Forge, nginx.org no longer builds packages for these releases, and the newest one available there (1.27.5) is still vulnerable. Ubuntu's own nginx package is fixed for 16.04, 18.04 and 20.04, but only through Ubuntu Pro, which is free for up to five machines. Either way, plan a move to a supported release.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Check your nginx version
&lt;/h2&gt;

&lt;p&gt;Run this over SSH on the server, or inside the web container if you use Docker:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nginx -v
&lt;span class="c"&gt;# Docker: docker exec &amp;lt;web-container&amp;gt; nginx -v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output from the official images we tested, vulnerable first and patched second:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nginx version: nginx/1.31.8
nginx version: nginx/1.31.9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The package version and its maintainer tell you where nginx came from, which decides how you update it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dpkg-query -W -f=&lt;span class="s1"&gt;'${Version}  ${Maintainer}\n'&lt;/span&gt; nginx   &lt;span class="c"&gt;# Debian and Ubuntu&lt;/span&gt;
rpm -q nginx                                          &lt;span class="c"&gt;# RHEL, AlmaLinux, Rocky&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the official images the package comes from nginx.org, and the version moves from &lt;code&gt;1.30.6-1~trixie&lt;/code&gt; to &lt;code&gt;1.30.7-1~trixie&lt;/code&gt; after the fix. If the maintainer line shows &lt;code&gt;NGINX Packaging&lt;/code&gt;, you update from nginx.org. If it shows Ubuntu or Debian, your distribution's security team ships the fix.&lt;/p&gt;

&lt;p&gt;To check many servers quickly, this script compares the running version with the fixed release for its branch. Save it as &lt;code&gt;check-nginx.sh&lt;/code&gt; and run &lt;code&gt;sh check-nginx.sh&lt;/code&gt;.&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="c"&gt;#!/bin/sh&lt;/span&gt;
&lt;span class="c"&gt;# Compare the running nginx version with the nginx2root fixed releases&lt;/span&gt;
&lt;span class="nv"&gt;v&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;nginx -v 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1 &lt;span class="o"&gt;|&lt;/span&gt; sed &lt;span class="s1"&gt;'s#.*nginx/##; s# .*##'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;branch&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$v"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; cut -d. -f1,2&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"$branch"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
  1.31&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;fixed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1.31.9 &lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  1.30&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;fixed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1.30.7 &lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  *&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"nginx $v: branch $branch gets no fix - upgrade to 1.30.7 or 1.31.9"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1 &lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"$(printf '%s\n' "&lt;/span&gt;&lt;span class="nv"&gt;$fixed&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="nv"&gt;$v&lt;/span&gt;&lt;span class="s2"&gt;" | sort -V | head -n1)"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"$fixed"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"nginx $v: patched (needs $fixed or later)"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"nginx $v: VULNERABLE - upgrade to $fixed or later"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Against all four test images it gave the expected verdicts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nginx 1.30.6: VULNERABLE - upgrade to 1.30.7 or later
nginx 1.30.7: patched &lt;span class="o"&gt;(&lt;/span&gt;needs 1.30.7 or later&lt;span class="o"&gt;)&lt;/span&gt;
nginx 1.31.8: VULNERABLE - upgrade to 1.31.9 or later
nginx 1.31.9: patched &lt;span class="o"&gt;(&lt;/span&gt;needs 1.31.9 or later&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Distribution packages keep older version numbers and backport fixes. Aikido lists Ubuntu 24.04 (1.24.0), Ubuntu 22.04 (1.18.0), Debian 12 (1.22.1) and Debian 13 (1.26) as being in the affected range before any backport. On those builds the script will always report "branch gets no fix", so look up the CVEs in your distribution's security tracker and compare the full package version instead.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Ubuntu&lt;/strong&gt; shipped fixes on 19 November in &lt;a href="https://ubuntu.com/security/notices/USN-9159-1" rel="noopener noreferrer"&gt;USN-9159-1&lt;/a&gt;, which covers all five nginx2root CVEs. You are patched once your &lt;code&gt;nginx&lt;/code&gt; package is at least the version below (&lt;code&gt;nginx-core&lt;/code&gt;, &lt;code&gt;nginx-full&lt;/code&gt; and the other variants carry the same version):&lt;/p&gt;

&lt;p&gt;Ubuntu release&lt;br&gt;
Fixed package version&lt;/p&gt;

&lt;p&gt;26.10&lt;br&gt;
1.30.4-7ubuntu1.2&lt;/p&gt;

&lt;p&gt;26.04 LTS&lt;br&gt;
1.28.3-2ubuntu1.13&lt;/p&gt;

&lt;p&gt;24.04 LTS&lt;br&gt;
1.24.0-2ubuntu7.20&lt;/p&gt;

&lt;p&gt;22.04 LTS&lt;br&gt;
1.18.0-6ubuntu14.23&lt;/p&gt;

&lt;p&gt;20.04 LTS&lt;br&gt;
1.18.0-0ubuntu1.7+esm5 (Ubuntu Pro)&lt;/p&gt;

&lt;p&gt;18.04 LTS&lt;br&gt;
1.14.0-0ubuntu1.11+esm6 (Ubuntu Pro)&lt;/p&gt;

&lt;p&gt;16.04 LTS&lt;br&gt;
1.10.3-0ubuntu0.16.04.5+esm11 (Ubuntu Pro)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debian&lt;/strong&gt; was slower. On 19 November the &lt;a href="https://security-tracker.debian.org/tracker/CVE-2026-123007" rel="noopener noreferrer"&gt;Debian security tracker&lt;/a&gt; showed a fix only in unstable (sid, 1.30.6-4). Bookworm, trixie and forky were still listed as vulnerable. If you run Debian's own nginx package, apply the mitigations below now, and either switch to the nginx.org packages or watch the tracker for a security update.&lt;/p&gt;
&lt;h2&gt;
  
  
  Check which nginx2root features your config uses
&lt;/h2&gt;

&lt;p&gt;First see which modules your binary has. The official images include all of them, on both vulnerable and fixed versions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nginx -V 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1 &lt;span class="o"&gt;|&lt;/span&gt; tr &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; grep -E &lt;span class="s1"&gt;'^--with-(http_v2|http_v3|mail|stream)'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;--with-http_v2_module
--with-http_v3_module
--with-mail
--with-mail_ssl_module
--with-stream
--with-stream_realip_module
--with-stream_ssl_module
--with-stream_ssl_preread_module
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A compiled-in module only matters if your configuration switches it on. &lt;code&gt;nginx -T&lt;/code&gt; prints the full effective configuration, every &lt;code&gt;include&lt;/code&gt; included, so search that for the directives each CVE needs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo nginx -T 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;|&lt;/span&gt; grep -nE \
  -e &lt;span class="s1"&gt;'^\s*(http2|http3|resolver|mirror|auth_http|mail|stream)\b'&lt;/span&gt; \
  -e &lt;span class="s1"&gt;'^\s*listen .*(http2|quic)'&lt;/span&gt; \
  -e &lt;span class="s1"&gt;'^\s*(proxy_pass .*\$|fastcgi_pass|ssi on)'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We ran it on nginx 1.31.8 with a typical WordPress server block that also proxies one path to an asset host using a variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;139:    http2 on&lt;span class="o"&gt;;&lt;/span&gt;
143:    resolver 1.1.1.1 &lt;span class="nv"&gt;valid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;300s&lt;span class="o"&gt;;&lt;/span&gt;
150:        fastcgi_pass 127.0.0.1:9000&lt;span class="o"&gt;;&lt;/span&gt;
157:        proxy_pass http://&lt;span class="nv"&gt;$backend&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read it like this. Line 139 together with line 150 means the HTTP/2 bugs apply. Line 143 together with line 157 is the resolver pattern behind CVE-2026-123634. Any &lt;code&gt;mail&lt;/code&gt;, &lt;code&gt;auth_http&lt;/code&gt; or &lt;code&gt;quic&lt;/code&gt; lines you did not expect deserve a closer look before you do anything else.&lt;/p&gt;

&lt;p&gt;Configuration files can mislead, so also ask the server itself whether it accepts HTTP/2. If you sit behind a CDN, test the origin directly, because the CDN will always answer with HTTP/2:&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="nb"&gt;echo&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; openssl s_client -connect ORIGIN_IP:443 \
  -servername example.com -alpn h2 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;|&lt;/span&gt; grep ALPN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We ran it against nginx 1.31.8 in an offline container, first with &lt;code&gt;http2 on;&lt;/code&gt; and then with &lt;code&gt;http2 off;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;--- http2 on
ALPN protocol: h2
--- http2 off
No ALPN negotiated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ALPN protocol: h2&lt;/code&gt; means the server speaks HTTP/2 and is exposed to CVE-2026-123007 until it is patched.&lt;/p&gt;

&lt;h2&gt;
  
  
  Patch nginx
&lt;/h2&gt;

&lt;p&gt;Back up the configuration first so that a package upgrade cannot cost you your server blocks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo tar -czf /root/nginx-conf-&lt;span class="nv"&gt;$(&lt;/span&gt;date -u +%Y%m%d-%H%M&lt;span class="o"&gt;)&lt;/span&gt;.tgz /etc/nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Packages from nginx.org or your distribution
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo apt-get update
sudo apt-get install --only-upgrade -o Dpkg::Options::=--force-confold nginx
sudo nginx -t &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; sudo systemctl restart nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--force-confold&lt;/code&gt; keeps your existing configuration files. On RHEL-family systems use &lt;code&gt;sudo dnf upgrade nginx&lt;/code&gt;. If your nginx came from a PPA that no longer exists, switch to the official nginx.org repository first; Forge's guide above walks through it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Warning:&lt;/strong&gt; &lt;code&gt;systemctl reload nginx&lt;/code&gt; is not enough. A reload keeps the old binary in memory. Restart nginx so the patched binary is the one running.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Docker
&lt;/h3&gt;

&lt;p&gt;Pin a fixed tag instead of relying on &lt;code&gt;latest&lt;/code&gt;, then pull and recreate only the web container:&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="c"&gt;# docker-compose.yml: image: nginx:1.30.7   (or nginx:1.31.9 for mainline)&lt;/span&gt;
docker compose pull web
docker compose up -d web
docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;web-container&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; nginx -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember images that bundle their own nginx, such as phpMyAdmin, control panels and all-in-one WordPress images, and Kubernetes ingress controllers. Aikido notes that ingress-nginx bundles nginx 1.27.1 and the project, archived in March 2026, will not ship a fix.&lt;/p&gt;

&lt;h3&gt;
  
  
  Managed and shared hosting
&lt;/h3&gt;

&lt;p&gt;Open a ticket and ask directly: "Are your web servers patched for nginx2root (CVE-2026-123007 and related CVEs), running nginx 1.30.7 or 1.31.9 or a vendor build with the fixes, and restarted since?" Keep the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Block the kernel route to root
&lt;/h2&gt;

&lt;p&gt;Most WordPress servers never use SCTP, so the simplest defence against the second half of the chain is to stop the kernel loading it. First check whether it is loaded now:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsmod &lt;span class="o"&gt;|&lt;/span&gt; grep sctp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No output means it is not loaded. Then add a rule that refuses to load it in future, and test the rule with a dry run:&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="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'install sctp /bin/false'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sudo tee /etc/modprobe.d/disable-sctp.conf
modprobe -n -v sctp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On our Ubuntu server (kernel 6.8) the dry run ends with &lt;code&gt;install /bin/false&lt;/code&gt;, which confirms the rule wins:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;insmod /lib/modules/6.8.0-149-generic/kernel/net/ipv4/udp_tunnel.ko.zst
insmod /lib/modules/6.8.0-149-generic/kernel/net/ipv6/ip6_udp_tunnel.ko.zst
install /bin/false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This rule does not unload a module that is already loaded, and it cannot help if SCTP is built into the kernel. If &lt;code&gt;lsmod&lt;/code&gt; showed it, reboot after adding the rule. Docker containers share the host kernel, so do this on the host, not inside containers. Install the kernel update as soon as your distribution ships one, and reboot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mitigate if you cannot patch today
&lt;/h2&gt;

&lt;p&gt;These steps cut exposure while you wait; none of them replaces the upgrade. Change one thing at a time and run &lt;code&gt;sudo nginx -t&lt;/code&gt; before each restart.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Turn off HTTP/2.&lt;/strong&gt; On nginx 1.25.1 or later set &lt;code&gt;http2 off;&lt;/code&gt; in each server block; on older versions remove &lt;code&gt;http2&lt;/code&gt; from the &lt;code&gt;listen&lt;/code&gt; line. This blocks CVE-2026-123007 and CVE-2026-123633. The site falls back to HTTP/1.1 and keeps working. Restart nginx and run the &lt;code&gt;openssl s_client&lt;/code&gt; check again; it should now say &lt;code&gt;No ALPN negotiated&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Turn off HTTP/3.&lt;/strong&gt; Remove &lt;code&gt;quic&lt;/code&gt; listeners, set &lt;code&gt;http3 off;&lt;/code&gt;, remove any &lt;code&gt;Alt-Svc&lt;/code&gt; header that advertises HTTP/3, and optionally block UDP port 443.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Avoid DNS lookups at request time.&lt;/strong&gt; Point &lt;code&gt;proxy_pass&lt;/code&gt; at a fixed &lt;code&gt;upstream&lt;/code&gt; block instead of a variable, and turn off &lt;code&gt;mirror&lt;/code&gt; where you do not need it. Xint notes that other subrequest features such as SSI may still reach the bug, so this is a partial fix only.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Close the mail proxy.&lt;/strong&gt; Bind it to &lt;code&gt;127.0.0.1&lt;/code&gt; or firewall it to trusted IPs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lock the origin to your CDN&lt;/strong&gt; so that only its published IP ranges can reach ports 80 and 443.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Restart, do not just reload,&lt;/strong&gt; so that old workers holding existing connections are replaced.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Verify the fix and look for signs of trouble
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. The binary is fixed.&lt;/strong&gt; Run the check script again and look for "patched", or check the package version against your distribution's advisory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The running process uses it.&lt;/strong&gt; If nginx was not restarted, the old binary is still running from memory and Linux marks its file as deleted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo ls -l /proc/&lt;span class="nv"&gt;$(&lt;/span&gt;cat /run/nginx.pid&lt;span class="o"&gt;)&lt;/span&gt;/exe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the result ends in &lt;code&gt;(deleted)&lt;/code&gt;, run &lt;code&gt;sudo systemctl restart nginx&lt;/code&gt; and check again.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The configuration loads.&lt;/strong&gt; A successful test looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf &lt;span class="nb"&gt;test&lt;/span&gt; is successful
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Warnings that &lt;code&gt;listen ... http2&lt;/code&gt; is deprecated are harmless.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. WordPress still works.&lt;/strong&gt; From another machine, check the protocol and the login page, then log in, save a draft and submit a test comment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sI --http2 https://example.com/ &lt;span class="o"&gt;|&lt;/span&gt; head -n1
curl -s -o /dev/null -w &lt;span class="s1"&gt;'%{http_code}\n'&lt;/span&gt; https://example.com/wp-login.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Nothing odd is running as the web server user.&lt;/strong&gt; nginx workers never start other programs, so any child process under a worker is a red flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ps -eo user,pid,ppid,lstart,cmd --forest &lt;span class="o"&gt;|&lt;/span&gt; grep -A3 &lt;span class="s1"&gt;'nginx: worker'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Logs are quiet.&lt;/strong&gt; Xint suggests looking for workers exiting abnormally, long-lived connections from one address that send a lot and receive little, and bursts of short TLS connections from the same IP. The error log is the easiest place to start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo grep -E &lt;span class="s1"&gt;'exited on signal|signal (6|11)'&lt;/span&gt; /var/log/nginx/error.log* &lt;span class="o"&gt;|&lt;/span&gt; tail -n 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Xint warns that these attacks may leave little trace in normal access logs, so a clean result is reassuring but not proof. If you find anything suspicious, rotate the database password and WordPress salts, and check for unknown admin users and new PHP files in &lt;code&gt;wp-content/uploads&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep WordPress servers ahead of the next one
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Watch the &lt;a href="https://nginx.org/" rel="noopener noreferrer"&gt;nginx.org news page&lt;/a&gt; and your distribution's security announcements, so you hear about a fixed release on the day it ships.&lt;/li&gt;
&lt;li&gt;Keep a list of every server, container and image that runs nginx, including staging sites, phpMyAdmin and ingress controllers.&lt;/li&gt;
&lt;li&gt;Pin Docker images to exact versions so you always know what is deployed.&lt;/li&gt;
&lt;li&gt;Treat PHP the same way. Our guide to the &lt;a href="https://wptutshub.com/php2shell-critical-rce-protect-wordpress/" rel="noopener noreferrer"&gt;PHP2Shell critical RCE&lt;/a&gt; uses the same check, patch and verify routine for the PHP interpreter.&lt;/li&gt;
&lt;li&gt;Add a WordPress-level layer too. A server patch stops attacks on nginx; a good plugin from our list of the &lt;a href="https://wptutshub.com/best-wordpress-security-plugins/" rel="noopener noreferrer"&gt;best WordPress security plugins&lt;/a&gt; watches logins, file changes and suspicious requests inside WordPress.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The short version: run &lt;code&gt;nginx -v&lt;/code&gt; today, get to &lt;strong&gt;1.30.7 or 1.31.9&lt;/strong&gt; (or your distribution's fixed package), restart nginx so the new binary is the one running, block SCTP on the host, and test your login and checkout pages afterwards.&lt;/p&gt;

&lt;p&gt;Further reading: &lt;a href="https://nginx2root.com/" rel="noopener noreferrer"&gt;nginx2root.com&lt;/a&gt; and &lt;a href="https://www.aikido.dev/blog/nginx2root-critical-nginx-rce-vulnerabilities" rel="noopener noreferrer"&gt;Aikido's nginx2root analysis&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/nginx2root-wordpress/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>security</category>
      <category>php</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Fix WordPress Critical Error After Update</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Wed, 18 Nov 2026 12:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/fix-wordpress-critical-error-after-update-3fkh</link>
      <guid>https://dev.to/zubaer/fix-wordpress-critical-error-after-update-3fkh</guid>
      <description>&lt;p&gt;A WordPress critical error after update is rarely a mystery for long, but the screen itself tells you nothing. Since WordPress 5.2 the core fatal error handler catches the PHP crash, prints a polite white page, and emails the admin a recovery link, deliberately withholding the file and line that would identify the culprit. This tutorial compares the three realistic recovery routes, then implements the one worth keeping: read the fatal from &lt;code&gt;wp-content/debug.log&lt;/code&gt;, get back into &lt;code&gt;wp-admin&lt;/code&gt; through recovery mode, and roll the offending plugin or theme back with WP-CLI. It finishes with a small mu-plugin that emails you the file and line the moment the next update fails.&lt;/p&gt;

&lt;p&gt;You need file or SSH access to the install (SFTP covers the first half), WP-CLI 2.7 or newer for the rollback, and access to the admin email inbox on that site.&lt;/p&gt;

&lt;h2&gt;
  
  
  The critical error screen is a symptom, not a diagnosis
&lt;/h2&gt;

&lt;p&gt;When PHP hits an uncaught fatal, WordPress runs &lt;code&gt;WP_Fatal_Error_Handler&lt;/code&gt; on shutdown. That handler checks whether the error came from a plugin or theme file, pauses the offending extension for the current session, sends the recovery-mode email, and renders the generic template. The message is suppressed on purpose: a raw stack trace on a live site leaks absolute paths, plugin versions and occasionally database credentials.&lt;/p&gt;

&lt;p&gt;That design is good for visitors and bad for you. Everything you need is written to a log instead, which is why the first move is never "deactivate plugins one by one" but "turn on the log and read it".&lt;/p&gt;

&lt;h2&gt;
  
  
  Which of the three recovery routes actually fits your situation?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Route 1: Recovery mode alone: fast, but it only buys you wp-admin
&lt;/h3&gt;

&lt;p&gt;Recovery mode emails a one-time login link that loads the dashboard with the plugin or theme that crashed paused, for your session only. It is the right choice when you have no shell, no SFTP, and one obvious suspect you can deactivate from the Plugins screen. It is the wrong choice when you want to know &lt;em&gt;why&lt;/em&gt; something broke, because it never tells you. Visitors keep seeing the error while you are in recovery mode: it is a diagnostic session, not a fix.&lt;/p&gt;

&lt;h3&gt;
  
  
  Route 2: Debug log plus manual rollback: precise, but slow
&lt;/h3&gt;

&lt;p&gt;Editing &lt;code&gt;wp-config.php&lt;/code&gt; over SFTP and reading &lt;code&gt;debug.log&lt;/code&gt; gives you the exact file and line. The catch is the fix: without WP-CLI you are downloading the previous plugin ZIP from wordpress.org, deleting the plugin folder, uploading the ZIP, and hoping the settings survive. Workable on a single site, miserable on five.&lt;/p&gt;

&lt;h3&gt;
  
  
  Route 3: Debug log plus WP-CLI: the one to learn
&lt;/h3&gt;

&lt;p&gt;Diagnosis and repair happen in the same terminal, the rollback is a single command, and the whole sequence is repeatable on the next site. It needs SSH and a working PHP CLI binary, which is the only real cost. The rest of this tutorial implements this route, using recovery mode as the bridge whenever you need the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Turn on WP_DEBUG_LOG without leaking errors to visitors
&lt;/h2&gt;

&lt;p&gt;Add these lines to &lt;code&gt;wp-config.php&lt;/code&gt;, above the &lt;em&gt;"That's all, stop editing"&lt;/em&gt; comment. The &lt;a href="https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/" rel="noopener noreferrer"&gt;debugging handbook page&lt;/a&gt; documents every constant here.&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;// wp-config.php — above the "That's all, stop editing" line.&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_DEBUG'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_DEBUG_LOG'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// writes to wp-content/debug.log&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_DEBUG_DISPLAY'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&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 print errors into the page&lt;/span&gt;
&lt;span class="nd"&gt;@ini_set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'display_errors'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&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;&lt;code&gt;WP_DEBUG_LOG&lt;/code&gt; does nothing on its own: it only takes effect when &lt;code&gt;WP_DEBUG&lt;/code&gt; is also true. And leaving &lt;code&gt;WP_DEBUG_DISPLAY&lt;/code&gt; at its default on a live site turns every notice into a visible path disclosure. Setting it to &lt;code&gt;false&lt;/code&gt; means the log fills up while visitors see nothing unusual.&lt;/p&gt;

&lt;p&gt;Since WordPress 5.1 you can point the log at a path outside the web root, which is strictly better if your host allows it:&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="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_DEBUG_LOG'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'/home/example/logs/wp-debug.log'&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;h2&gt;
  
  
  Step 2: Read the fatal error line and find the file that caused it
&lt;/h2&gt;

&lt;p&gt;Reload the broken page once, then read the tail of the log. If you have SSH, follow it live while you refresh:&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="c"&gt;# Follow the log while you reload the broken page&lt;/span&gt;
tail -f wp-content/debug.log

&lt;span class="c"&gt;# Or list the 20 most recent fatal lines&lt;/span&gt;
grep -n &lt;span class="s2"&gt;"PHP Fatal error"&lt;/span&gt; wp-content/debug.log &lt;span class="o"&gt;|&lt;/span&gt; tail -n 20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A useful line looks like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PHP Fatal error: Uncaught Error: Call to undefined function acme_shipping_init() in /var/www/html/wp-content/plugins/acme-shipping/includes/bootstrap.php:3&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Read it right to left. The path after &lt;code&gt;in&lt;/code&gt; is the file that actually crashed; the number after the final colon is the line. Here the culprit is the &lt;code&gt;acme-shipping&lt;/code&gt; plugin, not the theme and not core. If the path points into &lt;code&gt;wp-includes/&lt;/code&gt; or &lt;code&gt;wp-admin/&lt;/code&gt;, suspect a half-finished core update rather than a plugin.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;PHP Warning&lt;/code&gt; and &lt;code&gt;PHP Notice&lt;/code&gt; lines immediately above the fatal usually name the real trigger: a missing option, a removed filter, a class that no longer exists. Reading only the fatal line often sends you to the wrong plugin.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;debug.log&lt;/code&gt; stays empty after a reload, the crash is happening before &lt;code&gt;WP_DEBUG&lt;/code&gt; is defined (a parse error in an mu-plugin, for example) or the host has disabled &lt;code&gt;error_log&lt;/code&gt;. Check the server's own error log at that point: &lt;code&gt;/var/log/php-fpm/error.log&lt;/code&gt;, or the equivalent in your control panel.&lt;/p&gt;

&lt;p&gt;The fatal error in wp-content/debug.log after a plugin update broke the site (one line per page load) (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ grep -n "PHP Fatal error" wp-content/debug.log | tail -n 20
1:[11-Nov-2026 13:38:41 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function acme_shipping_init() in /var/www/html/wp-content/plugins/acme-shipping/includes/bootstrap.php:3
11:[11-Nov-2026 13:38:41 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function acme_shipping_init() in /var/www/html/wp-content/plugins/acme-shipping/includes/bootstrap.php:3
21:[11-Nov-2026 13:38:41 UTC] PHP Fatal error:  Uncaught Error: Call to undefined function acme_shipping_init() in /var/www/html/wp-content/plugins/acme-shipping/includes/bootstrap.php:3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Use recovery mode to get back into wp-admin
&lt;/h2&gt;

&lt;p&gt;The recovery email arrives at the admin address with the subject &lt;em&gt;"Your site is experiencing a technical issue"&lt;/em&gt;. The link inside is valid for 24 hours by default and sets a session cookie, so you can browse the dashboard with plugins paused. The &lt;a href="https://wordpress.org/documentation/article/recovery-mode/" rel="noopener noreferrer"&gt;recovery mode documentation&lt;/a&gt; explains the email and the session, and the &lt;code&gt;recovery_mode_email_link_ttl&lt;/code&gt; filter changes how long the link stays valid if you need a longer window.&lt;/p&gt;

&lt;p&gt;Two limits are worth knowing before you rely on it. First, recovery mode only triggers when the fatal is caught by the core handler: a fatal inside an mu-plugin, or inside a file loaded before the handler is registered, will not produce an email. Second, it depends on &lt;code&gt;wp_mail()&lt;/code&gt; actually working, which on many shared hosts it does not.&lt;/p&gt;

&lt;p&gt;If the email never arrives, you have not lost anything: the WP-CLI route in the next step does the same job without needing mail at all. Do not spend an hour fixing SMTP while the site is down.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Roll back the plugin or theme with WP-CLI
&lt;/h2&gt;

&lt;p&gt;Work through this sequence in the WordPress root. The &lt;a href="https://developer.wordpress.org/cli/commands/plugin/" rel="noopener noreferrer"&gt;wp plugin command reference&lt;/a&gt; lists every flag used below.&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="c"&gt;# 1. Confirm WP-CLI can bootstrap at all&lt;/span&gt;
wp core version

&lt;span class="c"&gt;# 2. If a plugin fatals during bootstrap, skip them entirely&lt;/span&gt;
wp --skip-plugins --skip-themes plugin list --fields=name,status,version,update_version

&lt;span class="c"&gt;# 3. Take the suspect out of the equation&lt;/span&gt;
wp plugin deactivate acme-shipping

&lt;span class="c"&gt;# 4. Roll back to the last version you know worked&lt;/span&gt;
wp plugin install acme-shipping --version=2.4.1 --force

&lt;span class="c"&gt;# 5. Bring it back and re-test&lt;/span&gt;
wp plugin activate acme-shipping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;--skip-plugins&lt;/code&gt; is the escape hatch when the fatal happens during WP-CLI's own bootstrap and every command dies with the same error. &lt;code&gt;--force&lt;/code&gt; is mandatory for a downgrade, without it WP-CLI refuses because the installed version is newer than the requested one. And &lt;code&gt;--version&lt;/code&gt; accepts any published tag, which you can find on the plugin's &lt;em&gt;Advanced View&lt;/em&gt; page on wordpress.org.&lt;/p&gt;

&lt;p&gt;Themes and core follow the same pattern:&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="c"&gt;# Swap to a default theme, then roll the broken one back&lt;/span&gt;
wp theme activate twentytwentyfour
wp theme install acme-theme --version=1.8.0 --force

&lt;span class="c"&gt;# Core: reinstall the version you are already on, then check for tampering&lt;/span&gt;
wp core download --version=&lt;span class="s2"&gt;"$(wp core version)"&lt;/span&gt; --force --skip-content
wp core verify-checksums
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;wp core verify-checksums&lt;/code&gt; is the fastest way to spot a core file that was modified or truncated mid-upload: a common cause of fatals in &lt;code&gt;wp-includes/&lt;/code&gt; after a failed automatic update. If it reports mismatches, reinstall core with &lt;code&gt;wp core download --force&lt;/code&gt; rather than patching files by hand. Do not roll core back to an older major version: the update may already have upgraded the database, and older code cannot be trusted to read it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Catch the next fatal error with an mu-plugin that emails you
&lt;/h2&gt;

&lt;p&gt;Core's recovery email tells you &lt;em&gt;that&lt;/em&gt; the site broke. It does not tell you &lt;em&gt;where&lt;/em&gt;. Drop this file in &lt;code&gt;wp-content/mu-plugins/&lt;/code&gt; (create the directory if it does not exist) and you get the file and line in your inbox within seconds of the crash.&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Plugin Name: Fatal Error Notifier
 * Description: Emails the site admin the file and line of any PHP fatal error.
 */&lt;/span&gt;

&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'shutdown'&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;$error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;error_get_last&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;$fatal_types&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="no"&gt;E_ERROR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;E_PARSE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;E_CORE_ERROR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;E_COMPILE_ERROR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;E_USER_ERROR&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="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$error&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nf"&gt;in_array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$error&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'type'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$fatal_types&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'fatal_notice_'&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;md5&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$error&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'file'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$error&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'line'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$error&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'message'&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;get_transient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$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;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;set_transient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$key&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="no"&gt;HOUR_IN_SECONDS&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nv"&gt;$body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"Fatal error on %s\n\nMessage: %s\nFile:    %s\nLine:    %d\nRequest: %s"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nf"&gt;home_url&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;$error&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'message'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nv"&gt;$error&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'file'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nv"&gt;$error&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'line'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;esc_url_raw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;wp_unslash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&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="s1"&gt;'n/a'&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// A fatal while plugins load happens before pluggable.php is included, so wp_mail() may not exist yet.&lt;/span&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;function_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'wp_mail'&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;require_once&lt;/span&gt; &lt;span class="no"&gt;ABSPATH&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="no"&gt;WPINC&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/pluggable.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;wp_mail&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nf"&gt;get_option&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'admin_email'&lt;/span&gt; &lt;span class="p"&gt;)&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="nf"&gt;wp_specialchars_decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;get_bloginfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'name'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;ENT_QUOTES&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'] PHP fatal error'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nv"&gt;$body&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;Use an mu-plugin rather than a normal one: must-use plugins load before regular plugins, cannot be deactivated by accident from the admin, and are not affected by the very crash you are trying to report. The &lt;code&gt;shutdown&lt;/code&gt; hook still fires after a fatal, which is exactly the window this needs. The transient keyed on file, line and message stops a broken page from sending you four hundred identical emails. The &lt;code&gt;function_exists()&lt;/code&gt; check matters too: a plugin that crashes while loading does so before WordPress includes &lt;code&gt;pluggable.php&lt;/code&gt;, and without the check the notifier dies with a second fatal error instead of emailing you.&lt;/p&gt;

&lt;p&gt;If you would rather change the wording of the white screen itself, WordPress also supports a &lt;code&gt;wp-content/php-error.php&lt;/code&gt; drop-in that overrides the default template: useful for adding a support address, less useful for diagnosis.&lt;/p&gt;

&lt;p&gt;The email the notifier sends, captured on the test site instead of being delivered (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;To: admin@example.test
Subject: [Test Site] PHP fatal error

Fatal error on http://localhost

Message: Uncaught Error: Call to undefined function acme_shipping_init() in /var/www/html/wp-content/plugins/acme-shipping/includes/bootstrap.php:3
Stack trace:
#0 /var/www/html/wp-content/plugins/acme-shipping/acme-shipping.php(6): require()
#1 /var/www/html/wp-settings.php(597): include_once('/var/www/html/w...')
#2 /var/www/html/wp-config.php(106): require_once('/var/www/html/w...')
#3 /var/www/html/wp-load.php(50): require_once('/var/www/html/w...')
#4 /var/www/html/wp-blog-header.php(13): require_once('/var/www/html/w...')
#5 /var/www/html/index.php(17): require('/var/www/html/w...')
#6 {main}
  thrown
File:    /var/www/html/wp-content/plugins/acme-shipping/includes/bootstrap.php
Line:    3
Request: /
---
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lock the debug log down before you forget
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;debug.log&lt;/code&gt; sits in &lt;code&gt;wp-content&lt;/code&gt;, which is web-accessible on most configurations. A single stack trace exposes absolute paths, plugin versions and sometimes query fragments. Deny it explicitly:&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="c"&gt;# Apache: deny direct requests for the log&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;Files "debug.log"&amp;gt;\n  Require all denied\n&amp;lt;/Files&amp;gt;\n'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; wp-content/.htaccess
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On nginx, add a &lt;code&gt;location = /wp-content/debug.log { deny all; }&lt;/code&gt; block to the server config instead: &lt;code&gt;.htaccess&lt;/code&gt; is ignored there. Better still, use the absolute-path form of &lt;code&gt;WP_DEBUG_LOG&lt;/code&gt; shown in step 1 and keep the file out of the document root entirely.&lt;/p&gt;

&lt;p&gt;The log is at its most dangerous immediately after an incident, which is precisely when people leave debugging switched on for a week. Decide where it lives before you need it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do when the fatal is in a theme or in core
&lt;/h2&gt;

&lt;p&gt;A theme fatal almost always follows a theme update or a child-theme template that calls a function the parent removed. Activate a default theme with WP-CLI, confirm the site loads, then roll the theme back and diff the template that appears in the log.&lt;/p&gt;

&lt;p&gt;A core fatal is different: core does not spontaneously break, so something changed underneath it. Run &lt;code&gt;wp core verify-checksums&lt;/code&gt; first. If it passes, the crash is in a file that core loads but a plugin filters: check the stack trace for the first frame inside &lt;code&gt;wp-content/&lt;/code&gt;. If it fails, reinstall core from the same version with &lt;code&gt;wp core download --force&lt;/code&gt;; a truncated upload from a dropped FTP connection is the usual explanation.&lt;/p&gt;

&lt;p&gt;If the fatal also locks you out of wp-admin and the recovery email never arrives, you can &lt;a href="https://wptutshub.com/create-new-wordpress-administrator-via-mysql/" rel="noopener noreferrer"&gt;create a new administrator directly in MySQL&lt;/a&gt;. And if the white screen turns out to say “Error establishing a database connection” instead, that one has its own checklist: &lt;a href="https://wptutshub.com/fix-wordpress-database-connection-error/" rel="noopener noreferrer"&gt;fixing the WordPress database connection error&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The follow-up worth doing this week: add a nightly cron entry that greps the log and mails you a digest, so you learn about fatals from your own inbox rather than from a customer. Something as small as &lt;code&gt;grep -c "PHP Fatal error" /home/example/logs/wp-debug.log&lt;/code&gt; piped into &lt;code&gt;mail -s&lt;/code&gt; is enough to catch the pattern before the next update takes the site down at 2am.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/wordpress-critical-error-after-update/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Fix WordPress Memory Exhausted Error</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Mon, 16 Nov 2026 16:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/fix-wordpress-memory-exhausted-error-2gnn</link>
      <guid>https://dev.to/zubaer/fix-wordpress-memory-exhausted-error-2gnn</guid>
      <description>&lt;p&gt;The WordPress memory exhausted error is a PHP fatal, not a WordPress bug. When a request prints &lt;code&gt;Allowed memory size of 268435456 bytes exhausted (tried to allocate 20480 bytes)&lt;/code&gt;, PHP stopped at the ceiling set for that process. Raising the ceiling is the easy half. Finding the code that filled it is the half that stops the error coming back next Tuesday.&lt;/p&gt;

&lt;h2&gt;
  
  
  The file named in the fatal error is the last straw, not the cause
&lt;/h2&gt;

&lt;p&gt;Read the message in three parts before touching a file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;268435456 bytes&lt;/strong&gt; is the limit at the moment of death: 256 MB here. Compare it with what you assumed the limit was.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;20480 bytes&lt;/strong&gt; is the allocation that failed. A small number means the request was already full and something earlier consumed the memory. A large number points at one operation: an image resize, a CSV import, a query pulling 50,000 rows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;wp-includes/… on line N&lt;/strong&gt; is where it died, which is rarely where it started. Core code doing an ordinary thing on behalf of a plugin is the usual scene.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Visitors see &lt;em&gt;There has been a critical error on this website.&lt;/em&gt; and nothing else, because &lt;code&gt;WP_DEBUG_DISPLAY&lt;/code&gt; is off on any site you care about. The real message lands in the PHP error log, so start there rather than in the browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read the limit PHP is actually running with before you change a single file
&lt;/h2&gt;

&lt;p&gt;Three numbers matter and they are not the same number: the &lt;code&gt;memory_limit&lt;/code&gt; PHP is running with, the &lt;code&gt;WP_MEMORY_LIMIT&lt;/code&gt; constant WordPress wants, and &lt;code&gt;WP_MAX_MEMORY_LIMIT&lt;/code&gt;, the higher ceiling WordPress uses for admin screens, AJAX, cron and image work. Save this as &lt;code&gt;memory-report.php&lt;/code&gt; and run it with WP-CLI:&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Save as memory-report.php and run: wp eval-file memory-report.php
 */&lt;/span&gt;

&lt;span class="c1"&gt;// ini_set() returns false when the host has locked the value, for example with php_admin_value.&lt;/span&gt;
&lt;span class="nv"&gt;$changeable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nd"&gt;@ini_set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'memory_limit'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'memory_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="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"memory_limit          : %s\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'memory_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="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"WP_MEMORY_LIMIT       : %s\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_MEMORY_LIMIT'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="no"&gt;WP_MEMORY_LIMIT&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'not defined'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"WP_MAX_MEMORY_LIMIT   : %s\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_MAX_MEMORY_LIMIT'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="no"&gt;WP_MAX_MEMORY_LIMIT&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'not defined'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"peak so far           : %s\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;size_format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;memory_get_peak_usage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;true&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="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"changeable at runtime : %s\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$changeable&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'yes'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'no (locked by the server)'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"loaded php.ini        : %s\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;php_ini_loaded_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;php_ini_loaded_file&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="s1"&gt;'none'&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 last two lines decide your next move. If &lt;code&gt;changeable at runtime&lt;/code&gt; says &lt;code&gt;no&lt;/code&gt;, the host has locked &lt;code&gt;memory_limit&lt;/code&gt;, usually with &lt;code&gt;php_admin_value&lt;/code&gt; in the PHP-FPM pool, and &lt;code&gt;ini_set()&lt;/code&gt;, including anything WordPress does on your behalf, is ignored. Editing &lt;code&gt;wp-config.php&lt;/code&gt; in that situation is wasted effort; you need the server-side route below. &lt;code&gt;php_ini_loaded_file()&lt;/code&gt; tells you which file to edit when you have access to it. Run the report through the web server as well as WP-CLI: the command line often has no limit at all, as the first output below shows.&lt;/p&gt;

&lt;p&gt;memory-report.php run with WP-CLI (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;memory_limit          : -1
WP_MEMORY_LIMIT       : 40M
WP_MAX_MEMORY_LIMIT   : 256M
peak so far           : 51 MB
changeable at runtime : yes
loaded php.ini        : none
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same report served by Apache, before and after locking the value with php_admin_value memory_limit 128M (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;== web, default:
memory_limit          : 128M
changeable at runtime : yes
== web, php_admin_value memory_limit 128M:
memory_limit          : 128M
changeable at runtime : no (locked by the server)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Three places to raise the ceiling, and which one wins on your host
&lt;/h2&gt;

&lt;p&gt;There are three routes that actually work, plus one that mostly does not. They are not interchangeable.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;wp-config.php constants&lt;/strong&gt;: portable, per site, no restart, no root. They only affect WordPress requests, which is usually exactly what you want. This is the right first move on shared hosting and most managed platforms, and it is the only route that travels with the site when you migrate it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.user.ini&lt;/strong&gt;: read by PHP-FPM and FastCGI per directory, so it covers every PHP file under the WordPress root, not just WordPress. Use it when &lt;code&gt;ini_set()&lt;/code&gt; is blocked but you can still write files. Changes are cached for &lt;code&gt;user_ini.cache_ttl&lt;/code&gt; (300 seconds by default), so it can look broken for five minutes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;php.ini or the FPM pool config&lt;/strong&gt;: server-wide, needs root and a reload, and it is the only thing that beats &lt;code&gt;php_admin_value[memory_limit]&lt;/code&gt;. Correct for a VPS or a dedicated box, and the only answer when the runtime flag above says the value is fixed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.htaccess&lt;/strong&gt;: works only under &lt;code&gt;mod_php&lt;/code&gt;, which most modern hosts no longer run. See below.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why an .htaccess php_value line is usually ignored
&lt;/h2&gt;

&lt;p&gt;The snippet people paste into &lt;code&gt;.htaccess&lt;/code&gt; looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .htaccess — only has an effect when PHP runs as an Apache module.
&amp;lt;IfModule mod_php.c&amp;gt;
    php_value memory_limit 512M
&amp;lt;/IfModule&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under &lt;code&gt;mod_php&lt;/code&gt;, with &lt;code&gt;AllowOverride Options&lt;/code&gt; enabled, that works. Under PHP-FPM, which is what nearly every host runs now, Apache never sees a PHP directive and the block is a no-op: the limit does not move and you conclude that raising memory simply does not work. Worse, an unguarded &lt;code&gt;php_value&lt;/code&gt; line under &lt;code&gt;mod_proxy_fcgi&lt;/code&gt; produces &lt;em&gt;Invalid command 'php_value'&lt;/em&gt; and a 500 on every request. If you cannot confirm &lt;code&gt;mod_php&lt;/code&gt; is loaded, skip this route entirely; a silent no-op is harder to debug than an error.&lt;/p&gt;

&lt;h2&gt;
  
  
  Raise the limit in wp-config.php the way WordPress expects
&lt;/h2&gt;

&lt;p&gt;Add two constants above the line that requires &lt;code&gt;wp-settings.php&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="cm"&gt;/**
 * Memory ceiling for WordPress requests.
 * Must sit above the line that requires wp-settings.php.
 */&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_MEMORY_LIMIT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'256M'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'WP_MAX_MEMORY_LIMIT'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'512M'&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;&lt;code&gt;WP_MEMORY_LIMIT&lt;/code&gt; is the target for ordinary front-end requests. &lt;code&gt;WP_MAX_MEMORY_LIMIT&lt;/code&gt; is what &lt;a href="https://developer.wordpress.org/reference/functions/wp_raise_memory_limit/" rel="noopener noreferrer"&gt;wp_raise_memory_limit()&lt;/a&gt; applies in admin, AJAX, cron and image-editing contexts, so a 256M front end with a 512M admin is a sane split: the block editor, plugin updates and thumbnail regeneration are the requests that actually need the headroom.&lt;/p&gt;

&lt;p&gt;WordPress only raises the limit, never lowers it, so a constant below the server value does nothing. Do not reach for &lt;code&gt;ini_set( 'memory_limit', '-1' )&lt;/code&gt; here: unlimited memory on a shared box turns a clean fatal into a slow death by swapping, and you lose the one signal that told you something was wrong. If the diagnostic above reported the value as fixed, this block will be ignored: go to the server-side route instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Push the ceiling from the server side with .user.ini or php.ini
&lt;/h2&gt;

&lt;p&gt;Create &lt;code&gt;.user.ini&lt;/code&gt; in the WordPress root, or edit the matching lines in the loaded &lt;code&gt;php.ini&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c1"&gt;; .user.ini in the WordPress root, or the matching lines in php.ini
&lt;/span&gt;&lt;span class="na"&gt;memory_limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;512M&lt;/span&gt;
&lt;span class="na"&gt;max_execution_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details trip people up. First, &lt;code&gt;.user.ini&lt;/code&gt; is only read when &lt;code&gt;user_ini.filename&lt;/code&gt; is set (it is by default) and PHP runs as FPM or FastCGI; under &lt;code&gt;mod_php&lt;/code&gt; the file is ignored. Second, the values are cached, so after saving, wait out &lt;code&gt;user_ini.cache_ttl&lt;/code&gt; or reload PHP-FPM before you re-run the diagnostic. If the value still refuses to move, the pool config has &lt;code&gt;php_admin_value[memory_limit]&lt;/code&gt; set, and no file inside the site can override it: that is a support ticket, not a code change.&lt;/p&gt;

&lt;p&gt;Remember that WP-CLI uses the CLI &lt;code&gt;php.ini&lt;/code&gt;, which often has a different (sometimes unlimited) limit from the web server. A &lt;code&gt;wp&lt;/code&gt; command succeeding proves nothing about a browser request.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rank plugins by peak memory with WP-CLI before you blame one
&lt;/h2&gt;

&lt;p&gt;Guessing which plugin is heavy is unreliable, and deactivating them one at a time on a live site is worse. WP-CLI can load WordPress with a chosen subset of plugins, so you can measure each one's bootstrap cost in isolation:&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="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Peak memory per active plugin: load one plugin at a time, skip the rest.&lt;/span&gt;
&lt;span class="nv"&gt;all&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;wp plugin list --status=active --field=name &lt;span class="o"&gt;|&lt;/span&gt; paste -sd, -&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%-34s %s\n'&lt;/span&gt; &lt;span class="s1"&gt;'plugin'&lt;/span&gt; &lt;span class="s1"&gt;'peak MB'&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%-34s %s\n'&lt;/span&gt; &lt;span class="s1"&gt;'(core only)'&lt;/span&gt; &lt;span class="s2"&gt;"$(wp --skip-plugins eval 'echo round(memory_get_peak_usage(true)/1048576,1);')"&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; plugin &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;wp plugin list --status=active --field=name&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="nv"&gt;skip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$all"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; tr &lt;span class="s1"&gt;','&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; grep -vx &lt;span class="s2"&gt;"$plugin"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; paste -sd, -&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -z &lt;span class="s2"&gt;"$skip"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
        &lt;span class="nv"&gt;peak&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'echo round(memory_get_peak_usage(true)/1048576,1);'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="nv"&gt;peak&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;wp --skip-plugins=&lt;span class="s2"&gt;"$skip"&lt;/span&gt; &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'echo round(memory_get_peak_usage(true)/1048576,1);'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
    &lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%-34s %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"$plugin"&lt;/span&gt; &lt;span class="s2"&gt;"$peak"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first row is the baseline: WordPress with every plugin skipped. Each following row loads exactly one plugin, so the difference from the baseline is what that plugin costs before it does anything useful. &lt;code&gt;memory_get_peak_usage( true )&lt;/code&gt; is the number that matters: current usage tells you where you are now, peak tells you what nearly killed the request.&lt;/p&gt;

&lt;p&gt;This measures the bootstrap only. A plugin that allocates nothing at load time and then builds a 300 MB table on &lt;code&gt;wp_ajax_export&lt;/code&gt; or a nightly cron event will look innocent here, which is why the next step exists.&lt;/p&gt;

&lt;h2&gt;
  
  
  Catch the plugin that dies mid-request with a shutdown-hook logger
&lt;/h2&gt;

&lt;p&gt;Drop this in &lt;code&gt;wp-content/mu-plugins/memory-watch.php&lt;/code&gt;. Must-use plugins load before regular plugins, so the logger is already watching when the guilty plugin runs:&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Plugin Name: Memory Watch
 * Description: Logs peak memory per plugin and the request that runs out of it.
 * Version:     1.0.0
 */&lt;/span&gt;

&lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'ABSPATH'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'MEMORY_WATCH_LOG'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;WP_CONTENT_DIR&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/memory-watch.log'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'MEMORY_WATCH_RATIO'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Log once a request passes 80% of the limit.&lt;/span&gt;

&lt;span class="nv"&gt;$GLOBALS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'memory_watch_marks'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;array&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="cm"&gt;/**
 * Memory in use right after each plugin file has been included.
 *
 * @param string $plugin Absolute path to the plugin file.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;memory_watch_mark&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$plugin&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$GLOBALS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'memory_watch_marks'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$plugin&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;memory_get_usage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;true&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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'plugin_loaded'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'memory_watch_mark'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Build the log entry for the current request.
 *
 * @param string $note Optional extra line, such as the fatal error message.
 * @return string
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;memory_watch_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&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;$request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;esc_url_raw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;wp_unslash&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$_SERVER&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'REQUEST_URI'&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="s1"&gt;'cli'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$lines&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'--- %s  %s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;gmdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Y-m-d H:i:s'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$request&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'peak %s of %s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;size_format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;memory_get_peak_usage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;true&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="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'memory_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="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="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'fatal: '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$note&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$deltas&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;array&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;$previous&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&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;$GLOBALS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'memory_watch_marks'&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;$plugin&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$bytes&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$deltas&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$plugin&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$bytes&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nv"&gt;$previous&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$previous&lt;/span&gt;          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$bytes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;arsort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$deltas&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="nf"&gt;array_slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$deltas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&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;$plugin&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$bytes&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'  +%s  %s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;size_format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$bytes&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;plugin_basename&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$plugin&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="nb"&gt;implode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$lines&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Write the entry once per request.
 *
 * @param string $note Optional extra line.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;memory_watch_write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&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;static&lt;/span&gt; &lt;span class="nv"&gt;$done&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;$done&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$done&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;error_log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;memory_watch_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;MEMORY_WATCH_LOG&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="cm"&gt;/**
 * Normal requests: log only when the peak got close to the ceiling.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;memory_watch_shutdown&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;$limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_convert_hr_to_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'memory_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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$limit&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;memory_get_peak_usage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nv"&gt;$limit&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;MEMORY_WATCH_RATIO&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;memory_watch_write&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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'shutdown'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'memory_watch_shutdown'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;register_shutdown_function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'memory_watch_shutdown'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Hard fatals: WordPress applies this filter just before it renders the error page.
 *
 * @param string $message Message shown to the visitor.
 * @param array  $error   Error details from error_get_last().
 * @return string
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;memory_watch_fatal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$error&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;memory_watch_write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$message&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="nv"&gt;$message&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'wp_php_error_message'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'memory_watch_fatal'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&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 &lt;code&gt;plugin_loaded&lt;/code&gt; action fires after each plugin file is included, so the marks are a timeline of the request rather than a snapshot. At the end, the deltas are sorted and the five biggest are written out with the peak and the limit.&lt;/p&gt;

&lt;p&gt;Three write paths look like overkill until you have watched a fatal: WordPress's own fatal handler renders the error page and ends the request, which can happen before later shutdown callbacks run. The &lt;code&gt;shutdown&lt;/code&gt; action and the raw shutdown function cover ordinary requests that get close to the ceiling; the &lt;a href="https://developer.wordpress.org/reference/hooks/wp_php_error_message/" rel="noopener noreferrer"&gt;&lt;code&gt;wp_php_error_message&lt;/code&gt;&lt;/a&gt; filter fires inside the fatal handler, just before the error page is printed, and that is the path that survives a hard fatal. A static guard keeps it to one entry per request.&lt;/p&gt;

&lt;p&gt;Keep the log out of reach: &lt;code&gt;wp-content&lt;/code&gt; is web-accessible, so either point &lt;code&gt;MEMORY_WATCH_LOG&lt;/code&gt; at a path above the document root or add a deny rule for &lt;code&gt;memory-watch.log&lt;/code&gt;. Delete the mu-plugin once you have your answer: it is a diagnostic, not a permanent feature.&lt;/p&gt;

&lt;p&gt;The critical error page a visitor sees when the request runs out of memory (test site: WordPress 7.1.3, PHP 8.2, WooCommerce 11.2.2)&lt;/p&gt;

&lt;p&gt;The logger's entry: peak memory, the fatal message and the plugins that grew the request (test site: WordPress 7.1.3, PHP 8.2, WooCommerce 11.2.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--- 2026-11-11 01:46:45  
peak 124 MB of -1
  +67 MB  woocommerce/woocommerce.php
--- 2026-11-11 01:46:49  
peak 124 MB of -1
  +67 MB  woocommerce/woocommerce.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What to change once the log names a plugin
&lt;/h2&gt;

&lt;p&gt;With a name and a number, the fix is usually obvious:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One plugin dominates the timeline.&lt;/strong&gt; Update it first; memory leaks in page builders and import tools are routinely fixed in minor releases. If the current version is the problem, look for a lighter alternative rather than raising the limit again.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The peak is in admin or cron only.&lt;/strong&gt; Leave &lt;code&gt;WP_MEMORY_LIMIT&lt;/code&gt; alone and raise &lt;code&gt;WP_MAX_MEMORY_LIMIT&lt;/code&gt;. Then break the cron job into batches: &lt;code&gt;wp cron event run &amp;lt;hook&amp;gt;&lt;/code&gt; for a single event is a quick way to reproduce it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nothing stands out and the peak is still high.&lt;/strong&gt; The cost is in the query, not the plugin: &lt;code&gt;posts_per_page =&amp;gt; -1&lt;/code&gt;, an unbounded &lt;code&gt;meta_query&lt;/code&gt;, or a page builder loading every revision. Fix the query before you buy more memory.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The same php.ini and .user.ini precedence decides your upload limit too, which is covered in &lt;a href="https://wptutshub.com/increase-wordpress-max-upload-file-size/" rel="noopener noreferrer"&gt;increasing the WordPress max upload file size&lt;/a&gt;. If image uploads fail with a generic “HTTP error” rather than a memory fatal, start with &lt;a href="https://wptutshub.com/fix-http-error-wordpress-different-ways/" rel="noopener noreferrer"&gt;fixing the HTTP error when uploading images&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once the fatal is gone, the same measurement habit is worth pointing at the database: autoloaded options are loaded on every single request, and a handful of leftover plugin settings can quietly add megabytes before any plugin runs. &lt;code&gt;wp option list --autoload=on --orderby=size --order=desc --fields=option_name,size&lt;/code&gt; prints them largest first, and anything left behind by a plugin you deleted is safe to remove.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/fix-wordpress-memory-exhausted-error/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Add Custom Fields to WooCommerce Checkout</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Fri, 13 Nov 2026 20:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/add-custom-fields-to-woocommerce-checkout-1gb2</link>
      <guid>https://dev.to/zubaer/add-custom-fields-to-woocommerce-checkout-1gb2</guid>
      <description>&lt;p&gt;To add a custom field to a WooCommerce checkout you need three hooks for the data path and two for display: &lt;code&gt;woocommerce_after_checkout_billing_form&lt;/code&gt; prints the input, &lt;code&gt;woocommerce_after_checkout_validation&lt;/code&gt; rejects bad values, &lt;code&gt;woocommerce_checkout_update_order_meta&lt;/code&gt; saves it, and then &lt;code&gt;woocommerce_admin_order_data_after_billing_address&lt;/code&gt; and &lt;code&gt;woocommerce_email_order_meta_fields&lt;/code&gt; put it on the order screen and in the emails. The popular version of that recipe does all five and still loses the value on a shop running HPOS, because it writes to post meta and trusts the request.&lt;/p&gt;

&lt;p&gt;Below is the snippet as it usually appears, then a refactor in four steps with the reason for each change. You need WooCommerce active and somewhere to put PHP. A small plugin or an mu-plugin beats functions.php here, because the field is order data and should outlive a theme switch.&lt;/p&gt;

&lt;h2&gt;
  
  
  The snippet most people start with, and what it actually stores
&lt;/h2&gt;

&lt;p&gt;This is close to the first thing you find for the search, and it looks fine on a test order placed by the person who wrote it.&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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_after_checkout_billing_form'&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="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;p class="form-row"&amp;gt;&amp;lt;label for="delivery_note"&amp;gt;Delivery note&amp;lt;/label&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;input type="text" id="delivery_note" name="delivery_note" /&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;/p&amp;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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_checkout_update_order_meta'&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;$order_id&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;update_post_meta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'delivery_note'&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="s1"&gt;'delivery_note'&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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_admin_order_data_after_billing_address'&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;$order&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;Delivery note:&amp;lt;/strong&amp;gt; '&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nf"&gt;get_post_meta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_id&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="s1"&gt;'delivery_note'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'&amp;lt;/p&amp;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;Four things are wrong with it, and none of them show up on the first checkout.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;update_post_meta()&lt;/code&gt; writes to &lt;code&gt;wp_postmeta&lt;/code&gt;. Orders lived there for years, so this worked. With HPOS an order is a row in &lt;code&gt;wc_orders&lt;/code&gt; and its meta is in &lt;code&gt;wc_orders_meta&lt;/code&gt;, and &lt;code&gt;$order-&amp;gt;get_meta()&lt;/code&gt; never looks at post meta. On an HPOS store WooCommerce keeps a placeholder row in &lt;code&gt;wp_posts&lt;/code&gt; with the same ID, so &lt;code&gt;update_post_meta()&lt;/code&gt; and &lt;code&gt;get_post_meta()&lt;/code&gt; still find each other and the order screen shows the note. Everything that reads the order the supported way does not: &lt;code&gt;$order-&amp;gt;get_meta()&lt;/code&gt;, the REST API, exports and other plugins all see nothing. The &lt;a href="https://wptutshub.com/woocommerce-hpos-custom-order-meta-migration/" rel="noopener noreferrer"&gt;HPOS custom order meta migration&lt;/a&gt; post goes further into what to do with orders created before the switch.&lt;/p&gt;

&lt;p&gt;The second problem is &lt;code&gt;$_POST['delivery_note']&lt;/code&gt; read without checking it exists. On the block checkout, or when another plugin removes the field, PHP raises "Undefined array key" on every order. With &lt;code&gt;WP_DEBUG_DISPLAY&lt;/code&gt; on, that warning is printed into the checkout AJAX response and the spinner never resolves.&lt;/p&gt;

&lt;p&gt;Third, nothing is sanitised. A customer can type &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; into a text input, it goes into the database as typed, and it comes back out as typed on the order screen. That is stored XSS aimed at whoever opens the order, usually a shop manager with more capabilities than the customer. Emails are less exposed because WooCommerce runs the value through &lt;code&gt;wp_kses_post()&lt;/code&gt;; the admin screen is not.&lt;/p&gt;

&lt;p&gt;The snippet above on an HPOS store, after a customer typed a note with a script tag in it (test site: WordPress 7.1.3, WooCommerce 11.2.2 with HPOS on, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Order #13, HPOS on: yes
get_post_meta( id, 'delivery_note' ):    'Leave by the door &amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;'
$order-&amp;gt;get_meta( 'delivery_note' ):     ''
$order-&amp;gt;get_meta( '_wpth_delivery_note' ): ''
Order screen prints: &amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;Delivery note:&amp;lt;/strong&amp;gt; Leave by the door &amp;lt;script&amp;gt;alert(document.cookie)&amp;lt;/script&amp;gt;&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The order screen line is exactly what a shop manager's browser receives: the script tag runs as soon as they open the order.&lt;/p&gt;

&lt;p&gt;Fourth, there is no length limit and no validation, so a 4,000 character paste ends up on a picking slip. The hand-written markup also misses the label association and the classes the rest of the form uses, which is why the field looks pasted in.&lt;/p&gt;

&lt;h2&gt;
  
  
  woocommerce_form_field gives you the wrapper, the label and the styling
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_after_checkout_billing_form'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_render_delivery_note_field'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_render_delivery_note_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$checkout&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;woocommerce_form_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'wpth_delivery_note'&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;'type'&lt;/span&gt;              &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'text'&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="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Delivery note'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'placeholder'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Gate code, safe place, neighbour'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'required'&lt;/span&gt;          &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'class'&lt;/span&gt;             &lt;span class="o"&gt;=&amp;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;'form-row-wide'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'custom_attributes'&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;'maxlength'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'200'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s1"&gt;'autocomplete'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'off'&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="nv"&gt;$checkout&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'wpth_delivery_note'&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;&lt;code&gt;woocommerce_form_field()&lt;/code&gt; is the helper WooCommerce uses for its own billing inputs. You pass a key, an argument array and a value, and it builds the &lt;code&gt;form-row&lt;/code&gt; wrapper, the label with a matching &lt;code&gt;for&lt;/code&gt;, the &lt;code&gt;input-text&lt;/code&gt; class and the placeholder. The field then lines up with the rest of the form and inherits whatever styling the theme applies to checkout inputs.&lt;/p&gt;

&lt;p&gt;The third argument is the current value. Passing &lt;code&gt;$checkout-&amp;gt;get_value( 'wpth_delivery_note' )&lt;/code&gt; lets WooCommerce repopulate the input from the posted data when the checkout is re-rendered after a validation error, so the customer does not retype the gate code.&lt;/p&gt;

&lt;p&gt;The classic checkout with the delivery note field at the end of the billing details (test site: WordPress 7.1.3, WooCommerce 11.2.2 with HPOS on, PHP 8.2)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;maxlength&lt;/code&gt; goes in &lt;code&gt;custom_attributes&lt;/code&gt; because that array is rendered straight onto the input element. Treat it as a hint for the browser, not a rule: anyone can remove it in devtools, which is why the next step repeats the limit on the server.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where to validate: woocommerce_after_checkout_validation, not the render callback
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_after_checkout_validation'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_validate_delivery_note'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_validate_delivery_note&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$errors&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="o"&gt;!&lt;/span&gt; &lt;span class="nb"&gt;isset&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="s1"&gt;'wpth_delivery_note'&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$raw&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_unslash&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="s1"&gt;'wpth_delivery_note'&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;$note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;is_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$raw&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;sanitize_text_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$raw&lt;/span&gt; &lt;span class="p"&gt;)&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;is_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$raw&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$raw&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$errors&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="s1"&gt;'wpth_delivery_note_unreadable'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'That delivery note could not be read. Please type it again.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth'&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="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="nf"&gt;mb_strlen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$errors&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="s1"&gt;'wpth_delivery_note_length'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Please keep the delivery note under 200 characters.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth'&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;preg_match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'#https?://#i'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$note&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;$errors&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="s1"&gt;'wpth_delivery_note_url'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Please do not put links in the delivery note.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth'&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;&lt;code&gt;woocommerce_checkout_process&lt;/code&gt; is the hook most snippets use, and it works: add a notice with type &lt;code&gt;error&lt;/code&gt; and checkout stops. &lt;code&gt;woocommerce_after_checkout_validation&lt;/code&gt; is the better place because it hands you a &lt;code&gt;WP_Error&lt;/code&gt; object and runs after WooCommerce has checked its own fields, so you add one message instead of racing the core checks.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;$data&lt;/code&gt; argument is not the whole request. &lt;code&gt;WC_Checkout::get_posted_data()&lt;/code&gt; builds it from the fields registered through &lt;code&gt;woocommerce_checkout_fields&lt;/code&gt;, so a field added with &lt;code&gt;woocommerce_after_checkout_billing_form&lt;/code&gt; is not in there. Read &lt;code&gt;$_POST&lt;/code&gt; and treat it as hostile.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;wp_unslash()&lt;/code&gt; comes first because WordPress slashes every superglobal on load; sanitising comes second. The &lt;code&gt;is_string()&lt;/code&gt; guard makes the intent explicit. A request with &lt;code&gt;wpth_delivery_note[]=x&lt;/code&gt; posts an array; &lt;code&gt;sanitize_text_field()&lt;/code&gt; turns an array into an empty string rather than failing, so without the guard an array would quietly become an empty note. With it, you decide.&lt;/p&gt;

&lt;p&gt;woocommerce_after_checkout_validation run against four inputs (test site: WordPress 7.1.3, WooCommerce 11.2.2 with HPOS on, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a 250-character note   -&amp;gt; Please keep the delivery note under 200 characters.
a note with a link     -&amp;gt; Please do not put links in the delivery note.
an array (note[]=x)    -&amp;gt; accepted
a normal note          -&amp;gt; accepted

sanitize_text_field( array( 'x' ) ) returns: ''
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;$errors-&amp;gt;add()&lt;/code&gt; takes a code and a message. The code is what you grep for later, so make it unique to the field rather than reusing &lt;code&gt;invalid_postcode&lt;/code&gt;. To see the error path without a real payment, submit the checkout with a 250 character note: the notice appears above the payment box and no order is created.&lt;/p&gt;

&lt;h2&gt;
  
  
  Saving through the order object is what keeps the value under HPOS
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_checkout_update_order_meta'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_save_delivery_note'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_save_delivery_note&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$order_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$data&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="o"&gt;!&lt;/span&gt; &lt;span class="nb"&gt;isset&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="s1"&gt;'wpth_delivery_note'&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$raw&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_unslash&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="s1"&gt;'wpth_delivery_note'&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;$note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;is_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$raw&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;sanitize_text_field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$raw&lt;/span&gt; &lt;span class="p"&gt;)&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="nv"&gt;$order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wc_get_order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$order_id&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="o"&gt;!&lt;/span&gt; &lt;span class="nv"&gt;$order&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="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="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;delete_meta_data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'_wpth_delivery_note'&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;update_meta_data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'_wpth_delivery_note'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$note&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;$order&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;save&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;&lt;code&gt;wc_get_order()&lt;/code&gt; returns the order whichever storage is active, and &lt;code&gt;update_meta_data()&lt;/code&gt; followed by &lt;code&gt;save()&lt;/code&gt; writes to the right table. That is the whole HPOS fix: no &lt;code&gt;update_post_meta()&lt;/code&gt;, no &lt;code&gt;get_post_meta()&lt;/code&gt;, no branching on which storage the shop uses.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;_wpth_&lt;/code&gt; prefix avoids collisions with other plugins, and the leading underscore hides the key from the legacy custom fields box, which is what you want for a value the customer should not edit from the order screen.&lt;/p&gt;

&lt;p&gt;Deleting on empty matters more than it looks. Without it, a customer who clears the field on a second attempt leaves the old note attached, and the warehouse reads a gate code that no longer applies.&lt;/p&gt;

&lt;p&gt;The same script-tag note saved through the order object, and read back (test site: WordPress 7.1.3, WooCommerce 11.2.2 with HPOS on, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Order #13, HPOS on: yes
get_post_meta( id, 'delivery_note' ):    ''
$order-&amp;gt;get_meta( 'delivery_note' ):     ''
$order-&amp;gt;get_meta( '_wpth_delivery_note' ): 'Leave by the door'
Order screen prints: &amp;lt;p class="wpth-delivery-note"&amp;gt;&amp;lt;strong&amp;gt;Delivery note&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;Leave by the door&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;sanitize_text_field()&lt;/code&gt; removed the tag on the way in, and the order screen line is plain text.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;woocommerce_checkout_create_order&lt;/code&gt; is the other place to save. It passes the order object before it is written, so you call &lt;code&gt;$order-&amp;gt;update_meta_data()&lt;/code&gt; and let WooCommerce do the &lt;code&gt;save()&lt;/code&gt;. Either hook works; &lt;code&gt;woocommerce_checkout_update_order_meta&lt;/code&gt; passes the ID, which is why older snippets use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The order screen and the emails need two separate display hooks
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_admin_order_data_after_billing_address'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_show_delivery_note_in_admin'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_show_delivery_note_in_admin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$order&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_meta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'_wpth_delivery_note'&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="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$note&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'&amp;lt;p class="wpth-delivery-note"&amp;gt;&amp;lt;strong&amp;gt;%s&amp;lt;/strong&amp;gt;&amp;lt;br /&amp;gt;%s&amp;lt;/p&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nf"&gt;esc_html__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Delivery note'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$note&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="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_email_order_meta_fields'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_add_delivery_note_to_emails'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_add_delivery_note_to_emails&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$fields&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$sent_to_admin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$order&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$order&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get_meta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'_wpth_delivery_note'&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="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$note&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="nv"&gt;$fields&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$fields&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'wpth_delivery_note'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&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;'label'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Delivery note'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'value'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$note&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="nv"&gt;$fields&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;&lt;code&gt;woocommerce_admin_order_data_after_billing_address&lt;/code&gt; fires inside the billing box on both the legacy order screen and the HPOS one, so the note sits where the person packing the parcel is already looking. &lt;code&gt;esc_html()&lt;/code&gt; on the way out is the second half of the XSS fix: sanitising on save protects new orders, escaping on output protects the ones already in the database with a script tag in them.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;woocommerce_email_order_meta_fields&lt;/code&gt; adds a row to the order details table in every WooCommerce email, customer and admin. The &lt;code&gt;$sent_to_admin&lt;/code&gt; argument is there if you want the note only in the admin copy. The value is printed through &lt;code&gt;wp_kses_post()&lt;/code&gt;, so a stray bracket will not break the email layout, but that is not a substitute for sanitising at save time.&lt;/p&gt;

&lt;p&gt;For the customer-facing side, &lt;code&gt;woocommerce_order_details_after_order_table&lt;/code&gt; prints the same value on the thank-you page and under My Account. Same &lt;code&gt;get_meta()&lt;/code&gt; call, same escaping.&lt;/p&gt;

&lt;p&gt;The email field the filter adds (same test site):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Email fields: {"wpth_delivery_note":{"label":"Delivery note","value":"Leave by the door"}}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The HPOS order edit screen with the delivery note under the billing address (test site: WordPress 7.1.3, WooCommerce 11.2.2 with HPOS on, PHP 8.2)&lt;/p&gt;

&lt;h2&gt;
  
  
  The block checkout never runs woocommerce_after_checkout_billing_form
&lt;/h2&gt;

&lt;p&gt;If the Checkout page contains the Checkout block instead of the &lt;code&gt;[woocommerce_checkout]&lt;/code&gt; shortcode, none of the rendering above happens. The block is rendered by React from the Store API, and the classic form hooks do not exist in that tree. New WooCommerce installs create block checkout pages, so this is the default on a fresh shop rather than an edge case.&lt;/p&gt;

&lt;p&gt;The supported route is the Additional Checkout Fields API, available since WooCommerce 8.9.&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="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_init'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth_register_delivery_note_block_field'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_register_delivery_note_block_field&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;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;function_exists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'woocommerce_register_additional_checkout_field'&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;woocommerce_register_additional_checkout_field&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;'id'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'wpth/delivery-note'&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="nf"&gt;__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'Delivery note'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'wpth'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'location'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'order'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'type'&lt;/span&gt;     &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'required'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&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 &lt;code&gt;id&lt;/code&gt; has to be namespaced, &lt;code&gt;location&lt;/code&gt; decides where the field appears (&lt;code&gt;contact&lt;/code&gt;, &lt;code&gt;address&lt;/code&gt; or &lt;code&gt;order&lt;/code&gt;), and &lt;code&gt;type&lt;/code&gt; is &lt;code&gt;text&lt;/code&gt;, &lt;code&gt;select&lt;/code&gt; or &lt;code&gt;checkbox&lt;/code&gt;. WooCommerce renders it, validates it and saves it. The value lands in order meta under &lt;code&gt;_wc_other/&lt;/code&gt; followed by the field id, so &lt;code&gt;$order-&amp;gt;get_meta( '_wc_other/wpth/delivery-note' )&lt;/code&gt; reads it back and the admin and email callbacks above work once you point them at that key. If the key looks different on your install, dump &lt;code&gt;$order-&amp;gt;get_meta_data()&lt;/code&gt; once and read it off.&lt;/p&gt;

&lt;p&gt;Whether these fields also appear in the shortcode checkout depends on your WooCommerce version, so test both before deleting the classic hooks. Registering the field while the classic callbacks are still active is safe, because the block checkout ignores the classic ones.&lt;/p&gt;

&lt;p&gt;The block checkout with the delivery note registered through the Additional Checkout Fields API (test site: WordPress 7.1.3, WooCommerce 11.2.2 with HPOS on, PHP 8.2)&lt;/p&gt;

&lt;p&gt;The meta WooCommerce writes when the block checkout saves the field (same test site):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;meta key _billing_address_index =           
meta key _shipping_address_index =          
meta key _wc_other/wpth/delivery-note = Leave at the back door
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Checking the saved value from the command line
&lt;/h2&gt;

&lt;p&gt;When the field saves but does not display, or displays but does not save, the question is which half is broken. Read the meta straight off the order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'
$order = wc_get_order( 123 );
echo $order-&amp;gt;get_meta( "_wpth_delivery_note" ), PHP_EOL;
'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An empty result means the save hook did not run, so check which checkout form is actually rendering. A value here with nothing on the order screen means the display callback is attached to something that is not being rendered, usually a legacy meta box on a store that has moved to HPOS.&lt;/p&gt;

&lt;p&gt;If customers cannot get past the shipping step at all, that is a different problem: &lt;a href="https://wptutshub.com/no-shipping-options-available-woocommerce/" rel="noopener noreferrer"&gt;no shipping options available in WooCommerce&lt;/a&gt; walks through it.&lt;/p&gt;

&lt;p&gt;One follow-up worth the time: put the note in the orders list so nobody opens each order to read it. On HPOS the column filter is &lt;code&gt;woocommerce_shop_order_list_table_columns&lt;/code&gt; and the render hook is &lt;code&gt;woocommerce_shop_order_list_table_custom_column&lt;/code&gt;; on the legacy list it is &lt;code&gt;manage_edit-shop_order_columns&lt;/code&gt; with &lt;code&gt;manage_shop_order_posts_custom_column&lt;/code&gt;. Two callbacks, one &lt;code&gt;get_meta()&lt;/code&gt; call, and the packing bench stops clicking.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/add-custom-field-woocommerce-checkout/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>woocommerce</category>
      <category>php</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>Increase WordPress Max Upload File Size</title>
      <dc:creator>Md. Zubaer Ahammed</dc:creator>
      <pubDate>Thu, 12 Nov 2026 16:00:32 +0000</pubDate>
      <link>https://dev.to/zubaer/increase-wordpress-max-upload-file-size-58ae</link>
      <guid>https://dev.to/zubaer/increase-wordpress-max-upload-file-size-58ae</guid>
      <description>&lt;h2&gt;
  
  
  WordPress never sets the upload ceiling — PHP does
&lt;/h2&gt;

&lt;p&gt;To increase the WordPress max upload file size you change a PHP directive, not a WordPress setting. The number in the media library comes from &lt;a href="https://developer.wordpress.org/reference/functions/wp_max_upload_size/" rel="noopener noreferrer"&gt;wp_max_upload_size()&lt;/a&gt;, which reads &lt;code&gt;upload_max_filesize&lt;/code&gt; and &lt;code&gt;post_max_size&lt;/code&gt; with &lt;code&gt;ini_get()&lt;/code&gt; and returns whichever is smaller. Both directives are &lt;code&gt;PHP_INI_PERDIR&lt;/code&gt;: they can be set in php.ini, .user.ini, httpd.conf or .htaccess, and &lt;code&gt;ini_set()&lt;/code&gt; at runtime returns &lt;code&gt;false&lt;/code&gt;. That single fact explains why so many "increase upload size" snippets appear to work and then fail on the first real upload.&lt;/p&gt;

&lt;p&gt;You need shell or hosting-panel access to the server, the ability to restart PHP (or the patience to wait out the .user.ini cache), and a test file large enough to prove the change. Everything below assumes you can reach php.ini or the WordPress document root.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three places to change the limit, and how to tell which one your host honours
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Hosting panel or php.ini&lt;/strong&gt; — the reliable route. cPanel has MultiPHP INI Editor, Plesk has PHP Settings, and most managed hosts expose a PHP configuration screen. On a VPS you edit &lt;code&gt;/etc/php/8.2/fpm/php.ini&lt;/code&gt; and restart the FPM service. This survives WordPress and plugin updates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.user.ini in the WordPress root&lt;/strong&gt; — the same directives in a plain text file, read by PHP-FPM and other FastCGI SAPIs. It is cached for &lt;code&gt;user_ini.cache_ttl&lt;/code&gt; seconds (300 by default), so an edit can take five minutes to appear. mod_php ignores it entirely.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.htaccess with &lt;code&gt;php_value&lt;/code&gt;&lt;/strong&gt; — only when PHP runs as an Apache module. On PHP-FPM, LiteSpeed or suPHP it either does nothing or throws a 500. Use it only after confirming mod_php is in play.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Choose by what the host gives you, not by what the snippet you found uses. A panel writes the correct file for the correct SAPI and restarts the pool for you. .user.ini is the fallback when there is no PHP settings screen but you can upload files to the document root. .htaccess belongs to legacy mod_php stacks and should be removed again the moment the host migrates to FPM.&lt;/p&gt;

&lt;h2&gt;
  
  
  The php.ini values that have to move together
&lt;/h2&gt;

&lt;p&gt;Raising one directive is the classic mistake. &lt;code&gt;upload_max_filesize&lt;/code&gt; caps a single file; &lt;code&gt;post_max_size&lt;/code&gt; caps the whole request body, multipart wrapper included. If &lt;code&gt;post_max_size&lt;/code&gt; is smaller, PHP discards the request before WordPress sees it: &lt;code&gt;$_FILES&lt;/code&gt; is empty, &lt;code&gt;$_POST&lt;/code&gt; is empty, and the form appears to do nothing at all — no error, no log entry.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c1"&gt;; php.ini or .user.ini — no trailing comments after a value
&lt;/span&gt;&lt;span class="na"&gt;file_uploads&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;On&lt;/span&gt;
&lt;span class="na"&gt;upload_max_filesize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;64M&lt;/span&gt;
&lt;span class="na"&gt;post_max_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;68M&lt;/span&gt;
&lt;span class="na"&gt;memory_limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;256M&lt;/span&gt;
&lt;span class="na"&gt;max_execution_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;
&lt;span class="na"&gt;max_input_time&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why each line matters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;upload_max_filesize&lt;/code&gt; — the per-file ceiling. This is the number the media library prints.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;post_max_size&lt;/code&gt; — set it a few megabytes above the file limit so the multipart wrapper and any extra form fields still fit.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;memory_limit&lt;/code&gt; — at least as large as &lt;code&gt;post_max_size&lt;/code&gt;, realistically two to three times larger. WordPress loads the image into memory to generate sub-sizes, and GD or Imagick needs several copies of the pixel data, not just the compressed file size.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;max_execution_time&lt;/code&gt; and &lt;code&gt;max_input_time&lt;/code&gt; — a 60 MB file on a slow connection takes longer than the default 30 seconds to arrive, and the request dies mid-upload.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;file_uploads&lt;/code&gt; — if this is Off, no upload can succeed regardless of the other values.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Restart PHP-FPM or Apache after editing php.ini. Saving the file without a reload changes nothing, and it is the most common reason a correct edit appears to have no effect.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  When .htaccess is the right file, and when it takes the site down
&lt;/h2&gt;

&lt;p&gt;Apache only, mod_php only. The &lt;code&gt;&amp;lt;IfModule&amp;gt;&lt;/code&gt; guard stops the block from being fatal on a server without that module — which also means a wrong module name fails silently instead of loudly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Only honoured when PHP runs as an Apache module (mod_php).
# Module names differ between builds: mod_php.c, mod_php7.c, mod_php8.c.
&amp;lt;IfModule mod_php.c&amp;gt;
    php_value upload_max_filesize 64M
    php_value post_max_size 68M
    php_value memory_limit 256M
    php_value max_execution_time 300
&amp;lt;/IfModule&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two failure modes to recognise. A 500 Internal Server Error immediately after saving means PHP is not running as a module — delete the block and switch to .user.ini. A site that loads normally but still reports the old limit means the &lt;code&gt;&amp;lt;IfModule&amp;gt;&lt;/code&gt; name did not match, so Apache skipped everything inside it. Check with &lt;code&gt;wp eval 'echo php_sapi_name();'&lt;/code&gt;: &lt;code&gt;apache2handler&lt;/code&gt; means mod_php, &lt;code&gt;fpm-fcgi&lt;/code&gt; means .htaccess will never work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multisite adds a second ceiling above the PHP one
&lt;/h2&gt;

&lt;p&gt;On a network, Network Admin → Settings → &lt;strong&gt;Max upload file size&lt;/strong&gt; caps every site in the network on top of the PHP values. It is stored as the &lt;code&gt;fileupload_maxk&lt;/code&gt; site option in kilobytes, so the default 1500 means roughly 1.5 MB. Raising php.ini to 64 MB while that field still says 1500 leaves you at 1.5 MB, and the media library will keep reporting the smaller number. Change both, then check a single site's Media → Add New screen rather than the network admin.&lt;/p&gt;

&lt;p&gt;Per-site storage quotas are a separate wall. If a site has a quota set and it is full, the upload is rejected with a quota message even though the file is well under the size limit. Network Admin → Sites → Edit → Settings shows the quota, and the &lt;code&gt;upload_space_check_disabled&lt;/code&gt; site option turns the check off for the whole network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build a diagnostics panel that reads the values PHP actually reports
&lt;/h2&gt;

&lt;p&gt;Rather than guessing which php.ini won, print the live values from inside WordPress. This must-use plugin adds Tools → Upload Limits, compares each directive against a target, and flags the combinations that break uploads. It belongs in &lt;code&gt;wp-content/mu-plugins/&lt;/code&gt; so it loads before ordinary plugins and cannot be deactivated by accident.&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="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="cm"&gt;/**
 * Plugin Name: WPTH Upload Limit Diagnostics
 * Description: Prints the PHP upload limits that actually apply and flags mismatches between them.
 * Version:     1.0.0
 */&lt;/span&gt;

&lt;span class="nf"&gt;defined&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'ABSPATH'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Convert a php.ini shorthand size (64M, 1G, 524288) to bytes.
 * Returns -1 for the unlimited sentinel that memory_limit accepts.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_ini_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$value&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="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$value&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="mi"&gt;0&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="s1"&gt;'-1'&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$value&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="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;strtolower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&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;case&lt;/span&gt; &lt;span class="s1"&gt;'g'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nv"&gt;$number&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="c1"&gt;// Fall through to megabytes.&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'m'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nv"&gt;$number&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="c1"&gt;// Fall through to kilobytes.&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'k'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="nv"&gt;$number&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;1024&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="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * The values the server should end up with. Filterable per site.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_upload_targets&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="kt"&gt;array&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="kt"&gt;array&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;apply_filters&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s1"&gt;'wpth_upload_targets'&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;'upload_max_filesize'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'64M'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'post_max_size'&lt;/span&gt;       &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'68M'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'memory_limit'&lt;/span&gt;        &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'256M'&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="cm"&gt;/**
 * Compare the live ini values against the targets.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_upload_report&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="kt"&gt;array&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$report&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;array&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="nf"&gt;wpth_upload_targets&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;$directive&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$target&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$directive&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$have&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wpth_ini_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$current&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nv"&gt;$want&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wpth_ini_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$target&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$directive&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&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;'current'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$current&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'target'&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;$target&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'ok'&lt;/span&gt;      &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$have&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$have&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nv"&gt;$want&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;return&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * Combinations that break uploads even when each directive looks fine.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_upload_checks&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="kt"&gt;array&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$report&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wpth_upload_report&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;$upload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wpth_ini_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'upload_max_filesize'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'current'&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;$post&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wpth_ini_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'post_max_size'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'current'&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;$memory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wpth_ini_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'memory_limit'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'current'&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;$time&lt;/span&gt;   &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'max_execution_time'&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;array&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;'label'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'file_uploads is enabled'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'ok'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'file_uploads'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'note'&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;ini_get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'file_uploads'&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'On'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Off - every upload is rejected.'&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="kt"&gt;array&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;'post_max_size covers upload_max_filesize'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'ok'&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="nv"&gt;$upload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'note'&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'post_max_size %s vs upload_max_filesize %s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'post_max_size'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'current'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'upload_max_filesize'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'current'&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="kt"&gt;array&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;'memory_limit leaves room to process the file'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'ok'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$memory&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$memory&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'note'&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'memory_limit %s vs post_max_size %s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'memory_limit'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'current'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$report&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'post_max_size'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'current'&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="kt"&gt;array&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;'max_execution_time allows a slow upload to finish'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'ok'&lt;/span&gt;    &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$time&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$time&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'note'&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'max_execution_time %d seconds'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$time&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;span class="cm"&gt;/**
 * The block to paste into php.ini or .user.ini.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_upload_ini_snippet&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="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$lines&lt;/span&gt; &lt;span class="o"&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;'; Raise the ceiling for large media, plugin and theme ZIPs.'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'file_uploads = On'&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="nf"&gt;wpth_upload_targets&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;$directive&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$target&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'%s = %s'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$directive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$target&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;$lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'max_execution_time = 300'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nv"&gt;$lines&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'max_input_time = 300'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;implode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"\n"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$lines&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="cm"&gt;/**
 * Tools -&amp;gt; Upload Limits.
 */&lt;/span&gt;
&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;wpth_render_upload_limits_page&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="kt"&gt;void&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="o"&gt;!&lt;/span&gt; &lt;span class="nf"&gt;current_user_can&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'manage_options'&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="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$report&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wpth_upload_report&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;$checks&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wpth_upload_checks&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;$ceiling&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;wp_max_upload_size&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"wrap"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Upload&lt;/span&gt; &lt;span class="nc"&gt;Limit&lt;/span&gt; &lt;span class="nc"&gt;Diagnostics&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;These&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="n"&gt;come&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;ini_get&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;lt;/&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;media&lt;/span&gt; &lt;span class="n"&gt;library&lt;/span&gt; &lt;span class="n"&gt;prints&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Effective&lt;/span&gt; &lt;span class="nc"&gt;WordPress&lt;/span&gt; &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$ceiling&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;size_format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$ceiling&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="s1"&gt;'uploads disabled'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;?&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"widefat striped"&lt;/span&gt; &lt;span class="n"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"max-width:900px"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;thead&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;tr&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;th&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"col"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Directive&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;th&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;th&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"col"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Current&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;th&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;th&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"col"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Target&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;th&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;th&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"col"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Status&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;th&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;tr&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;thead&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;tbody&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&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;$report&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$directive&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$row&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;tr&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;td&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$directive&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;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;td&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;td&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'current'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'(empty)'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'current'&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;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;td&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;td&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'target'&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;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;td&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;td&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ok'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'OK'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Below target'&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;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;td&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;tr&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;endforeach&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;?&amp;gt;&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;tbody&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Consistency&lt;/span&gt; &lt;span class="n"&gt;checks&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&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;$checks&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$check&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;strong&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$check&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ok'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'OK'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'FAIL'&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;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;strong&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;
                &lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$check&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'label'&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="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$check&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'note'&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="p"&gt;)&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;li&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;endforeach&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="o"&gt;?&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nc"&gt;Paste&lt;/span&gt; &lt;span class="n"&gt;this&lt;/span&gt; &lt;span class="n"&gt;into&lt;/span&gt; &lt;span class="n"&gt;php&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ini&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ini&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;h2&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;pre&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="nf"&gt;esc_html&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;wpth_upload_ini_snippet&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;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;pre&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;add_action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s1"&gt;'admin_menu'&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="nf"&gt;add_management_page&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s1"&gt;'Upload Limit Diagnostics'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'Upload Limits'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'manage_options'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'wpth-upload-limits'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s1"&gt;'wpth_render_upload_limits_page'&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;Three details in that file are worth copying into your own diagnostics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ini_get()&lt;/code&gt; rather than &lt;code&gt;wp_max_upload_size()&lt;/code&gt; for the table.&lt;/strong&gt; The WordPress function returns one combined number; you need to see which of the two directives is the smaller one before you can fix it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A shorthand parser.&lt;/strong&gt; &lt;code&gt;ini_get()&lt;/code&gt; returns the string exactly as written — &lt;code&gt;64M&lt;/code&gt;, &lt;code&gt;1G&lt;/code&gt;, &lt;code&gt;524288&lt;/code&gt; — so every comparison has to happen in bytes. The deliberate switch fall-through converts G to M to K to bytes in a single pass.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The &lt;code&gt;-1&lt;/code&gt; sentinel.&lt;/strong&gt; &lt;code&gt;memory_limit = -1&lt;/code&gt; means unlimited, and a naive byte comparison would report it as the smallest value on the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Targets are filterable through &lt;code&gt;wpth_upload_targets&lt;/code&gt;, so a site that only needs 8 MB can lower them without editing the plugin, and a staging copy can raise them without a second file.&lt;/p&gt;

&lt;p&gt;Tools → Upload Limits showing the live ini values, the targets and the consistency checks (test site: WordPress 7.1.3, PHP 8.2)&lt;/p&gt;

&lt;h2&gt;
  
  
  Read the same numbers from WP-CLI before you open the browser
&lt;/h2&gt;

&lt;p&gt;WP-CLI runs under the command-line SAPI, which often uses a different php.ini from the FPM pool that serves the site. That makes it a fast way to confirm which file you edited — and a trap if you assume the CLI values are the web values.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'foreach ( array( "upload_max_filesize", "post_max_size", "memory_limit", "max_execution_time", "file_uploads" ) as $directive ) { printf( "%-22s %s\n", $directive, ini_get( $directive ) ); }'&lt;/span&gt;

wp &lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s1"&gt;'echo size_format( wp_max_upload_size() ), "\n";'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the CLI shows 64M and the diagnostics page shows 2M, you edited the CLI ini and the web pool is still on its own file. Look in &lt;code&gt;/etc/php/8.2/fpm/pool.d/*.conf&lt;/code&gt; for a &lt;code&gt;php_admin_value[upload_max_filesize]&lt;/code&gt; line: a pool-level value overrides php.ini and cannot be changed from .user.ini at all.&lt;/p&gt;

&lt;p&gt;The five PHP directives the tutorial edits, as reported by ini_get() under WP-CLI (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;upload_max_filesize    2M
post_max_size          8M
memory_limit           -1
max_execution_time     0
file_uploads           1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Prove it with a real upload, then read the failure mode
&lt;/h2&gt;

&lt;p&gt;Numbers in a table are not proof. Upload a file just under the new limit through Media → Add New, and check that the thumbnail is generated as well as the file arriving — thumbnail generation is where &lt;code&gt;memory_limit&lt;/code&gt; shows up. If the media library still prints the old figure, the change never reached the SAPI that serves the site.&lt;/p&gt;

&lt;p&gt;When it still fails, the error tells you which layer rejected it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;The uploaded file exceeds the upload_max_filesize directive in php.ini&lt;/em&gt; — PHP rejected the file. The web pool is still on the old value, or a pool-level &lt;code&gt;php_admin_value&lt;/code&gt; is overriding you.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Nothing happens, no error, empty media library&lt;/em&gt; — &lt;code&gt;post_max_size&lt;/code&gt; is smaller than the file. PHP discarded the request body silently, so there is nothing for WordPress to report.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;File uploads but no thumbnail, or a white screen&lt;/em&gt; — &lt;code&gt;memory_limit&lt;/code&gt; ran out inside &lt;code&gt;WP_Image_Editor&lt;/code&gt;. Raise it to at least twice &lt;code&gt;post_max_size&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Request times out at 30 or 60 seconds&lt;/em&gt; — &lt;code&gt;max_execution_time&lt;/code&gt;, &lt;code&gt;max_input_time&lt;/code&gt;, or a proxy in front of PHP.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;413 Request Entity Too Large from nginx or a CDN&lt;/em&gt; — PHP was never reached. nginx needs &lt;code&gt;client_max_body_size 68m;&lt;/code&gt; in the server block, and Cloudflare's free plan stops at 100 MB regardless of your php.ini.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Do not reach for &lt;code&gt;wp media import&lt;/code&gt; to script this check. It copies a file that is already on the server, so it never meets &lt;code&gt;upload_max_filesize&lt;/code&gt; or &lt;code&gt;post_max_size&lt;/code&gt;: on the test site it imported a 5 MB file while the limit was 2M and exited with 0. Only a real upload, through the browser or an HTTP request, exercises the limits.&lt;/p&gt;

&lt;p&gt;wp media import accepting a 5 MB file while upload_max_filesize is 2M (test site: WordPress 7.1.3, PHP 8.2):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ wp eval 'echo ini_get( "upload_max_filesize" ), "\n";'
2M

$ head -c 5242880 /dev/urandom &amp;gt; /tmp/large-test.zip &amp;amp;&amp;amp; ls -lh /tmp/large-test.zip | awk '{print $5, $9}'
5.0M /tmp/large-test.zip

$ wp media import /tmp/large-test.zip --porcelain; echo "exit code: $?"
5
exit code: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The filter that changes the label and nothing else
&lt;/h2&gt;

&lt;p&gt;You will find snippets that add an &lt;code&gt;upload_size_limit&lt;/code&gt; filter and claim to raise the limit. They change what &lt;code&gt;wp_max_upload_size()&lt;/code&gt; returns, which is what the media library prints — and nothing else. PHP still aborts at &lt;code&gt;upload_max_filesize&lt;/code&gt;, so the user sees a generous number, picks a large file, and gets a generic failure with no explanation.&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;// Do not use this to raise the ceiling. It only changes the number on screen.&lt;/span&gt;
&lt;span class="nf"&gt;add_filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s1"&gt;'upload_size_limit'&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;$bytes&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="mi"&gt;512&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;MB_IN_BYTES&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 filter is still useful in the other direction: return a smaller number to stop a role from filling the disk, or to keep a staging site from accepting 200 MB imports. Just never use it to advertise a limit the server will not honour — the mismatch is invisible until someone tries it.&lt;/p&gt;

&lt;p&gt;A useful follow-up: register a &lt;code&gt;site_status_tests&lt;/code&gt; entry that fails when &lt;code&gt;post_max_size&lt;/code&gt; is smaller than &lt;code&gt;upload_max_filesize&lt;/code&gt;, or when &lt;code&gt;memory_limit&lt;/code&gt; sits below &lt;code&gt;post_max_size&lt;/code&gt;. Site Health then reports the mismatch on every site you manage, instead of waiting for a client to hit it halfway through a theme upload.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://wptutshub.com/increase-wordpress-max-upload-file-size/" rel="noopener noreferrer"&gt;WP Tuts Hub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>wordpress</category>
      <category>php</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
