Created
January 12, 2026 09:32
-
-
Save andrewlimaza/9bbe1d2ff85793a75fed27d60f4af12a to your computer and use it in GitHub Desktop.
Enable comments on PMPro Courses and Lessons.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Enable comments for Courses and Lessons for members with access. | |
| * People who don't have access will only be able to view comments only. Great for upselling lessons and courses. | |
| * | |
| * To add this code to your site, follow this guide - https://www.paidmembershipspro.com/documentation/templates/customizing-via-a-custom-plugin/ | |
| */ | |
| function my_pmpro_courses_enable_comments( $open, $post_id ) { | |
| // Check if the person has access to the post type to comment. | |
| if ( function_exists( 'pmpro_has_membership_access' ) ) { | |
| if ( ! pmpro_has_membership_access( $post_id ) ) { | |
| return false; | |
| } | |
| } | |
| $courses_cpt = array( 'pmpro_course', 'pmpro_lesson' ); | |
| $post = get_post( $post_id ); | |
| if ( $post && in_array( $post->post_type, $courses_cpt ) ) { | |
| return true; | |
| } | |
| return $open; | |
| } | |
| add_filter( 'comments_open', 'my_pmpro_courses_enable_comments', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment