Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created January 12, 2026 09:32
Show Gist options
  • Select an option

  • Save andrewlimaza/9bbe1d2ff85793a75fed27d60f4af12a to your computer and use it in GitHub Desktop.

Select an option

Save andrewlimaza/9bbe1d2ff85793a75fed27d60f4af12a to your computer and use it in GitHub Desktop.
Enable comments on PMPro Courses and Lessons.
<?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