Skip to:
Content
Pages
Categories
Search
Top
Bottom

Detecting if User Uploaded an Avatar

  • Avatar of wp_kouhai
    wp_kouhai
    Participant

    @wp_kouhai

    This seemed to be a simple task, but I’ve been struggling to get it working.

    I wish to check on user login if they have uploaded an avatar or if they are using the auto-generated gravatar. For now, I am just trying to get it to redirect to the upload page (I’ll likely pop up a light box, display a notice, or restrict functions in the future).

    I have done some searching, and after some tweaking, this is what I have come up with:

    function uaol_get_user_has_avatar() {
      global $bp;
    
      $avatar = bp_core_fetch_avatar( array( 'item_id' => $bp->loggedin_user->id, 'no_grav' => true, 'html'=>false) );
    
      $pos = strpos($avatar, 'wavatar');
      if ($pos === false) { return true;}
      else {
        return false;
      }
    }
    
    function buddypress_redirect_if_no_avatar($redirect_url,$request_url,$user) {
        $redirect_url = bp_core_get_user_domain($user->ID)."/profile/change-avatar/";
        return $redirect_url;
    }
    
    if( !uaol_get_user_has_avatar()){
      add_filter("login_redirect","buddypress_redirect_if_no_avatar",100,3);
    }

    This however does not redirect anyone. Can someone point me in the right direction?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Avatar of wp_kouhai
    wp_kouhai
    Participant

    @wp_kouhai

    I have found and corrected the issue.

    function buddypress_redirect_if_no_avatar($redirect_url,$request_url,$user) {
    
      $avatar = bp_core_fetch_avatar( array( 'item_id' => $user->ID, 'no_grav' => true, 'html'=>false) );
    
      $pos = strpos($avatar, 'mystery-man');
      if ($pos === false) { return "/";}
      else {
        $redirect_url = bp_core_get_user_domain($user->ID)."/profile/change-avatar/";
        return $redirect_url;
      }
    
    }
    
    add_filter("login_redirect","buddypress_redirect_if_no_avatar",100,3);
    Avatar of Lerroy
    Lerroy
    Participant

    @lerroy

    Wow this is great thanks

    Avatar of Lerroy
    Lerroy
    Participant

    @lerroy

    Hi Where did you put this in functions file ?

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.