Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 574881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:52:44+00:00 2026-05-13T13:52:44+00:00

I’m passing the ABSPATH value from a wordpress theme options page to an external

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:52:44+00:00Added an answer on May 13, 2026 at 1:52 pm

    It is the lack of JavaScript string literal escaping that has tripped you up: \x and \h are escapes in strings, so you’d need \\ to get a real backslash.

    But that’s not all.

    <input ...  onclick="window.open('.../myuploader.php?abspath=<?php echo ABSPATH ?>',... />
    

    Here you’re outputting a value into:

    1. a URL parameter, inside
    2. a JavaScript string literal, inside
    3. an HTML attribute

    That means you need three levels of escaping:

    $uri= '../wp-content/themes/mytheme/myuploader.php?abspath='.urlencode(ABSPATH);
    $jsuri= json_encode($uri);
    $htmljsuri= htmlspecialchars($jsuri);
    
    <input ... onclick="window.open(<?php echo $htmljsuri; ?>, 'popup', 'features...')" />
    

    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+:

    $uri= '../wp-content/themes/mytheme/myuploader.php?abspath='.urlencode(ABSPATH);
    $jsuri= json_encode($uri, JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_AMP);
    
    <input ... onclick="window.open(<?php echo $jsuri; ?>, 'popup', 'features...')" />
    

    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:

    <input type="button" id="templateUpload" value="Add New Template" />
    <script type="text/javascript">
        var ABSPATH= <?php echo json_encode(ABSPATH, JSON_HEX_TAG|JSON_HEX_AMP); ?>;
    
        document.getElementById('templateUpload').onclick= function() {
            var uri= '../wp-content/themes/mytheme/myuploader.php?abspath='+encodeURIComponent(ABSPATH);
            window.open(uri, 'popup', 'width=330, height=230');
        };
    </script>
    

    I omitted the return false as it isn’t needed for a button, which has no default action to prevent. I also removed the stuff about removing browser chrome just due to finding it quite distasteful. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 340k
  • Answers 340k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This was discussed before. Your case is much easier though,… May 14, 2026 at 4:44 am
  • Editorial Team
    Editorial Team added an answer I really prefer exceptions over old-fashion error handling. The advantages… May 14, 2026 at 4:44 am
  • Editorial Team
    Editorial Team added an answer <input type="submit" onclick="triggerSubmit();" value="Submit" /> <script type="text/javascript"> function trigerSubmit(e){ var… May 14, 2026 at 4:44 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.