Support » Plugin: Comments - wpDiscuz » MyCred User Ranks and Badges image does not display

  • Resolved whateverfree2

    (@whateverfree2)


    Hi
    I installed WPDicuz and mycred plugin at my site, I have placed the code below to functions.php file. However, the badge did not display correct. Could you please check your code and fix it?

    ////////////////////////////////////////////////////////////////////////
    // MyCred User Ranks and Badges Integration ////////////////////////////
    ////////////////////////////////////////////////////////////////////////
    add_filter('wpdiscuz_after_label', 'wpdiscuz_mc_after_label_html', 110, 2);
    function wpdiscuz_mc_after_label_html($afterLabelHtml, $comment) {
        if ($comment->user_id) {
            if (function_exists('mycred_get_users_rank')) { //User Rank
                $afterLabelHtml .= mycred_get_users_rank($comment->user_id, 'logo', 'post-thumbnail', array('class' => 'mycred-rank'));
            }
            if (function_exists('mycred_get_users_badges')) { //User Badges
                $users_badges = mycred_get_users_badges($comment->user_id);
                if (!empty($users_badges)) {
                    foreach ($users_badges as $badge_id => $level) {
                        $imageKey = ( $level > 0 ) ? 'level_image' . $level : 'main_image';
                        $afterLabelHtml .= '<img src="' . get_post_meta($badge_id, $imageKey, true) . '" width="22" height="22" class="mycred-badge earned" alt="' . get_the_title($badge_id) . '" title="' . get_the_title($badge_id) . '" />';
                    }
                }
            }        
        }
        return $afterLabelHtml;
    }

    Thanks

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support gVectors Support

    (@gvectorssupport)

    Hi,

    Please, try to use this code

    add_filter('wpdiscuz_after_label', 'wpdiscuz_mc_after_label_html', 110, 2);
    
    function wpdiscuz_mc_after_label_html($afterLabelHtml, $comment) {
       $wpdiscuz = wpDiscuz();
       $userID = $comment->user_id;
       if (!$userID && $wpdiscuz->optionsSerialized->isUserByEmail) {
           $user = get_user_by('email', $comment->comment_author_email);
           if ($user) {
               $userID = $user->ID;
           }
       }
       if ($userID) {
           if (function_exists('mycred_get_users_rank')) { //User Rank
               $rank = mycred_get_users_rank($userID);
               if (is_object($rank)) {
                   $src = $rank->logo_url;
                   $title = $rank->title;
                   $afterLabelHtml .= "<img src='$src' title='$title' class='mycred-rank wp-post-image' alt='$title'/>";
               } else {
                   $afterLabelHtml .= mycred_get_users_rank($userID, 'logo', 'post-thumbnail', array('class' => 'mycred-rank'));
               }
           }
       }
       return '<div class="wpdiscuz-mycred-rank-wrap">' . $afterLabelHtml . '</div>';
    }
    whateverfree2

    (@whateverfree2)

    Thansk for replied.

    I replace with your new code but nothing display

    Plugin Support gVectors Support

    (@gvectorssupport)

    We’ve tested this code, it works on our end. You should put it in active theme “functions.php” file.

    Also, when you test it, please make sure that:
    1. myCRED plugin is active
    2. Ranks are enabled

    whateverfree2

    (@whateverfree2)

    Thank you for notifying me. It’s working now. Your code is for Ranks display.

    How about Badges?

    Thanks

    Plugin Support gVectors Support

    (@gvectorssupport)

    Please remove the code, which I provide before and add the following one.

    add_filter('wpdiscuz_after_label', 'wpdiscuz_mc_after_label_html', 110, 2);
    
    function wpdiscuz_mc_after_label_html($afterLabelHtml, $comment) {
       $wpdiscuz = wpDiscuz();
       $userID = $comment->user_id;
       if (!$userID && $wpdiscuz->optionsSerialized->isUserByEmail) {
           $user = get_user_by('email', $comment->comment_author_email);
           if ($user) {
               $userID = $user->ID;
           }
       }
       if ($userID) {
           if (function_exists('mycred_get_users_badges')) { //User Badges
               $wpcusers_badges = mycred_get_users_badges($userID);
               if (!empty($wpcusers_badges)) {
                   $afterLabelHtml .= '<div class="row mycred-users-badges wpdiscuz-mycred-badges-wrap"><div class="col-xs-12">';
                   foreach ($wpcusers_badges as $badge_id => $level) {
                       $afterLabelHtml .= '<div class="the-badge">';
                       if (function_exists("mycred_get_badge")) {
                           $badge = mycred_get_badge($badge_id, $level);
                           if ($badge && isset($badge->level_image) && $badge->level_image !== false) {
                               $afterLabelHtml .= apply_filters('mycred_the_badge', $badge->level_image, $badge_id, $badge, $userID);
                           }
                       } else {
                           $imageKey = ( $level > 0 ) ? 'level_image' . $level : 'main_image';
                           $imgSrc = get_post_meta($badge_id, $imageKey, true);
                           if ($imgSrc) {
                               $afterLabelHtml .= '<img src="' . get_post_meta($badge_id, $imageKey, true) . '" class="mycred-badge earned" alt="' . get_the_title($badge_id) . '"  title="' . get_the_title($badge_id) . '" />';
                           }
                       }
                       $afterLabelHtml .= '</div>';
                   }
                   $afterLabelHtml .= '</div></div>';
               }
           }
           if (function_exists('mycred_get_users_rank')) { //User Rank
               $rank = mycred_get_users_rank($userID);
               if (is_object($rank)) {
                   $src = $rank->logo_url;
                   $title = $rank->title;
                   $afterLabelHtml .= "<img src='$src' title='$title' class='mycred-rank wp-post-image' alt='$title'/>";
               } else {
                   $afterLabelHtml .= mycred_get_users_rank($userID, 'logo', 'post-thumbnail', array('class' => 'mycred-rank'));
               }
           }
       }
       return '<div class="wpdiscuz-mycred-rank-wrap">' . $afterLabelHtml . '</div>';
    }
    whateverfree2

    (@whateverfree2)

    Thank you for the code.

    The badge image still can’t display, I inspect the lost image to see the code and here is the result

    <img src="http://314" class="mycred-badge-image badge-level0" title="Level 1" alt="Level 1" width="100" height="100">

    Is there anyway to give guest user badge and rank via their published comment and the date count (for example: The user with first commend one year ago will get the badge “One year with my site”).

    My idea:
    Guest user who has more 1000 published comment will have rank: VIP member
    If he join (post the first comment) one year ago will get a badge, two year will get an other badge etc.

    Thanks

    Plugin Support gVectors Support

    (@gvectorssupport)

    Please try to use this code.

    add_filter('wpdiscuz_after_label', 'wpdiscuz_mc_after_label_html', 110, 2);
    
    function wpdiscuz_mc_after_label_html($afterLabelHtml, $comment) {
       $wpdiscuz = wpDiscuz();
       $userID = $comment->user_id;
       if (!$userID && $wpdiscuz->optionsSerialized->isUserByEmail) {
           $user = get_user_by('email', $comment->comment_author_email);
           if ($user) {
               $userID = $user->ID;
           }
       }
       if ($userID) {
           if (function_exists('mycred_get_users_badges')) { //User Badges
               $wpcusers_badges = mycred_get_users_badges($userID);
               if (!empty($wpcusers_badges)) {
                   $afterLabelHtml .= '<div class="row mycred-users-badges wpdiscuz-mycred-badges-wrap"><div class="col-xs-12">';
                   foreach ($wpcusers_badges as $badge_id => $level) {
                       $afterLabelHtml .= '<div class="the-badge">';
                       if (function_exists("mycred_get_badge")) {
                           $badge = mycred_get_badge($badge_id, $level);
                           if ($badge && isset($badge->level_image) && $badge->level_image !== false) {
    						    $afterLabelHtml .= apply_filters('mycred_the_badge', $badge->get_image( $level ), $badge_id, $badge, $userID);
                           }
                       } else {
                           $imageKey = ( $level > 0 ) ? 'level_image' . $level : 'main_image';
                           $imgSrc = get_post_meta($badge_id, $imageKey, true);
                           if ($imgSrc) {
                               $afterLabelHtml .= '<img src="' . get_post_meta($badge_id, $imageKey, true) . '" class="mycred-badge earned" alt="' . get_the_title($badge_id) . '"  title="' . get_the_title($badge_id) . '" />';
                           }
                       }
                       $afterLabelHtml .= '</div>';
                   }
                   $afterLabelHtml .= '</div></div>';
               }
           }
           if (function_exists('mycred_get_users_rank')) { //User Rank
               $rank = mycred_get_users_rank($userID);
               if (is_object($rank)) {
                   $src = $rank->logo_url;
                   $title = $rank->title;
                   $afterLabelHtml .= "<img src='$src' title='$title' class='mycred-rank wp-post-image' alt='$title'/>";
               } else {
                   $afterLabelHtml .= mycred_get_users_rank($userID, 'logo', 'post-thumbnail', array('class' => 'mycred-rank'));
               }
           }
       }
       return '<div class="wpdiscuz-mycred-rank-wrap">' . $afterLabelHtml . '</div>';
    }

    Also, please try to update Badges from the admin page.

    kingstakh

    (@kingstakh)

    How set image width and height? Now is 100px

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘MyCred User Ranks and Badges image does not display’ is closed to new replies.