public function single_lesson_handler()
 {
     global $post;
     // Preview Lessons shouldn't ignore this rule.
     if (WooThemes_Sensei_Utils::is_preview_lesson($post->ID)) {
         return;
     }
     $course_id = get_post_meta($post->ID, '_lesson_course', true);
     // User already started this course, so ideally, we shouldn't restrict access.
     if (WooThemes_Sensei_Utils::user_started_course($post->ID, wp_get_current_user()->ID)) {
         return;
     }
     // This happens if the lesson isn't locked itself.
     if (memberful_can_user_access_post(wp_get_current_user()->ID, $post->ID)) {
         if (!memberful_can_user_access_post(wp_get_current_user()->ID, $course_id)) {
             // The user doesn't have access to this post, so he shouldn't have actions on it.
             remove_all_actions('sensei_lesson_single_meta');
             // Now the funky filtering part.
             remove_action('the_content', 'memberful_wp_protect_content');
             add_action('the_content', array($this, 'single_lesson_special_content_filter'), -10);
         }
     } else {
         // The user doesn't have access to this post, so he shouldn't have actions on it.
         remove_all_actions('sensei_lesson_single_meta');
     }
 }
function memberful_wp_protect_content($content)
{
    global $post;
    if (current_user_can('publish_posts')) {
        return $content;
    }
    if (!memberful_can_user_access_post(wp_get_current_user()->ID, $post->ID)) {
        $memberful_marketing_content = memberful_marketing_content($post->ID);
        return apply_filters('memberful_wp_protect_content', $memberful_marketing_content);
    }
    return $content;
}
/**
 * This function will Hide comments on protected posts - #124
 */
function memberful_comments_protection_template_redirect()
{
    // The user most has admin - publisher rights, so we'll not restrict comments access.
    if (current_user_can('publish_posts')) {
        return;
    }
    // This isn't a single post page, so we don't do anything.
    if (!is_singular()) {
        return;
    }
    global $post;
    // User has access to this post, we won't do anything.
    if (memberful_can_user_access_post(wp_get_current_user()->ID, $post->ID)) {
        return;
    }
    // Replace the comments template with the one used by us.
    add_filter('comments_template', 'memberful_comments_protection_comments_template', 20);
    wp_deregister_script('comment-reply');
    remove_action('wp_head', 'feed_links_extra', 3);
}