Posted on Leave a comment

[affiliates_username] shortcode

If you are using Affiliates by @itthinx and you need to display the referrer username, now you can use this shortcode:
add_shortcode( 'affiliates_username', 'affiliates_username_shortcode' );
function affiliates_username_shortcode( $atts ) {
  if ( !class_exists( "Affiliates_Service" ) ) {
    include_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' );
  }
  $output = "";
  $affiliate_id = Affiliates_Service::get_referrer_id();
  if ( $affiliate_id ) {
    if ( $affiliate_id !== affiliates_get_direct_id() ) {
      if ( $user_id = affiliates_get_affiliate_user( $affiliate_id ) ) {
        if ( $user = get_user_by( 'id', $user_id ) ) {
          $output .= $user->user_login;
        }
      }
    }
  }
  return $output;
}