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..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 @@ -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( $this->post_id ); + } }