wpDiscuz 7 API Documentation

⌘K
  1. Home
  2. Docs
  3. wpDiscuz 7 API Documentat...
  4. Filters
  5. wpdiscuz_show_vote

wpdiscuz_show_vote

This filter can be used to hide the voting component on individual comments.

Parameters

  1. $showVote (type: bool) – whether the voting component should be rendered. Arrives as the value of the Show Voting Buttons setting
  2. $comment (type: WP_Comment object) – the comment being rendered
  3. $commentUser (type: WP_User object or empty string) – the comment author’s user object, or an empty string when the author is a guest
  4. $currentUser (type: WP_User object) – the current visitor. Its ID is 0 for guests

Usage

add_filter("wpdiscuz_show_vote", "my_hide_vote_from_guests", 10, 4);

function my_hide_vote_from_guests($showVote, $comment, $commentUser, $currentUser) {
    if (!$currentUser->ID) {
        return false;
    }

    return $showVote;
}

Note

Callbacks written before 7.6.67 change meaning on upgrade. The filter previously received a hardcoded false and its return value was discarded on the next line, so no callback had any effect. From 7.6.67 the returned value is respected.

A callback returning false was a no-op before and now hides the voting component. A callback returning true did nothing before and still cannot force the component on.

The global Show Voting Buttons setting and the comment’s approval status are applied after the filter and cannot be overridden by it. Self-voting no longer routes through this filter to hide the component – it renders read-only instead, with the totals visible and the buttons hidden by the wpd-vote-readonly class.

Changelog

Since 5.3.1 version
Starting from the 7.6.67 version the returned value is now respected, and the incoming value reflects the Show Voting Buttons setting instead of always being false.