1

I try to pass a javascript array to a shortcode, but it seems to be sanitized/escaped. For example this character "[" generate that "`{`". What is the function to retrieve original data ?

Here is a shortcode example :

[shortcode jsarray="[{start:"19:30",end:"21:00",color:'#d99694'},{start:"20:00",end: "21:30",color:'#d99694'},],"]
Some text
[/shortcode]

Here is my shortcode render function :

public function render_html($atts,$content)
{
    $atts = shortcode_atts(array('jsarray' =>''), $atts);

    $jsarray=$atts['jsarray'];
    if(empty($jsarray))
    {
        return;
    }

    ob_start(); ?>
        <div  data="<?php echo base64_encode($jsarray) ?>">
           <?php echo $content; ?>
        </div>
    <?php
    return ob_get_clean();
}

EDIT : Here is the result in shortcode_atts function :

`{`{``start``:``19:30``, ``end``:``21:00``, ``color``:``#d99694``}, {``start``:``19:30``, ``end``:``21:00``, ``color``:``#d99694``}`}`

1 Answer 1

3

You're going to have other problems than the brackets because shortcode_parse_atts will have already parsed your attributes, and the various single and double quotes will confuse the regular expression used to do that.

If you need the exact string, perhaps you could get it from a custom field. Alternatively, and better, you could specify a number of attributes for your shortcode (time1start, time1end, time1color, etc.) and rebuild your Javascript at the back end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.