PluginProbe
Tutor LMS – eLearning and online course solution / 2.0.1
Tutor LMS – eLearning and online course solution v2.0.1
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
tutor / classes / Private_Course_Access.php

Private_Course_Access.php in Tutor LMS – eLearning and online course solution 2.0.1, at classes/Private_Course_Access.php

40 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace TUTOR;
3
4 if ( ! defined( 'ABSPATH' ) )
5 exit;
6
7
8 class Private_Course_Access {
9
10 private $allow_empty=false;
11
12 public function __construct() {
13 add_action('pre_get_posts', array($this, 'enable_private_access'));
14 }
15
16 public function enable_private_access($query=null){
17
18 if(!is_admin() && is_user_logged_in() ){
19
20 global $wpdb;
21 $p_name = isset($query->query['name']) ? $query->query['name'] : '';
22 $p_name = esc_sql($p_name);
23
24 if($this->allow_empty && empty($p_name)){
25 $query->set('post_status', array('private', 'publish'));
26 return;
27 }
28
29 // Get using raw query to speed up
30 $private_query = "SELECT ID, post_parent FROM {$wpdb->posts} WHERE post_type='courses' AND post_name='{$p_name}' AND post_status='private'";
31 $result = $wpdb->get_results($private_query);
32 $private_course_id = (is_array($result) && isset($result[0])) ? $result[0]->ID : 0;
33
34 if($private_course_id>0 && tutor_utils()->is_enrolled($private_course_id)){
35 $this->allow_empty = true;
36 $query->set('post_status', array('private', 'publish'));
37 }
38 }
39 }
40 }