Jon Imms
asked on
PHP Function , converted from WordPress
Hey,
I've been using a function in Wordpress which works great. It stores cookies from ads, and appends UTM's to the end of links, so we can track sources.
My friend has a pure PHP, MySQL website, and we want to try and convert this function we have in WordPress into this PHP website.
This is the function we are using in Wordpress, It's on all pages of the website. How can i convert this to a php function.
I've been using a function in Wordpress which works great. It stores cookies from ads, and appends UTM's to the end of links, so we can track sources.
My friend has a pure PHP, MySQL website, and we want to try and convert this function we have in WordPress into this PHP website.
This is the function we are using in Wordpress, It's on all pages of the website. How can i convert this to a php function.
function replace_links($text) {
$url = explode('?', 'https://'.$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
$addCookiesToLink = "";
if (strlen($url[1]) > 1) {
$text = str_replace('intelliapp2.driverapponline.com/c/cretec', 'intelliapp2.driverapponline.com/c/cretec?' . $url[1], $text);
}
else { //no parameters in URL. Cookies?
if(isset($_COOKIE['orig_utmsource'])) {
$addCookiesToLink .= "utm_source=" . $_COOKIE['orig_utmsource'];
}
elseif(isset($_COOKIE['orig_utm_source'])) {
if(strlen($addCookiesToLink) > 0) {
$addCookiesToLink .= "&";
}
$addCookiesToLink .= "utm_source=" . $_COOKIE['orig_utm_source'];
}
elseif(isset($_COOKIE['orig_utmmedium'])) {
if(strlen($addCookiesToLink) > 0) {
$addCookiesToLink .= "&";
}
$addCookiesToLink .= "utm_medium=" . $_COOKIE['orig_utmmedium'];
}
elseif(isset($_COOKIE['orig_utmcampaign'])) {
if(strlen($addCookiesToLink) > 0) {
$addCookiesToLink .= "&";
}
$addCookiesToLink .= "utm_campaign=" . $_COOKIE['orig_utmcampaign'];
}
elseif(isset($_COOKIE['orig_utm_campaign'])) {
if(strlen($addCookiesToLink) > 0) {
$addCookiesToLink .= "&";
}
$addCookiesToLink .= "utm_campaign=" . $_COOKIE['orig_utm_campaign'];
}
if(strlen($addCookiesToLink) > 0) {
//echo $addCookiesToLink;
$text = str_replace('intelliapp2.driverapponline.com/c/cretecarrier', 'intelliapp2.driverapponline.com/c/cretecarrier?' . $addCookiesToLink, $text);
}
//echo "test1" . $_COOKIE['orig_utm_campaign'] . " 2:" . $_COOKIE['orig_utm_source'] . " 3:" . $_COOKIE['orig_utmcampaign'] . " 4:" . $_COOKIE['orig_utmmedium'] . " 5:" . $_COOKIE['orig_utmsource'];
}
return $text;
}
add_filter('widget_text', 'replace_links');
add_filter('the_content', 'replace_links');
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.