Serializing URL via wp add_shortcode to auto select from option list onload

Use of the wordpress add_shortcode method to use url string to automatically select options in a scraped table on this page (may require couple of refreshes):

Aim is to pass in something like this to the url to auto select an option onLoad:[]=Adam%20Cooper

The tech is a scraped appointment widget from Healcode, and in the wp template the option drops are dynamically generated by including things like this:

   <?=$schedule->getElement("staff"); ?>

This then calls the parser which has the source:



class schedule{

    protected $_content;
    protected $_dom;
    protected $_schedule;
    protected $_scheduleWidget = "";

    protected $_cacheFolder;

     * when the class is first called it sets the cache folder and tries to get the timetable (most of the time from the cache)
     * @param string $cacheFolder
    function __construct($cacheFolder,$date=null){
        $this->_cacheFolder = $cacheFolder;
        $this->_schedule = $this->getSchedule($this->_scheduleWidget);

    function saveSchedule($data,$startDate){
        // set TTL (1800 seconds/30 mins) and create cache filename with timestamp
        $ttl = 1800;
        $cacheFilename = "-cacheschedule-".str_replace("-","",$startDate)."-_".$ttl . '_' . time();
        file_put_contents($this->_cacheFolder.$cacheFilename, serialize($data));

    function getSchedule($url){
        $found = false;
        $date = date("Ymd");
        foreach (scandir($this->_cacheFolder) as $file) {
                $info = explode("_",$file);
                $expiry = $info[1]+$info[2];
                $currentTime = time();
                if($expiry >= $currentTime){
                    $found = $file;
            return $this->parseSchedule($date);
        } else {
            return unserialize(file_get_contents($this->_cacheFolder."/".$found));


    function search($params){
        $url = "".$_SERVER['QUERY_STRING'];
    //  $url= "[session_type_ids]=21&options[staff_ids][]=&options[location_ids][]=450&options[start_date]=2015-05-01&options[end_date]=2015-05-07&_=1429789051232";
        $html = file_get_contents($url);
        $content = stripslashes(str_replace("n",chr(10),$html));
        $content = str_replace("u003C","<",$content);
        $content = str_replace("u003E",">",$content);
        $content = str_replace('jQuery18104174805885557632_1429783411238({"contents":"',"",$content);
        $content = str_replace('"});',"",$content);
        $content = str_replace('rel="modal"','rel="booking"',$content);
        $content = str_replace('u0026amp;','&',$content); 
        if(strpos($content,"Network timeout occurred. Please try again.")>0){
            $content="There was an issue returning results, please try again later";

        return $content;

    function parseSchedule($date){
        $obj = new stdClass();
        $html = @file_get_contents($this->_scheduleWidget);
        $content = stripslashes(str_replace("n",chr(10),$html));
        $this->_dom = str_get_html(file_get_contents($this->_cacheFolder."schedule".$date.".html"));
        $obj->session = $this->_dom->find("#session_type",0);;
        $obj->staff = $this->_dom->find("#options_staff_ids_",0);
        $obj->location = $this->_dom->find("#options_location_ids_",0);
        $obj->startDate =  $this->_dom->find("#options_start_date",0);
        $obj->endDate =  $this->_dom->find("#options_end_date",0);


    function getElement($name){
        return $this->_schedule->$name;


Shortcode code:

// shortcode logic to link to PT timetable
function ptLinks( $atts ) {

    extract( shortcode_atts(
    'session' => '',
    'staff' => '',
    'location' => '',
    ), $atts )

    $link = get_permalink( get_page_by_path( 'personal-training-timetable' ) )."?action=go";
    if(isset($atts['session']) && $atts['session']!=""){
        $atts['session'] = str_replace("-","",$atts['session']);

    if(isset($atts['staff']) && $atts['staff']!=""){
        $atts['staff'] = str_replace("-"," ",$atts['staff']);

    if(isset($atts['location']) && $atts['location']!=""){
        $atts['location'] = str_replace("-"," ",$atts['location']);

    return $link;
add_shortcode( 'ptLinks', 'ptLinks' );

I think I’m missing a few more steps here to get it sorted. Can anyone advise?

Many thanks indeed!

Source: shortcode

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.