Created
December 8, 2014 07:25
-
-
Save amdrew/e3b4b6dd49ca5b978a69 to your computer and use it in GitHub Desktop.
AffiliateWP - Remove the affiliate_referral_url shortcode and add the same shortcode back which returns the affiliate referral URL in a site.com/ref/username format
This file contains hidden or 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 | |
// remove original shortcode | |
remove_shortcode( 'affiliate_referral_url' ); | |
/** | |
* Add our new shortcode which returns the affiliate referral URL in a site.com/ref/username format | |
*/ | |
function affwp_custom_referral_url_shortcode( $atts, $content = null ) { | |
if ( ! affwp_is_affiliate() ) { | |
return; | |
} | |
shortcode_atts( array( | |
'url' => '' | |
), $atts, 'affiliate_referral_url' ); | |
if ( ! empty( $content ) ) { | |
$base = $content; | |
} else { | |
$base = ! empty( $atts[ 'url' ] ) ? $atts[ 'url' ] : home_url( '/' ); | |
} | |
$affiliate = affwp_get_affiliate( affwp_get_affiliate_id() ); | |
$user_info = get_userdata( $affiliate->user_id ); | |
$username = esc_html( $user_info->user_login ); | |
return $base . affiliate_wp()->tracking->get_referral_var() . '/' . $username; | |
} | |
add_shortcode( 'affiliate_referral_url', 'affwp_custom_referral_url_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment