I’m passing the ABSPATH value from a wordpress theme options page to an external page which does not have access to ABSPATH. The problem is that once the value is received in the external file, the slashes are removed. How can I send the value and keep the slashes intact?
I’m passing the value for ABSPATH via a javascript window.open URL parameter like so…
<input type="button" id="templateUpload" value="Add New Template" onclick="window.open('../wp-content/themes/mytheme/myuploader.php?abspath=<?php echo ABSPATH ?>','popup','width=330,height=230,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no'); return false" />
The view source of the above executed wordpress theme options page reads…
?abspath=C:\xampplite\htdocs\wordpress/
Which is why I believe I’m having an issue
It is the lack of JavaScript string literal escaping that has tripped you up:
\xand\hare escapes in strings, so you’d need\\to get a real backslash.But that’s not all.
Here you’re outputting a value into:
That means you need three levels of escaping:
You can reduce that by using the HEX_ options in json_encode to ensure HTML special characters are already escaped out of the way, in PHP 5.3+:
However, anything involving multiple levels of escaping like this is confusing and generally to be avoided. Kick the JavaScript and the variable out of the markup instead, then you have only one level of escaping to worry about at once:
I omitted the
return falseas it isn’t needed for abutton, which has no default action to prevent. I also removed the stuff about removing browser chrome just due to finding it quite distasteful. 😉