Skip to content

Instantly share code, notes, and snippets.

@pasadamedia
Last active March 23, 2018 19:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasadamedia/c18d5cd135ddb5085ed0 to your computer and use it in GitHub Desktop.
Save pasadamedia/c18d5cd135ddb5085ed0 to your computer and use it in GitHub Desktop.
Display WooThemes Sensei comments and messages in a Genesis framework child theme. Insert in your child theme's functions.php file.
/**
* Remove Sensei comments output and replace with comments done the Genesis way.
*
* @notes Extends the WooThemes_Sensei_Frontend class.
*
*/
if (class_exists('WooThemes_Sensei_Frontend')) {
remove_action( 'sensei_comments', array( $woothemes_sensei->frontend, 'sensei_output_comments' ), 10 );
add_action( 'sensei_comments', array( 'WooThemes_Sensei_Frontend_Comments', 'pasada_sensei_output_comments' ), 10 );
class WooThemes_Sensei_Frontend_Comments extends WooThemes_Sensei_Frontend
{
function pasada_sensei_output_comments()
{
global $woothemes_sensei, $view_lesson, $user_taking_course;
$allow_comments = $woothemes_sensei->settings->settings['lesson_comments'];
if ( is_user_logged_in() && $allow_comments && ( isset( $view_lesson ) && $view_lesson ) && ( isset( $user_taking_course ) && $user_taking_course )) {
genesis_get_comments_template();
} elseif ( is_singular( 'sensei_message' ) ) {
genesis_get_comments_template();
}
}
}
}
@rothschild86
Copy link

thank you!

@tsemp
Copy link

tsemp commented Mar 29, 2016

Hi there,

Thank you for posting this - it solved all our issues - until sensei 1.9 was released :(

I was hoping that by replacing the deprecated "sensei_comments" hook with "sensei_after_main_content" was going to fix it but that didn't quite work. I'm not new to coding but I am new to web development ..

For whatever reason, ( isset( $view_lesson ) && $view_lesson ) && ( isset( $user_taking_course ) && $user_taking_course )) all return nothing so the comments never get displayed.

I tried shortening it to if ( is_user_logged_in() && $allow_comments ) { for testing - that displayed the students comments but not the teacher's replies?!

Do you by any chance have a workaround that works with Sensei > 1.8?

Thanks
K

@zao3d
Copy link

zao3d commented Dec 12, 2017

Hi, I see that there are not response here for long time. I have the same problem with the comments. I'm using Genesis Framework and Woothemes Sensei 1.9.19. For now is not working anymore the comments. Any solution for that?

@chvillanuevap
Copy link

chvillanuevap commented Mar 13, 2018

Add the following to your functions.php file:

remove_action( 'sensei_pagination', array( 'Sensei_Lesson', 'output_comments' ), 90 );

add_action( 'sensei_pagination', function() {

	$course_id = Sensei()->lesson->get_course_id( get_the_ID() );
	$allow_comments = Sensei()->settings->settings[ 'lesson_comments' ];
	$user_taking_course = Sensei_Utils::user_started_course($course_id );

	$lesson_allow_comments = $allow_comments  && $user_taking_course;

	if (  $lesson_allow_comments || is_singular( 'sensei_message' ) ) {

		comments_template( '', true );

	}

}, 90 );

The problem is Genesis requires comments to be separated into comment, ping, and trackback groups. The way Sensei outputs comments is by using the output_comments function, and then calling comments_template(). I removed the default way Sensei outputs comments, and wrote comments_template( '', true ) to make it compatible with Genesis.

@zao3d
Copy link

zao3d commented Mar 23, 2018

Thank you! That's works perfectly. Interesting your comment about how Genesis requires comments.

See you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment