From e4eb0c4f3309143545653f70ee8683f2a3263c22 Mon Sep 17 00:00:00 2001 From: Miroslav Mitev Date: Tue, 16 Sep 2025 18:59:17 +0300 Subject: [PATCH 1/2] Fix lesson comments being visible in some cases --- ...son-comments-visible-to-unregistered-users | 4 ++++ ...s-sensei-unsupported-theme-handler-cpt.php | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 changelog/fix-lesson-comments-visible-to-unregistered-users diff --git a/changelog/fix-lesson-comments-visible-to-unregistered-users b/changelog/fix-lesson-comments-visible-to-unregistered-users new file mode 100644 index 0000000000..eae0fc51ea --- /dev/null +++ b/changelog/fix-lesson-comments-visible-to-unregistered-users @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +Fix lesson comments being visible to unregistered users in some cases diff --git a/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-cpt.php b/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-cpt.php index e6e4495676..5bd8170d91 100644 --- a/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-cpt.php +++ b/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-cpt.php @@ -76,7 +76,7 @@ public function handle_request() { add_filter( 'template_include', array( $this, 'force_page_template' ) ); // Disable comments if not block theme and post type is not lesson. - if ( ! $this->is_lesson_cpt_in_block_fse_theme() ) { + if ( ! $this->should_show_comments() ) { Sensei_Unsupported_Theme_Handler_Utils::disable_comments(); } @@ -121,7 +121,7 @@ public function cpt_page_content_filter( $content ) { $content = $renderer->render(); // Disable theme comments. - if ( ! $this->is_lesson_cpt_in_block_fse_theme() ) { + if ( ! $this->should_show_comments() ) { Sensei_Unsupported_Theme_Handler_Utils::disable_comments(); } @@ -247,4 +247,19 @@ public function force_page_template( $template ) { private function is_lesson_cpt_in_block_fse_theme() { return 'lesson' === $this->post_type && Sensei_Utils::is_fse_theme(); } + + /** + * Determine if comments should be shown. + * + * Comments are only shown for lessons in block themes if the user can view + * the lesson. + * + * @since $$next-version$$ + * + * @return bool + */ + private function should_show_comments(): bool { + return $this->is_lesson_cpt_in_block_fse_theme() + && sensei_can_user_view_lesson(); + } } From 53a418f16815e216e8c4d8fc1feb4015e36b272c Mon Sep 17 00:00:00 2001 From: Miroslav Mitev Date: Wed, 17 Sep 2025 17:42:03 +0300 Subject: [PATCH 2/2] Use the instance `post_id` instead of relying on the global `$post` Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../class-sensei-unsupported-theme-handler-cpt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-cpt.php b/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-cpt.php index 5bd8170d91..e33e377fac 100644 --- a/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-cpt.php +++ b/includes/unsupported-theme-handlers/class-sensei-unsupported-theme-handler-cpt.php @@ -260,6 +260,6 @@ private function is_lesson_cpt_in_block_fse_theme() { */ private function should_show_comments(): bool { return $this->is_lesson_cpt_in_block_fse_theme() - && sensei_can_user_view_lesson(); + && sensei_can_user_view_lesson( $this->post_id ); } }