Support » Plugin: Comments - wpDiscuz » Comment badge, how to have more or custom?

  • Resolved peopleinside

    (@peopleinside)


    Hi,
    thank you for this wonder plugin.

    A question:
    I read the guide User Labels and Badges

    The guide say:

    In the Dashboard > wpDiscuz > Settings > User Labels and Badges admin page you can manage User Labels and Colors. User Labels are small rectangles with specific background colors and text indicating comment author role, such as Guest, Member, Author, Admin, etc… These labels can be enabled and disabled for certain user role.

    but is not saying how I can assign a badge to an user.

    When I made a comment with my administrator account, I have the badge post author because I created the post where I’m commenting. If I want have also the badge administrator that is my rule, how I can do?

    Thanks.

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

    (@gvectorssupport)

    Dear peopleinside ,

    You can use the wpdiscuz_after_label hook for adding extra badges. More info here: https://wpdiscuz.com/docs/codex/filters/wpdiscuz_after_label/

    If you want to replace the “Author” label with “Administrator”, you can use the hook code below:

    add_filter("wpdiscuz_author_title", function ($label, $comment) {
        global $post;
        if ($comment->user_id == $post->post_author) {
            $label = __("Administrator", "wpdiscuz");
        }
        return $label;
    }, 10, 2);
    Thread Starter peopleinside

    (@peopleinside)

    @gvectorssupport thanks for the answer. Not really easy and this code where need to be added?
    If I want not replace but show both badges?

    Plugin Support gVectors Support

    (@gvectorssupport)

    If I want not replace but show both badges?

    Then you should use the wpdiscuz_after_label hook. Here is an example:

    add_filter("wpdiscuz_after_label", function ($afterLabelHtml, $comment) {
        global $post;
        if ($comment->user_id == $post->post_author) {
            $afterLabelHtml =  "<span> Administrator </span>";
        }
        return $afterLabelHtml;
    }, 110, 2);

    The code should be added in the active theme functions.php file. Helpful article: https://www.rosehosting.com/blog/how-to-add-code-to-functions-php-in-wordpress/

    Thread Starter peopleinside

    (@peopleinside)

    @gvectorssupport thanks,

    this seems work partially. The badge administrator is added but is not respecting color.

    https://i.postimg.cc/hGqCrTX8/Immagine-2022-07-02-164116.png

    https://i.postimg.cc/1RYJdLg3/color-abel-Immagine-2022-07-02-164225.png

    Plugin Support gVectors Support

    (@gvectorssupport)

    Please note, the code is just an example, you should customize and make it work as you like. You should apply some classes to the span, add paddings, etc.

    Here is a simple example:

    add_filter("wpdiscuz_after_label", function ($afterLabelHtml, $comment) {
        global $post;
        if ($comment->user_id == $post->post_author) {
            $afterLabelHtml =  "<span class='wpd-comment-label'> Admin </span>";
        }
        return $afterLabelHtml;
    }, 110, 2);
    Thread Starter peopleinside

    (@peopleinside)

    Thanks for the reply @gvectorssupport .

    This code you give me seems dangerous as generate a fatal error to WordPress.
    Is not so easy do what I’m asking and what your guide try to explain, seems need to be very expert to do that and also your code is not working.

    Plugin Support gVectors Support

    (@gvectorssupport)

    Dear peopleinside,

    The code doesn’t cause any issue. Please watch this video: https://www.screencast.com/t/Xu6B6MXLae

    If you’re not familiar with adding/changing some codes, you should ask a developer to make the customizations for you.

    Thread Starter peopleinside

    (@peopleinside)

    @gvectorssupport thanks for the video.
    The issue where your code broken my site is something caused by a plugin I use to add functions to function.php

    I tried to insert the code creating a child theme and your code work.
    Thanks, I will report the issue of crashing to the other plugin that I use: My Custom Functions

    Thread Starter peopleinside

    (@peopleinside)

    In any case I see the Author badge has a text size different from the text size of the second badge added. Again there is an issue.

    Plugin Support gVectors Support

    (@gvectorssupport)

    Dear peopleinside,

    There is not any issues.

    Please note, the code is just an example, you should customize and make it work as you like. You should apply some classes to the span, add paddings, etc.

    As I’ve already mentioned, this is just an example. You should make customizations you like based on it.

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.