AuthorPostUrl.php
2 days ago
CommentCount.php
2 days ago
FirstPost.php
2 days ago
FullName.php
2 days ago
HasRichEditing.php
2 days ago
LastPost.php
2 days ago
Meta.php
2 days ago
PostCount.php
2 days ago
PostCountOriginal.php
2 days ago
Property.php
2 days ago
Roles.php
2 days ago
ShowToolbar.php
2 days ago
TranslatedRoles.php
2 days ago
UserFilteredPostLink.php
2 days ago
UserLink.php
2 days ago
UserName.php
2 days ago
CommentCount.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\User; |
| 6 | |
| 7 | use AC\Formatter; |
| 8 | use AC\Type\Value; |
| 9 | |
| 10 | class CommentCount implements Formatter |
| 11 | { |
| 12 | public function format(Value $value): Value |
| 13 | { |
| 14 | $user_id = (int)$value->get_id(); |
| 15 | |
| 16 | $count = $this->get_user_comments($user_id); |
| 17 | |
| 18 | return $count |
| 19 | ? $value->with_value( |
| 20 | sprintf( |
| 21 | '<a href="%s">%d</a>', |
| 22 | add_query_arg(['user_id' => $user_id], admin_url('edit-comments.php')), |
| 23 | $count |
| 24 | ) |
| 25 | ) |
| 26 | : $value->with_value(false); |
| 27 | } |
| 28 | |
| 29 | private function get_user_comments(int $user_id): int |
| 30 | { |
| 31 | return (int)get_comments([ |
| 32 | 'user_id' => $user_id, |
| 33 | 'count' => true, |
| 34 | 'orderby' => 'none', |
| 35 | ]); |
| 36 | } |
| 37 | |
| 38 | } |
| 39 |