Completed
Pull Request — master (#1233)
by Dan
07:34
created
includes/shortcodes/class-sensei-shortcode-lesson-page.php 3 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -14,88 +14,88 @@
 block discarded – undo
14 14
  */
15 15
 class Sensei_Shortcode_Lesson_Page implements Sensei_Shortcode_Interface {
16 16
 
17
-    /**
18
-     * @var array $lesson_page_query {
19
-     *     @type WP_Post
20
-     * }
21
-     * The lessons query
22
-     */
23
-    protected $lesson_page_query;
17
+	/**
18
+	 * @var array $lesson_page_query {
19
+	 *     @type WP_Post
20
+	 * }
21
+	 * The lessons query
22
+	 */
23
+	protected $lesson_page_query;
24 24
 
25
-    /**
26
-     * Setup the shortcode object
27
-     *
28
-     * @since 1.9.0
29
-     * @param array $attributes
30
-     * @param string $content
31
-     * @param string $shortcode the shortcode that was called for this instance
32
-     */
33
-    public function __construct( $attributes, $content, $shortcode ){
25
+	/**
26
+	 * Setup the shortcode object
27
+	 *
28
+	 * @since 1.9.0
29
+	 * @param array $attributes
30
+	 * @param string $content
31
+	 * @param string $shortcode the shortcode that was called for this instance
32
+	 */
33
+	public function __construct( $attributes, $content, $shortcode ){
34 34
 
35
-        $this->id = isset( $attributes['id'] ) ? $attributes['id'] : '';
36
-        $this->setup_lesson_query();
35
+		$this->id = isset( $attributes['id'] ) ? $attributes['id'] : '';
36
+		$this->setup_lesson_query();
37 37
 
38
-    }
38
+	}
39 39
 
40
-    /**
41
-     * create the lessons query .
42
-     *
43
-     * @return mixed
44
-     */
45
-    public function setup_lesson_query(){
40
+	/**
41
+	 * create the lessons query .
42
+	 *
43
+	 * @return mixed
44
+	 */
45
+	public function setup_lesson_query(){
46 46
 
47
-        if( empty( $this->id ) ){
48
-            return;
49
-        }
47
+		if( empty( $this->id ) ){
48
+			return;
49
+		}
50 50
 
51
-        $args = array(
52
-            'post_type' => 'lesson',
53
-            'posts_per_page' => 1,
54
-            'post_status' => 'publish',
55
-            'post__in' => array( $this->id ),
56
-        );
51
+		$args = array(
52
+			'post_type' => 'lesson',
53
+			'posts_per_page' => 1,
54
+			'post_status' => 'publish',
55
+			'post__in' => array( $this->id ),
56
+		);
57 57
 
58
-        $this->lesson_page_query  = new WP_Query( $args );
58
+		$this->lesson_page_query  = new WP_Query( $args );
59 59
 
60
-    }
60
+	}
61 61
 
62
-    /**
63
-     * Rendering the shortcode this class is responsible for.
64
-     *
65
-     * @return string $content
66
-     */
67
-    public function render(){
62
+	/**
63
+	 * Rendering the shortcode this class is responsible for.
64
+	 *
65
+	 * @return string $content
66
+	 */
67
+	public function render(){
68 68
 
69
-        if( empty(  $this->id  ) ){
69
+		if( empty(  $this->id  ) ){
70 70
 
71
-            return __( 'Please supply a lesson ID for this shortcode.', 'woothemes-sensei' );
71
+			return __( 'Please supply a lesson ID for this shortcode.', 'woothemes-sensei' );
72 72
 
73
-        }
73
+		}
74 74
 
75
-        //set the wp_query to the current lessons query
76
-        global $wp_query;
77
-        $wp_query = $this->lesson_page_query;
75
+		//set the wp_query to the current lessons query
76
+		global $wp_query;
77
+		$wp_query = $this->lesson_page_query;
78 78
 
79
-        if( have_posts() ){
79
+		if( have_posts() ){
80 80
 
81
-            the_post();
81
+			the_post();
82 82
 
83
-        }else{
83
+		}else{
84 84
 
85
-            return __('No posts found.', 'woothemes-sensei');
85
+			return __('No posts found.', 'woothemes-sensei');
86 86
 
87
-        }
87
+		}
88 88
 
89
-        ob_start();
90
-        Sensei_Templates::get_template('content-single-lesson.php');
91
-        $shortcode_output = ob_get_clean();
89
+		ob_start();
90
+		Sensei_Templates::get_template('content-single-lesson.php');
91
+		$shortcode_output = ob_get_clean();
92 92
 
93
-        // set back the global query
94
-        wp_reset_query();
93
+		// set back the global query
94
+		wp_reset_query();
95 95
 
96
-        return $shortcode_output;
96
+		return $shortcode_output;
97 97
 
98
-    }// end render
98
+	}// end render
99 99
 
100 100
 }// end class
101 101
 
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 /**
4 4
  *
5 5
  * Renders the [sensei_lesson_page] shortcode. Display a single lesson based on the ID parameter given.
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
      * @param string $content
31 31
      * @param string $shortcode the shortcode that was called for this instance
32 32
      */
33
-    public function __construct( $attributes, $content, $shortcode ){
33
+    public function __construct($attributes, $content, $shortcode) {
34 34
 
35
-        $this->id = isset( $attributes['id'] ) ? $attributes['id'] : '';
35
+        $this->id = isset($attributes['id']) ? $attributes['id'] : '';
36 36
         $this->setup_lesson_query();
37 37
 
38 38
     }
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return mixed
44 44
      */
45
-    public function setup_lesson_query(){
45
+    public function setup_lesson_query() {
46 46
 
47
-        if( empty( $this->id ) ){
47
+        if (empty($this->id)) {
48 48
             return;
49 49
         }
50 50
 
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
             'post_type' => 'lesson',
53 53
             'posts_per_page' => 1,
54 54
             'post_status' => 'publish',
55
-            'post__in' => array( $this->id ),
55
+            'post__in' => array($this->id),
56 56
         );
57 57
 
58
-        $this->lesson_page_query  = new WP_Query( $args );
58
+        $this->lesson_page_query = new WP_Query($args);
59 59
 
60 60
     }
61 61
 
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
      *
65 65
      * @return string $content
66 66
      */
67
-    public function render(){
67
+    public function render() {
68 68
 
69
-        if( empty(  $this->id  ) ){
69
+        if (empty($this->id)) {
70 70
 
71
-            return __( 'Please supply a lesson ID for this shortcode.', 'woothemes-sensei' );
71
+            return __('Please supply a lesson ID for this shortcode.', 'woothemes-sensei');
72 72
 
73 73
         }
74 74
 
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
         global $wp_query;
77 77
         $wp_query = $this->lesson_page_query;
78 78
 
79
-        if( have_posts() ){
79
+        if (have_posts()) {
80 80
 
81 81
             the_post();
82 82
 
83
-        }else{
83
+        } else {
84 84
 
85 85
             return __('No posts found.', 'woothemes-sensei');
86 86
 
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Post Types Class
@@ -146,7 +149,7 @@  discard block
 block discarded – undo
146 149
 
147 150
              return get_page_uri( $settings_course_page->ID );
148 151
 
149
-        }else{
152
+        } else{
150 153
 
151 154
             return 'courses';
152 155
 
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-loader.php 3 patches
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // security check
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// security check
3 6
 /**
4 7
  * Sensei Shortcode Loader Class
5 8
  *
Please login to merge, or discard this patch.
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -15,172 +15,172 @@
 block discarded – undo
15 15
  */
16 16
 class Sensei_Shortcode_Loader{
17 17
 
18
-    /**
19
-     * @var array {
20
-     *  type string $shortcode
21
-     *  type Sensei_Shortcode
22
-     * } all the shortcodes and which class to instantiate when they are called from
23
-     * WordPress's do_shortcode() function.
24
-     *
25
-     */
26
-    protected $shortcode_classes;
27
-
28
-    /**
29
-     * Run all the functions that needs to be hooked into WordPress
30
-     *
31
-     * @since 1.9.0
32
-     */
33
-    public function __construct(){
34
-
35
-        // create a list of shortcodes and the class that handles them
36
-        $this->setup_shortcode_class_map();
37
-
38
-        // setup all the shortcodes and load the listener into WP
39
-        $this->initialize_shortcodes();
40
-
41
-        // add sensei body class for shortcodes
42
-        add_filter( 'body_class', array( $this, 'possibly_add_body_class' ));
43
-
44
-        // array( $this, 'add_body_class')
45
-
46
-    }
47
-
48
-    /**
49
-     * Array of shortcode classes that should be instantiated when WordPress loads
50
-     * a Sensei specific shortcode.
51
-     * This list contains:
52
-     * $shortcode => $class_name
53
-     *
54
-     * $shortcode is the actual shortcode the user will add to the editor
55
-     * $class_name is the name of the class that will be instantiated to handle
56
-     * the rendering of the shortcode.
57
-     *
58
-     * NOTE: When adding a new shortcode here be sure to load your shortcodes class
59
-     * in class-sensei-autoloader class_file_map function
60
-     */
61
-    public function setup_shortcode_class_map(){
62
-
63
-        $this->shortcode_classes = array(
64
-            'sensei_featured_courses'    => 'Sensei_Shortcode_Featured_Courses',
65
-            'sensei_user_courses'        => 'Sensei_Shortcode_User_Courses',
66
-            'sensei_courses'             => 'Sensei_Shortcode_Courses',
67
-            'sensei_teachers'            => 'Sensei_Shortcode_Teachers',
68
-            'sensei_user_messages'       => 'Sensei_Shortcode_User_Messages',
69
-            'sensei_course_page'         => 'Sensei_Shortcode_Course_Page',
70
-            'sensei_lesson_page'         => 'Sensei_Shortcode_Lesson_Page',
71
-            'sensei_course_categories'   => 'Sensei_Shortcode_Course_Categories',
72
-            'sensei_unpurchased_courses' => 'Sensei_Shortcode_Unpurchased_Courses',
73
-        );
74
-
75
-        // legacy shortcode handling:
76
-        Sensei_Legacy_Shortcodes::init();
77
-
78
-    }
79
-
80
-    /**
81
-     * Add all shortcodes here
82
-     *
83
-     * This function adds shortcodes to WP that links to other functionality.
84
-     * @since 1.9.0
85
-     */
86
-    public function initialize_shortcodes(){
87
-
88
-        // shortcodes should only respond to front end calls
89
-        if( is_admin() || defined( 'DOING_AJAX' ) ){
90
-            return;
91
-        }
92
-
93
-        /**
94
-         * Tell WP to run this classes load_shortcode function for all the
95
-         * shortcodes registered here in.
96
-         *
97
-         * With this method we only load shortcode classes when we need them.
98
-         */
99
-        foreach( $this->shortcode_classes as $shortcode => $class ){
100
-
101
-            // all Sensei shortcodes are rendered by this loader class
102
-            // it acts as an interface between wp and the shortcodes registered
103
-            // above
104
-            add_shortcode( $shortcode, array( $this,'render_shortcode' ) );
105
-
106
-        }
107
-
108
-    }
109
-
110
-    /**
111
-     * Respond to WordPress do_shortcode calls
112
-     * for shortcodes registered in the initialize_shortcodes function.
113
-     *
114
-     * @since 1.9.0
115
-     *
116
-     * @param $attributes
117
-     * @param $content
118
-     * @param $code the shortcode that is being requested
119
-     *
120
-     * @return string
121
-     */
122
-    public function render_shortcode( $attributes='', $content='', $code ){
123
-
124
-        // only respond if the shortcode that we've added shortcode
125
-        // classes for.
126
-        if( ! isset( $this->shortcode_classes[ $code ] ) ){
127
-            return '';
128
-        }
129
-
130
-        // create an instances of the current requested shortcode
131
-        $shortcode_handling_class = $this->shortcode_classes[ $code ];
132
-        $shortcode = new $shortcode_handling_class( $attributes, $content, $code );
133
-
134
-        // we expect the sensei class instantiated to implement the Sensei_Shortcode interface
135
-        if( ! in_array( 'Sensei_Shortcode_Interface', class_implements( $shortcode) ) ){
136
-
137
-            $message = "The rendering class for your shortcode: $code, must implement the Sensei_Shortcode interface";
138
-            _doing_it_wrong('Sensei_Shortcode_Loader::render_shortcode',$message, '1.9.0' );
139
-
140
-        }
141
-
142
-        return $shortcode->render();
143
-
144
-    }
145
-
146
-    /**
147
-     * Add the Sensei body class if
148
-     * the current page has a Sensei shortcode.
149
-     *
150
-     * Note: legacy shortcodes not supported here.
151
-     *
152
-     * @since 1.9.0
153
-     *
154
-     * @param array $classes
155
-     * @return array
156
-     */
157
-    public function possibly_add_body_class ( $classes ) {
158
-
159
-        global $post;
160
-
161
-        $has_sensei_shortcode = false;
162
-
163
-        if ( is_a( $post, 'WP_Post' ) ) {
164
-
165
-            // check all registered Sensei shortcodes (not legacy shortcodes)
166
-            foreach ( $this->shortcode_classes as $shortcode => $class ){
167
-
168
-                if ( has_shortcode( $post->post_content, $shortcode ) ) {
18
+	/**
19
+	 * @var array {
20
+	 *  type string $shortcode
21
+	 *  type Sensei_Shortcode
22
+	 * } all the shortcodes and which class to instantiate when they are called from
23
+	 * WordPress's do_shortcode() function.
24
+	 *
25
+	 */
26
+	protected $shortcode_classes;
27
+
28
+	/**
29
+	 * Run all the functions that needs to be hooked into WordPress
30
+	 *
31
+	 * @since 1.9.0
32
+	 */
33
+	public function __construct(){
34
+
35
+		// create a list of shortcodes and the class that handles them
36
+		$this->setup_shortcode_class_map();
37
+
38
+		// setup all the shortcodes and load the listener into WP
39
+		$this->initialize_shortcodes();
40
+
41
+		// add sensei body class for shortcodes
42
+		add_filter( 'body_class', array( $this, 'possibly_add_body_class' ));
43
+
44
+		// array( $this, 'add_body_class')
45
+
46
+	}
47
+
48
+	/**
49
+	 * Array of shortcode classes that should be instantiated when WordPress loads
50
+	 * a Sensei specific shortcode.
51
+	 * This list contains:
52
+	 * $shortcode => $class_name
53
+	 *
54
+	 * $shortcode is the actual shortcode the user will add to the editor
55
+	 * $class_name is the name of the class that will be instantiated to handle
56
+	 * the rendering of the shortcode.
57
+	 *
58
+	 * NOTE: When adding a new shortcode here be sure to load your shortcodes class
59
+	 * in class-sensei-autoloader class_file_map function
60
+	 */
61
+	public function setup_shortcode_class_map(){
62
+
63
+		$this->shortcode_classes = array(
64
+			'sensei_featured_courses'    => 'Sensei_Shortcode_Featured_Courses',
65
+			'sensei_user_courses'        => 'Sensei_Shortcode_User_Courses',
66
+			'sensei_courses'             => 'Sensei_Shortcode_Courses',
67
+			'sensei_teachers'            => 'Sensei_Shortcode_Teachers',
68
+			'sensei_user_messages'       => 'Sensei_Shortcode_User_Messages',
69
+			'sensei_course_page'         => 'Sensei_Shortcode_Course_Page',
70
+			'sensei_lesson_page'         => 'Sensei_Shortcode_Lesson_Page',
71
+			'sensei_course_categories'   => 'Sensei_Shortcode_Course_Categories',
72
+			'sensei_unpurchased_courses' => 'Sensei_Shortcode_Unpurchased_Courses',
73
+		);
74
+
75
+		// legacy shortcode handling:
76
+		Sensei_Legacy_Shortcodes::init();
77
+
78
+	}
79
+
80
+	/**
81
+	 * Add all shortcodes here
82
+	 *
83
+	 * This function adds shortcodes to WP that links to other functionality.
84
+	 * @since 1.9.0
85
+	 */
86
+	public function initialize_shortcodes(){
87
+
88
+		// shortcodes should only respond to front end calls
89
+		if( is_admin() || defined( 'DOING_AJAX' ) ){
90
+			return;
91
+		}
92
+
93
+		/**
94
+		 * Tell WP to run this classes load_shortcode function for all the
95
+		 * shortcodes registered here in.
96
+		 *
97
+		 * With this method we only load shortcode classes when we need them.
98
+		 */
99
+		foreach( $this->shortcode_classes as $shortcode => $class ){
100
+
101
+			// all Sensei shortcodes are rendered by this loader class
102
+			// it acts as an interface between wp and the shortcodes registered
103
+			// above
104
+			add_shortcode( $shortcode, array( $this,'render_shortcode' ) );
105
+
106
+		}
107
+
108
+	}
109
+
110
+	/**
111
+	 * Respond to WordPress do_shortcode calls
112
+	 * for shortcodes registered in the initialize_shortcodes function.
113
+	 *
114
+	 * @since 1.9.0
115
+	 *
116
+	 * @param $attributes
117
+	 * @param $content
118
+	 * @param $code the shortcode that is being requested
119
+	 *
120
+	 * @return string
121
+	 */
122
+	public function render_shortcode( $attributes='', $content='', $code ){
123
+
124
+		// only respond if the shortcode that we've added shortcode
125
+		// classes for.
126
+		if( ! isset( $this->shortcode_classes[ $code ] ) ){
127
+			return '';
128
+		}
129
+
130
+		// create an instances of the current requested shortcode
131
+		$shortcode_handling_class = $this->shortcode_classes[ $code ];
132
+		$shortcode = new $shortcode_handling_class( $attributes, $content, $code );
133
+
134
+		// we expect the sensei class instantiated to implement the Sensei_Shortcode interface
135
+		if( ! in_array( 'Sensei_Shortcode_Interface', class_implements( $shortcode) ) ){
136
+
137
+			$message = "The rendering class for your shortcode: $code, must implement the Sensei_Shortcode interface";
138
+			_doing_it_wrong('Sensei_Shortcode_Loader::render_shortcode',$message, '1.9.0' );
139
+
140
+		}
141
+
142
+		return $shortcode->render();
143
+
144
+	}
145
+
146
+	/**
147
+	 * Add the Sensei body class if
148
+	 * the current page has a Sensei shortcode.
149
+	 *
150
+	 * Note: legacy shortcodes not supported here.
151
+	 *
152
+	 * @since 1.9.0
153
+	 *
154
+	 * @param array $classes
155
+	 * @return array
156
+	 */
157
+	public function possibly_add_body_class ( $classes ) {
158
+
159
+		global $post;
160
+
161
+		$has_sensei_shortcode = false;
162
+
163
+		if ( is_a( $post, 'WP_Post' ) ) {
164
+
165
+			// check all registered Sensei shortcodes (not legacy shortcodes)
166
+			foreach ( $this->shortcode_classes as $shortcode => $class ){
167
+
168
+				if ( has_shortcode( $post->post_content, $shortcode ) ) {
169 169
 
170
-                    $has_sensei_shortcode = true;
171
-                }
170
+					$has_sensei_shortcode = true;
171
+				}
172 172
 
173
-            }
174
-        }
173
+			}
174
+		}
175 175
 
176
-        if( $has_sensei_shortcode ) {
177
-            $classes[] = 'sensei' ;
178
-        }
176
+		if( $has_sensei_shortcode ) {
177
+			$classes[] = 'sensei' ;
178
+		}
179 179
 
180 180
 
181
-        return $classes;
182
-
183
-    }
181
+		return $classes;
182
+
183
+	}
184 184
 
185 185
 } // end class Sensei_Shortcodes
186 186
 new Sensei_Shortcode_Loader();
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // security check
2
+if ( ! defined('ABSPATH')) exit; // security check
3 3
 /**
4 4
  * Sensei Shortcode Loader Class
5 5
  *
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * @category Shortcodes
14 14
  * @since 1.9.0
15 15
  */
16
-class Sensei_Shortcode_Loader{
16
+class Sensei_Shortcode_Loader {
17 17
 
18 18
     /**
19 19
      * @var array {
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @since 1.9.0
32 32
      */
33
-    public function __construct(){
33
+    public function __construct() {
34 34
 
35 35
         // create a list of shortcodes and the class that handles them
36 36
         $this->setup_shortcode_class_map();
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
         $this->initialize_shortcodes();
40 40
 
41 41
         // add sensei body class for shortcodes
42
-        add_filter( 'body_class', array( $this, 'possibly_add_body_class' ));
42
+        add_filter('body_class', array($this, 'possibly_add_body_class'));
43 43
 
44 44
         // array( $this, 'add_body_class')
45 45
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      * NOTE: When adding a new shortcode here be sure to load your shortcodes class
59 59
      * in class-sensei-autoloader class_file_map function
60 60
      */
61
-    public function setup_shortcode_class_map(){
61
+    public function setup_shortcode_class_map() {
62 62
 
63 63
         $this->shortcode_classes = array(
64 64
             'sensei_featured_courses'    => 'Sensei_Shortcode_Featured_Courses',
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
      * This function adds shortcodes to WP that links to other functionality.
84 84
      * @since 1.9.0
85 85
      */
86
-    public function initialize_shortcodes(){
86
+    public function initialize_shortcodes() {
87 87
 
88 88
         // shortcodes should only respond to front end calls
89
-        if( is_admin() || defined( 'DOING_AJAX' ) ){
89
+        if (is_admin() || defined('DOING_AJAX')) {
90 90
             return;
91 91
         }
92 92
 
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
          *
97 97
          * With this method we only load shortcode classes when we need them.
98 98
          */
99
-        foreach( $this->shortcode_classes as $shortcode => $class ){
99
+        foreach ($this->shortcode_classes as $shortcode => $class) {
100 100
 
101 101
             // all Sensei shortcodes are rendered by this loader class
102 102
             // it acts as an interface between wp and the shortcodes registered
103 103
             // above
104
-            add_shortcode( $shortcode, array( $this,'render_shortcode' ) );
104
+            add_shortcode($shortcode, array($this, 'render_shortcode'));
105 105
 
106 106
         }
107 107
 
@@ -119,23 +119,23 @@  discard block
 block discarded – undo
119 119
      *
120 120
      * @return string
121 121
      */
122
-    public function render_shortcode( $attributes='', $content='', $code ){
122
+    public function render_shortcode($attributes = '', $content = '', $code) {
123 123
 
124 124
         // only respond if the shortcode that we've added shortcode
125 125
         // classes for.
126
-        if( ! isset( $this->shortcode_classes[ $code ] ) ){
126
+        if ( ! isset($this->shortcode_classes[$code])) {
127 127
             return '';
128 128
         }
129 129
 
130 130
         // create an instances of the current requested shortcode
131
-        $shortcode_handling_class = $this->shortcode_classes[ $code ];
132
-        $shortcode = new $shortcode_handling_class( $attributes, $content, $code );
131
+        $shortcode_handling_class = $this->shortcode_classes[$code];
132
+        $shortcode = new $shortcode_handling_class($attributes, $content, $code);
133 133
 
134 134
         // we expect the sensei class instantiated to implement the Sensei_Shortcode interface
135
-        if( ! in_array( 'Sensei_Shortcode_Interface', class_implements( $shortcode) ) ){
135
+        if ( ! in_array('Sensei_Shortcode_Interface', class_implements($shortcode))) {
136 136
 
137 137
             $message = "The rendering class for your shortcode: $code, must implement the Sensei_Shortcode interface";
138
-            _doing_it_wrong('Sensei_Shortcode_Loader::render_shortcode',$message, '1.9.0' );
138
+            _doing_it_wrong('Sensei_Shortcode_Loader::render_shortcode', $message, '1.9.0');
139 139
 
140 140
         }
141 141
 
@@ -154,18 +154,18 @@  discard block
 block discarded – undo
154 154
      * @param array $classes
155 155
      * @return array
156 156
      */
157
-    public function possibly_add_body_class ( $classes ) {
157
+    public function possibly_add_body_class($classes) {
158 158
 
159 159
         global $post;
160 160
 
161 161
         $has_sensei_shortcode = false;
162 162
 
163
-        if ( is_a( $post, 'WP_Post' ) ) {
163
+        if (is_a($post, 'WP_Post')) {
164 164
 
165 165
             // check all registered Sensei shortcodes (not legacy shortcodes)
166
-            foreach ( $this->shortcode_classes as $shortcode => $class ){
166
+            foreach ($this->shortcode_classes as $shortcode => $class) {
167 167
 
168
-                if ( has_shortcode( $post->post_content, $shortcode ) ) {
168
+                if (has_shortcode($post->post_content, $shortcode)) {
169 169
 
170 170
                     $has_sensei_shortcode = true;
171 171
                 }
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
             }
174 174
         }
175 175
 
176
-        if( $has_sensei_shortcode ) {
177
-            $classes[] = 'sensei' ;
176
+        if ($has_sensei_shortcode) {
177
+            $classes[] = 'sensei';
178 178
         }
179 179
 
180 180
 
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-featured-courses.php 3 patches
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -13,115 +13,115 @@
 block discarded – undo
13 13
  */
14 14
 class Sensei_Shortcode_Featured_Courses implements Sensei_Shortcode_Interface {
15 15
 
16
-    /**
17
-     * @var WP_Query to help setup the query needed by the render method.
18
-     */
19
-    protected $query;
20
-
21
-    /**
22
-     * @var string number of items to show on the current page
23
-     * Default: -1.
24
-     */
25
-    protected $number;
26
-
27
-    /**
28
-     * @var string ordery by course field
29
-     * Default: date
30
-     */
31
-    protected $orderby;
32
-
33
-    /**
34
-     * @var string ASC or DESC
35
-     * Default: 'DESC'
36
-     */
37
-    protected  $order;
38
-
39
-    /**
40
-     * @var string teacher id to limit the courses to
41
-     */
42
-    protected $teacher;
43
-
44
-    /**
45
-     * Setup the shortcode object
46
-     *
47
-     * @since 1.9.0
48
-     * @param array $attributes
49
-     * @param string $content
50
-     * @param string $shortcode the shortcode that was called for this instance
51
-     */
52
-    public function __construct( $attributes, $content, $shortcode ){
53
-
54
-        // set up all argument need for constructing the course query
55
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
56
-        $this->teacher = isset( $attributes['teacher'] ) ? $attributes['teacher'] : '';
57
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'date';
58
-
59
-        // set the default for menu_order to be ASC
60
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
61
-
62
-            $this->order =  'ASC';
63
-
64
-        }else{
65
-
66
-            // for everything else use the value passed or the default DESC
67
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
68
-
69
-        }
70
-
71
-        // setup the course query that will be used when rendering
72
-        $this->setup_course_query();
73
-    }
74
-
75
-    /**
76
-     * Sets up the object course query
77
-     * that will be used int he render method.
78
-     *
79
-     * @since 1.9.0
80
-     */
81
-    protected function setup_course_query(){
82
-
83
-        //for non numeric teacher arguments value query by author_name and not author
84
-        $teacher_query_by = is_numeric( $this->teacher )? 'author':'author_name';
85
-
86
-        $query_args = array(
87
-            'post_type'        => 'course',
88
-            'post_status'      => 'publish',
89
-            'orderby'          => $this->orderby,
90
-            'order'            => $this->order,
91
-            'posts_per_page'   => $this->number,
92
-            $teacher_query_by  => $this->teacher,
93
-            'meta_value' 	   => 'featured',
94
-            'meta_key' 		   => '_course_featured',
95
-            'meta_compare' 	   => '=',
96
-            'suppress_filters' => 0,
97
-        );
98
-
99
-        $this->query = new WP_Query( $query_args );
100
-
101
-    }// end setup _course_query
102
-
103
-    /**
104
-     * Rendering the shortcode this class is responsible for.
105
-     */
106
-    public function render(){
107
-
108
-        global $wp_query;
109
-
110
-        // keep a reference to old query
111
-        $current_global_query = $wp_query;
112
-
113
-        // assign the query setup in $this-> setup_course_query
114
-        $wp_query = $this->query;
115
-
116
-        ob_start();
117
-        Sensei_Templates::get_template('loop-course.php');
118
-        $shortcode_output =  ob_get_clean();
119
-
120
-        //restore old query
121
-        $wp_query = $current_global_query;
122
-
123
-        return $shortcode_output;
124
-
125
-    }// end render
16
+	/**
17
+	 * @var WP_Query to help setup the query needed by the render method.
18
+	 */
19
+	protected $query;
20
+
21
+	/**
22
+	 * @var string number of items to show on the current page
23
+	 * Default: -1.
24
+	 */
25
+	protected $number;
26
+
27
+	/**
28
+	 * @var string ordery by course field
29
+	 * Default: date
30
+	 */
31
+	protected $orderby;
32
+
33
+	/**
34
+	 * @var string ASC or DESC
35
+	 * Default: 'DESC'
36
+	 */
37
+	protected  $order;
38
+
39
+	/**
40
+	 * @var string teacher id to limit the courses to
41
+	 */
42
+	protected $teacher;
43
+
44
+	/**
45
+	 * Setup the shortcode object
46
+	 *
47
+	 * @since 1.9.0
48
+	 * @param array $attributes
49
+	 * @param string $content
50
+	 * @param string $shortcode the shortcode that was called for this instance
51
+	 */
52
+	public function __construct( $attributes, $content, $shortcode ){
53
+
54
+		// set up all argument need for constructing the course query
55
+		$this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
56
+		$this->teacher = isset( $attributes['teacher'] ) ? $attributes['teacher'] : '';
57
+		$this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'date';
58
+
59
+		// set the default for menu_order to be ASC
60
+		if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
61
+
62
+			$this->order =  'ASC';
63
+
64
+		}else{
65
+
66
+			// for everything else use the value passed or the default DESC
67
+			$this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
68
+
69
+		}
70
+
71
+		// setup the course query that will be used when rendering
72
+		$this->setup_course_query();
73
+	}
74
+
75
+	/**
76
+	 * Sets up the object course query
77
+	 * that will be used int he render method.
78
+	 *
79
+	 * @since 1.9.0
80
+	 */
81
+	protected function setup_course_query(){
82
+
83
+		//for non numeric teacher arguments value query by author_name and not author
84
+		$teacher_query_by = is_numeric( $this->teacher )? 'author':'author_name';
85
+
86
+		$query_args = array(
87
+			'post_type'        => 'course',
88
+			'post_status'      => 'publish',
89
+			'orderby'          => $this->orderby,
90
+			'order'            => $this->order,
91
+			'posts_per_page'   => $this->number,
92
+			$teacher_query_by  => $this->teacher,
93
+			'meta_value' 	   => 'featured',
94
+			'meta_key' 		   => '_course_featured',
95
+			'meta_compare' 	   => '=',
96
+			'suppress_filters' => 0,
97
+		);
98
+
99
+		$this->query = new WP_Query( $query_args );
100
+
101
+	}// end setup _course_query
102
+
103
+	/**
104
+	 * Rendering the shortcode this class is responsible for.
105
+	 */
106
+	public function render(){
107
+
108
+		global $wp_query;
109
+
110
+		// keep a reference to old query
111
+		$current_global_query = $wp_query;
112
+
113
+		// assign the query setup in $this-> setup_course_query
114
+		$wp_query = $this->query;
115
+
116
+		ob_start();
117
+		Sensei_Templates::get_template('loop-course.php');
118
+		$shortcode_output =  ob_get_clean();
119
+
120
+		//restore old query
121
+		$wp_query = $current_global_query;
122
+
123
+		return $shortcode_output;
124
+
125
+	}// end render
126 126
 
127 127
 }
128 128
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 /**
4 4
  * Sensei Feature Course rendering class
5 5
  *
@@ -49,22 +49,22 @@  discard block
 block discarded – undo
49 49
      * @param string $content
50 50
      * @param string $shortcode the shortcode that was called for this instance
51 51
      */
52
-    public function __construct( $attributes, $content, $shortcode ){
52
+    public function __construct($attributes, $content, $shortcode) {
53 53
 
54 54
         // set up all argument need for constructing the course query
55
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
56
-        $this->teacher = isset( $attributes['teacher'] ) ? $attributes['teacher'] : '';
57
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'date';
55
+        $this->number = isset($attributes['number']) ? $attributes['number'] : '10';
56
+        $this->teacher = isset($attributes['teacher']) ? $attributes['teacher'] : '';
57
+        $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'date';
58 58
 
59 59
         // set the default for menu_order to be ASC
60
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
60
+        if ('menu_order' == $this->orderby && ! isset($attributes['order'])) {
61 61
 
62
-            $this->order =  'ASC';
62
+            $this->order = 'ASC';
63 63
 
64
-        }else{
64
+        } else {
65 65
 
66 66
             // for everything else use the value passed or the default DESC
67
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
67
+            $this->order = isset($attributes['order']) ? $attributes['order'] : 'DESC';
68 68
 
69 69
         }
70 70
 
@@ -78,10 +78,10 @@  discard block
 block discarded – undo
78 78
      *
79 79
      * @since 1.9.0
80 80
      */
81
-    protected function setup_course_query(){
81
+    protected function setup_course_query() {
82 82
 
83 83
         //for non numeric teacher arguments value query by author_name and not author
84
-        $teacher_query_by = is_numeric( $this->teacher )? 'author':'author_name';
84
+        $teacher_query_by = is_numeric($this->teacher) ? 'author' : 'author_name';
85 85
 
86 86
         $query_args = array(
87 87
             'post_type'        => 'course',
@@ -96,14 +96,14 @@  discard block
 block discarded – undo
96 96
             'suppress_filters' => 0,
97 97
         );
98 98
 
99
-        $this->query = new WP_Query( $query_args );
99
+        $this->query = new WP_Query($query_args);
100 100
 
101 101
     }// end setup _course_query
102 102
 
103 103
     /**
104 104
      * Rendering the shortcode this class is responsible for.
105 105
      */
106
-    public function render(){
106
+    public function render() {
107 107
 
108 108
         global $wp_query;
109 109
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 
116 116
         ob_start();
117 117
         Sensei_Templates::get_template('loop-course.php');
118
-        $shortcode_output =  ob_get_clean();
118
+        $shortcode_output = ob_get_clean();
119 119
 
120 120
         //restore old query
121 121
         $wp_query = $current_global_query;
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Post Types Class
@@ -146,7 +149,7 @@  discard block
 block discarded – undo
146 149
 
147 150
              return get_page_uri( $settings_course_page->ID );
148 151
 
149
-        }else{
152
+        } else{
150 153
 
151 154
             return 'courses';
152 155
 
Please login to merge, or discard this patch.
includes/shortcodes/interface-sensei-shortcode.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,19 +12,19 @@
 block discarded – undo
12 12
  */
13 13
 interface Sensei_Shortcode_Interface {
14 14
 
15
-    /**
16
-     * All constructors must implement and accept $attributes and $content as arguments
17
-     *
18
-     * @param array $attributes
19
-     * @param string $content
20
-     * @param string $shortcode
21
-     * @return mixed
22
-     */
23
-    public function __construct($attributes, $content, $shortcode);
15
+	/**
16
+	 * All constructors must implement and accept $attributes and $content as arguments
17
+	 *
18
+	 * @param array $attributes
19
+	 * @param string $content
20
+	 * @param string $shortcode
21
+	 * @return mixed
22
+	 */
23
+	public function __construct($attributes, $content, $shortcode);
24 24
 
25
-    /**
26
-     * @return string generated output
27
-     */
28
-    public function render();
25
+	/**
26
+	 * @return string generated output
27
+	 */
28
+	public function render();
29 29
 
30 30
 }// end interface
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-course-page.php 3 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -14,97 +14,97 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Shortcode_Course_Page implements Sensei_Shortcode_Interface {
16 16
 
17
-    /**
18
-     * @var array $course_page_query{
19
-     *     @type WP_Post
20
-     * }
21
-     * The courses query
22
-     */
23
-    protected $course_page_query;
24
-
25
-    /**
26
-     * Setup the shortcode object
27
-     *
28
-     * @since 1.9.0
29
-     * @param array $attributes
30
-     * @param string $content
31
-     * @param string $shortcode the shortcode that was called for this instance
32
-     */
33
-    public function __construct( $attributes, $content, $shortcode ){
34
-
35
-        $this->id = isset( $attributes['id'] ) ? $attributes['id'] : '';
36
-        $this->setup_course_query();
37
-
38
-    }
39
-
40
-    /**
41
-     * create the courses query .
42
-     *
43
-     * @return mixed
44
-     */
45
-    public function setup_course_query(){
46
-
47
-        if( empty( $this->id ) ){
48
-            return;
49
-        }
50
-
51
-        $args = array(
52
-            'post_type' => 'course',
53
-            'posts_per_page' => 1,
54
-            'post_status' => 'publish',
55
-            'post__in' => array( $this->id ),
56
-        );
57
-
58
-        $this->course_page_query  = new WP_Query( $args );
59
-
60
-    }
61
-
62
-    /**
63
-     * Rendering the shortcode this class is responsible for.
64
-     *
65
-     * @return string $content
66
-     */
67
-    public function render(){
68
-
69
-        if( empty(  $this->id  ) ){
70
-
71
-            return sprintf( __( 'Please supply a course ID for the shortcode: %s', 'woothemes-sensei' ),'[sensei_course_page id=""]') ;
72
-
73
-        }
74
-
75
-        //set the wp_query to the current courses query
76
-        global $wp_query, $post;
77
-
78
-        // backups
79
-        $global_post_ref = $post;
80
-        $global_wp_query_ref = $wp_query;
81
-
82
-        $post = get_post( $this->id );
83
-        $wp_query->post = get_post( $this->id ); //  set this in case some the course hooks resets the query
84
-        $wp_query = $this->course_page_query;
85
-
86
-        ob_start();
87
-        self::the_single_course_content();
88
-        $shortcode_output = ob_get_clean();
89
-
90
-        // set back the global query and post
91
-        // restore global backups
92
-        $wp_query       = $global_wp_query_ref;
93
-        $post           = $global_post_ref;
94
-        $wp_query->post = $global_post_ref;
95
-        wp_reset_query();
96
-
97
-        return $shortcode_output;
98
-
99
-    }// end render
100
-
101
-    /**
102
-     * Print out the single course content markup
103
-     *
104
-     * @since 1.9.0
105
-     */
106
-    public static function the_single_course_content(){
107
-        ?>
17
+	/**
18
+	 * @var array $course_page_query{
19
+	 *     @type WP_Post
20
+	 * }
21
+	 * The courses query
22
+	 */
23
+	protected $course_page_query;
24
+
25
+	/**
26
+	 * Setup the shortcode object
27
+	 *
28
+	 * @since 1.9.0
29
+	 * @param array $attributes
30
+	 * @param string $content
31
+	 * @param string $shortcode the shortcode that was called for this instance
32
+	 */
33
+	public function __construct( $attributes, $content, $shortcode ){
34
+
35
+		$this->id = isset( $attributes['id'] ) ? $attributes['id'] : '';
36
+		$this->setup_course_query();
37
+
38
+	}
39
+
40
+	/**
41
+	 * create the courses query .
42
+	 *
43
+	 * @return mixed
44
+	 */
45
+	public function setup_course_query(){
46
+
47
+		if( empty( $this->id ) ){
48
+			return;
49
+		}
50
+
51
+		$args = array(
52
+			'post_type' => 'course',
53
+			'posts_per_page' => 1,
54
+			'post_status' => 'publish',
55
+			'post__in' => array( $this->id ),
56
+		);
57
+
58
+		$this->course_page_query  = new WP_Query( $args );
59
+
60
+	}
61
+
62
+	/**
63
+	 * Rendering the shortcode this class is responsible for.
64
+	 *
65
+	 * @return string $content
66
+	 */
67
+	public function render(){
68
+
69
+		if( empty(  $this->id  ) ){
70
+
71
+			return sprintf( __( 'Please supply a course ID for the shortcode: %s', 'woothemes-sensei' ),'[sensei_course_page id=""]') ;
72
+
73
+		}
74
+
75
+		//set the wp_query to the current courses query
76
+		global $wp_query, $post;
77
+
78
+		// backups
79
+		$global_post_ref = $post;
80
+		$global_wp_query_ref = $wp_query;
81
+
82
+		$post = get_post( $this->id );
83
+		$wp_query->post = get_post( $this->id ); //  set this in case some the course hooks resets the query
84
+		$wp_query = $this->course_page_query;
85
+
86
+		ob_start();
87
+		self::the_single_course_content();
88
+		$shortcode_output = ob_get_clean();
89
+
90
+		// set back the global query and post
91
+		// restore global backups
92
+		$wp_query       = $global_wp_query_ref;
93
+		$post           = $global_post_ref;
94
+		$wp_query->post = $global_post_ref;
95
+		wp_reset_query();
96
+
97
+		return $shortcode_output;
98
+
99
+	}// end render
100
+
101
+	/**
102
+	 * Print out the single course content markup
103
+	 *
104
+	 * @since 1.9.0
105
+	 */
106
+	public static function the_single_course_content(){
107
+		?>
108 108
 
109 109
         <article <?php post_class( array( 'course', 'post' ) ); ?> >
110 110
 
@@ -122,6 +122,6 @@  discard block
 block discarded – undo
122 122
         </article>
123 123
 
124 124
         <?php
125
-    }// end the_single_course_content
125
+	}// end the_single_course_content
126 126
 
127 127
 }// end class
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 /**
4 4
  *
5 5
  * Renders the [sensei_course_page] shortcode. Display a single course based on the ID parameter given
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
      * @param string $content
31 31
      * @param string $shortcode the shortcode that was called for this instance
32 32
      */
33
-    public function __construct( $attributes, $content, $shortcode ){
33
+    public function __construct($attributes, $content, $shortcode) {
34 34
 
35
-        $this->id = isset( $attributes['id'] ) ? $attributes['id'] : '';
35
+        $this->id = isset($attributes['id']) ? $attributes['id'] : '';
36 36
         $this->setup_course_query();
37 37
 
38 38
     }
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
      *
43 43
      * @return mixed
44 44
      */
45
-    public function setup_course_query(){
45
+    public function setup_course_query() {
46 46
 
47
-        if( empty( $this->id ) ){
47
+        if (empty($this->id)) {
48 48
             return;
49 49
         }
50 50
 
@@ -52,10 +52,10 @@  discard block
 block discarded – undo
52 52
             'post_type' => 'course',
53 53
             'posts_per_page' => 1,
54 54
             'post_status' => 'publish',
55
-            'post__in' => array( $this->id ),
55
+            'post__in' => array($this->id),
56 56
         );
57 57
 
58
-        $this->course_page_query  = new WP_Query( $args );
58
+        $this->course_page_query = new WP_Query($args);
59 59
 
60 60
     }
61 61
 
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
      *
65 65
      * @return string $content
66 66
      */
67
-    public function render(){
67
+    public function render() {
68 68
 
69
-        if( empty(  $this->id  ) ){
69
+        if (empty($this->id)) {
70 70
 
71
-            return sprintf( __( 'Please supply a course ID for the shortcode: %s', 'woothemes-sensei' ),'[sensei_course_page id=""]') ;
71
+            return sprintf(__('Please supply a course ID for the shortcode: %s', 'woothemes-sensei'), '[sensei_course_page id=""]');
72 72
 
73 73
         }
74 74
 
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
         $global_post_ref = $post;
80 80
         $global_wp_query_ref = $wp_query;
81 81
 
82
-        $post = get_post( $this->id );
83
-        $wp_query->post = get_post( $this->id ); //  set this in case some the course hooks resets the query
82
+        $post = get_post($this->id);
83
+        $wp_query->post = get_post($this->id); //  set this in case some the course hooks resets the query
84 84
         $wp_query = $this->course_page_query;
85 85
 
86 86
         ob_start();
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
      *
104 104
      * @since 1.9.0
105 105
      */
106
-    public static function the_single_course_content(){
106
+    public static function the_single_course_content() {
107 107
         ?>
108 108
 
109
-        <article <?php post_class( array( 'course', 'post' ) ); ?> >
109
+        <article <?php post_class(array('course', 'post')); ?> >
110 110
 
111 111
 
112
-            <?php  do_action( 'sensei_single_course_content_inside_before' );  ?>
112
+            <?php  do_action('sensei_single_course_content_inside_before'); ?>
113 113
 
114 114
             <section class="entry fix">
115 115
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
             </section>
119 119
 
120
-            <?php  do_action( 'sensei_single_course_content_inside_after' );  ?>
120
+            <?php  do_action('sensei_single_course_content_inside_after'); ?>
121 121
 
122 122
         </article>
123 123
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis User Profile List Table Class
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-teachers.php 3 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -17,270 +17,270 @@
 block discarded – undo
17 17
  */
18 18
 class Sensei_Shortcode_Teachers implements Sensei_Shortcode_Interface {
19 19
 
20
-    /**
21
-     * @var WP_User_Query keeps a reference to the user query created
22
-     */
23
-    protected $user_query;
20
+	/**
21
+	 * @var WP_User_Query keeps a reference to the user query created
22
+	 */
23
+	protected $user_query;
24 24
 
25
-    /**
26
-     * @var which user id's to include
27
-     */
28
-    protected $include;
25
+	/**
26
+	 * @var which user id's to include
27
+	 */
28
+	protected $include;
29 29
 
30
-    /**
31
-     * @var which user id's to exclude
32
-     */
33
-    protected $exclude;
30
+	/**
31
+	 * @var which user id's to exclude
32
+	 */
33
+	protected $exclude;
34 34
 
35
-    /**
36
-     * Setup the shortcode object
37
-     *
38
-     * @since 1.9.0
39
-     * @param array $attributes
40
-     * @param string $content
41
-     * @param string $shortcode the shortcode that was called for this instance
42
-     */
43
-    public function __construct( $attributes, $content, $shortcode ){
35
+	/**
36
+	 * Setup the shortcode object
37
+	 *
38
+	 * @since 1.9.0
39
+	 * @param array $attributes
40
+	 * @param string $content
41
+	 * @param string $shortcode the shortcode that was called for this instance
42
+	 */
43
+	public function __construct( $attributes, $content, $shortcode ){
44 44
 
45
-        $include = isset( $attributes['include'] ) ? explode( ',', $attributes['include'] ) : '';
46
-        $exclude = isset( $attributes['exclude'] ) ? explode( ',', $attributes['exclude'] ) : '';
45
+		$include = isset( $attributes['include'] ) ? explode( ',', $attributes['include'] ) : '';
46
+		$exclude = isset( $attributes['exclude'] ) ? explode( ',', $attributes['exclude'] ) : '';
47 47
 
48
-        // convert teacher usernames given to the id
49
-        $this->include = $this->convert_usernames_to_ids( $include );
50
-        $this->exclude = $this->convert_usernames_to_ids( $exclude );
48
+		// convert teacher usernames given to the id
49
+		$this->include = $this->convert_usernames_to_ids( $include );
50
+		$this->exclude = $this->convert_usernames_to_ids( $exclude );
51 51
 
52
-        $this->setup_teacher_query();
52
+		$this->setup_teacher_query();
53 53
 
54
-    }
54
+	}
55 55
 
56
-    /**
57
-     *
58
-     * Setup the user query that will be used in the render method
59
-     *
60
-     * @since 1.9.0
61
-     */
62
-    protected function setup_teacher_query(){
56
+	/**
57
+	 *
58
+	 * Setup the user query that will be used in the render method
59
+	 *
60
+	 * @since 1.9.0
61
+	 */
62
+	protected function setup_teacher_query(){
63 63
 
64
-        $user_query_args = array(
65
-            'role' => 'teacher',
66
-        );
64
+		$user_query_args = array(
65
+			'role' => 'teacher',
66
+		);
67 67
 
68
-        $this->user_query = new WP_User_Query( $user_query_args );
68
+		$this->user_query = new WP_User_Query( $user_query_args );
69 69
 
70
-    }// end setup _course_query
70
+	}// end setup _course_query
71 71
 
72
-    /**
73
-     * Rendering the shortcode this class is responsible for.
74
-     *
75
-     * @return string $content
76
-     */
77
-    public function render(){
72
+	/**
73
+	 * Rendering the shortcode this class is responsible for.
74
+	 *
75
+	 * @return string $content
76
+	 */
77
+	public function render(){
78 78
 
79
-        $all_users = $this->user_query->get_results();
80
-        // if the user has specified more users add them as well.
81
-        if( ! empty( $this->include ) ){
79
+		$all_users = $this->user_query->get_results();
80
+		// if the user has specified more users add them as well.
81
+		if( ! empty( $this->include ) ){
82 82
 
83
-            $included_users_query = new WP_User_Query( array( 'include' => $this->include ) );
84
-            $included_users = $included_users_query->get_results();
85
-            if( ! empty( $included_users ) ){
83
+			$included_users_query = new WP_User_Query( array( 'include' => $this->include ) );
84
+			$included_users = $included_users_query->get_results();
85
+			if( ! empty( $included_users ) ){
86 86
 
87
-                $merged_users = array_merge( $all_users, $included_users );
88
-                $all_users = $this->users_unique( $merged_users );
89
-                $all_users = $this->users_sort( $all_users );
87
+				$merged_users = array_merge( $all_users, $included_users );
88
+				$all_users = $this->users_unique( $merged_users );
89
+				$all_users = $this->users_sort( $all_users );
90 90
 
91
-            }
91
+			}
92 92
 
93
-        }
93
+		}
94 94
 
95
-        // exclude the users not wanted
96
-        if( ! empty( $this->exclude ) ){
95
+		// exclude the users not wanted
96
+		if( ! empty( $this->exclude ) ){
97 97
 
98
-            $all_users = $this->exclude_users( $all_users, $this->exclude );
98
+			$all_users = $this->exclude_users( $all_users, $this->exclude );
99 99
 
100
-        }
100
+		}
101 101
 
102
-        if( ! count( $all_users )> 0  ){
103
-            return '';
104
-        }
102
+		if( ! count( $all_users )> 0  ){
103
+			return '';
104
+		}
105 105
 
106 106
 
107
-        $users_output = '';
107
+		$users_output = '';
108 108
 
109
-        foreach ( $all_users as $user ) {
109
+		foreach ( $all_users as $user ) {
110 110
 
111
-            $user_display_name = $this->get_user_public_name( $user );
111
+			$user_display_name = $this->get_user_public_name( $user );
112 112
 
113
-            /**
114
-             * Sensei teachers shortcode list item filter
115
-             *
116
-             * @since 1.9.0
117
-             *
118
-             * @param string $teacher_li the html for the teacher li
119
-             * @param WP_User $user
120
-             */
121
-            $users_output .= apply_filters( 'sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'. get_author_posts_url( $user->ID ) . '">'. $user_display_name .  '<a/></li>', $user );
113
+			/**
114
+			 * Sensei teachers shortcode list item filter
115
+			 *
116
+			 * @since 1.9.0
117
+			 *
118
+			 * @param string $teacher_li the html for the teacher li
119
+			 * @param WP_User $user
120
+			 */
121
+			$users_output .= apply_filters( 'sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'. get_author_posts_url( $user->ID ) . '">'. $user_display_name .  '<a/></li>', $user );
122 122
 
123
-        }
123
+		}
124 124
 
125
-        return '<ul class="sensei-teachers">' . $users_output . '</ul>';
125
+		return '<ul class="sensei-teachers">' . $users_output . '</ul>';
126 126
 
127
-    }// end render
127
+	}// end render
128 128
 
129
-    /**
130
-     * remove duplicate user objects from and array of users
131
-     *
132
-     * @since 1.9.0
133
-     *
134
-     * @param array $users{
135
-     *   @type WP_User
136
-     * }
137
-     *
138
-     * @return array $unique_users {
139
-     *   @type WP_User
140
-     * }
141
-     */
142
-    public  function users_unique( $users ){
129
+	/**
130
+	 * remove duplicate user objects from and array of users
131
+	 *
132
+	 * @since 1.9.0
133
+	 *
134
+	 * @param array $users{
135
+	 *   @type WP_User
136
+	 * }
137
+	 *
138
+	 * @return array $unique_users {
139
+	 *   @type WP_User
140
+	 * }
141
+	 */
142
+	public  function users_unique( $users ){
143 143
 
144
-        $array_unique_users_ids = array();
145
-        foreach( $users as $index => $user ){
144
+		$array_unique_users_ids = array();
145
+		foreach( $users as $index => $user ){
146 146
 
147
-            if(  in_array( $user->ID,  $array_unique_users_ids)  ){
147
+			if(  in_array( $user->ID,  $array_unique_users_ids)  ){
148 148
 
149
-                // exclude this user as it is already in the list
150
-                unset( $users[ $index ] );
149
+				// exclude this user as it is already in the list
150
+				unset( $users[ $index ] );
151 151
 
152
-            }else{
152
+			}else{
153 153
 
154
-                // add teh user to the list of users
155
-                $array_unique_users_ids[] = $user->ID;
154
+				// add teh user to the list of users
155
+				$array_unique_users_ids[] = $user->ID;
156 156
 
157
-            }
157
+			}
158 158
 
159
-        }
159
+		}
160 160
 
161
-        return $users;
161
+		return $users;
162 162
 
163
-    }// end users_unique
163
+	}// end users_unique
164 164
 
165
-    /**
166
-     * Exclude users based ont he ids given.
167
-     *
168
-     * @since 1.9.0
169
-     *
170
-     * @param array $users
171
-     * @param array $exclude_ids
172
-     * @return array
173
-     */
174
-    public function exclude_users( $users, $exclude_ids ){
165
+	/**
166
+	 * Exclude users based ont he ids given.
167
+	 *
168
+	 * @since 1.9.0
169
+	 *
170
+	 * @param array $users
171
+	 * @param array $exclude_ids
172
+	 * @return array
173
+	 */
174
+	public function exclude_users( $users, $exclude_ids ){
175 175
 
176
-        foreach( $users as $index => $user ){
176
+		foreach( $users as $index => $user ){
177 177
 
178
-            if( in_array( $user->ID, $exclude_ids )  ){
178
+			if( in_array( $user->ID, $exclude_ids )  ){
179 179
 
180
-                // remove the user from the list
181
-                unset( $users[ $index ] );
180
+				// remove the user from the list
181
+				unset( $users[ $index ] );
182 182
 
183
-            }
183
+			}
184 184
 
185
-        }
185
+		}
186 186
 
187
-        return $users;
187
+		return $users;
188 188
 
189
-    }// end exclude_users
189
+	}// end exclude_users
190 190
 
191
-    /**
192
-     * Convert mixed array of user id and user names to only be an array of user_ids
193
-     *
194
-     * @param array $users
195
-     * @return array $users_ids
196
-     */
197
-    public function convert_usernames_to_ids( $users ){
191
+	/**
192
+	 * Convert mixed array of user id and user names to only be an array of user_ids
193
+	 *
194
+	 * @param array $users
195
+	 * @return array $users_ids
196
+	 */
197
+	public function convert_usernames_to_ids( $users ){
198 198
 
199
-        // backup
200
-        $users_ids = array();
199
+		// backup
200
+		$users_ids = array();
201 201
 
202
-        if ( is_array($users) ) {
202
+		if ( is_array($users) ) {
203 203
 
204
-            foreach ($users as $user_id_or_username) {
204
+			foreach ($users as $user_id_or_username) {
205 205
 
206
-                if (!is_numeric($user_id_or_username)) {
206
+				if (!is_numeric($user_id_or_username)) {
207 207
 
208
-                    $user_name = $user_id_or_username;
209
-                    $user = get_user_by('login', $user_name);
208
+					$user_name = $user_id_or_username;
209
+					$user = get_user_by('login', $user_name);
210 210
 
211
-                    if (is_a($user, 'WP_User')) {
212
-                        $users_ids[] = $user->ID;
213
-                    }
211
+					if (is_a($user, 'WP_User')) {
212
+						$users_ids[] = $user->ID;
213
+					}
214 214
 
215
-                } else {
215
+				} else {
216 216
 
217
-                    $user_id = $user_id_or_username;
218
-                    $users_ids[] = $user_id;
217
+					$user_id = $user_id_or_username;
218
+					$users_ids[] = $user_id;
219 219
 
220
-                }
220
+				}
221 221
 
222
-            }
223
-        }
222
+			}
223
+		}
224 224
 
225
-        return $users_ids;
226
-    }
225
+		return $users_ids;
226
+	}
227 227
 
228
-    /**
229
-     * Returns the first name and last name or the display name of a user.
230
-     *
231
-     * @since 1.9.0
232
-     *
233
-     * @param $user
234
-     * @return string $user_public_name
235
-     */
236
-    public function get_user_public_name( $user ){
228
+	/**
229
+	 * Returns the first name and last name or the display name of a user.
230
+	 *
231
+	 * @since 1.9.0
232
+	 *
233
+	 * @param $user
234
+	 * @return string $user_public_name
235
+	 */
236
+	public function get_user_public_name( $user ){
237 237
 
238
-        if (!empty($user->first_name) && !empty($user->last_name)) {
238
+		if (!empty($user->first_name) && !empty($user->last_name)) {
239 239
 
240
-            $user_public_name = $user->first_name . ' ' . $user->last_name;
240
+			$user_public_name = $user->first_name . ' ' . $user->last_name;
241 241
 
242
-        }
242
+		}
243 243
 
244
-        else {
244
+		else {
245 245
 
246
-            $user_public_name = $user->display_name;
246
+			$user_public_name = $user->display_name;
247 247
 
248
-        }
248
+		}
249 249
 
250
-        return $user_public_name;
251
-    }
250
+		return $user_public_name;
251
+	}
252 252
 
253
-    /**
254
-     *
255
-     * Sort user objects by user display
256
-     *
257
-     * @since 1.9.0
258
-     *
259
-     * @param $users
260
-     * @return  array $sorted_users
261
-     */
262
-    public function users_sort( $users ){
253
+	/**
254
+	 *
255
+	 * Sort user objects by user display
256
+	 *
257
+	 * @since 1.9.0
258
+	 *
259
+	 * @param $users
260
+	 * @return  array $sorted_users
261
+	 */
262
+	public function users_sort( $users ){
263 263
 
264
-        $sorted_users = $users;
264
+		$sorted_users = $users;
265 265
 
266
-        uasort( $sorted_users, array( $this, 'custom_user_sort' ) );
266
+		uasort( $sorted_users, array( $this, 'custom_user_sort' ) );
267 267
 
268
-        return $sorted_users;
269
-    }
268
+		return $sorted_users;
269
+	}
270 270
 
271
-    /**
272
-     * Used in the uasort function to sort users by title
273
-     *
274
-     * @since 1.9.0
275
-     *
276
-     * @param $user_1
277
-     * @param $user_2
278
-     * @return int
279
-     */
280
-    public function custom_user_sort($user_1, $user_2){
271
+	/**
272
+	 * Used in the uasort function to sort users by title
273
+	 *
274
+	 * @since 1.9.0
275
+	 *
276
+	 * @param $user_1
277
+	 * @param $user_2
278
+	 * @return int
279
+	 */
280
+	public function custom_user_sort($user_1, $user_2){
281 281
 
282
-        return strcasecmp( $this->get_user_public_name( $user_1 ), $this->get_user_public_name( $user_2 )  );
282
+		return strcasecmp( $this->get_user_public_name( $user_1 ), $this->get_user_public_name( $user_2 )  );
283 283
 
284
-    }// end custom_user_sort
284
+	}// end custom_user_sort
285 285
 
286 286
 }// end class
287 287
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 /**
4 4
  *
5 5
  * Renders the [sensei_teachers] shortcode. Will show a list of teachers
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
      * @param string $content
41 41
      * @param string $shortcode the shortcode that was called for this instance
42 42
      */
43
-    public function __construct( $attributes, $content, $shortcode ){
43
+    public function __construct($attributes, $content, $shortcode) {
44 44
 
45
-        $include = isset( $attributes['include'] ) ? explode( ',', $attributes['include'] ) : '';
46
-        $exclude = isset( $attributes['exclude'] ) ? explode( ',', $attributes['exclude'] ) : '';
45
+        $include = isset($attributes['include']) ? explode(',', $attributes['include']) : '';
46
+        $exclude = isset($attributes['exclude']) ? explode(',', $attributes['exclude']) : '';
47 47
 
48 48
         // convert teacher usernames given to the id
49
-        $this->include = $this->convert_usernames_to_ids( $include );
50
-        $this->exclude = $this->convert_usernames_to_ids( $exclude );
49
+        $this->include = $this->convert_usernames_to_ids($include);
50
+        $this->exclude = $this->convert_usernames_to_ids($exclude);
51 51
 
52 52
         $this->setup_teacher_query();
53 53
 
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @since 1.9.0
61 61
      */
62
-    protected function setup_teacher_query(){
62
+    protected function setup_teacher_query() {
63 63
 
64 64
         $user_query_args = array(
65 65
             'role' => 'teacher',
66 66
         );
67 67
 
68
-        $this->user_query = new WP_User_Query( $user_query_args );
68
+        $this->user_query = new WP_User_Query($user_query_args);
69 69
 
70 70
     }// end setup _course_query
71 71
 
@@ -74,41 +74,41 @@  discard block
 block discarded – undo
74 74
      *
75 75
      * @return string $content
76 76
      */
77
-    public function render(){
77
+    public function render() {
78 78
 
79 79
         $all_users = $this->user_query->get_results();
80 80
         // if the user has specified more users add them as well.
81
-        if( ! empty( $this->include ) ){
81
+        if ( ! empty($this->include)) {
82 82
 
83
-            $included_users_query = new WP_User_Query( array( 'include' => $this->include ) );
83
+            $included_users_query = new WP_User_Query(array('include' => $this->include));
84 84
             $included_users = $included_users_query->get_results();
85
-            if( ! empty( $included_users ) ){
85
+            if ( ! empty($included_users)) {
86 86
 
87
-                $merged_users = array_merge( $all_users, $included_users );
88
-                $all_users = $this->users_unique( $merged_users );
89
-                $all_users = $this->users_sort( $all_users );
87
+                $merged_users = array_merge($all_users, $included_users);
88
+                $all_users = $this->users_unique($merged_users);
89
+                $all_users = $this->users_sort($all_users);
90 90
 
91 91
             }
92 92
 
93 93
         }
94 94
 
95 95
         // exclude the users not wanted
96
-        if( ! empty( $this->exclude ) ){
96
+        if ( ! empty($this->exclude)) {
97 97
 
98
-            $all_users = $this->exclude_users( $all_users, $this->exclude );
98
+            $all_users = $this->exclude_users($all_users, $this->exclude);
99 99
 
100 100
         }
101 101
 
102
-        if( ! count( $all_users )> 0  ){
102
+        if ( ! count($all_users) > 0) {
103 103
             return '';
104 104
         }
105 105
 
106 106
 
107 107
         $users_output = '';
108 108
 
109
-        foreach ( $all_users as $user ) {
109
+        foreach ($all_users as $user) {
110 110
 
111
-            $user_display_name = $this->get_user_public_name( $user );
111
+            $user_display_name = $this->get_user_public_name($user);
112 112
 
113 113
             /**
114 114
              * Sensei teachers shortcode list item filter
@@ -118,11 +118,11 @@  discard block
 block discarded – undo
118 118
              * @param string $teacher_li the html for the teacher li
119 119
              * @param WP_User $user
120 120
              */
121
-            $users_output .= apply_filters( 'sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'. get_author_posts_url( $user->ID ) . '">'. $user_display_name .  '<a/></li>', $user );
121
+            $users_output .= apply_filters('sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'.get_author_posts_url($user->ID).'">'.$user_display_name.'<a/></li>', $user);
122 122
 
123 123
         }
124 124
 
125
-        return '<ul class="sensei-teachers">' . $users_output . '</ul>';
125
+        return '<ul class="sensei-teachers">'.$users_output.'</ul>';
126 126
 
127 127
     }// end render
128 128
 
@@ -139,17 +139,17 @@  discard block
 block discarded – undo
139 139
      *   @type WP_User
140 140
      * }
141 141
      */
142
-    public  function users_unique( $users ){
142
+    public  function users_unique($users) {
143 143
 
144 144
         $array_unique_users_ids = array();
145
-        foreach( $users as $index => $user ){
145
+        foreach ($users as $index => $user) {
146 146
 
147
-            if(  in_array( $user->ID,  $array_unique_users_ids)  ){
147
+            if (in_array($user->ID, $array_unique_users_ids)) {
148 148
 
149 149
                 // exclude this user as it is already in the list
150
-                unset( $users[ $index ] );
150
+                unset($users[$index]);
151 151
 
152
-            }else{
152
+            } else {
153 153
 
154 154
                 // add teh user to the list of users
155 155
                 $array_unique_users_ids[] = $user->ID;
@@ -171,14 +171,14 @@  discard block
 block discarded – undo
171 171
      * @param array $exclude_ids
172 172
      * @return array
173 173
      */
174
-    public function exclude_users( $users, $exclude_ids ){
174
+    public function exclude_users($users, $exclude_ids) {
175 175
 
176
-        foreach( $users as $index => $user ){
176
+        foreach ($users as $index => $user) {
177 177
 
178
-            if( in_array( $user->ID, $exclude_ids )  ){
178
+            if (in_array($user->ID, $exclude_ids)) {
179 179
 
180 180
                 // remove the user from the list
181
-                unset( $users[ $index ] );
181
+                unset($users[$index]);
182 182
 
183 183
             }
184 184
 
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
      * @param array $users
195 195
      * @return array $users_ids
196 196
      */
197
-    public function convert_usernames_to_ids( $users ){
197
+    public function convert_usernames_to_ids($users) {
198 198
 
199 199
         // backup
200 200
         $users_ids = array();
201 201
 
202
-        if ( is_array($users) ) {
202
+        if (is_array($users)) {
203 203
 
204 204
             foreach ($users as $user_id_or_username) {
205 205
 
206
-                if (!is_numeric($user_id_or_username)) {
206
+                if ( ! is_numeric($user_id_or_username)) {
207 207
 
208 208
                     $user_name = $user_id_or_username;
209 209
                     $user = get_user_by('login', $user_name);
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
      * @param $user
234 234
      * @return string $user_public_name
235 235
      */
236
-    public function get_user_public_name( $user ){
236
+    public function get_user_public_name($user) {
237 237
 
238
-        if (!empty($user->first_name) && !empty($user->last_name)) {
238
+        if ( ! empty($user->first_name) && ! empty($user->last_name)) {
239 239
 
240
-            $user_public_name = $user->first_name . ' ' . $user->last_name;
240
+            $user_public_name = $user->first_name.' '.$user->last_name;
241 241
 
242 242
         }
243 243
 
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
      * @param $users
260 260
      * @return  array $sorted_users
261 261
      */
262
-    public function users_sort( $users ){
262
+    public function users_sort($users) {
263 263
 
264 264
         $sorted_users = $users;
265 265
 
266
-        uasort( $sorted_users, array( $this, 'custom_user_sort' ) );
266
+        uasort($sorted_users, array($this, 'custom_user_sort'));
267 267
 
268 268
         return $sorted_users;
269 269
     }
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
      * @param $user_2
278 278
      * @return int
279 279
      */
280
-    public function custom_user_sort($user_1, $user_2){
280
+    public function custom_user_sort($user_1, $user_2) {
281 281
 
282
-        return strcasecmp( $this->get_user_public_name( $user_1 ), $this->get_user_public_name( $user_2 )  );
282
+        return strcasecmp($this->get_user_public_name($user_1), $this->get_user_public_name($user_2));
283 283
 
284 284
     }// end custom_user_sort
285 285
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 /**
4 7
  *
5 8
  * Renders the [sensei_teachers] shortcode. Will show a list of teachers
@@ -149,7 +152,7 @@  discard block
 block discarded – undo
149 152
                 // exclude this user as it is already in the list
150 153
                 unset( $users[ $index ] );
151 154
 
152
-            }else{
155
+            } else{
153 156
 
154 157
                 // add teh user to the list of users
155 158
                 $array_unique_users_ids[] = $user->ID;
@@ -239,9 +242,7 @@  discard block
 block discarded – undo
239 242
 
240 243
             $user_public_name = $user->first_name . ' ' . $user->last_name;
241 244
 
242
-        }
243
-
244
-        else {
245
+        } else {
245 246
 
246 247
             $user_public_name = $user->display_name;
247 248
 
Please login to merge, or discard this patch.
includes/class-sensei-modules.php 4 patches
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+	exit;
5
+}
4 6
 
5 7
 /**
6 8
  * Sensei Modules Class
@@ -401,8 +403,9 @@  discard block
 block discarded – undo
401 403
         $term = urldecode(stripslashes($_GET['term']));
402 404
 
403 405
         // Return nothing if term is empty
404
-        if (empty($term))
405
-            die();
406
+        if (empty($term)) {
407
+                    die();
408
+        }
406 409
 
407 410
         // Set a default if none is given
408 411
         $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
@@ -789,7 +792,9 @@  discard block
 block discarded – undo
789 792
         );
790 793
         $lessons = get_posts($args);
791 794
 
792
-        if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
795
+        if (is_wp_error($lessons) || 0 >= count($lessons)) {
796
+        	return 0;
797
+        }
793 798
 
794 799
         $completed = false;
795 800
         $lesson_count = 0;
@@ -1378,7 +1383,7 @@  discard block
 block discarded – undo
1378 1383
 
1379 1384
             return $lesson_query->posts;
1380 1385
 
1381
-        }else{
1386
+        } else{
1382 1387
 
1383 1388
             return array();
1384 1389
 
Please login to merge, or discard this patch.
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -21,6 +21,9 @@  discard block
 block discarded – undo
21 21
     private $order_page_slug;
22 22
     public $taxonomy;
23 23
 
24
+    /**
25
+     * @param string $file
26
+     */
24 27
     public function __construct( $file )
25 28
     {
26 29
         $this->file = $file;
@@ -1942,6 +1945,7 @@  discard block
 block discarded – undo
1942 1945
      * Hooked into 'get_terms'
1943 1946
      *
1944 1947
      * @since 1.8.0
1948
+     * @param string[] $taxonomies
1945 1949
      */
1946 1950
     public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1947 1951
     {
Please login to merge, or discard this patch.
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * Sensei Modules Class
@@ -21,33 +21,33 @@  discard block
 block discarded – undo
21 21
     private $order_page_slug;
22 22
     public $taxonomy;
23 23
 
24
-    public function __construct( $file )
24
+    public function __construct($file)
25 25
     {
26 26
         $this->file = $file;
27 27
         $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
28
+        $this->assets_dir = trailingslashit($this->dir).'assets';
29 29
         $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30 30
         $this->taxonomy = 'module';
31 31
         $this->order_page_slug = 'module-order';
32 32
 
33 33
         // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
34
+        add_action('init', array($this, 'setup_modules_taxonomy'), 10);
35 35
 
36 36
         // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
37
+        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2);
38 38
 
39 39
         // Save lesson meta box
40 40
         add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41 41
 
42 42
         //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
43
+        add_action('save_post', array('Sensei_Core_Modules', 'reset_none_modules_transient'));
44 44
 
45 45
         // Frontend styling
46 46
         add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47 47
 
48 48
         // Admin styling
49 49
         add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
50
+        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'), 20, 2);
51 51
 
52 52
         // Handle module completion record
53 53
         add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
@@ -55,20 +55,20 @@  discard block
 block discarded – undo
55 55
         add_action('wp', array($this, 'save_module_progress'), 10);
56 56
 
57 57
         // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
58
+        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30);
59 59
         add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60 60
         add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61 61
 
62 62
         // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
63
+        add_action('admin_menu', array($this, 'remove_lessons_menu_model_taxonomy'), 10);
64
+        add_action('admin_menu', array($this, 'remove_courses_menu_model_taxonomy'), 10);
65
+        add_action('admin_menu', array($this, 'redirect_to_lesson_module_taxonomy_to_course'), 20);
66 66
 
67 67
         // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
68
+        add_action($this->taxonomy.'_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+        add_action($this->taxonomy.'_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+        add_action('edited_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+        add_action('created_'.$this->taxonomy, array($this, 'save_module_course'), 10, 2);
72 72
         add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73 73
 
74 74
         // Manage module taxonomy archive page
@@ -80,10 +80,10 @@  discard block
 block discarded – undo
80 80
         add_filter('body_class', array($this, 'module_archive_body_class'));
81 81
 
82 82
         // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
83
+        add_action('sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template'), 8);
84 84
 
85 85
         //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
86
+        add_action('sensei_single_course_modules_before', array($this, 'course_modules_title'), 20);
87 87
 
88 88
         // Set up display on single lesson page
89 89
         add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
         add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96 96
 
97 97
         // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
98
+        add_filter('manage_edit-'.$this->taxonomy.'_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+        add_filter('manage_'.$this->taxonomy.'_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100 100
         add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101 101
 
102 102
         //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
103
+        add_action('wp_ajax_sensei_add_new_module_term', array('Sensei_Core_Modules', 'add_new_module_term'));
104 104
 
105 105
         // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
106
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
107
+        add_filter('get_object_terms', array($this, 'filter_course_selected_terms'), 20, 3);
108 108
 
109 109
         // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
110
+        add_filter('get_terms', array($this, 'append_teacher_name_to_module'), 70, 3);
111 111
 
112 112
         // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
113
+        add_action('admin_init', array('Sensei_Core_Modules', 'remove_default_modules_box'));
114 114
 
115 115
     } // end constructor
116 116
 
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
      * @return void
128 128
      * @deprecated since 1.9.0
129 129
      */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
130
+    public function change_module_term_slug($term_id, $tt_id, $taxonomy) {
131 131
 
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
132
+        _deprecated_function('change_module_term_slug', '1.9.0');
133 133
 
134 134
     }// end add_module_term_group
135 135
 
@@ -143,20 +143,20 @@  discard block
 block discarded – undo
143 143
      *
144 144
      * @return void
145 145
      */
146
-    public function modules_metaboxes( $post_type, $post )
146
+    public function modules_metaboxes($post_type, $post)
147 147
     {
148
-        if ('lesson' == $post_type ) {
148
+        if ('lesson' == $post_type) {
149 149
 
150 150
             // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
151
+            remove_meta_box($this->taxonomy.'div', 'lesson', 'side');
152 152
 
153 153
             // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
154
+            add_meta_box($this->taxonomy.'_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155 155
         }
156 156
 
157
-        if( 'course' == $post_type ){
157
+        if ('course' == $post_type) {
158 158
             // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
159
+            add_meta_box($this->taxonomy.'_course_mb', __('Course Modules', 'woothemes-sensei'), array($this, 'course_module_metabox'), 'course', 'side', 'core');
160 160
         }
161 161
     }
162 162
 
@@ -192,21 +192,21 @@  discard block
 block discarded – undo
192 192
             $modules = $this->get_course_modules($lesson_course);
193 193
 
194 194
             // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
195
+            $html .= '<input type="hidden" name="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" id="'.esc_attr('woo_lesson_'.$this->taxonomy.'_nonce').'" value="'.esc_attr(wp_create_nonce(plugin_basename($this->file))).'" />';
196 196
             if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
197
+                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">'."\n";
198
+                $html .= '<option value="">'.__('None', 'woothemes-sensei').'</option>';
199 199
                 foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
200
+                    $html .= '<option value="'.esc_attr(absint($module->term_id)).'"'.selected($module->term_id, $lesson_module, false).'>'.esc_html($module->name).'</option>'."\n";
201 201
                 }
202
-                $html .= '</select>' . "\n";
202
+                $html .= '</select>'."\n";
203 203
             } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
204
+                $course_url = admin_url('post.php?post='.urlencode($lesson_course).'&action=edit');
205
+                $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="'.esc_url($course_url).'">', '</a>').'</p>';
206 206
             } // End If Statement
207 207
 
208 208
         } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
209
+            $html .= '<p>'.sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>').'</p>';
210 210
         } // End If Statement
211 211
 
212 212
         // Output the HTML
@@ -225,38 +225,38 @@  discard block
 block discarded – undo
225 225
         global $post;
226 226
 
227 227
         // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
228
+        if ((get_post_type() != 'lesson') || ! isset($_POST['woo_lesson_'.$this->taxonomy.'_nonce'])
229
+            ||! wp_verify_nonce($_POST['woo_lesson_'.$this->taxonomy.'_nonce'], plugin_basename($this->file))) {
230 230
             return $post_id;
231 231
         }
232 232
 
233 233
         // Check if user has permissions to edit lessons
234 234
         $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
235
+        if ( ! current_user_can($post_type->cap->edit_post, $post_id)) {
236 236
             return $post_id;
237 237
         }
238 238
 
239 239
         // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
240
+        if ( ! current_user_can('edit_post', $post_id)) {
241 241
             return $post_id;
242 242
         }
243 243
 
244 244
         // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
245
+        if (isset($_POST['lesson_module'])) {
246 246
 
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
247
+            if (empty ($_POST['lesson_module'])) {
248
+                wp_delete_object_term_relationships($post_id, $this->taxonomy);
249 249
                 return true;
250 250
             }
251 251
 
252
-            $module_id = intval( $_POST['lesson_module'] );
252
+            $module_id = intval($_POST['lesson_module']);
253 253
 
254 254
             // Assign lesson to selected module
255 255
             wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256 256
 
257 257
             // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
258
+            if ( ! get_post_meta($post_id, '_order_module_'.$module_id, true)) {
259
+                update_post_meta($post_id, '_order_module_'.$module_id, 0);
260 260
             }
261 261
         }
262 262
 
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         $module_courses = array();
315 315
         if (isset($courses) && is_array($courses)) {
316 316
             foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
317
+                $module_courses[] = array('id' =>$course->ID, 'details'=>$course->post_title);
318 318
             }
319 319
         }
320 320
 
@@ -324,8 +324,8 @@  discard block
 block discarded – undo
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
325 325
             <td>
326 326
                 <input type="hidden"
327
-                       data-defaults="<?php echo esc_attr( json_encode($module_courses)); ?>"
328
-                       value="<?php echo esc_attr( json_encode($module_courses) ); ?>"
327
+                       data-defaults="<?php echo esc_attr(json_encode($module_courses)); ?>"
328
+                       value="<?php echo esc_attr(json_encode($module_courses)); ?>"
329 329
                        id="module_courses" name="module_courses"
330 330
                        class="ajax_chosen_select_courses"
331 331
                        placeholder="<?php esc_attr_e('Search for courses...', 'woothemes-sensei'); ?>"
@@ -370,11 +370,11 @@  discard block
 block discarded – undo
370 370
         }
371 371
 
372 372
         // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
373
+        if (isset($_POST['module_courses']) && ! empty($_POST['module_courses'])) {
374 374
 
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
375
+            $course_ids = explode(",", $_POST['module_courses']);
376 376
 
377
-            foreach ( $course_ids as $course_id ) {
377
+            foreach ($course_ids as $course_id) {
378 378
 
379 379
                 wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380 380
 
@@ -438,11 +438,11 @@  discard block
 block discarded – undo
438 438
      * @since 1.8.0
439 439
      * @return void
440 440
      */
441
-    public function single_course_modules(){
441
+    public function single_course_modules() {
442 442
 
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
443
+        _deprecated_function('Sensei_Modules->single_course_modules', 'Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444 444
         // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
445
+        if (is_singular('course') && has_term('', 'module')) {
446 446
 
447 447
             $this->load_course_module_content_template();
448 448
 
@@ -459,15 +459,15 @@  discard block
 block discarded – undo
459 459
 
460 460
         if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461 461
             $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
462
+            if ( ! $is_user_taking_course) {
463 463
                 if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464 464
                     $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465 465
                     // Remove brackets for display here
466 466
                     $title_text = str_replace('(', '', $title_text);
467 467
                     $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
468
+                    $title_text = '<span class="preview-label">'.$title_text.'</span>';
469 469
                 }
470
-                $title .= ' ' . $title_text;
470
+                $title .= ' '.$title_text;
471 471
             }
472 472
         }
473 473
 
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
         if (is_singular('lesson')) {
482 482
             if (has_term('', $this->taxonomy, $post->ID)) {
483 483
                 $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
484
+                if ($module) {
485
+                    $html .= ' '.$separator.' <a href="'.esc_url($module->url).'" title="'.__('Back to the module', 'woothemes-sensei').'">'.$module->name.'</a>';
486 486
                 }
487 487
             }
488 488
         }
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
         if (is_tax($this->taxonomy)) {
491 491
             if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492 492
                 $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
493
+                $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>';
494 494
             }
495 495
         }
496 496
         return $html;
@@ -505,18 +505,18 @@  discard block
 block discarded – undo
505 505
      */
506 506
     public function module_archive_template($template) {
507 507
 
508
-        if ( ! is_tax($this->taxonomy) ) {
508
+        if ( ! is_tax($this->taxonomy)) {
509 509
             return $template;
510 510
         }
511 511
 
512 512
         $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
513
+        $find = array($file, Sensei()->template_url.$file);
514 514
 
515 515
         // locate the template file
516 516
         $template = locate_template($find);
517
-        if (!$template) {
517
+        if ( ! $template) {
518 518
 
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
519
+            $template = Sensei()->plugin_path().'templates/'.$file;
520 520
 
521 521
         }
522 522
 
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
             // Set order of lessons
543 543
             if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544 544
                 $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
545
+                $query->set('meta_key', '_order_module_'.$module_id);
546 546
                 $query->set('orderby', 'meta_value_num date');
547 547
             } else {
548 548
                 $query->set('orderby', 'menu_order');
@@ -603,10 +603,10 @@  discard block
 block discarded – undo
603 603
                     $status = __('In progress', 'woothemes-sensei');
604 604
                     $class = 'in-progress';
605 605
                 }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
606
+                echo '<p class="status '.esc_attr($class).'">'.$status.'</p>';
607 607
             }
608 608
 
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
609
+            echo '<p class="archive-description module-description">'.apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id).'</p>';
610 610
         }
611 611
     }
612 612
 
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
     public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732 732
     {
733 733
         $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
734
+        update_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), intval($module_progress));
735 735
 
736 736
         do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737 737
     }
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
      */
749 749
     public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750 750
     {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
751
+        $module_progress = get_user_meta(intval($user_id), '_module_progress_'.intval($course_id).'_'.intval($module_id), true);
752 752
         if ($module_progress) {
753
-            return (float)$module_progress;
753
+            return (float) $module_progress;
754 754
         }
755 755
         return false;
756 756
     }
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
         }
804 804
         $module_progress = ($completed_count / $lesson_count) * 100;
805 805
 
806
-        return (float)$module_progress;
806
+        return (float) $module_progress;
807 807
     }
808 808
 
809 809
     /**
@@ -816,7 +816,7 @@  discard block
 block discarded – undo
816 816
     public function register_modules_admin_menu_items()
817 817
     {
818 818
         //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
819
+        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module', '');
820 820
 
821 821
         // Regsiter new admin page for module ordering
822 822
         $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
@@ -843,19 +843,19 @@  discard block
 block discarded – undo
843 843
             $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844 844
 
845 845
             if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
846
+                $html .= '<div class="updated fade">'."\n";
847
+                $html .= '<p>'.__('The module order has been saved for this course.', 'woothemes-sensei').'</p>'."\n";
848
+                $html .= '</div>'."\n";
849 849
             }
850 850
         }
851 851
 
852 852
         $courses = Sensei()->course->get_all_courses();
853 853
 
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
854
+        $html .= '<form action="'.admin_url('edit.php').'" method="get">'."\n";
855
+        $html .= '<input type="hidden" name="post_type" value="course" />'."\n";
856
+        $html .= '<input type="hidden" name="page" value="'.esc_attr($this->order_page_slug).'" />'."\n";
857
+        $html .= '<select id="module-order-course" name="course_id">'."\n";
858
+        $html .= '<option value="">'.__('Select a course', 'woothemes-sensei').'</option>'."\n";
859 859
 
860 860
         foreach ($courses as $course) {
861 861
             if (has_term('', $this->taxonomy, $course->ID)) {
@@ -863,30 +863,30 @@  discard block
 block discarded – undo
863 863
                 if (isset($_GET['course_id'])) {
864 864
                     $course_id = intval($_GET['course_id']);
865 865
                 }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
866
+                $html .= '<option value="'.esc_attr(intval($course->ID)).'" '.selected($course->ID, $course_id, false).'>'.get_the_title($course->ID).'</option>'."\n";
867 867
             }
868 868
         }
869 869
 
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
870
+        $html .= '</select>'."\n";
871
+        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="'.__('Select', 'woothemes-sensei').'" />'."\n";
872
+        $html .= '</form>'."\n";
873 873
 
874 874
         if (isset($_GET['course_id'])) {
875 875
             $course_id = intval($_GET['course_id']);
876 876
             if ($course_id > 0) {
877 877
                 $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
878
+                $modules = $this->append_teacher_name_to_module($modules, array('module'), array());
879 879
                 if ($modules) {
880 880
 
881 881
                     $order = $this->get_course_module_order($course_id);
882 882
 
883
-                    $order_string='';
883
+                    $order_string = '';
884 884
                     if ($order) {
885 885
                         $order_string = implode(',', $order);
886 886
                     }
887 887
 
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
888
+                    $html .= '<form id="editgrouping" method="post" action="" class="validate">'."\n";
889
+                    $html .= '<ul class="sortable-module-list">'."\n";
890 890
                     $count = 0;
891 891
                     foreach ($modules as $module) {
892 892
                         $count++;
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
                         if ($count % 2 != 0) {
901 901
                             $class .= ' alternate';
902 902
                         }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
903
+                        $html .= '<li class="'.esc_attr($class).'"><span rel="'.esc_attr($module->term_id).'" style="width: 100%;"> '.$module->name.'</span></li>'."\n";
904 904
                     }
905
-                    $html .= '</ul>' . "\n";
905
+                    $html .= '</ul>'."\n";
906 906
 
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
907
+                    $html .= '<input type="hidden" name="module-order" value="'.$order_string.'" />'."\n";
908
+                    $html .= '<input type="hidden" name="course_id" value="'.$course_id.'" />'."\n";
909
+                    $html .= '<input type="submit" class="button-primary" value="'.__('Save module order', 'woothemes-sensei').'" />'."\n";
910
+                    $html .= '<a href="'.admin_url('post.php?post='.$course_id.'&action=edit').'" class="button-secondary">'.__('Edit course', 'woothemes-sensei').'</a>'."\n";
911 911
                 }
912 912
             }
913 913
         }
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
     {
945 945
         if ($column == 'module_order') {
946 946
             if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
947
+                echo '<a class="button-secondary" href="'.admin_url('edit.php?post_type=course&page=module-order&course_id='.urlencode(intval($course_id))).'">'.__('Order modules', 'woothemes-sensei').'</a>';
948 948
             }
949 949
         }
950 950
     }
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
                 $args['post_type'] = 'lesson';
1037 1037
                 $lessons = get_posts($args);
1038 1038
                 $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1039
+                $column_data = '<a href="'.admin_url('edit.php?module='.urlencode($module->slug).'&post_type=lesson').'">'.intval($total_lessons).'</a>';
1040 1040
                 break;
1041 1041
         }
1042 1042
 
@@ -1054,7 +1054,7 @@  discard block
 block discarded – undo
1054 1054
     public function analysis_overview_column_title($columns)
1055 1055
     {
1056 1056
 
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1057
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1058 1058
             $new_columns = array();
1059 1059
             if (is_array($columns) && 0 < count($columns)) {
1060 1060
                 foreach ($columns as $column => $title) {
@@ -1082,15 +1082,15 @@  discard block
 block discarded – undo
1082 1082
      * @param  WP_Post $lesson
1083 1083
      * @return array              Updated column data
1084 1084
      */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1085
+    public function analysis_overview_column_data($columns, $lesson)
1086 1086
     {
1087 1087
 
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1088
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1089 1089
             $lesson_module = '';
1090 1090
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091 1091
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092 1092
                 foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1093
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1094 1094
                     break;
1095 1095
                 }
1096 1096
             }
@@ -1111,7 +1111,7 @@  discard block
 block discarded – undo
1111 1111
      */
1112 1112
     public function analysis_course_column_title($columns)
1113 1113
     {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1114
+        if (isset($_GET['view']) && 'lessons' == $_GET['view']) {
1115 1115
             $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116 1116
         }
1117 1117
         return $columns;
@@ -1126,15 +1126,15 @@  discard block
 block discarded – undo
1126 1126
      * @param  WP_Post $lesson
1127 1127
      * @return array              Updated columns data
1128 1128
      */
1129
-    public function analysis_course_column_data($columns, $lesson )
1129
+    public function analysis_course_column_data($columns, $lesson)
1130 1130
     {
1131 1131
 
1132
-        if ( isset( $_GET['course_id'] ) ) {
1132
+        if (isset($_GET['course_id'])) {
1133 1133
             $lesson_module = '';
1134 1134
             $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135 1135
             if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136 1136
                 foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1137
+                    $lesson_module = '<a href="'.esc_url(admin_url('edit-tags.php?action=edit&taxonomy='.urlencode($this->taxonomy).'&tag_ID='.urlencode($single_module->term_id))).'">'.$single_module->name.'</a>';
1138 1138
                     break;
1139 1139
                 }
1140 1140
             }
@@ -1161,7 +1161,7 @@  discard block
 block discarded – undo
1161 1161
     public function get_lesson_module($lesson_id = 0)
1162 1162
     {
1163 1163
         $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1164
+        if ( ! (intval($lesson_id > 0))) {
1165 1165
             return false;
1166 1166
         }
1167 1167
 
@@ -1169,13 +1169,13 @@  discard block
 block discarded – undo
1169 1169
         $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170 1170
 
1171 1171
         //check if error returned
1172
-        if( empty( $modules ) || isset( $modules['errors']  ) ){
1172
+        if (empty($modules) || isset($modules['errors'])) {
1173 1173
             return false;
1174 1174
         }
1175 1175
 
1176 1176
        // get the last item in the array there should be only be 1 really.
1177 1177
        // this method works for all php versions.
1178
-       foreach( $modules as $module ){
1178
+       foreach ($modules as $module) {
1179 1179
            break;
1180 1180
        }
1181 1181
 
@@ -1188,7 +1188,7 @@  discard block
 block discarded – undo
1188 1188
         if (isset($course_id) && 0 < $course_id) {
1189 1189
 
1190 1190
             // the course should contain the same module taxonomy term for this to be valid
1191
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1191
+            if ( ! has_term($module, $this->taxonomy, $course_id)) {
1192 1192
                 return false;
1193 1193
             }
1194 1194
 
@@ -1262,8 +1262,8 @@  discard block
 block discarded – undo
1262 1262
     {
1263 1263
 
1264 1264
 
1265
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1266
-        wp_enqueue_style($this->taxonomy . '-frontend');
1265
+        wp_register_style($this->taxonomy.'-frontend', esc_url($this->assets_url).'css/modules-frontend.css', Sensei()->version);
1266
+        wp_enqueue_style($this->taxonomy.'-frontend');
1267 1267
     }
1268 1268
 
1269 1269
     /**
@@ -1273,37 +1273,37 @@  discard block
 block discarded – undo
1273 1273
      *
1274 1274
      * @return void
1275 1275
      */
1276
-    public function admin_enqueue_scripts( $hook ) {
1276
+    public function admin_enqueue_scripts($hook) {
1277 1277
 
1278 1278
         /**
1279 1279
          * Filter the page hooks where modules admin script can be loaded on.
1280 1280
          *
1281 1281
          * @param array $white_listed_pages
1282 1282
          */
1283
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1283
+        $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array(
1284 1284
             'edit-tags.php',
1285 1285
             'course_page_module-order',
1286 1286
             'post-new.php',
1287 1287
             'post.php'
1288
-        ) );
1288
+        ));
1289 1289
 
1290
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1290
+        if ( ! in_array($hook, $script_on_pages_white_list)) {
1291 1291
             return;
1292 1292
         }
1293 1293
 
1294
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1294
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1295 1295
 
1296
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1297
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1298
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true );
1296
+        wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1297
+        wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true);
1298
+        wp_enqueue_script($this->taxonomy.'-admin', esc_url($this->assets_url).'js/modules-admin'.$suffix.'.js', array('jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2'), Sensei()->version, true);
1299 1299
 
1300 1300
         // localized module data
1301 1301
         $localize_modulesAdmin = array(
1302
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1303
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1302
+            'search_courses_nonce' => wp_create_nonce('search-courses'),
1303
+            'selectPlaceholder'    => __('Search for courses', 'woothemes-sensei')
1304 1304
         );
1305 1305
 
1306
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1306
+        wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin);
1307 1307
     }
1308 1308
 
1309 1309
     /**
@@ -1316,8 +1316,8 @@  discard block
 block discarded – undo
1316 1316
     public function admin_enqueue_styles() {
1317 1317
 
1318 1318
 
1319
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1320
-        wp_enqueue_style($this->taxonomy . '-sortable');
1319
+        wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version);
1320
+        wp_enqueue_style($this->taxonomy.'-sortable');
1321 1321
 
1322 1322
     }
1323 1323
 
@@ -1331,9 +1331,9 @@  discard block
 block discarded – undo
1331 1331
      */
1332 1332
     public function course_modules_title( ) {
1333 1333
 
1334
-       if( sensei_module_has_lessons() ){
1334
+       if (sensei_module_has_lessons()) {
1335 1335
 
1336
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1336
+            echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>';
1337 1337
 
1338 1338
         }
1339 1339
 
@@ -1346,18 +1346,18 @@  discard block
 block discarded – undo
1346 1346
      * @since 1.8.0
1347 1347
      * @return void
1348 1348
      */
1349
-    public function load_course_module_content_template(){
1349
+    public function load_course_module_content_template() {
1350 1350
 
1351 1351
         // load backwards compatible template name if it exists in the users theme
1352
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1353
-        if( $located_template ){
1352
+        $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php');
1353
+        if ($located_template) {
1354 1354
 
1355
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1355
+            Sensei_Templates::get_template('single-course/course-modules.php');
1356 1356
             return;
1357 1357
 
1358 1358
         }
1359 1359
 
1360
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1360
+        Sensei_Templates::get_template('single-course/modules.php');
1361 1361
 
1362 1362
     } // end course_module_content
1363 1363
 
@@ -1370,15 +1370,15 @@  discard block
 block discarded – undo
1370 1370
      * @param $term_id
1371 1371
      * @return array $lessons
1372 1372
      */
1373
-    public function get_lessons( $course_id , $term_id ){
1373
+    public function get_lessons($course_id, $term_id) {
1374 1374
 
1375
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1375
+        $lesson_query = $this->get_lessons_query($course_id, $term_id);
1376 1376
 
1377
-        if( isset( $lesson_query->posts ) ){
1377
+        if (isset($lesson_query->posts)) {
1378 1378
 
1379 1379
             return $lesson_query->posts;
1380 1380
 
1381
-        }else{
1381
+        } else {
1382 1382
 
1383 1383
             return array();
1384 1384
 
@@ -1395,9 +1395,9 @@  discard block
 block discarded – undo
1395 1395
      * @param $term_id
1396 1396
      * @return WP_Query $lessons_query
1397 1397
      */
1398
-    public function get_lessons_query( $course_id , $term_id ){
1398
+    public function get_lessons_query($course_id, $term_id) {
1399 1399
 
1400
-        if( empty( $term_id ) || empty( $course_id ) ){
1400
+        if (empty($term_id) || empty($course_id)) {
1401 1401
 
1402 1402
             return array();
1403 1403
 
@@ -1418,7 +1418,7 @@  discard block
 block discarded – undo
1418 1418
                 array(
1419 1419
                     'taxonomy' => 'module',
1420 1420
                     'field' => 'id',
1421
-                    'terms' => intval( $term_id )
1421
+                    'terms' => intval($term_id)
1422 1422
                 )
1423 1423
             ),
1424 1424
             'orderby' => 'menu_order',
@@ -1426,12 +1426,12 @@  discard block
 block discarded – undo
1426 1426
             'suppress_filters' => 0
1427 1427
         );
1428 1428
 
1429
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1430
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1429
+        if (version_compare(Sensei()->version, '1.6.0', '>=')) {
1430
+            $args['meta_key'] = '_order_module_'.intval($term_id);
1431 1431
             $args['orderby'] = 'meta_value_num date';
1432 1432
         }
1433 1433
 
1434
-        $lessons_query = new WP_Query( $args );
1434
+        $lessons_query = new WP_Query($args);
1435 1435
 
1436 1436
         return $lessons_query;
1437 1437
 
@@ -1446,37 +1446,37 @@  discard block
 block discarded – undo
1446 1446
      *
1447 1447
      * @return array $non_module_lessons
1448 1448
      */
1449
-    public function get_none_module_lessons( $course_id ){
1449
+    public function get_none_module_lessons($course_id) {
1450 1450
 
1451 1451
         $non_module_lessons = array();
1452 1452
 
1453 1453
         //exit if there is no course id passed in
1454
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1454
+        if (empty($course_id) || 'course' != get_post_type($course_id)) {
1455 1455
 
1456 1456
             return $non_module_lessons;
1457 1457
         }
1458 1458
 
1459 1459
         //save some time and check if we already have the saved
1460
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1460
+        if (get_transient('sensei_'.$course_id.'_none_module_lessons')) {
1461 1461
 
1462
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1462
+            return get_transient('sensei_'.$course_id.'_none_module_lessons');
1463 1463
 
1464 1464
         }
1465 1465
 
1466 1466
         // create terms array which must be excluded from other arrays
1467
-        $course_modules = $this->get_course_modules( $course_id );
1467
+        $course_modules = $this->get_course_modules($course_id);
1468 1468
 
1469 1469
         //exit if there are no module on this course
1470
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1470
+        if (empty($course_modules) || ! is_array($course_modules)) {
1471 1471
 
1472
-            return  Sensei()->course->course_lessons( $course_id );
1472
+            return  Sensei()->course->course_lessons($course_id);
1473 1473
 
1474 1474
         }
1475 1475
 
1476 1476
         $terms = array();
1477
-        foreach( $course_modules as $module ){
1477
+        foreach ($course_modules as $module) {
1478 1478
 
1479
-            array_push( $terms ,  $module->term_id );
1479
+            array_push($terms, $module->term_id);
1480 1480
 
1481 1481
         }
1482 1482
 
@@ -1487,7 +1487,7 @@  discard block
 block discarded – undo
1487 1487
             'meta_query' => array(
1488 1488
                 array(
1489 1489
                     'key' => '_lesson_course',
1490
-                    'value' => intval( $course_id ),
1490
+                    'value' => intval($course_id),
1491 1491
                     'compare' => '='
1492 1492
                 )
1493 1493
             ),
@@ -1504,11 +1504,11 @@  discard block
 block discarded – undo
1504 1504
             'suppress_filters' => 0
1505 1505
         );
1506 1506
 
1507
-        $wp_lessons_query = new WP_Query( $args );
1507
+        $wp_lessons_query = new WP_Query($args);
1508 1508
 
1509
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1509
+        if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) {
1510 1510
             $non_module_lessons = $wp_lessons_query->get_posts();
1511
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1511
+            set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS);
1512 1512
         }
1513 1513
 
1514 1514
         return $non_module_lessons;
@@ -1519,7 +1519,7 @@  discard block
 block discarded – undo
1519 1519
      *
1520 1520
      * @since 1.8.0
1521 1521
      */
1522
-    public function setup_modules_taxonomy(){
1522
+    public function setup_modules_taxonomy() {
1523 1523
 
1524 1524
         $labels = array(
1525 1525
             'name' => __('Modules', 'woothemes-sensei'),
@@ -1556,11 +1556,11 @@  discard block
 block discarded – undo
1556 1556
             'show_in_nav_menus' => false,
1557 1557
             'show_in_quick_edit' => false,
1558 1558
             'show_ui' => true,
1559
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1559
+            'rewrite' => array('slug' => $modules_rewrite_slug),
1560 1560
             'labels' => $labels
1561 1561
         );
1562 1562
 
1563
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1563
+        register_taxonomy('module', array('course', 'lesson'), $args);
1564 1564
 
1565 1565
     }// end setup_modules_taxonomy
1566 1566
 
@@ -1572,12 +1572,12 @@  discard block
 block discarded – undo
1572 1572
      * @since 1.8.0
1573 1573
      * @return void
1574 1574
      */
1575
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1575
+    function redirect_to_lesson_module_taxonomy_to_course( ) {
1576 1576
 
1577
-        global $typenow , $taxnow;
1577
+        global $typenow, $taxnow;
1578 1578
 
1579
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1580
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1579
+        if ('lesson' == $typenow && 'module' == $taxnow) {
1580
+            wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course'));
1581 1581
         }
1582 1582
 
1583 1583
     }// end redirect to course taxonomy
@@ -1590,18 +1590,18 @@  discard block
 block discarded – undo
1590 1590
      * @since 1.8.0
1591 1591
      * @return void
1592 1592
      */
1593
-    public function remove_lessons_menu_model_taxonomy(){
1593
+    public function remove_lessons_menu_model_taxonomy() {
1594 1594
         global $submenu;
1595 1595
 
1596
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1596
+        if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) {
1597 1597
             return; // exit
1598 1598
         }
1599 1599
 
1600 1600
         $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1601
-        foreach( $lesson_main_menu as $index => $sub_item ){
1601
+        foreach ($lesson_main_menu as $index => $sub_item) {
1602 1602
 
1603
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1604
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1603
+            if ('edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2]) {
1604
+                unset($submenu['edit.php?post_type=lesson'][$index]);
1605 1605
             }
1606 1606
         }
1607 1607
 
@@ -1615,18 +1615,18 @@  discard block
 block discarded – undo
1615 1615
      * @since 1.8.0
1616 1616
      * @return void
1617 1617
      */
1618
-    public function remove_courses_menu_model_taxonomy(){
1618
+    public function remove_courses_menu_model_taxonomy() {
1619 1619
         global $submenu;
1620 1620
 
1621
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1621
+        if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) {
1622 1622
             return; // exit
1623 1623
         }
1624 1624
 
1625 1625
         $course_main_menu = $submenu['edit.php?post_type=course'];
1626
-        foreach( $course_main_menu as $index => $sub_item ){
1626
+        foreach ($course_main_menu as $index => $sub_item) {
1627 1627
 
1628
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1629
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1628
+            if ('edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2]) {
1629
+                unset($submenu['edit.php?post_type=course'][$index]);
1630 1630
             }
1631 1631
         }
1632 1632
 
@@ -1642,12 +1642,12 @@  discard block
 block discarded – undo
1642 1642
      * @param string $term_name
1643 1643
      * @return array $owners { type WP_User }. Empty array if none if found.
1644 1644
      */
1645
-    public static function get_term_authors( $term_name ){
1645
+    public static function get_term_authors($term_name) {
1646 1646
 
1647
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1647
+        $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false));
1648 1648
 
1649 1649
         $owners = array();
1650
-        if( empty( $terms ) ){
1650
+        if (empty($terms)) {
1651 1651
 
1652 1652
             return $owners;
1653 1653
 
@@ -1657,11 +1657,11 @@  discard block
 block discarded – undo
1657 1657
 
1658 1658
 
1659 1659
         //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1660
-        foreach( $terms as $term){
1661
-            if( $term->name == $term_name ){
1660
+        foreach ($terms as $term) {
1661
+            if ($term->name == $term_name) {
1662 1662
 
1663 1663
                 // look for the author in the slug
1664
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1664
+                $owners[] = Sensei_Core_Modules::get_term_author($term->slug);
1665 1665
 
1666 1666
             }// end if term name
1667 1667
 
@@ -1682,30 +1682,30 @@  discard block
 block discarded – undo
1682 1682
      * @param $slug
1683 1683
      * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1684 1684
      */
1685
-    public static function get_term_author( $slug='' ){
1685
+    public static function get_term_author($slug = '') {
1686 1686
 
1687
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1687
+        $term_owner = get_user_by('email', get_bloginfo('admin_email'));
1688 1688
 
1689
-        if( empty( $slug ) ){
1689
+        if (empty($slug)) {
1690 1690
 
1691 1691
             return $term_owner;
1692 1692
 
1693 1693
         }
1694 1694
 
1695 1695
         // look for the author in the slug
1696
-        $slug_parts = explode( '-', $slug );
1696
+        $slug_parts = explode('-', $slug);
1697 1697
 
1698
-        if( count( $slug_parts ) > 1 ){
1698
+        if (count($slug_parts) > 1) {
1699 1699
 
1700 1700
             // get the user data
1701 1701
             $possible_user_id = $slug_parts[0];
1702
-            $author = get_userdata( $possible_user_id );
1702
+            $author = get_userdata($possible_user_id);
1703 1703
 
1704 1704
             // if the user doesnt exist for the first part of the slug
1705 1705
             // then this slug was also created by admin
1706
-            if( is_a( $author, 'WP_User' ) ){
1706
+            if (is_a($author, 'WP_User')) {
1707 1707
 
1708
-                $term_owner =  $author;
1708
+                $term_owner = $author;
1709 1709
 
1710 1710
             }
1711 1711
         }
@@ -1722,48 +1722,48 @@  discard block
 block discarded – undo
1722 1722
      *
1723 1723
      * @param WP_Post $post Post object.
1724 1724
      */
1725
-    public function course_module_metabox( $post ) {
1725
+    public function course_module_metabox($post) {
1726 1726
 
1727 1727
         $tax_name = 'module';
1728
-        $taxonomy = get_taxonomy( 'module' );
1728
+        $taxonomy = get_taxonomy('module');
1729 1729
 
1730 1730
         ?>
1731 1731
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1732 1732
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1733 1733
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
1734
-                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li>
1734
+                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
1735 1735
             </ul>
1736 1736
 
1737 1737
             <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
1738 1738
                 <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
1739
-                    <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
1739
+                    <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?>
1740 1740
                 </ul>
1741 1741
             </div>
1742 1742
 
1743 1743
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1744 1744
                 <?php
1745
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1745
+                $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']';
1746 1746
                 echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1747 1747
                 ?>
1748 1748
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1749
-                    <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1749
+                    <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?>
1750 1750
                 </ul>
1751 1751
             </div>
1752
-            <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
1752
+            <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?>
1753 1753
                 <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
1754 1754
                     <h4>
1755 1755
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1756 1756
                             <?php
1757 1757
                             /* translators: %s: add new taxonomy label */
1758
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1758
+                            printf(__('+ %s'), $taxonomy->labels->add_new_item);
1759 1759
                             ?>
1760 1760
                         </a>
1761 1761
                     </h4>
1762 1762
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
1763 1763
                         <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
1764
-                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" aria-required="true"/>
1765
-                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr( $taxonomy->labels->add_new_item ); ?></a>
1766
-                        <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?>
1764
+                        <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" class="form-required form-input-tip" value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" aria-required="true"/>
1765
+                        <a class="button" id="sensei-<?php echo $tax_name; ?>-add-submit" class="button category-add-submit"><?php echo esc_attr($taxonomy->labels->add_new_item); ?></a>
1766
+                        <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?>
1767 1767
                         <span id="<?php echo $tax_name; ?>-ajax-response"></span>
1768 1768
                     </p>
1769 1769
                 </div>
@@ -1783,55 +1783,55 @@  discard block
 block discarded – undo
1783 1783
     public static function add_new_module_term( ) {
1784 1784
 
1785 1785
 
1786
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1787
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1786
+        if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) {
1787
+            wp_send_json_error(array('error'=> 'wrong security nonce'));
1788 1788
         }
1789 1789
 
1790 1790
         // get the term an create the new term storing infomration
1791
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1791
+        $term_name = sanitize_text_field($_POST['newTerm']);
1792 1792
 
1793
-        if( current_user_can('manage_options' ) ) {
1793
+        if (current_user_can('manage_options')) {
1794 1794
 
1795
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1795
+            $term_slug = str_ireplace(' ', '-', trim($term_name));
1796 1796
 
1797 1797
         } else {
1798 1798
 
1799
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1799
+            $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name));
1800 1800
 
1801 1801
         }
1802 1802
 
1803
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1803
+        $course_id = sanitize_text_field($_POST['course_id']);
1804 1804
 
1805 1805
         // save the term
1806
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1806
+        $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug));
1807 1807
 
1808 1808
         // send error for all errors except term exits
1809
-        if( is_wp_error( $slug ) ){
1809
+        if (is_wp_error($slug)) {
1810 1810
 
1811 1811
             // prepare for possible term name and id to be passed down if term exists
1812 1812
             $term_data = array();
1813 1813
 
1814 1814
             // if term exists also send back the term name and id
1815
-            if( isset( $slug->errors['term_exists'] ) ){
1815
+            if (isset($slug->errors['term_exists'])) {
1816 1816
 
1817
-                $term = get_term_by( 'slug', $term_slug, 'module');
1817
+                $term = get_term_by('slug', $term_slug, 'module');
1818 1818
                 $term_data['name'] = $term_name;
1819 1819
                 $term_data['id'] = $term->term_id;
1820 1820
 
1821 1821
                 // set the object terms
1822
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1822
+                wp_set_object_terms($course_id, $term->term_id, 'module', true);
1823 1823
             }
1824 1824
 
1825
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1825
+            wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data));
1826 1826
 
1827 1827
         }
1828 1828
 
1829 1829
         //make sure the new term is checked for this course
1830 1830
 
1831
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1831
+        wp_set_object_terms($course_id, $slug['term_id'], 'module', true);
1832 1832
 
1833 1833
         // Handle request then generate response using WP_Ajax_Response
1834
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1834
+        wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name));
1835 1835
 
1836 1836
     }
1837 1837
 
@@ -1843,26 +1843,26 @@  discard block
 block discarded – undo
1843 1843
      *
1844 1844
      * @since 1.8.0
1845 1845
      */
1846
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1846
+    public function filter_module_terms($terms, $taxonomies, $args) {
1847 1847
 
1848 1848
         //dont limit for admins and other taxonomies. This should also only apply to admin
1849
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1849
+        if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1850 1850
             return $terms;
1851 1851
         }
1852 1852
 
1853 1853
         // avoid infinite call loop
1854
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1854
+        remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1855 1855
 
1856 1856
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1857
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1857
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1858 1858
             // change only scrub the terms ids form the array keys
1859
-            $terms = array_keys( $terms );
1859
+            $terms = array_keys($terms);
1860 1860
         }
1861 1861
 
1862
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1862
+        $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id());
1863 1863
 
1864 1864
         // add filter again as removed above
1865
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1865
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1866 1866
 
1867 1867
         return $teachers_terms;
1868 1868
     }// end filter_module_terms
@@ -1875,25 +1875,25 @@  discard block
 block discarded – undo
1875 1875
      *
1876 1876
      * @since 1.8.0
1877 1877
      */
1878
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1878
+    public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) {
1879 1879
 
1880 1880
         //dont limit for admins and other taxonomies. This should also only apply to admin
1881
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1881
+        if (current_user_can('manage_options') || ! is_admin() || empty($terms)
1882 1882
             // only apply this to module only taxonomy queries so 1 taxonomy only:
1883
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1883
+            ||  count($taxonomies) > 1 || ! in_array('module', $taxonomies)) {
1884 1884
             return $terms;
1885 1885
         }
1886 1886
 
1887
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1887
+        $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id());
1888 1888
 
1889 1889
         // if term objects were passed in send back objects
1890 1890
         // if term id were passed in send that back
1891
-        if( is_object( $terms[0] ) ){
1891
+        if (is_object($terms[0])) {
1892 1892
             return $term_objects;
1893 1893
         }
1894 1894
 
1895 1895
         $terms = array();
1896
-        foreach( $term_objects as $term_object ){
1896
+        foreach ($term_objects as $term_object) {
1897 1897
             $terms[] = $term_object->term_id;
1898 1898
         }
1899 1899
 
@@ -1911,20 +1911,20 @@  discard block
 block discarded – undo
1911 1911
      * @param $user_id
1912 1912
      * @return array
1913 1913
      */
1914
-    public function filter_terms_by_owner( $terms, $user_id ){
1914
+    public function filter_terms_by_owner($terms, $user_id) {
1915 1915
 
1916 1916
         $users_terms = array();
1917 1917
 
1918
-        foreach( $terms as $index => $term ){
1918
+        foreach ($terms as $index => $term) {
1919 1919
 
1920
-            if( is_numeric( $term ) ){
1920
+            if (is_numeric($term)) {
1921 1921
                 // the term id was given, get the term object
1922
-                $term = get_term( $term, 'module' );
1922
+                $term = get_term($term, 'module');
1923 1923
             }
1924 1924
 
1925
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1925
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1926 1926
 
1927
-            if ( $user_id == $author->ID ) {
1927
+            if ($user_id == $author->ID) {
1928 1928
                 // add the term to the teachers terms
1929 1929
                 $users_terms[] = $term;
1930 1930
             }
@@ -1943,34 +1943,34 @@  discard block
 block discarded – undo
1943 1943
      *
1944 1944
      * @since 1.8.0
1945 1945
      */
1946
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1946
+    public function append_teacher_name_to_module($terms, $taxonomies, $args)
1947 1947
     {
1948 1948
 
1949 1949
         // only for admin users ont he module taxonomy
1950
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1950
+        if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1951 1951
             return $terms;
1952 1952
         }
1953 1953
 
1954 1954
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1955 1955
         // simply return this as wp doesn't need an array of stdObject Term
1956
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1956
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1957 1957
 
1958 1958
             return $terms;
1959 1959
 
1960 1960
         }
1961 1961
 
1962 1962
         // loop through and update all terms adding the author name
1963
-        foreach( $terms as $index => $term ){
1963
+        foreach ($terms as $index => $term) {
1964 1964
 
1965
-            if( is_numeric( $term ) ){
1965
+            if (is_numeric($term)) {
1966 1966
                 // the term id was given, get the term object
1967
-                $term = get_term( $term, 'module' );
1967
+                $term = get_term($term, 'module');
1968 1968
             }
1969 1969
 
1970
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1970
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1971 1971
 
1972
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1973
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1972
+            if ( ! user_can($author, 'manage_options') && isset($term->name)) {
1973
+                $term->name = $term->name.' ('.$author->display_name.') ';
1974 1974
             }
1975 1975
 
1976 1976
             // add the term to the teachers terms
@@ -1999,23 +1999,23 @@  discard block
 block discarded – undo
1999 1999
      * @sine 1.9.0
2000 2000
      * @param $post_id
2001 2001
      */
2002
-    public static function reset_none_modules_transient ( $post_id ){
2002
+    public static function reset_none_modules_transient($post_id) {
2003 2003
 
2004 2004
         // this should only apply to course and lesson post types
2005
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2005
+        if (in_array(get_post_type($post_id), array('course', 'lesson'))) {
2006 2006
 
2007 2007
             $course_id = '';
2008 2008
 
2009
-            if( 'lesson' == get_post_type( $post_id ) ){
2009
+            if ('lesson' == get_post_type($post_id)) {
2010 2010
 
2011
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2011
+                $course_id = Sensei()->lesson->get_course_id($post_id);
2012 2012
 
2013 2013
             }
2014 2014
 
2015 2015
 
2016
-            if( !empty( $course_id ) ){
2016
+            if ( ! empty($course_id)) {
2017 2017
 
2018
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2018
+                delete_transient('sensei_'.$course_id.'_none_module_lessons');
2019 2019
 
2020 2020
             }
2021 2021
 
@@ -2030,9 +2030,9 @@  discard block
 block discarded – undo
2030 2030
      * @deprecated since 1.9.0
2031 2031
      *
2032 2032
      */
2033
-    public static function deprecate_sensei_single_course_modules_content(){
2033
+    public static function deprecate_sensei_single_course_modules_content() {
2034 2034
 
2035
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2035
+        sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after');
2036 2036
 
2037 2037
     }
2038 2038
 
@@ -2043,12 +2043,12 @@  discard block
 block discarded – undo
2043 2043
      *
2044 2044
      * @since 1.9.0
2045 2045
      */
2046
-    public static function setup_single_course_module_loop(){
2046
+    public static function setup_single_course_module_loop() {
2047 2047
 
2048 2048
         global $sensei_modules_loop, $post;
2049 2049
         $course_id = $post->ID;
2050 2050
 
2051
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2051
+        $modules = Sensei()->modules->get_course_modules($course_id);
2052 2052
 
2053 2053
         //initial setup
2054 2054
         $sensei_modules_loop['total'] = 0;
@@ -2056,22 +2056,22 @@  discard block
 block discarded – undo
2056 2056
         $sensei_modules_loop['current'] = -1;
2057 2057
 
2058 2058
         // exit if this course doesn't have modules
2059
-        if( !$modules || empty( $modules )  ){
2059
+        if ( ! $modules || empty($modules)) {
2060 2060
             return;
2061 2061
         }
2062 2062
 
2063 2063
 
2064 2064
         $lessons_in_all_modules = array();
2065
-        foreach( $modules as $term ){
2065
+        foreach ($modules as $term) {
2066 2066
 
2067
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2068
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2067
+            $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id);
2068
+            $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module);
2069 2069
 
2070 2070
         }
2071 2071
 
2072 2072
 
2073 2073
         //setup all of the modules loop variables
2074
-        $sensei_modules_loop['total'] = count( $modules );
2074
+        $sensei_modules_loop['total'] = count($modules);
2075 2075
         $sensei_modules_loop['modules'] = $modules;
2076 2076
         $sensei_modules_loop['current'] = -1;
2077 2077
         $sensei_modules_loop['course_id'] = $course_id;
@@ -2084,7 +2084,7 @@  discard block
 block discarded – undo
2084 2084
      * @since 1.9.0
2085 2085
      *
2086 2086
      */
2087
-    public static function teardown_single_course_module_loop(){
2087
+    public static function teardown_single_course_module_loop() {
2088 2088
 
2089 2089
         global $sensei_modules_loop, $wp_query, $post;
2090 2090
 
Please login to merge, or discard this patch.
Indentation   +1880 added lines, -1880 removed lines patch added patch discarded remove patch
@@ -14,265 +14,265 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Sensei_Core_Modules
16 16
 {
17
-    private $dir;
18
-    private $file;
19
-    private $assets_dir;
20
-    private $assets_url;
21
-    private $order_page_slug;
22
-    public $taxonomy;
23
-
24
-    public function __construct( $file )
25
-    {
26
-        $this->file = $file;
27
-        $this->dir = dirname($this->file);
28
-        $this->assets_dir = trailingslashit($this->dir) . 'assets';
29
-        $this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
-        $this->taxonomy = 'module';
31
-        $this->order_page_slug = 'module-order';
32
-
33
-        // setup taxonomy
34
-        add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
-
36
-        // Manage lesson meta boxes for taxonomy
37
-        add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
-
39
-        // Save lesson meta box
40
-        add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
-
42
-        //Reset the none modules lessons transient
43
-        add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
-
45
-        // Frontend styling
46
-        add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
-
48
-        // Admin styling
49
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
-        add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
-
52
-        // Handle module completion record
53
-        add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
-        add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
-        add_action('wp', array($this, 'save_module_progress'), 10);
56
-
57
-        // Handle module ordering
58
-        add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
-        add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
-        add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
-
62
-        // Ensure modules always show under courses
63
-        add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
-        add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
-        add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
-
67
-        // Add course field to taxonomy
68
-        add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
-        add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
-        add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
-        add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
-        add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
-
74
-        // Manage module taxonomy archive page
75
-        add_filter('template_include', array($this, 'module_archive_template'), 10);
76
-        add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
-        add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
-        add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
-        add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
-        add_filter('body_class', array($this, 'module_archive_body_class'));
81
-
82
-        // add modules to the single course template
83
-        add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
-
85
-        //Single Course modules actions. Add to single-course/course-modules.php
86
-        add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
-
88
-        // Set up display on single lesson page
89
-        add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
-
91
-        // Add 'Modules' columns to Analysis tables
92
-        add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
-        add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
-        add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
-        add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
-
97
-        // Manage module taxonomy columns
98
-        add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
-        add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
-        add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
-
102
-        //store new modules created on the course edit screen
103
-        add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
-
105
-        // for non admin users, only show taxonomies that belong to them
106
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
-        add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
-
109
-        // add the teacher name next to the module term in for admin users
110
-        add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
-
112
-        // remove the default modules  metabox
113
-        add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
-
115
-    } // end constructor
116
-
117
-    /**
118
-     * Alter a module term slug when a new taxonomy term is created
119
-     * This will add the creators user name to the slug for uniqueness.
120
-     *
121
-     * @since 1.8.0
122
-     *
123
-     * @param $term_id
124
-     * @param $tt_id
125
-     * @param $taxonomy
126
-     *
127
-     * @return void
128
-     * @deprecated since 1.9.0
129
-     */
130
-    public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
-
132
-        _deprecated_function('change_module_term_slug', '1.9.0' );
133
-
134
-    }// end add_module_term_group
135
-
136
-    /**
137
-     * Hook in all meta boxes related tot he modules taxonomy
138
-     *
139
-     * @since 1.8.0
140
-     *
141
-     * @param string $post_type
142
-     * @param WP_Post $post
143
-     *
144
-     * @return void
145
-     */
146
-    public function modules_metaboxes( $post_type, $post )
147
-    {
148
-        if ('lesson' == $post_type ) {
149
-
150
-            // Remove default taxonomy meta box from Lesson edit screen
151
-            remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
-
153
-            // Add custom meta box to limit module selection to one per lesson
154
-            add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
-        }
156
-
157
-        if( 'course' == $post_type ){
158
-            // Course modules selection metabox
159
-            add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
-        }
161
-    }
162
-
163
-    /**
164
-     * Build content for custom module meta box
165
-     *
166
-     * @since 1.8.0
167
-     * @param  object $post Current post object
168
-     * @return void
169
-     */
170
-    public function lesson_module_metabox($post)
171
-    {
172
-
173
-        // Get lesson course
174
-        $lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
-
176
-        $html = '';
177
-
178
-        // Only show module selection if this lesson is part of a course
179
-        if ($lesson_course && $lesson_course > 0) {
180
-
181
-            // Get existing lesson module
182
-            $lesson_module = 0;
183
-            $lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
-                foreach ($lesson_module_list as $single_module) {
186
-                    $lesson_module = $single_module->term_id;
187
-                    break;
188
-                }
189
-            }
190
-
191
-            // Get the available modules for this lesson's course
192
-            $modules = $this->get_course_modules($lesson_course);
193
-
194
-            // Build the HTML to output
195
-            $html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
-            if (is_array($modules) && count($modules) > 0) {
197
-                $html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
-                $html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
-                foreach ($modules as $module) {
200
-                    $html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
-                }
202
-                $html .= '</select>' . "\n";
203
-            } else {
204
-                $course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
-                $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
-            } // End If Statement
207
-
208
-        } else {
209
-            $html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
-        } // End If Statement
211
-
212
-        // Output the HTML
213
-        echo $html;
214
-    }
215
-
216
-    /**
217
-     * Save module to lesson
218
-     *
219
-     * @since 1.8.0
220
-     * @param  integer $post_id ID of post
221
-     * @return mixed            Post ID on permissions failure, boolean true on success
222
-     */
223
-    public function save_lesson_module($post_id)
224
-    {
225
-        global $post;
226
-
227
-        // Verify post type and nonce
228
-        if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
-            ||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
-            return $post_id;
231
-        }
232
-
233
-        // Check if user has permissions to edit lessons
234
-        $post_type = get_post_type_object($post->post_type);
235
-        if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
-            return $post_id;
237
-        }
238
-
239
-        // Check if user has permissions to edit this specific post
240
-        if (!current_user_can('edit_post', $post_id)) {
241
-            return $post_id;
242
-        }
243
-
244
-        // Cast module ID as an integer if selected, otherwise leave as empty string
245
-        if ( isset( $_POST['lesson_module'] ) ) {
246
-
247
-            if( empty ( $_POST['lesson_module'] ) ){
248
-                wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
-                return true;
250
-            }
251
-
252
-            $module_id = intval( $_POST['lesson_module'] );
253
-
254
-            // Assign lesson to selected module
255
-            wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
-
257
-            // Set default order for lesson inside module
258
-            if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
-                update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
-            }
261
-        }
262
-
263
-        return true;
264
-    }
265
-
266
-    /**
267
-     * Display course field on new module screen
268
-     *
269
-     * @since 1.8.0
270
-     * @param object $taxonomy Taxonomy object
271
-     * @return void
272
-     */
273
-    public function add_module_fields($taxonomy)
274
-    {
275
-        ?>
17
+	private $dir;
18
+	private $file;
19
+	private $assets_dir;
20
+	private $assets_url;
21
+	private $order_page_slug;
22
+	public $taxonomy;
23
+
24
+	public function __construct( $file )
25
+	{
26
+		$this->file = $file;
27
+		$this->dir = dirname($this->file);
28
+		$this->assets_dir = trailingslashit($this->dir) . 'assets';
29
+		$this->assets_url = esc_url(trailingslashit(plugins_url('/assets/', $this->file)));
30
+		$this->taxonomy = 'module';
31
+		$this->order_page_slug = 'module-order';
32
+
33
+		// setup taxonomy
34
+		add_action( 'init', array( $this, 'setup_modules_taxonomy' ), 10 );
35
+
36
+		// Manage lesson meta boxes for taxonomy
37
+		add_action('add_meta_boxes', array($this, 'modules_metaboxes'), 20, 2 );
38
+
39
+		// Save lesson meta box
40
+		add_action('save_post', array($this, 'save_lesson_module'), 10, 1);
41
+
42
+		//Reset the none modules lessons transient
43
+		add_action( 'save_post', array( 'Sensei_Core_Modules', 'reset_none_modules_transient' ) );
44
+
45
+		// Frontend styling
46
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_styles'));
47
+
48
+		// Admin styling
49
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_styles'));
50
+		add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'),  20 , 2 );
51
+
52
+		// Handle module completion record
53
+		add_action('sensei_lesson_status_updated', array($this, 'update_lesson_status_module_progress'), 10, 3);
54
+		add_action('sensei_user_lesson_reset', array($this, 'save_lesson_module_progress'), 10, 2);
55
+		add_action('wp', array($this, 'save_module_progress'), 10);
56
+
57
+		// Handle module ordering
58
+		add_action('admin_menu', array($this, 'register_modules_admin_menu_items'), 30 );
59
+		add_filter('manage_edit-course_columns', array($this, 'course_columns'), 11, 1);
60
+		add_action('manage_posts_custom_column', array($this, 'course_column_content'), 11, 2);
61
+
62
+		// Ensure modules always show under courses
63
+		add_action( 'admin_menu', array( $this, 'remove_lessons_menu_model_taxonomy' ) , 10 );
64
+		add_action( 'admin_menu', array( $this, 'remove_courses_menu_model_taxonomy' ) , 10 );
65
+		add_action( 'admin_menu', array( $this, 'redirect_to_lesson_module_taxonomy_to_course' ) , 20 );
66
+
67
+		// Add course field to taxonomy
68
+		add_action($this->taxonomy . '_add_form_fields', array($this, 'add_module_fields'), 50, 1);
69
+		add_action($this->taxonomy . '_edit_form_fields', array($this, 'edit_module_fields'), 1, 1);
70
+		add_action('edited_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
71
+		add_action('created_' . $this->taxonomy, array($this, 'save_module_course'), 10, 2);
72
+		add_action('wp_ajax_sensei_json_search_courses', array($this, 'search_courses_json'));
73
+
74
+		// Manage module taxonomy archive page
75
+		add_filter('template_include', array($this, 'module_archive_template'), 10);
76
+		add_action('pre_get_posts', array($this, 'module_archive_filter'), 10, 1);
77
+		add_filter('sensei_lessons_archive_text', array($this, 'module_archive_title'));
78
+		add_action('sensei_content_lesson_inside_before', array($this, 'module_archive_description'), 11);
79
+		add_action('sensei_pagination', array($this, 'module_navigation_links'), 11);
80
+		add_filter('body_class', array($this, 'module_archive_body_class'));
81
+
82
+		// add modules to the single course template
83
+		add_action( 'sensei_single_course_content_inside_after', array($this, 'load_course_module_content_template') , 8 );
84
+
85
+		//Single Course modules actions. Add to single-course/course-modules.php
86
+		add_action('sensei_single_course_modules_before',array( $this,'course_modules_title' ), 20);
87
+
88
+		// Set up display on single lesson page
89
+		add_filter('sensei_breadcrumb_output', array($this, 'module_breadcrumb_link'), 10, 2);
90
+
91
+		// Add 'Modules' columns to Analysis tables
92
+		add_filter('sensei_analysis_overview_columns', array($this, 'analysis_overview_column_title'), 10, 2);
93
+		add_filter('sensei_analysis_overview_column_data', array($this, 'analysis_overview_column_data'), 10, 3);
94
+		add_filter('sensei_analysis_course_columns', array($this, 'analysis_course_column_title'), 10, 2);
95
+		add_filter('sensei_analysis_course_column_data', array($this, 'analysis_course_column_data'), 10, 3);
96
+
97
+		// Manage module taxonomy columns
98
+		add_filter('manage_edit-' . $this->taxonomy . '_columns', array($this, 'taxonomy_column_headings'), 1, 1);
99
+		add_filter('manage_' . $this->taxonomy . '_custom_column', array($this, 'taxonomy_column_content'), 1, 3);
100
+		add_filter('sensei_module_lesson_list_title', array($this, 'sensei_course_preview_titles'), 10, 2);
101
+
102
+		//store new modules created on the course edit screen
103
+		add_action( 'wp_ajax_sensei_add_new_module_term', array( 'Sensei_Core_Modules','add_new_module_term' ) );
104
+
105
+		// for non admin users, only show taxonomies that belong to them
106
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
107
+		add_filter('get_object_terms', array( $this, 'filter_course_selected_terms' ), 20, 3 );
108
+
109
+		// add the teacher name next to the module term in for admin users
110
+		add_filter('get_terms', array( $this, 'append_teacher_name_to_module' ), 70, 3 );
111
+
112
+		// remove the default modules  metabox
113
+		add_action('admin_init',array( 'Sensei_Core_Modules' , 'remove_default_modules_box' ));
114
+
115
+	} // end constructor
116
+
117
+	/**
118
+	 * Alter a module term slug when a new taxonomy term is created
119
+	 * This will add the creators user name to the slug for uniqueness.
120
+	 *
121
+	 * @since 1.8.0
122
+	 *
123
+	 * @param $term_id
124
+	 * @param $tt_id
125
+	 * @param $taxonomy
126
+	 *
127
+	 * @return void
128
+	 * @deprecated since 1.9.0
129
+	 */
130
+	public function change_module_term_slug( $term_id, $tt_id, $taxonomy ){
131
+
132
+		_deprecated_function('change_module_term_slug', '1.9.0' );
133
+
134
+	}// end add_module_term_group
135
+
136
+	/**
137
+	 * Hook in all meta boxes related tot he modules taxonomy
138
+	 *
139
+	 * @since 1.8.0
140
+	 *
141
+	 * @param string $post_type
142
+	 * @param WP_Post $post
143
+	 *
144
+	 * @return void
145
+	 */
146
+	public function modules_metaboxes( $post_type, $post )
147
+	{
148
+		if ('lesson' == $post_type ) {
149
+
150
+			// Remove default taxonomy meta box from Lesson edit screen
151
+			remove_meta_box($this->taxonomy . 'div', 'lesson', 'side');
152
+
153
+			// Add custom meta box to limit module selection to one per lesson
154
+			add_meta_box($this->taxonomy . '_select', __('Lesson Module', 'woothemes-sensei'), array($this, 'lesson_module_metabox'), 'lesson', 'side', 'default');
155
+		}
156
+
157
+		if( 'course' == $post_type ){
158
+			// Course modules selection metabox
159
+			add_meta_box( $this->taxonomy . '_course_mb', __('Course Modules', 'woothemes-sensei'), array( $this, 'course_module_metabox'), 'course', 'side', 'core');
160
+		}
161
+	}
162
+
163
+	/**
164
+	 * Build content for custom module meta box
165
+	 *
166
+	 * @since 1.8.0
167
+	 * @param  object $post Current post object
168
+	 * @return void
169
+	 */
170
+	public function lesson_module_metabox($post)
171
+	{
172
+
173
+		// Get lesson course
174
+		$lesson_course = get_post_meta($post->ID, '_lesson_course', true);
175
+
176
+		$html = '';
177
+
178
+		// Only show module selection if this lesson is part of a course
179
+		if ($lesson_course && $lesson_course > 0) {
180
+
181
+			// Get existing lesson module
182
+			$lesson_module = 0;
183
+			$lesson_module_list = wp_get_post_terms($post->ID, $this->taxonomy);
184
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
185
+				foreach ($lesson_module_list as $single_module) {
186
+					$lesson_module = $single_module->term_id;
187
+					break;
188
+				}
189
+			}
190
+
191
+			// Get the available modules for this lesson's course
192
+			$modules = $this->get_course_modules($lesson_course);
193
+
194
+			// Build the HTML to output
195
+			$html .= '<input type="hidden" name="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" id="' . esc_attr('woo_lesson_' . $this->taxonomy . '_nonce') . '" value="' . esc_attr(wp_create_nonce(plugin_basename($this->file))) . '" />';
196
+			if (is_array($modules) && count($modules) > 0) {
197
+				$html .= '<select id="lesson-module-options" name="lesson_module" class="widefat">' . "\n";
198
+				$html .= '<option value="">' . __('None', 'woothemes-sensei') . '</option>';
199
+				foreach ($modules as $module) {
200
+					$html .= '<option value="' . esc_attr(absint($module->term_id)) . '"' . selected($module->term_id, $lesson_module, false) . '>' . esc_html($module->name) . '</option>' . "\n";
201
+				}
202
+				$html .= '</select>' . "\n";
203
+			} else {
204
+				$course_url = admin_url('post.php?post=' . urlencode($lesson_course) . '&action=edit');
205
+				$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease add some to %3$sthe course%4$s.%2$s', 'woothemes-sensei'), '<em>', '</em>', '<a href="' . esc_url($course_url) . '">', '</a>') . '</p>';
206
+			} // End If Statement
207
+
208
+		} else {
209
+			$html .= '<p>' . sprintf(__('No modules are available for this lesson yet. %1$sPlease select a course first.%2$s', 'woothemes-sensei'), '<em>', '</em>') . '</p>';
210
+		} // End If Statement
211
+
212
+		// Output the HTML
213
+		echo $html;
214
+	}
215
+
216
+	/**
217
+	 * Save module to lesson
218
+	 *
219
+	 * @since 1.8.0
220
+	 * @param  integer $post_id ID of post
221
+	 * @return mixed            Post ID on permissions failure, boolean true on success
222
+	 */
223
+	public function save_lesson_module($post_id)
224
+	{
225
+		global $post;
226
+
227
+		// Verify post type and nonce
228
+		if ((get_post_type() != 'lesson') || !isset($_POST['woo_lesson_' . $this->taxonomy . '_nonce'] )
229
+			||!wp_verify_nonce($_POST['woo_lesson_' . $this->taxonomy . '_nonce'], plugin_basename($this->file))) {
230
+			return $post_id;
231
+		}
232
+
233
+		// Check if user has permissions to edit lessons
234
+		$post_type = get_post_type_object($post->post_type);
235
+		if (!current_user_can($post_type->cap->edit_post, $post_id)) {
236
+			return $post_id;
237
+		}
238
+
239
+		// Check if user has permissions to edit this specific post
240
+		if (!current_user_can('edit_post', $post_id)) {
241
+			return $post_id;
242
+		}
243
+
244
+		// Cast module ID as an integer if selected, otherwise leave as empty string
245
+		if ( isset( $_POST['lesson_module'] ) ) {
246
+
247
+			if( empty ( $_POST['lesson_module'] ) ){
248
+				wp_delete_object_term_relationships($post_id, $this->taxonomy  );
249
+				return true;
250
+			}
251
+
252
+			$module_id = intval( $_POST['lesson_module'] );
253
+
254
+			// Assign lesson to selected module
255
+			wp_set_object_terms($post_id, $module_id, $this->taxonomy, false);
256
+
257
+			// Set default order for lesson inside module
258
+			if (!get_post_meta($post_id, '_order_module_' . $module_id, true)) {
259
+				update_post_meta($post_id, '_order_module_' . $module_id, 0);
260
+			}
261
+		}
262
+
263
+		return true;
264
+	}
265
+
266
+	/**
267
+	 * Display course field on new module screen
268
+	 *
269
+	 * @since 1.8.0
270
+	 * @param object $taxonomy Taxonomy object
271
+	 * @return void
272
+	 */
273
+	public function add_module_fields($taxonomy)
274
+	{
275
+		?>
276 276
         <div class="form-field">
277 277
             <label for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label>
278 278
             <input type="hidden" id="module_courses" name="module_courses" class="ajax_chosen_select_courses"
@@ -281,44 +281,44 @@  discard block
 block discarded – undo
281 281
                 class="description"><?php _e('Search for and select the courses that this module will belong to.', 'woothemes-sensei'); ?></span>
282 282
         </div>
283 283
     <?php
284
-    }
285
-
286
-    /**
287
-     * Display course field on module edit screen
288
-     *
289
-     * @since 1.8.0
290
-     * @param  object $module Module term object
291
-     * @return void
292
-     */
293
-    public function edit_module_fields($module)
294
-    {
295
-
296
-        $module_id = $module->term_id;
297
-
298
-        // Get module's existing courses
299
-        $args = array(
300
-            'post_type' => 'course',
301
-            'post_status' => array('publish', 'draft', 'future', 'private'),
302
-            'posts_per_page' => -1,
303
-            'tax_query' => array(
304
-                array(
305
-                    'taxonomy' => $this->taxonomy,
306
-                    'field' => 'id',
307
-                    'terms' => $module_id
308
-                )
309
-            )
310
-        );
311
-        $courses = get_posts($args);
312
-
313
-        //build the defaults array
314
-        $module_courses = array();
315
-        if (isset($courses) && is_array($courses)) {
316
-            foreach ($courses as $course) {
317
-                $module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
-            }
319
-        }
320
-
321
-        ?>
284
+	}
285
+
286
+	/**
287
+	 * Display course field on module edit screen
288
+	 *
289
+	 * @since 1.8.0
290
+	 * @param  object $module Module term object
291
+	 * @return void
292
+	 */
293
+	public function edit_module_fields($module)
294
+	{
295
+
296
+		$module_id = $module->term_id;
297
+
298
+		// Get module's existing courses
299
+		$args = array(
300
+			'post_type' => 'course',
301
+			'post_status' => array('publish', 'draft', 'future', 'private'),
302
+			'posts_per_page' => -1,
303
+			'tax_query' => array(
304
+				array(
305
+					'taxonomy' => $this->taxonomy,
306
+					'field' => 'id',
307
+					'terms' => $module_id
308
+				)
309
+			)
310
+		);
311
+		$courses = get_posts($args);
312
+
313
+		//build the defaults array
314
+		$module_courses = array();
315
+		if (isset($courses) && is_array($courses)) {
316
+			foreach ($courses as $course) {
317
+				$module_courses[] =   array( 'id' =>$course->ID, 'details'=>$course->post_title );
318
+			}
319
+		}
320
+
321
+		?>
322 322
         <tr class="form-field">
323 323
             <th scope="row" valign="top"><label
324 324
                     for="module_courses"><?php _e('Course(s)', 'woothemes-sensei'); ?></label></th>
@@ -335,1397 +335,1397 @@  discard block
 block discarded – undo
335 335
             </td>
336 336
         </tr>
337 337
     <?php
338
-    }
339
-
340
-    /**
341
-     * Save module course on add/edit
342
-     *
343
-     * @since 1.8.0
344
-     * @param  integer $module_id ID of module
345
-     * @return void
346
-     */
347
-    public function save_module_course($module_id)
348
-    {
349
-
350
-        // Get module's existing courses
351
-        $args = array(
352
-            'post_type' => 'course',
353
-            'post_status' => array('publish', 'draft', 'future', 'private'),
354
-            'posts_per_page' => -1,
355
-            'tax_query' => array(
356
-                array(
357
-                    'taxonomy' => $this->taxonomy,
358
-                    'field' => 'id',
359
-                    'terms' => $module_id
360
-                )
361
-            )
362
-        );
363
-        $courses = get_posts($args);
364
-
365
-        // Remove module from existing courses
366
-        if (isset($courses) && is_array($courses)) {
367
-            foreach ($courses as $course) {
368
-                wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
-            }
370
-        }
371
-
372
-        // Add module to selected courses
373
-        if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
-
375
-            $course_ids = explode( ",", $_POST['module_courses'] );
376
-
377
-            foreach ( $course_ids as $course_id ) {
378
-
379
-                wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
-
381
-            }
382
-        }
383
-    }
384
-
385
-    /**
386
-     * Ajax function to search for courses matching term
387
-     *
388
-     * @since 1.8.0
389
-     * @return void
390
-     */
391
-    public function search_courses_json()
392
-    {
393
-
394
-        // Security check
395
-        check_ajax_referer('search-courses', 'security');
396
-
397
-        // Set content type
398
-        header('Content-Type: application/json; charset=utf-8');
399
-
400
-        // Get user input
401
-        $term = urldecode(stripslashes($_GET['term']));
402
-
403
-        // Return nothing if term is empty
404
-        if (empty($term))
405
-            die();
406
-
407
-        // Set a default if none is given
408
-        $default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
-
410
-        // Set up array of results
411
-        $found_courses = array('' => $default);
412
-
413
-        // Fetch results
414
-        $args = array(
415
-            'post_type' => 'course',
416
-            'post_status' => array('publish', 'draft', 'future', 'private'),
417
-            'posts_per_page' => -1,
418
-            'orderby' => 'title',
419
-            's' => $term
420
-        );
421
-        $courses = get_posts($args);
422
-
423
-        // Add results to array
424
-        if ($courses) {
425
-            foreach ($courses as $course) {
426
-                $found_courses[$course->ID] = $course->post_title;
427
-            }
428
-        }
429
-
430
-        // Encode and return results for processing & selection
431
-        echo json_encode($found_courses);
432
-        die();
433
-    }
434
-
435
-    /**
436
-     * display modules on single course pages
437
-     *
438
-     * @since 1.8.0
439
-     * @return void
440
-     */
441
-    public function single_course_modules(){
442
-
443
-        _deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
-        // only show modules on the course that has modules
445
-        if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
-
447
-            $this->load_course_module_content_template();
448
-
449
-        }
450
-
451
-    } // end single_course_modules
452
-
453
-    public function sensei_course_preview_titles($title, $lesson_id)
454
-    {
455
-        global $post, $current_user;
456
-
457
-        $course_id = $post->ID;
458
-        $title_text = '';
459
-
460
-        if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
-            $is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
-            if (!$is_user_taking_course) {
463
-                if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
-                    $title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
-                    // Remove brackets for display here
466
-                    $title_text = str_replace('(', '', $title_text);
467
-                    $title_text = str_replace(')', '', $title_text);
468
-                    $title_text = '<span class="preview-label">' . $title_text . '</span>';
469
-                }
470
-                $title .= ' ' . $title_text;
471
-            }
472
-        }
473
-
474
-        return $title;
475
-    }
476
-
477
-    public function module_breadcrumb_link($html, $separator)
478
-    {
479
-        global $post;
480
-        // Lesson
481
-        if (is_singular('lesson')) {
482
-            if (has_term('', $this->taxonomy, $post->ID)) {
483
-                $module = $this->get_lesson_module($post->ID);
484
-                if( $module ) {
485
-                    $html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
-                }
487
-            }
488
-        }
489
-        // Module
490
-        if (is_tax($this->taxonomy)) {
491
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
-                $course_id = intval($_GET['course_id']);
493
-                $html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
-            }
495
-        }
496
-        return $html;
497
-    }
498
-
499
-    /**
500
-     * Set lesson archive template to display on module taxonomy archive page
501
-     *
502
-     * @since 1.8.0
503
-     * @param  string $template Default template
504
-     * @return string           Modified template
505
-     */
506
-    public function module_archive_template($template) {
507
-
508
-        if ( ! is_tax($this->taxonomy) ) {
509
-            return $template;
510
-        }
511
-
512
-        $file = 'archive-lesson.php';
513
-        $find = array( $file, Sensei()->template_url . $file );
514
-
515
-        // locate the template file
516
-        $template = locate_template($find);
517
-        if (!$template) {
518
-
519
-            $template = Sensei()->plugin_path() . 'templates/' . $file;
520
-
521
-        }
522
-
523
-
524
-        return $template;
525
-    }
526
-
527
-    /**
528
-     * Modify module taxonomy archive query
529
-     *
530
-     * @since 1.8.0
531
-     * @param  object $query The query object passed by reference
532
-     * @return void
533
-     */
534
-    public function module_archive_filter($query)
535
-    {
536
-        if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
-
538
-
539
-            // Limit to lessons only
540
-            $query->set('post_type', 'lesson');
541
-
542
-            // Set order of lessons
543
-            if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
-                $module_id = $query->queried_object_id;
545
-                $query->set('meta_key', '_order_module_' . $module_id);
546
-                $query->set('orderby', 'meta_value_num date');
547
-            } else {
548
-                $query->set('orderby', 'menu_order');
549
-            }
550
-            $query->set('order', 'ASC');
551
-
552
-            // Limit to specific course if specified
553
-            if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
-                $course_id = intval($_GET['course_id']);
555
-                $meta_query[] = array(
556
-                    'key' => '_lesson_course',
557
-                    'value' => intval($course_id)
558
-                );
559
-                $query->set('meta_query', $meta_query);
560
-            }
561
-
562
-        }
563
-    }
564
-
565
-    /**
566
-     * Modify archive page title
567
-     *
568
-     * @since 1.8.0
569
-     * @param  string $title Default title
570
-     * @return string        Modified title
571
-     */
572
-    public function module_archive_title($title)
573
-    {
574
-        if (is_tax($this->taxonomy)) {
575
-            $title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
-        }
577
-        return $title;
578
-    }
579
-
580
-    /**
581
-     * Display module description on taxonomy archive page
582
-     *
583
-     * @since 1.8.0
584
-     * @return void
585
-     */
586
-    public function module_archive_description()
587
-    {
588
-        if (is_tax($this->taxonomy)) {
589
-
590
-            $module = get_queried_object();
591
-
592
-            $module_progress = false;
593
-            if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
-                global $current_user;
595
-                wp_get_current_user();
596
-                $module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
-            }
598
-
599
-            if ($module_progress && $module_progress > 0) {
600
-                $status = __('Completed', 'woothemes-sensei');
601
-                $class = 'completed';
602
-                if ($module_progress < 100) {
603
-                    $status = __('In progress', 'woothemes-sensei');
604
-                    $class = 'in-progress';
605
-                }
606
-                echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
-            }
608
-
609
-            echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
-        }
611
-    }
612
-
613
-    public function module_archive_body_class($classes)
614
-    {
615
-        if (is_tax($this->taxonomy)) {
616
-            $classes[] = 'module-archive';
617
-        }
618
-        return $classes;
619
-    }
620
-
621
-    /**
622
-     * Display module navigation links on module taxonomy archive page
623
-     *
624
-     * @since 1.8.0
625
-     * @return void
626
-     */
627
-    public function module_navigation_links()
628
-    {
629
-        if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
-
631
-            $queried_module = get_queried_object();
632
-            $course_modules = $this->get_course_modules($_GET['course_id']);
633
-
634
-            $prev_module = false;
635
-            $next_module = false;
636
-            $on_current = false;
637
-            foreach ($course_modules as $module) {
638
-                $this_module = $module;
639
-                if ($on_current) {
640
-                    $next_module = $this_module;
641
-                    break;
642
-                }
643
-                if ($this_module == $queried_module) {
644
-                    $on_current = true;
645
-                } else {
646
-                    $prev_module = $module;
647
-                }
648
-            }
649
-
650
-            ?>
338
+	}
339
+
340
+	/**
341
+	 * Save module course on add/edit
342
+	 *
343
+	 * @since 1.8.0
344
+	 * @param  integer $module_id ID of module
345
+	 * @return void
346
+	 */
347
+	public function save_module_course($module_id)
348
+	{
349
+
350
+		// Get module's existing courses
351
+		$args = array(
352
+			'post_type' => 'course',
353
+			'post_status' => array('publish', 'draft', 'future', 'private'),
354
+			'posts_per_page' => -1,
355
+			'tax_query' => array(
356
+				array(
357
+					'taxonomy' => $this->taxonomy,
358
+					'field' => 'id',
359
+					'terms' => $module_id
360
+				)
361
+			)
362
+		);
363
+		$courses = get_posts($args);
364
+
365
+		// Remove module from existing courses
366
+		if (isset($courses) && is_array($courses)) {
367
+			foreach ($courses as $course) {
368
+				wp_remove_object_terms($course->ID, $module_id, $this->taxonomy);
369
+			}
370
+		}
371
+
372
+		// Add module to selected courses
373
+		if ( isset( $_POST['module_courses'] ) && ! empty( $_POST['module_courses'] ) ) {
374
+
375
+			$course_ids = explode( ",", $_POST['module_courses'] );
376
+
377
+			foreach ( $course_ids as $course_id ) {
378
+
379
+				wp_set_object_terms($course_id, $module_id, $this->taxonomy, true);
380
+
381
+			}
382
+		}
383
+	}
384
+
385
+	/**
386
+	 * Ajax function to search for courses matching term
387
+	 *
388
+	 * @since 1.8.0
389
+	 * @return void
390
+	 */
391
+	public function search_courses_json()
392
+	{
393
+
394
+		// Security check
395
+		check_ajax_referer('search-courses', 'security');
396
+
397
+		// Set content type
398
+		header('Content-Type: application/json; charset=utf-8');
399
+
400
+		// Get user input
401
+		$term = urldecode(stripslashes($_GET['term']));
402
+
403
+		// Return nothing if term is empty
404
+		if (empty($term))
405
+			die();
406
+
407
+		// Set a default if none is given
408
+		$default = isset($_GET['default']) ? $_GET['default'] : __('No course', 'woothemes-sensei');
409
+
410
+		// Set up array of results
411
+		$found_courses = array('' => $default);
412
+
413
+		// Fetch results
414
+		$args = array(
415
+			'post_type' => 'course',
416
+			'post_status' => array('publish', 'draft', 'future', 'private'),
417
+			'posts_per_page' => -1,
418
+			'orderby' => 'title',
419
+			's' => $term
420
+		);
421
+		$courses = get_posts($args);
422
+
423
+		// Add results to array
424
+		if ($courses) {
425
+			foreach ($courses as $course) {
426
+				$found_courses[$course->ID] = $course->post_title;
427
+			}
428
+		}
429
+
430
+		// Encode and return results for processing & selection
431
+		echo json_encode($found_courses);
432
+		die();
433
+	}
434
+
435
+	/**
436
+	 * display modules on single course pages
437
+	 *
438
+	 * @since 1.8.0
439
+	 * @return void
440
+	 */
441
+	public function single_course_modules(){
442
+
443
+		_deprecated_function('Sensei_Modules->single_course_modules','Sensei 1.9.0', 'Sensei()->modules->load_course_module_content_template');
444
+		// only show modules on the course that has modules
445
+		if( is_singular( 'course' ) && has_term( '', 'module' )  )  {
446
+
447
+			$this->load_course_module_content_template();
448
+
449
+		}
450
+
451
+	} // end single_course_modules
452
+
453
+	public function sensei_course_preview_titles($title, $lesson_id)
454
+	{
455
+		global $post, $current_user;
456
+
457
+		$course_id = $post->ID;
458
+		$title_text = '';
459
+
460
+		if (method_exists('Sensei_Utils', 'is_preview_lesson') && Sensei_Utils::is_preview_lesson($lesson_id)) {
461
+			$is_user_taking_course = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course_id, 'user_id' => $current_user->ID, 'type' => 'sensei_course_status'));
462
+			if (!$is_user_taking_course) {
463
+				if (method_exists('WooThemes_Sensei_Frontend', 'sensei_lesson_preview_title_text')) {
464
+					$title_text = Sensei()->frontend->sensei_lesson_preview_title_text($course_id);
465
+					// Remove brackets for display here
466
+					$title_text = str_replace('(', '', $title_text);
467
+					$title_text = str_replace(')', '', $title_text);
468
+					$title_text = '<span class="preview-label">' . $title_text . '</span>';
469
+				}
470
+				$title .= ' ' . $title_text;
471
+			}
472
+		}
473
+
474
+		return $title;
475
+	}
476
+
477
+	public function module_breadcrumb_link($html, $separator)
478
+	{
479
+		global $post;
480
+		// Lesson
481
+		if (is_singular('lesson')) {
482
+			if (has_term('', $this->taxonomy, $post->ID)) {
483
+				$module = $this->get_lesson_module($post->ID);
484
+				if( $module ) {
485
+					$html .= ' ' . $separator . ' <a href="' . esc_url($module->url) . '" title="' .  __('Back to the module', 'woothemes-sensei') . '">' . $module->name . '</a>';
486
+				}
487
+			}
488
+		}
489
+		// Module
490
+		if (is_tax($this->taxonomy)) {
491
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
492
+				$course_id = intval($_GET['course_id']);
493
+				$html .= '<a href="' . esc_url(get_permalink($course_id)) . '" title="' .  __('Back to the course', 'woothemes-sensei') . '">' . get_the_title($course_id) . '</a>';
494
+			}
495
+		}
496
+		return $html;
497
+	}
498
+
499
+	/**
500
+	 * Set lesson archive template to display on module taxonomy archive page
501
+	 *
502
+	 * @since 1.8.0
503
+	 * @param  string $template Default template
504
+	 * @return string           Modified template
505
+	 */
506
+	public function module_archive_template($template) {
507
+
508
+		if ( ! is_tax($this->taxonomy) ) {
509
+			return $template;
510
+		}
511
+
512
+		$file = 'archive-lesson.php';
513
+		$find = array( $file, Sensei()->template_url . $file );
514
+
515
+		// locate the template file
516
+		$template = locate_template($find);
517
+		if (!$template) {
518
+
519
+			$template = Sensei()->plugin_path() . 'templates/' . $file;
520
+
521
+		}
522
+
523
+
524
+		return $template;
525
+	}
526
+
527
+	/**
528
+	 * Modify module taxonomy archive query
529
+	 *
530
+	 * @since 1.8.0
531
+	 * @param  object $query The query object passed by reference
532
+	 * @return void
533
+	 */
534
+	public function module_archive_filter($query)
535
+	{
536
+		if (is_tax($this->taxonomy) && $query->is_main_query()) {
537
+
538
+
539
+			// Limit to lessons only
540
+			$query->set('post_type', 'lesson');
541
+
542
+			// Set order of lessons
543
+			if (version_compare(Sensei()->version, '1.6.0', '>=')) {
544
+				$module_id = $query->queried_object_id;
545
+				$query->set('meta_key', '_order_module_' . $module_id);
546
+				$query->set('orderby', 'meta_value_num date');
547
+			} else {
548
+				$query->set('orderby', 'menu_order');
549
+			}
550
+			$query->set('order', 'ASC');
551
+
552
+			// Limit to specific course if specified
553
+			if (isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
554
+				$course_id = intval($_GET['course_id']);
555
+				$meta_query[] = array(
556
+					'key' => '_lesson_course',
557
+					'value' => intval($course_id)
558
+				);
559
+				$query->set('meta_query', $meta_query);
560
+			}
561
+
562
+		}
563
+	}
564
+
565
+	/**
566
+	 * Modify archive page title
567
+	 *
568
+	 * @since 1.8.0
569
+	 * @param  string $title Default title
570
+	 * @return string        Modified title
571
+	 */
572
+	public function module_archive_title($title)
573
+	{
574
+		if (is_tax($this->taxonomy)) {
575
+			$title = apply_filters('sensei_module_archive_title', get_queried_object()->name);
576
+		}
577
+		return $title;
578
+	}
579
+
580
+	/**
581
+	 * Display module description on taxonomy archive page
582
+	 *
583
+	 * @since 1.8.0
584
+	 * @return void
585
+	 */
586
+	public function module_archive_description()
587
+	{
588
+		if (is_tax($this->taxonomy)) {
589
+
590
+			$module = get_queried_object();
591
+
592
+			$module_progress = false;
593
+			if (is_user_logged_in() && isset($_GET['course_id']) && intval($_GET['course_id']) > 0) {
594
+				global $current_user;
595
+				wp_get_current_user();
596
+				$module_progress = $this->get_user_module_progress($module->term_id, $_GET['course_id'], $current_user->ID);
597
+			}
598
+
599
+			if ($module_progress && $module_progress > 0) {
600
+				$status = __('Completed', 'woothemes-sensei');
601
+				$class = 'completed';
602
+				if ($module_progress < 100) {
603
+					$status = __('In progress', 'woothemes-sensei');
604
+					$class = 'in-progress';
605
+				}
606
+				echo '<p class="status ' . esc_attr($class) . '">' . $status . '</p>';
607
+			}
608
+
609
+			echo '<p class="archive-description module-description">' . apply_filters('sensei_module_archive_description', nl2br($module->description), $module->term_id) . '</p>';
610
+		}
611
+	}
612
+
613
+	public function module_archive_body_class($classes)
614
+	{
615
+		if (is_tax($this->taxonomy)) {
616
+			$classes[] = 'module-archive';
617
+		}
618
+		return $classes;
619
+	}
620
+
621
+	/**
622
+	 * Display module navigation links on module taxonomy archive page
623
+	 *
624
+	 * @since 1.8.0
625
+	 * @return void
626
+	 */
627
+	public function module_navigation_links()
628
+	{
629
+		if (is_tax($this->taxonomy) && isset($_GET['course_id'])) {
630
+
631
+			$queried_module = get_queried_object();
632
+			$course_modules = $this->get_course_modules($_GET['course_id']);
633
+
634
+			$prev_module = false;
635
+			$next_module = false;
636
+			$on_current = false;
637
+			foreach ($course_modules as $module) {
638
+				$this_module = $module;
639
+				if ($on_current) {
640
+					$next_module = $this_module;
641
+					break;
642
+				}
643
+				if ($this_module == $queried_module) {
644
+					$on_current = true;
645
+				} else {
646
+					$prev_module = $module;
647
+				}
648
+			}
649
+
650
+			?>
651 651
             <div id="post-entries" class="post-entries module-navigation fix">
652 652
                 <?php if ($next_module) {
653
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
-                    ?>
653
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($next_module, $this->taxonomy));
654
+					?>
655 655
                     <div class="nav-next fr"><a href="<?php echo esc_url($module_link); ?>"
656 656
                                                 title="<?php esc_attr_e('Next module', 'woothemes-sensei'); ?>"><?php echo $next_module->name; ?>
657 657
                             <span class="meta-nav"></span></a></div>
658 658
                 <?php } ?>
659 659
                 <?php if ($prev_module) {
660
-                    $module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
-                    ?>
660
+					$module_link = add_query_arg('course_id', intval($_GET['course_id']), get_term_link($prev_module, $this->taxonomy));
661
+					?>
662 662
                     <div class="nav-prev fl"><a href="<?php echo esc_url($module_link); ?>"
663 663
                                                 title="<?php _e('Previous module', 'woothemes-sensei'); ?>"><span
664 664
                                 class="meta-nav"></span> <?php echo $prev_module->name; ?></a></div>
665 665
                 <?php } ?>
666 666
             </div>
667 667
         <?php
668
-        }
669
-    }
670
-
671
-    /**
672
-     * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
-     *
674
-     * @since 1.8.0
675
-     * @param  string $status Status of the lesson for the user
676
-     * @param  integer $user_id ID of user
677
-     * @param  integer $lesson_id ID of lesson
678
-     * @return void
679
-     */
680
-    public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
-    {
682
-        $this->save_lesson_module_progress($user_id, $lesson_id);
683
-    }
684
-
685
-    /**
686
-     * Save lesson's module progress for a specific user
687
-     *
688
-     * @since 1.8.0
689
-     * @param  integer $user_id ID of user
690
-     * @param  integer $lesson_id ID of lesson
691
-     * @return void
692
-     */
693
-    public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
-    {
695
-        $module = $this->get_lesson_module($lesson_id);
696
-        $course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
-        if ($module && $course_id) {
698
-            $this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
-        }
700
-    }
701
-
702
-    /**
703
-     * Save progress of module for user
704
-     *
705
-     * @since 1.8.0
706
-     * @return void
707
-     */
708
-    public function save_module_progress()
709
-    {
710
-        if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
-            global $current_user;
712
-            wp_get_current_user();
713
-            $user_id = $current_user->ID;
714
-
715
-            $module = get_queried_object();
716
-
717
-            $this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
-        }
719
-    }
720
-
721
-    /**
722
-     * Save module progess for user
723
-     *
724
-     * @since 1.8.0
725
-     *
726
-     * @param  integer $module_id ID of module
727
-     * @param  integer $course_id ID of course
728
-     * @param  integer $user_id ID of user
729
-     * @return void
730
-     */
731
-    public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
-    {
733
-        $module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
-        update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
-
736
-        do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
-    }
738
-
739
-    /**
740
-     * Get module progress for a user
741
-     *
742
-     * @since 1.8.0
743
-     *
744
-     * @param  integer $module_id ID of module
745
-     * @param  integer $course_id ID of course
746
-     * @param  integer $user_id ID of user
747
-     * @return mixed              Module progress percentage on success, false on failure
748
-     */
749
-    public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
-    {
751
-        $module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
-        if ($module_progress) {
753
-            return (float)$module_progress;
754
-        }
755
-        return false;
756
-    }
757
-
758
-    /**
759
-     * Calculate module progess for user
760
-     *
761
-     * @since 1.8.0
762
-     *
763
-     * @param  integer $user_id ID of user
764
-     * @param  integer $module_id ID of module
765
-     * @param  integer $course_id ID of course
766
-     * @return integer            Module progress percentage
767
-     */
768
-    public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
-    {
770
-
771
-        $args = array(
772
-            'post_type' => 'lesson',
773
-            'post_status' => 'publish',
774
-            'posts_per_page' => -1,
775
-            'tax_query' => array(
776
-                array(
777
-                    'taxonomy' => $this->taxonomy,
778
-                    'field' => 'id',
779
-                    'terms' => $module_id
780
-                )
781
-            ),
782
-            'meta_query' => array(
783
-                array(
784
-                    'key' => '_lesson_course',
785
-                    'value' => $course_id
786
-                )
787
-            ),
788
-            'fields' => 'ids'
789
-        );
790
-        $lessons = get_posts($args);
791
-
792
-        if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
-
794
-        $completed = false;
795
-        $lesson_count = 0;
796
-        $completed_count = 0;
797
-        foreach ($lessons as $lesson_id) {
798
-            $completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
-            ++$lesson_count;
800
-            if ($completed) {
801
-                ++$completed_count;
802
-            }
803
-        }
804
-        $module_progress = ($completed_count / $lesson_count) * 100;
805
-
806
-        return (float)$module_progress;
807
-    }
808
-
809
-    /**
810
-     * Register admin screen for ordering modules
811
-     *
812
-     * @since 1.8.0
813
-     *
814
-     * @return void
815
-     */
816
-    public function register_modules_admin_menu_items()
817
-    {
818
-        //add the modules link under the Course main menu
819
-        add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
-
821
-        // Regsiter new admin page for module ordering
822
-        $hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
-
824
-    }
825
-
826
-    /**
827
-     * Display Module Order screen
828
-     *
829
-     * @since 1.8.0
830
-     *
831
-     * @return void
832
-     */
833
-    public function module_order_screen()
834
-    {
835
-        ?>
668
+		}
669
+	}
670
+
671
+	/**
672
+	 * Trigger save_lesson_module_progress() when a lesson status is updated for a specific user
673
+	 *
674
+	 * @since 1.8.0
675
+	 * @param  string $status Status of the lesson for the user
676
+	 * @param  integer $user_id ID of user
677
+	 * @param  integer $lesson_id ID of lesson
678
+	 * @return void
679
+	 */
680
+	public function update_lesson_status_module_progress($status = '', $user_id = 0, $lesson_id = 0)
681
+	{
682
+		$this->save_lesson_module_progress($user_id, $lesson_id);
683
+	}
684
+
685
+	/**
686
+	 * Save lesson's module progress for a specific user
687
+	 *
688
+	 * @since 1.8.0
689
+	 * @param  integer $user_id ID of user
690
+	 * @param  integer $lesson_id ID of lesson
691
+	 * @return void
692
+	 */
693
+	public function save_lesson_module_progress($user_id = 0, $lesson_id = 0)
694
+	{
695
+		$module = $this->get_lesson_module($lesson_id);
696
+		$course_id = get_post_meta($lesson_id, '_lesson_course', true);
697
+		if ($module && $course_id) {
698
+			$this->save_user_module_progress(intval($module->term_id), intval($course_id), intval($user_id));
699
+		}
700
+	}
701
+
702
+	/**
703
+	 * Save progress of module for user
704
+	 *
705
+	 * @since 1.8.0
706
+	 * @return void
707
+	 */
708
+	public function save_module_progress()
709
+	{
710
+		if (is_tax($this->taxonomy) && is_user_logged_in() && isset($_GET['course_id']) && 0 < intval($_GET['course_id'])) {
711
+			global $current_user;
712
+			wp_get_current_user();
713
+			$user_id = $current_user->ID;
714
+
715
+			$module = get_queried_object();
716
+
717
+			$this->save_user_module_progress(intval($module->term_id), intval($_GET['course_id']), intval($user_id));
718
+		}
719
+	}
720
+
721
+	/**
722
+	 * Save module progess for user
723
+	 *
724
+	 * @since 1.8.0
725
+	 *
726
+	 * @param  integer $module_id ID of module
727
+	 * @param  integer $course_id ID of course
728
+	 * @param  integer $user_id ID of user
729
+	 * @return void
730
+	 */
731
+	public function save_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
732
+	{
733
+		$module_progress = $this->calculate_user_module_progress($user_id, $module_id, $course_id);
734
+		update_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), intval($module_progress));
735
+
736
+		do_action('sensei_module_save_user_progress', $course_id, $module_id, $user_id, $module_progress);
737
+	}
738
+
739
+	/**
740
+	 * Get module progress for a user
741
+	 *
742
+	 * @since 1.8.0
743
+	 *
744
+	 * @param  integer $module_id ID of module
745
+	 * @param  integer $course_id ID of course
746
+	 * @param  integer $user_id ID of user
747
+	 * @return mixed              Module progress percentage on success, false on failure
748
+	 */
749
+	public function get_user_module_progress($module_id = 0, $course_id = 0, $user_id = 0)
750
+	{
751
+		$module_progress = get_user_meta(intval($user_id), '_module_progress_' . intval($course_id) . '_' . intval($module_id), true);
752
+		if ($module_progress) {
753
+			return (float)$module_progress;
754
+		}
755
+		return false;
756
+	}
757
+
758
+	/**
759
+	 * Calculate module progess for user
760
+	 *
761
+	 * @since 1.8.0
762
+	 *
763
+	 * @param  integer $user_id ID of user
764
+	 * @param  integer $module_id ID of module
765
+	 * @param  integer $course_id ID of course
766
+	 * @return integer            Module progress percentage
767
+	 */
768
+	public function calculate_user_module_progress($user_id = 0, $module_id = 0, $course_id = 0)
769
+	{
770
+
771
+		$args = array(
772
+			'post_type' => 'lesson',
773
+			'post_status' => 'publish',
774
+			'posts_per_page' => -1,
775
+			'tax_query' => array(
776
+				array(
777
+					'taxonomy' => $this->taxonomy,
778
+					'field' => 'id',
779
+					'terms' => $module_id
780
+				)
781
+			),
782
+			'meta_query' => array(
783
+				array(
784
+					'key' => '_lesson_course',
785
+					'value' => $course_id
786
+				)
787
+			),
788
+			'fields' => 'ids'
789
+		);
790
+		$lessons = get_posts($args);
791
+
792
+		if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
793
+
794
+		$completed = false;
795
+		$lesson_count = 0;
796
+		$completed_count = 0;
797
+		foreach ($lessons as $lesson_id) {
798
+			$completed = Sensei_Utils::user_completed_lesson($lesson_id, $user_id);
799
+			++$lesson_count;
800
+			if ($completed) {
801
+				++$completed_count;
802
+			}
803
+		}
804
+		$module_progress = ($completed_count / $lesson_count) * 100;
805
+
806
+		return (float)$module_progress;
807
+	}
808
+
809
+	/**
810
+	 * Register admin screen for ordering modules
811
+	 *
812
+	 * @since 1.8.0
813
+	 *
814
+	 * @return void
815
+	 */
816
+	public function register_modules_admin_menu_items()
817
+	{
818
+		//add the modules link under the Course main menu
819
+		add_submenu_page('edit.php?post_type=course', __('Modules', 'woothemes-sensei'), __('Modules', 'woothemes-sensei'), 'manage_categories', 'edit-tags.php?taxonomy=module','' );
820
+
821
+		// Regsiter new admin page for module ordering
822
+		$hook = add_submenu_page('edit.php?post_type=course', __('Order Modules', 'woothemes-sensei'), __('Order Modules', 'woothemes-sensei'), 'edit_lessons', $this->order_page_slug, array($this, 'module_order_screen'));
823
+
824
+	}
825
+
826
+	/**
827
+	 * Display Module Order screen
828
+	 *
829
+	 * @since 1.8.0
830
+	 *
831
+	 * @return void
832
+	 */
833
+	public function module_order_screen()
834
+	{
835
+		?>
836 836
         <div id="<?php echo esc_attr($this->order_page_slug); ?>"
837 837
              class="wrap <?php echo esc_attr($this->order_page_slug); ?>">
838 838
         <h2><?php _e('Order Modules', 'woothemes-sensei'); ?></h2><?php
839 839
 
840
-        $html = '';
841
-
842
-        if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
-            $ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
-
845
-            if ($ordered) {
846
-                $html .= '<div class="updated fade">' . "\n";
847
-                $html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
-                $html .= '</div>' . "\n";
849
-            }
850
-        }
851
-
852
-        $courses = Sensei()->course->get_all_courses();
853
-
854
-        $html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
-        $html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
-        $html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
-        $html .= '<select id="module-order-course" name="course_id">' . "\n";
858
-        $html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
-
860
-        foreach ($courses as $course) {
861
-            if (has_term('', $this->taxonomy, $course->ID)) {
862
-                $course_id = '';
863
-                if (isset($_GET['course_id'])) {
864
-                    $course_id = intval($_GET['course_id']);
865
-                }
866
-                $html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
-            }
868
-        }
869
-
870
-        $html .= '</select>' . "\n";
871
-        $html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
-        $html .= '</form>' . "\n";
873
-
874
-        if (isset($_GET['course_id'])) {
875
-            $course_id = intval($_GET['course_id']);
876
-            if ($course_id > 0) {
877
-                $modules = $this->get_course_modules($course_id);
878
-                $modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
-                if ($modules) {
880
-
881
-                    $order = $this->get_course_module_order($course_id);
882
-
883
-                    $order_string='';
884
-                    if ($order) {
885
-                        $order_string = implode(',', $order);
886
-                    }
887
-
888
-                    $html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
-                    $html .= '<ul class="sortable-module-list">' . "\n";
890
-                    $count = 0;
891
-                    foreach ($modules as $module) {
892
-                        $count++;
893
-                        $class = $this->taxonomy;
894
-                        if ($count == 1) {
895
-                            $class .= ' first';
896
-                        }
897
-                        if ($count == count($module)) {
898
-                            $class .= ' last';
899
-                        }
900
-                        if ($count % 2 != 0) {
901
-                            $class .= ' alternate';
902
-                        }
903
-                        $html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
-                    }
905
-                    $html .= '</ul>' . "\n";
906
-
907
-                    $html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
-                    $html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
-                    $html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
-                    $html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
-                }
912
-            }
913
-        }
914
-
915
-        echo $html;
916
-
917
-        ?></div><?php
918
-    }
919
-
920
-    /**
921
-     * Add 'Module order' column to courses list table
922
-     *
923
-     * @since 1.8.0
924
-     *
925
-     * @param  array $columns Existing columns
926
-     * @return array           Modifed columns
927
-     */
928
-    public function course_columns($columns = array())
929
-    {
930
-        $columns['module_order'] = __('Module order', 'woothemes-sensei');
931
-        return $columns;
932
-    }
933
-
934
-    /**
935
-     * Load content in 'Module order' column
936
-     *
937
-     * @since 1.8.0
938
-     *
939
-     * @param  string $column Current column name
940
-     * @param  integer $course_id ID of course
941
-     * @return void
942
-     */
943
-    public function course_column_content($column = '', $course_id = 0)
944
-    {
945
-        if ($column == 'module_order') {
946
-            if (has_term('', $this->taxonomy, $course_id)) {
947
-                echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
-            }
949
-        }
950
-    }
951
-
952
-    /**
953
-     * Save module order for course
954
-     *
955
-     * @since 1.8.0
956
-     *
957
-     * @param  string $order_string Comma-separated string of module IDs
958
-     * @param  integer $course_id ID of course
959
-     * @return boolean                 True on success, false on failure
960
-     */
961
-    private function save_course_module_order($order_string = '', $course_id = 0)
962
-    {
963
-        if ($order_string && $course_id) {
964
-            $order = explode(',', $order_string);
965
-            update_post_meta(intval($course_id), '_module_order', $order);
966
-            return true;
967
-        }
968
-        return false;
969
-    }
970
-
971
-    /**
972
-     * Get module order for course
973
-     *
974
-     * @since 1.8.0
975
-     *
976
-     * @param  integer $course_id ID of course
977
-     * @return mixed              Module order on success, false if no module order has been saved
978
-     */
979
-    public function get_course_module_order($course_id = 0)
980
-    {
981
-        if ($course_id) {
982
-            $order = get_post_meta(intval($course_id), '_module_order', true);
983
-            return $order;
984
-        }
985
-        return false;
986
-    }
987
-
988
-    /**
989
-     * Modify module taxonomy columns
990
-     *
991
-     * @since 1.8.0
992
-     *
993
-     * @param  array $columns Default columns
994
-     * @return array          Modified columns
995
-     */
996
-    public function taxonomy_column_headings($columns)
997
-    {
998
-
999
-        unset($columns['posts']);
1000
-
1001
-        $columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
-
1003
-        return $columns;
1004
-    }
1005
-
1006
-    /**
1007
-     * Manage content in custom module taxonomy columns
1008
-     *
1009
-     * @since 1.8.0
1010
-     *
1011
-     * @param  string $column_data Default data for column
1012
-     * @param  string $column_name Name of current column
1013
-     * @param  integer $term_id ID of current term
1014
-     * @return string               Modified column data
1015
-     */
1016
-    public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
-    {
1018
-
1019
-        $args = array(
1020
-            'post_status' => 'publish',
1021
-            'posts_per_page' => -1,
1022
-            'tax_query' => array(
1023
-                array(
1024
-                    'taxonomy' => $this->taxonomy,
1025
-                    'field' => 'id',
1026
-                    'terms' => intval($term_id)
1027
-                )
1028
-            )
1029
-        );
1030
-
1031
-        $module = get_term($term_id, $this->taxonomy);
1032
-
1033
-        switch ($column_name) {
1034
-
1035
-            case 'lessons':
1036
-                $args['post_type'] = 'lesson';
1037
-                $lessons = get_posts($args);
1038
-                $total_lessons = count($lessons);
1039
-                $column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
-                break;
1041
-        }
1042
-
1043
-        return $column_data;
1044
-    }
1045
-
1046
-    /**
1047
-     * Add 'Module' columns to Analysis Lesson Overview table
1048
-     *
1049
-     * @since 1.8.0
1050
-     *
1051
-     * @param  array $columns Default columns
1052
-     * @return array          Modified columns
1053
-     */
1054
-    public function analysis_overview_column_title($columns)
1055
-    {
1056
-
1057
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
-            $new_columns = array();
1059
-            if (is_array($columns) && 0 < count($columns)) {
1060
-                foreach ($columns as $column => $title) {
1061
-                    $new_columns[$column] = $title;
1062
-                    if ($column == 'title') {
1063
-                        $new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
-                    }
1065
-                }
1066
-            }
1067
-
1068
-            if (0 < count($new_columns)) {
1069
-                return $new_columns;
1070
-            }
1071
-        }
1072
-
1073
-        return $columns;
1074
-    }
1075
-
1076
-    /**
1077
-     * Data for 'Module' column Analysis Lesson Overview table
1078
-     *
1079
-     * @since 1.8.0
1080
-     *
1081
-     * @param  array $columns Table column data
1082
-     * @param  WP_Post $lesson
1083
-     * @return array              Updated column data
1084
-     */
1085
-    public function analysis_overview_column_data($columns, $lesson )
1086
-    {
1087
-
1088
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
-            $lesson_module = '';
1090
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
-                foreach ($lesson_module_list as $single_module) {
1093
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
-                    break;
1095
-                }
1096
-            }
1097
-
1098
-            $columns['lesson_module'] = $lesson_module;
1099
-        }
1100
-
1101
-        return $columns;
1102
-    }
1103
-
1104
-    /**
1105
-     * Add 'Module' columns to Analysis Course table
1106
-     *
1107
-     * @since 1.8.0
1108
-     *
1109
-     * @param  array $columns Default columns
1110
-     * @return array          Modified columns
1111
-     */
1112
-    public function analysis_course_column_title($columns)
1113
-    {
1114
-        if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
-            $columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
-        }
1117
-        return $columns;
1118
-    }
1119
-
1120
-    /**
1121
-     * Data for 'Module' column in Analysis Course table
1122
-     *
1123
-     * @since 1.8.0
1124
-     *
1125
-     * @param  array $columns Table column data
1126
-     * @param  WP_Post $lesson
1127
-     * @return array              Updated columns data
1128
-     */
1129
-    public function analysis_course_column_data($columns, $lesson )
1130
-    {
1131
-
1132
-        if ( isset( $_GET['course_id'] ) ) {
1133
-            $lesson_module = '';
1134
-            $lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
-            if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
-                foreach ($lesson_module_list as $single_module) {
1137
-                    $lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
-                    break;
1139
-                }
1140
-            }
1141
-
1142
-            $columns['lesson_module'] = $lesson_module;
1143
-        }
1144
-
1145
-        return $columns;
1146
-    }
1147
-
1148
-    /**
1149
-     * Get module for lesson
1150
-     *
1151
-     * This function also checks if the module still
1152
-     * exists on the course before returning it. Although
1153
-     * the lesson has a module the same module must exist on the
1154
-     * course for it to be valid.
1155
-     *
1156
-     * @since 1.8.0
1157
-     *
1158
-     * @param  integer $lesson_id ID of lesson
1159
-     * @return object             Module taxonomy term object
1160
-     */
1161
-    public function get_lesson_module($lesson_id = 0)
1162
-    {
1163
-        $lesson_id = intval($lesson_id);
1164
-        if ( ! ( intval( $lesson_id > 0) ) ) {
1165
-            return false;
1166
-        }
1167
-
1168
-        // get taxonomy terms on this lesson
1169
-        $modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
-
1171
-        //check if error returned
1172
-        if( empty( $modules ) || isset( $modules['errors']  ) ){
1173
-            return false;
1174
-        }
1175
-
1176
-       // get the last item in the array there should be only be 1 really.
1177
-       // this method works for all php versions.
1178
-       foreach( $modules as $module ){
1179
-           break;
1180
-       }
1181
-
1182
-        if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1183
-            return false;
1184
-        }
1185
-
1186
-        $module->url = get_term_link($module, $this->taxonomy);
1187
-        $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1188
-        if (isset($course_id) && 0 < $course_id) {
1189
-
1190
-            // the course should contain the same module taxonomy term for this to be valid
1191
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1192
-                return false;
1193
-            }
1194
-
1195
-            $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1196
-        }
1197
-        return $module;
1198
-
1199
-    }
1200
-
1201
-    /**
1202
-     * Get ordered array of all modules in course
1203
-     *
1204
-     * @since 1.8.0
1205
-     *
1206
-     * @param  integer $course_id ID of course
1207
-     * @return array              Ordered array of module taxonomy term objects
1208
-     */
1209
-    public function get_course_modules($course_id = 0)
1210
-    {
1211
-        $course_id = intval($course_id);
1212
-        if (0 < $course_id) {
1213
-
1214
-            // Get modules for course
1215
-            $modules = wp_get_post_terms($course_id, $this->taxonomy);
1216
-
1217
-            // Get custom module order for course
1218
-            $order = $this->get_course_module_order($course_id);
1219
-
1220
-            // Sort by custom order if custom order exists
1221
-            if ($order) {
1222
-                $ordered_modules = array();
1223
-                $unordered_modules = array();
1224
-                foreach ($modules as $module) {
1225
-                    $order_key = array_search($module->term_id, $order);
1226
-                    if ($order_key !== false) {
1227
-                        $ordered_modules[$order_key] = $module;
1228
-                    } else {
1229
-                        $unordered_modules[] = $module;
1230
-                    }
1231
-                }
1232
-
1233
-                // Order modules correctly
1234
-                ksort($ordered_modules);
1235
-
1236
-                // Append modules that have not yet been ordered
1237
-                if (count($unordered_modules) > 0) {
1238
-                    $ordered_modules = array_merge($ordered_modules, $unordered_modules);
1239
-                }
1240
-
1241
-            } else {
1242
-
1243
-                $ordered_modules = $modules;
1244
-
1245
-            }
1246
-
1247
-            return $ordered_modules;
1248
-
1249
-        }
1250
-
1251
-        return false;
1252
-    }
1253
-
1254
-    /**
1255
-     * Load frontend CSS
1256
-     *
1257
-     * @since 1.8.0
1258
-     *
1259
-     * @return void
1260
-     */
1261
-    public function enqueue_styles() {
1262
-
1263
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1264
-        wp_enqueue_style($this->taxonomy . '-frontend');
1265
-
1266
-    }
1267
-
1268
-    /**
1269
-     * Load admin Javascript
1270
-     *
1271
-     * @since 1.8.0
1272
-     *
1273
-     * @return void
1274
-     */
1275
-    public function admin_enqueue_scripts( $hook ) {
1276
-
1277
-        /**
1278
-         * Filter the page hooks where modules admin script can be loaded on.
1279
-         *
1280
-         * @param array $white_listed_pages
1281
-         */
1282
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1283
-            'edit-tags.php',
1284
-            'course_page_module-order',
1285
-            'post-new.php',
1286
-            'post.php'
1287
-        ) );
1288
-
1289
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1290
-            return;
1291
-        }
1292
-
1293
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1294
-
1295
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1296
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1297
-        wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true );
1298
-
1299
-        // localized module data
1300
-        $localize_modulesAdmin = array(
1301
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1302
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1303
-        );
1304
-
1305
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1306
-    }
1307
-
1308
-    /**
1309
-     * Load admin CSS
1310
-     *
1311
-     * @since 1.8.0
1312
-     *
1313
-     * @return void
1314
-     */
1315
-    public function admin_enqueue_styles() {
1316
-
1317
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1318
-        wp_enqueue_style($this->taxonomy . '-sortable');
1319
-
1320
-    }
1321
-
1322
-    /**
1323
-     * Show the title modules on the single course template.
1324
-     *
1325
-     * Function is hooked into sensei_single_course_modules_before.
1326
-     *
1327
-     * @since 1.8.0
1328
-     * @return void
1329
-     */
1330
-    public function course_modules_title( ) {
1331
-
1332
-       if( sensei_module_has_lessons() ){
1333
-
1334
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1335
-
1336
-        }
1337
-
1338
-    }
1339
-
1340
-    /**
1341
-     * Display the single course modules content this will only show
1342
-     * if the course has modules.
1343
-     *
1344
-     * @since 1.8.0
1345
-     * @return void
1346
-     */
1347
-    public function load_course_module_content_template(){
1348
-
1349
-        // load backwards compatible template name if it exists in the users theme
1350
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1351
-        if( $located_template ){
1352
-
1353
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1354
-            return;
1355
-
1356
-        }
1357
-
1358
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1359
-
1360
-    } // end course_module_content
1361
-
1362
-    /**
1363
-     * Returns all lessons for the given module ID
1364
-     *
1365
-     * @since 1.8.0
1366
-     *
1367
-     * @param $course_id
1368
-     * @param $term_id
1369
-     * @return array $lessons
1370
-     */
1371
-    public function get_lessons( $course_id , $term_id ){
1372
-
1373
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1374
-
1375
-        if( isset( $lesson_query->posts ) ){
840
+		$html = '';
841
+
842
+		if (isset($_POST['module-order']) && 0 < strlen($_POST['module-order'])) {
843
+			$ordered = $this->save_course_module_order(esc_attr($_POST['module-order']), esc_attr($_POST['course_id']));
844
+
845
+			if ($ordered) {
846
+				$html .= '<div class="updated fade">' . "\n";
847
+				$html .= '<p>' . __('The module order has been saved for this course.', 'woothemes-sensei') . '</p>' . "\n";
848
+				$html .= '</div>' . "\n";
849
+			}
850
+		}
851
+
852
+		$courses = Sensei()->course->get_all_courses();
853
+
854
+		$html .= '<form action="' . admin_url('edit.php') . '" method="get">' . "\n";
855
+		$html .= '<input type="hidden" name="post_type" value="course" />' . "\n";
856
+		$html .= '<input type="hidden" name="page" value="' . esc_attr($this->order_page_slug) . '" />' . "\n";
857
+		$html .= '<select id="module-order-course" name="course_id">' . "\n";
858
+		$html .= '<option value="">' . __('Select a course', 'woothemes-sensei') . '</option>' . "\n";
859
+
860
+		foreach ($courses as $course) {
861
+			if (has_term('', $this->taxonomy, $course->ID)) {
862
+				$course_id = '';
863
+				if (isset($_GET['course_id'])) {
864
+					$course_id = intval($_GET['course_id']);
865
+				}
866
+				$html .= '<option value="' . esc_attr(intval($course->ID)) . '" ' . selected($course->ID, $course_id, false) . '>' . get_the_title($course->ID) . '</option>' . "\n";
867
+			}
868
+		}
869
+
870
+		$html .= '</select>' . "\n";
871
+		$html .= '<input type="submit" class="button-primary module-order-select-course-submit" value="' . __('Select', 'woothemes-sensei') . '" />' . "\n";
872
+		$html .= '</form>' . "\n";
873
+
874
+		if (isset($_GET['course_id'])) {
875
+			$course_id = intval($_GET['course_id']);
876
+			if ($course_id > 0) {
877
+				$modules = $this->get_course_modules($course_id);
878
+				$modules = $this->append_teacher_name_to_module( $modules, array( 'module' ), array() );
879
+				if ($modules) {
880
+
881
+					$order = $this->get_course_module_order($course_id);
882
+
883
+					$order_string='';
884
+					if ($order) {
885
+						$order_string = implode(',', $order);
886
+					}
887
+
888
+					$html .= '<form id="editgrouping" method="post" action="" class="validate">' . "\n";
889
+					$html .= '<ul class="sortable-module-list">' . "\n";
890
+					$count = 0;
891
+					foreach ($modules as $module) {
892
+						$count++;
893
+						$class = $this->taxonomy;
894
+						if ($count == 1) {
895
+							$class .= ' first';
896
+						}
897
+						if ($count == count($module)) {
898
+							$class .= ' last';
899
+						}
900
+						if ($count % 2 != 0) {
901
+							$class .= ' alternate';
902
+						}
903
+						$html .= '<li class="' . esc_attr($class) . '"><span rel="' . esc_attr($module->term_id) . '" style="width: 100%;"> ' . $module->name . '</span></li>' . "\n";
904
+					}
905
+					$html .= '</ul>' . "\n";
906
+
907
+					$html .= '<input type="hidden" name="module-order" value="' . $order_string . '" />' . "\n";
908
+					$html .= '<input type="hidden" name="course_id" value="' . $course_id . '" />' . "\n";
909
+					$html .= '<input type="submit" class="button-primary" value="' . __('Save module order', 'woothemes-sensei') . '" />' . "\n";
910
+					$html .= '<a href="' . admin_url('post.php?post=' . $course_id . '&action=edit') . '" class="button-secondary">' . __('Edit course', 'woothemes-sensei') . '</a>' . "\n";
911
+				}
912
+			}
913
+		}
914
+
915
+		echo $html;
916
+
917
+		?></div><?php
918
+	}
919
+
920
+	/**
921
+	 * Add 'Module order' column to courses list table
922
+	 *
923
+	 * @since 1.8.0
924
+	 *
925
+	 * @param  array $columns Existing columns
926
+	 * @return array           Modifed columns
927
+	 */
928
+	public function course_columns($columns = array())
929
+	{
930
+		$columns['module_order'] = __('Module order', 'woothemes-sensei');
931
+		return $columns;
932
+	}
933
+
934
+	/**
935
+	 * Load content in 'Module order' column
936
+	 *
937
+	 * @since 1.8.0
938
+	 *
939
+	 * @param  string $column Current column name
940
+	 * @param  integer $course_id ID of course
941
+	 * @return void
942
+	 */
943
+	public function course_column_content($column = '', $course_id = 0)
944
+	{
945
+		if ($column == 'module_order') {
946
+			if (has_term('', $this->taxonomy, $course_id)) {
947
+				echo '<a class="button-secondary" href="' . admin_url('edit.php?post_type=course&page=module-order&course_id=' . urlencode(intval($course_id))) . '">' . __('Order modules', 'woothemes-sensei') . '</a>';
948
+			}
949
+		}
950
+	}
951
+
952
+	/**
953
+	 * Save module order for course
954
+	 *
955
+	 * @since 1.8.0
956
+	 *
957
+	 * @param  string $order_string Comma-separated string of module IDs
958
+	 * @param  integer $course_id ID of course
959
+	 * @return boolean                 True on success, false on failure
960
+	 */
961
+	private function save_course_module_order($order_string = '', $course_id = 0)
962
+	{
963
+		if ($order_string && $course_id) {
964
+			$order = explode(',', $order_string);
965
+			update_post_meta(intval($course_id), '_module_order', $order);
966
+			return true;
967
+		}
968
+		return false;
969
+	}
970
+
971
+	/**
972
+	 * Get module order for course
973
+	 *
974
+	 * @since 1.8.0
975
+	 *
976
+	 * @param  integer $course_id ID of course
977
+	 * @return mixed              Module order on success, false if no module order has been saved
978
+	 */
979
+	public function get_course_module_order($course_id = 0)
980
+	{
981
+		if ($course_id) {
982
+			$order = get_post_meta(intval($course_id), '_module_order', true);
983
+			return $order;
984
+		}
985
+		return false;
986
+	}
987
+
988
+	/**
989
+	 * Modify module taxonomy columns
990
+	 *
991
+	 * @since 1.8.0
992
+	 *
993
+	 * @param  array $columns Default columns
994
+	 * @return array          Modified columns
995
+	 */
996
+	public function taxonomy_column_headings($columns)
997
+	{
998
+
999
+		unset($columns['posts']);
1000
+
1001
+		$columns['lessons'] = __('Lessons', 'woothemes-sensei');
1002
+
1003
+		return $columns;
1004
+	}
1005
+
1006
+	/**
1007
+	 * Manage content in custom module taxonomy columns
1008
+	 *
1009
+	 * @since 1.8.0
1010
+	 *
1011
+	 * @param  string $column_data Default data for column
1012
+	 * @param  string $column_name Name of current column
1013
+	 * @param  integer $term_id ID of current term
1014
+	 * @return string               Modified column data
1015
+	 */
1016
+	public function taxonomy_column_content($column_data, $column_name, $term_id)
1017
+	{
1018
+
1019
+		$args = array(
1020
+			'post_status' => 'publish',
1021
+			'posts_per_page' => -1,
1022
+			'tax_query' => array(
1023
+				array(
1024
+					'taxonomy' => $this->taxonomy,
1025
+					'field' => 'id',
1026
+					'terms' => intval($term_id)
1027
+				)
1028
+			)
1029
+		);
1030
+
1031
+		$module = get_term($term_id, $this->taxonomy);
1032
+
1033
+		switch ($column_name) {
1034
+
1035
+			case 'lessons':
1036
+				$args['post_type'] = 'lesson';
1037
+				$lessons = get_posts($args);
1038
+				$total_lessons = count($lessons);
1039
+				$column_data = '<a href="' . admin_url('edit.php?module=' . urlencode($module->slug) . '&post_type=lesson') . '">' . intval($total_lessons) . '</a>';
1040
+				break;
1041
+		}
1042
+
1043
+		return $column_data;
1044
+	}
1045
+
1046
+	/**
1047
+	 * Add 'Module' columns to Analysis Lesson Overview table
1048
+	 *
1049
+	 * @since 1.8.0
1050
+	 *
1051
+	 * @param  array $columns Default columns
1052
+	 * @return array          Modified columns
1053
+	 */
1054
+	public function analysis_overview_column_title($columns)
1055
+	{
1056
+
1057
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1058
+			$new_columns = array();
1059
+			if (is_array($columns) && 0 < count($columns)) {
1060
+				foreach ($columns as $column => $title) {
1061
+					$new_columns[$column] = $title;
1062
+					if ($column == 'title') {
1063
+						$new_columns['lesson_module'] = __('Module', 'woothemes-sensei');
1064
+					}
1065
+				}
1066
+			}
1067
+
1068
+			if (0 < count($new_columns)) {
1069
+				return $new_columns;
1070
+			}
1071
+		}
1072
+
1073
+		return $columns;
1074
+	}
1075
+
1076
+	/**
1077
+	 * Data for 'Module' column Analysis Lesson Overview table
1078
+	 *
1079
+	 * @since 1.8.0
1080
+	 *
1081
+	 * @param  array $columns Table column data
1082
+	 * @param  WP_Post $lesson
1083
+	 * @return array              Updated column data
1084
+	 */
1085
+	public function analysis_overview_column_data($columns, $lesson )
1086
+	{
1087
+
1088
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1089
+			$lesson_module = '';
1090
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1091
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1092
+				foreach ($lesson_module_list as $single_module) {
1093
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1094
+					break;
1095
+				}
1096
+			}
1097
+
1098
+			$columns['lesson_module'] = $lesson_module;
1099
+		}
1100
+
1101
+		return $columns;
1102
+	}
1103
+
1104
+	/**
1105
+	 * Add 'Module' columns to Analysis Course table
1106
+	 *
1107
+	 * @since 1.8.0
1108
+	 *
1109
+	 * @param  array $columns Default columns
1110
+	 * @return array          Modified columns
1111
+	 */
1112
+	public function analysis_course_column_title($columns)
1113
+	{
1114
+		if ( isset( $_GET['view'] ) && 'lessons' == $_GET['view'] ) {
1115
+			$columns['lesson_module'] = __('Module', 'woothemes-sensei');
1116
+		}
1117
+		return $columns;
1118
+	}
1119
+
1120
+	/**
1121
+	 * Data for 'Module' column in Analysis Course table
1122
+	 *
1123
+	 * @since 1.8.0
1124
+	 *
1125
+	 * @param  array $columns Table column data
1126
+	 * @param  WP_Post $lesson
1127
+	 * @return array              Updated columns data
1128
+	 */
1129
+	public function analysis_course_column_data($columns, $lesson )
1130
+	{
1131
+
1132
+		if ( isset( $_GET['course_id'] ) ) {
1133
+			$lesson_module = '';
1134
+			$lesson_module_list = wp_get_post_terms($lesson->ID, $this->taxonomy);
1135
+			if (is_array($lesson_module_list) && count($lesson_module_list) > 0) {
1136
+				foreach ($lesson_module_list as $single_module) {
1137
+					$lesson_module = '<a href="' . esc_url(admin_url('edit-tags.php?action=edit&taxonomy=' . urlencode($this->taxonomy) . '&tag_ID=' . urlencode($single_module->term_id))) . '">' . $single_module->name . '</a>';
1138
+					break;
1139
+				}
1140
+			}
1141
+
1142
+			$columns['lesson_module'] = $lesson_module;
1143
+		}
1144
+
1145
+		return $columns;
1146
+	}
1147
+
1148
+	/**
1149
+	 * Get module for lesson
1150
+	 *
1151
+	 * This function also checks if the module still
1152
+	 * exists on the course before returning it. Although
1153
+	 * the lesson has a module the same module must exist on the
1154
+	 * course for it to be valid.
1155
+	 *
1156
+	 * @since 1.8.0
1157
+	 *
1158
+	 * @param  integer $lesson_id ID of lesson
1159
+	 * @return object             Module taxonomy term object
1160
+	 */
1161
+	public function get_lesson_module($lesson_id = 0)
1162
+	{
1163
+		$lesson_id = intval($lesson_id);
1164
+		if ( ! ( intval( $lesson_id > 0) ) ) {
1165
+			return false;
1166
+		}
1167
+
1168
+		// get taxonomy terms on this lesson
1169
+		$modules = wp_get_post_terms($lesson_id, $this->taxonomy);
1170
+
1171
+		//check if error returned
1172
+		if( empty( $modules ) || isset( $modules['errors']  ) ){
1173
+			return false;
1174
+		}
1175
+
1176
+	   // get the last item in the array there should be only be 1 really.
1177
+	   // this method works for all php versions.
1178
+	   foreach( $modules as $module ){
1179
+		   break;
1180
+	   }
1181
+
1182
+		if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1183
+			return false;
1184
+		}
1185
+
1186
+		$module->url = get_term_link($module, $this->taxonomy);
1187
+		$course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1188
+		if (isset($course_id) && 0 < $course_id) {
1189
+
1190
+			// the course should contain the same module taxonomy term for this to be valid
1191
+			if( ! has_term( $module, $this->taxonomy, $course_id)){
1192
+				return false;
1193
+			}
1194
+
1195
+			$module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1196
+		}
1197
+		return $module;
1198
+
1199
+	}
1200
+
1201
+	/**
1202
+	 * Get ordered array of all modules in course
1203
+	 *
1204
+	 * @since 1.8.0
1205
+	 *
1206
+	 * @param  integer $course_id ID of course
1207
+	 * @return array              Ordered array of module taxonomy term objects
1208
+	 */
1209
+	public function get_course_modules($course_id = 0)
1210
+	{
1211
+		$course_id = intval($course_id);
1212
+		if (0 < $course_id) {
1213
+
1214
+			// Get modules for course
1215
+			$modules = wp_get_post_terms($course_id, $this->taxonomy);
1216
+
1217
+			// Get custom module order for course
1218
+			$order = $this->get_course_module_order($course_id);
1219
+
1220
+			// Sort by custom order if custom order exists
1221
+			if ($order) {
1222
+				$ordered_modules = array();
1223
+				$unordered_modules = array();
1224
+				foreach ($modules as $module) {
1225
+					$order_key = array_search($module->term_id, $order);
1226
+					if ($order_key !== false) {
1227
+						$ordered_modules[$order_key] = $module;
1228
+					} else {
1229
+						$unordered_modules[] = $module;
1230
+					}
1231
+				}
1232
+
1233
+				// Order modules correctly
1234
+				ksort($ordered_modules);
1235
+
1236
+				// Append modules that have not yet been ordered
1237
+				if (count($unordered_modules) > 0) {
1238
+					$ordered_modules = array_merge($ordered_modules, $unordered_modules);
1239
+				}
1240
+
1241
+			} else {
1242
+
1243
+				$ordered_modules = $modules;
1244
+
1245
+			}
1246
+
1247
+			return $ordered_modules;
1248
+
1249
+		}
1250
+
1251
+		return false;
1252
+	}
1253
+
1254
+	/**
1255
+	 * Load frontend CSS
1256
+	 *
1257
+	 * @since 1.8.0
1258
+	 *
1259
+	 * @return void
1260
+	 */
1261
+	public function enqueue_styles() {
1262
+
1263
+		wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1264
+		wp_enqueue_style($this->taxonomy . '-frontend');
1265
+
1266
+	}
1267
+
1268
+	/**
1269
+	 * Load admin Javascript
1270
+	 *
1271
+	 * @since 1.8.0
1272
+	 *
1273
+	 * @return void
1274
+	 */
1275
+	public function admin_enqueue_scripts( $hook ) {
1276
+
1277
+		/**
1278
+		 * Filter the page hooks where modules admin script can be loaded on.
1279
+		 *
1280
+		 * @param array $white_listed_pages
1281
+		 */
1282
+		$script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1283
+			'edit-tags.php',
1284
+			'course_page_module-order',
1285
+			'post-new.php',
1286
+			'post.php'
1287
+		) );
1288
+
1289
+		if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1290
+			return;
1291
+		}
1292
+
1293
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1294
+
1295
+		wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1296
+		wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1297
+		wp_enqueue_script( $this->taxonomy . '-admin', esc_url( $this->assets_url ) . 'js/modules-admin' . $suffix . '.js', array( 'jquery', 'sensei-chosen', 'sensei-chosen-ajax', 'jquery-ui-sortable', 'select2' ), Sensei()->version, true );
1298
+
1299
+		// localized module data
1300
+		$localize_modulesAdmin = array(
1301
+			'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1302
+			'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1303
+		);
1304
+
1305
+		wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1306
+	}
1307
+
1308
+	/**
1309
+	 * Load admin CSS
1310
+	 *
1311
+	 * @since 1.8.0
1312
+	 *
1313
+	 * @return void
1314
+	 */
1315
+	public function admin_enqueue_styles() {
1316
+
1317
+		wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1318
+		wp_enqueue_style($this->taxonomy . '-sortable');
1319
+
1320
+	}
1321
+
1322
+	/**
1323
+	 * Show the title modules on the single course template.
1324
+	 *
1325
+	 * Function is hooked into sensei_single_course_modules_before.
1326
+	 *
1327
+	 * @since 1.8.0
1328
+	 * @return void
1329
+	 */
1330
+	public function course_modules_title( ) {
1331
+
1332
+	   if( sensei_module_has_lessons() ){
1333
+
1334
+			echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1335
+
1336
+		}
1337
+
1338
+	}
1339
+
1340
+	/**
1341
+	 * Display the single course modules content this will only show
1342
+	 * if the course has modules.
1343
+	 *
1344
+	 * @since 1.8.0
1345
+	 * @return void
1346
+	 */
1347
+	public function load_course_module_content_template(){
1348
+
1349
+		// load backwards compatible template name if it exists in the users theme
1350
+		$located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1351
+		if( $located_template ){
1352
+
1353
+			Sensei_Templates::get_template( 'single-course/course-modules.php' );
1354
+			return;
1355
+
1356
+		}
1357
+
1358
+		Sensei_Templates::get_template( 'single-course/modules.php' );
1359
+
1360
+	} // end course_module_content
1361
+
1362
+	/**
1363
+	 * Returns all lessons for the given module ID
1364
+	 *
1365
+	 * @since 1.8.0
1366
+	 *
1367
+	 * @param $course_id
1368
+	 * @param $term_id
1369
+	 * @return array $lessons
1370
+	 */
1371
+	public function get_lessons( $course_id , $term_id ){
1372
+
1373
+		$lesson_query = $this->get_lessons_query( $course_id, $term_id );
1374
+
1375
+		if( isset( $lesson_query->posts ) ){
1376 1376
 
1377
-            return $lesson_query->posts;
1377
+			return $lesson_query->posts;
1378 1378
 
1379
-        }else{
1379
+		}else{
1380 1380
 
1381
-            return array();
1381
+			return array();
1382 1382
 
1383
-        }
1383
+		}
1384 1384
 
1385
-    } // end get lessons
1385
+	} // end get lessons
1386 1386
 
1387
-    /**
1388
-     * Returns all lessons for the given module ID
1389
-     *
1390
-     * @since 1.8.0
1391
-     *
1392
-     * @param $course_id
1393
-     * @param $term_id
1394
-     * @return WP_Query $lessons_query
1395
-     */
1396
-    public function get_lessons_query( $course_id , $term_id ){
1397
-
1398
-        if( empty( $term_id ) || empty( $course_id ) ){
1399
-
1400
-            return array();
1401
-
1402
-        }
1403
-
1404
-        $args = array(
1405
-            'post_type' => 'lesson',
1406
-            'post_status' => 'publish',
1407
-            'posts_per_page' => -1,
1408
-            'meta_query' => array(
1409
-                array(
1410
-                    'key' => '_lesson_course',
1411
-                    'value' => intval($course_id),
1412
-                    'compare' => '='
1413
-                )
1414
-            ),
1415
-            'tax_query' => array(
1416
-                array(
1417
-                    'taxonomy' => 'module',
1418
-                    'field' => 'id',
1419
-                    'terms' => intval( $term_id )
1420
-                )
1421
-            ),
1422
-            'orderby' => 'menu_order',
1423
-            'order' => 'ASC',
1424
-            'suppress_filters' => 0
1425
-        );
1426
-
1427
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1428
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1429
-            $args['orderby'] = 'meta_value_num date';
1430
-        }
1431
-
1432
-        $lessons_query = new WP_Query( $args );
1433
-
1434
-        return $lessons_query;
1435
-
1436
-    } // end get lessons
1437
-
1438
-    /**
1439
-     * Find the lesson in the given course that doesn't belong
1440
-     * to any of the courses modules
1441
-     *
1442
-     *
1443
-     * @param $course_id
1444
-     *
1445
-     * @return array $non_module_lessons
1446
-     */
1447
-    public function get_none_module_lessons( $course_id ){
1448
-
1449
-        $non_module_lessons = array();
1450
-
1451
-        //exit if there is no course id passed in
1452
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1453
-
1454
-            return $non_module_lessons;
1455
-        }
1456
-
1457
-        //save some time and check if we already have the saved
1458
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1459
-
1460
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1461
-
1462
-        }
1463
-
1464
-        // create terms array which must be excluded from other arrays
1465
-        $course_modules = $this->get_course_modules( $course_id );
1466
-
1467
-        //exit if there are no module on this course
1468
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1469
-
1470
-            return  Sensei()->course->course_lessons( $course_id );
1471
-
1472
-        }
1473
-
1474
-        $terms = array();
1475
-        foreach( $course_modules as $module ){
1476
-
1477
-            array_push( $terms ,  $module->term_id );
1478
-
1479
-        }
1480
-
1481
-        $args = array(
1482
-            'post_type' => 'lesson',
1483
-            'post_status' => 'publish',
1484
-            'posts_per_page' => -1,
1485
-            'meta_query' => array(
1486
-                array(
1487
-                    'key' => '_lesson_course',
1488
-                    'value' => intval( $course_id ),
1489
-                    'compare' => '='
1490
-                )
1491
-            ),
1492
-            'tax_query' => array(
1493
-                array(
1494
-                    'taxonomy' => 'module',
1495
-                    'field' => 'id',
1496
-                    'terms' =>  $terms,
1497
-                    'operator' => 'NOT IN'
1498
-                )
1499
-            ),
1500
-            'orderby' => 'menu_order',
1501
-            'order' => 'ASC',
1502
-            'suppress_filters' => 0
1503
-        );
1504
-
1505
-        $wp_lessons_query = new WP_Query( $args );
1506
-
1507
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1508
-            $non_module_lessons = $wp_lessons_query->get_posts();
1509
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1510
-        }
1511
-
1512
-        return $non_module_lessons;
1513
-    } // end get_none_module_lessons
1514
-
1515
-    /**
1516
-     * Register the modules taxonomy
1517
-     *
1518
-     * @since 1.8.0
1519
-     */
1520
-    public function setup_modules_taxonomy(){
1521
-
1522
-        $labels = array(
1523
-            'name' => __('Modules', 'woothemes-sensei'),
1524
-            'singular_name' => __('Module', 'woothemes-sensei'),
1525
-            'search_items' => __('Search Modules', 'woothemes-sensei'),
1526
-            'all_items' => __('All Modules', 'woothemes-sensei'),
1527
-            'parent_item' => __('Parent Module', 'woothemes-sensei'),
1528
-            'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1529
-            'edit_item' => __('Edit Module', 'woothemes-sensei'),
1530
-            'update_item' => __('Update Module', 'woothemes-sensei'),
1531
-            'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1532
-            'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1533
-            'menu_name' => __('Modules', 'woothemes-sensei'),
1534
-        );
1535
-
1536
-        /**
1537
-         * Filter to alter the Sensei Modules rewrite slug
1538
-         *
1539
-         * @since 1.8.0
1540
-         * @param string default 'modules'
1541
-         */
1542
-        $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1543
-
1544
-        $args = array(
1545
-            'public' => true,
1546
-            'hierarchical' => true,
1547
-            'show_admin_column' => true,
1548
-            'capabilities' => array(
1549
-                'manage_terms' => 'manage_categories',
1550
-                'edit_terms'   => 'edit_courses',
1551
-                'delete_terms' => 'manage_categories',
1552
-                'assign_terms' => 'edit_courses'
1553
-            ),
1554
-            'show_in_nav_menus' => false,
1555
-            'show_in_quick_edit' => false,
1556
-            'show_ui' => true,
1557
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1558
-            'labels' => $labels
1559
-        );
1560
-
1561
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1562
-
1563
-    }// end setup_modules_taxonomy
1564
-
1565
-    /**
1566
-     * When the wants to edit the lesson modules redirect them to the course modules.
1567
-     *
1568
-     * This function is hooked into the admin_menu
1569
-     *
1570
-     * @since 1.8.0
1571
-     * @return void
1572
-     */
1573
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1574
-
1575
-        global $typenow , $taxnow;
1576
-
1577
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1578
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1579
-        }
1580
-
1581
-    }// end redirect to course taxonomy
1582
-
1583
-    /**
1584
-     * Completely remove the module menu item under lessons.
1585
-     *
1586
-     * This function is hooked into the admin_menu
1587
-     *
1588
-     * @since 1.8.0
1589
-     * @return void
1590
-     */
1591
-    public function remove_lessons_menu_model_taxonomy(){
1592
-        global $submenu;
1593
-
1594
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1595
-            return; // exit
1596
-        }
1597
-
1598
-        $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1599
-        foreach( $lesson_main_menu as $index => $sub_item ){
1600
-
1601
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1602
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1603
-            }
1604
-        }
1605
-
1606
-    }// end remove lesson module tax
1607
-
1608
-    /**
1609
-     * Completely remove the second modules under courses
1610
-     *
1611
-     * This function is hooked into the admin_menu
1612
-     *
1613
-     * @since 1.8.0
1614
-     * @return void
1615
-     */
1616
-    public function remove_courses_menu_model_taxonomy(){
1617
-        global $submenu;
1618
-
1619
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1620
-            return; // exit
1621
-        }
1622
-
1623
-        $course_main_menu = $submenu['edit.php?post_type=course'];
1624
-        foreach( $course_main_menu as $index => $sub_item ){
1625
-
1626
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1627
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1628
-            }
1629
-        }
1630
-
1631
-    }// end remove courses module tax
1632
-
1633
-    /**
1634
-     * Determine the author of a module term term by looking at
1635
-     * the prefixed author id. This function will query the full term object.
1636
-     * Will return the admin user author could not be determined.
1637
-     *
1638
-     * @since 1.8.0
1639
-     *
1640
-     * @param string $term_name
1641
-     * @return array $owners { type WP_User }. Empty array if none if found.
1642
-     */
1643
-    public static function get_term_authors( $term_name ){
1644
-
1645
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1646
-
1647
-        $owners = array();
1648
-        if( empty( $terms ) ){
1649
-
1650
-            return $owners;
1387
+	/**
1388
+	 * Returns all lessons for the given module ID
1389
+	 *
1390
+	 * @since 1.8.0
1391
+	 *
1392
+	 * @param $course_id
1393
+	 * @param $term_id
1394
+	 * @return WP_Query $lessons_query
1395
+	 */
1396
+	public function get_lessons_query( $course_id , $term_id ){
1397
+
1398
+		if( empty( $term_id ) || empty( $course_id ) ){
1399
+
1400
+			return array();
1401
+
1402
+		}
1403
+
1404
+		$args = array(
1405
+			'post_type' => 'lesson',
1406
+			'post_status' => 'publish',
1407
+			'posts_per_page' => -1,
1408
+			'meta_query' => array(
1409
+				array(
1410
+					'key' => '_lesson_course',
1411
+					'value' => intval($course_id),
1412
+					'compare' => '='
1413
+				)
1414
+			),
1415
+			'tax_query' => array(
1416
+				array(
1417
+					'taxonomy' => 'module',
1418
+					'field' => 'id',
1419
+					'terms' => intval( $term_id )
1420
+				)
1421
+			),
1422
+			'orderby' => 'menu_order',
1423
+			'order' => 'ASC',
1424
+			'suppress_filters' => 0
1425
+		);
1426
+
1427
+		if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1428
+			$args['meta_key'] = '_order_module_' . intval( $term_id );
1429
+			$args['orderby'] = 'meta_value_num date';
1430
+		}
1431
+
1432
+		$lessons_query = new WP_Query( $args );
1433
+
1434
+		return $lessons_query;
1435
+
1436
+	} // end get lessons
1437
+
1438
+	/**
1439
+	 * Find the lesson in the given course that doesn't belong
1440
+	 * to any of the courses modules
1441
+	 *
1442
+	 *
1443
+	 * @param $course_id
1444
+	 *
1445
+	 * @return array $non_module_lessons
1446
+	 */
1447
+	public function get_none_module_lessons( $course_id ){
1448
+
1449
+		$non_module_lessons = array();
1450
+
1451
+		//exit if there is no course id passed in
1452
+		if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1453
+
1454
+			return $non_module_lessons;
1455
+		}
1456
+
1457
+		//save some time and check if we already have the saved
1458
+		if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1459
+
1460
+			return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1461
+
1462
+		}
1463
+
1464
+		// create terms array which must be excluded from other arrays
1465
+		$course_modules = $this->get_course_modules( $course_id );
1466
+
1467
+		//exit if there are no module on this course
1468
+		if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1469
+
1470
+			return  Sensei()->course->course_lessons( $course_id );
1471
+
1472
+		}
1473
+
1474
+		$terms = array();
1475
+		foreach( $course_modules as $module ){
1476
+
1477
+			array_push( $terms ,  $module->term_id );
1478
+
1479
+		}
1480
+
1481
+		$args = array(
1482
+			'post_type' => 'lesson',
1483
+			'post_status' => 'publish',
1484
+			'posts_per_page' => -1,
1485
+			'meta_query' => array(
1486
+				array(
1487
+					'key' => '_lesson_course',
1488
+					'value' => intval( $course_id ),
1489
+					'compare' => '='
1490
+				)
1491
+			),
1492
+			'tax_query' => array(
1493
+				array(
1494
+					'taxonomy' => 'module',
1495
+					'field' => 'id',
1496
+					'terms' =>  $terms,
1497
+					'operator' => 'NOT IN'
1498
+				)
1499
+			),
1500
+			'orderby' => 'menu_order',
1501
+			'order' => 'ASC',
1502
+			'suppress_filters' => 0
1503
+		);
1504
+
1505
+		$wp_lessons_query = new WP_Query( $args );
1506
+
1507
+		if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1508
+			$non_module_lessons = $wp_lessons_query->get_posts();
1509
+			set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1510
+		}
1511
+
1512
+		return $non_module_lessons;
1513
+	} // end get_none_module_lessons
1514
+
1515
+	/**
1516
+	 * Register the modules taxonomy
1517
+	 *
1518
+	 * @since 1.8.0
1519
+	 */
1520
+	public function setup_modules_taxonomy(){
1521
+
1522
+		$labels = array(
1523
+			'name' => __('Modules', 'woothemes-sensei'),
1524
+			'singular_name' => __('Module', 'woothemes-sensei'),
1525
+			'search_items' => __('Search Modules', 'woothemes-sensei'),
1526
+			'all_items' => __('All Modules', 'woothemes-sensei'),
1527
+			'parent_item' => __('Parent Module', 'woothemes-sensei'),
1528
+			'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1529
+			'edit_item' => __('Edit Module', 'woothemes-sensei'),
1530
+			'update_item' => __('Update Module', 'woothemes-sensei'),
1531
+			'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1532
+			'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1533
+			'menu_name' => __('Modules', 'woothemes-sensei'),
1534
+		);
1535
+
1536
+		/**
1537
+		 * Filter to alter the Sensei Modules rewrite slug
1538
+		 *
1539
+		 * @since 1.8.0
1540
+		 * @param string default 'modules'
1541
+		 */
1542
+		$modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1543
+
1544
+		$args = array(
1545
+			'public' => true,
1546
+			'hierarchical' => true,
1547
+			'show_admin_column' => true,
1548
+			'capabilities' => array(
1549
+				'manage_terms' => 'manage_categories',
1550
+				'edit_terms'   => 'edit_courses',
1551
+				'delete_terms' => 'manage_categories',
1552
+				'assign_terms' => 'edit_courses'
1553
+			),
1554
+			'show_in_nav_menus' => false,
1555
+			'show_in_quick_edit' => false,
1556
+			'show_ui' => true,
1557
+			'rewrite' => array('slug' => $modules_rewrite_slug ),
1558
+			'labels' => $labels
1559
+		);
1560
+
1561
+		register_taxonomy( 'module' , array('course', 'lesson'), $args);
1562
+
1563
+	}// end setup_modules_taxonomy
1564
+
1565
+	/**
1566
+	 * When the wants to edit the lesson modules redirect them to the course modules.
1567
+	 *
1568
+	 * This function is hooked into the admin_menu
1569
+	 *
1570
+	 * @since 1.8.0
1571
+	 * @return void
1572
+	 */
1573
+	function redirect_to_lesson_module_taxonomy_to_course( ){
1574
+
1575
+		global $typenow , $taxnow;
1576
+
1577
+		if( 'lesson'== $typenow && 'module'==$taxnow ){
1578
+			wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1579
+		}
1580
+
1581
+	}// end redirect to course taxonomy
1582
+
1583
+	/**
1584
+	 * Completely remove the module menu item under lessons.
1585
+	 *
1586
+	 * This function is hooked into the admin_menu
1587
+	 *
1588
+	 * @since 1.8.0
1589
+	 * @return void
1590
+	 */
1591
+	public function remove_lessons_menu_model_taxonomy(){
1592
+		global $submenu;
1593
+
1594
+		if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1595
+			return; // exit
1596
+		}
1597
+
1598
+		$lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1599
+		foreach( $lesson_main_menu as $index => $sub_item ){
1600
+
1601
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1602
+				unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1603
+			}
1604
+		}
1605
+
1606
+	}// end remove lesson module tax
1607
+
1608
+	/**
1609
+	 * Completely remove the second modules under courses
1610
+	 *
1611
+	 * This function is hooked into the admin_menu
1612
+	 *
1613
+	 * @since 1.8.0
1614
+	 * @return void
1615
+	 */
1616
+	public function remove_courses_menu_model_taxonomy(){
1617
+		global $submenu;
1618
+
1619
+		if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1620
+			return; // exit
1621
+		}
1622
+
1623
+		$course_main_menu = $submenu['edit.php?post_type=course'];
1624
+		foreach( $course_main_menu as $index => $sub_item ){
1625
+
1626
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1627
+				unset( $submenu['edit.php?post_type=course'][ $index ]);
1628
+			}
1629
+		}
1630
+
1631
+	}// end remove courses module tax
1632
+
1633
+	/**
1634
+	 * Determine the author of a module term term by looking at
1635
+	 * the prefixed author id. This function will query the full term object.
1636
+	 * Will return the admin user author could not be determined.
1637
+	 *
1638
+	 * @since 1.8.0
1639
+	 *
1640
+	 * @param string $term_name
1641
+	 * @return array $owners { type WP_User }. Empty array if none if found.
1642
+	 */
1643
+	public static function get_term_authors( $term_name ){
1644
+
1645
+		$terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1646
+
1647
+		$owners = array();
1648
+		if( empty( $terms ) ){
1649
+
1650
+			return $owners;
1651 1651
 
1652
-        }
1652
+		}
1653 1653
 
1654
-        // setup the admin user
1654
+		// setup the admin user
1655 1655
 
1656 1656
 
1657
-        //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1658
-        foreach( $terms as $term){
1659
-            if( $term->name == $term_name ){
1657
+		//if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1658
+		foreach( $terms as $term){
1659
+			if( $term->name == $term_name ){
1660 1660
 
1661
-                // look for the author in the slug
1662
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1661
+				// look for the author in the slug
1662
+				$owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1663 1663
 
1664
-            }// end if term name
1664
+			}// end if term name
1665 1665
 
1666
-        } // end for each
1666
+		} // end for each
1667 1667
 
1668
-        return $owners;
1668
+		return $owners;
1669 1669
 
1670
-    }// end get_term_author
1670
+	}// end get_term_author
1671 1671
 
1672
-    /**
1673
-     * Looks at a term slug and figures out
1674
-     * which author created the slug. The author was
1675
-     * appended when the user saved the module term in the course edit
1676
-     * screen.
1677
-     *
1678
-     * @since 1.8.0
1679
-     *
1680
-     * @param $slug
1681
-     * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1682
-     */
1683
-    public static function get_term_author( $slug='' ){
1672
+	/**
1673
+	 * Looks at a term slug and figures out
1674
+	 * which author created the slug. The author was
1675
+	 * appended when the user saved the module term in the course edit
1676
+	 * screen.
1677
+	 *
1678
+	 * @since 1.8.0
1679
+	 *
1680
+	 * @param $slug
1681
+	 * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1682
+	 */
1683
+	public static function get_term_author( $slug='' ){
1684 1684
 
1685
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1685
+		$term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1686 1686
 
1687
-        if( empty( $slug ) ){
1687
+		if( empty( $slug ) ){
1688 1688
 
1689
-            return $term_owner;
1689
+			return $term_owner;
1690 1690
 
1691
-        }
1691
+		}
1692 1692
 
1693
-        // look for the author in the slug
1694
-        $slug_parts = explode( '-', $slug );
1693
+		// look for the author in the slug
1694
+		$slug_parts = explode( '-', $slug );
1695 1695
 
1696
-        if( count( $slug_parts ) > 1 ){
1696
+		if( count( $slug_parts ) > 1 ){
1697 1697
 
1698
-            // get the user data
1699
-            $possible_user_id = $slug_parts[0];
1700
-            $author = get_userdata( $possible_user_id );
1698
+			// get the user data
1699
+			$possible_user_id = $slug_parts[0];
1700
+			$author = get_userdata( $possible_user_id );
1701 1701
 
1702
-            // if the user doesnt exist for the first part of the slug
1703
-            // then this slug was also created by admin
1704
-            if( is_a( $author, 'WP_User' ) ){
1702
+			// if the user doesnt exist for the first part of the slug
1703
+			// then this slug was also created by admin
1704
+			if( is_a( $author, 'WP_User' ) ){
1705 1705
 
1706
-                $term_owner =  $author;
1706
+				$term_owner =  $author;
1707 1707
 
1708
-            }
1709
-        }
1708
+			}
1709
+		}
1710 1710
 
1711
-        return $term_owner;
1712
-    }
1711
+		return $term_owner;
1712
+	}
1713 1713
 
1714
-    /**
1715
-     * Display the Sensei modules taxonomy terms metabox
1716
-     *
1717
-     * @since 1.8.0
1718
-     *
1719
-     * @hooked into add_meta_box
1720
-     *
1721
-     * @param WP_Post $post Post object.
1722
-     */
1723
-    public function course_module_metabox( $post ) {
1714
+	/**
1715
+	 * Display the Sensei modules taxonomy terms metabox
1716
+	 *
1717
+	 * @since 1.8.0
1718
+	 *
1719
+	 * @hooked into add_meta_box
1720
+	 *
1721
+	 * @param WP_Post $post Post object.
1722
+	 */
1723
+	public function course_module_metabox( $post ) {
1724 1724
 
1725
-        $tax_name = 'module';
1726
-        $taxonomy = get_taxonomy( 'module' );
1725
+		$tax_name = 'module';
1726
+		$taxonomy = get_taxonomy( 'module' );
1727 1727
 
1728
-        ?>
1728
+		?>
1729 1729
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1730 1730
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1731 1731
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
@@ -1740,9 +1740,9 @@  discard block
 block discarded – undo
1740 1740
 
1741 1741
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1742 1742
                 <?php
1743
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1744
-                echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1745
-                ?>
1743
+				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1744
+				echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks.
1745
+				?>
1746 1746
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1747 1747
                     <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1748 1748
                 </ul>
@@ -1752,9 +1752,9 @@  discard block
 block discarded – undo
1752 1752
                     <h4>
1753 1753
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1754 1754
                             <?php
1755
-                            /* translators: %s: add new taxonomy label */
1756
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1757
-                            ?>
1755
+							/* translators: %s: add new taxonomy label */
1756
+							printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1757
+							?>
1758 1758
                         </a>
1759 1759
                     </h4>
1760 1760
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -1769,331 +1769,331 @@  discard block
 block discarded – undo
1769 1769
         </div>
1770 1770
     <?php
1771 1771
 
1772
-    } // end course_module_metabox
1772
+	} // end course_module_metabox
1773 1773
 
1774 1774
 
1775
-    /**
1776
-     * Submits a new module term prefixed with the
1777
-     * the current author id.
1778
-     *
1779
-     * @since 1.8.0
1780
-     */
1781
-    public static function add_new_module_term( ) {
1775
+	/**
1776
+	 * Submits a new module term prefixed with the
1777
+	 * the current author id.
1778
+	 *
1779
+	 * @since 1.8.0
1780
+	 */
1781
+	public static function add_new_module_term( ) {
1782 1782
 
1783 1783
 
1784
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1785
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1786
-        }
1784
+		if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1785
+			wp_send_json_error( array('error'=> 'wrong security nonce') );
1786
+		}
1787 1787
 
1788
-        // get the term an create the new term storing infomration
1789
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1788
+		// get the term an create the new term storing infomration
1789
+		$term_name = sanitize_text_field( $_POST['newTerm'] );
1790 1790
 
1791
-        if( current_user_can('manage_options' ) ) {
1791
+		if( current_user_can('manage_options' ) ) {
1792 1792
 
1793
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1793
+			$term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1794 1794
 
1795
-        } else {
1795
+		} else {
1796 1796
 
1797
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1797
+			$term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1798 1798
 
1799
-        }
1799
+		}
1800 1800
 
1801
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1801
+		$course_id = sanitize_text_field( $_POST['course_id'] );
1802 1802
 
1803
-        // save the term
1804
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1803
+		// save the term
1804
+		$slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1805 1805
 
1806
-        // send error for all errors except term exits
1807
-        if( is_wp_error( $slug ) ){
1806
+		// send error for all errors except term exits
1807
+		if( is_wp_error( $slug ) ){
1808 1808
 
1809
-            // prepare for possible term name and id to be passed down if term exists
1810
-            $term_data = array();
1809
+			// prepare for possible term name and id to be passed down if term exists
1810
+			$term_data = array();
1811 1811
 
1812
-            // if term exists also send back the term name and id
1813
-            if( isset( $slug->errors['term_exists'] ) ){
1812
+			// if term exists also send back the term name and id
1813
+			if( isset( $slug->errors['term_exists'] ) ){
1814 1814
 
1815
-                $term = get_term_by( 'slug', $term_slug, 'module');
1816
-                $term_data['name'] = $term_name;
1817
-                $term_data['id'] = $term->term_id;
1815
+				$term = get_term_by( 'slug', $term_slug, 'module');
1816
+				$term_data['name'] = $term_name;
1817
+				$term_data['id'] = $term->term_id;
1818 1818
 
1819
-                // set the object terms
1820
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1821
-            }
1819
+				// set the object terms
1820
+				wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1821
+			}
1822 1822
 
1823
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1823
+			wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1824 1824
 
1825
-        }
1825
+		}
1826 1826
 
1827
-        //make sure the new term is checked for this course
1827
+		//make sure the new term is checked for this course
1828 1828
 
1829
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1829
+		wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1830 1830
 
1831
-        // Handle request then generate response using WP_Ajax_Response
1832
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1831
+		// Handle request then generate response using WP_Ajax_Response
1832
+		wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1833 1833
 
1834
-    }
1834
+	}
1835 1835
 
1836
-    /**
1837
-     * Limit the course module metabox
1838
-     * term list to only those on courses belonging to current teacher.
1839
-     *
1840
-     * Hooked into 'get_terms'
1841
-     *
1842
-     * @since 1.8.0
1843
-     */
1844
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1836
+	/**
1837
+	 * Limit the course module metabox
1838
+	 * term list to only those on courses belonging to current teacher.
1839
+	 *
1840
+	 * Hooked into 'get_terms'
1841
+	 *
1842
+	 * @since 1.8.0
1843
+	 */
1844
+	public function filter_module_terms( $terms, $taxonomies, $args ){
1845 1845
 
1846
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1847
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1848
-            return $terms;
1849
-        }
1846
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1847
+		if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1848
+			return $terms;
1849
+		}
1850 1850
 
1851
-        // avoid infinite call loop
1852
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1851
+		// avoid infinite call loop
1852
+		remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1853 1853
 
1854
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1855
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1856
-            // change only scrub the terms ids form the array keys
1857
-            $terms = array_keys( $terms );
1858
-        }
1854
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1855
+		if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1856
+			// change only scrub the terms ids form the array keys
1857
+			$terms = array_keys( $terms );
1858
+		}
1859 1859
 
1860
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1860
+		$teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1861 1861
 
1862
-        // add filter again as removed above
1863
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1862
+		// add filter again as removed above
1863
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1864 1864
 
1865
-        return $teachers_terms;
1866
-    }// end filter_module_terms
1865
+		return $teachers_terms;
1866
+	}// end filter_module_terms
1867 1867
 
1868
-    /**
1869
-     * For the selected items on a course module only return those
1870
-     * for the current user. This does not apply to admin and super admin users.
1871
-     *
1872
-     * hooked into get_object_terms
1873
-     *
1874
-     * @since 1.8.0
1875
-     */
1876
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1868
+	/**
1869
+	 * For the selected items on a course module only return those
1870
+	 * for the current user. This does not apply to admin and super admin users.
1871
+	 *
1872
+	 * hooked into get_object_terms
1873
+	 *
1874
+	 * @since 1.8.0
1875
+	 */
1876
+	public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1877 1877
 
1878
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1879
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1880
-            // only apply this to module only taxonomy queries so 1 taxonomy only:
1881
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1882
-            return $terms;
1883
-        }
1878
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1879
+		if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1880
+			// only apply this to module only taxonomy queries so 1 taxonomy only:
1881
+			||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1882
+			return $terms;
1883
+		}
1884 1884
 
1885
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1885
+		$term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1886 1886
 
1887
-        // if term objects were passed in send back objects
1888
-        // if term id were passed in send that back
1889
-        if( is_object( $terms[0] ) ){
1890
-            return $term_objects;
1891
-        }
1887
+		// if term objects were passed in send back objects
1888
+		// if term id were passed in send that back
1889
+		if( is_object( $terms[0] ) ){
1890
+			return $term_objects;
1891
+		}
1892 1892
 
1893
-        $terms = array();
1894
-        foreach( $term_objects as $term_object ){
1895
-            $terms[] = $term_object->term_id;
1896
-        }
1893
+		$terms = array();
1894
+		foreach( $term_objects as $term_object ){
1895
+			$terms[] = $term_object->term_id;
1896
+		}
1897 1897
 
1898
-        return $terms;
1898
+		return $terms;
1899 1899
 
1900 1900
 
1901
-    }// end filter_course_selected_terms
1901
+	}// end filter_course_selected_terms
1902 1902
 
1903
-    /**
1904
-     * Filter the given terms and only return the
1905
-     * terms that belong to the given user id.
1906
-     *
1907
-     * @since 1.8.0
1908
-     * @param $terms
1909
-     * @param $user_id
1910
-     * @return array
1911
-     */
1912
-    public function filter_terms_by_owner( $terms, $user_id ){
1903
+	/**
1904
+	 * Filter the given terms and only return the
1905
+	 * terms that belong to the given user id.
1906
+	 *
1907
+	 * @since 1.8.0
1908
+	 * @param $terms
1909
+	 * @param $user_id
1910
+	 * @return array
1911
+	 */
1912
+	public function filter_terms_by_owner( $terms, $user_id ){
1913 1913
 
1914
-        $users_terms = array();
1914
+		$users_terms = array();
1915 1915
 
1916
-        foreach( $terms as $index => $term ){
1916
+		foreach( $terms as $index => $term ){
1917 1917
 
1918
-            if( is_numeric( $term ) ){
1919
-                // the term id was given, get the term object
1920
-                $term = get_term( $term, 'module' );
1921
-            }
1918
+			if( is_numeric( $term ) ){
1919
+				// the term id was given, get the term object
1920
+				$term = get_term( $term, 'module' );
1921
+			}
1922 1922
 
1923
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1923
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1924 1924
 
1925
-            if ( $user_id == $author->ID ) {
1926
-                // add the term to the teachers terms
1927
-                $users_terms[] = $term;
1928
-            }
1925
+			if ( $user_id == $author->ID ) {
1926
+				// add the term to the teachers terms
1927
+				$users_terms[] = $term;
1928
+			}
1929 1929
 
1930
-        }
1930
+		}
1931 1931
 
1932
-        return $users_terms;
1932
+		return $users_terms;
1933 1933
 
1934
-    } // end filter terms by owner
1934
+	} // end filter terms by owner
1935 1935
 
1936
-    /**
1937
-     * Add the teacher name next to modules. Only works in Admin for Admin users.
1938
-     * This will not add name to terms belonging to admin user.
1939
-     *
1940
-     * Hooked into 'get_terms'
1941
-     *
1942
-     * @since 1.8.0
1943
-     */
1944
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1945
-    {
1936
+	/**
1937
+	 * Add the teacher name next to modules. Only works in Admin for Admin users.
1938
+	 * This will not add name to terms belonging to admin user.
1939
+	 *
1940
+	 * Hooked into 'get_terms'
1941
+	 *
1942
+	 * @since 1.8.0
1943
+	 */
1944
+	public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1945
+	{
1946 1946
 
1947
-        // only for admin users ont he module taxonomy
1948
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1949
-            return $terms;
1950
-        }
1947
+		// only for admin users ont he module taxonomy
1948
+		if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1949
+			return $terms;
1950
+		}
1951 1951
 
1952
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1953
-        // simply return this as wp doesn't need an array of stdObject Term
1954
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1952
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1953
+		// simply return this as wp doesn't need an array of stdObject Term
1954
+		if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1955 1955
 
1956
-            return $terms;
1956
+			return $terms;
1957 1957
 
1958
-        }
1958
+		}
1959 1959
 
1960
-        // loop through and update all terms adding the author name
1961
-        foreach( $terms as $index => $term ){
1960
+		// loop through and update all terms adding the author name
1961
+		foreach( $terms as $index => $term ){
1962 1962
 
1963
-            if( is_numeric( $term ) ){
1964
-                // the term id was given, get the term object
1965
-                $term = get_term( $term, 'module' );
1966
-            }
1963
+			if( is_numeric( $term ) ){
1964
+				// the term id was given, get the term object
1965
+				$term = get_term( $term, 'module' );
1966
+			}
1967 1967
 
1968
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1968
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1969 1969
 
1970
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1971
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1972
-            }
1970
+			if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1971
+				$term->name = $term->name . ' (' . $author->display_name . ') ';
1972
+			}
1973 1973
 
1974
-            // add the term to the teachers terms
1975
-            $users_terms[] = $term;
1974
+			// add the term to the teachers terms
1975
+			$users_terms[] = $term;
1976 1976
 
1977
-        }
1977
+		}
1978 1978
 
1979
-        return $users_terms;
1980
-    }
1979
+		return $users_terms;
1980
+	}
1981 1981
 
1982
-    /**
1983
-     * Remove modules metabox that come by default
1984
-     * with the modules taxonomy. We are removing this as
1985
-     * we have created our own custom meta box.
1986
-     */
1987
-    public static function remove_default_modules_box() {
1982
+	/**
1983
+	 * Remove modules metabox that come by default
1984
+	 * with the modules taxonomy. We are removing this as
1985
+	 * we have created our own custom meta box.
1986
+	 */
1987
+	public static function remove_default_modules_box() {
1988 1988
 
1989
-        remove_meta_box('modulediv', 'course', 'side');
1989
+		remove_meta_box('modulediv', 'course', 'side');
1990 1990
 
1991
-    }
1991
+	}
1992 1992
 
1993
-    /**
1994
-     * When a course is save make sure to reset the transient set
1995
-     * for it when determining the none module lessons.
1996
-     *
1997
-     * @sine 1.9.0
1998
-     * @param $post_id
1999
-     */
2000
-    public static function reset_none_modules_transient ( $post_id ){
1993
+	/**
1994
+	 * When a course is save make sure to reset the transient set
1995
+	 * for it when determining the none module lessons.
1996
+	 *
1997
+	 * @sine 1.9.0
1998
+	 * @param $post_id
1999
+	 */
2000
+	public static function reset_none_modules_transient ( $post_id ){
2001 2001
 
2002
-        // this should only apply to course and lesson post types
2003
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2002
+		// this should only apply to course and lesson post types
2003
+		if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2004 2004
 
2005
-            $course_id = '';
2005
+			$course_id = '';
2006 2006
 
2007
-            if( 'lesson' == get_post_type( $post_id ) ){
2007
+			if( 'lesson' == get_post_type( $post_id ) ){
2008 2008
 
2009
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2009
+				$course_id = Sensei()->lesson->get_course_id( $post_id );
2010 2010
 
2011
-            }
2011
+			}
2012 2012
 
2013 2013
 
2014
-            if( !empty( $course_id ) ){
2014
+			if( !empty( $course_id ) ){
2015 2015
 
2016
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2016
+				delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2017 2017
 
2018
-            }
2018
+			}
2019 2019
 
2020
-        } // end if is a course or a lesson
2020
+		} // end if is a course or a lesson
2021 2021
 
2022
-    } // end reset_none_modules_transient
2022
+	} // end reset_none_modules_transient
2023 2023
 
2024
-    /**
2025
-     * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2026
-     *
2027
-     * @since 1.9.0
2028
-     * @deprecated since 1.9.0
2029
-     *
2030
-     */
2031
-    public static function deprecate_sensei_single_course_modules_content(){
2024
+	/**
2025
+	 * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2026
+	 *
2027
+	 * @since 1.9.0
2028
+	 * @deprecated since 1.9.0
2029
+	 *
2030
+	 */
2031
+	public static function deprecate_sensei_single_course_modules_content(){
2032 2032
 
2033
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2033
+		sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2034 2034
 
2035
-    }
2035
+	}
2036 2036
 
2037
-    /**
2038
-     * Setup the single course module loop.
2039
-     *
2040
-     * Setup the global $sensei_modules_loop
2041
-     *
2042
-     * @since 1.9.0
2043
-     */
2044
-    public static function setup_single_course_module_loop(){
2037
+	/**
2038
+	 * Setup the single course module loop.
2039
+	 *
2040
+	 * Setup the global $sensei_modules_loop
2041
+	 *
2042
+	 * @since 1.9.0
2043
+	 */
2044
+	public static function setup_single_course_module_loop(){
2045 2045
 
2046
-        global $sensei_modules_loop, $post;
2047
-        $course_id = $post->ID;
2046
+		global $sensei_modules_loop, $post;
2047
+		$course_id = $post->ID;
2048 2048
 
2049
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2049
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2050 2050
 
2051
-        //initial setup
2052
-        $sensei_modules_loop['total'] = 0;
2053
-        $sensei_modules_loop['modules'] = array();
2054
-        $sensei_modules_loop['current'] = -1;
2051
+		//initial setup
2052
+		$sensei_modules_loop['total'] = 0;
2053
+		$sensei_modules_loop['modules'] = array();
2054
+		$sensei_modules_loop['current'] = -1;
2055 2055
 
2056
-        // exit if this course doesn't have modules
2057
-        if( !$modules || empty( $modules )  ){
2058
-            return;
2059
-        }
2056
+		// exit if this course doesn't have modules
2057
+		if( !$modules || empty( $modules )  ){
2058
+			return;
2059
+		}
2060 2060
 
2061 2061
 
2062
-        $lessons_in_all_modules = array();
2063
-        foreach( $modules as $term ){
2062
+		$lessons_in_all_modules = array();
2063
+		foreach( $modules as $term ){
2064 2064
 
2065
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2066
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2065
+			$lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2066
+			$lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2067 2067
 
2068
-        }
2068
+		}
2069 2069
 
2070 2070
 
2071
-        //setup all of the modules loop variables
2072
-        $sensei_modules_loop['total'] = count( $modules );
2073
-        $sensei_modules_loop['modules'] = $modules;
2074
-        $sensei_modules_loop['current'] = -1;
2075
-        $sensei_modules_loop['course_id'] = $course_id;
2071
+		//setup all of the modules loop variables
2072
+		$sensei_modules_loop['total'] = count( $modules );
2073
+		$sensei_modules_loop['modules'] = $modules;
2074
+		$sensei_modules_loop['current'] = -1;
2075
+		$sensei_modules_loop['course_id'] = $course_id;
2076 2076
 
2077
-    }// end setup_single_course_module_loop
2077
+	}// end setup_single_course_module_loop
2078 2078
 
2079
-    /**
2080
-     * Tear down the course module loop.
2081
-     *
2082
-     * @since 1.9.0
2083
-     *
2084
-     */
2085
-    public static function teardown_single_course_module_loop(){
2079
+	/**
2080
+	 * Tear down the course module loop.
2081
+	 *
2082
+	 * @since 1.9.0
2083
+	 *
2084
+	 */
2085
+	public static function teardown_single_course_module_loop(){
2086 2086
 
2087
-        global $sensei_modules_loop, $wp_query, $post;
2087
+		global $sensei_modules_loop, $wp_query, $post;
2088 2088
 
2089
-        //reset all of the modules loop variables
2090
-        $sensei_modules_loop['total'] = 0;
2091
-        $sensei_modules_loop['modules'] = array();
2092
-        $sensei_modules_loop['current'] = -1;
2089
+		//reset all of the modules loop variables
2090
+		$sensei_modules_loop['total'] = 0;
2091
+		$sensei_modules_loop['modules'] = array();
2092
+		$sensei_modules_loop['current'] = -1;
2093 2093
 
2094
-        // set the current course to be the global post again
2095
-        wp_reset_query();
2096
-        $post = $wp_query->post;
2097
-    }// end teardown_single_course_module_loop
2094
+		// set the current course to be the global post again
2095
+		wp_reset_query();
2096
+		$post = $wp_query->post;
2097
+	}// end teardown_single_course_module_loop
2098 2098
 
2099 2099
 } // end modules class
Please login to merge, or discard this patch.
includes/class-sensei-analysis-overview-list-table.php 3 patches
Braces   +8 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Analysis Overview List Table Class
@@ -306,8 +309,7 @@  discard block
 block discarded – undo
306 309
 				// Output course data
307 310
 				if ( $this->csv_output ) {
308 311
 					$course_title = apply_filters( 'the_title', $item->post_title, $item->ID );
309
-				}
310
-				else {
312
+				} else {
311 313
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID ), admin_url( 'admin.php' ) );
312 314
 
313 315
 					$course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>';
@@ -363,16 +365,14 @@  discard block
 block discarded – undo
363 365
 				// Output lesson data
364 366
 				if ( $this->csv_output ) {
365 367
 					$lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID );
366
-				}
367
-				else {
368
+				} else {
368 369
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) );
369 370
 					$lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>';
370 371
 
371 372
 					if ( $course_id ) {
372 373
 						$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
373 374
 						$course_title = '<a href="' . esc_url( $url ) . '">' . $course_title . '</a>';
374
-					}
375
-					else {
375
+					} else {
376 376
 						$course_title = __('n/a', 'woothemes-sensei');
377 377
 					}
378 378
 					if ( is_numeric( $lesson_average_grade ) ) {
@@ -423,8 +423,7 @@  discard block
 block discarded – undo
423 423
 				// Output the users data
424 424
 				if ( $this->csv_output ) {
425 425
                     $user_name = Sensei()->learners->get_learner_full_name( $item->ID );
426
-                }
427
-				else {
426
+                } else {
428 427
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
429 428
 					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
430 429
 					$user_average_grade .= '%';
Please login to merge, or discard this patch.
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
 			'order' => $order,
160 160
 		);
161 161
 
162
-        // Handle search
163
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
164
-            $args['search'] = esc_html( $_GET['s'] );
165
-        }
162
+		// Handle search
163
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
164
+			$args['search'] = esc_html( $_GET['s'] );
165
+		}
166 166
 
167 167
 		switch ( $this->type ) {
168 168
 			case 'courses':
@@ -219,10 +219,10 @@  discard block
 block discarded – undo
219 219
 		);
220 220
 
221 221
 
222
-        // Handle search
223
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
224
-            $args['search'] = esc_html( $_GET['s'] );
225
-        }
222
+		// Handle search
223
+		if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
224
+			$args['search'] = esc_html( $_GET['s'] );
225
+		}
226 226
 
227 227
 
228 228
 		// Start the csv with the column headings
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
 	 * Generates the overall array for a single item in the display
261 261
 	 * @since  1.7.0
262 262
 	 * @param object $item The current item
263
-     * @return array $column_data;
263
+	 * @return array $column_data;
264 264
 	 */
265 265
 	protected function get_row_data( $item ) {
266 266
 
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
 
420 420
 				// Output the users data
421 421
 				if ( $this->csv_output ) {
422
-                    $user_name = Sensei_Learner::get_full_name( $item->ID );
423
-                }
422
+					$user_name = Sensei_Learner::get_full_name( $item->ID );
423
+				}
424 424
 				else {
425 425
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
426 426
 					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
@@ -514,17 +514,17 @@  discard block
 block discarded – undo
514 514
 		// This stops the full meta data of each user being loaded
515 515
 		$args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' );
516 516
 
517
-        /**
518
-         * Filter the WP_User_Query arguments
519
-         * @since 1.6.0
520
-         * @param $args
521
-         */
522
-        $args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
517
+		/**
518
+		 * Filter the WP_User_Query arguments
519
+		 * @since 1.6.0
520
+		 * @param $args
521
+		 */
522
+		$args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
523 523
 		$wp_user_search = new WP_User_Query( $args );
524
-        $learners = $wp_user_search->get_results();
524
+		$learners = $wp_user_search->get_results();
525 525
 		$this->total_items = $wp_user_search->get_total();
526 526
 
527
-        return $learners;
527
+		return $learners;
528 528
 
529 529
 	} // End get_learners()
530 530
 
Please login to merge, or discard this patch.
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Analysis Overview Data Table.
@@ -18,17 +18,17 @@  discard block
 block discarded – undo
18 18
 	 * @since  1.2.0
19 19
 	 * @return  void
20 20
 	 */
21
-	public function __construct ( $type = 'users' ) {
22
-		$this->type = in_array( $type, array( 'courses', 'lessons', 'users' ) ) ? $type : 'users';
21
+	public function __construct($type = 'users') {
22
+		$this->type = in_array($type, array('courses', 'lessons', 'users')) ? $type : 'users';
23 23
 
24 24
 		// Load Parent token into constructor
25
-		parent::__construct( 'analysis_overview' );
25
+		parent::__construct('analysis_overview');
26 26
 
27 27
 		// Actions
28
-		add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) );
29
-		add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) );
28
+		add_action('sensei_before_list_table', array($this, 'data_table_header'));
29
+		add_action('sensei_after_list_table', array($this, 'data_table_footer'));
30 30
 
31
-		add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) );
31
+		add_filter('sensei_list_table_search_button_text', array($this, 'search_button'));
32 32
 	} // End __construct()
33 33
 
34 34
 	/**
@@ -38,41 +38,41 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	function get_columns() {
40 40
 
41
-		switch( $this->type ) {
41
+		switch ($this->type) {
42 42
 			case 'courses':
43 43
 				$columns = array(
44
-					'title' => __( 'Course', 'woothemes-sensei' ),
45
-					'students' => __( 'Learners', 'woothemes-sensei' ),
46
-					'lessons' => __( 'Lessons', 'woothemes-sensei' ),
47
-					'completions' => __( 'Completed', 'woothemes-sensei' ),
48
-					'average_percent' => __( 'Average Percentage', 'woothemes-sensei' ),
44
+					'title' => __('Course', 'woothemes-sensei'),
45
+					'students' => __('Learners', 'woothemes-sensei'),
46
+					'lessons' => __('Lessons', 'woothemes-sensei'),
47
+					'completions' => __('Completed', 'woothemes-sensei'),
48
+					'average_percent' => __('Average Percentage', 'woothemes-sensei'),
49 49
 				);
50 50
 				break;
51 51
 
52 52
 			case 'lessons':
53 53
 				$columns = array(
54
-					'title' => __( 'Lesson', 'woothemes-sensei' ),
55
-					'course' => __( 'Course', 'woothemes-sensei' ),
56
-					'students' => __( 'Learners', 'woothemes-sensei' ),
57
-					'completions' => __( 'Completed', 'woothemes-sensei' ),
58
-					'average_grade' => __( 'Average Grade', 'woothemes-sensei' ),
54
+					'title' => __('Lesson', 'woothemes-sensei'),
55
+					'course' => __('Course', 'woothemes-sensei'),
56
+					'students' => __('Learners', 'woothemes-sensei'),
57
+					'completions' => __('Completed', 'woothemes-sensei'),
58
+					'average_grade' => __('Average Grade', 'woothemes-sensei'),
59 59
 				);
60 60
 				break;
61 61
 
62 62
 			case 'users':
63 63
 			default:
64 64
 				$columns = array(
65
-					'title' => __( 'Learner', 'woothemes-sensei' ),
66
-					'registered' => __( 'Date Registered', 'woothemes-sensei' ),
67
-					'active_courses' => __( 'Active Courses', 'woothemes-sensei' ),
68
-					'completed_courses' => __( 'Completed Courses', 'woothemes-sensei' ),
69
-					'average_grade' => __( 'Average Grade', 'woothemes-sensei' ),
65
+					'title' => __('Learner', 'woothemes-sensei'),
66
+					'registered' => __('Date Registered', 'woothemes-sensei'),
67
+					'active_courses' => __('Active Courses', 'woothemes-sensei'),
68
+					'completed_courses' => __('Completed Courses', 'woothemes-sensei'),
69
+					'average_grade' => __('Average Grade', 'woothemes-sensei'),
70 70
 				);
71 71
 				break;
72 72
 		}
73 73
 		// Backwards compatible filter name, moving forward should have single filter name
74
-		$columns = apply_filters( 'sensei_analysis_overview_' . $this->type . '_columns', $columns, $this );
75
-		$columns = apply_filters( 'sensei_analysis_overview_columns', $columns, $this );
74
+		$columns = apply_filters('sensei_analysis_overview_'.$this->type.'_columns', $columns, $this);
75
+		$columns = apply_filters('sensei_analysis_overview_columns', $columns, $this);
76 76
 		return $columns;
77 77
 	}
78 78
 
@@ -83,41 +83,41 @@  discard block
 block discarded – undo
83 83
 	 */
84 84
 	function get_sortable_columns() {
85 85
 
86
-		switch( $this->type ) {
86
+		switch ($this->type) {
87 87
 			case 'courses':
88 88
 				$columns = array(
89
-					'title' => array( 'title', false ),
90
-					'students' => array( 'students', false ),
91
-					'lessons' => array( 'lessons', false ),
92
-					'completions' => array( 'completions', false ),
93
-					'average_percent' => array( 'average_percent', false ),
89
+					'title' => array('title', false),
90
+					'students' => array('students', false),
91
+					'lessons' => array('lessons', false),
92
+					'completions' => array('completions', false),
93
+					'average_percent' => array('average_percent', false),
94 94
 				);
95 95
 				break;
96 96
 
97 97
 			case 'lessons':
98 98
 				$columns = array(
99
-					'title' => array( 'title', false ),
100
-					'course' => array( 'course', false ),
101
-					'students' => array( 'students', false ),
102
-					'completions' => array( 'completions', false ),
103
-					'average_grade' => array( 'average_grade', false ),
99
+					'title' => array('title', false),
100
+					'course' => array('course', false),
101
+					'students' => array('students', false),
102
+					'completions' => array('completions', false),
103
+					'average_grade' => array('average_grade', false),
104 104
 				);
105 105
 				break;
106 106
 
107 107
 			case 'users':
108 108
 			default:
109 109
 				$columns = array(
110
-					'title' => array( 'user_login', false ),
111
-					'registered' => array( 'registered', false ),
112
-					'active_courses' => array( 'active_courses', false ),
113
-					'completed_courses' => array( 'completed_courses', false ),
114
-					'average_grade' => array( 'average_grade', false )
110
+					'title' => array('user_login', false),
111
+					'registered' => array('registered', false),
112
+					'active_courses' => array('active_courses', false),
113
+					'completed_courses' => array('completed_courses', false),
114
+					'average_grade' => array('average_grade', false)
115 115
 				);
116 116
 				break;
117 117
 		}
118 118
 		// Backwards compatible filter name, moving forward should have single filter name
119
-		$columns = apply_filters( 'sensei_analysis_overview_' . $this->type . '_columns_sortable', $columns, $this );
120
-		$columns = apply_filters( 'sensei_analysis_overview_columns_sortable', $columns, $this );
119
+		$columns = apply_filters('sensei_analysis_overview_'.$this->type.'_columns_sortable', $columns, $this);
120
+		$columns = apply_filters('sensei_analysis_overview_columns_sortable', $columns, $this);
121 121
 		return $columns;
122 122
 	}
123 123
 
@@ -131,25 +131,25 @@  discard block
 block discarded – undo
131 131
 
132 132
 		// Handle orderby
133 133
 		$orderby = '';
134
-		if ( !empty( $_GET['orderby'] ) ) {
135
-			if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) {
136
-				$orderby = esc_html( $_GET['orderby'] );
134
+		if ( ! empty($_GET['orderby'])) {
135
+			if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) {
136
+				$orderby = esc_html($_GET['orderby']);
137 137
 			} // End If Statement
138 138
 		}
139 139
 
140 140
 		// Handle order
141 141
 		$order = 'ASC';
142
-		if ( !empty( $_GET['order'] ) ) {
143
-			$order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC';
142
+		if ( ! empty($_GET['order'])) {
143
+			$order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC';
144 144
 		}
145 145
 
146
-		$per_page = $this->get_items_per_page( 'sensei_comments_per_page' );
147
-		$per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' );
146
+		$per_page = $this->get_items_per_page('sensei_comments_per_page');
147
+		$per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments');
148 148
 
149 149
 		$paged = $this->get_pagenum();
150 150
 		$offset = 0;
151
-		if ( !empty($paged) ) {
152
-			$offset = $per_page * ( $paged - 1 );
151
+		if ( ! empty($paged)) {
152
+			$offset = $per_page * ($paged - 1);
153 153
 		} // End If Statement
154 154
 
155 155
 		$args = array(
@@ -160,32 +160,32 @@  discard block
 block discarded – undo
160 160
 		);
161 161
 
162 162
         // Handle search
163
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
164
-            $args['search'] = esc_html( $_GET['s'] );
163
+        if (isset($_GET['s']) && ! empty($_GET['s'])) {
164
+            $args['search'] = esc_html($_GET['s']);
165 165
         }
166 166
 
167
-		switch ( $this->type ) {
167
+		switch ($this->type) {
168 168
 			case 'courses':
169
-				$this->items = $this->get_courses( $args );
169
+				$this->items = $this->get_courses($args);
170 170
 				break;
171 171
 
172 172
 			case 'lessons':
173
-				$this->items = $this->get_lessons( $args );
173
+				$this->items = $this->get_lessons($args);
174 174
 				break;
175 175
 
176 176
 			case 'users':
177 177
 			default :
178
-				$this->items = $this->get_learners( $args );
178
+				$this->items = $this->get_learners($args);
179 179
 				break;
180 180
 		}
181 181
 
182 182
 		$total_items = $this->total_items;
183
-		$total_pages = ceil( $total_items / $per_page );
184
-		$this->set_pagination_args( array(
183
+		$total_pages = ceil($total_items / $per_page);
184
+		$this->set_pagination_args(array(
185 185
 			'total_items' => $total_items,
186 186
 			'total_pages' => $total_pages,
187 187
 			'per_page' => $per_page
188
-		) );
188
+		));
189 189
 	}
190 190
 
191 191
 	/**
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 	 * @since  1.7.0
194 194
 	 * @return data
195 195
 	 */
196
-	public function generate_report( $report ) {
196
+	public function generate_report($report) {
197 197
 
198 198
 		$data = array();
199 199
 
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
 
202 202
 		// Handle orderby
203 203
 		$orderby = '';
204
-		if ( !empty( $_GET['orderby'] ) ) {
205
-			if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) {
206
-				$orderby = esc_html( $_GET['orderby'] );
204
+		if ( ! empty($_GET['orderby'])) {
205
+			if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) {
206
+				$orderby = esc_html($_GET['orderby']);
207 207
 			} // End If Statement
208 208
 		}
209 209
 
210 210
 		// Handle order
211 211
 		$order = 'ASC';
212
-		if ( !empty( $_GET['order'] ) ) {
213
-			$order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC';
212
+		if ( ! empty($_GET['order'])) {
213
+			$order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC';
214 214
 		}
215 215
 
216 216
 		$args = array(
@@ -220,37 +220,37 @@  discard block
 block discarded – undo
220 220
 
221 221
 
222 222
         // Handle search
223
-        if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) {
224
-            $args['search'] = esc_html( $_GET['s'] );
223
+        if (isset($_GET['s']) && ! empty($_GET['s'])) {
224
+            $args['search'] = esc_html($_GET['s']);
225 225
         }
226 226
 
227 227
 
228 228
 		// Start the csv with the column headings
229 229
 		$column_headers = array();
230 230
 		$columns = $this->get_columns();
231
-		foreach( $columns AS $key => $title ) {
231
+		foreach ($columns AS $key => $title) {
232 232
 			$column_headers[] = $title;
233 233
 		}
234 234
 		$data[] = $column_headers;
235 235
 
236
-		switch ( $this->type ) {
236
+		switch ($this->type) {
237 237
 			case 'courses':
238
-				$this->items = $this->get_courses( $args );
238
+				$this->items = $this->get_courses($args);
239 239
 				break;
240 240
 
241 241
 			case 'lessons':
242
-				$this->items = $this->get_lessons( $args );
242
+				$this->items = $this->get_lessons($args);
243 243
 				break;
244 244
 
245 245
 			case 'users':
246 246
 			default :
247
-				$this->items = $this->get_learners( $args );
247
+				$this->items = $this->get_learners($args);
248 248
 				break;
249 249
 		}
250 250
 
251 251
 		// Process each row
252
-		foreach( $this->items AS $item) {
253
-			$data[] = $this->get_row_data( $item );
252
+		foreach ($this->items AS $item) {
253
+			$data[] = $this->get_row_data($item);
254 254
 		}
255 255
 
256 256
 		return $data;
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 	 * @param object $item The current item
263 263
      * @return array $column_data;
264 264
 	 */
265
-	protected function get_row_data( $item ) {
265
+	protected function get_row_data($item) {
266 266
 
267
-		switch( $this->type ) {
267
+		switch ($this->type) {
268 268
 			case 'courses' :
269 269
 				// Get Learners (i.e. those who have started)
270 270
 				$course_args = array( 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 						'type' => 'sensei_course_status',
273 273
 						'status' => 'any',
274 274
 					);
275
-				$course_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_learners', $course_args, $item ) );
275
+				$course_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_learners', $course_args, $item));
276 276
 
277 277
 				// Get Course Completions
278 278
 				$course_args = array( 
@@ -280,10 +280,10 @@  discard block
 block discarded – undo
280 280
 						'type' => 'sensei_course_status',
281 281
 						'status' => 'complete',
282 282
 					);
283
-				$course_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_completions', $course_args, $item ) );
283
+				$course_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_completions', $course_args, $item));
284 284
 
285 285
 				// Course Lessons
286
-				$course_lessons = Sensei()->lesson->lesson_count( array('publish', 'private'), $item->ID );
286
+				$course_lessons = Sensei()->lesson->lesson_count(array('publish', 'private'), $item->ID);
287 287
 
288 288
 				// Get Percent Complete
289 289
 				$grade_args = array( 
@@ -292,30 +292,30 @@  discard block
 block discarded – undo
292 292
 						'status' => 'any',
293 293
 						'meta_key' => 'percent',
294 294
 					);
295
-				add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) );
296
-				$course_percentage = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_percentage', $grade_args, $item ), true );
297
-				remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) );
295
+				add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
296
+				$course_percentage = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_percentage', $grade_args, $item), true);
297
+				remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
298 298
 
299
-				$percent_count = !empty( $course_percentage->total ) ? $course_percentage->total : 1;
300
-				$percent_total = !empty( $course_percentage->meta_sum ) ? doubleval( $course_percentage->meta_sum ) : 0;
301
-				$course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) );
299
+				$percent_count = ! empty($course_percentage->total) ? $course_percentage->total : 1;
300
+				$percent_total = ! empty($course_percentage->meta_sum) ? doubleval($course_percentage->meta_sum) : 0;
301
+				$course_average_percent = abs(round(doubleval($percent_total / $percent_count), 2));
302 302
 
303 303
 				// Output course data
304
-				if ( $this->csv_output ) {
305
-					$course_title = apply_filters( 'the_title', $item->post_title, $item->ID );
304
+				if ($this->csv_output) {
305
+					$course_title = apply_filters('the_title', $item->post_title, $item->ID);
306 306
 				}
307 307
 				else {
308
-					$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID ), admin_url( 'admin.php' ) );
308
+					$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID), admin_url('admin.php'));
309 309
 
310
-					$course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>';
310
+					$course_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>';
311 311
 					$course_average_percent .= '%';
312 312
 				} // End If Statement
313
-				$column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $course_title,
313
+				$column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $course_title,
314 314
 												'students' => $course_students,
315 315
 												'lessons' => $course_lessons,
316 316
 												'completions' => $course_completions,
317 317
 												'average_percent' => $course_average_percent,
318
-											), $item, $this );
318
+											), $item, $this);
319 319
 				break;
320 320
 
321 321
 			case 'lessons' :
@@ -325,63 +325,63 @@  discard block
 block discarded – undo
325 325
 						'type' => 'sensei_lesson_status',
326 326
 						'status' => 'any',
327 327
 					);
328
-				$lesson_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_learners', $lesson_args, $item ) );
328
+				$lesson_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_learners', $lesson_args, $item));
329 329
 
330 330
 				// Get Course Completions
331 331
 				$lesson_args = array( 
332 332
 						'post_id' => $item->ID,
333 333
 						'type' => 'sensei_lesson_status',
334
-						'status' => array( 'complete', 'graded', 'passed', 'failed' ),
334
+						'status' => array('complete', 'graded', 'passed', 'failed'),
335 335
 						'count' => true,
336 336
 					);
337
-				$lesson_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_completions', $lesson_args, $item ) );
337
+				$lesson_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_completions', $lesson_args, $item));
338 338
 
339 339
 				// Course 
340
-				$course_id = get_post_meta( $item->ID, '_lesson_course', true );
341
-				$course_title = $course_id ? get_the_title( $course_id ) : '';
340
+				$course_id = get_post_meta($item->ID, '_lesson_course', true);
341
+				$course_title = $course_id ? get_the_title($course_id) : '';
342 342
 
343 343
 				$lesson_average_grade = __('n/a', 'woothemes-sensei');
344
-				if ( false != get_post_meta($item->ID, '_quiz_has_questions', true) ) {
344
+				if (false != get_post_meta($item->ID, '_quiz_has_questions', true)) {
345 345
 					// Get Percent Complete
346 346
 					$grade_args = array( 
347 347
 							'post_id' => $item->ID,
348 348
 							'type' => 'sensei_lesson_status',
349
-							'status' => array( 'graded', 'passed', 'failed' ),
349
+							'status' => array('graded', 'passed', 'failed'),
350 350
 							'meta_key' => 'grade',
351 351
 						);
352
-					add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) );
353
-					$lesson_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true );
354
-					remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) );
352
+					add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
353
+					$lesson_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_grades', $grade_args, $item), true);
354
+					remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
355 355
 
356
-					$grade_count = !empty( $lesson_grades->total ) ? $lesson_grades->total : 1;
357
-					$grade_total = !empty( $lesson_grades->meta_sum ) ? doubleval( $lesson_grades->meta_sum ) : 0;
358
-					$lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
356
+					$grade_count = ! empty($lesson_grades->total) ? $lesson_grades->total : 1;
357
+					$grade_total = ! empty($lesson_grades->meta_sum) ? doubleval($lesson_grades->meta_sum) : 0;
358
+					$lesson_average_grade = abs(round(doubleval($grade_total / $grade_count), 2));
359 359
 				}
360 360
 				// Output lesson data
361
-				if ( $this->csv_output ) {
362
-					$lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID );
361
+				if ($this->csv_output) {
362
+					$lesson_title = apply_filters('the_title', $item->post_title, $item->ID);
363 363
 				}
364 364
 				else {
365
-					$url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) );
366
-					$lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>';
365
+					$url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php'));
366
+					$lesson_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>';
367 367
 
368
-					if ( $course_id ) {
369
-						$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
370
-						$course_title = '<a href="' . esc_url( $url ) . '">' . $course_title . '</a>';
368
+					if ($course_id) {
369
+						$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
370
+						$course_title = '<a href="'.esc_url($url).'">'.$course_title.'</a>';
371 371
 					}
372 372
 					else {
373 373
 						$course_title = __('n/a', 'woothemes-sensei');
374 374
 					}
375
-					if ( is_numeric( $lesson_average_grade ) ) {
375
+					if (is_numeric($lesson_average_grade)) {
376 376
 						$lesson_average_grade .= '%';
377 377
 					}
378 378
 				} // End If Statement
379
-				$column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $lesson_title,
379
+				$column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $lesson_title,
380 380
 												'course' => $course_title,
381 381
 												'students' => $lesson_students,
382 382
 												'completions' => $lesson_completions,
383 383
 												'average_grade' => $lesson_average_grade,
384
-											), $item, $this );
384
+											), $item, $this);
385 385
 				break;
386 386
 
387 387
 			case 'users' :
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 						'type' => 'sensei_course_status',
393 393
 						'status' => 'any',
394 394
 					);
395
-				$user_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_started', $course_args, $item ) );
395
+				$user_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_started', $course_args, $item));
396 396
 
397 397
 				// Get Completed Courses
398 398
 				$course_args = array( 
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 						'type' => 'sensei_course_status',
401 401
 						'status' => 'complete',
402 402
 					);
403
-				$user_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_ended', $course_args, $item ) );
403
+				$user_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_ended', $course_args, $item));
404 404
 
405 405
 				// Get Quiz Grades
406 406
 				$grade_args = array( 
@@ -409,29 +409,29 @@  discard block
 block discarded – undo
409 409
 						'status' => 'any',
410 410
 						'meta_key' => 'grade',
411 411
 					);
412
-				add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) );
413
-				$user_quiz_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_lesson_grades', $grade_args, $item ), true );
414
-				remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) );
412
+				add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
413
+				$user_quiz_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_lesson_grades', $grade_args, $item), true);
414
+				remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
415 415
 
416
-				$grade_count = !empty( $user_quiz_grades->total ) ? $user_quiz_grades->total : 1;
417
-				$grade_total = !empty( $user_quiz_grades->meta_sum ) ? doubleval( $user_quiz_grades->meta_sum ) : 0;
418
-				$user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
416
+				$grade_count = ! empty($user_quiz_grades->total) ? $user_quiz_grades->total : 1;
417
+				$grade_total = ! empty($user_quiz_grades->meta_sum) ? doubleval($user_quiz_grades->meta_sum) : 0;
418
+				$user_average_grade = abs(round(doubleval($grade_total / $grade_count), 2));
419 419
 
420 420
 				// Output the users data
421
-				if ( $this->csv_output ) {
422
-                    $user_name = Sensei_Learner::get_full_name( $item->ID );
421
+				if ($this->csv_output) {
422
+                    $user_name = Sensei_Learner::get_full_name($item->ID);
423 423
                 }
424 424
 				else {
425
-					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
426
-					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
425
+					$url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->ID), admin_url('admin.php'));
426
+					$user_name = '<strong><a class="row-title" href="'.esc_url($url).'">'.$item->display_name.'</a></strong>';
427 427
 					$user_average_grade .= '%';
428 428
 				} // End If Statement
429
-				$column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $user_name,
429
+				$column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $user_name,
430 430
 												'registered' => $item->user_registered,
431
-												'active_courses' => ( $user_courses_started - $user_courses_ended ),
431
+												'active_courses' => ($user_courses_started - $user_courses_ended),
432 432
 												'completed_courses' => $user_courses_ended,
433 433
 												'average_grade' => $user_average_grade,
434
-											), $item, $this );
434
+											), $item, $this);
435 435
 				break;
436 436
 		} // end switch
437 437
 		return $column_data;
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 	 * @since  1.7.0
443 443
 	 * @return array courses
444 444
 	 */
445
-	private function get_courses( $args ) {
445
+	private function get_courses($args) {
446 446
 		$course_args = array(
447 447
 			'post_type' => 'course',
448 448
 			'post_status' => array('publish', 'private'),
@@ -453,16 +453,16 @@  discard block
 block discarded – undo
453 453
 			'suppress_filters' => 0,
454 454
 		);
455 455
 
456
-		if ( $this->csv_output ) {
456
+		if ($this->csv_output) {
457 457
 			$course_args['posts_per_page'] = '-1';
458 458
 		}
459 459
 
460
-		if( isset( $args['search'] ) ) {
460
+		if (isset($args['search'])) {
461 461
 			$course_args['s'] = $args['search'];
462 462
 		}
463 463
 
464 464
 		// Using WP_Query as get_posts() doesn't support 'found_posts'
465
-		$courses_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_courses', $course_args ) );
465
+		$courses_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_courses', $course_args));
466 466
 		$this->total_items = $courses_query->found_posts;
467 467
 		return $courses_query->posts;
468 468
 
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
 	 * @since  1.7.0
474 474
 	 * @return array lessons
475 475
 	 */
476
-	private function get_lessons( $args ) {
476
+	private function get_lessons($args) {
477 477
 		$lessons_args = array(
478 478
 			'post_type' => 'lesson',
479 479
 			'post_status' => array('publish', 'private'),
@@ -484,16 +484,16 @@  discard block
 block discarded – undo
484 484
 			'suppress_filters' => 0,
485 485
 		);
486 486
 
487
-		if ( $this->csv_output ) {
487
+		if ($this->csv_output) {
488 488
 			$lessons_args['posts_per_page'] = '-1';
489 489
 		}
490 490
 
491
-		if( isset( $args['search'] ) ) {
491
+		if (isset($args['search'])) {
492 492
 			$lessons_args['s'] = $args['search'];
493 493
 		}
494 494
 
495 495
 		// Using WP_Query as get_posts() doesn't support 'found_posts'
496
-		$lessons_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_lessons', $lessons_args ) );
496
+		$lessons_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_lessons', $lessons_args));
497 497
 		$this->total_items = $lessons_query->found_posts;
498 498
 		return $lessons_query->posts;
499 499
 	} // End get_lessons()
@@ -503,24 +503,24 @@  discard block
 block discarded – undo
503 503
 	 * @since  1.7.0
504 504
 	 * @return array learners
505 505
 	 */
506
-	private function get_learners( $args ) {
506
+	private function get_learners($args) {
507 507
 
508
-		if ( !empty($args['search']) ) {
508
+		if ( ! empty($args['search'])) {
509 509
 			$args = array(
510
-				'search' => '*' . trim( $args['search'], '*' ) . '*',
510
+				'search' => '*'.trim($args['search'], '*').'*',
511 511
 			);
512 512
 		}
513 513
 
514 514
 		// This stops the full meta data of each user being loaded
515
-		$args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' );
515
+		$args['fields'] = array('ID', 'user_login', 'user_email', 'user_registered', 'display_name');
516 516
 
517 517
         /**
518 518
          * Filter the WP_User_Query arguments
519 519
          * @since 1.6.0
520 520
          * @param $args
521 521
          */
522
-        $args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
523
-		$wp_user_search = new WP_User_Query( $args );
522
+        $args = apply_filters('sensei_analysis_overview_filter_users', $args);
523
+		$wp_user_search = new WP_User_Query($args);
524 524
         $learners = $wp_user_search->get_results();
525 525
 		$this->total_items = $wp_user_search->get_total();
526 526
 
@@ -533,13 +533,13 @@  discard block
 block discarded – undo
533 533
 	 * @since  1.2.0
534 534
 	 * @return array $stats_to_render of stats boxes and values
535 535
 	 */
536
-	public function stats_boxes () {
536
+	public function stats_boxes() {
537 537
 
538 538
 		// Get the data required
539 539
 		$user_count = count_users();
540
-		$user_count = apply_filters( 'sensei_analysis_total_users', $user_count['total_users'], $user_count );
541
-		$total_courses = Sensei()->course->course_count( array('publish', 'private') );
542
-		$total_lessons = Sensei()->lesson->lesson_count( array('publish', 'private') );
540
+		$user_count = apply_filters('sensei_analysis_total_users', $user_count['total_users'], $user_count);
541
+		$total_courses = Sensei()->course->course_count(array('publish', 'private'));
542
+		$total_lessons = Sensei()->lesson->lesson_count(array('publish', 'private'));
543 543
 
544 544
 		$grade_args = array( 
545 545
 				'type' => 'sensei_lesson_status',
@@ -547,36 +547,36 @@  discard block
 block discarded – undo
547 547
 				'meta_key' => 'grade',
548 548
 			);
549 549
 
550
-		add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) );
551
-		$total_quiz_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_quiz_grades', $grade_args ), true );
552
-		remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) );
550
+		add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
551
+		$total_quiz_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_quiz_grades', $grade_args), true);
552
+		remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter'));
553 553
 
554
-		$total_grade_count = !empty( $total_quiz_grades->total ) ? $total_quiz_grades->total : 1;
555
-		$total_grade_total = !empty( $total_quiz_grades->meta_sum ) ? doubleval( $total_quiz_grades->meta_sum ) : 0;
556
-		$total_average_grade = abs( round( doubleval( $total_grade_total / $total_grade_count ), 2 ) );
554
+		$total_grade_count = ! empty($total_quiz_grades->total) ? $total_quiz_grades->total : 1;
555
+		$total_grade_total = ! empty($total_quiz_grades->meta_sum) ? doubleval($total_quiz_grades->meta_sum) : 0;
556
+		$total_average_grade = abs(round(doubleval($total_grade_total / $total_grade_count), 2));
557 557
 
558 558
 		$course_args = array( 
559 559
 				'type' => 'sensei_course_status',
560 560
 				'status' => 'any',
561 561
 			);
562
-		$total_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_started', $course_args ) );
562
+		$total_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_started', $course_args));
563 563
 		$course_args = array( 
564 564
 				'type' => 'sensei_course_status',
565 565
 				'status' => 'complete',
566 566
 			);
567
-		$total_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_ended', $course_args ) );
568
-		$average_courses_per_learner = abs( round( doubleval( $total_courses_started / $user_count ), 2 ) );
567
+		$total_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_ended', $course_args));
568
+		$average_courses_per_learner = abs(round(doubleval($total_courses_started / $user_count), 2));
569 569
 
570 570
 		// Setup the boxes to render
571 571
 		$stats_to_render = array( 
572
-								__( 'Total Courses', 'woothemes-sensei' ) => $total_courses,
573
-								__( 'Total Lessons', 'woothemes-sensei' ) => $total_lessons,
574
-								__( 'Total Learners', 'woothemes-sensei' ) => $user_count,
575
-								__( 'Average Courses per Learner', 'woothemes-sensei' ) => $average_courses_per_learner,
576
-								__( 'Average Grade', 'woothemes-sensei' ) => $total_average_grade . '%',
577
-								__( 'Total Completed Courses', 'woothemes-sensei' ) => $total_courses_ended,
572
+								__('Total Courses', 'woothemes-sensei') => $total_courses,
573
+								__('Total Lessons', 'woothemes-sensei') => $total_lessons,
574
+								__('Total Learners', 'woothemes-sensei') => $user_count,
575
+								__('Average Courses per Learner', 'woothemes-sensei') => $average_courses_per_learner,
576
+								__('Average Grade', 'woothemes-sensei') => $total_average_grade.'%',
577
+								__('Total Completed Courses', 'woothemes-sensei') => $total_courses_ended,
578 578
 							);
579
-		return apply_filters( 'sensei_analysis_stats_boxes', $stats_to_render );
579
+		return apply_filters('sensei_analysis_stats_boxes', $stats_to_render);
580 580
 	} // End stats_boxes()
581 581
 
582 582
 	/**
@@ -586,12 +586,12 @@  discard block
 block discarded – undo
586 586
 	 * @return void
587 587
 	 */
588 588
 	public function no_items() {
589
-		if( ! $this->view || 'users' == $this->view ) {
589
+		if ( ! $this->view || 'users' == $this->view) {
590 590
 			$type = 'learners';
591 591
 		} else {
592 592
 			$type = $this->view;
593 593
 		}
594
-		echo  sprintf( __( '%1$sNo %2$s found%3$s', 'woothemes-sensei' ), '<em>', $type, '</em>' );
594
+		echo  sprintf(__('%1$sNo %2$s found%3$s', 'woothemes-sensei'), '<em>', $type, '</em>');
595 595
 	} // End no_items()
596 596
 
597 597
 	/**
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 			'page' => $this->page_slug,
607 607
 		);
608 608
 		$learners_class = $courses_class = $lessons_class = '';
609
-		switch( $this->type ) {
609
+		switch ($this->type) {
610 610
 			case 'courses':
611 611
 				$courses_class = 'current';
612 612
 				break;
@@ -624,18 +624,18 @@  discard block
 block discarded – undo
624 624
 		$lesson_args['view'] = 'lessons';
625 625
 		$courses_args['view'] = 'courses';
626 626
 
627
-		$menu['learners'] = '<a class="' . $learners_class . '" href="' . esc_url( add_query_arg( $learner_args, admin_url( 'admin.php' ) ) ). '">' . __( 'Learners', 'woothemes-sensei' ) . '</a>';
628
-		$menu['courses'] = '<a class="' . $courses_class . '" href="' . esc_url ( add_query_arg( $courses_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Courses', 'woothemes-sensei' ) . '</a>';
629
-		$menu['lessons'] = '<a class="' . $lessons_class . '" href="' . esc_url( add_query_arg( $lesson_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Lessons', 'woothemes-sensei' ) . '</a>';
627
+		$menu['learners'] = '<a class="'.$learners_class.'" href="'.esc_url(add_query_arg($learner_args, admin_url('admin.php'))).'">'.__('Learners', 'woothemes-sensei').'</a>';
628
+		$menu['courses'] = '<a class="'.$courses_class.'" href="'.esc_url(add_query_arg($courses_args, admin_url('admin.php'))).'">'.__('Courses', 'woothemes-sensei').'</a>';
629
+		$menu['lessons'] = '<a class="'.$lessons_class.'" href="'.esc_url(add_query_arg($lesson_args, admin_url('admin.php'))).'">'.__('Lessons', 'woothemes-sensei').'</a>';
630 630
 
631
-		$menu = apply_filters( 'sensei_analysis_overview_sub_menu', $menu );
632
-		if ( !empty($menu) ) {
633
-			echo '<ul class="subsubsub">' . "\n";
634
-			foreach ( $menu as $class => $item ) {
635
-				$menu[ $class ] = "\t<li class='$class'>$item";
631
+		$menu = apply_filters('sensei_analysis_overview_sub_menu', $menu);
632
+		if ( ! empty($menu)) {
633
+			echo '<ul class="subsubsub">'."\n";
634
+			foreach ($menu as $class => $item) {
635
+				$menu[$class] = "\t<li class='$class'>$item";
636 636
 			}
637
-			echo implode( " |</li>\n", $menu ) . "</li>\n";
638
-			echo '</ul>' . "\n";
637
+			echo implode(" |</li>\n", $menu)."</li>\n";
638
+			echo '</ul>'."\n";
639 639
 		}
640 640
 	} // End data_table_header()
641 641
 
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 	 * @return void
646 646
 	 */
647 647
 	public function data_table_footer() {
648
-		switch ( $this->type ) {
648
+		switch ($this->type) {
649 649
 			case 'courses':
650 650
 				$report = 'courses-overview';
651 651
 				break;
@@ -659,8 +659,8 @@  discard block
 block discarded – undo
659 659
 				$report = 'user-overview';
660 660
 			break;
661 661
 		} // End Switch Statement
662
-		$url = add_query_arg( array( 'page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report ), admin_url( 'admin.php' ) );
663
-		echo '<a class="button button-primary" href="' . esc_url( wp_nonce_url( $url, 'sensei_csv_download-' . $report, '_sdl_nonce' ) ) . '">' . __( 'Export all rows (CSV)', 'woothemes-sensei' ) . '</a>';
662
+		$url = add_query_arg(array('page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report), admin_url('admin.php'));
663
+		echo '<a class="button button-primary" href="'.esc_url(wp_nonce_url($url, 'sensei_csv_download-'.$report, '_sdl_nonce')).'">'.__('Export all rows (CSV)', 'woothemes-sensei').'</a>';
664 664
 	} // End data_table_footer()
665 665
 
666 666
 	/**
@@ -668,19 +668,19 @@  discard block
 block discarded – undo
668 668
 	 * @since  1.7.0
669 669
 	 * @return string $text
670 670
 	 */
671
-	public function search_button( $text = '' ) {
672
-		switch( $this->type ) {
671
+	public function search_button($text = '') {
672
+		switch ($this->type) {
673 673
 			case 'courses':
674
-				$text = __( 'Search Courses', 'woothemes-sensei' );
674
+				$text = __('Search Courses', 'woothemes-sensei');
675 675
 			break;
676 676
 
677 677
 			case 'lessons':
678
-				$text = __( 'Search Lessons', 'woothemes-sensei' );
678
+				$text = __('Search Lessons', 'woothemes-sensei');
679 679
 			break;
680 680
 
681 681
 			case 'users':
682 682
 			default:
683
-				$text = __( 'Search Learners', 'woothemes-sensei' );
683
+				$text = __('Search Learners', 'woothemes-sensei');
684 684
 			break;
685 685
 		} // End Switch Statement
686 686
 
Please login to merge, or discard this patch.
includes/class-sensei-teacher.php 4 patches
Braces   +11 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,5 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// Exit if accessed directly
3 6
 
4 7
 /**
5 8
  * Sensei Teacher class
@@ -414,7 +417,7 @@  discard block
 block discarded – undo
414 417
                     $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
415 418
                     $term_id = $existing_term->term_id;
416 419
 
417
-                }else{
420
+                } else{
418 421
 
419 422
                     // for a new term simply get the term from the returned value
420 423
                     $term_id = $new_term['term_id'];
@@ -495,7 +498,7 @@  discard block
 block discarded – undo
495 498
                         'post_author' =>  $new_author
496 499
                     ) );
497 500
                 }
498
-            }else{
501
+            } else{
499 502
                 wp_update_post( array(
500 503
                     'ID'           => $lesson_quizzes,
501 504
                     'post_author' =>  $new_author
@@ -789,7 +792,7 @@  discard block
 block discarded – undo
789 792
             // merge the post types instead of overwriting it
790 793
             $new_post_types = array_merge( $current_post_types, array( 'course' ) );
791 794
 
792
-        }else{
795
+        } else{
793 796
 
794 797
             // in this instance it is probably just one post type in string format
795 798
             $new_post_types =  array( $current_post_types , 'course');
@@ -979,7 +982,7 @@  discard block
 block discarded – undo
979 982
                     $course_learner_ids[] = $user->ID;
980 983
                 }
981 984
 
982
-            }else{
985
+            } else{
983 986
 
984 987
                 $user = get_userdata( $activity_comments->user_id );
985 988
                 $course_learner_ids[] = $user->ID;
@@ -996,7 +999,7 @@  discard block
 block discarded – undo
996 999
 
997 1000
             $args[ 'include'] = array( 0 );
998 1001
 
999
-        }else{
1002
+        } else{
1000 1003
 
1001 1004
             $args[ 'include'] = $learner_ids_for_teacher_courses;
1002 1005
 
@@ -1164,7 +1167,7 @@  discard block
 block discarded – undo
1164 1167
 
1165 1168
                 $teachers_courses[] = $course->ID;
1166 1169
 
1167
-            }else{
1170
+            } else{
1168 1171
 
1169 1172
                 $teachers_courses[] = $course;
1170 1173
 
@@ -1534,7 +1537,7 @@  discard block
 block discarded – undo
1534 1537
 
1535 1538
             return true;
1536 1539
 
1537
-        }else{
1540
+        } else{
1538 1541
 
1539 1542
             return false;
1540 1543
 
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
      * @since 1.8.0
453 453
      * @access public
454 454
      * @parameters
455
-     * @return array $users user id array
455
+     * @return boolean $users user id array
456 456
      */
457 457
     public function update_course_lessons_author ( $course_id, $new_author  ){
458 458
 
@@ -841,8 +841,7 @@  discard block
 block discarded – undo
841 841
      * This function hooks into wp_insert_post
842 842
      *
843 843
      * @since 1.8.0
844
-     * @param int $course_id
845
-     * @return bool
844
+     * @return false|null
846 845
      */
847 846
     public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
848 847
 
Please login to merge, or discard this patch.
Indentation   +1339 added lines, -1339 removed lines patch added patch discarded remove patch
@@ -12,251 +12,251 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class Sensei_Teacher {
14 14
 
15
-    /**
16
-     * $teacher_role
17
-     *
18
-     * Keeps a reference to the teacher role object
19
-     *
20
-     * @access protected
21
-     * @since 1.8.0
22
-     */
23
-    protected $teacher_role;
24
-
25
-    /**
26
-     * $token
27
-     *
28
-     * Keeps a reference to the global sensei token
29
-     *
30
-     * @access protected
31
-     * @since 1.8.0
32
-     */
33
-    public  $token;
34
-
35
-    /**
36
-     * Sensei_Teacher::__constructor
37
-     *
38
-     * Constructor Function
39
-     *
40
-     * @since 1.8.0
41
-     * @access public
42
-     */
43
-    public function __construct ( ) {
44
-
45
-        add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
46
-        add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
47
-        add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
48
-        add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
49
-        add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
50
-
51
-        add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
52
-
53
-        //filter the quiz submissions
54
-        add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
55
-
56
-        //grading totals count only those belonging to the teacher
57
-        add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
58
-
59
-        // show the courses owned by a user on his author archive page
60
-        add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
61
-
62
-        // notify admin when a teacher creates a course
63
-        add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
64
-
65
-        // limit the analysis view to only the users taking courses belong to this teacher
66
-        add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
67
-
68
-        // give teacher access to question post type
69
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
70
-
71
-        // Teacher column on the courses list on the admin edit screen
72
-        add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
73
-        add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
74
-
75
-        //admin edit messages query limit teacher
76
-        add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
77
-
78
-        //add filter by teacher on courses list
79
-        add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
80
-        add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
81
-
82
-        // Handle media library restrictions
83
-        add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
84
-        add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
85
-
86
-        // update lesson owner to course teacher when saved
87
-        add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
88
-
89
-        // If a Teacher logs in, redirect to /wp-admin/
90
-        add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
91
-
92
-
93
-        add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
94
-        add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
95
-
96
-
97
-    } // end __constructor()
98
-
99
-    /**
100
-     * Sensei_Teacher::create_teacher_role
101
-     *
102
-     * This function checks if the role exist, if not it creates it.
103
-     * for the teacher role
104
-     *
105
-     * @since 1.8.0
106
-     * @access public
107
-     * @return void
108
-     */
109
-    public function create_role ( ) {
110
-
111
-        // check if the role exists
112
-        $this->teacher_role = get_role( 'teacher' );
113
-
114
-        // if the the teacher is not a valid WordPress role create it
115
-       if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
116
-           // create the role
117
-           $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
118
-       }
119
-
120
-       // add the capabilities before returning
121
-        $this->add_capabilities();
122
-
123
-    }// end create_teacher_role
124
-
125
-    /**
126
-     * Sensei_Teacher::add_capabilities
127
-     *
128
-     * @since 1.8.0
129
-     * @access protected
130
-     */
131
-    protected function add_capabilities ( ) {
132
-
133
-        // if this is not a valid WP_Role object exit without adding anything
134
-        if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
135
-            return;
136
-        }
137
-
138
-        /**
139
-         * Sensei teachers capabilities array filter
140
-         *
141
-         * These capabilities will be applied to the teacher role
142
-         * @param array $capabilities
143
-         * keys: (string) $cap_name => (bool) $grant
144
-         */
145
-        $caps = apply_filters( 'sensei_teacher_role_capabilities', array(
146
-            // General access rules
147
-            'read' => true,
148
-            'manage_sensei_grades' => true,
149
-            'moderate_comments'=> true,
150
-            'upload_files'	=> true,
151
-            'edit_files'	=> true,
152
-
153
-            //Lessons
154
-            'publish_lessons'	 => true,
155
-            'manage_lesson_categories'	 => true,
156
-            'edit_lessons'	 => true,
157
-            'edit_published_lessons'  => true,
158
-            'edit_private_lessons' => true,
159
-            'read_private_lessons' => true,
160
-            'delete_published_lessons' => true,
161
-
162
-            // Courses
163
-            'create_courses' => true,
164
-            'publish_courses'	 => false,
165
-            'manage_course_categories'	 => true,
166
-            'edit_courses'	 => true,
167
-            'edit_published_courses'  => true,
168
-            'edit_private_courses' => true,
169
-            'read_private_courses' => true,
170
-            'delete_published_courses' => true,
171
-
172
-            // Quiz
173
-            'publish_quizzes'	 => true,
174
-            'edit_quizzes'	 => true,
175
-            'edit_published_quizzes'  => true,
176
-            'edit_private_quizzes' => true,
177
-            'read_private_quizzes' => true,
178
-
179
-            // Questions
180
-            'publish_questions'	 => true,
181
-            'edit_questions'	 => true,
182
-            'edit_published_questions'  => true,
183
-            'edit_private_questions' => true,
184
-            'read_private_questions' => true,
185
-
186
-            //messages
187
-            'publish_sensei_messages'	 => true,
188
-            'edit_sensei_messages'	 => true,
189
-            'edit_published_sensei_messages'  => true,
190
-            'edit_private_sensei_messages' => true,
191
-            'read_private_sensei_messages' => true,
192
-
193
-            // Comments -
194
-            // Necessary cap so Teachers can moderate comments
195
-            // on their own lessons. We restrict access to other
196
-            // post types in $this->restrict_posts_menu_page()
197
-
198
-            'edit_posts' => true,
199
-
200
-        ));
201
-
202
-        foreach ( $caps as $cap => $grant ) {
203
-
204
-            // load the capability on to the teacher role
205
-            $this->teacher_role->add_cap($cap, $grant);
206
-
207
-        } // end for each
208
-
209
-    }// end add_cap
210
-
211
-    /**
212
-     * Sensei_Teacher::teacher_meta_box
213
-     *
214
-     * Add the teacher metabox to the course post type edit screen
215
-     *
216
-     * @since 1.8.0
217
-     * @access public
218
-     * @parameter string $post_type
219
-     * @parameter WP_Post $post
220
-     * @return void
221
-     */
222
-    public function add_teacher_meta_boxes ( $post ) {
223
-
224
-        if( !current_user_can('manage_options') ){
225
-            return;
226
-        }
227
-        add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
228
-            'course',
229
-            'side',
230
-            'core'
231
-        );
232
-
233
-    } // end teacher_meta_box()
234
-
235
-    /**
236
-     * Sensei_Teacher::teacher_meta_box_content
237
-     *
238
-     * Render the teacher meta box markup
239
-     *
240
-     * @since 1.8.0
241
-     * @access public
242
-     * @parameters
243
-     */
244
-    public function teacher_meta_box_content ( $post ) {
245
-
246
-        // get the current author
247
-        $current_author = $post->post_author;
248
-
249
-        //get the users authorised to author courses
250
-        $users = $this->get_teachers_and_authors();
251
-
252
-    ?>
15
+	/**
16
+	 * $teacher_role
17
+	 *
18
+	 * Keeps a reference to the teacher role object
19
+	 *
20
+	 * @access protected
21
+	 * @since 1.8.0
22
+	 */
23
+	protected $teacher_role;
24
+
25
+	/**
26
+	 * $token
27
+	 *
28
+	 * Keeps a reference to the global sensei token
29
+	 *
30
+	 * @access protected
31
+	 * @since 1.8.0
32
+	 */
33
+	public  $token;
34
+
35
+	/**
36
+	 * Sensei_Teacher::__constructor
37
+	 *
38
+	 * Constructor Function
39
+	 *
40
+	 * @since 1.8.0
41
+	 * @access public
42
+	 */
43
+	public function __construct ( ) {
44
+
45
+		add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
46
+		add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
47
+		add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
48
+		add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
49
+		add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
50
+
51
+		add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
52
+
53
+		//filter the quiz submissions
54
+		add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
55
+
56
+		//grading totals count only those belonging to the teacher
57
+		add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
58
+
59
+		// show the courses owned by a user on his author archive page
60
+		add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
61
+
62
+		// notify admin when a teacher creates a course
63
+		add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
64
+
65
+		// limit the analysis view to only the users taking courses belong to this teacher
66
+		add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
67
+
68
+		// give teacher access to question post type
69
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
70
+
71
+		// Teacher column on the courses list on the admin edit screen
72
+		add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
73
+		add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
74
+
75
+		//admin edit messages query limit teacher
76
+		add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
77
+
78
+		//add filter by teacher on courses list
79
+		add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
80
+		add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
81
+
82
+		// Handle media library restrictions
83
+		add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
84
+		add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
85
+
86
+		// update lesson owner to course teacher when saved
87
+		add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
88
+
89
+		// If a Teacher logs in, redirect to /wp-admin/
90
+		add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
91
+
92
+
93
+		add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
94
+		add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
95
+
96
+
97
+	} // end __constructor()
98
+
99
+	/**
100
+	 * Sensei_Teacher::create_teacher_role
101
+	 *
102
+	 * This function checks if the role exist, if not it creates it.
103
+	 * for the teacher role
104
+	 *
105
+	 * @since 1.8.0
106
+	 * @access public
107
+	 * @return void
108
+	 */
109
+	public function create_role ( ) {
110
+
111
+		// check if the role exists
112
+		$this->teacher_role = get_role( 'teacher' );
113
+
114
+		// if the the teacher is not a valid WordPress role create it
115
+	   if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
116
+		   // create the role
117
+		   $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
118
+	   }
119
+
120
+	   // add the capabilities before returning
121
+		$this->add_capabilities();
122
+
123
+	}// end create_teacher_role
124
+
125
+	/**
126
+	 * Sensei_Teacher::add_capabilities
127
+	 *
128
+	 * @since 1.8.0
129
+	 * @access protected
130
+	 */
131
+	protected function add_capabilities ( ) {
132
+
133
+		// if this is not a valid WP_Role object exit without adding anything
134
+		if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
135
+			return;
136
+		}
137
+
138
+		/**
139
+		 * Sensei teachers capabilities array filter
140
+		 *
141
+		 * These capabilities will be applied to the teacher role
142
+		 * @param array $capabilities
143
+		 * keys: (string) $cap_name => (bool) $grant
144
+		 */
145
+		$caps = apply_filters( 'sensei_teacher_role_capabilities', array(
146
+			// General access rules
147
+			'read' => true,
148
+			'manage_sensei_grades' => true,
149
+			'moderate_comments'=> true,
150
+			'upload_files'	=> true,
151
+			'edit_files'	=> true,
152
+
153
+			//Lessons
154
+			'publish_lessons'	 => true,
155
+			'manage_lesson_categories'	 => true,
156
+			'edit_lessons'	 => true,
157
+			'edit_published_lessons'  => true,
158
+			'edit_private_lessons' => true,
159
+			'read_private_lessons' => true,
160
+			'delete_published_lessons' => true,
161
+
162
+			// Courses
163
+			'create_courses' => true,
164
+			'publish_courses'	 => false,
165
+			'manage_course_categories'	 => true,
166
+			'edit_courses'	 => true,
167
+			'edit_published_courses'  => true,
168
+			'edit_private_courses' => true,
169
+			'read_private_courses' => true,
170
+			'delete_published_courses' => true,
171
+
172
+			// Quiz
173
+			'publish_quizzes'	 => true,
174
+			'edit_quizzes'	 => true,
175
+			'edit_published_quizzes'  => true,
176
+			'edit_private_quizzes' => true,
177
+			'read_private_quizzes' => true,
178
+
179
+			// Questions
180
+			'publish_questions'	 => true,
181
+			'edit_questions'	 => true,
182
+			'edit_published_questions'  => true,
183
+			'edit_private_questions' => true,
184
+			'read_private_questions' => true,
185
+
186
+			//messages
187
+			'publish_sensei_messages'	 => true,
188
+			'edit_sensei_messages'	 => true,
189
+			'edit_published_sensei_messages'  => true,
190
+			'edit_private_sensei_messages' => true,
191
+			'read_private_sensei_messages' => true,
192
+
193
+			// Comments -
194
+			// Necessary cap so Teachers can moderate comments
195
+			// on their own lessons. We restrict access to other
196
+			// post types in $this->restrict_posts_menu_page()
197
+
198
+			'edit_posts' => true,
199
+
200
+		));
201
+
202
+		foreach ( $caps as $cap => $grant ) {
203
+
204
+			// load the capability on to the teacher role
205
+			$this->teacher_role->add_cap($cap, $grant);
206
+
207
+		} // end for each
208
+
209
+	}// end add_cap
210
+
211
+	/**
212
+	 * Sensei_Teacher::teacher_meta_box
213
+	 *
214
+	 * Add the teacher metabox to the course post type edit screen
215
+	 *
216
+	 * @since 1.8.0
217
+	 * @access public
218
+	 * @parameter string $post_type
219
+	 * @parameter WP_Post $post
220
+	 * @return void
221
+	 */
222
+	public function add_teacher_meta_boxes ( $post ) {
223
+
224
+		if( !current_user_can('manage_options') ){
225
+			return;
226
+		}
227
+		add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
228
+			'course',
229
+			'side',
230
+			'core'
231
+		);
232
+
233
+	} // end teacher_meta_box()
234
+
235
+	/**
236
+	 * Sensei_Teacher::teacher_meta_box_content
237
+	 *
238
+	 * Render the teacher meta box markup
239
+	 *
240
+	 * @since 1.8.0
241
+	 * @access public
242
+	 * @parameters
243
+	 */
244
+	public function teacher_meta_box_content ( $post ) {
245
+
246
+		// get the current author
247
+		$current_author = $post->post_author;
248
+
249
+		//get the users authorised to author courses
250
+		$users = $this->get_teachers_and_authors();
251
+
252
+	?>
253 253
         <select name="sensei-course-teacher-author" class="sensei course teacher">
254 254
 
255 255
             <?php foreach ( $users as $user_id ) { ?>
256 256
 
257 257
                     <?php
258
-                        $user = get_user_by('id', $user_id);
259
-                    ?>
258
+						$user = get_user_by('id', $user_id);
259
+					?>
260 260
                     <option <?php selected(  $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" >
261 261
                         <?php echo  $user->display_name; ?>
262 262
                     </option>
@@ -267,1289 +267,1289 @@  discard block
 block discarded – undo
267 267
 
268 268
         <?php
269 269
 
270
-    } // end render_teacher_meta_box()
271
-
272
-    /**
273
-     * Sensei_Teacher::get_teachers_and_authors
274
-     *
275
-     * Get a list of users who can author courses, lessons and quizes.
276
-     *
277
-     * @since 1.8.0
278
-     * @access public
279
-     * @parameters
280
-     * @return array $users user id array
281
-     */
282
-    public function get_teachers_and_authors ( ){
283
-
284
-        $author_query_args = array(
285
-            'blog_id'      => $GLOBALS['blog_id'],
286
-            'fields'       => 'any',
287
-            'who'          => 'authors'
288
-        );
289
-
290
-        $authors = get_users( $author_query_args );
291
-
292
-        $teacher_query_args = array(
293
-            'blog_id'      => $GLOBALS['blog_id'],
294
-            'fields'       => 'any',
295
-            'role'         => 'teacher',
296
-        );
297
-
298
-        $teachers = get_users( $teacher_query_args );
299
-
300
-        return  array_unique( array_merge( $teachers, $authors ) );
301
-
302
-    }// end get_teachers_and_authors
303
-
304
-    /**
305
-     * Sensei_Teacher::save_teacher_meta_box
306
-     *
307
-     * Save the new teacher / author to course and all lessons
308
-     *
309
-     * Hooked into admin_init
310
-     *
311
-     * @since 1.8.0
312
-     * @access public
313
-     * @parameters
314
-     * @return array $users user id array
315
-     */
316
-    public function save_teacher_meta_box ( $course_id ){
270
+	} // end render_teacher_meta_box()
271
+
272
+	/**
273
+	 * Sensei_Teacher::get_teachers_and_authors
274
+	 *
275
+	 * Get a list of users who can author courses, lessons and quizes.
276
+	 *
277
+	 * @since 1.8.0
278
+	 * @access public
279
+	 * @parameters
280
+	 * @return array $users user id array
281
+	 */
282
+	public function get_teachers_and_authors ( ){
283
+
284
+		$author_query_args = array(
285
+			'blog_id'      => $GLOBALS['blog_id'],
286
+			'fields'       => 'any',
287
+			'who'          => 'authors'
288
+		);
289
+
290
+		$authors = get_users( $author_query_args );
291
+
292
+		$teacher_query_args = array(
293
+			'blog_id'      => $GLOBALS['blog_id'],
294
+			'fields'       => 'any',
295
+			'role'         => 'teacher',
296
+		);
297
+
298
+		$teachers = get_users( $teacher_query_args );
299
+
300
+		return  array_unique( array_merge( $teachers, $authors ) );
301
+
302
+	}// end get_teachers_and_authors
303
+
304
+	/**
305
+	 * Sensei_Teacher::save_teacher_meta_box
306
+	 *
307
+	 * Save the new teacher / author to course and all lessons
308
+	 *
309
+	 * Hooked into admin_init
310
+	 *
311
+	 * @since 1.8.0
312
+	 * @access public
313
+	 * @parameters
314
+	 * @return array $users user id array
315
+	 */
316
+	public function save_teacher_meta_box ( $course_id ){
317 317
 
318
-        // check if this is a post from saving the teacher, if not exit early
319
-        if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
320
-            return;
321
-        }
318
+		// check if this is a post from saving the teacher, if not exit early
319
+		if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
320
+			return;
321
+		}
322 322
 
323
-        //don't fire this hook again
324
-        remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
323
+		//don't fire this hook again
324
+		remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
325 325
 
326
-        // get the current post object
327
-        $post = get_post( $course_id );
326
+		// get the current post object
327
+		$post = get_post( $course_id );
328 328
 
329
-        // get the current teacher/author
330
-        $current_author = absint( $post->post_author );
331
-        $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
329
+		// get the current teacher/author
330
+		$current_author = absint( $post->post_author );
331
+		$new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
332 332
 
333
-        // loop through all post lessons to update their authors as well
334
-        $this->update_course_lessons_author( $course_id , $new_author );
333
+		// loop through all post lessons to update their authors as well
334
+		$this->update_course_lessons_author( $course_id , $new_author );
335 335
 
336
-        // do not do any processing if the selected author is the same as the current author
337
-        if( $current_author == $new_author ){
338
-            return;
339
-        }
336
+		// do not do any processing if the selected author is the same as the current author
337
+		if( $current_author == $new_author ){
338
+			return;
339
+		}
340 340
 
341
-        // save the course  author
342
-        $post_updates = array(
343
-            'ID' => $post->ID ,
344
-            'post_author' => $new_author
345
-        );
346
-        wp_update_post( $post_updates );
341
+		// save the course  author
342
+		$post_updates = array(
343
+			'ID' => $post->ID ,
344
+			'post_author' => $new_author
345
+		);
346
+		wp_update_post( $post_updates );
347 347
 
348
-        // ensure the the modules are update so that then new teacher has access to them
349
-        Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
348
+		// ensure the the modules are update so that then new teacher has access to them
349
+		Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
350 350
 
351
-        // notify the new teacher
352
-        $this->teacher_course_assigned_notification( $new_author, $course_id );
351
+		// notify the new teacher
352
+		$this->teacher_course_assigned_notification( $new_author, $course_id );
353 353
 
354
-    } // end save_teacher_meta_box
354
+	} // end save_teacher_meta_box
355 355
 
356
-    /**
357
-     * Update all the course terms set(selected) on the given course. Moving course term ownership to
358
-     * the new author. Making sure the course terms are maintained.
359
-     *
360
-     * This function also checks if terms are shared, with other courses
361
-     *
362
-     * @param $course_id
363
-     * @param $new_teacher_id
364
-     * @return void
365
-     */
366
-    public static function update_course_modules_author( $course_id ,$new_teacher_id ){
356
+	/**
357
+	 * Update all the course terms set(selected) on the given course. Moving course term ownership to
358
+	 * the new author. Making sure the course terms are maintained.
359
+	 *
360
+	 * This function also checks if terms are shared, with other courses
361
+	 *
362
+	 * @param $course_id
363
+	 * @param $new_teacher_id
364
+	 * @return void
365
+	 */
366
+	public static function update_course_modules_author( $course_id ,$new_teacher_id ){
367 367
 
368
-        if( empty( $course_id ) || empty( $new_teacher_id ) ){
369
-            return;
370
-        }
368
+		if( empty( $course_id ) || empty( $new_teacher_id ) ){
369
+			return;
370
+		}
371 371
 
372
-        $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
372
+		$terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
373 373
 
374
-        if( empty( $terms_selected_on_course ) ){
375
-            return;
376
-        }
374
+		if( empty( $terms_selected_on_course ) ){
375
+			return;
376
+		}
377 377
 
378
-        foreach( $terms_selected_on_course as $term ){
378
+		foreach( $terms_selected_on_course as $term ){
379 379
 
380
-            $term_author = Sensei_Core_Modules::get_term_author( $term->slug );
381
-            if( $new_teacher_id != $term_author->ID  ){
380
+			$term_author = Sensei_Core_Modules::get_term_author( $term->slug );
381
+			if( $new_teacher_id != $term_author->ID  ){
382 382
 
383
-                $new_term = '';
383
+				$new_term = '';
384 384
 
385
-                //if the new teacher is admin first check to see if the term with this name already exists
386
-                if( user_can( $new_teacher_id, 'manage_options' ) ){
385
+				//if the new teacher is admin first check to see if the term with this name already exists
386
+				if( user_can( $new_teacher_id, 'manage_options' ) ){
387 387
 
388
-                    $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
389
-                    $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
390
-                    $existing_admin_terms = get_terms( 'module', $term_args );
391
-                    if( !empty( $existing_admin_terms ) ){
392
-                        // insert it even if it exists
393
-                        $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
394
-                    }
395
-                }
388
+					$slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
389
+					$term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
390
+					$existing_admin_terms = get_terms( 'module', $term_args );
391
+					if( !empty( $existing_admin_terms ) ){
392
+						// insert it even if it exists
393
+						$new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
394
+					}
395
+				}
396 396
 
397
-                if( empty ( $new_term ) ){
397
+				if( empty ( $new_term ) ){
398 398
 
399
-                   //setup the new slug
400
-                   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
401
-
402
-                   // create new term and set it
403
-                   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
404
-
405
-                }
399
+				   //setup the new slug
400
+				   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
401
+
402
+				   // create new term and set it
403
+				   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
404
+
405
+				}
406 406
 
407 407
 
408 408
 
409
-                // if term exists
410
-                if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
409
+				// if term exists
410
+				if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
411 411
 
412
-                    $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
413
-                    $term_id = $existing_term->term_id;
412
+					$existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
413
+					$term_id = $existing_term->term_id;
414 414
 
415
-                }else{
415
+				}else{
416 416
 
417
-                    // for a new term simply get the term from the returned value
418
-                    $term_id = $new_term['term_id'];
417
+					// for a new term simply get the term from the returned value
418
+					$term_id = $new_term['term_id'];
419 419
 
420
-                } // end if term exist
420
+				} // end if term exist
421 421
 
422
-                // set the terms selected on the course
423
-                wp_set_object_terms( $course_id, $term_id , 'module', true );
422
+				// set the terms selected on the course
423
+				wp_set_object_terms( $course_id, $term_id , 'module', true );
424 424
 
425
-                // remove old term
426
-                wp_remove_object_terms( $course_id, $term->term_id, 'module' );
425
+				// remove old term
426
+				wp_remove_object_terms( $course_id, $term->term_id, 'module' );
427 427
 
428
-                // update the lessons within the current module term
429
-                $lessons = Sensei()->course->course_lessons( $course_id );
430
-                foreach( $lessons as $lesson  ){
428
+				// update the lessons within the current module term
429
+				$lessons = Sensei()->course->course_lessons( $course_id );
430
+				foreach( $lessons as $lesson  ){
431 431
 
432
-                    if( has_term( $term->slug, 'module', $lesson ) ){
432
+					if( has_term( $term->slug, 'module', $lesson ) ){
433 433
 
434
-                        // add the new term, the false at the end says to replace all terms on this module
435
-                        // with the new term.
436
-                        wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
437
-                        update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
438
-                    }
434
+						// add the new term, the false at the end says to replace all terms on this module
435
+						// with the new term.
436
+						wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
437
+						update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
438
+					}
439 439
 
440
-                }// end for each
440
+				}// end for each
441 441
 
442
-            }
443
-        }
442
+			}
443
+		}
444 444
 
445
-    }// end update_course_module_terms_author
445
+	}// end update_course_module_terms_author
446 446
 
447
-    /**
448
-     * Sensei_Teacher::update_course_lessons_author
449
-     *
450
-     * Update all course lessons and their quiz with a new author
451
-     *
452
-     * @since 1.8.0
453
-     * @access public
454
-     * @parameters
455
-     * @return array $users user id array
456
-     */
457
-    public function update_course_lessons_author ( $course_id, $new_author  ){
447
+	/**
448
+	 * Sensei_Teacher::update_course_lessons_author
449
+	 *
450
+	 * Update all course lessons and their quiz with a new author
451
+	 *
452
+	 * @since 1.8.0
453
+	 * @access public
454
+	 * @parameters
455
+	 * @return array $users user id array
456
+	 */
457
+	public function update_course_lessons_author ( $course_id, $new_author  ){
458 458
 
459 459
 
460
-        if( empty( $course_id ) || empty( $new_author ) ){
461
-            return false;
462
-        }
460
+		if( empty( $course_id ) || empty( $new_author ) ){
461
+			return false;
462
+		}
463 463
 
464
-        //get a list of course lessons
465
-        $lessons = Sensei()->course->course_lessons( $course_id );
464
+		//get a list of course lessons
465
+		$lessons = Sensei()->course->course_lessons( $course_id );
466 466
 
467
-        if( empty( $lessons )  ||  ! is_array( $lessons )  ){
468
-            return false;
469
-        }
467
+		if( empty( $lessons )  ||  ! is_array( $lessons )  ){
468
+			return false;
469
+		}
470 470
 
471
-        // update each lesson and quiz author
472
-        foreach( $lessons as $lesson ){
471
+		// update each lesson and quiz author
472
+		foreach( $lessons as $lesson ){
473 473
 
474
-            // don't update if the author is tha same as the new author
475
-            if( $new_author == $lesson->post_author ){
476
-                continue;
477
-            }
474
+			// don't update if the author is tha same as the new author
475
+			if( $new_author == $lesson->post_author ){
476
+				continue;
477
+			}
478 478
 
479
-            // update lesson author
480
-            wp_update_post( array(
481
-                'ID'=> $lesson->ID,
482
-                'post_author' => $new_author
483
-                ) );
479
+			// update lesson author
480
+			wp_update_post( array(
481
+				'ID'=> $lesson->ID,
482
+				'post_author' => $new_author
483
+				) );
484 484
 
485
-            // update quiz author
486
-            //get the lessons quiz
487
-            $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
488
-            if( is_array( $lesson_quizzes ) ){
489
-                foreach ( $lesson_quizzes as $quiz_id ) {
490
-                    // update quiz with new author
491
-                    wp_update_post( array(
492
-                        'ID'           => $quiz_id,
493
-                        'post_author' =>  $new_author
494
-                    ) );
495
-                }
496
-            }else{
497
-                wp_update_post( array(
498
-                    'ID'           => $lesson_quizzes,
499
-                    'post_author' =>  $new_author
500
-                ) );
501
-            }
485
+			// update quiz author
486
+			//get the lessons quiz
487
+			$lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
488
+			if( is_array( $lesson_quizzes ) ){
489
+				foreach ( $lesson_quizzes as $quiz_id ) {
490
+					// update quiz with new author
491
+					wp_update_post( array(
492
+						'ID'           => $quiz_id,
493
+						'post_author' =>  $new_author
494
+					) );
495
+				}
496
+			}else{
497
+				wp_update_post( array(
498
+					'ID'           => $lesson_quizzes,
499
+					'post_author' =>  $new_author
500
+				) );
501
+			}
502 502
 
503
-        } // end for each lessons
503
+		} // end for each lessons
504 504
 
505
-        return true;
505
+		return true;
506 506
 
507
-    }// end update_course_lessons_author
508
-
509
-
510
-
511
-    /**
512
-     * Sensei_Teacher::course_analysis_teacher_access_limit
513
-     *
514
-     * Alter the query so that users can only see their courses on the analysis page
515
-     *
516
-     * @since 1.8.0
517
-     * @access public
518
-     * @parameters $query
519
-     * @return array $users user id array
520
-     */
521
-    public function course_analysis_teacher_access_limit ( $query ) {
522
-
523
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
524
-            return $query;
525
-        }
526
-
527
-        if ( ! function_exists( 'get_current_screen' ) ) {
528
-            return $query;
529
-        }
530
-
531
-        $screen = get_current_screen();
532
-        $sensei_post_types = array('course', 'lesson', 'question' );
533
-
534
-        // exit early for the following conditions
535
-        $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
536
-
537
-        if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
538
-            || ! in_array( $query->query['post_type'], $sensei_post_types ) ){
539
-            return $query;
540
-        }
541
-
542
-        global $current_user;
543
-        // set the query author to the current user to only show those those posts
544
-        $query->set( 'author', $current_user->ID );
545
-        return $query;
546
-
547
-    }// end course_analysis_teacher_access_limit
548
-
549
-
550
-    /**
551
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
552
-     *
553
-     * Determine if we're in admin and the current logged in use is a teacher
554
-     *
555
-     * @since 1.8.0
556
-     * @access public
557
-     * @parameters array $wp_query
558
-     * @return bool $is_admin_teacher
559
-     */
560
-    public function is_admin_teacher ( ){
561
-
562
-        if( ! is_user_logged_in()){
563
-            return false;
564
-        }
565
-        $is_admin_teacher = false;
566
-
567
-        if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
568
-
569
-            $is_admin_teacher = true;
570
-
571
-        }
572
-
573
-        return $is_admin_teacher;
574
-
575
-    } // end is_admin_teacher
576
-
577
-    /**
578
-     * Show correct post counts on list table for Sensei post types
579
-     *
580
-     * @since 1.8.0
581
-     *
582
-     * @param  object $counts Default status counts
583
-     * @param  string $type   Current post type
584
-     * @param  string $perm   User permission level
585
-     * @return object         Modified status counts
586
-     */
587
-    public function list_table_counts( $counts, $type, $perm ) {
588
-        global $current_user;
589
-
590
-        if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
591
-            return $counts;
592
-        }
593
-
594
-        if( ! $this->is_admin_teacher() ) {
595
-            return $counts;
596
-        }
597
-
598
-        $args = array(
599
-            'post_type' => $type,
600
-            'author' => $current_user->ID,
601
-            'posts_per_page' => -1
602
-        );
603
-
604
-         // Get all available statuses
605
-        $stati = get_post_stati();
606
-
607
-        // Update count object
608
-        foreach( $stati as $status ) {
609
-            $args['post_status'] = $status;
610
-            $posts = get_posts( $args );
611
-            $counts->$status = count( $posts );
612
-        }
613
-
614
-        return $counts;
615
-    }
616
-
617
-    /**
618
-     * Filter the post queries to show
619
-     * only lesson /course and users that belong
620
-     * to the current logged teacher.
621
-     *
622
-     * @since 1.8.0
623
-     *
624
-     */
625
-    public function filter_queries ( $query ) {
626
-        global $current_user;
627
-
628
-        if( ! $this->is_admin_teacher() ) {
629
-            return;
630
-        }
631
-
632
-        if ( ! function_exists( 'get_current_screen' ) ) {
633
-            return;
634
-        }
635
-
636
-        $screen = get_current_screen();
637
-        if( empty( $screen ) ) {
638
-            return $query;
639
-        }
640
-        switch( $screen->id ) {
641
-            case 'sensei_page_sensei_grading':
642
-            case 'sensei_page_sensei_analysis':
643
-            case 'sensei_page_sensei_learners':
644
-            case 'lesson':
645
-            case 'course':
646
-            case 'question':
647
-            case 'lesson_page_module-order':
648
-
649
-            /**
650
-             * sensei_filter_queries_set_author
651
-             * Filter the author Sensei set for queries
652
-             *
653
-             * @since 1.8.0
654
-             *
655
-             * @param int $user_id
656
-             * @param string $screen_id
657
-             *
658
-             */
659
-            $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
660
-            break;
661
-        }
662
-    }
663
-
664
-    /**
665
-     * Limit grading quizzes to only those within courses belonging to the current teacher
666
-     * . This excludes the admin user.
667
-     *
668
-     * @since 1.8.0
669
-     * @hooked into the_comments
670
-     * @param array  $comments
671
-     *
672
-     * @return array $comments
673
-     */
674
-    public function filter_grading_activity_queries( $comments ){
675
-
676
-        if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
677
-            return $comments ;
678
-        }
679
-
680
-        //check if we're on the grading screen
681
-        $screen = get_current_screen();
682
-
683
-        if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
684
-            return $comments;
685
-        }
686
-
687
-        // get the course and determine if the current teacher is the owner
688
-        // if not remove it from the list of comments to be returned
689
-        foreach( $comments as $key => $comment){
690
-            $lesson = get_post( $comment->comment_post_ID );
691
-            $course_id = Sensei()->lesson->get_course_id( $lesson->ID );
692
-            $course = get_post( $course_id );
693
-            if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
694
-                //remove this as the teacher should see this.
695
-                unset( $comments[ $key ] );
696
-            }
697
-        }
698
-        return $comments ;
699
-
700
-    }// end function filter grading
701
-
702
-    /**
703
-     * Limit the grading screen totals to only show lessons in the course
704
-     * belonging to the currently logged in teacher. This only applies to
705
-     * the teacher role.
706
-     *
707
-     * @since 1.8.0
708
-     *
709
-     * @hooked into sensei_count_statuses_args
710
-     * @param array $args
711
-     *
712
-     * @return array  $args
713
-     */
714
-    public function limit_grading_totals( $args ){
715
-
716
-        if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
717
-            return $args ;
718
-        }
719
-
720
-        //get the teachers courses
721
-        // the query is already filtered to only the teacher
722
-        $courses =  Sensei()->course->get_all_courses();
723
-
724
-        if( empty(  $courses ) || ! is_array( $courses ) ){
725
-            return $args;
726
-        }
727
-
728
-        //setup the lessons quizzes  to limit the grading totals to
729
-        $quiz_scope = array();
730
-        foreach( $courses as $course ){
731
-
732
-            $course_lessons = Sensei()->course->course_lessons( $course->ID );
733
-
734
-            if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
735
-
736
-                foreach(  $course_lessons as $lesson ){
737
-
738
-                    $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
739
-                    if( !empty( $quiz_id ) ) {
740
-
741
-                        array_push( $quiz_scope, $quiz_id );
742
-
743
-                    }
744
-
745
-                }
746
-
747
-            }
748
-
749
-        }
750
-
751
-        $args['post__in'] = $quiz_scope;
752
-
753
-        return $args;
754
-    }
755
-
756
-    /**
757
-     * It ensures that the author archive shows course by the current user.
758
-     *
759
-     * This function is hooked into the pre_get_posts filter
760
-     *
761
-     * @param WP_Query $query
762
-     * @return WP_Query $query
763
-     */
764
-    public function add_courses_to_author_archive( $query ) {
765
-
766
-        if ( is_admin() || ! $query->is_author() ){
767
-            return $query;
768
-        }
769
-
770
-        // this should only apply to users with the teacher role
771
-        $current_page_user = get_user_by('login', $query->get('author_name') );
772
-        if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
773
-
774
-            return $query;
775
-
776
-        }
777
-
778
-        // Change post types depending on what is set already
779
-        $current_post_types = $query->get( 'post_type' );
780
-        if( empty( $current_post_types  ) ){
781
-
782
-            // if empty it means post by default, so add post so that it also includes that for now
783
-            $new_post_types = array( 'post', 'course' );
784
-
785
-        } elseif( is_array( $current_post_types  ) ) {
786
-
787
-            // merge the post types instead of overwriting it
788
-            $new_post_types = array_merge( $current_post_types, array( 'course' ) );
789
-
790
-        }else{
791
-
792
-            // in this instance it is probably just one post type in string format
793
-            $new_post_types =  array( $current_post_types , 'course');
794
-
795
-        }
796
-
797
-        // change the query before returning it
798
-        $query->set('post_type', $new_post_types );
799
-
800
-        /**
801
-         * Change the query on the teacher author archive template
802
-         *
803
-         * @since 1.8.4
804
-         * @param WP_Query $query
805
-         */
806
-        return apply_filters( 'sensei_teacher_archive_query', $query );
807
-
808
-    }
809
-
810
-    /**
811
-     * Notify teacher when someone assigns a course to their account.
812
-     *
813
-     * @since 1.8.0
814
-     *
815
-     * @param $teacher_id
816
-     * @param $course_id
817
-     * @return bool
818
-     */
819
-    public function teacher_course_assigned_notification( $teacher_id, $course_id ){
820
-
821
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
822
-            return false;
823
-        }
824
-
825
-        // if new user is the same as the current logged user, they don't need an email
826
-        if( $teacher_id == get_current_user_id() ){
827
-            return true;
828
-        }
829
-
830
-        // load the email class
831
-        include('emails/class-sensei-email-teacher-new-course-assignment.php');
832
-        $email = new Sensei_Email_Teacher_New_Course_Assignment();
833
-        $email->trigger( $teacher_id, $course_id );
834
-
835
-        return true;
836
-    } // end  teacher_course_assigned_notification
837
-
838
-    /**
839
-     * Email the admin when a teacher creates a new course
840
-     *
841
-     * This function hooks into wp_insert_post
842
-     *
843
-     * @since 1.8.0
844
-     * @param int $course_id
845
-     * @return bool
846
-     */
847
-    public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
848
-
849
-        $course_id = $post->ID;
850
-
851
-        if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
852
-            || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
853
-
854
-            return false;
855
-
856
-        }
857
-
858
-        /**
859
-         * Filter the option to send admin notification emails when teachers creation
860
-         * course.
861
-         *
862
-         * @since 1.8.0
863
-         *
864
-         * @param bool $on default true
865
-         */
866
-        if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
867
-            return false;
868
-        }
869
-
870
-        // setting up the data needed by the email template
871
-        global $sensei_email_data;
872
-        $template = 'admin-teacher-new-course-created';
873
-        $course = get_post( $course_id );
874
-        $teacher = new WP_User( $course->post_author );
875
-        $recipient = get_option('admin_email', true);
876
-
877
-        // don't send if the course is created by admin
878
-        if( $recipient == $teacher->user_email ){
879
-            return;
880
-        }
881
-
882
-        /**
883
-         * Filter the email Header for the admin-teacher-new-course-created template
884
-         *
885
-         * @since 1.8.0
886
-         * @param string $template
887
-         */
888
-        $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
889
-
890
-        /**
891
-         * Filter the email subject for the the
892
-         * admin-teacher-new-course-created template
893
-         *
894
-         * @since 1.8.0
895
-         * @param string $subject default New course assigned to you
896
-         * @param string $template
897
-         */
898
-        $subject = apply_filters('sensei_email_subject',
899
-                                '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
900
-                                $template );
901
-
902
-        //course edit link
903
-        $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
904
-
905
-        // Construct data array
906
-        $email_data = array(
907
-            'template'			=> $template,
908
-            'heading' =>  $heading,
909
-            'teacher'		=> $teacher,
910
-            'course_id'			=> $course_id,
911
-            'course_name'			=> $course->post_title,
912
-            'course_edit_link' => $course_edit_link,
913
-        );
914
-
915
-        /**
916
-         * Filter the sensei email data for the admin-teacher-new-course-created template
917
-         *
918
-         * @since 1.8.0
919
-         * @param array $email_data
920
-         * @param string $template
921
-         */
922
-        $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
923
-
924
-        // Send mail
925
-        Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
926
-
927
-    }// end notify admin of course creation
928
-
929
-    /**
930
-     * Limit the analysis view to only the users taking courses belong to this teacher
931
-     *
932
-     * Hooked into sensei_analysis_get_learners
933
-     * @param array $args WP_User_Query arguments
934
-     * @return array $learners_query_results
935
-     */
936
-    public function limit_analysis_learners( $args ){
937
-
938
-        // show default for none teachers
939
-        if( ! Sensei()->teacher->is_admin_teacher() ) {
940
-                return $args;
941
-        }
942
-
943
-        // for teachers all courses only return those which belong to the teacher
944
-        // as they don't have access to course belonging to other users
945
-        $teacher_courses = Sensei()->course->get_all_courses();
507
+	}// end update_course_lessons_author
508
+
509
+
510
+
511
+	/**
512
+	 * Sensei_Teacher::course_analysis_teacher_access_limit
513
+	 *
514
+	 * Alter the query so that users can only see their courses on the analysis page
515
+	 *
516
+	 * @since 1.8.0
517
+	 * @access public
518
+	 * @parameters $query
519
+	 * @return array $users user id array
520
+	 */
521
+	public function course_analysis_teacher_access_limit ( $query ) {
522
+
523
+		if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
524
+			return $query;
525
+		}
526
+
527
+		if ( ! function_exists( 'get_current_screen' ) ) {
528
+			return $query;
529
+		}
530
+
531
+		$screen = get_current_screen();
532
+		$sensei_post_types = array('course', 'lesson', 'question' );
533
+
534
+		// exit early for the following conditions
535
+		$limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
536
+
537
+		if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
538
+			|| ! in_array( $query->query['post_type'], $sensei_post_types ) ){
539
+			return $query;
540
+		}
541
+
542
+		global $current_user;
543
+		// set the query author to the current user to only show those those posts
544
+		$query->set( 'author', $current_user->ID );
545
+		return $query;
546
+
547
+	}// end course_analysis_teacher_access_limit
548
+
549
+
550
+	/**
551
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
552
+	 *
553
+	 * Determine if we're in admin and the current logged in use is a teacher
554
+	 *
555
+	 * @since 1.8.0
556
+	 * @access public
557
+	 * @parameters array $wp_query
558
+	 * @return bool $is_admin_teacher
559
+	 */
560
+	public function is_admin_teacher ( ){
561
+
562
+		if( ! is_user_logged_in()){
563
+			return false;
564
+		}
565
+		$is_admin_teacher = false;
566
+
567
+		if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
568
+
569
+			$is_admin_teacher = true;
570
+
571
+		}
572
+
573
+		return $is_admin_teacher;
574
+
575
+	} // end is_admin_teacher
576
+
577
+	/**
578
+	 * Show correct post counts on list table for Sensei post types
579
+	 *
580
+	 * @since 1.8.0
581
+	 *
582
+	 * @param  object $counts Default status counts
583
+	 * @param  string $type   Current post type
584
+	 * @param  string $perm   User permission level
585
+	 * @return object         Modified status counts
586
+	 */
587
+	public function list_table_counts( $counts, $type, $perm ) {
588
+		global $current_user;
589
+
590
+		if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
591
+			return $counts;
592
+		}
593
+
594
+		if( ! $this->is_admin_teacher() ) {
595
+			return $counts;
596
+		}
597
+
598
+		$args = array(
599
+			'post_type' => $type,
600
+			'author' => $current_user->ID,
601
+			'posts_per_page' => -1
602
+		);
603
+
604
+		 // Get all available statuses
605
+		$stati = get_post_stati();
606
+
607
+		// Update count object
608
+		foreach( $stati as $status ) {
609
+			$args['post_status'] = $status;
610
+			$posts = get_posts( $args );
611
+			$counts->$status = count( $posts );
612
+		}
613
+
614
+		return $counts;
615
+	}
616
+
617
+	/**
618
+	 * Filter the post queries to show
619
+	 * only lesson /course and users that belong
620
+	 * to the current logged teacher.
621
+	 *
622
+	 * @since 1.8.0
623
+	 *
624
+	 */
625
+	public function filter_queries ( $query ) {
626
+		global $current_user;
627
+
628
+		if( ! $this->is_admin_teacher() ) {
629
+			return;
630
+		}
631
+
632
+		if ( ! function_exists( 'get_current_screen' ) ) {
633
+			return;
634
+		}
635
+
636
+		$screen = get_current_screen();
637
+		if( empty( $screen ) ) {
638
+			return $query;
639
+		}
640
+		switch( $screen->id ) {
641
+			case 'sensei_page_sensei_grading':
642
+			case 'sensei_page_sensei_analysis':
643
+			case 'sensei_page_sensei_learners':
644
+			case 'lesson':
645
+			case 'course':
646
+			case 'question':
647
+			case 'lesson_page_module-order':
648
+
649
+			/**
650
+			 * sensei_filter_queries_set_author
651
+			 * Filter the author Sensei set for queries
652
+			 *
653
+			 * @since 1.8.0
654
+			 *
655
+			 * @param int $user_id
656
+			 * @param string $screen_id
657
+			 *
658
+			 */
659
+			$query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
660
+			break;
661
+		}
662
+	}
663
+
664
+	/**
665
+	 * Limit grading quizzes to only those within courses belonging to the current teacher
666
+	 * . This excludes the admin user.
667
+	 *
668
+	 * @since 1.8.0
669
+	 * @hooked into the_comments
670
+	 * @param array  $comments
671
+	 *
672
+	 * @return array $comments
673
+	 */
674
+	public function filter_grading_activity_queries( $comments ){
675
+
676
+		if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
677
+			return $comments ;
678
+		}
679
+
680
+		//check if we're on the grading screen
681
+		$screen = get_current_screen();
682
+
683
+		if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
684
+			return $comments;
685
+		}
686
+
687
+		// get the course and determine if the current teacher is the owner
688
+		// if not remove it from the list of comments to be returned
689
+		foreach( $comments as $key => $comment){
690
+			$lesson = get_post( $comment->comment_post_ID );
691
+			$course_id = Sensei()->lesson->get_course_id( $lesson->ID );
692
+			$course = get_post( $course_id );
693
+			if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
694
+				//remove this as the teacher should see this.
695
+				unset( $comments[ $key ] );
696
+			}
697
+		}
698
+		return $comments ;
699
+
700
+	}// end function filter grading
701
+
702
+	/**
703
+	 * Limit the grading screen totals to only show lessons in the course
704
+	 * belonging to the currently logged in teacher. This only applies to
705
+	 * the teacher role.
706
+	 *
707
+	 * @since 1.8.0
708
+	 *
709
+	 * @hooked into sensei_count_statuses_args
710
+	 * @param array $args
711
+	 *
712
+	 * @return array  $args
713
+	 */
714
+	public function limit_grading_totals( $args ){
715
+
716
+		if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
717
+			return $args ;
718
+		}
719
+
720
+		//get the teachers courses
721
+		// the query is already filtered to only the teacher
722
+		$courses =  Sensei()->course->get_all_courses();
723
+
724
+		if( empty(  $courses ) || ! is_array( $courses ) ){
725
+			return $args;
726
+		}
727
+
728
+		//setup the lessons quizzes  to limit the grading totals to
729
+		$quiz_scope = array();
730
+		foreach( $courses as $course ){
731
+
732
+			$course_lessons = Sensei()->course->course_lessons( $course->ID );
733
+
734
+			if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
735
+
736
+				foreach(  $course_lessons as $lesson ){
737
+
738
+					$quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
739
+					if( !empty( $quiz_id ) ) {
740
+
741
+						array_push( $quiz_scope, $quiz_id );
742
+
743
+					}
744
+
745
+				}
746
+
747
+			}
748
+
749
+		}
750
+
751
+		$args['post__in'] = $quiz_scope;
752
+
753
+		return $args;
754
+	}
755
+
756
+	/**
757
+	 * It ensures that the author archive shows course by the current user.
758
+	 *
759
+	 * This function is hooked into the pre_get_posts filter
760
+	 *
761
+	 * @param WP_Query $query
762
+	 * @return WP_Query $query
763
+	 */
764
+	public function add_courses_to_author_archive( $query ) {
765
+
766
+		if ( is_admin() || ! $query->is_author() ){
767
+			return $query;
768
+		}
769
+
770
+		// this should only apply to users with the teacher role
771
+		$current_page_user = get_user_by('login', $query->get('author_name') );
772
+		if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
773
+
774
+			return $query;
775
+
776
+		}
777
+
778
+		// Change post types depending on what is set already
779
+		$current_post_types = $query->get( 'post_type' );
780
+		if( empty( $current_post_types  ) ){
781
+
782
+			// if empty it means post by default, so add post so that it also includes that for now
783
+			$new_post_types = array( 'post', 'course' );
784
+
785
+		} elseif( is_array( $current_post_types  ) ) {
786
+
787
+			// merge the post types instead of overwriting it
788
+			$new_post_types = array_merge( $current_post_types, array( 'course' ) );
789
+
790
+		}else{
791
+
792
+			// in this instance it is probably just one post type in string format
793
+			$new_post_types =  array( $current_post_types , 'course');
794
+
795
+		}
796
+
797
+		// change the query before returning it
798
+		$query->set('post_type', $new_post_types );
799
+
800
+		/**
801
+		 * Change the query on the teacher author archive template
802
+		 *
803
+		 * @since 1.8.4
804
+		 * @param WP_Query $query
805
+		 */
806
+		return apply_filters( 'sensei_teacher_archive_query', $query );
807
+
808
+	}
809
+
810
+	/**
811
+	 * Notify teacher when someone assigns a course to their account.
812
+	 *
813
+	 * @since 1.8.0
814
+	 *
815
+	 * @param $teacher_id
816
+	 * @param $course_id
817
+	 * @return bool
818
+	 */
819
+	public function teacher_course_assigned_notification( $teacher_id, $course_id ){
820
+
821
+		if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
822
+			return false;
823
+		}
824
+
825
+		// if new user is the same as the current logged user, they don't need an email
826
+		if( $teacher_id == get_current_user_id() ){
827
+			return true;
828
+		}
829
+
830
+		// load the email class
831
+		include('emails/class-sensei-email-teacher-new-course-assignment.php');
832
+		$email = new Sensei_Email_Teacher_New_Course_Assignment();
833
+		$email->trigger( $teacher_id, $course_id );
834
+
835
+		return true;
836
+	} // end  teacher_course_assigned_notification
837
+
838
+	/**
839
+	 * Email the admin when a teacher creates a new course
840
+	 *
841
+	 * This function hooks into wp_insert_post
842
+	 *
843
+	 * @since 1.8.0
844
+	 * @param int $course_id
845
+	 * @return bool
846
+	 */
847
+	public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
848
+
849
+		$course_id = $post->ID;
850
+
851
+		if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
852
+			|| 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
853
+
854
+			return false;
855
+
856
+		}
857
+
858
+		/**
859
+		 * Filter the option to send admin notification emails when teachers creation
860
+		 * course.
861
+		 *
862
+		 * @since 1.8.0
863
+		 *
864
+		 * @param bool $on default true
865
+		 */
866
+		if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
867
+			return false;
868
+		}
869
+
870
+		// setting up the data needed by the email template
871
+		global $sensei_email_data;
872
+		$template = 'admin-teacher-new-course-created';
873
+		$course = get_post( $course_id );
874
+		$teacher = new WP_User( $course->post_author );
875
+		$recipient = get_option('admin_email', true);
876
+
877
+		// don't send if the course is created by admin
878
+		if( $recipient == $teacher->user_email ){
879
+			return;
880
+		}
881
+
882
+		/**
883
+		 * Filter the email Header for the admin-teacher-new-course-created template
884
+		 *
885
+		 * @since 1.8.0
886
+		 * @param string $template
887
+		 */
888
+		$heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
889
+
890
+		/**
891
+		 * Filter the email subject for the the
892
+		 * admin-teacher-new-course-created template
893
+		 *
894
+		 * @since 1.8.0
895
+		 * @param string $subject default New course assigned to you
896
+		 * @param string $template
897
+		 */
898
+		$subject = apply_filters('sensei_email_subject',
899
+								'['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
900
+								$template );
901
+
902
+		//course edit link
903
+		$course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
904
+
905
+		// Construct data array
906
+		$email_data = array(
907
+			'template'			=> $template,
908
+			'heading' =>  $heading,
909
+			'teacher'		=> $teacher,
910
+			'course_id'			=> $course_id,
911
+			'course_name'			=> $course->post_title,
912
+			'course_edit_link' => $course_edit_link,
913
+		);
914
+
915
+		/**
916
+		 * Filter the sensei email data for the admin-teacher-new-course-created template
917
+		 *
918
+		 * @since 1.8.0
919
+		 * @param array $email_data
920
+		 * @param string $template
921
+		 */
922
+		$sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
923
+
924
+		// Send mail
925
+		Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
926
+
927
+	}// end notify admin of course creation
928
+
929
+	/**
930
+	 * Limit the analysis view to only the users taking courses belong to this teacher
931
+	 *
932
+	 * Hooked into sensei_analysis_get_learners
933
+	 * @param array $args WP_User_Query arguments
934
+	 * @return array $learners_query_results
935
+	 */
936
+	public function limit_analysis_learners( $args ){
937
+
938
+		// show default for none teachers
939
+		if( ! Sensei()->teacher->is_admin_teacher() ) {
940
+				return $args;
941
+		}
942
+
943
+		// for teachers all courses only return those which belong to the teacher
944
+		// as they don't have access to course belonging to other users
945
+		$teacher_courses = Sensei()->course->get_all_courses();
946 946
 
947
-        // if the user has no courses they should see no users
948
-        if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
949
-            // tell the query to return 0 students
950
-            $args[ 'include'] = array( 0 );
951
-            return $args;
952
-
953
-        }
954
-
955
-        $learner_ids_for_teacher_courses = array();
956
-        foreach( $teacher_courses as $course ){
957
-
958
-            $course_learner_ids = array();
959
-            $activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
960
-
961
-            if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
962
-                continue; // skip to the next course as there are no users on this course
963
-            }
964
-
965
-            // it could be an array of comments or a single comment
966
-            if( is_array( $activity_comments ) ){
947
+		// if the user has no courses they should see no users
948
+		if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
949
+			// tell the query to return 0 students
950
+			$args[ 'include'] = array( 0 );
951
+			return $args;
952
+
953
+		}
954
+
955
+		$learner_ids_for_teacher_courses = array();
956
+		foreach( $teacher_courses as $course ){
957
+
958
+			$course_learner_ids = array();
959
+			$activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
960
+
961
+			if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
962
+				continue; // skip to the next course as there are no users on this course
963
+			}
964
+
965
+			// it could be an array of comments or a single comment
966
+			if( is_array( $activity_comments ) ){
967 967
 
968
-                foreach( $activity_comments as $comment ){
968
+				foreach( $activity_comments as $comment ){
969 969
 
970
-                    $user = get_userdata( $comment->user_id );
970
+					$user = get_userdata( $comment->user_id );
971 971
 
972
-                    if( empty( $user ) ){
973
-                        // next comment in this array
974
-                        continue;
975
-                    }
972
+					if( empty( $user ) ){
973
+						// next comment in this array
974
+						continue;
975
+					}
976 976
 
977
-                    $course_learner_ids[] = $user->ID;
978
-                }
977
+					$course_learner_ids[] = $user->ID;
978
+				}
979 979
 
980
-            }else{
980
+			}else{
981 981
 
982
-                $user = get_userdata( $activity_comments->user_id );
983
-                $course_learner_ids[] = $user->ID;
982
+				$user = get_userdata( $activity_comments->user_id );
983
+				$course_learner_ids[] = $user->ID;
984 984
 
985
-            }
985
+			}
986 986
 
987
-            // add learners on this course to the all courses learner list
988
-            $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
987
+			// add learners on this course to the all courses learner list
988
+			$learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
989 989
 
990
-        }
990
+		}
991 991
 
992
-        // if there are no students taking the courses by this teacher don't show them any of the other users
993
-        if( empty( $learner_ids_for_teacher_courses ) ){
992
+		// if there are no students taking the courses by this teacher don't show them any of the other users
993
+		if( empty( $learner_ids_for_teacher_courses ) ){
994 994
 
995
-            $args[ 'include'] = array( 0 );
995
+			$args[ 'include'] = array( 0 );
996 996
 
997
-        }else{
997
+		}else{
998 998
 
999
-            $args[ 'include'] = $learner_ids_for_teacher_courses;
999
+			$args[ 'include'] = $learner_ids_for_teacher_courses;
1000 1000
 
1001
-        }
1001
+		}
1002 1002
 
1003
-        // return the WP_Use_Query arguments
1004
-        return $args;
1003
+		// return the WP_Use_Query arguments
1004
+		return $args;
1005 1005
 
1006
-    }// end limit_analysis_learners
1006
+	}// end limit_analysis_learners
1007 1007
 
1008
-    /**
1009
-     * Give teacher full admin access to the question post type
1010
-     * in certain cases.
1011
-     *
1012
-     * @since 1.8.0
1013
-     * @param $questions
1014
-     * @return mixed
1015
-     */
1016
-    public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1008
+	/**
1009
+	 * Give teacher full admin access to the question post type
1010
+	 * in certain cases.
1011
+	 *
1012
+	 * @since 1.8.0
1013
+	 * @param $questions
1014
+	 * @return mixed
1015
+	 */
1016
+	public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1017 1017
 
1018
-        if( ! $this->is_admin_teacher() ){
1019
-            return $questions;
1020
-        }
1018
+		if( ! $this->is_admin_teacher() ){
1019
+			return $questions;
1020
+		}
1021 1021
 
1022
-        $screen = get_current_screen();
1022
+		$screen = get_current_screen();
1023 1023
 
1024
-        // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1025
-        remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1024
+		// don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1025
+		remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1026 1026
 
1027
-        if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1027
+		if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1028 1028
 
1029
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1030
-            if( ! empty($admin_user) ){
1029
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1030
+			if( ! empty($admin_user) ){
1031 1031
 
1032
-                $current_teacher_id = get_current_user_id();
1032
+				$current_teacher_id = get_current_user_id();
1033 1033
 
1034
-                // set current user to admin so teacher can view all questions
1035
-                wp_set_current_user( $admin_user->ID  );
1036
-                $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1034
+				// set current user to admin so teacher can view all questions
1035
+				wp_set_current_user( $admin_user->ID  );
1036
+				$questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1037 1037
 
1038
-                // set the teacher as the current use again
1039
-                wp_set_current_user( $current_teacher_id );
1040
-            }
1038
+				// set the teacher as the current use again
1039
+				wp_set_current_user( $current_teacher_id );
1040
+			}
1041 1041
 
1042
-        }
1043
-        // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1044
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1042
+		}
1043
+		// attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1044
+		add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1045 1045
 
1046
-        return $questions;
1047
-    }
1046
+		return $questions;
1047
+	}
1048 1048
 
1049
-    /**
1050
-     * Give the teacher role access to questions from the question bank
1051
-     *
1052
-     * @since 1.8.0
1053
-     * @param $wp_query
1054
-     * @return mixed
1055
-     */
1056
-    public function give_access_to_all_questions( $wp_query ){
1049
+	/**
1050
+	 * Give the teacher role access to questions from the question bank
1051
+	 *
1052
+	 * @since 1.8.0
1053
+	 * @param $wp_query
1054
+	 * @return mixed
1055
+	 */
1056
+	public function give_access_to_all_questions( $wp_query ){
1057 1057
 
1058
-        if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1058
+		if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1059 1059
 
1060
-            return $wp_query;
1061
-        }
1060
+			return $wp_query;
1061
+		}
1062 1062
 
1063
-        $screen = get_current_screen();
1064
-        if( ( isset($screen->id) && 'lesson' == $screen->id )
1065
-            || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1063
+		$screen = get_current_screen();
1064
+		if( ( isset($screen->id) && 'lesson' == $screen->id )
1065
+			|| ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1066 1066
 
1067
-            $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1068
-            if( ! empty($admin_user) ){
1067
+			$admin_user = get_user_by('email', get_bloginfo('admin_email'));
1068
+			if( ! empty($admin_user) ){
1069 1069
 
1070
-                $current_teacher_id = get_current_user_id();
1070
+				$current_teacher_id = get_current_user_id();
1071 1071
 
1072
-                // set current user to admin so teacher can view all questions
1073
-                wp_set_current_user( $admin_user->ID  );
1072
+				// set current user to admin so teacher can view all questions
1073
+				wp_set_current_user( $admin_user->ID  );
1074 1074
 
1075
-                //run new query as admin
1076
-                $wp_query = new WP_Query( $wp_query->query );
1075
+				//run new query as admin
1076
+				$wp_query = new WP_Query( $wp_query->query );
1077 1077
 
1078
-                //set the teache as current use again
1079
-                wp_set_current_user( $current_teacher_id );
1078
+				//set the teache as current use again
1079
+				wp_set_current_user( $current_teacher_id );
1080 1080
 
1081
-            }
1082
-        }
1081
+			}
1082
+		}
1083 1083
 
1084
-        return $wp_query;
1085
-    }// end give_access_to_all_questions
1084
+		return $wp_query;
1085
+	}// end give_access_to_all_questions
1086 1086
 
1087
-    /**
1088
-     * Add new column heading to the course admin edit list
1089
-     *
1090
-     * @since 1.8.0
1091
-     * @param $columns
1092
-     * @return array
1093
-     */
1094
-    public function course_column_heading($columns) {
1087
+	/**
1088
+	 * Add new column heading to the course admin edit list
1089
+	 *
1090
+	 * @since 1.8.0
1091
+	 * @param $columns
1092
+	 * @return array
1093
+	 */
1094
+	public function course_column_heading($columns) {
1095 1095
 
1096
-        if( $this->is_admin_teacher() ){
1097
-            return $columns;
1098
-        }
1099
-        $new_columns = array(
1100
-            'teacher' => __('Teacher', 'woothemes-sensei'),
1101
-        );
1102
-        return array_merge($columns, $new_columns);
1096
+		if( $this->is_admin_teacher() ){
1097
+			return $columns;
1098
+		}
1099
+		$new_columns = array(
1100
+			'teacher' => __('Teacher', 'woothemes-sensei'),
1101
+		);
1102
+		return array_merge($columns, $new_columns);
1103 1103
 
1104
-    }// end teacher column add
1104
+	}// end teacher column add
1105 1105
 
1106
-    /**
1107
-     * Print out  teacher column data
1108
-     *
1109
-     * @since 1.8.0
1110
-     * @param $column
1111
-     * @param $course_id
1112
-     */
1113
-    public function course_column_data( $column, $course_id  ){
1106
+	/**
1107
+	 * Print out  teacher column data
1108
+	 *
1109
+	 * @since 1.8.0
1110
+	 * @param $column
1111
+	 * @param $course_id
1112
+	 */
1113
+	public function course_column_data( $column, $course_id  ){
1114 1114
 
1115
-        if( $this->is_admin_teacher() || 'teacher' != $column  ){
1116
-            return;
1117
-        }
1115
+		if( $this->is_admin_teacher() || 'teacher' != $column  ){
1116
+			return;
1117
+		}
1118 1118
 
1119
-        $course = get_post( $course_id );
1120
-        $teacher = get_userdata( $course->post_author );
1119
+		$course = get_post( $course_id );
1120
+		$teacher = get_userdata( $course->post_author );
1121 1121
 
1122
-        if( !$teacher ){
1123
-            return;
1124
-        }
1122
+		if( !$teacher ){
1123
+			return;
1124
+		}
1125 1125
 
1126
-        echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1126
+		echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1127 1127
 
1128
-    }// end course_column_ data
1128
+	}// end course_column_ data
1129 1129
 
1130
-    /**
1131
-     * Return only courses belonging to the given teacher.
1132
-     *
1133
-     *
1134
-     * @since 1.8.0
1135
-     *
1136
-     * @param int $teacher_id
1137
-     * @param bool $return_ids_only
1138
-     *
1139
-     * @return array $teachers_courses
1140
-     */
1141
-    public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1130
+	/**
1131
+	 * Return only courses belonging to the given teacher.
1132
+	 *
1133
+	 *
1134
+	 * @since 1.8.0
1135
+	 *
1136
+	 * @param int $teacher_id
1137
+	 * @param bool $return_ids_only
1138
+	 *
1139
+	 * @return array $teachers_courses
1140
+	 */
1141
+	public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1142 1142
 
1143
-        $teachers_courses = array();
1143
+		$teachers_courses = array();
1144 1144
 
1145
-        if( empty( $teacher_id  ) ){
1146
-            $teacher_id = get_current_user_id();
1147
-        }
1145
+		if( empty( $teacher_id  ) ){
1146
+			$teacher_id = get_current_user_id();
1147
+		}
1148 1148
 
1149
-        $all_courses = Sensei()->course->get_all_courses();
1149
+		$all_courses = Sensei()->course->get_all_courses();
1150 1150
 
1151
-        if( empty( $all_courses ) ){
1152
-            return $all_courses;
1153
-        }
1151
+		if( empty( $all_courses ) ){
1152
+			return $all_courses;
1153
+		}
1154 1154
 
1155
-        foreach( $all_courses as $course ){
1155
+		foreach( $all_courses as $course ){
1156 1156
 
1157
-            if( $course->post_author != $teacher_id  ){
1158
-                continue;
1159
-            }
1157
+			if( $course->post_author != $teacher_id  ){
1158
+				continue;
1159
+			}
1160 1160
 
1161
-            if( $return_ids_only ){
1161
+			if( $return_ids_only ){
1162 1162
 
1163
-                $teachers_courses[] = $course->ID;
1163
+				$teachers_courses[] = $course->ID;
1164 1164
 
1165
-            }else{
1165
+			}else{
1166 1166
 
1167
-                $teachers_courses[] = $course;
1167
+				$teachers_courses[] = $course;
1168 1168
 
1169
-            }
1169
+			}
1170 1170
 
1171
-        }
1171
+		}
1172 1172
 
1173
-        return $teachers_courses;
1173
+		return $teachers_courses;
1174 1174
 
1175
-    }
1175
+	}
1176 1176
 
1177
-    /**
1178
-     * Limit the message display to only those sent to the current teacher
1179
-     *
1180
-     * @since 1.8.0
1181
-     *
1182
-     * @param $query
1183
-     * @return mixed
1184
-     */
1185
-    public function limit_edit_messages_query( $query ){
1186
-        if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1187
-            return $query;
1188
-        }
1189
-
1190
-        $teacher = wp_get_current_user();
1191
-
1192
-        $query->set( 'meta_key', '_receiver' );
1193
-        $meta_query_args = array(
1194
-            'key'     => '_receiver',
1195
-            'value'   => $teacher->get('user_login') ,
1196
-            'compare' => '='
1197
-        );
1177
+	/**
1178
+	 * Limit the message display to only those sent to the current teacher
1179
+	 *
1180
+	 * @since 1.8.0
1181
+	 *
1182
+	 * @param $query
1183
+	 * @return mixed
1184
+	 */
1185
+	public function limit_edit_messages_query( $query ){
1186
+		if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1187
+			return $query;
1188
+		}
1189
+
1190
+		$teacher = wp_get_current_user();
1191
+
1192
+		$query->set( 'meta_key', '_receiver' );
1193
+		$meta_query_args = array(
1194
+			'key'     => '_receiver',
1195
+			'value'   => $teacher->get('user_login') ,
1196
+			'compare' => '='
1197
+		);
1198 1198
 
1199
-        $query->set('meta_query', $meta_query_args  );
1199
+		$query->set('meta_query', $meta_query_args  );
1200 1200
 
1201
-        return $query;
1202
-    }
1201
+		return $query;
1202
+	}
1203 1203
 
1204 1204
 
1205
-    /**
1206
-     * Add options to filter courses by teacher
1207
-     *
1208
-     * @since 1.8.0
1209
-     *
1210
-     * @return void
1211
-     */
1212
-    public function course_teacher_filter_options() {
1213
-        global $typenow;
1205
+	/**
1206
+	 * Add options to filter courses by teacher
1207
+	 *
1208
+	 * @since 1.8.0
1209
+	 *
1210
+	 * @return void
1211
+	 */
1212
+	public function course_teacher_filter_options() {
1213
+		global $typenow;
1214 1214
 
1215
-        if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1216
-            return;
1217
-        }
1215
+		if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1216
+			return;
1217
+		}
1218 1218
 
1219
-        // get all roles
1220
-        $roles = get_editable_roles();
1219
+		// get all roles
1220
+		$roles = get_editable_roles();
1221 1221
 
1222
-        // get roles with the course edit capability
1223
-        // and then get the users with those roles
1224
-        $users_who_can_edit_courses = array();
1225
-        foreach( $roles as $role_item ){
1222
+		// get roles with the course edit capability
1223
+		// and then get the users with those roles
1224
+		$users_who_can_edit_courses = array();
1225
+		foreach( $roles as $role_item ){
1226 1226
 
1227
-            $role = get_role( strtolower( $role_item['name'] ) );
1227
+			$role = get_role( strtolower( $role_item['name'] ) );
1228 1228
 
1229
-            if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1229
+			if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1230 1230
 
1231
-                $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1232
-                $role_users_who_can_edit_courses = get_users( $user_query_args );
1231
+				$user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1232
+				$role_users_who_can_edit_courses = get_users( $user_query_args );
1233 1233
 
1234
-                // add user from the current $user_role to all users
1235
-                $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1234
+				// add user from the current $user_role to all users
1235
+				$users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1236 1236
 
1237
-            }
1237
+			}
1238 1238
 
1239
-        }
1239
+		}
1240 1240
 
1241
-        // Create the select element with the given users who can edit course
1242
-        $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1243
-        $course_options = '';
1244
-        foreach( $users_who_can_edit_courses as $user ) {
1245
-            $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1246
-        }
1241
+		// Create the select element with the given users who can edit course
1242
+		$selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1243
+		$course_options = '';
1244
+		foreach( $users_who_can_edit_courses as $user ) {
1245
+			$course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1246
+		}
1247 1247
 
1248
-        $output = '<select name="course_teacher" id="dropdown_course_teachers">';
1249
-        $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1250
-        $output .= $course_options;
1251
-        $output .= '</select>';
1248
+		$output = '<select name="course_teacher" id="dropdown_course_teachers">';
1249
+		$output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1250
+		$output .= $course_options;
1251
+		$output .= '</select>';
1252 1252
 
1253
-        echo $output;
1254
-    }
1253
+		echo $output;
1254
+	}
1255 1255
 
1256
-    /**
1257
-     * Modify the main query on the admin course list screen
1258
-     *
1259
-     * @since 1.8.0
1260
-     *
1261
-     * @param $query
1262
-     * @return $query
1263
-     */
1264
-    public function teacher_filter_query_modify( $query ){
1265
-        global $typenow;
1256
+	/**
1257
+	 * Modify the main query on the admin course list screen
1258
+	 *
1259
+	 * @since 1.8.0
1260
+	 *
1261
+	 * @param $query
1262
+	 * @return $query
1263
+	 */
1264
+	public function teacher_filter_query_modify( $query ){
1265
+		global $typenow;
1266 1266
 
1267
-        if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1268
-            return $query;
1269
-        }
1270
-        $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1271
-
1272
-        if( empty( $course_teacher ) ) {
1273
-            return $query;
1274
-        }
1275
-
1276
-        $query['author'] = $course_teacher;
1277
-        return $query;
1278
-    }
1279
-
1280
-    /**
1281
-     * Only show current teacher's media in the media library
1282
-     * @param  array $request Default request arguments
1283
-     * @return array          Modified request arguments
1284
-     */
1285
-    public function restrict_media_library( $request = array() ) {
1286
-
1287
-        if( ! is_admin() ) {
1288
-            return $request;
1289
-        }
1290
-
1291
-        if( ! $this->is_admin_teacher() ) {
1292
-            return $request;
1293
-        }
1294
-
1295
-        $screen = get_current_screen();
1296
-
1297
-        if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1298
-            $teacher = intval( get_current_user_id() );
1299
-
1300
-            if( $teacher ) {
1301
-                $request['author__in'] = array( $teacher );
1302
-            }
1303
-        }
1304
-
1305
-        return $request;
1306
-    } // End restrict_media_library()
1307
-
1308
-    /**
1309
-     * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1310
-     * @param  array $query Default query arguments
1311
-     * @return array        Modified query arguments
1312
-     */
1313
-    public function restrict_media_library_modal( $query = array() ) {
1314
-
1315
-        if( ! is_admin() ) {
1316
-            return $query;
1317
-        }
1318
-
1319
-        if( ! $this->is_admin_teacher() ) {
1320
-            return $query;
1321
-        }
1322
-
1323
-        $teacher = intval( get_current_user_id() );
1324
-
1325
-        if( $teacher ) {
1326
-            $query['author__in'] = array( $teacher );
1327
-        }
1328
-
1329
-        return $query;
1330
-    } // End restrict_media_library_modal()
1331
-
1332
-    /**
1333
-     * When saving the lesson, update the teacher if the lesson belongs to a course
1334
-     *
1335
-     * @since 1.8.0
1336
-     *
1337
-     * @param int $lesson_id
1338
-     */
1339
-    public function update_lesson_teacher( $lesson_id ){
1340
-
1341
-        if( 'lesson'!= get_post_type() ){
1342
-            return;
1343
-        }
1267
+		if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1268
+			return $query;
1269
+		}
1270
+		$course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1271
+
1272
+		if( empty( $course_teacher ) ) {
1273
+			return $query;
1274
+		}
1275
+
1276
+		$query['author'] = $course_teacher;
1277
+		return $query;
1278
+	}
1279
+
1280
+	/**
1281
+	 * Only show current teacher's media in the media library
1282
+	 * @param  array $request Default request arguments
1283
+	 * @return array          Modified request arguments
1284
+	 */
1285
+	public function restrict_media_library( $request = array() ) {
1286
+
1287
+		if( ! is_admin() ) {
1288
+			return $request;
1289
+		}
1290
+
1291
+		if( ! $this->is_admin_teacher() ) {
1292
+			return $request;
1293
+		}
1294
+
1295
+		$screen = get_current_screen();
1296
+
1297
+		if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1298
+			$teacher = intval( get_current_user_id() );
1299
+
1300
+			if( $teacher ) {
1301
+				$request['author__in'] = array( $teacher );
1302
+			}
1303
+		}
1304
+
1305
+		return $request;
1306
+	} // End restrict_media_library()
1307
+
1308
+	/**
1309
+	 * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen
1310
+	 * @param  array $query Default query arguments
1311
+	 * @return array        Modified query arguments
1312
+	 */
1313
+	public function restrict_media_library_modal( $query = array() ) {
1314
+
1315
+		if( ! is_admin() ) {
1316
+			return $query;
1317
+		}
1318
+
1319
+		if( ! $this->is_admin_teacher() ) {
1320
+			return $query;
1321
+		}
1322
+
1323
+		$teacher = intval( get_current_user_id() );
1324
+
1325
+		if( $teacher ) {
1326
+			$query['author__in'] = array( $teacher );
1327
+		}
1328
+
1329
+		return $query;
1330
+	} // End restrict_media_library_modal()
1331
+
1332
+	/**
1333
+	 * When saving the lesson, update the teacher if the lesson belongs to a course
1334
+	 *
1335
+	 * @since 1.8.0
1336
+	 *
1337
+	 * @param int $lesson_id
1338
+	 */
1339
+	public function update_lesson_teacher( $lesson_id ){
1340
+
1341
+		if( 'lesson'!= get_post_type() ){
1342
+			return;
1343
+		}
1344 1344
 
1345
-        // this should only run once per request cycle
1346
-        remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1345
+		// this should only run once per request cycle
1346
+		remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1347 1347
 
1348
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1348
+		$course_id = Sensei()->lesson->get_course_id( $lesson_id );
1349 1349
 
1350
-        if(  empty( $course_id ) || ! $course_id ){
1351
-            return;
1352
-        }
1350
+		if(  empty( $course_id ) || ! $course_id ){
1351
+			return;
1352
+		}
1353 1353
 
1354
-        $course = get_post( $course_id );
1354
+		$course = get_post( $course_id );
1355 1355
 
1356
-        $lesson_update_args= array(
1357
-            'ID' => $lesson_id ,
1358
-            'post_author' => $course->post_author
1359
-        );
1360
-        wp_update_post( $lesson_update_args );
1356
+		$lesson_update_args= array(
1357
+			'ID' => $lesson_id ,
1358
+			'post_author' => $course->post_author
1359
+		);
1360
+		wp_update_post( $lesson_update_args );
1361 1361
 
1362
-    } // end update_lesson_teacher
1362
+	} // end update_lesson_teacher
1363 1363
 
1364
-    /**
1365
-     * Sensei_Teacher::limit_teacher_edit_screen_post_types
1366
-     *
1367
-     * Limit teachers to only see their courses, lessons and questions
1368
-     *
1369
-     * @since 1.8.0
1370
-     * @access public
1371
-     * @parameters array $wp_query
1372
-     * @return WP_Query $wp_query
1373
-     */
1374
-    public function limit_teacher_edit_screen_post_types( $wp_query ) {
1375
-        global $current_user;
1364
+	/**
1365
+	 * Sensei_Teacher::limit_teacher_edit_screen_post_types
1366
+	 *
1367
+	 * Limit teachers to only see their courses, lessons and questions
1368
+	 *
1369
+	 * @since 1.8.0
1370
+	 * @access public
1371
+	 * @parameters array $wp_query
1372
+	 * @return WP_Query $wp_query
1373
+	 */
1374
+	public function limit_teacher_edit_screen_post_types( $wp_query ) {
1375
+		global $current_user;
1376 1376
 
1377
-        //exit early
1378
-        if( ! $this->is_admin_teacher() ){
1379
-            return $wp_query;
1380
-        }
1377
+		//exit early
1378
+		if( ! $this->is_admin_teacher() ){
1379
+			return $wp_query;
1380
+		}
1381 1381
 
1382
-        if ( ! function_exists( 'get_current_screen' ) ) {
1383
-            return $wp_query;
1384
-        }
1382
+		if ( ! function_exists( 'get_current_screen' ) ) {
1383
+			return $wp_query;
1384
+		}
1385 1385
 
1386
-        $screen = get_current_screen();
1386
+		$screen = get_current_screen();
1387 1387
 
1388
-        if( empty( $screen ) ){
1389
-            return $wp_query;
1390
-        }
1388
+		if( empty( $screen ) ){
1389
+			return $wp_query;
1390
+		}
1391 1391
 
1392
-        // for any of these conditions limit what the teacher will see
1393
-        $limit_screens = array(
1394
-            'edit-lesson',
1395
-            'edit-course',
1396
-            'edit-question',
1397
-            'course_page_course-order',
1398
-            'lesson_page_lesson-order',
1399
-        );
1392
+		// for any of these conditions limit what the teacher will see
1393
+		$limit_screens = array(
1394
+			'edit-lesson',
1395
+			'edit-course',
1396
+			'edit-question',
1397
+			'course_page_course-order',
1398
+			'lesson_page_lesson-order',
1399
+		);
1400 1400
 
1401
-        if(  in_array($screen->id  , $limit_screens ) ) {
1401
+		if(  in_array($screen->id  , $limit_screens ) ) {
1402 1402
 
1403
-            // set the query author to the current user to only show those those posts
1404
-            $wp_query->set( 'author', $current_user->ID );
1405
-        }
1403
+			// set the query author to the current user to only show those those posts
1404
+			$wp_query->set( 'author', $current_user->ID );
1405
+		}
1406 1406
 
1407
-        return $wp_query;
1407
+		return $wp_query;
1408 1408
 
1409
-    } // end limit_teacher_edit_screen_post_types()
1409
+	} // end limit_teacher_edit_screen_post_types()
1410 1410
 
1411 1411
 
1412
-    /**
1413
-     * Sensei_Teacher::teacher_login_redirect
1414
-     *
1415
-     * Redirect teachers to /wp-admin/ after login
1416
-     *
1417
-     * @since 1.8.7
1418
-     * @access public
1419
-     * @param string $user_login
1420
-     * @param object $user
1421
-     * @return void
1422
-     */
1412
+	/**
1413
+	 * Sensei_Teacher::teacher_login_redirect
1414
+	 *
1415
+	 * Redirect teachers to /wp-admin/ after login
1416
+	 *
1417
+	 * @since 1.8.7
1418
+	 * @access public
1419
+	 * @param string $user_login
1420
+	 * @param object $user
1421
+	 * @return void
1422
+	 */
1423 1423
 
1424
-    public function teacher_login_redirect( $user_login, $user  ) {
1424
+	public function teacher_login_redirect( $user_login, $user  ) {
1425 1425
 
1426
-        if (user_can($user, 'edit_courses')) {
1426
+		if (user_can($user, 'edit_courses')) {
1427 1427
 
1428
-            if (isset($_POST['redirect_to'])) {
1428
+			if (isset($_POST['redirect_to'])) {
1429 1429
 
1430
-                wp_redirect($_POST['redirect_to'], 303);
1430
+				wp_redirect($_POST['redirect_to'], 303);
1431 1431
 
1432
-                exit;
1432
+				exit;
1433 1433
 
1434
-            } else {
1434
+			} else {
1435 1435
 
1436
-                wp_redirect(admin_url(), 303);
1436
+				wp_redirect(admin_url(), 303);
1437 1437
 
1438
-                exit;
1438
+				exit;
1439 1439
 
1440
-            }
1441
-        }
1440
+			}
1441
+		}
1442 1442
 
1443
-    } // end teacher_login_redirect()
1443
+	} // end teacher_login_redirect()
1444 1444
 
1445 1445
 
1446 1446
 
1447
-    /**
1448
-     * Sensei_Teacher::restrict_posts_menu_page()
1449
-     *
1450
-     * Remove the Posts menu page for teachers and restrict access to it.
1451
-     * We have to do this because we give teachers the 'edit_posts' cap
1452
-     * so they can 'moderate_comments' as well.
1453
-     *
1454
-     * @since 1.8.7
1455
-     * @access public
1456
-     * @parameters void
1457
-     * @return void
1458
-     */
1447
+	/**
1448
+	 * Sensei_Teacher::restrict_posts_menu_page()
1449
+	 *
1450
+	 * Remove the Posts menu page for teachers and restrict access to it.
1451
+	 * We have to do this because we give teachers the 'edit_posts' cap
1452
+	 * so they can 'moderate_comments' as well.
1453
+	 *
1454
+	 * @since 1.8.7
1455
+	 * @access public
1456
+	 * @parameters void
1457
+	 * @return void
1458
+	 */
1459 1459
 
1460
-    public function restrict_posts_menu_page() {
1460
+	public function restrict_posts_menu_page() {
1461 1461
 
1462
-        global $pagenow, $typenow;
1462
+		global $pagenow, $typenow;
1463 1463
 
1464
-        $user = wp_get_current_user();
1464
+		$user = wp_get_current_user();
1465 1465
 
1466
-        /**
1467
-         * Filter the option to hide the Posts menu page.
1468
-         *
1469
-         * @since 1.8.7
1470
-         *
1471
-         * @param bool $restrict default true
1472
-         */
1466
+		/**
1467
+		 * Filter the option to hide the Posts menu page.
1468
+		 *
1469
+		 * @since 1.8.7
1470
+		 *
1471
+		 * @param bool $restrict default true
1472
+		 */
1473 1473
 
1474
-        $restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1474
+		$restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1475 1475
 
1476
-        if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1476
+		if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1477 1477
 
1478
-            remove_menu_page('edit.php');
1478
+			remove_menu_page('edit.php');
1479 1479
 
1480
-            if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1480
+			if ($pagenow == "edit.php" || $pagenow == "post-new.php") {
1481 1481
 
1482
-                if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1482
+				if ($typenow == '' || $typenow == 'post' || $typenow == 'page') {
1483 1483
 
1484
-                    wp_die('You do not have sufficient permissions to access this page.');
1484
+					wp_die('You do not have sufficient permissions to access this page.');
1485 1485
 
1486
-                }
1486
+				}
1487 1487
 
1488
-            }
1488
+			}
1489 1489
 
1490
-        }
1490
+		}
1491 1491
 
1492
-    } // end restrict_posts_menu_page()
1492
+	} // end restrict_posts_menu_page()
1493 1493
 
1494
-    /**
1495
-     * Sensei_Teacher::restrict_comment_moderation()
1496
-     *
1497
-     * Restrict commendation moderation for teachers
1498
-     * so they can only moderate comments made to posts they own.
1499
-     *
1500
-     * @since 1.8.7
1501
-     * @access public
1502
-     * @parameters obj $clauses
1503
-     * @return WP_Comment_Query  $clauses
1504
-     */
1494
+	/**
1495
+	 * Sensei_Teacher::restrict_comment_moderation()
1496
+	 *
1497
+	 * Restrict commendation moderation for teachers
1498
+	 * so they can only moderate comments made to posts they own.
1499
+	 *
1500
+	 * @since 1.8.7
1501
+	 * @access public
1502
+	 * @parameters obj $clauses
1503
+	 * @return WP_Comment_Query  $clauses
1504
+	 */
1505 1505
 
1506
-    public function restrict_comment_moderation ( $clauses ) {
1506
+	public function restrict_comment_moderation ( $clauses ) {
1507 1507
 
1508
-        global $pagenow;
1508
+		global $pagenow;
1509 1509
 
1510
-        if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1510
+		if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1511 1511
 
1512
-            $clauses->query_vars['post_author'] = get_current_user_id();
1512
+			$clauses->query_vars['post_author'] = get_current_user_id();
1513 1513
 
1514
-        }
1514
+		}
1515 1515
 
1516
-        return $clauses;
1516
+		return $clauses;
1517 1517
 
1518
-    }   // end restrict_comment_moderation()
1518
+	}   // end restrict_comment_moderation()
1519 1519
 
1520
-    /**
1521
-     * Determine if a user is a teacher by ID
1522
-     *
1523
-     * @param int $user_id
1524
-     *
1525
-     * @return bool
1526
-     */
1527
-    public static function is_a_teacher( $user_id ){
1520
+	/**
1521
+	 * Determine if a user is a teacher by ID
1522
+	 *
1523
+	 * @param int $user_id
1524
+	 *
1525
+	 * @return bool
1526
+	 */
1527
+	public static function is_a_teacher( $user_id ){
1528 1528
 
1529
-        $user = get_user_by('id', $user_id);
1529
+		$user = get_user_by('id', $user_id);
1530 1530
 
1531
-        if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1531
+		if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1532 1532
 
1533
-            return true;
1533
+			return true;
1534 1534
 
1535
-        }else{
1535
+		}else{
1536 1536
 
1537
-            return false;
1537
+			return false;
1538 1538
 
1539
-        }
1539
+		}
1540 1540
 
1541
-    }// end is_a_teacher
1541
+	}// end is_a_teacher
1542 1542
 
1543
-    /**
1544
-     * The archive title on the teacher archive filter
1545
-     *
1546
-     * @since 1.9.0
1547
-     */
1548
-    public static function archive_title(){
1543
+	/**
1544
+	 * The archive title on the teacher archive filter
1545
+	 *
1546
+	 * @since 1.9.0
1547
+	 */
1548
+	public static function archive_title(){
1549 1549
 
1550
-        $author = get_user_by( 'id', get_query_var( 'author' ) );
1551
-        $author_name = $author->display_name;
1552
-        ?>
1550
+		$author = get_user_by( 'id', get_query_var( 'author' ) );
1551
+		$author_name = $author->display_name;
1552
+		?>
1553 1553
             <h2 class="teacher-archive-title">
1554 1554
 
1555 1555
                 <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?>
@@ -1557,17 +1557,17 @@  discard block
 block discarded – undo
1557 1557
             </h2>
1558 1558
         <?php
1559 1559
 
1560
-    }// archive title
1560
+	}// archive title
1561 1561
 
1562
-    /**
1563
-     * Removing course meta on the teacher archive page
1564
-     *
1565
-     * @since 1.9.0
1566
-     */
1567
-    public static function remove_course_meta_on_teacher_archive(){
1562
+	/**
1563
+	 * Removing course meta on the teacher archive page
1564
+	 *
1565
+	 * @since 1.9.0
1566
+	 */
1567
+	public static function remove_course_meta_on_teacher_archive(){
1568 1568
 
1569
-        remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1569
+		remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1570 1570
 
1571
-    }
1571
+	}
1572 1572
 
1573 1573
 } // End Class
Please login to merge, or discard this patch.
Spacing   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2
+if ( ! defined('ABSPATH')) exit; // Exit if accessed directly
3 3
 
4 4
 /**
5 5
  * Sensei Teacher class
@@ -40,58 +40,58 @@  discard block
 block discarded – undo
40 40
      * @since 1.8.0
41 41
      * @access public
42 42
      */
43
-    public function __construct ( ) {
43
+    public function __construct( ) {
44 44
 
45
-        add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 );
46
-        add_action( 'save_post',  array( $this, 'save_teacher_meta_box' ) );
47
-        add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' ));
48
-        add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) );
49
-        add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 );
45
+        add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2);
46
+        add_action('save_post', array($this, 'save_teacher_meta_box'));
47
+        add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types'));
48
+        add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit'));
49
+        add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3);
50 50
 
51
-        add_action( 'pre_get_posts', array( $this, 'filter_queries' ) );
51
+        add_action('pre_get_posts', array($this, 'filter_queries'));
52 52
 
53 53
         //filter the quiz submissions
54
-        add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') );
54
+        add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries'));
55 55
 
56 56
         //grading totals count only those belonging to the teacher
57
-        add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) );
57
+        add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals'));
58 58
 
59 59
         // show the courses owned by a user on his author archive page
60
-        add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) );
60
+        add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive'));
61 61
 
62 62
         // notify admin when a teacher creates a course
63
-        add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 );
63
+        add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3);
64 64
 
65 65
         // limit the analysis view to only the users taking courses belong to this teacher
66
-        add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 );
66
+        add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1);
67 67
 
68 68
         // give teacher access to question post type
69
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 );
69
+        add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2);
70 70
 
71 71
         // Teacher column on the courses list on the admin edit screen
72
-        add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 );
73
-        add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 );
72
+        add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1);
73
+        add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2);
74 74
 
75 75
         //admin edit messages query limit teacher
76
-        add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) );
76
+        add_filter('pre_get_posts', array($this, 'limit_edit_messages_query'));
77 77
 
78 78
         //add filter by teacher on courses list
79
-        add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) );
80
-        add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) );
79
+        add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options'));
80
+        add_filter('request', array($this, 'teacher_filter_query_modify'));
81 81
 
82 82
         // Handle media library restrictions
83
-        add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 );
84
-        add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 );
83
+        add_filter('request', array($this, 'restrict_media_library'), 10, 1);
84
+        add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1);
85 85
 
86 86
         // update lesson owner to course teacher when saved
87
-        add_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
87
+        add_action('save_post', array($this, 'update_lesson_teacher'));
88 88
 
89 89
         // If a Teacher logs in, redirect to /wp-admin/
90
-        add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 );
90
+        add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2);
91 91
 
92 92
 
93
-        add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10);
94
-        add_filter('pre_get_comments',  array ($this, 'restrict_comment_moderation'), 10, 1);
93
+        add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10);
94
+        add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1);
95 95
 
96 96
 
97 97
     } // end __constructor()
@@ -106,15 +106,15 @@  discard block
 block discarded – undo
106 106
      * @access public
107 107
      * @return void
108 108
      */
109
-    public function create_role ( ) {
109
+    public function create_role( ) {
110 110
 
111 111
         // check if the role exists
112
-        $this->teacher_role = get_role( 'teacher' );
112
+        $this->teacher_role = get_role('teacher');
113 113
 
114 114
         // if the the teacher is not a valid WordPress role create it
115
-       if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) {
115
+       if ( ! is_a($this->teacher_role, 'WP_Role')) {
116 116
            // create the role
117
-           $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) );
117
+           $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei'));
118 118
        }
119 119
 
120 120
        // add the capabilities before returning
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
      * @since 1.8.0
129 129
      * @access protected
130 130
      */
131
-    protected function add_capabilities ( ) {
131
+    protected function add_capabilities( ) {
132 132
 
133 133
         // if this is not a valid WP_Role object exit without adding anything
134
-        if(  ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) {
134
+        if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) {
135 135
             return;
136 136
         }
137 137
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
          * @param array $capabilities
143 143
          * keys: (string) $cap_name => (bool) $grant
144 144
          */
145
-        $caps = apply_filters( 'sensei_teacher_role_capabilities', array(
145
+        $caps = apply_filters('sensei_teacher_role_capabilities', array(
146 146
             // General access rules
147 147
             'read' => true,
148 148
             'manage_sensei_grades' => true,
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
 
200 200
         ));
201 201
 
202
-        foreach ( $caps as $cap => $grant ) {
202
+        foreach ($caps as $cap => $grant) {
203 203
 
204 204
             // load the capability on to the teacher role
205 205
             $this->teacher_role->add_cap($cap, $grant);
@@ -219,12 +219,12 @@  discard block
 block discarded – undo
219 219
      * @parameter WP_Post $post
220 220
      * @return void
221 221
      */
222
-    public function add_teacher_meta_boxes ( $post ) {
222
+    public function add_teacher_meta_boxes($post) {
223 223
 
224
-        if( !current_user_can('manage_options') ){
224
+        if ( ! current_user_can('manage_options')) {
225 225
             return;
226 226
         }
227
-        add_meta_box( 'sensei-teacher',  __( 'Teacher' , 'woothemes-sensei'),  array( $this , 'teacher_meta_box_content' ),
227
+        add_meta_box('sensei-teacher', __('Teacher', 'woothemes-sensei'), array($this, 'teacher_meta_box_content'),
228 228
             'course',
229 229
             'side',
230 230
             'core'
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      * @access public
242 242
      * @parameters
243 243
      */
244
-    public function teacher_meta_box_content ( $post ) {
244
+    public function teacher_meta_box_content($post) {
245 245
 
246 246
         // get the current author
247 247
         $current_author = $post->post_author;
@@ -252,12 +252,12 @@  discard block
 block discarded – undo
252 252
     ?>
253 253
         <select name="sensei-course-teacher-author" class="sensei course teacher">
254 254
 
255
-            <?php foreach ( $users as $user_id ) { ?>
255
+            <?php foreach ($users as $user_id) { ?>
256 256
 
257 257
                     <?php
258 258
                         $user = get_user_by('id', $user_id);
259 259
                     ?>
260
-                    <option <?php selected(  $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" >
260
+                    <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" >
261 261
                         <?php echo  $user->display_name; ?>
262 262
                     </option>
263 263
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
      * @parameters
280 280
      * @return array $users user id array
281 281
      */
282
-    public function get_teachers_and_authors ( ){
282
+    public function get_teachers_and_authors( ) {
283 283
 
284 284
         $author_query_args = array(
285 285
             'blog_id'      => $GLOBALS['blog_id'],
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             'who'          => 'authors'
288 288
         );
289 289
 
290
-        $authors = get_users( $author_query_args );
290
+        $authors = get_users($author_query_args);
291 291
 
292 292
         $teacher_query_args = array(
293 293
             'blog_id'      => $GLOBALS['blog_id'],
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
             'role'         => 'teacher',
296 296
         );
297 297
 
298
-        $teachers = get_users( $teacher_query_args );
298
+        $teachers = get_users($teacher_query_args);
299 299
 
300
-        return  array_unique( array_merge( $teachers, $authors ) );
300
+        return  array_unique(array_merge($teachers, $authors));
301 301
 
302 302
     }// end get_teachers_and_authors
303 303
 
@@ -313,43 +313,43 @@  discard block
 block discarded – undo
313 313
      * @parameters
314 314
      * @return array $users user id array
315 315
      */
316
-    public function save_teacher_meta_box ( $course_id ){
316
+    public function save_teacher_meta_box($course_id) {
317 317
 
318 318
         // check if this is a post from saving the teacher, if not exit early
319
-        if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] )  ){
319
+        if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) {
320 320
             return;
321 321
         }
322 322
 
323 323
         //don't fire this hook again
324
-        remove_action('save_post', array( $this, 'save_teacher_meta_box' ) );
324
+        remove_action('save_post', array($this, 'save_teacher_meta_box'));
325 325
 
326 326
         // get the current post object
327
-        $post = get_post( $course_id );
327
+        $post = get_post($course_id);
328 328
 
329 329
         // get the current teacher/author
330
-        $current_author = absint( $post->post_author );
331
-        $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] );
330
+        $current_author = absint($post->post_author);
331
+        $new_author = absint($_POST['sensei-course-teacher-author']);
332 332
 
333 333
         // loop through all post lessons to update their authors as well
334
-        $this->update_course_lessons_author( $course_id , $new_author );
334
+        $this->update_course_lessons_author($course_id, $new_author);
335 335
 
336 336
         // do not do any processing if the selected author is the same as the current author
337
-        if( $current_author == $new_author ){
337
+        if ($current_author == $new_author) {
338 338
             return;
339 339
         }
340 340
 
341 341
         // save the course  author
342 342
         $post_updates = array(
343
-            'ID' => $post->ID ,
343
+            'ID' => $post->ID,
344 344
             'post_author' => $new_author
345 345
         );
346
-        wp_update_post( $post_updates );
346
+        wp_update_post($post_updates);
347 347
 
348 348
         // ensure the the modules are update so that then new teacher has access to them
349
-        Sensei_Teacher::update_course_modules_author( $course_id, $new_author );
349
+        Sensei_Teacher::update_course_modules_author($course_id, $new_author);
350 350
 
351 351
         // notify the new teacher
352
-        $this->teacher_course_assigned_notification( $new_author, $course_id );
352
+        $this->teacher_course_assigned_notification($new_author, $course_id);
353 353
 
354 354
     } // end save_teacher_meta_box
355 355
 
@@ -363,56 +363,56 @@  discard block
 block discarded – undo
363 363
      * @param $new_teacher_id
364 364
      * @return void
365 365
      */
366
-    public static function update_course_modules_author( $course_id ,$new_teacher_id ){
366
+    public static function update_course_modules_author($course_id, $new_teacher_id) {
367 367
 
368
-        if( empty( $course_id ) || empty( $new_teacher_id ) ){
368
+        if (empty($course_id) || empty($new_teacher_id)) {
369 369
             return;
370 370
         }
371 371
 
372
-        $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' );
372
+        $terms_selected_on_course = wp_get_object_terms($course_id, 'module');
373 373
 
374
-        if( empty( $terms_selected_on_course ) ){
374
+        if (empty($terms_selected_on_course)) {
375 375
             return;
376 376
         }
377 377
 
378
-        foreach( $terms_selected_on_course as $term ){
378
+        foreach ($terms_selected_on_course as $term) {
379 379
 
380
-            $term_author = Sensei_Core_Modules::get_term_author( $term->slug );
381
-            if( $new_teacher_id != $term_author->ID  ){
380
+            $term_author = Sensei_Core_Modules::get_term_author($term->slug);
381
+            if ($new_teacher_id != $term_author->ID) {
382 382
 
383 383
                 $new_term = '';
384 384
 
385 385
                 //if the new teacher is admin first check to see if the term with this name already exists
386
-                if( user_can( $new_teacher_id, 'manage_options' ) ){
386
+                if (user_can($new_teacher_id, 'manage_options')) {
387 387
 
388
-                    $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) );
389
-                    $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, );
390
-                    $existing_admin_terms = get_terms( 'module', $term_args );
391
-                    if( !empty( $existing_admin_terms ) ){
388
+                    $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name));
389
+                    $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,);
390
+                    $existing_admin_terms = get_terms('module', $term_args);
391
+                    if ( ! empty($existing_admin_terms)) {
392 392
                         // insert it even if it exists
393
-                        $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A );
393
+                        $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A);
394 394
                     }
395 395
                 }
396 396
 
397
-                if( empty ( $new_term ) ){
397
+                if (empty ($new_term)) {
398 398
 
399 399
                    //setup the new slug
400
-                   $new_author_term_slug =  $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) );
400
+                   $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name));
401 401
 
402 402
                    // create new term and set it
403
-                   $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug )  );
403
+                   $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug));
404 404
 
405 405
                 }
406 406
 
407 407
 
408 408
 
409 409
                 // if term exists
410
-                if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){
410
+                if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) {
411 411
 
412
-                    $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module');
412
+                    $existing_term = get_term_by('slug', $new_author_term_slug, 'module');
413 413
                     $term_id = $existing_term->term_id;
414 414
 
415
-                }else{
415
+                } else {
416 416
 
417 417
                     // for a new term simply get the term from the returned value
418 418
                     $term_id = $new_term['term_id'];
@@ -420,21 +420,21 @@  discard block
 block discarded – undo
420 420
                 } // end if term exist
421 421
 
422 422
                 // set the terms selected on the course
423
-                wp_set_object_terms( $course_id, $term_id , 'module', true );
423
+                wp_set_object_terms($course_id, $term_id, 'module', true);
424 424
 
425 425
                 // remove old term
426
-                wp_remove_object_terms( $course_id, $term->term_id, 'module' );
426
+                wp_remove_object_terms($course_id, $term->term_id, 'module');
427 427
 
428 428
                 // update the lessons within the current module term
429
-                $lessons = Sensei()->course->course_lessons( $course_id );
430
-                foreach( $lessons as $lesson  ){
429
+                $lessons = Sensei()->course->course_lessons($course_id);
430
+                foreach ($lessons as $lesson) {
431 431
 
432
-                    if( has_term( $term->slug, 'module', $lesson ) ){
432
+                    if (has_term($term->slug, 'module', $lesson)) {
433 433
 
434 434
                         // add the new term, the false at the end says to replace all terms on this module
435 435
                         // with the new term.
436
-                        wp_set_object_terms( $lesson->ID, $term_id , 'module', false );
437
-                        update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 );
436
+                        wp_set_object_terms($lesson->ID, $term_id, 'module', false);
437
+                        update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0);
438 438
                     }
439 439
 
440 440
                 }// end for each
@@ -454,50 +454,50 @@  discard block
 block discarded – undo
454 454
      * @parameters
455 455
      * @return array $users user id array
456 456
      */
457
-    public function update_course_lessons_author ( $course_id, $new_author  ){
457
+    public function update_course_lessons_author($course_id, $new_author) {
458 458
 
459 459
 
460
-        if( empty( $course_id ) || empty( $new_author ) ){
460
+        if (empty($course_id) || empty($new_author)) {
461 461
             return false;
462 462
         }
463 463
 
464 464
         //get a list of course lessons
465
-        $lessons = Sensei()->course->course_lessons( $course_id );
465
+        $lessons = Sensei()->course->course_lessons($course_id);
466 466
 
467
-        if( empty( $lessons )  ||  ! is_array( $lessons )  ){
467
+        if (empty($lessons) || ! is_array($lessons)) {
468 468
             return false;
469 469
         }
470 470
 
471 471
         // update each lesson and quiz author
472
-        foreach( $lessons as $lesson ){
472
+        foreach ($lessons as $lesson) {
473 473
 
474 474
             // don't update if the author is tha same as the new author
475
-            if( $new_author == $lesson->post_author ){
475
+            if ($new_author == $lesson->post_author) {
476 476
                 continue;
477 477
             }
478 478
 
479 479
             // update lesson author
480
-            wp_update_post( array(
480
+            wp_update_post(array(
481 481
                 'ID'=> $lesson->ID,
482 482
                 'post_author' => $new_author
483
-                ) );
483
+                ));
484 484
 
485 485
             // update quiz author
486 486
             //get the lessons quiz
487
-            $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID );
488
-            if( is_array( $lesson_quizzes ) ){
489
-                foreach ( $lesson_quizzes as $quiz_id ) {
487
+            $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID);
488
+            if (is_array($lesson_quizzes)) {
489
+                foreach ($lesson_quizzes as $quiz_id) {
490 490
                     // update quiz with new author
491
-                    wp_update_post( array(
491
+                    wp_update_post(array(
492 492
                         'ID'           => $quiz_id,
493 493
                         'post_author' =>  $new_author
494
-                    ) );
494
+                    ));
495 495
                 }
496
-            }else{
497
-                wp_update_post( array(
496
+            } else {
497
+                wp_update_post(array(
498 498
                     'ID'           => $lesson_quizzes,
499 499
                     'post_author' =>  $new_author
500
-                ) );
500
+                ));
501 501
             }
502 502
 
503 503
         } // end for each lessons
@@ -518,30 +518,30 @@  discard block
 block discarded – undo
518 518
      * @parameters $query
519 519
      * @return array $users user id array
520 520
      */
521
-    public function course_analysis_teacher_access_limit ( $query ) {
521
+    public function course_analysis_teacher_access_limit($query) {
522 522
 
523
-        if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
523
+        if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) {
524 524
             return $query;
525 525
         }
526 526
 
527
-        if ( ! function_exists( 'get_current_screen' ) ) {
527
+        if ( ! function_exists('get_current_screen')) {
528 528
             return $query;
529 529
         }
530 530
 
531 531
         $screen = get_current_screen();
532
-        $sensei_post_types = array('course', 'lesson', 'question' );
532
+        $sensei_post_types = array('course', 'lesson', 'question');
533 533
 
534 534
         // exit early for the following conditions
535
-        $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' );
535
+        $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order');
536 536
 
537
-        if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids )
538
-            || ! in_array( $query->query['post_type'], $sensei_post_types ) ){
537
+        if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids)
538
+            || ! in_array($query->query['post_type'], $sensei_post_types)) {
539 539
             return $query;
540 540
         }
541 541
 
542 542
         global $current_user;
543 543
         // set the query author to the current user to only show those those posts
544
-        $query->set( 'author', $current_user->ID );
544
+        $query->set('author', $current_user->ID);
545 545
         return $query;
546 546
 
547 547
     }// end course_analysis_teacher_access_limit
@@ -557,14 +557,14 @@  discard block
 block discarded – undo
557 557
      * @parameters array $wp_query
558 558
      * @return bool $is_admin_teacher
559 559
      */
560
-    public function is_admin_teacher ( ){
560
+    public function is_admin_teacher( ) {
561 561
 
562
-        if( ! is_user_logged_in()){
562
+        if ( ! is_user_logged_in()) {
563 563
             return false;
564 564
         }
565 565
         $is_admin_teacher = false;
566 566
 
567
-        if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() )  ){
567
+        if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) {
568 568
 
569 569
             $is_admin_teacher = true;
570 570
 
@@ -584,14 +584,14 @@  discard block
 block discarded – undo
584 584
      * @param  string $perm   User permission level
585 585
      * @return object         Modified status counts
586 586
      */
587
-    public function list_table_counts( $counts, $type, $perm ) {
587
+    public function list_table_counts($counts, $type, $perm) {
588 588
         global $current_user;
589 589
 
590
-        if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) {
590
+        if ( ! in_array($type, array('course', 'lesson', 'question'))) {
591 591
             return $counts;
592 592
         }
593 593
 
594
-        if( ! $this->is_admin_teacher() ) {
594
+        if ( ! $this->is_admin_teacher()) {
595 595
             return $counts;
596 596
         }
597 597
 
@@ -605,10 +605,10 @@  discard block
 block discarded – undo
605 605
         $stati = get_post_stati();
606 606
 
607 607
         // Update count object
608
-        foreach( $stati as $status ) {
608
+        foreach ($stati as $status) {
609 609
             $args['post_status'] = $status;
610
-            $posts = get_posts( $args );
611
-            $counts->$status = count( $posts );
610
+            $posts = get_posts($args);
611
+            $counts->$status = count($posts);
612 612
         }
613 613
 
614 614
         return $counts;
@@ -622,22 +622,22 @@  discard block
 block discarded – undo
622 622
      * @since 1.8.0
623 623
      *
624 624
      */
625
-    public function filter_queries ( $query ) {
625
+    public function filter_queries($query) {
626 626
         global $current_user;
627 627
 
628
-        if( ! $this->is_admin_teacher() ) {
628
+        if ( ! $this->is_admin_teacher()) {
629 629
             return;
630 630
         }
631 631
 
632
-        if ( ! function_exists( 'get_current_screen' ) ) {
632
+        if ( ! function_exists('get_current_screen')) {
633 633
             return;
634 634
         }
635 635
 
636 636
         $screen = get_current_screen();
637
-        if( empty( $screen ) ) {
637
+        if (empty($screen)) {
638 638
             return $query;
639 639
         }
640
-        switch( $screen->id ) {
640
+        switch ($screen->id) {
641 641
             case 'sensei_page_sensei_grading':
642 642
             case 'sensei_page_sensei_analysis':
643 643
             case 'sensei_page_sensei_learners':
@@ -656,7 +656,7 @@  discard block
 block discarded – undo
656 656
              * @param string $screen_id
657 657
              *
658 658
              */
659
-            $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) );
659
+            $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id));
660 660
             break;
661 661
         }
662 662
     }
@@ -671,31 +671,31 @@  discard block
 block discarded – undo
671 671
      *
672 672
      * @return array $comments
673 673
      */
674
-    public function filter_grading_activity_queries( $comments ){
674
+    public function filter_grading_activity_queries($comments) {
675 675
 
676
-        if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){
677
-            return $comments ;
676
+        if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) {
677
+            return $comments;
678 678
         }
679 679
 
680 680
         //check if we're on the grading screen
681 681
         $screen = get_current_screen();
682 682
 
683
-        if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){
683
+        if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) {
684 684
             return $comments;
685 685
         }
686 686
 
687 687
         // get the course and determine if the current teacher is the owner
688 688
         // if not remove it from the list of comments to be returned
689
-        foreach( $comments as $key => $comment){
690
-            $lesson = get_post( $comment->comment_post_ID );
691
-            $course_id = Sensei()->lesson->get_course_id( $lesson->ID );
692
-            $course = get_post( $course_id );
693
-            if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){
689
+        foreach ($comments as $key => $comment) {
690
+            $lesson = get_post($comment->comment_post_ID);
691
+            $course_id = Sensei()->lesson->get_course_id($lesson->ID);
692
+            $course = get_post($course_id);
693
+            if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) {
694 694
                 //remove this as the teacher should see this.
695
-                unset( $comments[ $key ] );
695
+                unset($comments[$key]);
696 696
             }
697 697
         }
698
-        return $comments ;
698
+        return $comments;
699 699
 
700 700
     }// end function filter grading
701 701
 
@@ -711,34 +711,34 @@  discard block
 block discarded – undo
711 711
      *
712 712
      * @return array  $args
713 713
      */
714
-    public function limit_grading_totals( $args ){
714
+    public function limit_grading_totals($args) {
715 715
 
716
-        if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){
717
-            return $args ;
716
+        if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) {
717
+            return $args;
718 718
         }
719 719
 
720 720
         //get the teachers courses
721 721
         // the query is already filtered to only the teacher
722
-        $courses =  Sensei()->course->get_all_courses();
722
+        $courses = Sensei()->course->get_all_courses();
723 723
 
724
-        if( empty(  $courses ) || ! is_array( $courses ) ){
724
+        if (empty($courses) || ! is_array($courses)) {
725 725
             return $args;
726 726
         }
727 727
 
728 728
         //setup the lessons quizzes  to limit the grading totals to
729 729
         $quiz_scope = array();
730
-        foreach( $courses as $course ){
730
+        foreach ($courses as $course) {
731 731
 
732
-            $course_lessons = Sensei()->course->course_lessons( $course->ID );
732
+            $course_lessons = Sensei()->course->course_lessons($course->ID);
733 733
 
734
-            if( ! empty( $course_lessons ) && is_array( $course_lessons  ) ){
734
+            if ( ! empty($course_lessons) && is_array($course_lessons)) {
735 735
 
736
-                foreach(  $course_lessons as $lesson ){
736
+                foreach ($course_lessons as $lesson) {
737 737
 
738
-                    $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID );
739
-                    if( !empty( $quiz_id ) ) {
738
+                    $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID);
739
+                    if ( ! empty($quiz_id)) {
740 740
 
741
-                        array_push( $quiz_scope, $quiz_id );
741
+                        array_push($quiz_scope, $quiz_id);
742 742
 
743 743
                     }
744 744
 
@@ -761,41 +761,41 @@  discard block
 block discarded – undo
761 761
      * @param WP_Query $query
762 762
      * @return WP_Query $query
763 763
      */
764
-    public function add_courses_to_author_archive( $query ) {
764
+    public function add_courses_to_author_archive($query) {
765 765
 
766
-        if ( is_admin() || ! $query->is_author() ){
766
+        if (is_admin() || ! $query->is_author()) {
767 767
             return $query;
768 768
         }
769 769
 
770 770
         // this should only apply to users with the teacher role
771
-        $current_page_user = get_user_by('login', $query->get('author_name') );
772
-        if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) )     {
771
+        $current_page_user = get_user_by('login', $query->get('author_name'));
772
+        if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) {
773 773
 
774 774
             return $query;
775 775
 
776 776
         }
777 777
 
778 778
         // Change post types depending on what is set already
779
-        $current_post_types = $query->get( 'post_type' );
780
-        if( empty( $current_post_types  ) ){
779
+        $current_post_types = $query->get('post_type');
780
+        if (empty($current_post_types)) {
781 781
 
782 782
             // if empty it means post by default, so add post so that it also includes that for now
783
-            $new_post_types = array( 'post', 'course' );
783
+            $new_post_types = array('post', 'course');
784 784
 
785
-        } elseif( is_array( $current_post_types  ) ) {
785
+        } elseif (is_array($current_post_types)) {
786 786
 
787 787
             // merge the post types instead of overwriting it
788
-            $new_post_types = array_merge( $current_post_types, array( 'course' ) );
788
+            $new_post_types = array_merge($current_post_types, array('course'));
789 789
 
790
-        }else{
790
+        } else {
791 791
 
792 792
             // in this instance it is probably just one post type in string format
793
-            $new_post_types =  array( $current_post_types , 'course');
793
+            $new_post_types = array($current_post_types, 'course');
794 794
 
795 795
         }
796 796
 
797 797
         // change the query before returning it
798
-        $query->set('post_type', $new_post_types );
798
+        $query->set('post_type', $new_post_types);
799 799
 
800 800
         /**
801 801
          * Change the query on the teacher author archive template
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
          * @since 1.8.4
804 804
          * @param WP_Query $query
805 805
          */
806
-        return apply_filters( 'sensei_teacher_archive_query', $query );
806
+        return apply_filters('sensei_teacher_archive_query', $query);
807 807
 
808 808
     }
809 809
 
@@ -816,21 +816,21 @@  discard block
 block discarded – undo
816 816
      * @param $course_id
817 817
      * @return bool
818 818
      */
819
-    public function teacher_course_assigned_notification( $teacher_id, $course_id ){
819
+    public function teacher_course_assigned_notification($teacher_id, $course_id) {
820 820
 
821
-        if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){
821
+        if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) {
822 822
             return false;
823 823
         }
824 824
 
825 825
         // if new user is the same as the current logged user, they don't need an email
826
-        if( $teacher_id == get_current_user_id() ){
826
+        if ($teacher_id == get_current_user_id()) {
827 827
             return true;
828 828
         }
829 829
 
830 830
         // load the email class
831 831
         include('emails/class-sensei-email-teacher-new-course-assignment.php');
832 832
         $email = new Sensei_Email_Teacher_New_Course_Assignment();
833
-        $email->trigger( $teacher_id, $course_id );
833
+        $email->trigger($teacher_id, $course_id);
834 834
 
835 835
         return true;
836 836
     } // end  teacher_course_assigned_notification
@@ -844,12 +844,12 @@  discard block
 block discarded – undo
844 844
      * @param int $course_id
845 845
      * @return bool
846 846
      */
847
-    public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){
847
+    public function notify_admin_teacher_course_creation($new_status, $old_status, $post) {
848 848
 
849 849
         $course_id = $post->ID;
850 850
 
851
-        if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id )
852
-            || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) {
851
+        if ('course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id)
852
+            || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) {
853 853
 
854 854
             return false;
855 855
 
@@ -863,19 +863,19 @@  discard block
 block discarded – undo
863 863
          *
864 864
          * @param bool $on default true
865 865
          */
866
-        if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){
866
+        if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) {
867 867
             return false;
868 868
         }
869 869
 
870 870
         // setting up the data needed by the email template
871 871
         global $sensei_email_data;
872 872
         $template = 'admin-teacher-new-course-created';
873
-        $course = get_post( $course_id );
874
-        $teacher = new WP_User( $course->post_author );
873
+        $course = get_post($course_id);
874
+        $teacher = new WP_User($course->post_author);
875 875
         $recipient = get_option('admin_email', true);
876 876
 
877 877
         // don't send if the course is created by admin
878
-        if( $recipient == $teacher->user_email ){
878
+        if ($recipient == $teacher->user_email) {
879 879
             return;
880 880
         }
881 881
 
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
          * @since 1.8.0
886 886
          * @param string $template
887 887
          */
888
-        $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template );
888
+        $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template);
889 889
 
890 890
         /**
891 891
          * Filter the email subject for the the
@@ -896,11 +896,11 @@  discard block
 block discarded – undo
896 896
          * @param string $template
897 897
          */
898 898
         $subject = apply_filters('sensei_email_subject',
899
-                                '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name ,
900
-                                $template );
899
+                                '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name,
900
+                                $template);
901 901
 
902 902
         //course edit link
903
-        $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' );
903
+        $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit');
904 904
 
905 905
         // Construct data array
906 906
         $email_data = array(
@@ -919,10 +919,10 @@  discard block
 block discarded – undo
919 919
          * @param array $email_data
920 920
          * @param string $template
921 921
          */
922
-        $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template );
922
+        $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template);
923 923
 
924 924
         // Send mail
925
-        Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) );
925
+        Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template));
926 926
 
927 927
     }// end notify admin of course creation
928 928
 
@@ -933,10 +933,10 @@  discard block
 block discarded – undo
933 933
      * @param array $args WP_User_Query arguments
934 934
      * @return array $learners_query_results
935 935
      */
936
-    public function limit_analysis_learners( $args ){
936
+    public function limit_analysis_learners($args) {
937 937
 
938 938
         // show default for none teachers
939
-        if( ! Sensei()->teacher->is_admin_teacher() ) {
939
+        if ( ! Sensei()->teacher->is_admin_teacher()) {
940 940
                 return $args;
941 941
         }
942 942
 
@@ -945,31 +945,31 @@  discard block
 block discarded – undo
945 945
         $teacher_courses = Sensei()->course->get_all_courses();
946 946
 
947 947
         // if the user has no courses they should see no users
948
-        if( empty( $teacher_courses ) ||  ! is_array( $teacher_courses ) ){
948
+        if (empty($teacher_courses) || ! is_array($teacher_courses)) {
949 949
             // tell the query to return 0 students
950
-            $args[ 'include'] = array( 0 );
950
+            $args['include'] = array(0);
951 951
             return $args;
952 952
 
953 953
         }
954 954
 
955 955
         $learner_ids_for_teacher_courses = array();
956
-        foreach( $teacher_courses as $course ){
956
+        foreach ($teacher_courses as $course) {
957 957
 
958 958
             $course_learner_ids = array();
959
-            $activity_comments =  Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true );
959
+            $activity_comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true);
960 960
 
961
-            if( empty( $activity_comments ) ||  ( is_array( $activity_comments  ) && ! ( count( $activity_comments ) > 0 ) ) ){
961
+            if (empty($activity_comments) || (is_array($activity_comments) && ! (count($activity_comments) > 0))) {
962 962
                 continue; // skip to the next course as there are no users on this course
963 963
             }
964 964
 
965 965
             // it could be an array of comments or a single comment
966
-            if( is_array( $activity_comments ) ){
966
+            if (is_array($activity_comments)) {
967 967
 
968
-                foreach( $activity_comments as $comment ){
968
+                foreach ($activity_comments as $comment) {
969 969
 
970
-                    $user = get_userdata( $comment->user_id );
970
+                    $user = get_userdata($comment->user_id);
971 971
 
972
-                    if( empty( $user ) ){
972
+                    if (empty($user)) {
973 973
                         // next comment in this array
974 974
                         continue;
975 975
                     }
@@ -977,26 +977,26 @@  discard block
 block discarded – undo
977 977
                     $course_learner_ids[] = $user->ID;
978 978
                 }
979 979
 
980
-            }else{
980
+            } else {
981 981
 
982
-                $user = get_userdata( $activity_comments->user_id );
982
+                $user = get_userdata($activity_comments->user_id);
983 983
                 $course_learner_ids[] = $user->ID;
984 984
 
985 985
             }
986 986
 
987 987
             // add learners on this course to the all courses learner list
988
-            $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids );
988
+            $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids);
989 989
 
990 990
         }
991 991
 
992 992
         // if there are no students taking the courses by this teacher don't show them any of the other users
993
-        if( empty( $learner_ids_for_teacher_courses ) ){
993
+        if (empty($learner_ids_for_teacher_courses)) {
994 994
 
995
-            $args[ 'include'] = array( 0 );
995
+            $args['include'] = array(0);
996 996
 
997
-        }else{
997
+        } else {
998 998
 
999
-            $args[ 'include'] = $learner_ids_for_teacher_courses;
999
+            $args['include'] = $learner_ids_for_teacher_courses;
1000 1000
 
1001 1001
         }
1002 1002
 
@@ -1013,35 +1013,35 @@  discard block
 block discarded – undo
1013 1013
      * @param $questions
1014 1014
      * @return mixed
1015 1015
      */
1016
-    public function allow_teacher_access_to_questions( $questions, $quiz_id ){
1016
+    public function allow_teacher_access_to_questions($questions, $quiz_id) {
1017 1017
 
1018
-        if( ! $this->is_admin_teacher() ){
1018
+        if ( ! $this->is_admin_teacher()) {
1019 1019
             return $questions;
1020 1020
         }
1021 1021
 
1022 1022
         $screen = get_current_screen();
1023 1023
 
1024 1024
         // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions
1025
-        remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 );
1025
+        remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20);
1026 1026
 
1027
-        if( ! empty( $screen ) && 'lesson'== $screen->post_type ){
1027
+        if ( ! empty($screen) && 'lesson' == $screen->post_type) {
1028 1028
 
1029 1029
             $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1030
-            if( ! empty($admin_user) ){
1030
+            if ( ! empty($admin_user)) {
1031 1031
 
1032 1032
                 $current_teacher_id = get_current_user_id();
1033 1033
 
1034 1034
                 // set current user to admin so teacher can view all questions
1035
-                wp_set_current_user( $admin_user->ID  );
1036
-                $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id  );
1035
+                wp_set_current_user($admin_user->ID);
1036
+                $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id);
1037 1037
 
1038 1038
                 // set the teacher as the current use again
1039
-                wp_set_current_user( $current_teacher_id );
1039
+                wp_set_current_user($current_teacher_id);
1040 1040
             }
1041 1041
 
1042 1042
         }
1043 1043
         // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions
1044
-        add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 );
1044
+        add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2);
1045 1045
 
1046 1046
         return $questions;
1047 1047
     }
@@ -1053,30 +1053,30 @@  discard block
 block discarded – undo
1053 1053
      * @param $wp_query
1054 1054
      * @return mixed
1055 1055
      */
1056
-    public function give_access_to_all_questions( $wp_query ){
1056
+    public function give_access_to_all_questions($wp_query) {
1057 1057
 
1058
-        if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){
1058
+        if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) {
1059 1059
 
1060 1060
             return $wp_query;
1061 1061
         }
1062 1062
 
1063 1063
         $screen = get_current_screen();
1064
-        if( ( isset($screen->id) && 'lesson' == $screen->id )
1065
-            || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){
1064
+        if ((isset($screen->id) && 'lesson' == $screen->id)
1065
+            || (defined('DOING_AJAX') && DOING_AJAX)) {
1066 1066
 
1067 1067
             $admin_user = get_user_by('email', get_bloginfo('admin_email'));
1068
-            if( ! empty($admin_user) ){
1068
+            if ( ! empty($admin_user)) {
1069 1069
 
1070 1070
                 $current_teacher_id = get_current_user_id();
1071 1071
 
1072 1072
                 // set current user to admin so teacher can view all questions
1073
-                wp_set_current_user( $admin_user->ID  );
1073
+                wp_set_current_user($admin_user->ID);
1074 1074
 
1075 1075
                 //run new query as admin
1076
-                $wp_query = new WP_Query( $wp_query->query );
1076
+                $wp_query = new WP_Query($wp_query->query);
1077 1077
 
1078 1078
                 //set the teache as current use again
1079
-                wp_set_current_user( $current_teacher_id );
1079
+                wp_set_current_user($current_teacher_id);
1080 1080
 
1081 1081
             }
1082 1082
         }
@@ -1093,7 +1093,7 @@  discard block
 block discarded – undo
1093 1093
      */
1094 1094
     public function course_column_heading($columns) {
1095 1095
 
1096
-        if( $this->is_admin_teacher() ){
1096
+        if ($this->is_admin_teacher()) {
1097 1097
             return $columns;
1098 1098
         }
1099 1099
         $new_columns = array(
@@ -1110,20 +1110,20 @@  discard block
 block discarded – undo
1110 1110
      * @param $column
1111 1111
      * @param $course_id
1112 1112
      */
1113
-    public function course_column_data( $column, $course_id  ){
1113
+    public function course_column_data($column, $course_id) {
1114 1114
 
1115
-        if( $this->is_admin_teacher() || 'teacher' != $column  ){
1115
+        if ($this->is_admin_teacher() || 'teacher' != $column) {
1116 1116
             return;
1117 1117
         }
1118 1118
 
1119
-        $course = get_post( $course_id );
1120
-        $teacher = get_userdata( $course->post_author );
1119
+        $course = get_post($course_id);
1120
+        $teacher = get_userdata($course->post_author);
1121 1121
 
1122
-        if( !$teacher ){
1122
+        if ( ! $teacher) {
1123 1123
             return;
1124 1124
         }
1125 1125
 
1126
-        echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>';
1126
+        echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>';
1127 1127
 
1128 1128
     }// end course_column_ data
1129 1129
 
@@ -1138,31 +1138,31 @@  discard block
 block discarded – undo
1138 1138
      *
1139 1139
      * @return array $teachers_courses
1140 1140
      */
1141
-    public function get_teacher_courses( $teacher_id, $return_ids_only= false){
1141
+    public function get_teacher_courses($teacher_id, $return_ids_only = false) {
1142 1142
 
1143 1143
         $teachers_courses = array();
1144 1144
 
1145
-        if( empty( $teacher_id  ) ){
1145
+        if (empty($teacher_id)) {
1146 1146
             $teacher_id = get_current_user_id();
1147 1147
         }
1148 1148
 
1149 1149
         $all_courses = Sensei()->course->get_all_courses();
1150 1150
 
1151
-        if( empty( $all_courses ) ){
1151
+        if (empty($all_courses)) {
1152 1152
             return $all_courses;
1153 1153
         }
1154 1154
 
1155
-        foreach( $all_courses as $course ){
1155
+        foreach ($all_courses as $course) {
1156 1156
 
1157
-            if( $course->post_author != $teacher_id  ){
1157
+            if ($course->post_author != $teacher_id) {
1158 1158
                 continue;
1159 1159
             }
1160 1160
 
1161
-            if( $return_ids_only ){
1161
+            if ($return_ids_only) {
1162 1162
 
1163 1163
                 $teachers_courses[] = $course->ID;
1164 1164
 
1165
-            }else{
1165
+            } else {
1166 1166
 
1167 1167
                 $teachers_courses[] = $course;
1168 1168
 
@@ -1182,21 +1182,21 @@  discard block
 block discarded – undo
1182 1182
      * @param $query
1183 1183
      * @return mixed
1184 1184
      */
1185
-    public function limit_edit_messages_query( $query ){
1186
-        if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){
1185
+    public function limit_edit_messages_query($query) {
1186
+        if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) {
1187 1187
             return $query;
1188 1188
         }
1189 1189
 
1190 1190
         $teacher = wp_get_current_user();
1191 1191
 
1192
-        $query->set( 'meta_key', '_receiver' );
1192
+        $query->set('meta_key', '_receiver');
1193 1193
         $meta_query_args = array(
1194 1194
             'key'     => '_receiver',
1195
-            'value'   => $teacher->get('user_login') ,
1195
+            'value'   => $teacher->get('user_login'),
1196 1196
             'compare' => '='
1197 1197
         );
1198 1198
 
1199
-        $query->set('meta_query', $meta_query_args  );
1199
+        $query->set('meta_query', $meta_query_args);
1200 1200
 
1201 1201
         return $query;
1202 1202
     }
@@ -1212,7 +1212,7 @@  discard block
 block discarded – undo
1212 1212
     public function course_teacher_filter_options() {
1213 1213
         global $typenow;
1214 1214
 
1215
-        if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) {
1215
+        if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) {
1216 1216
             return;
1217 1217
         }
1218 1218
 
@@ -1222,31 +1222,31 @@  discard block
 block discarded – undo
1222 1222
         // get roles with the course edit capability
1223 1223
         // and then get the users with those roles
1224 1224
         $users_who_can_edit_courses = array();
1225
-        foreach( $roles as $role_item ){
1225
+        foreach ($roles as $role_item) {
1226 1226
 
1227
-            $role = get_role( strtolower( $role_item['name'] ) );
1227
+            $role = get_role(strtolower($role_item['name']));
1228 1228
 
1229
-            if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){
1229
+            if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) {
1230 1230
 
1231
-                $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) );
1232
-                $role_users_who_can_edit_courses = get_users( $user_query_args );
1231
+                $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name'));
1232
+                $role_users_who_can_edit_courses = get_users($user_query_args);
1233 1233
 
1234 1234
                 // add user from the current $user_role to all users
1235
-                $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses );
1235
+                $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses);
1236 1236
 
1237 1237
             }
1238 1238
 
1239 1239
         }
1240 1240
 
1241 1241
         // Create the select element with the given users who can edit course
1242
-        $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1242
+        $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : '';
1243 1243
         $course_options = '';
1244
-        foreach( $users_who_can_edit_courses as $user ) {
1245
-            $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' .  $user->display_name . '</option>';
1244
+        foreach ($users_who_can_edit_courses as $user) {
1245
+            $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>';
1246 1246
         }
1247 1247
 
1248 1248
         $output = '<select name="course_teacher" id="dropdown_course_teachers">';
1249
-        $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>';
1249
+        $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>';
1250 1250
         $output .= $course_options;
1251 1251
         $output .= '</select>';
1252 1252
 
@@ -1261,15 +1261,15 @@  discard block
 block discarded – undo
1261 1261
      * @param $query
1262 1262
      * @return $query
1263 1263
      */
1264
-    public function teacher_filter_query_modify( $query ){
1264
+    public function teacher_filter_query_modify($query) {
1265 1265
         global $typenow;
1266 1266
 
1267
-        if( ! is_admin() && 'course' != $typenow  || ! current_user_can('manage_sensei')  ) {
1267
+        if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) {
1268 1268
             return $query;
1269 1269
         }
1270
-        $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : '';
1270
+        $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : '';
1271 1271
 
1272
-        if( empty( $course_teacher ) ) {
1272
+        if (empty($course_teacher)) {
1273 1273
             return $query;
1274 1274
         }
1275 1275
 
@@ -1282,23 +1282,23 @@  discard block
 block discarded – undo
1282 1282
      * @param  array $request Default request arguments
1283 1283
      * @return array          Modified request arguments
1284 1284
      */
1285
-    public function restrict_media_library( $request = array() ) {
1285
+    public function restrict_media_library($request = array()) {
1286 1286
 
1287
-        if( ! is_admin() ) {
1287
+        if ( ! is_admin()) {
1288 1288
             return $request;
1289 1289
         }
1290 1290
 
1291
-        if( ! $this->is_admin_teacher() ) {
1291
+        if ( ! $this->is_admin_teacher()) {
1292 1292
             return $request;
1293 1293
         }
1294 1294
 
1295 1295
         $screen = get_current_screen();
1296 1296
 
1297
-        if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) {
1298
-            $teacher = intval( get_current_user_id() );
1297
+        if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) {
1298
+            $teacher = intval(get_current_user_id());
1299 1299
 
1300
-            if( $teacher ) {
1301
-                $request['author__in'] = array( $teacher );
1300
+            if ($teacher) {
1301
+                $request['author__in'] = array($teacher);
1302 1302
             }
1303 1303
         }
1304 1304
 
@@ -1310,20 +1310,20 @@  discard block
 block discarded – undo
1310 1310
      * @param  array $query Default query arguments
1311 1311
      * @return array        Modified query arguments
1312 1312
      */
1313
-    public function restrict_media_library_modal( $query = array() ) {
1313
+    public function restrict_media_library_modal($query = array()) {
1314 1314
 
1315
-        if( ! is_admin() ) {
1315
+        if ( ! is_admin()) {
1316 1316
             return $query;
1317 1317
         }
1318 1318
 
1319
-        if( ! $this->is_admin_teacher() ) {
1319
+        if ( ! $this->is_admin_teacher()) {
1320 1320
             return $query;
1321 1321
         }
1322 1322
 
1323
-        $teacher = intval( get_current_user_id() );
1323
+        $teacher = intval(get_current_user_id());
1324 1324
 
1325
-        if( $teacher ) {
1326
-            $query['author__in'] = array( $teacher );
1325
+        if ($teacher) {
1326
+            $query['author__in'] = array($teacher);
1327 1327
         }
1328 1328
 
1329 1329
         return $query;
@@ -1336,28 +1336,28 @@  discard block
 block discarded – undo
1336 1336
      *
1337 1337
      * @param int $lesson_id
1338 1338
      */
1339
-    public function update_lesson_teacher( $lesson_id ){
1339
+    public function update_lesson_teacher($lesson_id) {
1340 1340
 
1341
-        if( 'lesson'!= get_post_type() ){
1341
+        if ('lesson' != get_post_type()) {
1342 1342
             return;
1343 1343
         }
1344 1344
 
1345 1345
         // this should only run once per request cycle
1346
-        remove_action( 'save_post',  array( $this, 'update_lesson_teacher' ) );
1346
+        remove_action('save_post', array($this, 'update_lesson_teacher'));
1347 1347
 
1348
-        $course_id = Sensei()->lesson->get_course_id( $lesson_id );
1348
+        $course_id = Sensei()->lesson->get_course_id($lesson_id);
1349 1349
 
1350
-        if(  empty( $course_id ) || ! $course_id ){
1350
+        if (empty($course_id) || ! $course_id) {
1351 1351
             return;
1352 1352
         }
1353 1353
 
1354
-        $course = get_post( $course_id );
1354
+        $course = get_post($course_id);
1355 1355
 
1356
-        $lesson_update_args= array(
1357
-            'ID' => $lesson_id ,
1356
+        $lesson_update_args = array(
1357
+            'ID' => $lesson_id,
1358 1358
             'post_author' => $course->post_author
1359 1359
         );
1360
-        wp_update_post( $lesson_update_args );
1360
+        wp_update_post($lesson_update_args);
1361 1361
 
1362 1362
     } // end update_lesson_teacher
1363 1363
 
@@ -1371,21 +1371,21 @@  discard block
 block discarded – undo
1371 1371
      * @parameters array $wp_query
1372 1372
      * @return WP_Query $wp_query
1373 1373
      */
1374
-    public function limit_teacher_edit_screen_post_types( $wp_query ) {
1374
+    public function limit_teacher_edit_screen_post_types($wp_query) {
1375 1375
         global $current_user;
1376 1376
 
1377 1377
         //exit early
1378
-        if( ! $this->is_admin_teacher() ){
1378
+        if ( ! $this->is_admin_teacher()) {
1379 1379
             return $wp_query;
1380 1380
         }
1381 1381
 
1382
-        if ( ! function_exists( 'get_current_screen' ) ) {
1382
+        if ( ! function_exists('get_current_screen')) {
1383 1383
             return $wp_query;
1384 1384
         }
1385 1385
 
1386 1386
         $screen = get_current_screen();
1387 1387
 
1388
-        if( empty( $screen ) ){
1388
+        if (empty($screen)) {
1389 1389
             return $wp_query;
1390 1390
         }
1391 1391
 
@@ -1398,10 +1398,10 @@  discard block
 block discarded – undo
1398 1398
             'lesson_page_lesson-order',
1399 1399
         );
1400 1400
 
1401
-        if(  in_array($screen->id  , $limit_screens ) ) {
1401
+        if (in_array($screen->id, $limit_screens)) {
1402 1402
 
1403 1403
             // set the query author to the current user to only show those those posts
1404
-            $wp_query->set( 'author', $current_user->ID );
1404
+            $wp_query->set('author', $current_user->ID);
1405 1405
         }
1406 1406
 
1407 1407
         return $wp_query;
@@ -1421,7 +1421,7 @@  discard block
 block discarded – undo
1421 1421
      * @return void
1422 1422
      */
1423 1423
 
1424
-    public function teacher_login_redirect( $user_login, $user  ) {
1424
+    public function teacher_login_redirect($user_login, $user) {
1425 1425
 
1426 1426
         if (user_can($user, 'edit_courses')) {
1427 1427
 
@@ -1471,9 +1471,9 @@  discard block
 block discarded – undo
1471 1471
          * @param bool $restrict default true
1472 1472
          */
1473 1473
 
1474
-        $restrict = apply_filters('sensei_restrict_posts_menu_page', true );
1474
+        $restrict = apply_filters('sensei_restrict_posts_menu_page', true);
1475 1475
 
1476
-        if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) {
1476
+        if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) {
1477 1477
 
1478 1478
             remove_menu_page('edit.php');
1479 1479
 
@@ -1503,11 +1503,11 @@  discard block
 block discarded – undo
1503 1503
      * @return WP_Comment_Query  $clauses
1504 1504
      */
1505 1505
 
1506
-    public function restrict_comment_moderation ( $clauses ) {
1506
+    public function restrict_comment_moderation($clauses) {
1507 1507
 
1508 1508
         global $pagenow;
1509 1509
 
1510
-        if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") {
1510
+        if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") {
1511 1511
 
1512 1512
             $clauses->query_vars['post_author'] = get_current_user_id();
1513 1513
 
@@ -1524,15 +1524,15 @@  discard block
 block discarded – undo
1524 1524
      *
1525 1525
      * @return bool
1526 1526
      */
1527
-    public static function is_a_teacher( $user_id ){
1527
+    public static function is_a_teacher($user_id) {
1528 1528
 
1529 1529
         $user = get_user_by('id', $user_id);
1530 1530
 
1531
-        if( isset( $user->roles ) && in_array(  'teacher',  $user->roles )   ){
1531
+        if (isset($user->roles) && in_array('teacher', $user->roles)) {
1532 1532
 
1533 1533
             return true;
1534 1534
 
1535
-        }else{
1535
+        } else {
1536 1536
 
1537 1537
             return false;
1538 1538
 
@@ -1545,14 +1545,14 @@  discard block
 block discarded – undo
1545 1545
      *
1546 1546
      * @since 1.9.0
1547 1547
      */
1548
-    public static function archive_title(){
1548
+    public static function archive_title() {
1549 1549
 
1550
-        $author = get_user_by( 'id', get_query_var( 'author' ) );
1550
+        $author = get_user_by('id', get_query_var('author'));
1551 1551
         $author_name = $author->display_name;
1552 1552
         ?>
1553 1553
             <h2 class="teacher-archive-title">
1554 1554
 
1555
-                <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?>
1555
+                <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?>
1556 1556
 
1557 1557
             </h2>
1558 1558
         <?php
@@ -1564,9 +1564,9 @@  discard block
 block discarded – undo
1564 1564
      *
1565 1565
      * @since 1.9.0
1566 1566
      */
1567
-    public static function remove_course_meta_on_teacher_archive(){
1567
+    public static function remove_course_meta_on_teacher_archive() {
1568 1568
 
1569
-        remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) );
1569
+        remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta'));
1570 1570
 
1571 1571
     }
1572 1572
 
Please login to merge, or discard this patch.