Skip to content

Instantly share code, notes, and snippets.

@craigedmonds
Created October 19, 2018 18:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save craigedmonds/e45ef8909284f0a435e5eb9a94c1a0de to your computer and use it in GitHub Desktop.
This checks to see if the post being loaded is 1. a special offer 2. if the dealer is authorised to load the special offer on their dealer site and if not we force a 301 redirect back to the dealers home page
<?php
######################################################
//Here we will check to see if the special offer being presented
//is in the list of the dealers posts and if not do a 301 redirect
//back to the home page
//added on 19/10/2018 by craig@jucra.com
######################################################
function white_label_special_offer_301_redirect_check($array_of_dealer) {
###################################################
//STEP 1
//Make sure the post type is special-offer.
//If not stop the function in order to save resources.
###################################################
if(get_post_type(get_the_ID()) != "special-offers") {
return;
}
###################################################
//STEP 2
//Get a list of the post id's for this dealer from array_of_dealer.
//This list is created through white_label_get_array_of_special_offer_posts_for_dealer()
###################################################
$array_of_dealer_special_offers = $array_of_dealer["OtherData"]["dealer_special_offers"];
//if there are no posts at all, then we need to 301 redirect right away
//as this post should not appear on the
if(count($array_of_dealer_special_offers) == 0) {
header("HTTP/1.1 301 Moved Permanently");
header("Location: /");
exit;
}
###################################################
//STEP 3
//Now we need to check if this post id exists in the list of
//$array_of_dealer_special_offers and if not, 301 redirect.
###################################################
$this_post_id = get_the_ID();
if(!in_array($this_post_id, $array_of_dealer_special_offers)){
header("HTTP/1.1 301 Moved Permanently");
header("Location: /");
exit;
}
//thats it, nothing else to do here
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment