• Resolved Protooler

    (@protooler)


    Hi,
    first I wanna thanks for this great plugin!!!
    I’m trying to customize something inside the comments.php
    for retrive the facebook avatar instead the default gravatar..

    I have create a query that stamp the avatar of the facebook user nearby the comments but when I try to post a comment the page stops
    and don’t communicate with wordpress database..
    the url in the browser is: https://www.mysite.com/index.php?fb_sig_in_iframe&wpbook=comment-handler

    Hereby the code

    <div id="commentlist">
    
        <?php $comment_class = 'acomment'; ?>
    
            <?php foreach ($comments as $comment) : ?>
    
            <div class="<?php echo $comment_class ?>">
    
            <?php
    
            $urlu = get_comment_author_url();
    
            if ($use_gravatar == "true" && !ereg("facebook",$urlu)){ 
    
            echo'<div class="gravatarr">';
    
                    $grav_url = "https://www.gravatar.com/avatar/" . 
    
                    md5(strtolower(get_comment_author_email())) . "?d=" . $gravatar_default . "&s=50&r=".$gravatar_rating;
    
          echo "<img src='$grav_url'/></div>";
    
           echo '<div class="gravatarpadding">';    
    
                                  }
    
            elseif ($use_gravatar == "true" && ereg("facebook",$urlu)){  
    
            echo'<div class="gravatarr">';
    
            $parsed = parse_url($urlu, PHP_URL_QUERY);
    
            $parsed = parse_str($parsed);
    
            $idfb = $parsed['id'];
    
            echo "<img src='https://graph.facebook.com/";
    
            echo "{$id}"; 
    
            echo "/picture?type=square' />";
    
            echo '</div><div class="gravatarpadding">';    
    
                                  }                        
    
        ?>
    
            <span class="wpbook_comment_author"><?php comment_author_link(); ?></span>
    
            <br/><span class="wpbook_comment_date"> <?php comment_date('F jS, Y') ?> at <?php comment_time() ?></span> 
    
            <span class="wpbook_comment_text">        
    
                    <?php if ($comment->comment_approved == '0') : ?>
    
                        <em>Your comment is awaiting moderation.</em>
    
                    <?php endif; ?>
    
                     <?php comment_text() ?></span>
    
                <?php if ($use_gravatar == "true"){ echo '</div>'; } ?>
    
            </div>
    
              <?php /* Changes every other comment to a different class */    
    
                        if ('acomment' == $comment_class){$comment_class = 'bcomment';} else {$comment_class = 'acomment';}
    
                    ?>
    
            <?php endforeach; /* end for each comment */ ?>
    
        </div><!-- //commentlist -->

    In my setting pages inside wordpress I have set a custom gravatar..

    If I delete $urlu = get_comment_author_url();
    in the code I’m able again to comment but obviously it doesn’t show me the facebook avatar..
    but it show only the custom gravatar..

    Any suggestion?

    Thank you
    Claudio

Viewing 11 replies - 16 through 26 (of 26 total)
  • Plugin Contributor B.

    (@bandonrandon)

    Glad you got it working.

    If you still wanted to use gravatars from comments that are either not from Facebook you could change:
    $grav_url = "https://www.devotionmagazine.se/wp-content/themes/deadline/images/gravatar.png";

    to:

    $grav_url = "https://www.gravatar.com/avatar/" .
                    md5(strtolower($email))."?d=https://www.devotionmagazine.se/wp-content/themes/deadline/images/gravatar.png";

    This shows gravatars for users who have them (and are not leaving their Facebook profile url) and if they don’t have a gravatar will show your default. You can also add a size or rating by adding “&s=50&r=PG” for example. See https://en.gravatar.com/site/implement/images/php/ For more info on that.

    Glad I could help.

    Wow, the code for showing facebook avatar really works wonder for me. The only thing I couldn’t got it to work is to change the size of the default gravatar. I’ve tried “&s=” . $size and “&s=50”, both doesn’t work. But I think that is less mission critical.

    The reason of this post is to acknowledge the awesomeness of the code that makes the get_fb_avatar to work perfectly ^^. Thanks.

    Plugin Contributor B.

    (@bandonrandon)

    @joshuatj the gravatar size is a strange beast. Are you talking about the size of the default gravatar? I’ve never been able to get that to work properly so I also just make the image the correct size.

    If you’re trying to set the size of the Facebook avatar to my knowledge there is no way to do this it’s just set to square (50px) and that’s that.

    For the record the Facebook avatar function is in the core 2.10 relase that we’ve been working on for a while so upgrading to that version will have this set and you won’t have to mess with with the php files to add it.

    Thanks.

    I can’t get this to work (to get avatars to show up on my blog). I put this I my themes functions.php:

    function get_fb_avatar($email,$url) {
    if(preg_match("@^(?:https://)?(?:www\.)?facebook@i",trim($url))){
            $parse_author_url = (parse_url($url));
            $parse_author_url_q = $parse_author_url['query'];
                if(preg_match('/id[=]([0-9]*)/', $parse_author_url_q, $match)){
                    $fb_id = "/".$match[1];}
                else{ $fb_id = $parse_author_url['path'];
                }
            $grav_url= "https://graph.facebook.com".$fb_id."/picture?type=square";
            }
            else{
                $grav_url = "https://www.gravatar.com/avatar/" .
                    md5(strtolower($email))."?d=https://www.devotionmagazine.se/wp-content/themes/deadline/images/gravatar.png";
            }
        $grav_img = "<img src='".$grav_url." ' align='left' class='entry_author_image'/>";
            return $grav_img;
    
        }

    This was already there (and is now underneath the code above):

    if ( function_exists('register_sidebar') ) {register_sidebar();register_sidebar();}

    In my themes comments.php I put this:
    echo get_fb_avatar(get_comment_author_email(),get_comment_author_url());

    Any ideas?

    Plugin Contributor B.

    (@bandonrandon)

    @arro08 this really isn’t a question about WPBook more about your blog theme. If you aren’t using WPBook or just want the Facebook Avatars you can use a plugin like Simple Facebook Connect https://www.ads-software.com/extend/plugins/simple-facebook-connect/

    Their could be a few things going on for one you are using a custom version of the function that is set to default to Devotionmagazine’s deafult gravatar. Another thing is make sure you wrap your echo get_fb_avatar with <?php ?>

    Also check to see if gravatars are turned on inside your wp-admin.

    You should be able to just add this to functions.php and not mess with comments.php as long as you have the get_gravatar hook in your comments.php

    function wpbook_get_facebook_avatar($avatar, $comment, $size, $default,$rating) {
    	 $wpbookOptions = get_option('wpbookAdminOptions');
          if (!empty($wpbookOptions)) {
            foreach ($wpbookOptions as $key => $option)
              $wpbookAdminOptions[$key] = $option;
          }
    	$author_url = get_comment_author_url();
    	$default = $wpbookAdminOptions['gravatar_default'];
    	$rating=$wpbookAdminOptions['gravatar_rating'];
    	$size="50";
    	if(preg_match("@^(?:https://)?(?:www\.)?facebook@i",trim($url))){
            $parse_author_url = (parse_url($url));
            $parse_author_url_q = $parse_author_url['query'];
                if(preg_match('/id[=]([0-9]*)/', $parse_author_url_q, $match)){
                    $fb_id = "/".$match[1];}
                else{ $fb_id = $parse_author_url['path'];
                }
            $grav_url= "https://graph.facebook.com".$fb_id."/picture?type=square";
            }
            else{
                $grav_url = "https://www.gravatar.com/avatar/" .
                    md5(strtolower($avatar))."?d=" . $default . "&s=".$size."&r=".$rating;
            }
        $grav_img = "<img src='".$grav_url."'/>";
            return $grav_img;
    }
    //add gravatar/facebook avatar support
    add_filter( 'get_avatar','wpbook_get_facebook_avatar', 1, 3 );

    If that doesn’t work then I’m not sure what’s wrong. As I said this is more of a basic WordPress theme question and not related to WPBook. These are just some basic ideas.

    @bandonrandon Thanks for answering!

    > If you aren’t using WPBook …
    I am using WPBook to post excerpts from my blog to my FB-profile, and to import comments from that excerpt back to WordPress. This is where I’d want the FB-avatars as well. Do I need Simple Facebook Connect as well for this?

    > … you are using a custom version of the function that is set to default to Devotionmagazine’s deafult gravatar …
    I know, I’m going to change that but first I just want to get it working.

    > Another thing is make sure you wrap your echo get_fb_avatar with <?php ?>
    Of course, I did that before as well, just forgot to post it.

    > Also check to see if gravatars are turned on inside your wp-admin.
    Check!

    > You should be able to just add this to functions.php and not mess with comments.php as long as you have the get_gravatar hook in your comments.php

    Added that to the functions.php and indeed it made a difference. I now see no avatars at all on the blog. I’m basically using this theme: https://www.ads-software.com/extend/themes/clear. The avatar part looks like this:
    <?php echo get_avatar( $comment, $size = '28', $default = 'default' ); ?>

    I tried to change that to get_gravatar (as you wrote) but no luck. Also tried to remove everything between the paranthesises, same result.

    Plugin Contributor B.

    (@bandonrandon)

    Sorry I ment get_avatar() not get_gravatar() It’s odd that you see no avatars at all in your blog that last two lines

    //add gravatar/facebook avatar support
    add_filter( 'get_avatar','wpbook_get_facebook_avatar', 1, 3 );

    Should replace get_avatar() with the custom function so you shouldn’t have to touch the gravatar code in your theme. I wonder if clear is also adding a filter to the gravatars. Make sure your get_avatar() is within the loop.

    Also sometimes a link to the site helps troubleshoot these things.

    Another option would be to upgrade to the beta version of WPBook 2.0.10 although this can be buggy but it has Facebook avatar support in core.

    I got it to work! Using the beta version and turning on comments inside Facebook did the trick. Can’t get it to work with the stable version though, but this will do. Thanks @bandonrandon for all the help.

    how to change the size of avatar ?

    <?php echo get_fb_avatar(get_comment_author_email(),get_comment_author_url()); ?>

    like this <?php echo get_avatar($comment,$size=’41’); ?>

    @bandonrandon i am not using wpbook, i am using sociable.es’s facebook connect everything is working fine

    comment avatar showing in comment list but not in my footer widget

    how can i fetch avatar in my footer widget ?

    this is working when facebook comment
    <?php echo get_fb_avatar(get_comment_author_email(),get_comment_author_url()); ?>

    but gravatar not working, i used these all code

    <?php echo  get_avatar(get_comment_author_email($comment->comment_ID), 40); ?>
          <?php echo get_avatar(get_comment_author_email(), '37'); ?>
            <?php echo get_avatar(get_comment_author_url(), '37'); ?>

    i tried this plugin – recent comment with avatars
    https://pastebin.com/ZbMMbdtC
    it display all avatars fb or gravatar (working fine)

    but i dont want it as a plugin
    i want short code in widget
    if you can get idea from (https://pastebin.com/ZbMMbdtC) –
    i am not smart in php please help me

    please help me

Viewing 11 replies - 16 through 26 (of 26 total)
  • The topic ‘[Plugin: WPBook] Comments Facebook avatar’ is closed to new replies.