1

I have a shortcode that can parse page contents. For example you give it a link to a GitHub md file , it reads it and saves the page content for you.

$parse_atts = array(
    'id'        => $id,
    'url'       => $url,
    'days'      => $days,
    'hours'     => $hours,
    'markdown'  => $markdown,
    'escaped'   => $escaped,
    'mdengine'  => $mdengine,
);
echo thz_parse_page( $parse_atts );

Issue I have is that I dont know what the best way of saving this data is. Some say dont use transient , some dont save the data and so on.

I have made a code for each, save as transient , save as option or save as txt file in uploads dir. The shortcode itself gives you an option to choose the expire time so removal of the data will occur either way.

The way I utilize the shortcode is for docs. All docs are hosted on GitHub and with the shortcode I can display parsed doc md in WordPress post. When cache time expires transient,option,file is deleted and new data resaved.

All WP coding standards are followed and nothing is retrieved outside of WP scope. There are no issues I see. Only the one asked.

Any help is appreciated.

  • 2
    If it's meant to have a limited lifetime, I'd say storing it as a transient is the way to do it. – Pat J Dec 4 '17 at 21:01
2

I would go with transient. The reason I would choose transient it is they are created exactly for your case. I know that you have your own removal functionality but why to repeat yourself? Another advantage would be that transient beneath use cache. If for some reason your will need to install object cache your shortcode would automatically benefit from it.

  • I went with it, prntscr.com/hja0bg was just wondering what other devs would suggest. – Benn Dec 5 '17 at 8:47
  • Do you checking somewhere if transient with this key is already saved in database? – kierzniak Dec 5 '17 at 9:12
  • the keys a very unique , combo of auto generated id and post title. sanitize_title_with_dashes( $id.get_the_title() ) – Benn Dec 5 '17 at 10:22
  • You misunderstood me. Are you checking if your parsed content is already in database? Something like: codex.wordpress.org/Function_Reference/… I don't see such a part in your screenshot. – kierzniak Dec 5 '17 at 12:43
  • sure I do , im not doing request every time, request runs only if we dont have anything from db , after this , if( false === $parsed_page ) {... now request. the screenshot is after that check – Benn Dec 5 '17 at 13:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.