Skip to content

Instantly share code, notes, and snippets.

@alexstandiford
Last active March 6, 2019 20:16
Show Gist options
  • Select an option

  • Save alexstandiford/7cf6df7f7fbdccbbad51910c359a3c54 to your computer and use it in GitHub Desktop.

Select an option

Save alexstandiford/7cf6df7f7fbdccbbad51910c359a3c54 to your computer and use it in GitHub Desktop.
Force Affiliate WP Referral var to Stick Around When wp_redirect is Used
<?php
/**
* Keeps the referral var when wp_redirect is used.
*/
function affwpsupport_keep_referral_var_on_wp_redirect( $location, $status ) {
if ( function_exists( 'affiliate_wp' ) ) {
// Get the referral variable being used in AffiliateWP.
$referral_var = affiliate_wp()->tracking->get_referral_var();
if ( $_GET[ $referral_var ] ) {
// Append the referral variable and value to the URL after the redirect.
$location = add_query_arg( $referral_var, $_GET[ $referral_var ], $location );
}
}
return $location;
}
add_filter( 'wp_redirect', 'affwpsupport_keep_referral_var_on_wp_redirect', 10, 2 );
/**
* Forces tracking scripts to load on the wordpress login page
* Built for Affiliate WP version 2.2.14. Mileage may vary.
*/
function affwpsupport_force_tracking_scripts_to_load_on_login_page() {
//First, check and make sure that affiliate_wp is activated.
if ( function_exists( 'affiliate_wp' ) ) {
affiliate_wp()->tracking->header_scripts();
affiliate_wp()->tracking->load_scripts();
}
}
add_action( 'login_enqueue_scripts', 'affwpsupport_force_tracking_scripts_to_load_on_login_page', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment