CoursePress and Protected Content

Hi,

I am using CoursePress Pro and Protected Content on my website.

I would like to restrict certain courses to certain membership levels. How is the best way to do this?

Many thanks,

Kirsty

    Predrag Dubajic

    Hey Kirsty,

    Hope you're well today.

    You can hide your courses using additional options that come with Protected Content plugin.
    For example you can use the "Custom Post Type Protection - Post by Post", to add this option go to Protected Content > Add-ons in your admin section and activate the "Custom Post Type Protection - Post by Post" option.

    Now you can go to Protected Content > Protected Content panel and in Custom Post Types select the courses you want to protect.

    Let me know if you any more help with this.

    Best regards,
    Predrag

    Kirsty

    Hi Predrag,

    This solution only appears to allow me to protect units and modules - not entire courses. I don't want members to be offered a course and find they cannot access the individual units or modules because they don't have the right permissions.

    Ideally, I would like to restrict access based on course categories, but again, they don't appear in the options for things I can set permissions for within protected Content.

    Is there something else I'm missing?

    Thanks,

    Kirsty

    Predrag Dubajic

    Hey Kirsty,

    That's strange I'm able to see entire courses on my end.
    Can you try scrolling to end of list to see if courses are visible there?

    If you still can't find it would you mind allowing support access so I can have a closer look at this. If this is ok, just grant me temporary admin access to your site by clicking "Grant Access" button in the WPMU DEV Dashboard Settings from the following path and reply on this thread after granting it?

    Admin -> WPMU DEV -> Support -> Support Access Tab

    If you have not installed WPMU DEV Dashboard plugin yet, kindly do that here : https://premium.wpmudev.org/project/wpmu-dev-dashboard/ and then allow access as per the above process.

    Best regards,
    Predrag

    Kirsty

    Hi Predrag,

    I have checked, and as if by magic, the courses are now included on the list of custom post types I can protect. I'm sure they weren't there before, but I'm not going to knock it!

    However, now I have restricted access to my two courses according to user membership, I have another problem. When I test, all of the protected courses are showing up as available when users are logged into their learner dashboard (where it says "You are not enrolled in any courses: Here are a few to help you get started). Only the relevant courses should be showing in this list.

    When a user without permission clicks on a course they are not permitted to view, it returns this message:

    Warning: parse_url(/dev2/protected-content/?redirect_to=http://www.tconsult-ltd.com/dev2/courses/student-elearning-course/) [function.parse-url]: Unable to parse URL in /home/tconsul/public_html/dev2/wp-content/plugins/coursepress/coursepress.php on line 4695

    I have allowed support access to the site, so I am more than happy for you to take a look.

    Many thanks,

    Kirsty

    Kirsty

    Hi Predrag,

    Thanks for checking.

    I have followed the flowchart, and there are no plugin clashes (I deactivated everything except for CoursePress, Protected Content and WPMU Dev Dashboard).

    There was also no problem with the theme when I switched to the Wordpress default theme.

    I'm not sure if that helps - except to rule out the things that are easier to fix!

    I've tried in another browser too, just in case it is caching, but it would seem not.

    Many thanks,

    Kirsty

    Kirsty

    Predrag/Marko,

    As a temporary solution, is there a way to return a list of 'my courses' (as in those I manage/am enrolled on) without showing the list of suggested courses for those who are not yet enrolled? There don't seem to be any attributes for the [courses_student_dashboard] shortcode that I can see.

    This would allow me to create a list of available courses for each user manually, based on what they should be able to see.

    I appreciate this would not be an ideal solution, as the link to view the next course will still exist on the course overview page, but it would allow me to put something in front of my client that matches the rules we have agreed for course access whilst you're investigating.

    Many thanks,

    Kirsty

    Kirsty

    Hi Predrag,

    Sorry for the delayed response - I was away over Christmas.

    I have updated the Protected Content plugin to the latest version, and still experience the same problem. I am receiving the following error when viewing pages that are not permitted:

    Warning: parse_url(/dev2/protected-content-2/?redirect_to=http://www.tconsult-ltd.com/dev2/courses/student-elearning-course/) [function.parse-url]: Unable to parse URL in /home/tconsul/public_html/dev2/wp-content/plugins/coursepress/coursepress.php on line 4766

    Not sure if this might be relevant.

    More worryingly, I am now finding that the 'test membership' modes are not working (I can select a membership when in test mode, but it is not reloading the page to show that member's view. Refreshing manually just puts the membership type back to the default).

    I am demoing the site to my client this Friday, so if you're able to help on these issues, that would be appreciated!

    Many thanks,

    Kirsty

    Predrag Dubajic

    Hey Kirsty,

    I'm still unable to replicate this issue on my end so I'm tagging an available developer from second level support line in this thread for his valuable opinion on this issue.

    Can you send us your FTP login details so we can investigate this further?
    You can send us your details using our contact form and this template:

    Subject: "Attn: Predrag Dubajic"
    -WordPress admin username
    -WordPress admin password
    -login url
    -FTP credentials (host/username/password)
    -link back to this thread for reference
    -any other relevant urls

    Select "I have a different question" for your topic - this and the subject line ensure that it gets assigned to me.

    Best regards,
    Predrag

    Kirsty

    Hi Predrag,

    Many thanks for this. I have just sent the email.

    I have also just updated both plugins, as there were new releases today. The issue I described above where the "Test Membership" feature of Protected Content has been solved by this update, so that's one thing at least!

    However, now when attempt to access a page that is not available to my membership level, I get the following (extended) warning:

    Warning: parse_url(/dev2/protected-content-2/?redirect_to=http://www.tconsult-ltd.com/dev2/courses/student-elearning-course/) [function.parse-url]: Unable to parse URL in /home/tconsul/public_html/dev2/wp-content/plugins/coursepress/coursepress.php on line 4895
    
    Warning: parse_url(/dev2/protected-content-2/?redirect_to=http://www.tconsult-ltd.com/dev2/courses/student-elearning-course/) [function.parse-url]: Unable to parse URL in /home/tconsul/public_html/dev2/wp-content/plugins/coursepress/coursepress.php on line 2389

    This appears above the page - which loads the protected content message as expected.

    Many thanks for your help!

    Kirsty

    Kirsty

    Hi Hoang,

    Many thanks for your help.

    I have installed and activated the plugin, but I am still experiencing the same problem - i.e., the [course-list] is displaying all courses to all membership levels.

    See http://www.tconsult-ltd.com/dev2/

    Unless you are logged in as a Student or a Member, you should only see the "Public Course"

    On the individual course pages (such as http://www.tconsult-ltd.com/dev2/courses/public-course/) the link to the previous or next course is still showing, even if that course is not available to the visitor's membership level.

    This isn't ideal, but it is compounded by the problem I describe above, whereby the visitor sees a load of warning code when they come to a page they don't have permission to view. It would be great to fix this as well, or at least prevent people from getting to pages they don't have permission to see.

    I hope that makes sense?

    Thanks again for your help so far.

    All the best,

    Kirsty

    Hoang Ngo

    @ Kirsty,

    I saw your issue, to fix it, we need to modify the CP code (just add 1 line of code). And I also have some updates to the plugin I posted above, here is the new code.

    <?php
    /*
    Plugin Name: Protect CP dashboard for PC
    Author: Hoang Ngo
    Version: 1.0
    */
    
    add_filter('shortcode_atts_course_featured', 'hide_course_for_pc', 10, 3);
    add_filter('cp_course_list_sc_course', 'course_list_for_pc', 10, 3);
    
    function hide_course_for_pc($out, $pairs, $atts)
    {
        if ($atts['course_id'] != '') {
            $course_id = $atts['course_id'];
            $member = MS_Model_Member::get_current_member();
            foreach ($member->ms_relationships as $subscription) {
                $membership = $subscription->get_membership();
                if (!$membership->has_access_to_post($course_id)) {
                    $out['course_id'] = '-1';
                }
            }
        }
        return $out;
    }
    
    function course_list_for_pc($courses)
    {
        $member = MS_Model_Member::get_current_member();
        foreach ($courses as $key => $course) {
            foreach ($member->ms_relationships as $subscription) {
                $membership = $subscription->get_membership();
                if (!$membership->has_access_to_post($course->ID)) {
                    unset($courses[$key]);
                }
            }
        }
        return $courses;
    }

    Also about the CP code modification, in the line 1983 of the file /coursepress/includes/classes/class.shortcodes.php, I changed this code
    $content .= 0 < count( $courses ) && !empty( $list_wrapper_before ) ? '<' . $list_wrapper_before . ' class=' . $list_wrapper_before_class . '>' : '';
    To

    $content .= 0 < count( $courses ) && !empty( $list_wrapper_before ) ? '<' . $list_wrapper_before . ' class=' . $list_wrapper_before_class . '>' : '';
    			$courses=apply_filters('cp_course_list_sc_course',$courses);

    For now, the shortcode course-list should displaying right

    About the warning error, I will check with the developer, however, if your site is live, please turn of the WP_DEBUG, as showing errors can lead to potential security risks.

    Best regards,
    Hoang