[wp-hackers] What is the logic on stripping slashes on add_post_meta?

Mark Cunningham mark.cunningham at gmail.com
Thu Feb 12 13:46:02 GMT 2009

I have a situation in my plugin where I store a file path in a Custom
Field on a post using add_post_meta. But I discovered that
add_post_meta strips slashes out of the meta value before adding them
to the database, which causes a pain when people use my plugin on a
Windows host that uses '\' as directory seperaters. It turns
"C:\folder\subfolder" into "C:foldersubfolder". In fact add_post_meta
uses "stripslashes_deep" so even if you're using an array of strings,
the slashes will be removed.

Why doesn't add_post_meta do add slashes and protect the original
input rather than strip them and risk modifying the original input?
The function documentation doesn't mention having to protect slashes
in the metadata value and neither does the codex. Is this a bug or a

This actually caused a pretty serious bug in my plugin because it
would use the value in the custom field to delete a folder contain
files and subfolders when a post was deleted. It did this by using
dirname on the path to a file returned from the post meta. This works
fine in unix and linux which is my default testing environment and
about 99% of users of my plugin, but on windows when you run dirname
on "C:foldersubfolder" you get "C:" and so my plugin attempted to
systematically delete every thing on the root of a windows host - not
smart but I can't test every host/os combination myself.


More information about the wp-hackers mailing list