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`.
|
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:**
|
**Parameters:**
|
||||||
* $output (string) – Complete HTML of the comment badge.
|
* $output (string) – Complete HTML of the comment badge or empty string.
|
||||||
* $badge (string) – Label of the badge.
|
* $user (WP_User|null) – The user object. Unsafe.
|
||||||
* $badge_class (string) – Class of the badge.
|
|
||||||
|
**$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
|
* @since Fictioneer 5.0
|
||||||
*
|
*
|
||||||
* @param WP_User $user The comment user.
|
* @param WP_User|null $user The comment user.
|
||||||
* @param WP_Comment|null $comment The comment object.
|
* @param WP_Comment|null $comment Optional. The comment object.
|
||||||
* @param int $post_author_id Optional. ID of the author of the post
|
* @param int $post_author_id Optional. ID of the author of the post
|
||||||
* the comment is for.
|
* the comment is for.
|
||||||
*
|
*
|
||||||
* @return string Badge HTML or empty string.
|
* @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
|
// Pre-setup
|
||||||
$user_id = $user ? $user->ID : 0;
|
$user_id = $user ? $user->ID : 0;
|
||||||
|
$filter_args = array(
|
||||||
|
'comment' => $comment,
|
||||||
|
'post_author_id' => $post_author_id
|
||||||
|
);
|
||||||
|
|
||||||
// Abort conditions...
|
// Abort conditions...
|
||||||
if ( empty( $user_id ) || get_the_author_meta( 'fictioneer_hide_badge', $user_id ) ) {
|
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
|
// Setup
|
||||||
@ -514,7 +521,11 @@ if ( ! function_exists( 'fictioneer_get_comment_badge' ) ) {
|
|||||||
|
|
||||||
// Apply filters
|
// Apply filters
|
||||||
$output = empty( $badge ) ? '' : sprintf( $badge_body, $badge_class, $badge );
|
$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 badge or empty sting
|
||||||
return $output;
|
return $output;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user