| @@ -144,10 +144,14 @@ | ||
| 144 | 144 | return null; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $newComment = Comment::create($commentData); |
| 148 | - Feed::withoutGlobalScopes()->where('id', $feed->id)->increment('comments_count'); | |
| 149 | 148 | |
| 149 | + // A held comment is not visible yet, so it must not be counted until it is approved. | |
| 150 | + if ($newComment->status === 'published') { | |
| 151 | + Feed::withoutGlobalScopes()->where('id', $feed->id)->increment('comments_count'); | |
| 152 | + } | |
| 153 | + | |
| 150 | 154 | return $newComment; |
| 151 | 155 | }); |
| 152 | 156 | |
| 153 | 157 | if (!$comment) { |
| @@ -155,9 +159,11 @@ | ||
| 155 | 159 | 'message' => __('No duplicate comment please!', 'fluent-community') |
| 156 | 160 | ]); |
| 157 | 161 | } |
| 158 | 162 | |
| 159 | - $feed->comments_count = $feed->comments_count + 1; | |
| 163 | + if ($comment->status === 'published') { | |
| 164 | + $feed->comments_count = $feed->comments_count + 1; | |
| 165 | + } | |
| 160 | 166 | |
| 161 | 167 | |
| 162 | 168 | // Merge and save all media in one loop |
| 163 | 169 | $mediaItems = $mediaItems ? (is_array($mediaItems) ? $mediaItems : [$mediaItems]) : []; |
| @@ -613,9 +619,11 @@ | ||
| 613 | 619 | } |
| 614 | 620 | |
| 615 | 621 | $comment->delete(); |
| 616 | 622 | |
| 617 | - $feed->comments_count = Comment::where('post_id', $feed->id)->count(); | |
| 623 | + $feed->comments_count = Comment::where('post_id', $feed->id) | |
| 624 | + ->where('status', 'published') | |
| 625 | + ->count(); | |
| 618 | 626 | $feed->timestamps = false; // Don't update the updated_at timestamp |
| 619 | 627 | $feed->save(); |
| 620 | 628 | |
| 621 | 629 | do_action('fluent_community/comment_deleted_' . $feed->type, $commentId, $feed); |