Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geotsiokos/643e76be168b86e350ddb0690b8ed871 to your computer and use it in GitHub Desktop.
Save geotsiokos/643e76be168b86e350ddb0690b8ed871 to your computer and use it in GitHub Desktop.
Referring Affiliate's avatar - example shortcode
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