← All updates

Engineering / Field note

WordPress metadata escaping can change the bytes a hash protects

WordPress’s documented post-metadata escaping convention can change JSON strings before storage. An integrity check becomes easier to interpret when the protected representation is clear.

By Zyel · Published · 4 min read

WordPress documents a longstanding convention that can surprise an application storing JSON in post metadata. For historical reasons, update_post_meta expects slashed keys and values on input. Its reference warns that removing slashes during storage can change JSON containing escaped characters. This is documented API behavior, not a new security advisory. [1]

The reference illustrates a JSON string with embedded quotation marks becoming unparsable after its escaping is removed. It describes an additional escaping layer through wp_slash as compensation for that transformation. The important detail is the representation the metadata API expects to receive. [1]

Our interpretation is that this convention makes the location of an integrity check consequential. A digest calculated over the application’s original string describes that string. A later comparison against a representation changed along the storage path can report a mismatch even when nobody intended to edit the underlying document.

Consider a hypothetical editorial plugin storing a JSON description of review requirements. The plugin also records a content hash so a later decision can refer to the reviewed version. If the saved string differs from the reviewed string, the mismatch is meaningful: the two pieces of evidence no longer describe the same bytes. This is an illustrative design problem, not a report of a customer incident.

The same meaning does not require the same bytes

JSON’s specification allows insignificant whitespace around its structural characters and defines an object as an unordered collection of name/value pairs. RFC 8259 was published in December 2017; it supplies longstanding format rules rather than evidence of a recent WordPress change. [3]

For an integrity review, that distinction separates two possible requirements. One asks whether a stored document has exactly the representation that was approved. Another asks whether it expresses equivalent data under an agreed interpretation. Those requirements can be useful for different purposes, but a result needs to say which one it answers.

The WordPress example is more serious than harmless formatting variation: removing required escaping can make the JSON invalid. A document that no longer parses cannot be treated as an equivalent JSON value merely because the visible words look familiar. [1]

In our view, an automatic cleanup deserves the same scrutiny as any other transformation. Trimming, decoding or rewriting a document after approval changes the evidence relationship unless that transformation was part of the agreed representation. A tidy-looking readback is a presentation result; it leaves the integrity question unresolved.

Escaping belongs to a particular interface

WordPress describes wp_slash as preparation for core APIs that expect slashed input. It expressly says the function is not for escaping data sent directly to an SQL query. That documented limit matters when the word escaping starts standing in for several different responsibilities. [2]

Our reading is that the API convention, the application’s document format and its integrity decision need separate meanings. A transformation intended for one boundary does not establish that another boundary received the intended representation. Treating every extra backslash as interchangeable makes that relationship harder to explain.

The metadata reference also gives different return meanings: an identifier for a newly added field, true for a successful update, and false for either failure or an unchanged value. A false result alone therefore does not establish a failed write. [1]

For a reviewer, this creates a second distinction: the operation’s return value and the content later observed are separate evidence. An application can need both. A useful record makes clear which document was reviewed, which representation was stored and what the later comparison actually established.

A mismatch should preserve the question

A hypothetical hash mismatch can indicate an unexpected transformation, an outdated reference or an unauthorised change. The mismatch itself does not select among those explanations. Bypassing it to make a workflow continue would remove the signal before its cause was understood.

The operational consequence is a clearer handoff between whoever defines the data representation and whoever relies on it. If an approval, import or publication decision depends on exact content, both sides need the same account of that content. Otherwise, the next operator inherits two successful-looking stages with an unexplained gap between them.

The public references, checked on November 18, 2026, explain a narrow but durable engineering issue: storage APIs can have input conventions that matter to content identity. A useful integrity check keeps those conventions visible and keeps an unresolved difference available for investigation. The hash can raise the question; the surrounding evidence has to explain the answer.

Sources + further reading

Source dates describe the original material. Publication above is the date this Zyel article went live.

  1. update_post_meta: character escaping and return valuesWordPress Developer Resources · Checked Nov 18, 2026
  2. wp_slash: the contract for slashed API inputWordPress Developer Resources · Checked Nov 18, 2026
  3. RFC 8259: the JSON data interchange formatIETF / RFC Editor · Checked Nov 18, 2026

Reader discussion

What would you ask next?

Questions, useful corrections and thoughtful disagreement are welcome. Comments are reviewed before they appear.

No reader comments yet.

10–2,000 characters. Plain text. Leave out passwords, private project data and personal contact details. A blank display name appears as Anonymous.

Complete the CAPTCHA before sending. Verification runs on your device.