• ResolvedPlugin Author gVectors Team

    (@gvectors-team)


    In wpDiscuz 3.0.5 we’ve added a filter hook which allows to show MyCred badges under comment author avatar. But we couldn’t add the whole MyCred code in wpDiscuz core files, that would be a hard integration which is not recommended.
    So please put this code in your current active theme’s functions.php file in order to display those badges:

    <?php
    add_filter('wpdiscuz_after_label', 'add_wpd_mycred_badges', 110);
    function add_wpd_mycred_badges($comment) {
        $image = '';
        if (is_null($comment))
            return $image;
        if (function_exists('mycred_get_users_rank') && $comment->user_id) {
            $image .= mycred_get_users_rank($comment->user_id, 'logo', 'post-thumbnail', array('class' => 'mycred-rank'));
        }
    
        if (function_exists('mycred_get_users_badges') && $comment->user_id) {
    
            $users_badges = mycred_get_users_badges($comment->user_id);
            if (!empty($users_badges)) {
                foreach ($users_badges as $badge_id => $level)
                    $image .= '<img src="' . get_post_meta($badge_id, 'main_image', true) . '" width="24" height="24" class="mycred-badge earned" alt="' . get_the_title($badge_id) . '" title="' . get_the_title($badge_id) . '" />';
            }
        }
        return $image;
    }
    ?>

    https://www.ads-software.com/plugins/wpdiscuz/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author gVectors Team

    (@gvectors-team)

    == UPDATE ==
    For wpDiscuz 3.0.6 and higher versions please use this code instead of the one above:

    add_filter('wpdiscuz_after_label', 'add_wpd_mycred_badges', 110);
    function add_wpd_mycred_badges($args) {
       $image = ''; $comment = $args[1];
       if (is_null($comment)) return $image;
       if (function_exists('mycred_get_users_rank') && $comment->user_id) { $image .= mycred_get_users_rank($comment->user_id, 'logo', 'post-thumbnail', array('class' => 'mycred-rank')); }
       if (function_exists('mycred_get_users_badges') && $comment->user_id) { $users_badges = mycred_get_users_badges($comment->user_id); if (!empty($users_badges)) { foreach ($users_badges as $badge_id => $level) $image .= '<img src="' . get_post_meta($badge_id, 'main_image', true) . '" width="24" height="24" class="mycred-badge earned" alt="' . get_the_title($badge_id) . '" title="' . get_the_title($badge_id) . '" />'; } }
       return array($image,$comment);
    }
    Plugin Author gVectors Team

    (@gvectors-team)

    == UPDATE ==

    ////////////////////////////////////////////////////////////////////////
    // 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) {
            // keep your preffered profile plugin and remove others...
            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) . '" />';
                    }
                }
            }
            if (class_exists('userpro_api')) { // userpro user badges
                $afterLabelHtml .= userpro_show_badges($comment->user_id, $inline = true);
            }
        }
        return $afterLabelHtml;
    }

    it doesn’t work unfortunately ??

    Plugin Author gVectors Team

    (@gvectors-team)

    Make sure you’re adding this code in current active theme’s functions.php file. Put it after all functions:

    ////////////////////////////////////////////////////////////////////////
    // 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;
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to show MyCred badges under comment author avatar’ is closed to new replies.