How to activate comments below lessons in Coursepress ?

Hello,

Just wanted to know if it was possible to activate the regular commenting function of Wordpress within courses units, so that people can comment and leave questions for all to see. And if yes, how ? Couldn't find this in the setting.

Thanks a lot,

DJ

  • Rupok

    Hi DJ, thanks for asking.

    if it was possible to activate the regular commenting function of Wordpress within courses units

    Our Team Lead Bojan Radonic provided a nice workaround regarding this query, here: https://premium.wpmudev.org/forums/topic/i-would-like-to-add-the-default-comment-section-under-each#post-1083231

    Can you please follow that and check if that helps? If it doesn't work for you, please let us know. We will be glad to help further.

    Have a nice day. Cheers!
    Rupok

  • DJExp

    Hi there,

    Getting back to you after I asked my outsourcer to work on this based on the post you mentionned.

    He tells me :

    Page all unit didn;t have unique ID means the ID are Zero(0),
    Force added template comment will result show all post ID comment's.

    so my conclusion it's imposible without changed the struktur and table plugin coursespro

    (sorry for the broken english, but If I managed to understand surely you will as well ^^).

    Any answer to that ? Is there a way to do it on the unit level ? Please let me know, thanks.

  • Nithin

    Hi DJExp,

    Hope you are doing good today. :slight_smile:

    To activate the comments in your unit page, you could add the following code in your child themes, functions.php file:

    add_filter( 'comments_open', 'wpmudev_unit_comments_open', 10, 2 );
    
    function wpmudev_unit_comments_open( $open, $post_id ) {
    
        $post = get_post( $post_id );
    
        if ( 'unit' == $post->post_type )
            $open = true;
    
        return $open;
    }

    Once done, you'll have to create a new template single-unit.php in your child theme, and add the following code to it.

    <?php
    /**
     * The template for displaying all single unit
     *
     */
    
    global $coursepress, $wp, $wp_query;
    
    $course_id = do_shortcode('[get_parent_course_id]');
    
    add_thickbox();
    
    $paged = ! empty( $wp->query_vars['paged'] ) ? absint($wp->query_vars['paged']) : 1;
    //redirect to the parent course page if not enrolled or not preview unit/page
    while ( have_posts() ) : the_post();
        $coursepress->check_access($course_id, get_the_ID());
    endwhile;
    
    get_header();
    $post = $unit->details;
    ?>
    <?php if(get_post_type() != 'course') { ?>
    <div class="row row-pad-10">
    	<div class="col-md-8">
    		<div id="post-<?php the_id();?>" class="post post-default">
    			<?php while ( have_posts() ) : the_post();
    			if(has_post_thumbnail()){ ?>
    			<div class="post-image"><img src="<?php echo get_img_url(0)?>" /></div>
    			<?php }?>
        		<div class="post-title"><h1><?php the_title();?></h1></div>
    			<div class="post-content"><?php the_content();?></div>
    			<?php post_nav(); ?>
    			<?php comments_template(); ?>
    		 	<?php endwhile;?>
    		</div>
    	</div>
    	<div class="col-md-4">
    		<?php get_sidebar(); ?>
    	</div>
    </div>
    <?php } else { ?>
    <div class="row row-pad-10">
    	<div class="col-md-4">
    		<?php get_sidebar('member'); ?>
    	</div>
    	<div class="col-md-8">
    		<div id="post-<?php the_id();?>" class="post post-course x123">
    			<?php while ( have_posts() ) : the_post();?>
        		<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <header class="entry-header">
                        <h3 class="entry-title course-title"><?php echo do_shortcode('[course_title course_id="' . $course_id . '"]'); ?></h3>
                        <?php
                        //echo do_shortcode('[course_unit_details unit_id="' . get_the_ID() . '" field="parent_course"]');
                        ?>
                    </header><!-- .entry-header -->
                    <div class="instructors-content"></div>
                    <?php
                    echo do_shortcode('[course_unit_archive_submenu course_id="' . $course_id . '"]');
                    ?>
    
                    <div class="clearfix"></div>
    
                    <?php echo do_shortcode( '[course_unit_page_title unit_id="' . $unit->details->ID . '" title_tag="h3" show_unit_title="yes"]' ); ?>
    
                    <?php
                    Unit_Module::get_modules_front($unit->details->ID);
                    ?>
                </article>
                <?php comment_form(); ?>
    
    			<?php endwhile;?>
    		</div>
    	</div>
    </div>
    <?php }	?>
    <?php get_footer(); ?>

    I hope this helps. Please let us know if you still need any further assistance. Have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • DJExp

    Hi,

    Sadly it seems it doesn't work. Here's what my outsourcer tells me :

    "i have tried that code.
    it's only show form comment. but list comments wont show.
    => its because the support use comment_form() instead comments_template(). (tried use comments_template() result not show anything)
    => if use comment_form() = you can see the list comment on dashboard > comment. (cant delete, trash, edit, etc).

    i recode and style again. forced the comment won't do anymore on unit post. this will only show form comment.
    http://acadinvest.com/courses/assurance-vie-arlequin/units/4-presentation-du-fournisseur-2/

    single-unit.php:

    <?php
    /**
    * The template for displaying all single unit
    *
    */
    
    global $coursepress, $wp, $wp_query;
    
    $course_id = do_shortcode('[get_parent_course_id]');
    
    add_thickbox();
    
    $paged = ! empty( $wp->query_vars['paged'] ) ? absint($wp->query_vars['paged']) : 1;
    //redirect to the parent course page if not enrolled or not preview unit/page
    while ( have_posts() ) : the_post();
        $coursepress->check_access($course_id, get_the_ID());
    endwhile;
    
    get_header();
    $post = $unit->details;
    // var_dump($post);
    ?>
    
    <div class="row row-pad-10 single-unit side-member">
        <div class="col-md-4">
        <?php get_sidebar('member'); ?>
        </div>
        <div class="col-md-8">
            <div id="post-<?php the_id();?>" class="post">
            <?php while ( have_posts() ) : the_post();?>
                <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <header class="entry-header">
                        <h3 class="entry-title course-title"><?php echo do_shortcode('[course_title course_id="' . $course_id . '"]'); ?></h3>
                        <?php
                        //echo do_shortcode('[course_unit_details unit_id="' . get_the_ID() . '" field="parent_course"]');
                        ?>
                    </header><!-- .entry-header -->
                    <div class="instructors-content"></div>
                    <?php
                    echo do_shortcode('[course_unit_archive_submenu course_id="' . $course_id . '"]');
                    ?>
    
                    <div class="clearfix"></div>
    
                    <?php echo do_shortcode( '[course_unit_page_title unit_id="' . $unit->details->ID . '" title_tag="h3" show_unit_title="yes"]' ); ?>
    
                    <?php
                    Unit_Module::get_modules_front($unit->details->ID);
                    ?>
                </article>
                <div class="comments-wrapper">
                    <?php comment_form(); ?>
                </div>
            <?php endwhile;?>
            </div>
        </div>
    </div>
    
    <?php get_footer(); ?>

    function.php:

    <?php
    add_filter( 'comments_open', 'wpmudev_unit_comments_open', 10, 2 );
    function wpmudev_unit_comments_open( $open, $post_id ) {
        $post = get_post( $post_id );
        if ( 'unit' == $post->post_type ){
            $open = true;
        }
        return $open;
    }
    ?>
  • Nithin

    Hi DJExp,

    Hope you are doing good today. :slight_smile:

    I suppose, you meant to edit/delete etc the comments in the front end, I'm afraid this would require a lot of custom coding to achieve such functionality. I'm pinging the developer asking to give a look regrading this, and check whether there would be any quick workaround. Either myself, or the developer will keep you posted.

    Kind Regards,
    Nithin

  • DJExp

    Thanks Nithin, please let me know.

    We don't especially need to work on the comments from the front-end : my customer can login backend to edit the comment. The problem is that, for now :

    We can add a comment on Unit level, but it doesn't display. I assume is because comments needs to be validated, which make sense. Problem is, when I log in as admin and try to validate the comment, it doesn't work, it seems the comment is not recognized. (When I hover over the comment with my mouse, the menu to validate, delete, mark as spam, etc., don't appear. Please check for yourself, it'll be more clear and you have access).

    So for now, people can post comments but it's of no use since people can't see it and validate it.

    Any idea ? Thanks a lot,

    Dushan

    P.S : For a future version it would be a great idea to include an option to use the standard comment system within the units. The wordpress comment system is a very cool way to allow people to ask questions about a specific courses, and there is no equivalent functionality in CoursePress. It would be a big improvement of the plugin. :wink:

  • Nithin

    Hi DJExp,

    Thank you for enabling support access, I could notice the issue, however I did test the above templates, that I shared, and it does seem to show the link to edit, delete etc.

    But these links were missing from your comments. I'm pinging the developer, asking to give a look, and see whether we could have any quick workaround. Will keep you posted regarding this.

    Kind Regards,
    Nithin

  • Nithin

    Hi DJExp,

    Could you please try the following, in your single-unit.php file, and see how that goes:

    <?php
    /**
    * The template for displaying all single unit
    *
    */
    
    global $coursepress, $wp, $wp_query;
    
    $course_id = do_shortcode('[get_parent_course_id]');
    
    add_thickbox();
    
    $paged = ! empty( $wp->query_vars['paged'] ) ? absint($wp->query_vars['paged']) : 1;
    //redirect to the parent course page if not enrolled or not preview unit/page
    while ( have_posts() ) : the_post();
        $coursepress->check_access($course_id, get_the_ID());
    endwhile;
    
    get_header();
    $post = $unit->details;
    // var_dump($post);
    ?>
    
    <div class="row row-pad-10 single-unit side-member">
        <div class="col-md-4">
        <?php get_sidebar('member'); ?>
        </div>
        <div class="col-md-8">
            <div id="post-<?php the_id();?>" class="post">
            <?php while ( have_posts() ) : the_post();?>
                <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <header class="entry-header">
                        <h3 class="entry-title course-title"><?php echo do_shortcode('[course_title course_id="' . $course_id . '"]'); ?></h3>
                        <?php
                        //echo do_shortcode('[course_unit_details unit_id="' . get_the_ID() . '" field="parent_course"]');
                        ?>
                    </header><!-- .entry-header -->
                    <div class="instructors-content"></div>
                    <?php
                    echo do_shortcode('[course_unit_archive_submenu course_id="' . $course_id . '"]');
                    ?>
    
                    <div class="clearfix"></div>
    
                    <?php echo do_shortcode( '[course_unit_page_title unit_id="' . $unit->details->ID . '" title_tag="h3" show_unit_title="yes"]' ); ?>
    
                    <?php
                    Unit_Module::get_modules_front($unit->details->ID);
                    ?>
                </article>
                <div class="comments-wrapper">
    <?php comment_form(); ?>
    <?php
        if ( comments_open() || get_comments_number() ) {
            ?>
            <ol class="comment-list">
                <?php
    
                    $comments = get_comments(array('post_id'=>$unit->id));
    
                    wp_list_comments(array(
                        'per_page' => 10, //Allow comment pagination
                        'reverse_top_level' => false //Show the oldest comments at the top of the list
                    ), $comments);
                ?>
            </ol>
    
            <?php
        }
    ?>
                </div>
            <?php endwhile;?>
            </div>
        </div>
    </div>
    
    <?php get_footer(); ?>

    This should help with comments being displayed in your frontend. However, I wasn't able to replicate the issue with comment links not working in the dashboard, it does work fine in my system. Just to be sure, whether this isn't caused by any conflicts, could you please run a quick plugin/theme conflict test as illustrated in getting support manual (flowchart), and rule out whether any plugin is causing this issue.
    http://premium.wpmudev.org/manuals/using-wpmu-dev/getting-support/

    I hope this helps. Please let us know how that goes, have a nice day. :slight_smile:

    Kind Regards,
    Nithin

  • DJExp

    Hi there, thanks for your help,

    For the Wordpress comment problem, here's what my outsourcer is telling me about your suggestion :

    You said :

    on artikel with default comments wordpress you can reply without redirect link (not load page).

    He answered :

    but in this unit page's comments everytime click on "Reply"(Répondre) the link will redirect (load page)

    Any idea of what is causing the problem ?

  • DJExp

    As for the admin link for edit/validate/etc the comments in Wordpress admin :

    I'm currently working on creating a test version of the website so I can do that plugin compatibility test, but in the mean time here are some clarifications that hopefully can help you replicate the issue without that.

    The links are indeed working for the regular comments, but they are NOT working for the comments coming from CoursePress Units. So it makes me think that it's definitely a problem related to CoursePress. See the picture below and have a look at my comment admin area to see what I mean (I reopened support access) :

  • Rupok

    Hi DJExp,

    Thanks for providing details. Can you please let us know what happens in your test site? Does CoursePress comments behave in the same way in your test site too? Please let us know.

    I don't see Nithin online at this moment, but I'm pinging him to check with our developer regarding this. Either me or Nithin will post here as soon as we get an update from our developer.

    Have a nice day. Cheers!
    Rupok

  • Panos

    Hi DJExp ,

    I assume that the front end part of comments should be working for you. If not please let me know what issues you have there. Please note that comments on front end is not supported for units and exceeds the purpose of the support forum. In such cases it is better to hire a developer from the Jobs & Pros section or post is as a desired feature in the Features & Feedback forum.

    However we are happy to provide some guidance on this :slight_smile:

    Lets recap.

    We assume that you are using the CoursePress theme.
    In order to display comments list and comment form on front end
    In the single-unit.php file you need to add the following snipped at the position you want to show them:

    <?php comment_form(); ?>
    <?php
        if ( comments_open() || get_comments_number() ) {
            ?>
            <ol class="comment-list">
                <?php
    
                    $comments = get_comments(array('post_id'=>$unit->id));
    
                    wp_list_comments(array(
                        'per_page' => 10, //Allow comment pagination
                        'reverse_top_level' => false //Show the oldest comments at the top of the list
                    ), $comments);
                ?>
            </ol>
    
            <?php
        }
    ?>

    You also need the following snippet on your functions.php in order to force enable comments for units:

    add_filter( 'comments_open', 'wpmudev_unit_comments_open', 10, 2 );
    
    function wpmudev_unit_comments_open( $open, $post_id ) {
    
    	$post = get_post( $post_id );
    
    	if ( 'unit' == $post->post_type )
    		$open = true;
    
    	return $open;
    }
    
    add_post_type_support( 'unit', array( 'comments' ) );

    I believe you have followed above steps for front end :slight_smile:

    I can replicate your issue where you can't edit comments in admin. This is related to capabilities, so you can allow administrators to edit them by adding the following snippet in your functions.php file:

    add_filter( 'map_meta_cap', 'wpmudev_add_edit_comment_cap', 10, 4 );
    
    function wpmudev_add_edit_comment_cap( $caps, $cap, $user_id, $args ){
    
    	$user = get_userdata( $user_id );
    
    	//if( $user_id == 1 ){
    	if( isset( $user->roles ) && in_array("administrator", $user->roles ) ){
    
    		if ( $cap == 'edit_comment' )
    	 		$caps = array( 'edit_posts' );
    	}
    
       return $caps;
    }

    Hope this helps!

    Kind regards,
    Panos