Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ipokkel/1cb9d90ae5840d43b7dd809abe471b93 to your computer and use it in GitHub Desktop.

Select an option

Save ipokkel/1cb9d90ae5840d43b7dd809abe471b93 to your computer and use it in GitHub Desktop.
Allow comments for Lessons.
<?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