Please upgrade here. These earlier versions are no longer being updated and have security issues.

Show Vanilla Avatar in Wordpress

edited June 2016 in Vanilla 2.0 - 2.8

Hi there, i have a tricky one which drives me insane!

People can post on my wordpress blog. In order to do this they have to own a account. As far as i understood I have two user-databases at the moment. (Because of the WP-Vanilla Bridge.)

I want to put the vanilla avatar of the post-author under the wordpress post header. So i would need to create a script which looks in the wordpress database who the author of the current post is. (Well, I get the Author name already as a meta-information in my wordpress entry-title if that helps.) In the next step the script should head over to the vanilla database and get the user. As far as I read in the forum i could call the picture from json.

Is anybody bored and skilled enough to help me with this one? My Coding skills are growing but still to limited for such an example:/ I know, in the end it is just a little picture. But hey, this little picture would make me very happy:D

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    You might have better chances if you ask in a forum where WordPress guys hang around. YOu can get the information simply as that: https://vanillaforums.org/profile.json/Moehrenstein

    You'll find the "PhotoUrl" which is what you need. But I do not know how something can be shown in WP...


  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Looking at that, it shouldn't be too hard. It basically is the example from the plugin API page added with only very few lines of code (beginning at the inline comment in the final if condition).

    function get_vanilla_avatar( $avatar, $id_or_email, $size, $default, $alt ) {
        $user = false;
    
        if ( is_numeric( $id_or_email ) ) {
    
            $id = (int) $id_or_email;
            $user = get_user_by( 'id' , $id );
    
        } elseif ( is_object( $id_or_email ) ) {
    
            if ( ! empty( $id_or_email->user_id ) ) {
                $id = (int) $id_or_email->user_id;
                $user = get_user_by( 'id' , $id );
            }
    
        } else {
            $user = get_user_by( 'email', $id_or_email );
        }
    
        if ( $user && is_object( $user ) ) {
    
            if ( $user->data->ID == '1' ) {
                // Insert your homepage name and hope that $user has a name property...
                $json = file_get_contents('your home page/profile.json/'.$user->name);
                $profile = json_decode($json);
                $avatar = $profile->PhotoUrl;
                $avatar = "<img alt='{$alt}' src='{$avatar}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
            }
    
        }
    
        return $avatar;
    }
    

    I bet there a billion examples for adding your own filters to word press. Take one of them, use what you see in the code above and you are good to go.


    whu606ShadowdarehgtonightMoehrenstein
  • Wow, you are golden RJ! Thanks for pointing me in the right direction!!! :D

  • tukoltukol New
    edited June 2016

    Hello, guys! I have the same question too. I am using one of the wordpress blog themes for my website. Can someone please help me with this issue?

  • whu606whu606 I'm not a SuperHero; I just like wearing tights... Moderator

    @tukol

    I've deleted the link from your post, as it is superfluous.

    I'm also not sure why you are asking for help when the solution has already been provided.

    What parts of the provided solution have you tried?

Sign In or Register to comment.