Help with a plugin

Daegaladh

Member
I'm making a plugin to show social icons on each row using the custom fields but I'm getting some errors.

This is my code:
rankings_compile_stats.php
PHP:
$facebook_clean = filter_var($TMPL['acf_facebook'],FILTER_SANITIZE_URL);
$facebook_row = '<a href="{$facebook_clean}"><img src="{$skins_url}/{$skin_name}/img/facebook16.png" /></a>';
$twitter_row = '<a href="http://twitter.com/{$TMPL['acf_twitter']}"><img src="{$skins_url}/{$skin_name}/img/twitter16.png" /></a>';
if($TMPL['acf_facebook']) $TMPL['social_row'] = $facebook_row;
if($TMPL['acf_twitter']) $TMPL['social_row'] .= $twitter_row;
 

Basti

Administrator
Staff member
Yes you are triggering parsing errors on these 2 lines
Code:
$facebook_row = '<a href="{$facebook_clean}"><img src="{$skins_url}/{$skin_name}/img/facebook16.png" /></a>';
$twitter_row = '<a href="http://twitter.com/{$TMPL['acf_twitter']}"><img src="{$skins_url}/{$skin_name}/img/twitter16.png" /></a>';
the php variable writing like {$facebook_clean} is only supported if the main string is enclosed in double quotes. The way you have written it, you need the following setup

Also the img path template tags need the TMPL var as the way you have written it is for the html files
Code:
$facebook_row = '<a href="'.$facebook_clean.'"><img src="'.$TMPL['skins_url'].'/'.$TMPL['skin_name'].'/img/facebook16.png" /></a>';
$twitter_row = '<a href="http://twitter.com/'.$TMPL['acf_twitter'].'"><img src="'.$TMPL['skins_url'].'/'.$TMPL['skin_name'].'/img/twitter16.png" /></a>';
So, string enclosed with single quotes, php vars need the '.$var.' setup ( close string, append php var, append string/open string)

Alternative is to use double quotes for the string, then you can enclose your php vars in the curly brackets. But other double quotes within the string need to be escaped.
Code:
$facebook_row = "<a href=\"{$facebook_clean}\"><img src=\"{$TMPL['skins_url']}/{$TMPL['skin_name']}/img/facebook16.png\" /></a>";
$twitter_row = "<a href=\"http://twitter.com/{$TMPL['acf_twitter']}\"><img src=\"{$TMPL['skins_url']}/{$TMPL['skin_name']}/img/twitter16.png\" /></a>";
 
Top