Created
February 3, 2017 19:37
-
-
Save EricBusch/7a7fa3715928ddf75f1477741cab902c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This modifies the affiliate link and redirects the link back to the site's | |
* homepage with specific query parameters added. | |
*/ | |
add_filter( 'dfrapi_after_affiliate_id_insertion', 'mycode_redirect_to_exit_page', 20, 3 ); | |
function mycode_redirect_to_exit_page( $url, $product, $affiliate_id ) { | |
$args = array( | |
'dfrapi_id' => $product['_id'], | |
'dfrapi_url' => urlencode( $url ), | |
'dfrapi_name' => urlencode( $product['name'] ), | |
'dfrapi_brand' => urlencode( $product['brand'] ), | |
'dfrapi_merchant' => urlencode( $product['merchant'] ), | |
'dfrapi_merchant_id' => $product['merchant_id'], | |
); | |
$url = trailingslashit( get_home_url() ) . 'dfrapi-redirect'; | |
return add_query_arg( $args, $url ); | |
} | |
/** | |
* This overrides the loading of a template file and creates a lightweight bounce page | |
* to display a "redirect" message and the logo of the merchant you are redirecting to. | |
*/ | |
add_filter( 'template_include', 'portfolio_page_template', 99 ); | |
function portfolio_page_template( $template ) { | |
// Get query parameters. | |
$id = ( isset( $_GET['dfrapi_id'] ) ) ? urldecode( $_GET['dfrapi_id'] ) : false; | |
$url = ( isset( $_GET['dfrapi_url'] ) && ! empty( $_GET['dfrapi_url'] ) ) ? urldecode( $_GET['dfrapi_url'] ) : false; | |
$name = ( isset( $_GET['dfrapi_name'] ) ) ? urldecode( $_GET['dfrapi_name'] ) : false; | |
$brand = ( isset( $_GET['dfrapi_brand'] ) ) ? urldecode( $_GET['dfrapi_brand'] ) : false; | |
$merchant = ( isset( $_GET['dfrapi_merchant'] ) ) ? urldecode( $_GET['dfrapi_merchant'] ) : false; | |
$merchant_id = ( isset( $_GET['dfrapi_merchant_id'] ) ) ? urldecode( $_GET['dfrapi_merchant_id'] ) : false; | |
// Return if required parameters are not available. | |
if ( ! $url || ! $id ) { | |
return $template; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width"> | |
<meta name="robots" content="noindex"> | |
<meta http-equiv="refresh" content="3;url=<?php echo $url; ?>"> | |
<title>Redirecting to <?php echo $name; ?></title> | |
<style type="text/css"> | |
body { | |
margin-top: 100px; | |
font-family: sans-serif; | |
font-size: 16px; | |
} | |
.wrapper { | |
margin-right: auto; | |
margin-left: auto; | |
text-align: center; | |
padding: 30px; | |
max-width: 400px; | |
border-radius: 25px; | |
box-shadow: 0 10px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19) !important; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="wrapper"> | |
<p> | |
You are being redirected to <strong><?php echo $merchant; ?></strong>… | |
</p> | |
<p> | |
<img src="https://images.datafeedr.com/m/<?php echo $merchant_id; ?>.jpg" border="0"/> | |
</p> | |
<p> | |
If you don't wish to wait, <a href="<?php echo $url; ?>">click here</a>. | |
</p> | |
</div> | |
</body> | |
</html> | |
<?php | |
// Do NOT edit below this line. | |
die(); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment