Forked from ipokkel/pmpro-courses-enable-comment-support-for-lessons.php
Created
January 8, 2026 16:01
-
-
Save MaryOJob/46a92d3280580f6614be64d193b420db to your computer and use it in GitHub Desktop.
Allow comments for 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 comment support for the pmpro_lesson custom post type. | |
| * | |
| * Allowing users to comment on lessons may be set with the "Allow comments" | |
| * checkbox option in the "Discussion" metabox on the lesson edit screen. | |
| * | |
| * You can add this recipe to your site by creating a custom plugin | |
| * or using the Code Snippets plugin available for free in the WordPress repository. | |
| * Read this companion article for step-by-step directions on either method. | |
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function my_pmpro_courses_enable_comment_support_for_lessons( $args, $post_type ) { | |
| if ( ! function_exists( 'pmpro_courses_is_module_active' ) || ! pmpro_courses_is_module_active( 'default' ) ) { | |
| return $args; | |
| } | |
| // if post type does not support comments, add support for comments. | |
| if ( 'pmpro_lesson' === $post_type && ! post_type_supports( $post_type, 'comments' ) ) { | |
| $args['supports'][] = 'comments'; | |
| } | |
| return $args; | |
| } | |
| add_filter( 'register_post_type_args', 'my_pmpro_courses_enable_comment_support_for_lessons', 10, 2 ); | |
| // Enable allow comments by default for new lessons. | |
| function my_pmpro_courses_enable_allow_comments_for_lessons( $data, $postarr ) { | |
| if ( ! function_exists( 'pmpro_courses_is_module_active' ) || ! pmpro_courses_is_module_active( 'default' ) ) { | |
| return $data; | |
| } | |
| if ( 'pmpro_lesson' === $data['post_type'] && post_type_supports( $data['post_type'], 'comments' ) ) { | |
| $data['comment_status'] = 'open'; | |
| } | |
| return $data; | |
| } | |
| add_filter( 'wp_insert_post_data', 'my_pmpro_courses_enable_allow_comments_for_lessons', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment