Skip to content

Instantly share code, notes, and snippets.

@amdrew
Last active July 4, 2016 19:30
Show Gist options
  • Save amdrew/238913508f8ae2da663f to your computer and use it in GitHub Desktop.
Save amdrew/238913508f8ae2da663f to your computer and use it in GitHub Desktop.
<?php
/**
* [affiliate_referral_url_username] shortcode
*/
function affwp_custom_referral_url_shortcode( $atts, $content = null ) {
if ( ! affwp_is_affiliate() ) {
return;
}
shortcode_atts( array(
'url' => ''
), $atts, 'affiliate_referral_url_username' );
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 );
$affiliate_user_name = $user_info->user_login;
return add_query_arg( affiliate_wp()->tracking->get_referral_var(), $affiliate_user_name, $base );
}
add_shortcode( 'affiliate_referral_url_username', 'affwp_custom_referral_url_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment