| @@ -28,9 +28,18 @@ | ||
| 28 | 28 | 'message' => __('Sorry, you do not have permission to view this post', 'fluent-community') |
| 29 | 29 | ], 404); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - $canViewComments = apply_filters('fluent_community/can_view_comments_' . $feed->type, true, $feed); | |
| 32 | + /* | |
| 33 | + * The row's own setting is the default the filter gets handed, rather than a bare | |
| 34 | + * true. Before this, meta.enable_comments was read nowhere on this path, so a page | |
| 35 | + * with comments switched off still served its thread to anyone who asked for it. | |
| 36 | + */ | |
| 37 | + $canViewComments = apply_filters( | |
| 38 | + 'fluent_community/can_view_comments_' . $feed->type, | |
| 39 | + FeedsHelper::commentsEnabled($feed), | |
| 40 | + $feed | |
| 41 | + ); | |
| 33 | 42 | |
| 34 | 43 | if (!$canViewComments) { |
| 35 | 44 | return [ |
| 36 | 45 | 'comments' => [] |
| @@ -135,10 +144,14 @@ | ||
| 135 | 144 | return null; |
| 136 | 145 | } |
| 137 | 146 | |
| 138 | 147 | $newComment = Comment::create($commentData); |
| 139 | - Feed::withoutGlobalScopes()->where('id', $feed->id)->increment('comments_count'); | |
| 140 | 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 | + | |
| 141 | 154 | return $newComment; |
| 142 | 155 | }); |
| 143 | 156 | |
| 144 | 157 | if (!$comment) { |
| @@ -146,9 +159,11 @@ | ||
| 146 | 159 | 'message' => __('No duplicate comment please!', 'fluent-community') |
| 147 | 160 | ]); |
| 148 | 161 | } |
| 149 | 162 | |
| 150 | - $feed->comments_count = $feed->comments_count + 1; | |
| 163 | + if ($comment->status === 'published') { | |
| 164 | + $feed->comments_count = $feed->comments_count + 1; | |
| 165 | + } | |
| 151 | 166 | |
| 152 | 167 | |
| 153 | 168 | // Merge and save all media in one loop |
| 154 | 169 | $mediaItems = $mediaItems ? (is_array($mediaItems) ? $mediaItems : [$mediaItems]) : []; |
| @@ -431,9 +446,9 @@ | ||
| 431 | 446 | } |
| 432 | 447 | |
| 433 | 448 | private function validateCommentText($data) |
| 434 | 449 | { |
| 435 | - $text = trim(Arr::get($data, 'comment')); | |
| 450 | + $text = trim((string) Arr::get($data, 'comment', '')); | |
| 436 | 451 | $text = CustomSanitizer::unslashMarkdown($text); |
| 437 | 452 | |
| 438 | 453 | // Decode HTML entities (e.g.,   for space) and strip all whitespace for validation |
| 439 | 454 | $textForValidation = html_entity_decode($text, ENT_QUOTES | ENT_HTML5, 'UTF-8'); |
| @@ -460,9 +475,9 @@ | ||
| 460 | 475 | } |
| 461 | 476 | |
| 462 | 477 | private function verifyCreateCommentPermission($feed) |
| 463 | 478 | { |
| 464 | - if (Arr::get($feed->meta, 'comments_disabled') === 'yes') { | |
| 479 | + if (!FeedsHelper::commentsEnabled($feed)) { | |
| 465 | 480 | throw new \Exception(esc_html__('Comments are disabled for this post', 'fluent-community')); |
| 466 | 481 | } |
| 467 | 482 | |
| 468 | 483 | $this->verifySpacePermission($feed); |
| @@ -604,9 +619,11 @@ | ||
| 604 | 619 | } |
| 605 | 620 | |
| 606 | 621 | $comment->delete(); |
| 607 | 622 | |
| 608 | - $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(); | |
| 609 | 626 | $feed->timestamps = false; // Don't update the updated_at timestamp |
| 610 | 627 | $feed->save(); |
| 611 | 628 | |
| 612 | 629 | do_action('fluent_community/comment_deleted_' . $feed->type, $commentId, $feed); |