Created
June 23, 2017 13:24
Referring Affiliate's avatar - example shortcode
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
add_action( 'init', 'referring_affiliate_avatar_shortcode' ); | |
function referring_affiliate_avatar_shortcode() { | |
add_shortcode( 'referring-affiliate-avatar', 'referring_affiliate_avatar' ); | |
} | |
function referring_affiliate_avatar( $atts ) { | |
$output = ''; | |
if ( !is_admin() ) { | |
if ( !class_exists( "Affiliates_Service" ) ) { | |
include_once( AFFILIATES_CORE_LIB . '/class-affiliates-service.php' ); | |
$affiliate_id = Affiliates_Service::get_referrer_id(); | |
if ( $affiliate_id && $affiliate_id != affiliates_get_direct_id() ) { | |
if ( $user_id = affiliates_get_affiliate_user( $affiliate_id ) ) { | |
if ( $user = get_user_by( 'id', $user_id ) ) { | |
$output .= 'You come referred by: '; | |
if ( get_avatar( $user_id ) ) { | |
$output .= get_avatar( $user_id ); | |
} else { | |
$output .= $user->user_login ; | |
} | |
} | |
} | |
} | |
} | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment