'>
'>
'>
Warning : ALL Amazon links will be redirected to this single URL! Leave blank if you don't want to.
value='1'>
value='1'>
When posting, trims Amazon links from queries and appends your Amazon affiliate ID (tag) at the end of each one. Then it uses the URL shortening service bit.ly to generate pretty amzn.to links. The plugin works for new posts only. It does not affect existing posts.
bit.ly offers click analytics (total clicks per link, referrers, locations). To see this information, go to bit.ly and log in to your account.
First you need to sign up for bit.ly and verify your email address. Then you\'ll be able to generate a Generic Access Token in your bit.ly profile. Copy and paste it in the first input field.
The next input field is for your Amazon affiliate ID, which you\'ll receive after signing up for Amazon Associates in your respective country.
rel="nofollow" controls whether search engines should treat the link as a recommendation for SEO purposes. Check to disable (recommended).
"Open links in a new tab" makes each of your affiliate links open in a new browser tab by adding target="blank" to your affiliate links.
';
//echo __( 'Affiliate Link Builder will automatically add or edit the "tag" variable in each Amazon links in your posts. Here you can tell the plugin which tag he will add and if the links should be in nofollow and/or opened in a new tab.
Catch all : If you want to catch all Amazon links and redirect them to a single URL, a links proxy for example, just add this URL in the appropriate field below. Leave it blank if you don\'t want to, the plugin will still replace all tags as usual.', 'wordpress' );
echo __( $instructions, 'wordpress' );
}
function affiliatelinkbuilder_options_page(){
?>
]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $content, $link_matches, PREG_SET_ORDER)) {
foreach($link_matches as $match) {
if(preg_match('/(.*)amazon\.(com|co.uk|de|fr|es|it|co.jp|ca)+/i', $match[2])){
$thelink = str_replace('&',"&",$match[2]);
$parsed = parse_url($thelink);
$options_attr = "";
//Set up the right tag depending on the country
//TODO
//Replacing tag if it already exists in URL
/*if(preg_match('#tag#i',$parsed['query'])){
$query_string = html_entity_decode($parsed['query']);
parse_str($query_string, $variables);
$variables["tag"] = $Tagaffiliatelinkbuilder;
$new_query = http_build_query($variables, '', '&');
if($options_affiliatelinkbuilder['affiliatelinkbuilder_nofollow'] == '1'){
$options_attr .= ' rel="nofollow"';
}
if($options_affiliatelinkbuilder['affiliatelinkbuilder_target'] == '1'){
$options_attr .= ' target="_blank"';
}
$newlink = ''.$match[3].'';
}else{*/
if($options_affiliatelinkbuilder['affiliatelinkbuilder_nofollow'] == '1'){
$options_attr .= ' rel="nofollow"';
}
if($options_affiliatelinkbuilder['affiliatelinkbuilder_target'] == '1'){
$options_attr .= ' target="_blank"';
}
//Check if link have a query
if (isset($parsed['query'])){
//$newlink = ''.$match[3].'';
$thelink = substr($thelink, 0, strpos($thelink,"?"));
/*} else {*/
}
$thelink = $thelink.'?tag='.$Tagaffiliatelinkbuilder;
if(isset($options_affiliatelinkbuilder) && $options_affiliatelinkbuilder['affiliatelinkbuilder_bitly'] != "") {
$accessToken = $options_affiliatelinkbuilder['affiliatelinkbuilder_bitly'];
$thelink = file_get_contents("https://api-ssl.bitly.com/v3/shorten?access_token=$accessToken&longUrl=".urlencode($thelink)."&format=txt");
}
$newlink = ''.$match[3].'';
//} else
//If the catch all option is filled, plugin will redirect all links to the catch all URL
if($catchall_option != ''){
$newlink = ''.$match[3].'';
$content = str_replace($match[0], $newlink, $content);
}else{
$content = str_replace($match[0], $newlink, $content);
}
}
}
}
return $content;
}
add_filter( 'the_content', 'AddTag');
?>