We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum
Forum
Passing arguments to shortcode provider
I have put a shortcode provider together for Vimeo. Although any arguments I pass through don't seem to be recognised.
[cms:vimeo 191465923 width=1920]
class shortcode_Vimeo extends PerchShortcode_Provider {
public $shortcodes = ['vimeo'];
public function get_shortcode_replacement($Sortcode, $Tag)
{
$id = $Sortcode->arg(0);
$API = new PerchAPI(1.0, 'shortcode_vimeo');
$HTTP = $API->get('HTTPClient');
$response = $HTTP->get('https://vimeo.com/api/oembed.json?url='.urlencode('https://vimeo.com/'.$id));
if ($response) {
$data = json_decode($response, true);
if (isset($data['html'])) return $data['html'];
}
return '';
}
}
Would I change $id = $Sortcode->arg(0);
to $id = $Sortcode->arg(0).$Sortcode->arg('width');
?
Although, what if I wanted to add other arguments like autoplay, color, title ?
Thanks
Want to reply to this thread?
Login with Perch
$id = $Sortcode->arg(0);
is reading the first argument and assigning it to$id
. It doesn't make sense to concatenate anything to it.$Sortcode->arg('width')
should be the value of thewidth
attribute, if set.OK, so say if I waned to add arguments to the shortcode like
[cms:vimeo 191465923 width=1920 autoplay=true color=#4971b0]
Sometimes autoplay or colour may not be needed. How would I collect all the arguments and set them on the request. Would something like this work?
Updated the code, although doesn't seem to make a difference to the returned embed:
Anything standing out
I'm afraid can't offer support for this.
Cool, no worries
Thanks