Update comment badge filter
This commit is contained in:
parent
c0af4d2c81
commit
c34c1514e0
13
FILTERS.md
13
FILTERS.md
@ -240,13 +240,18 @@ Filters the queried comments in the `comments.php` template and `fictioneer_ajax
|
||||
|
||||
---
|
||||
|
||||
### `apply_filters( 'fictioneer_filter_comment_badge', $output, $badge, $badge_class )`
|
||||
### `apply_filters( 'fictioneer_filter_comment_badge', $output, $user, $args )`
|
||||
Filters the HTML of the `fictioneer_get_comment_badge( $user, $comment, $post_author_id )` function before it is returned for rendering. The badge class and label are inserted into `<div class="fictioneer-comment__badge CLASS"><span>LABEL</span></div>`. Possible label classes are `is-author`, `is-admin`, `is-moderator`, `is-supporter`, and `badge-override`.
|
||||
|
||||
**Parameters:**
|
||||
* $output (string) – Complete HTML of the comment badge.
|
||||
* $badge (string) – Label of the badge.
|
||||
* $badge_class (string) – Class of the badge.
|
||||
* $output (string) – Complete HTML of the comment badge or empty string.
|
||||
* $user (WP_User|null) – The user object. Unsafe.
|
||||
|
||||
**$args:**
|
||||
* $badge (string) – Label of the badge or empty string.
|
||||
* $class (string) – Class of the badge or empty string.
|
||||
* $comment (WP_Comment|null) – Comment object or null if called outside a comment.
|
||||
* $post_author_id (int) – ID of the author of the post the comment is for or `0`.
|
||||
|
||||
---
|
||||
|
||||
|
@ -445,21 +445,28 @@ if ( ! function_exists( 'fictioneer_get_comment_badge' ) ) {
|
||||
*
|
||||
* @since Fictioneer 5.0
|
||||
*
|
||||
* @param WP_User $user The comment user.
|
||||
* @param WP_Comment|null $comment The comment object.
|
||||
* @param WP_User|null $user The comment user.
|
||||
* @param WP_Comment|null $comment Optional. The comment object.
|
||||
* @param int $post_author_id Optional. ID of the author of the post
|
||||
* the comment is for.
|
||||
*
|
||||
* @return string Badge HTML or empty string.
|
||||
*/
|
||||
|
||||
function fictioneer_get_comment_badge( $user, $comment, $post_author_id = 0 ) {
|
||||
function fictioneer_get_comment_badge( $user, $comment = null, $post_author_id = 0 ) {
|
||||
// Pre-setup
|
||||
$user_id = $user ? $user->ID : 0;
|
||||
$filter_args = array(
|
||||
'comment' => $comment,
|
||||
'post_author_id' => $post_author_id
|
||||
);
|
||||
|
||||
// Abort conditions...
|
||||
if ( empty( $user_id ) || get_the_author_meta( 'fictioneer_hide_badge', $user_id ) ) {
|
||||
return apply_filters( 'fictioneer_filter_comment_badge', '', '', 'is-guest' );
|
||||
$filter_args['class'] = 'is-guest';
|
||||
$filter_args['badge'] = '';
|
||||
|
||||
return apply_filters( 'fictioneer_filter_comment_badge', '', $user, $filter_args );
|
||||
}
|
||||
|
||||
// Setup
|
||||
@ -514,7 +521,11 @@ if ( ! function_exists( 'fictioneer_get_comment_badge' ) ) {
|
||||
|
||||
// Apply filters
|
||||
$output = empty( $badge ) ? '' : sprintf( $badge_body, $badge_class, $badge );
|
||||
$output = apply_filters( 'fictioneer_filter_comment_badge', $output, $badge, $badge_class );
|
||||
|
||||
$filter_args['class'] = $badge_class;
|
||||
$filter_args['badge'] = $badge;
|
||||
|
||||
$output = apply_filters( 'fictioneer_filter_comment_badge', $output, $user, $filter_args );
|
||||
|
||||
// Return badge or empty sting
|
||||
return $output;
|
||||
|
Loading…
x
Reference in New Issue
Block a user