Side note: Strange cryptic characters in shortcodes

Note: Also available in German 🙂

A colleague of mine today: There is a shortcode with strange-looking, cryptic characters in one of its attributes.
Something like this:

eyJoYWxsbyI6IndlbHQiLCJzb25nLXRpdGVsIjp7Im1laW4iOiJnZWhpcm4iLCJkZWluIjoiZ2VoaXJuIn0sInVybCI6Imh0dHBzJTNBJTJGJTJGdXNhYmlsaXR5LWlkZWFsaXN0Lm5ldCUyRiUyM2tvbnRha3QiLCJlaW5zX3BsdXMiOnRydWV9

My comment: Looks a bit like rot13 ..
His reply a bit later on: Yes, it is base64, and the result is a JSON string.

Putting the rule to the test:


<?php
$x = 'eyJoYWxsbyI6IndlbHQiLCJzb25nLXRpdGVsIjp7Im1laW4iOiJnZWhpcm4iLCJkZWluIjoiZ2VoaXJuIn0sInVybCI6Imh0dHBzJTNBJTJGJTJGdXNhYmlsaXR5LWlkZWFsaXN0Lm5ldCUyRiUyM2tvbnRha3QiLCJlaW5zX3BsdXMiOnRydWV9';
$y = base64_decode( $x );
$z = json_decode( urldecode( $y ), true ); // true ergibt ein array, ohne haben wir reine StdClass-Objektorgie
?>

view raw

cryptic-bs.php

hosted with ❤ by GitHub

Yep … works 🙂
This is how the Uncode plugin is saving its data into shortcode attributes, and a few themes use it as well, to store their settings, eg. as a transient.

What effects does this have?

Well, right after moving a site, search & replace utterly fails with this. Ergo this is a really rotten habit. Yes, of corpse I do understand why one would go so far and store data this way – because (at least older version of) Visual Composer doesnt give any options to create direct connections between shortcodes and eg. meta fields. But still, if it was me who had to develop something like this, I’d still strived to get it done with meta fields, and maybe a shortcode attribute acting as ID. Because with that lengthy search, after those “hidden URLs”, my colleague wasted most of the day. That is time and money, he wont get back. At all.

Leave a Reply

Your email address will not be published. Required fields are marked *