Completed
Push — master ( 78b9e3...efb4fd )
by Dwain
04:49
created
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.
Indentation   +1888 added lines, -1888 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,1405 +335,1405 @@  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 )
1173
-            || is_wp_error( $modules )
1174
-            || isset( $modules['errors'] ) ){
1175
-
1176
-            return false;
1177
-
1178
-        }
1179
-
1180
-       // get the last item in the array there should be only be 1 really.
1181
-       // this method works for all php versions.
1182
-       foreach( $modules as $module ){
1183
-           break;
1184
-       }
1185
-
1186
-        if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1187
-            return false;
1188
-        }
1189
-
1190
-        $module->url = get_term_link($module, $this->taxonomy);
1191
-        $course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1192
-        if (isset($course_id) && 0 < $course_id) {
1193
-
1194
-            // the course should contain the same module taxonomy term for this to be valid
1195
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1196
-                return false;
1197
-            }
1198
-
1199
-            $module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1200
-        }
1201
-        return $module;
1202
-
1203
-    }
1204
-
1205
-    /**
1206
-     * Get ordered array of all modules in course
1207
-     *
1208
-     * @since 1.8.0
1209
-     *
1210
-     * @param  integer $course_id ID of course
1211
-     * @return array              Ordered array of module taxonomy term objects
1212
-     */
1213
-    public function get_course_modules($course_id = 0)
1214
-    {
1215
-        $course_id = intval($course_id);
1216
-        if (0 < $course_id) {
1217
-
1218
-            // Get modules for course
1219
-            $modules = wp_get_post_terms($course_id, $this->taxonomy);
1220
-
1221
-            // Get custom module order for course
1222
-            $order = $this->get_course_module_order($course_id);
1223
-
1224
-            // Sort by custom order if custom order exists
1225
-            if ($order) {
1226
-                $ordered_modules = array();
1227
-                $unordered_modules = array();
1228
-                foreach ($modules as $module) {
1229
-                    $order_key = array_search($module->term_id, $order);
1230
-                    if ($order_key !== false) {
1231
-                        $ordered_modules[$order_key] = $module;
1232
-                    } else {
1233
-                        $unordered_modules[] = $module;
1234
-                    }
1235
-                }
1236
-
1237
-                // Order modules correctly
1238
-                ksort($ordered_modules);
1239
-
1240
-                // Append modules that have not yet been ordered
1241
-                if (count($unordered_modules) > 0) {
1242
-                    $ordered_modules = array_merge($ordered_modules, $unordered_modules);
1243
-                }
1244
-
1245
-            } else {
1246
-
1247
-                $ordered_modules = $modules;
1248
-
1249
-            }
1250
-
1251
-            return $ordered_modules;
1252
-
1253
-        }
1254
-
1255
-        return false;
1256
-    }
1257
-
1258
-    /**
1259
-     * Load frontend CSS
1260
-     *
1261
-     * @since 1.8.0
1262
-     *
1263
-     * @return void
1264
-     */
1265
-    public function enqueue_styles() {
1266
-
1267
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1268
-        wp_enqueue_style($this->taxonomy . '-frontend');
1269
-
1270
-    }
1271
-
1272
-    /**
1273
-     * Load admin Javascript
1274
-     *
1275
-     * @since 1.8.0
1276
-     *
1277
-     * @return void
1278
-     */
1279
-    public function admin_enqueue_scripts( $hook ) {
1280
-
1281
-        /**
1282
-         * Filter the page hooks where modules admin script can be loaded on.
1283
-         *
1284
-         * @param array $white_listed_pages
1285
-         */
1286
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1287
-            'edit-tags.php',
1288
-            'course_page_module-order',
1289
-            'post-new.php',
1290
-            'post.php'
1291
-        ) );
1292
-
1293
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1294
-            return;
1295
-        }
1296
-
1297
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1298
-
1299
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1300
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1301
-        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', 'sensei-core-select2' ), Sensei()->version, true );
1302
-
1303
-        // localized module data
1304
-        $localize_modulesAdmin = array(
1305
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1306
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1307
-        );
1308
-
1309
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1310
-    }
1311
-
1312
-    /**
1313
-     * Load admin CSS
1314
-     *
1315
-     * @since 1.8.0
1316
-     *
1317
-     * @return void
1318
-     */
1319
-    public function admin_enqueue_styles() {
1320
-
1321
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1322
-        wp_enqueue_style($this->taxonomy . '-sortable');
1323
-
1324
-    }
1325
-
1326
-    /**
1327
-     * Show the title modules on the single course template.
1328
-     *
1329
-     * Function is hooked into sensei_single_course_modules_before.
1330
-     *
1331
-     * @since 1.8.0
1332
-     * @return void
1333
-     */
1334
-    public function course_modules_title( ) {
1335
-
1336
-       if( sensei_module_has_lessons() ){
1337
-
1338
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1339
-
1340
-        }
1341
-
1342
-    }
1343
-
1344
-    /**
1345
-     * Display the single course modules content this will only show
1346
-     * if the course has modules.
1347
-     *
1348
-     * @since 1.8.0
1349
-     * @return void
1350
-     */
1351
-    public function load_course_module_content_template(){
1352
-
1353
-	    if ( ! is_singular( 'course' )  ) {
1354
-		    return;
1355
-	    }
1356
-
1357
-        // load backwards compatible template name if it exists in the users theme
1358
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1359
-        if( $located_template ){
1360
-
1361
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1362
-            return;
1363
-
1364
-        }
1365
-
1366
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1367
-
1368
-    } // end course_module_content
1369
-
1370
-    /**
1371
-     * Returns all lessons for the given module ID
1372
-     *
1373
-     * @since 1.8.0
1374
-     *
1375
-     * @param $course_id
1376
-     * @param $term_id
1377
-     * @return array $lessons
1378
-     */
1379
-    public function get_lessons( $course_id , $term_id ){
1380
-
1381
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1382
-
1383
-        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 )
1173
+			|| is_wp_error( $modules )
1174
+			|| isset( $modules['errors'] ) ){
1175
+
1176
+			return false;
1177
+
1178
+		}
1179
+
1180
+	   // get the last item in the array there should be only be 1 really.
1181
+	   // this method works for all php versions.
1182
+	   foreach( $modules as $module ){
1183
+		   break;
1184
+	   }
1185
+
1186
+		if ( ! isset($module) || ! is_object($module) || is_wp_error($module)) {
1187
+			return false;
1188
+		}
1189
+
1190
+		$module->url = get_term_link($module, $this->taxonomy);
1191
+		$course_id = intval(get_post_meta(intval($lesson_id), '_lesson_course', true));
1192
+		if (isset($course_id) && 0 < $course_id) {
1193
+
1194
+			// the course should contain the same module taxonomy term for this to be valid
1195
+			if( ! has_term( $module, $this->taxonomy, $course_id)){
1196
+				return false;
1197
+			}
1198
+
1199
+			$module->url = esc_url(add_query_arg('course_id', intval($course_id), $module->url));
1200
+		}
1201
+		return $module;
1202
+
1203
+	}
1204
+
1205
+	/**
1206
+	 * Get ordered array of all modules in course
1207
+	 *
1208
+	 * @since 1.8.0
1209
+	 *
1210
+	 * @param  integer $course_id ID of course
1211
+	 * @return array              Ordered array of module taxonomy term objects
1212
+	 */
1213
+	public function get_course_modules($course_id = 0)
1214
+	{
1215
+		$course_id = intval($course_id);
1216
+		if (0 < $course_id) {
1217
+
1218
+			// Get modules for course
1219
+			$modules = wp_get_post_terms($course_id, $this->taxonomy);
1220
+
1221
+			// Get custom module order for course
1222
+			$order = $this->get_course_module_order($course_id);
1223
+
1224
+			// Sort by custom order if custom order exists
1225
+			if ($order) {
1226
+				$ordered_modules = array();
1227
+				$unordered_modules = array();
1228
+				foreach ($modules as $module) {
1229
+					$order_key = array_search($module->term_id, $order);
1230
+					if ($order_key !== false) {
1231
+						$ordered_modules[$order_key] = $module;
1232
+					} else {
1233
+						$unordered_modules[] = $module;
1234
+					}
1235
+				}
1236
+
1237
+				// Order modules correctly
1238
+				ksort($ordered_modules);
1239
+
1240
+				// Append modules that have not yet been ordered
1241
+				if (count($unordered_modules) > 0) {
1242
+					$ordered_modules = array_merge($ordered_modules, $unordered_modules);
1243
+				}
1244
+
1245
+			} else {
1246
+
1247
+				$ordered_modules = $modules;
1248
+
1249
+			}
1250
+
1251
+			return $ordered_modules;
1252
+
1253
+		}
1254
+
1255
+		return false;
1256
+	}
1257
+
1258
+	/**
1259
+	 * Load frontend CSS
1260
+	 *
1261
+	 * @since 1.8.0
1262
+	 *
1263
+	 * @return void
1264
+	 */
1265
+	public function enqueue_styles() {
1266
+
1267
+		wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1268
+		wp_enqueue_style($this->taxonomy . '-frontend');
1269
+
1270
+	}
1271
+
1272
+	/**
1273
+	 * Load admin Javascript
1274
+	 *
1275
+	 * @since 1.8.0
1276
+	 *
1277
+	 * @return void
1278
+	 */
1279
+	public function admin_enqueue_scripts( $hook ) {
1280
+
1281
+		/**
1282
+		 * Filter the page hooks where modules admin script can be loaded on.
1283
+		 *
1284
+		 * @param array $white_listed_pages
1285
+		 */
1286
+		$script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1287
+			'edit-tags.php',
1288
+			'course_page_module-order',
1289
+			'post-new.php',
1290
+			'post.php'
1291
+		) );
1292
+
1293
+		if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1294
+			return;
1295
+		}
1296
+
1297
+		$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1298
+
1299
+		wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1300
+		wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1301
+		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', 'sensei-core-select2' ), Sensei()->version, true );
1302
+
1303
+		// localized module data
1304
+		$localize_modulesAdmin = array(
1305
+			'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1306
+			'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1307
+		);
1308
+
1309
+		wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1310
+	}
1311
+
1312
+	/**
1313
+	 * Load admin CSS
1314
+	 *
1315
+	 * @since 1.8.0
1316
+	 *
1317
+	 * @return void
1318
+	 */
1319
+	public function admin_enqueue_styles() {
1320
+
1321
+		wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1322
+		wp_enqueue_style($this->taxonomy . '-sortable');
1323
+
1324
+	}
1325
+
1326
+	/**
1327
+	 * Show the title modules on the single course template.
1328
+	 *
1329
+	 * Function is hooked into sensei_single_course_modules_before.
1330
+	 *
1331
+	 * @since 1.8.0
1332
+	 * @return void
1333
+	 */
1334
+	public function course_modules_title( ) {
1335
+
1336
+	   if( sensei_module_has_lessons() ){
1337
+
1338
+			echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1339
+
1340
+		}
1341
+
1342
+	}
1343
+
1344
+	/**
1345
+	 * Display the single course modules content this will only show
1346
+	 * if the course has modules.
1347
+	 *
1348
+	 * @since 1.8.0
1349
+	 * @return void
1350
+	 */
1351
+	public function load_course_module_content_template(){
1352
+
1353
+		if ( ! is_singular( 'course' )  ) {
1354
+			return;
1355
+		}
1356
+
1357
+		// load backwards compatible template name if it exists in the users theme
1358
+		$located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1359
+		if( $located_template ){
1360
+
1361
+			Sensei_Templates::get_template( 'single-course/course-modules.php' );
1362
+			return;
1363
+
1364
+		}
1365
+
1366
+		Sensei_Templates::get_template( 'single-course/modules.php' );
1367
+
1368
+	} // end course_module_content
1369
+
1370
+	/**
1371
+	 * Returns all lessons for the given module ID
1372
+	 *
1373
+	 * @since 1.8.0
1374
+	 *
1375
+	 * @param $course_id
1376
+	 * @param $term_id
1377
+	 * @return array $lessons
1378
+	 */
1379
+	public function get_lessons( $course_id , $term_id ){
1380
+
1381
+		$lesson_query = $this->get_lessons_query( $course_id, $term_id );
1382
+
1383
+		if( isset( $lesson_query->posts ) ){
1384 1384
 
1385
-            return $lesson_query->posts;
1385
+			return $lesson_query->posts;
1386 1386
 
1387
-        }else{
1387
+		}else{
1388 1388
 
1389
-            return array();
1389
+			return array();
1390 1390
 
1391
-        }
1391
+		}
1392 1392
 
1393
-    } // end get lessons
1393
+	} // end get lessons
1394 1394
 
1395
-    /**
1396
-     * Returns all lessons for the given module ID
1397
-     *
1398
-     * @since 1.8.0
1399
-     *
1400
-     * @param $course_id
1401
-     * @param $term_id
1402
-     * @return WP_Query $lessons_query
1403
-     */
1404
-    public function get_lessons_query( $course_id , $term_id ){
1405
-
1406
-        if( empty( $term_id ) || empty( $course_id ) ){
1407
-
1408
-            return array();
1409
-
1410
-        }
1411
-
1412
-        $args = array(
1413
-            'post_type' => 'lesson',
1414
-            'post_status' => 'publish',
1415
-            'posts_per_page' => -1,
1416
-            'meta_query' => array(
1417
-                array(
1418
-                    'key' => '_lesson_course',
1419
-                    'value' => intval($course_id),
1420
-                    'compare' => '='
1421
-                )
1422
-            ),
1423
-            'tax_query' => array(
1424
-                array(
1425
-                    'taxonomy' => 'module',
1426
-                    'field' => 'id',
1427
-                    'terms' => intval( $term_id )
1428
-                )
1429
-            ),
1430
-            'orderby' => 'menu_order',
1431
-            'order' => 'ASC',
1432
-            'suppress_filters' => 0
1433
-        );
1434
-
1435
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1436
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1437
-            $args['orderby'] = 'meta_value_num date';
1438
-        }
1439
-
1440
-        $lessons_query = new WP_Query( $args );
1441
-
1442
-        return $lessons_query;
1443
-
1444
-    } // end get lessons
1445
-
1446
-    /**
1447
-     * Find the lesson in the given course that doesn't belong
1448
-     * to any of the courses modules
1449
-     *
1450
-     *
1451
-     * @param $course_id
1452
-     *
1453
-     * @return array $non_module_lessons
1454
-     */
1455
-    public function get_none_module_lessons( $course_id ){
1456
-
1457
-        $non_module_lessons = array();
1458
-
1459
-        //exit if there is no course id passed in
1460
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1461
-
1462
-            return $non_module_lessons;
1463
-        }
1464
-
1465
-        //save some time and check if we already have the saved
1466
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1467
-
1468
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1469
-
1470
-        }
1471
-
1472
-        // create terms array which must be excluded from other arrays
1473
-        $course_modules = $this->get_course_modules( $course_id );
1474
-
1475
-        //exit if there are no module on this course
1476
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1477
-
1478
-            return  Sensei()->course->course_lessons( $course_id );
1479
-
1480
-        }
1481
-
1482
-        $terms = array();
1483
-        foreach( $course_modules as $module ){
1484
-
1485
-            array_push( $terms ,  $module->term_id );
1486
-
1487
-        }
1488
-
1489
-        $args = array(
1490
-            'post_type' => 'lesson',
1491
-            'post_status' => 'publish',
1492
-            'posts_per_page' => -1,
1493
-            'meta_query' => array(
1494
-                array(
1495
-                    'key' => '_lesson_course',
1496
-                    'value' => intval( $course_id ),
1497
-                    'compare' => '='
1498
-                )
1499
-            ),
1500
-            'tax_query' => array(
1501
-                array(
1502
-                    'taxonomy' => 'module',
1503
-                    'field' => 'id',
1504
-                    'terms' =>  $terms,
1505
-                    'operator' => 'NOT IN'
1506
-                )
1507
-            ),
1508
-            'orderby' => 'menu_order',
1509
-            'order' => 'ASC',
1510
-            'suppress_filters' => 0
1511
-        );
1512
-
1513
-        $wp_lessons_query = new WP_Query( $args );
1514
-
1515
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1516
-            $non_module_lessons = $wp_lessons_query->get_posts();
1517
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1518
-        }
1519
-
1520
-        return $non_module_lessons;
1521
-    } // end get_none_module_lessons
1522
-
1523
-    /**
1524
-     * Register the modules taxonomy
1525
-     *
1526
-     * @since 1.8.0
1527
-     */
1528
-    public function setup_modules_taxonomy(){
1529
-
1530
-        $labels = array(
1531
-            'name' => __('Modules', 'woothemes-sensei'),
1532
-            'singular_name' => __('Module', 'woothemes-sensei'),
1533
-            'search_items' => __('Search Modules', 'woothemes-sensei'),
1534
-            'all_items' => __('All Modules', 'woothemes-sensei'),
1535
-            'parent_item' => __('Parent Module', 'woothemes-sensei'),
1536
-            'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1537
-            'edit_item' => __('Edit Module', 'woothemes-sensei'),
1538
-            'update_item' => __('Update Module', 'woothemes-sensei'),
1539
-            'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1540
-            'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1541
-            'menu_name' => __('Modules', 'woothemes-sensei'),
1542
-        );
1543
-
1544
-        /**
1545
-         * Filter to alter the Sensei Modules rewrite slug
1546
-         *
1547
-         * @since 1.8.0
1548
-         * @param string default 'modules'
1549
-         */
1550
-        $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1551
-
1552
-        $args = array(
1553
-            'public' => true,
1554
-            'hierarchical' => true,
1555
-            'show_admin_column' => true,
1556
-            'capabilities' => array(
1557
-                'manage_terms' => 'manage_categories',
1558
-                'edit_terms'   => 'edit_courses',
1559
-                'delete_terms' => 'manage_categories',
1560
-                'assign_terms' => 'edit_courses'
1561
-            ),
1562
-            'show_in_nav_menus' => false,
1563
-            'show_in_quick_edit' => false,
1564
-            'show_ui' => true,
1565
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1566
-            'labels' => $labels
1567
-        );
1568
-
1569
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1570
-
1571
-    }// end setup_modules_taxonomy
1572
-
1573
-    /**
1574
-     * When the wants to edit the lesson modules redirect them to the course modules.
1575
-     *
1576
-     * This function is hooked into the admin_menu
1577
-     *
1578
-     * @since 1.8.0
1579
-     * @return void
1580
-     */
1581
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1582
-
1583
-        global $typenow , $taxnow;
1584
-
1585
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1586
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1587
-        }
1588
-
1589
-    }// end redirect to course taxonomy
1590
-
1591
-    /**
1592
-     * Completely remove the module menu item under lessons.
1593
-     *
1594
-     * This function is hooked into the admin_menu
1595
-     *
1596
-     * @since 1.8.0
1597
-     * @return void
1598
-     */
1599
-    public function remove_lessons_menu_model_taxonomy(){
1600
-        global $submenu;
1601
-
1602
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1603
-            return; // exit
1604
-        }
1605
-
1606
-        $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1607
-        foreach( $lesson_main_menu as $index => $sub_item ){
1608
-
1609
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1610
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1611
-            }
1612
-        }
1613
-
1614
-    }// end remove lesson module tax
1615
-
1616
-    /**
1617
-     * Completely remove the second modules under courses
1618
-     *
1619
-     * This function is hooked into the admin_menu
1620
-     *
1621
-     * @since 1.8.0
1622
-     * @return void
1623
-     */
1624
-    public function remove_courses_menu_model_taxonomy(){
1625
-        global $submenu;
1626
-
1627
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1628
-            return; // exit
1629
-        }
1630
-
1631
-        $course_main_menu = $submenu['edit.php?post_type=course'];
1632
-        foreach( $course_main_menu as $index => $sub_item ){
1633
-
1634
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1635
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1636
-            }
1637
-        }
1638
-
1639
-    }// end remove courses module tax
1640
-
1641
-    /**
1642
-     * Determine the author of a module term term by looking at
1643
-     * the prefixed author id. This function will query the full term object.
1644
-     * Will return the admin user author could not be determined.
1645
-     *
1646
-     * @since 1.8.0
1647
-     *
1648
-     * @param string $term_name
1649
-     * @return array $owners { type WP_User }. Empty array if none if found.
1650
-     */
1651
-    public static function get_term_authors( $term_name ){
1652
-
1653
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1654
-
1655
-        $owners = array();
1656
-        if( empty( $terms ) ){
1657
-
1658
-            return $owners;
1395
+	/**
1396
+	 * Returns all lessons for the given module ID
1397
+	 *
1398
+	 * @since 1.8.0
1399
+	 *
1400
+	 * @param $course_id
1401
+	 * @param $term_id
1402
+	 * @return WP_Query $lessons_query
1403
+	 */
1404
+	public function get_lessons_query( $course_id , $term_id ){
1405
+
1406
+		if( empty( $term_id ) || empty( $course_id ) ){
1407
+
1408
+			return array();
1409
+
1410
+		}
1411
+
1412
+		$args = array(
1413
+			'post_type' => 'lesson',
1414
+			'post_status' => 'publish',
1415
+			'posts_per_page' => -1,
1416
+			'meta_query' => array(
1417
+				array(
1418
+					'key' => '_lesson_course',
1419
+					'value' => intval($course_id),
1420
+					'compare' => '='
1421
+				)
1422
+			),
1423
+			'tax_query' => array(
1424
+				array(
1425
+					'taxonomy' => 'module',
1426
+					'field' => 'id',
1427
+					'terms' => intval( $term_id )
1428
+				)
1429
+			),
1430
+			'orderby' => 'menu_order',
1431
+			'order' => 'ASC',
1432
+			'suppress_filters' => 0
1433
+		);
1434
+
1435
+		if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1436
+			$args['meta_key'] = '_order_module_' . intval( $term_id );
1437
+			$args['orderby'] = 'meta_value_num date';
1438
+		}
1439
+
1440
+		$lessons_query = new WP_Query( $args );
1441
+
1442
+		return $lessons_query;
1443
+
1444
+	} // end get lessons
1445
+
1446
+	/**
1447
+	 * Find the lesson in the given course that doesn't belong
1448
+	 * to any of the courses modules
1449
+	 *
1450
+	 *
1451
+	 * @param $course_id
1452
+	 *
1453
+	 * @return array $non_module_lessons
1454
+	 */
1455
+	public function get_none_module_lessons( $course_id ){
1456
+
1457
+		$non_module_lessons = array();
1458
+
1459
+		//exit if there is no course id passed in
1460
+		if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1461
+
1462
+			return $non_module_lessons;
1463
+		}
1464
+
1465
+		//save some time and check if we already have the saved
1466
+		if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1467
+
1468
+			return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1469
+
1470
+		}
1471
+
1472
+		// create terms array which must be excluded from other arrays
1473
+		$course_modules = $this->get_course_modules( $course_id );
1474
+
1475
+		//exit if there are no module on this course
1476
+		if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1477
+
1478
+			return  Sensei()->course->course_lessons( $course_id );
1479
+
1480
+		}
1481
+
1482
+		$terms = array();
1483
+		foreach( $course_modules as $module ){
1484
+
1485
+			array_push( $terms ,  $module->term_id );
1486
+
1487
+		}
1488
+
1489
+		$args = array(
1490
+			'post_type' => 'lesson',
1491
+			'post_status' => 'publish',
1492
+			'posts_per_page' => -1,
1493
+			'meta_query' => array(
1494
+				array(
1495
+					'key' => '_lesson_course',
1496
+					'value' => intval( $course_id ),
1497
+					'compare' => '='
1498
+				)
1499
+			),
1500
+			'tax_query' => array(
1501
+				array(
1502
+					'taxonomy' => 'module',
1503
+					'field' => 'id',
1504
+					'terms' =>  $terms,
1505
+					'operator' => 'NOT IN'
1506
+				)
1507
+			),
1508
+			'orderby' => 'menu_order',
1509
+			'order' => 'ASC',
1510
+			'suppress_filters' => 0
1511
+		);
1512
+
1513
+		$wp_lessons_query = new WP_Query( $args );
1514
+
1515
+		if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1516
+			$non_module_lessons = $wp_lessons_query->get_posts();
1517
+			set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1518
+		}
1519
+
1520
+		return $non_module_lessons;
1521
+	} // end get_none_module_lessons
1522
+
1523
+	/**
1524
+	 * Register the modules taxonomy
1525
+	 *
1526
+	 * @since 1.8.0
1527
+	 */
1528
+	public function setup_modules_taxonomy(){
1529
+
1530
+		$labels = array(
1531
+			'name' => __('Modules', 'woothemes-sensei'),
1532
+			'singular_name' => __('Module', 'woothemes-sensei'),
1533
+			'search_items' => __('Search Modules', 'woothemes-sensei'),
1534
+			'all_items' => __('All Modules', 'woothemes-sensei'),
1535
+			'parent_item' => __('Parent Module', 'woothemes-sensei'),
1536
+			'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'),
1537
+			'edit_item' => __('Edit Module', 'woothemes-sensei'),
1538
+			'update_item' => __('Update Module', 'woothemes-sensei'),
1539
+			'add_new_item' => __('Add New Module', 'woothemes-sensei'),
1540
+			'new_item_name' => __('New Module Name', 'woothemes-sensei'),
1541
+			'menu_name' => __('Modules', 'woothemes-sensei'),
1542
+		);
1543
+
1544
+		/**
1545
+		 * Filter to alter the Sensei Modules rewrite slug
1546
+		 *
1547
+		 * @since 1.8.0
1548
+		 * @param string default 'modules'
1549
+		 */
1550
+		$modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules');
1551
+
1552
+		$args = array(
1553
+			'public' => true,
1554
+			'hierarchical' => true,
1555
+			'show_admin_column' => true,
1556
+			'capabilities' => array(
1557
+				'manage_terms' => 'manage_categories',
1558
+				'edit_terms'   => 'edit_courses',
1559
+				'delete_terms' => 'manage_categories',
1560
+				'assign_terms' => 'edit_courses'
1561
+			),
1562
+			'show_in_nav_menus' => false,
1563
+			'show_in_quick_edit' => false,
1564
+			'show_ui' => true,
1565
+			'rewrite' => array('slug' => $modules_rewrite_slug ),
1566
+			'labels' => $labels
1567
+		);
1568
+
1569
+		register_taxonomy( 'module' , array('course', 'lesson'), $args);
1570
+
1571
+	}// end setup_modules_taxonomy
1572
+
1573
+	/**
1574
+	 * When the wants to edit the lesson modules redirect them to the course modules.
1575
+	 *
1576
+	 * This function is hooked into the admin_menu
1577
+	 *
1578
+	 * @since 1.8.0
1579
+	 * @return void
1580
+	 */
1581
+	function redirect_to_lesson_module_taxonomy_to_course( ){
1582
+
1583
+		global $typenow , $taxnow;
1584
+
1585
+		if( 'lesson'== $typenow && 'module'==$taxnow ){
1586
+			wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1587
+		}
1588
+
1589
+	}// end redirect to course taxonomy
1590
+
1591
+	/**
1592
+	 * Completely remove the module menu item under lessons.
1593
+	 *
1594
+	 * This function is hooked into the admin_menu
1595
+	 *
1596
+	 * @since 1.8.0
1597
+	 * @return void
1598
+	 */
1599
+	public function remove_lessons_menu_model_taxonomy(){
1600
+		global $submenu;
1601
+
1602
+		if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1603
+			return; // exit
1604
+		}
1605
+
1606
+		$lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1607
+		foreach( $lesson_main_menu as $index => $sub_item ){
1608
+
1609
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1610
+				unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1611
+			}
1612
+		}
1613
+
1614
+	}// end remove lesson module tax
1615
+
1616
+	/**
1617
+	 * Completely remove the second modules under courses
1618
+	 *
1619
+	 * This function is hooked into the admin_menu
1620
+	 *
1621
+	 * @since 1.8.0
1622
+	 * @return void
1623
+	 */
1624
+	public function remove_courses_menu_model_taxonomy(){
1625
+		global $submenu;
1626
+
1627
+		if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1628
+			return; // exit
1629
+		}
1630
+
1631
+		$course_main_menu = $submenu['edit.php?post_type=course'];
1632
+		foreach( $course_main_menu as $index => $sub_item ){
1633
+
1634
+			if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1635
+				unset( $submenu['edit.php?post_type=course'][ $index ]);
1636
+			}
1637
+		}
1638
+
1639
+	}// end remove courses module tax
1640
+
1641
+	/**
1642
+	 * Determine the author of a module term term by looking at
1643
+	 * the prefixed author id. This function will query the full term object.
1644
+	 * Will return the admin user author could not be determined.
1645
+	 *
1646
+	 * @since 1.8.0
1647
+	 *
1648
+	 * @param string $term_name
1649
+	 * @return array $owners { type WP_User }. Empty array if none if found.
1650
+	 */
1651
+	public static function get_term_authors( $term_name ){
1652
+
1653
+		$terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1654
+
1655
+		$owners = array();
1656
+		if( empty( $terms ) ){
1657
+
1658
+			return $owners;
1659 1659
 
1660
-        }
1660
+		}
1661 1661
 
1662
-        // setup the admin user
1662
+		// setup the admin user
1663 1663
 
1664 1664
 
1665
-        //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1666
-        foreach( $terms as $term){
1667
-            if( $term->name == $term_name ){
1665
+		//if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1666
+		foreach( $terms as $term){
1667
+			if( $term->name == $term_name ){
1668 1668
 
1669
-                // look for the author in the slug
1670
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1669
+				// look for the author in the slug
1670
+				$owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1671 1671
 
1672
-            }// end if term name
1672
+			}// end if term name
1673 1673
 
1674
-        } // end for each
1674
+		} // end for each
1675 1675
 
1676
-        return $owners;
1676
+		return $owners;
1677 1677
 
1678
-    }// end get_term_author
1678
+	}// end get_term_author
1679 1679
 
1680
-    /**
1681
-     * Looks at a term slug and figures out
1682
-     * which author created the slug. The author was
1683
-     * appended when the user saved the module term in the course edit
1684
-     * screen.
1685
-     *
1686
-     * @since 1.8.0
1687
-     *
1688
-     * @param $slug
1689
-     * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1690
-     */
1691
-    public static function get_term_author( $slug='' ){
1680
+	/**
1681
+	 * Looks at a term slug and figures out
1682
+	 * which author created the slug. The author was
1683
+	 * appended when the user saved the module term in the course edit
1684
+	 * screen.
1685
+	 *
1686
+	 * @since 1.8.0
1687
+	 *
1688
+	 * @param $slug
1689
+	 * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1690
+	 */
1691
+	public static function get_term_author( $slug='' ){
1692 1692
 
1693
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1693
+		$term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1694 1694
 
1695
-        if( empty( $slug ) ){
1695
+		if( empty( $slug ) ){
1696 1696
 
1697
-            return $term_owner;
1697
+			return $term_owner;
1698 1698
 
1699
-        }
1699
+		}
1700 1700
 
1701
-        // look for the author in the slug
1702
-        $slug_parts = explode( '-', $slug );
1701
+		// look for the author in the slug
1702
+		$slug_parts = explode( '-', $slug );
1703 1703
 
1704
-        if( count( $slug_parts ) > 1 ){
1704
+		if( count( $slug_parts ) > 1 ){
1705 1705
 
1706
-            // get the user data
1707
-            $possible_user_id = $slug_parts[0];
1708
-            $author = get_userdata( $possible_user_id );
1706
+			// get the user data
1707
+			$possible_user_id = $slug_parts[0];
1708
+			$author = get_userdata( $possible_user_id );
1709 1709
 
1710
-            // if the user doesnt exist for the first part of the slug
1711
-            // then this slug was also created by admin
1712
-            if( is_a( $author, 'WP_User' ) ){
1710
+			// if the user doesnt exist for the first part of the slug
1711
+			// then this slug was also created by admin
1712
+			if( is_a( $author, 'WP_User' ) ){
1713 1713
 
1714
-                $term_owner =  $author;
1714
+				$term_owner =  $author;
1715 1715
 
1716
-            }
1717
-        }
1716
+			}
1717
+		}
1718 1718
 
1719
-        return $term_owner;
1720
-    }
1719
+		return $term_owner;
1720
+	}
1721 1721
 
1722
-    /**
1723
-     * Display the Sensei modules taxonomy terms metabox
1724
-     *
1725
-     * @since 1.8.0
1726
-     *
1727
-     * @hooked into add_meta_box
1728
-     *
1729
-     * @param WP_Post $post Post object.
1730
-     */
1731
-    public function course_module_metabox( $post ) {
1722
+	/**
1723
+	 * Display the Sensei modules taxonomy terms metabox
1724
+	 *
1725
+	 * @since 1.8.0
1726
+	 *
1727
+	 * @hooked into add_meta_box
1728
+	 *
1729
+	 * @param WP_Post $post Post object.
1730
+	 */
1731
+	public function course_module_metabox( $post ) {
1732 1732
 
1733
-        $tax_name = 'module';
1734
-        $taxonomy = get_taxonomy( 'module' );
1733
+		$tax_name = 'module';
1734
+		$taxonomy = get_taxonomy( 'module' );
1735 1735
 
1736
-        ?>
1736
+		?>
1737 1737
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1738 1738
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1739 1739
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
@@ -1748,9 +1748,9 @@  discard block
 block discarded – undo
1748 1748
 
1749 1749
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1750 1750
                 <?php
1751
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1752
-                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.
1753
-                ?>
1751
+				$name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1752
+				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.
1753
+				?>
1754 1754
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1755 1755
                     <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1756 1756
                 </ul>
@@ -1760,9 +1760,9 @@  discard block
 block discarded – undo
1760 1760
                     <h4>
1761 1761
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1762 1762
                             <?php
1763
-                            /* translators: %s: add new taxonomy label */
1764
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1765
-                            ?>
1763
+							/* translators: %s: add new taxonomy label */
1764
+							printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1765
+							?>
1766 1766
                         </a>
1767 1767
                     </h4>
1768 1768
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
@@ -1777,331 +1777,331 @@  discard block
 block discarded – undo
1777 1777
         </div>
1778 1778
     <?php
1779 1779
 
1780
-    } // end course_module_metabox
1780
+	} // end course_module_metabox
1781 1781
 
1782 1782
 
1783
-    /**
1784
-     * Submits a new module term prefixed with the
1785
-     * the current author id.
1786
-     *
1787
-     * @since 1.8.0
1788
-     */
1789
-    public static function add_new_module_term( ) {
1783
+	/**
1784
+	 * Submits a new module term prefixed with the
1785
+	 * the current author id.
1786
+	 *
1787
+	 * @since 1.8.0
1788
+	 */
1789
+	public static function add_new_module_term( ) {
1790 1790
 
1791 1791
 
1792
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1793
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1794
-        }
1792
+		if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1793
+			wp_send_json_error( array('error'=> 'wrong security nonce') );
1794
+		}
1795 1795
 
1796
-        // get the term an create the new term storing infomration
1797
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1796
+		// get the term an create the new term storing infomration
1797
+		$term_name = sanitize_text_field( $_POST['newTerm'] );
1798 1798
 
1799
-        if( current_user_can('manage_options' ) ) {
1799
+		if( current_user_can('manage_options' ) ) {
1800 1800
 
1801
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1801
+			$term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1802 1802
 
1803
-        } else {
1803
+		} else {
1804 1804
 
1805
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1805
+			$term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1806 1806
 
1807
-        }
1807
+		}
1808 1808
 
1809
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1809
+		$course_id = sanitize_text_field( $_POST['course_id'] );
1810 1810
 
1811
-        // save the term
1812
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1811
+		// save the term
1812
+		$slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1813 1813
 
1814
-        // send error for all errors except term exits
1815
-        if( is_wp_error( $slug ) ){
1814
+		// send error for all errors except term exits
1815
+		if( is_wp_error( $slug ) ){
1816 1816
 
1817
-            // prepare for possible term name and id to be passed down if term exists
1818
-            $term_data = array();
1817
+			// prepare for possible term name and id to be passed down if term exists
1818
+			$term_data = array();
1819 1819
 
1820
-            // if term exists also send back the term name and id
1821
-            if( isset( $slug->errors['term_exists'] ) ){
1820
+			// if term exists also send back the term name and id
1821
+			if( isset( $slug->errors['term_exists'] ) ){
1822 1822
 
1823
-                $term = get_term_by( 'slug', $term_slug, 'module');
1824
-                $term_data['name'] = $term_name;
1825
-                $term_data['id'] = $term->term_id;
1823
+				$term = get_term_by( 'slug', $term_slug, 'module');
1824
+				$term_data['name'] = $term_name;
1825
+				$term_data['id'] = $term->term_id;
1826 1826
 
1827
-                // set the object terms
1828
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1829
-            }
1827
+				// set the object terms
1828
+				wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1829
+			}
1830 1830
 
1831
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1831
+			wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1832 1832
 
1833
-        }
1833
+		}
1834 1834
 
1835
-        //make sure the new term is checked for this course
1835
+		//make sure the new term is checked for this course
1836 1836
 
1837
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1837
+		wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1838 1838
 
1839
-        // Handle request then generate response using WP_Ajax_Response
1840
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1839
+		// Handle request then generate response using WP_Ajax_Response
1840
+		wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1841 1841
 
1842
-    }
1842
+	}
1843 1843
 
1844
-    /**
1845
-     * Limit the course module metabox
1846
-     * term list to only those on courses belonging to current teacher.
1847
-     *
1848
-     * Hooked into 'get_terms'
1849
-     *
1850
-     * @since 1.8.0
1851
-     */
1852
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1844
+	/**
1845
+	 * Limit the course module metabox
1846
+	 * term list to only those on courses belonging to current teacher.
1847
+	 *
1848
+	 * Hooked into 'get_terms'
1849
+	 *
1850
+	 * @since 1.8.0
1851
+	 */
1852
+	public function filter_module_terms( $terms, $taxonomies, $args ){
1853 1853
 
1854
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1855
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1856
-            return $terms;
1857
-        }
1854
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1855
+		if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1856
+			return $terms;
1857
+		}
1858 1858
 
1859
-        // avoid infinite call loop
1860
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1859
+		// avoid infinite call loop
1860
+		remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1861 1861
 
1862
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1863
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1864
-            // change only scrub the terms ids form the array keys
1865
-            $terms = array_keys( $terms );
1866
-        }
1862
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1863
+		if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1864
+			// change only scrub the terms ids form the array keys
1865
+			$terms = array_keys( $terms );
1866
+		}
1867 1867
 
1868
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1868
+		$teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1869 1869
 
1870
-        // add filter again as removed above
1871
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1870
+		// add filter again as removed above
1871
+		add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1872 1872
 
1873
-        return $teachers_terms;
1874
-    }// end filter_module_terms
1873
+		return $teachers_terms;
1874
+	}// end filter_module_terms
1875 1875
 
1876
-    /**
1877
-     * For the selected items on a course module only return those
1878
-     * for the current user. This does not apply to admin and super admin users.
1879
-     *
1880
-     * hooked into get_object_terms
1881
-     *
1882
-     * @since 1.8.0
1883
-     */
1884
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1876
+	/**
1877
+	 * For the selected items on a course module only return those
1878
+	 * for the current user. This does not apply to admin and super admin users.
1879
+	 *
1880
+	 * hooked into get_object_terms
1881
+	 *
1882
+	 * @since 1.8.0
1883
+	 */
1884
+	public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1885 1885
 
1886
-        //dont limit for admins and other taxonomies. This should also only apply to admin
1887
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1888
-            // only apply this to module only taxonomy queries so 1 taxonomy only:
1889
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1890
-            return $terms;
1891
-        }
1886
+		//dont limit for admins and other taxonomies. This should also only apply to admin
1887
+		if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1888
+			// only apply this to module only taxonomy queries so 1 taxonomy only:
1889
+			||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1890
+			return $terms;
1891
+		}
1892 1892
 
1893
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1893
+		$term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1894 1894
 
1895
-        // if term objects were passed in send back objects
1896
-        // if term id were passed in send that back
1897
-        if( is_object( $terms[0] ) ){
1898
-            return $term_objects;
1899
-        }
1895
+		// if term objects were passed in send back objects
1896
+		// if term id were passed in send that back
1897
+		if( is_object( $terms[0] ) ){
1898
+			return $term_objects;
1899
+		}
1900 1900
 
1901
-        $terms = array();
1902
-        foreach( $term_objects as $term_object ){
1903
-            $terms[] = $term_object->term_id;
1904
-        }
1901
+		$terms = array();
1902
+		foreach( $term_objects as $term_object ){
1903
+			$terms[] = $term_object->term_id;
1904
+		}
1905 1905
 
1906
-        return $terms;
1906
+		return $terms;
1907 1907
 
1908 1908
 
1909
-    }// end filter_course_selected_terms
1909
+	}// end filter_course_selected_terms
1910 1910
 
1911
-    /**
1912
-     * Filter the given terms and only return the
1913
-     * terms that belong to the given user id.
1914
-     *
1915
-     * @since 1.8.0
1916
-     * @param $terms
1917
-     * @param $user_id
1918
-     * @return array
1919
-     */
1920
-    public function filter_terms_by_owner( $terms, $user_id ){
1911
+	/**
1912
+	 * Filter the given terms and only return the
1913
+	 * terms that belong to the given user id.
1914
+	 *
1915
+	 * @since 1.8.0
1916
+	 * @param $terms
1917
+	 * @param $user_id
1918
+	 * @return array
1919
+	 */
1920
+	public function filter_terms_by_owner( $terms, $user_id ){
1921 1921
 
1922
-        $users_terms = array();
1922
+		$users_terms = array();
1923 1923
 
1924
-        foreach( $terms as $index => $term ){
1924
+		foreach( $terms as $index => $term ){
1925 1925
 
1926
-            if( is_numeric( $term ) ){
1927
-                // the term id was given, get the term object
1928
-                $term = get_term( $term, 'module' );
1929
-            }
1926
+			if( is_numeric( $term ) ){
1927
+				// the term id was given, get the term object
1928
+				$term = get_term( $term, 'module' );
1929
+			}
1930 1930
 
1931
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1931
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1932 1932
 
1933
-            if ( $user_id == $author->ID ) {
1934
-                // add the term to the teachers terms
1935
-                $users_terms[] = $term;
1936
-            }
1933
+			if ( $user_id == $author->ID ) {
1934
+				// add the term to the teachers terms
1935
+				$users_terms[] = $term;
1936
+			}
1937 1937
 
1938
-        }
1938
+		}
1939 1939
 
1940
-        return $users_terms;
1940
+		return $users_terms;
1941 1941
 
1942
-    } // end filter terms by owner
1942
+	} // end filter terms by owner
1943 1943
 
1944
-    /**
1945
-     * Add the teacher name next to modules. Only works in Admin for Admin users.
1946
-     * This will not add name to terms belonging to admin user.
1947
-     *
1948
-     * Hooked into 'get_terms'
1949
-     *
1950
-     * @since 1.8.0
1951
-     */
1952
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1953
-    {
1944
+	/**
1945
+	 * Add the teacher name next to modules. Only works in Admin for Admin users.
1946
+	 * This will not add name to terms belonging to admin user.
1947
+	 *
1948
+	 * Hooked into 'get_terms'
1949
+	 *
1950
+	 * @since 1.8.0
1951
+	 */
1952
+	public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1953
+	{
1954 1954
 
1955
-        // only for admin users ont he module taxonomy
1956
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1957
-            return $terms;
1958
-        }
1955
+		// only for admin users ont he module taxonomy
1956
+		if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1957
+			return $terms;
1958
+		}
1959 1959
 
1960
-        // in certain cases the array is passed in as reference to the parent term_id => parent_id
1961
-        // simply return this as wp doesn't need an array of stdObject Term
1962
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1960
+		// in certain cases the array is passed in as reference to the parent term_id => parent_id
1961
+		// simply return this as wp doesn't need an array of stdObject Term
1962
+		if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1963 1963
 
1964
-            return $terms;
1964
+			return $terms;
1965 1965
 
1966
-        }
1966
+		}
1967 1967
 
1968
-        // loop through and update all terms adding the author name
1969
-        foreach( $terms as $index => $term ){
1968
+		// loop through and update all terms adding the author name
1969
+		foreach( $terms as $index => $term ){
1970 1970
 
1971
-            if( is_numeric( $term ) ){
1972
-                // the term id was given, get the term object
1973
-                $term = get_term( $term, 'module' );
1974
-            }
1971
+			if( is_numeric( $term ) ){
1972
+				// the term id was given, get the term object
1973
+				$term = get_term( $term, 'module' );
1974
+			}
1975 1975
 
1976
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1976
+			$author = Sensei_Core_Modules::get_term_author( $term->slug );
1977 1977
 
1978
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1979
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1980
-            }
1978
+			if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1979
+				$term->name = $term->name . ' (' . $author->display_name . ') ';
1980
+			}
1981 1981
 
1982
-            // add the term to the teachers terms
1983
-            $users_terms[] = $term;
1982
+			// add the term to the teachers terms
1983
+			$users_terms[] = $term;
1984 1984
 
1985
-        }
1985
+		}
1986 1986
 
1987
-        return $users_terms;
1988
-    }
1987
+		return $users_terms;
1988
+	}
1989 1989
 
1990
-    /**
1991
-     * Remove modules metabox that come by default
1992
-     * with the modules taxonomy. We are removing this as
1993
-     * we have created our own custom meta box.
1994
-     */
1995
-    public static function remove_default_modules_box() {
1990
+	/**
1991
+	 * Remove modules metabox that come by default
1992
+	 * with the modules taxonomy. We are removing this as
1993
+	 * we have created our own custom meta box.
1994
+	 */
1995
+	public static function remove_default_modules_box() {
1996 1996
 
1997
-        remove_meta_box('modulediv', 'course', 'side');
1997
+		remove_meta_box('modulediv', 'course', 'side');
1998 1998
 
1999
-    }
1999
+	}
2000 2000
 
2001
-    /**
2002
-     * When a course is save make sure to reset the transient set
2003
-     * for it when determining the none module lessons.
2004
-     *
2005
-     * @sine 1.9.0
2006
-     * @param $post_id
2007
-     */
2008
-    public static function reset_none_modules_transient ( $post_id ){
2001
+	/**
2002
+	 * When a course is save make sure to reset the transient set
2003
+	 * for it when determining the none module lessons.
2004
+	 *
2005
+	 * @sine 1.9.0
2006
+	 * @param $post_id
2007
+	 */
2008
+	public static function reset_none_modules_transient ( $post_id ){
2009 2009
 
2010
-        // this should only apply to course and lesson post types
2011
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2010
+		// this should only apply to course and lesson post types
2011
+		if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2012 2012
 
2013
-            $course_id = '';
2013
+			$course_id = '';
2014 2014
 
2015
-            if( 'lesson' == get_post_type( $post_id ) ){
2015
+			if( 'lesson' == get_post_type( $post_id ) ){
2016 2016
 
2017
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2017
+				$course_id = Sensei()->lesson->get_course_id( $post_id );
2018 2018
 
2019
-            }
2019
+			}
2020 2020
 
2021 2021
 
2022
-            if( !empty( $course_id ) ){
2022
+			if( !empty( $course_id ) ){
2023 2023
 
2024
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2024
+				delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2025 2025
 
2026
-            }
2026
+			}
2027 2027
 
2028
-        } // end if is a course or a lesson
2028
+		} // end if is a course or a lesson
2029 2029
 
2030
-    } // end reset_none_modules_transient
2030
+	} // end reset_none_modules_transient
2031 2031
 
2032
-    /**
2033
-     * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2034
-     *
2035
-     * @since 1.9.0
2036
-     * @deprecated since 1.9.0
2037
-     *
2038
-     */
2039
-    public static function deprecate_sensei_single_course_modules_content(){
2032
+	/**
2033
+	 * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire
2034
+	 *
2035
+	 * @since 1.9.0
2036
+	 * @deprecated since 1.9.0
2037
+	 *
2038
+	 */
2039
+	public static function deprecate_sensei_single_course_modules_content(){
2040 2040
 
2041
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2041
+		sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2042 2042
 
2043
-    }
2043
+	}
2044 2044
 
2045
-    /**
2046
-     * Setup the single course module loop.
2047
-     *
2048
-     * Setup the global $sensei_modules_loop
2049
-     *
2050
-     * @since 1.9.0
2051
-     */
2052
-    public static function setup_single_course_module_loop(){
2045
+	/**
2046
+	 * Setup the single course module loop.
2047
+	 *
2048
+	 * Setup the global $sensei_modules_loop
2049
+	 *
2050
+	 * @since 1.9.0
2051
+	 */
2052
+	public static function setup_single_course_module_loop(){
2053 2053
 
2054
-        global $sensei_modules_loop, $post;
2055
-        $course_id = $post->ID;
2054
+		global $sensei_modules_loop, $post;
2055
+		$course_id = $post->ID;
2056 2056
 
2057
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2057
+		$modules = Sensei()->modules->get_course_modules( $course_id );
2058 2058
 
2059
-        //initial setup
2060
-        $sensei_modules_loop['total'] = 0;
2061
-        $sensei_modules_loop['modules'] = array();
2062
-        $sensei_modules_loop['current'] = -1;
2059
+		//initial setup
2060
+		$sensei_modules_loop['total'] = 0;
2061
+		$sensei_modules_loop['modules'] = array();
2062
+		$sensei_modules_loop['current'] = -1;
2063 2063
 
2064
-        // exit if this course doesn't have modules
2065
-        if( !$modules || empty( $modules )  ){
2066
-            return;
2067
-        }
2064
+		// exit if this course doesn't have modules
2065
+		if( !$modules || empty( $modules )  ){
2066
+			return;
2067
+		}
2068 2068
 
2069 2069
 
2070
-        $lessons_in_all_modules = array();
2071
-        foreach( $modules as $term ){
2070
+		$lessons_in_all_modules = array();
2071
+		foreach( $modules as $term ){
2072 2072
 
2073
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2074
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2073
+			$lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2074
+			$lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2075 2075
 
2076
-        }
2076
+		}
2077 2077
 
2078 2078
 
2079
-        //setup all of the modules loop variables
2080
-        $sensei_modules_loop['total'] = count( $modules );
2081
-        $sensei_modules_loop['modules'] = $modules;
2082
-        $sensei_modules_loop['current'] = -1;
2083
-        $sensei_modules_loop['course_id'] = $course_id;
2079
+		//setup all of the modules loop variables
2080
+		$sensei_modules_loop['total'] = count( $modules );
2081
+		$sensei_modules_loop['modules'] = $modules;
2082
+		$sensei_modules_loop['current'] = -1;
2083
+		$sensei_modules_loop['course_id'] = $course_id;
2084 2084
 
2085
-    }// end setup_single_course_module_loop
2085
+	}// end setup_single_course_module_loop
2086 2086
 
2087
-    /**
2088
-     * Tear down the course module loop.
2089
-     *
2090
-     * @since 1.9.0
2091
-     *
2092
-     */
2093
-    public static function teardown_single_course_module_loop(){
2087
+	/**
2088
+	 * Tear down the course module loop.
2089
+	 *
2090
+	 * @since 1.9.0
2091
+	 *
2092
+	 */
2093
+	public static function teardown_single_course_module_loop(){
2094 2094
 
2095
-        global $sensei_modules_loop, $wp_query, $post;
2095
+		global $sensei_modules_loop, $wp_query, $post;
2096 2096
 
2097
-        //reset all of the modules loop variables
2098
-        $sensei_modules_loop['total'] = 0;
2099
-        $sensei_modules_loop['modules'] = array();
2100
-        $sensei_modules_loop['current'] = -1;
2097
+		//reset all of the modules loop variables
2098
+		$sensei_modules_loop['total'] = 0;
2099
+		$sensei_modules_loop['modules'] = array();
2100
+		$sensei_modules_loop['current'] = -1;
2101 2101
 
2102
-        // set the current course to be the global post again
2103
-        wp_reset_query();
2104
-        $post = $wp_query->post;
2105
-    }// end teardown_single_course_module_loop
2102
+		// set the current course to be the global post again
2103
+		wp_reset_query();
2104
+		$post = $wp_query->post;
2105
+	}// end teardown_single_course_module_loop
2106 2106
 
2107 2107
 } // end modules class
Please login to merge, or discard this patch.
Spacing   +262 added lines, -262 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,9 +1169,9 @@  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 )
1173
-            || is_wp_error( $modules )
1174
-            || isset( $modules['errors'] ) ){
1172
+        if (empty($modules)
1173
+            || is_wp_error($modules)
1174
+            || isset($modules['errors'])) {
1175 1175
 
1176 1176
             return false;
1177 1177
 
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
 
1180 1180
        // get the last item in the array there should be only be 1 really.
1181 1181
        // this method works for all php versions.
1182
-       foreach( $modules as $module ){
1182
+       foreach ($modules as $module) {
1183 1183
            break;
1184 1184
        }
1185 1185
 
@@ -1192,7 +1192,7 @@  discard block
 block discarded – undo
1192 1192
         if (isset($course_id) && 0 < $course_id) {
1193 1193
 
1194 1194
             // the course should contain the same module taxonomy term for this to be valid
1195
-            if( ! has_term( $module, $this->taxonomy, $course_id)){
1195
+            if ( ! has_term($module, $this->taxonomy, $course_id)) {
1196 1196
                 return false;
1197 1197
             }
1198 1198
 
@@ -1264,8 +1264,8 @@  discard block
 block discarded – undo
1264 1264
      */
1265 1265
     public function enqueue_styles() {
1266 1266
 
1267
-        wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version );
1268
-        wp_enqueue_style($this->taxonomy . '-frontend');
1267
+        wp_register_style($this->taxonomy.'-frontend', esc_url($this->assets_url).'css/modules-frontend.css', Sensei()->version);
1268
+        wp_enqueue_style($this->taxonomy.'-frontend');
1269 1269
 
1270 1270
     }
1271 1271
 
@@ -1276,37 +1276,37 @@  discard block
 block discarded – undo
1276 1276
      *
1277 1277
      * @return void
1278 1278
      */
1279
-    public function admin_enqueue_scripts( $hook ) {
1279
+    public function admin_enqueue_scripts($hook) {
1280 1280
 
1281 1281
         /**
1282 1282
          * Filter the page hooks where modules admin script can be loaded on.
1283 1283
          *
1284 1284
          * @param array $white_listed_pages
1285 1285
          */
1286
-        $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array(
1286
+        $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array(
1287 1287
             'edit-tags.php',
1288 1288
             'course_page_module-order',
1289 1289
             'post-new.php',
1290 1290
             'post.php'
1291
-        ) );
1291
+        ));
1292 1292
 
1293
-        if ( ! in_array( $hook, $script_on_pages_white_list ) ) {
1293
+        if ( ! in_array($hook, $script_on_pages_white_list)) {
1294 1294
             return;
1295 1295
         }
1296 1296
 
1297
-        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1297
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
1298 1298
 
1299
-        wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true);
1300
-        wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true );
1301
-        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', 'sensei-core-select2' ), Sensei()->version, true );
1299
+        wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true);
1300
+        wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true);
1301
+        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', 'sensei-core-select2'), Sensei()->version, true);
1302 1302
 
1303 1303
         // localized module data
1304 1304
         $localize_modulesAdmin = array(
1305
-            'search_courses_nonce' => wp_create_nonce( 'search-courses' ),
1306
-            'selectPlaceholder'    => __( 'Search for courses', 'woothemes-sensei' )
1305
+            'search_courses_nonce' => wp_create_nonce('search-courses'),
1306
+            'selectPlaceholder'    => __('Search for courses', 'woothemes-sensei')
1307 1307
         );
1308 1308
 
1309
-        wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin );
1309
+        wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin);
1310 1310
     }
1311 1311
 
1312 1312
     /**
@@ -1318,8 +1318,8 @@  discard block
 block discarded – undo
1318 1318
      */
1319 1319
     public function admin_enqueue_styles() {
1320 1320
 
1321
-        wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version );
1322
-        wp_enqueue_style($this->taxonomy . '-sortable');
1321
+        wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version);
1322
+        wp_enqueue_style($this->taxonomy.'-sortable');
1323 1323
 
1324 1324
     }
1325 1325
 
@@ -1333,9 +1333,9 @@  discard block
 block discarded – undo
1333 1333
      */
1334 1334
     public function course_modules_title( ) {
1335 1335
 
1336
-       if( sensei_module_has_lessons() ){
1336
+       if (sensei_module_has_lessons()) {
1337 1337
 
1338
-            echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>';
1338
+            echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>';
1339 1339
 
1340 1340
         }
1341 1341
 
@@ -1348,22 +1348,22 @@  discard block
 block discarded – undo
1348 1348
      * @since 1.8.0
1349 1349
      * @return void
1350 1350
      */
1351
-    public function load_course_module_content_template(){
1351
+    public function load_course_module_content_template() {
1352 1352
 
1353
-	    if ( ! is_singular( 'course' )  ) {
1353
+	    if ( ! is_singular('course')) {
1354 1354
 		    return;
1355 1355
 	    }
1356 1356
 
1357 1357
         // load backwards compatible template name if it exists in the users theme
1358
-        $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' );
1359
-        if( $located_template ){
1358
+        $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php');
1359
+        if ($located_template) {
1360 1360
 
1361
-            Sensei_Templates::get_template( 'single-course/course-modules.php' );
1361
+            Sensei_Templates::get_template('single-course/course-modules.php');
1362 1362
             return;
1363 1363
 
1364 1364
         }
1365 1365
 
1366
-        Sensei_Templates::get_template( 'single-course/modules.php' );
1366
+        Sensei_Templates::get_template('single-course/modules.php');
1367 1367
 
1368 1368
     } // end course_module_content
1369 1369
 
@@ -1376,15 +1376,15 @@  discard block
 block discarded – undo
1376 1376
      * @param $term_id
1377 1377
      * @return array $lessons
1378 1378
      */
1379
-    public function get_lessons( $course_id , $term_id ){
1379
+    public function get_lessons($course_id, $term_id) {
1380 1380
 
1381
-        $lesson_query = $this->get_lessons_query( $course_id, $term_id );
1381
+        $lesson_query = $this->get_lessons_query($course_id, $term_id);
1382 1382
 
1383
-        if( isset( $lesson_query->posts ) ){
1383
+        if (isset($lesson_query->posts)) {
1384 1384
 
1385 1385
             return $lesson_query->posts;
1386 1386
 
1387
-        }else{
1387
+        } else {
1388 1388
 
1389 1389
             return array();
1390 1390
 
@@ -1401,9 +1401,9 @@  discard block
 block discarded – undo
1401 1401
      * @param $term_id
1402 1402
      * @return WP_Query $lessons_query
1403 1403
      */
1404
-    public function get_lessons_query( $course_id , $term_id ){
1404
+    public function get_lessons_query($course_id, $term_id) {
1405 1405
 
1406
-        if( empty( $term_id ) || empty( $course_id ) ){
1406
+        if (empty($term_id) || empty($course_id)) {
1407 1407
 
1408 1408
             return array();
1409 1409
 
@@ -1424,7 +1424,7 @@  discard block
 block discarded – undo
1424 1424
                 array(
1425 1425
                     'taxonomy' => 'module',
1426 1426
                     'field' => 'id',
1427
-                    'terms' => intval( $term_id )
1427
+                    'terms' => intval($term_id)
1428 1428
                 )
1429 1429
             ),
1430 1430
             'orderby' => 'menu_order',
@@ -1432,12 +1432,12 @@  discard block
 block discarded – undo
1432 1432
             'suppress_filters' => 0
1433 1433
         );
1434 1434
 
1435
-        if (version_compare( Sensei()->version, '1.6.0', '>=')) {
1436
-            $args['meta_key'] = '_order_module_' . intval( $term_id );
1435
+        if (version_compare(Sensei()->version, '1.6.0', '>=')) {
1436
+            $args['meta_key'] = '_order_module_'.intval($term_id);
1437 1437
             $args['orderby'] = 'meta_value_num date';
1438 1438
         }
1439 1439
 
1440
-        $lessons_query = new WP_Query( $args );
1440
+        $lessons_query = new WP_Query($args);
1441 1441
 
1442 1442
         return $lessons_query;
1443 1443
 
@@ -1452,37 +1452,37 @@  discard block
 block discarded – undo
1452 1452
      *
1453 1453
      * @return array $non_module_lessons
1454 1454
      */
1455
-    public function get_none_module_lessons( $course_id ){
1455
+    public function get_none_module_lessons($course_id) {
1456 1456
 
1457 1457
         $non_module_lessons = array();
1458 1458
 
1459 1459
         //exit if there is no course id passed in
1460
-        if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) {
1460
+        if (empty($course_id) || 'course' != get_post_type($course_id)) {
1461 1461
 
1462 1462
             return $non_module_lessons;
1463 1463
         }
1464 1464
 
1465 1465
         //save some time and check if we already have the saved
1466
-        if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){
1466
+        if (get_transient('sensei_'.$course_id.'_none_module_lessons')) {
1467 1467
 
1468
-            return get_transient( 'sensei_'. $course_id .'_none_module_lessons');
1468
+            return get_transient('sensei_'.$course_id.'_none_module_lessons');
1469 1469
 
1470 1470
         }
1471 1471
 
1472 1472
         // create terms array which must be excluded from other arrays
1473
-        $course_modules = $this->get_course_modules( $course_id );
1473
+        $course_modules = $this->get_course_modules($course_id);
1474 1474
 
1475 1475
         //exit if there are no module on this course
1476
-        if( empty( $course_modules ) || ! is_array( $course_modules ) ){
1476
+        if (empty($course_modules) || ! is_array($course_modules)) {
1477 1477
 
1478
-            return  Sensei()->course->course_lessons( $course_id );
1478
+            return  Sensei()->course->course_lessons($course_id);
1479 1479
 
1480 1480
         }
1481 1481
 
1482 1482
         $terms = array();
1483
-        foreach( $course_modules as $module ){
1483
+        foreach ($course_modules as $module) {
1484 1484
 
1485
-            array_push( $terms ,  $module->term_id );
1485
+            array_push($terms, $module->term_id);
1486 1486
 
1487 1487
         }
1488 1488
 
@@ -1493,7 +1493,7 @@  discard block
 block discarded – undo
1493 1493
             'meta_query' => array(
1494 1494
                 array(
1495 1495
                     'key' => '_lesson_course',
1496
-                    'value' => intval( $course_id ),
1496
+                    'value' => intval($course_id),
1497 1497
                     'compare' => '='
1498 1498
                 )
1499 1499
             ),
@@ -1510,11 +1510,11 @@  discard block
 block discarded – undo
1510 1510
             'suppress_filters' => 0
1511 1511
         );
1512 1512
 
1513
-        $wp_lessons_query = new WP_Query( $args );
1513
+        $wp_lessons_query = new WP_Query($args);
1514 1514
 
1515
-        if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0  ){
1515
+        if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) {
1516 1516
             $non_module_lessons = $wp_lessons_query->get_posts();
1517
-            set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS );
1517
+            set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS);
1518 1518
         }
1519 1519
 
1520 1520
         return $non_module_lessons;
@@ -1525,7 +1525,7 @@  discard block
 block discarded – undo
1525 1525
      *
1526 1526
      * @since 1.8.0
1527 1527
      */
1528
-    public function setup_modules_taxonomy(){
1528
+    public function setup_modules_taxonomy() {
1529 1529
 
1530 1530
         $labels = array(
1531 1531
             'name' => __('Modules', 'woothemes-sensei'),
@@ -1562,11 +1562,11 @@  discard block
 block discarded – undo
1562 1562
             'show_in_nav_menus' => false,
1563 1563
             'show_in_quick_edit' => false,
1564 1564
             'show_ui' => true,
1565
-            'rewrite' => array('slug' => $modules_rewrite_slug ),
1565
+            'rewrite' => array('slug' => $modules_rewrite_slug),
1566 1566
             'labels' => $labels
1567 1567
         );
1568 1568
 
1569
-        register_taxonomy( 'module' , array('course', 'lesson'), $args);
1569
+        register_taxonomy('module', array('course', 'lesson'), $args);
1570 1570
 
1571 1571
     }// end setup_modules_taxonomy
1572 1572
 
@@ -1578,12 +1578,12 @@  discard block
 block discarded – undo
1578 1578
      * @since 1.8.0
1579 1579
      * @return void
1580 1580
      */
1581
-    function redirect_to_lesson_module_taxonomy_to_course( ){
1581
+    function redirect_to_lesson_module_taxonomy_to_course( ) {
1582 1582
 
1583
-        global $typenow , $taxnow;
1583
+        global $typenow, $taxnow;
1584 1584
 
1585
-        if( 'lesson'== $typenow && 'module'==$taxnow ){
1586
-            wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course'  ) );
1585
+        if ('lesson' == $typenow && 'module' == $taxnow) {
1586
+            wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course'));
1587 1587
         }
1588 1588
 
1589 1589
     }// end redirect to course taxonomy
@@ -1596,18 +1596,18 @@  discard block
 block discarded – undo
1596 1596
      * @since 1.8.0
1597 1597
      * @return void
1598 1598
      */
1599
-    public function remove_lessons_menu_model_taxonomy(){
1599
+    public function remove_lessons_menu_model_taxonomy() {
1600 1600
         global $submenu;
1601 1601
 
1602
-        if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){
1602
+        if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) {
1603 1603
             return; // exit
1604 1604
         }
1605 1605
 
1606 1606
         $lesson_main_menu = $submenu['edit.php?post_type=lesson'];
1607
-        foreach( $lesson_main_menu as $index => $sub_item ){
1607
+        foreach ($lesson_main_menu as $index => $sub_item) {
1608 1608
 
1609
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2] ){
1610
-                unset( $submenu['edit.php?post_type=lesson'][ $index ]);
1609
+            if ('edit-tags.php?taxonomy=module&amp;post_type=lesson' == $sub_item[2]) {
1610
+                unset($submenu['edit.php?post_type=lesson'][$index]);
1611 1611
             }
1612 1612
         }
1613 1613
 
@@ -1621,18 +1621,18 @@  discard block
 block discarded – undo
1621 1621
      * @since 1.8.0
1622 1622
      * @return void
1623 1623
      */
1624
-    public function remove_courses_menu_model_taxonomy(){
1624
+    public function remove_courses_menu_model_taxonomy() {
1625 1625
         global $submenu;
1626 1626
 
1627
-        if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){
1627
+        if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) {
1628 1628
             return; // exit
1629 1629
         }
1630 1630
 
1631 1631
         $course_main_menu = $submenu['edit.php?post_type=course'];
1632
-        foreach( $course_main_menu as $index => $sub_item ){
1632
+        foreach ($course_main_menu as $index => $sub_item) {
1633 1633
 
1634
-            if( 'edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2] ){
1635
-                unset( $submenu['edit.php?post_type=course'][ $index ]);
1634
+            if ('edit-tags.php?taxonomy=module&amp;post_type=course' == $sub_item[2]) {
1635
+                unset($submenu['edit.php?post_type=course'][$index]);
1636 1636
             }
1637 1637
         }
1638 1638
 
@@ -1648,12 +1648,12 @@  discard block
 block discarded – undo
1648 1648
      * @param string $term_name
1649 1649
      * @return array $owners { type WP_User }. Empty array if none if found.
1650 1650
      */
1651
-    public static function get_term_authors( $term_name ){
1651
+    public static function get_term_authors($term_name) {
1652 1652
 
1653
-        $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false )  );
1653
+        $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false));
1654 1654
 
1655 1655
         $owners = array();
1656
-        if( empty( $terms ) ){
1656
+        if (empty($terms)) {
1657 1657
 
1658 1658
             return $owners;
1659 1659
 
@@ -1663,11 +1663,11 @@  discard block
 block discarded – undo
1663 1663
 
1664 1664
 
1665 1665
         //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly
1666
-        foreach( $terms as $term){
1667
-            if( $term->name == $term_name ){
1666
+        foreach ($terms as $term) {
1667
+            if ($term->name == $term_name) {
1668 1668
 
1669 1669
                 // look for the author in the slug
1670
-                $owners[] = Sensei_Core_Modules::get_term_author( $term->slug  );
1670
+                $owners[] = Sensei_Core_Modules::get_term_author($term->slug);
1671 1671
 
1672 1672
             }// end if term name
1673 1673
 
@@ -1688,30 +1688,30 @@  discard block
 block discarded – undo
1688 1688
      * @param $slug
1689 1689
      * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned.
1690 1690
      */
1691
-    public static function get_term_author( $slug='' ){
1691
+    public static function get_term_author($slug = '') {
1692 1692
 
1693
-        $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) );
1693
+        $term_owner = get_user_by('email', get_bloginfo('admin_email'));
1694 1694
 
1695
-        if( empty( $slug ) ){
1695
+        if (empty($slug)) {
1696 1696
 
1697 1697
             return $term_owner;
1698 1698
 
1699 1699
         }
1700 1700
 
1701 1701
         // look for the author in the slug
1702
-        $slug_parts = explode( '-', $slug );
1702
+        $slug_parts = explode('-', $slug);
1703 1703
 
1704
-        if( count( $slug_parts ) > 1 ){
1704
+        if (count($slug_parts) > 1) {
1705 1705
 
1706 1706
             // get the user data
1707 1707
             $possible_user_id = $slug_parts[0];
1708
-            $author = get_userdata( $possible_user_id );
1708
+            $author = get_userdata($possible_user_id);
1709 1709
 
1710 1710
             // if the user doesnt exist for the first part of the slug
1711 1711
             // then this slug was also created by admin
1712
-            if( is_a( $author, 'WP_User' ) ){
1712
+            if (is_a($author, 'WP_User')) {
1713 1713
 
1714
-                $term_owner =  $author;
1714
+                $term_owner = $author;
1715 1715
 
1716 1716
             }
1717 1717
         }
@@ -1728,48 +1728,48 @@  discard block
 block discarded – undo
1728 1728
      *
1729 1729
      * @param WP_Post $post Post object.
1730 1730
      */
1731
-    public function course_module_metabox( $post ) {
1731
+    public function course_module_metabox($post) {
1732 1732
 
1733 1733
         $tax_name = 'module';
1734
-        $taxonomy = get_taxonomy( 'module' );
1734
+        $taxonomy = get_taxonomy('module');
1735 1735
 
1736 1736
         ?>
1737 1737
         <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv">
1738 1738
             <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs">
1739 1739
                 <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li>
1740
-                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li>
1740
+                <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li>
1741 1741
             </ul>
1742 1742
 
1743 1743
             <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;">
1744 1744
                 <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" >
1745
-                    <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?>
1745
+                    <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?>
1746 1746
                 </ul>
1747 1747
             </div>
1748 1748
 
1749 1749
             <div id="<?php echo $tax_name; ?>-all" class="tabs-panel">
1750 1750
                 <?php
1751
-                $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']';
1751
+                $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']';
1752 1752
                 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.
1753 1753
                 ?>
1754 1754
                 <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear">
1755
-                    <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?>
1755
+                    <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?>
1756 1756
                 </ul>
1757 1757
             </div>
1758
-            <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?>
1758
+            <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?>
1759 1759
                 <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children">
1760 1760
                     <h4>
1761 1761
                         <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js">
1762 1762
                             <?php
1763 1763
                             /* translators: %s: add new taxonomy label */
1764
-                            printf( __( '+ %s' ), $taxonomy->labels->add_new_item );
1764
+                            printf(__('+ %s'), $taxonomy->labels->add_new_item);
1765 1765
                             ?>
1766 1766
                         </a>
1767 1767
                     </h4>
1768 1768
                     <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child">
1769 1769
                         <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label>
1770
-                        <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"/>
1771
-                        <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>
1772
-                        <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?>
1770
+                        <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"/>
1771
+                        <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>
1772
+                        <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?>
1773 1773
                         <span id="<?php echo $tax_name; ?>-ajax-response"></span>
1774 1774
                     </p>
1775 1775
                 </div>
@@ -1789,55 +1789,55 @@  discard block
 block discarded – undo
1789 1789
     public static function add_new_module_term( ) {
1790 1790
 
1791 1791
 
1792
-        if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module'  ) ){
1793
-            wp_send_json_error( array('error'=> 'wrong security nonce') );
1792
+        if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) {
1793
+            wp_send_json_error(array('error'=> 'wrong security nonce'));
1794 1794
         }
1795 1795
 
1796 1796
         // get the term an create the new term storing infomration
1797
-        $term_name = sanitize_text_field( $_POST['newTerm'] );
1797
+        $term_name = sanitize_text_field($_POST['newTerm']);
1798 1798
 
1799
-        if( current_user_can('manage_options' ) ) {
1799
+        if (current_user_can('manage_options')) {
1800 1800
 
1801
-            $term_slug = str_ireplace(' ', '-', trim( $term_name ) );
1801
+            $term_slug = str_ireplace(' ', '-', trim($term_name));
1802 1802
 
1803 1803
         } else {
1804 1804
 
1805
-            $term_slug =  get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) );
1805
+            $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name));
1806 1806
 
1807 1807
         }
1808 1808
 
1809
-        $course_id = sanitize_text_field( $_POST['course_id'] );
1809
+        $course_id = sanitize_text_field($_POST['course_id']);
1810 1810
 
1811 1811
         // save the term
1812
-        $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug)  );
1812
+        $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug));
1813 1813
 
1814 1814
         // send error for all errors except term exits
1815
-        if( is_wp_error( $slug ) ){
1815
+        if (is_wp_error($slug)) {
1816 1816
 
1817 1817
             // prepare for possible term name and id to be passed down if term exists
1818 1818
             $term_data = array();
1819 1819
 
1820 1820
             // if term exists also send back the term name and id
1821
-            if( isset( $slug->errors['term_exists'] ) ){
1821
+            if (isset($slug->errors['term_exists'])) {
1822 1822
 
1823
-                $term = get_term_by( 'slug', $term_slug, 'module');
1823
+                $term = get_term_by('slug', $term_slug, 'module');
1824 1824
                 $term_data['name'] = $term_name;
1825 1825
                 $term_data['id'] = $term->term_id;
1826 1826
 
1827 1827
                 // set the object terms
1828
-                wp_set_object_terms( $course_id, $term->term_id, 'module', true );
1828
+                wp_set_object_terms($course_id, $term->term_id, 'module', true);
1829 1829
             }
1830 1830
 
1831
-            wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) );
1831
+            wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data));
1832 1832
 
1833 1833
         }
1834 1834
 
1835 1835
         //make sure the new term is checked for this course
1836 1836
 
1837
-        wp_set_object_terms( $course_id, $slug['term_id'], 'module', true );
1837
+        wp_set_object_terms($course_id, $slug['term_id'], 'module', true);
1838 1838
 
1839 1839
         // Handle request then generate response using WP_Ajax_Response
1840
-        wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) );
1840
+        wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name));
1841 1841
 
1842 1842
     }
1843 1843
 
@@ -1849,26 +1849,26 @@  discard block
 block discarded – undo
1849 1849
      *
1850 1850
      * @since 1.8.0
1851 1851
      */
1852
-    public function filter_module_terms( $terms, $taxonomies, $args ){
1852
+    public function filter_module_terms($terms, $taxonomies, $args) {
1853 1853
 
1854 1854
         //dont limit for admins and other taxonomies. This should also only apply to admin
1855
-        if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin()  ){
1855
+        if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1856 1856
             return $terms;
1857 1857
         }
1858 1858
 
1859 1859
         // avoid infinite call loop
1860
-        remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1860
+        remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1861 1861
 
1862 1862
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1863
-        if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){
1863
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1864 1864
             // change only scrub the terms ids form the array keys
1865
-            $terms = array_keys( $terms );
1865
+            $terms = array_keys($terms);
1866 1866
         }
1867 1867
 
1868
-        $teachers_terms =  $this->filter_terms_by_owner( $terms, get_current_user_id() );
1868
+        $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id());
1869 1869
 
1870 1870
         // add filter again as removed above
1871
-        add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 );
1871
+        add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3);
1872 1872
 
1873 1873
         return $teachers_terms;
1874 1874
     }// end filter_module_terms
@@ -1881,25 +1881,25 @@  discard block
 block discarded – undo
1881 1881
      *
1882 1882
      * @since 1.8.0
1883 1883
      */
1884
-    public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){
1884
+    public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) {
1885 1885
 
1886 1886
         //dont limit for admins and other taxonomies. This should also only apply to admin
1887
-        if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms )
1887
+        if (current_user_can('manage_options') || ! is_admin() || empty($terms)
1888 1888
             // only apply this to module only taxonomy queries so 1 taxonomy only:
1889
-            ||  count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies )  ){
1889
+            ||  count($taxonomies) > 1 || ! in_array('module', $taxonomies)) {
1890 1890
             return $terms;
1891 1891
         }
1892 1892
 
1893
-        $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() );
1893
+        $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id());
1894 1894
 
1895 1895
         // if term objects were passed in send back objects
1896 1896
         // if term id were passed in send that back
1897
-        if( is_object( $terms[0] ) ){
1897
+        if (is_object($terms[0])) {
1898 1898
             return $term_objects;
1899 1899
         }
1900 1900
 
1901 1901
         $terms = array();
1902
-        foreach( $term_objects as $term_object ){
1902
+        foreach ($term_objects as $term_object) {
1903 1903
             $terms[] = $term_object->term_id;
1904 1904
         }
1905 1905
 
@@ -1917,20 +1917,20 @@  discard block
 block discarded – undo
1917 1917
      * @param $user_id
1918 1918
      * @return array
1919 1919
      */
1920
-    public function filter_terms_by_owner( $terms, $user_id ){
1920
+    public function filter_terms_by_owner($terms, $user_id) {
1921 1921
 
1922 1922
         $users_terms = array();
1923 1923
 
1924
-        foreach( $terms as $index => $term ){
1924
+        foreach ($terms as $index => $term) {
1925 1925
 
1926
-            if( is_numeric( $term ) ){
1926
+            if (is_numeric($term)) {
1927 1927
                 // the term id was given, get the term object
1928
-                $term = get_term( $term, 'module' );
1928
+                $term = get_term($term, 'module');
1929 1929
             }
1930 1930
 
1931
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1931
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1932 1932
 
1933
-            if ( $user_id == $author->ID ) {
1933
+            if ($user_id == $author->ID) {
1934 1934
                 // add the term to the teachers terms
1935 1935
                 $users_terms[] = $term;
1936 1936
             }
@@ -1949,34 +1949,34 @@  discard block
 block discarded – undo
1949 1949
      *
1950 1950
      * @since 1.8.0
1951 1951
      */
1952
-    public function append_teacher_name_to_module( $terms, $taxonomies, $args )
1952
+    public function append_teacher_name_to_module($terms, $taxonomies, $args)
1953 1953
     {
1954 1954
 
1955 1955
         // only for admin users ont he module taxonomy
1956
-        if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) {
1956
+        if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) {
1957 1957
             return $terms;
1958 1958
         }
1959 1959
 
1960 1960
         // in certain cases the array is passed in as reference to the parent term_id => parent_id
1961 1961
         // simply return this as wp doesn't need an array of stdObject Term
1962
-        if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) {
1962
+        if (isset($args['fields']) && 'id=>parent' == $args['fields']) {
1963 1963
 
1964 1964
             return $terms;
1965 1965
 
1966 1966
         }
1967 1967
 
1968 1968
         // loop through and update all terms adding the author name
1969
-        foreach( $terms as $index => $term ){
1969
+        foreach ($terms as $index => $term) {
1970 1970
 
1971
-            if( is_numeric( $term ) ){
1971
+            if (is_numeric($term)) {
1972 1972
                 // the term id was given, get the term object
1973
-                $term = get_term( $term, 'module' );
1973
+                $term = get_term($term, 'module');
1974 1974
             }
1975 1975
 
1976
-            $author = Sensei_Core_Modules::get_term_author( $term->slug );
1976
+            $author = Sensei_Core_Modules::get_term_author($term->slug);
1977 1977
 
1978
-            if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) {
1979
-                $term->name = $term->name . ' (' . $author->display_name . ') ';
1978
+            if ( ! user_can($author, 'manage_options') && isset($term->name)) {
1979
+                $term->name = $term->name.' ('.$author->display_name.') ';
1980 1980
             }
1981 1981
 
1982 1982
             // add the term to the teachers terms
@@ -2005,23 +2005,23 @@  discard block
 block discarded – undo
2005 2005
      * @sine 1.9.0
2006 2006
      * @param $post_id
2007 2007
      */
2008
-    public static function reset_none_modules_transient ( $post_id ){
2008
+    public static function reset_none_modules_transient($post_id) {
2009 2009
 
2010 2010
         // this should only apply to course and lesson post types
2011
-        if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){
2011
+        if (in_array(get_post_type($post_id), array('course', 'lesson'))) {
2012 2012
 
2013 2013
             $course_id = '';
2014 2014
 
2015
-            if( 'lesson' == get_post_type( $post_id ) ){
2015
+            if ('lesson' == get_post_type($post_id)) {
2016 2016
 
2017
-                $course_id = Sensei()->lesson->get_course_id( $post_id );
2017
+                $course_id = Sensei()->lesson->get_course_id($post_id);
2018 2018
 
2019 2019
             }
2020 2020
 
2021 2021
 
2022
-            if( !empty( $course_id ) ){
2022
+            if ( ! empty($course_id)) {
2023 2023
 
2024
-                delete_transient( 'sensei_'. $course_id .'_none_module_lessons' );
2024
+                delete_transient('sensei_'.$course_id.'_none_module_lessons');
2025 2025
 
2026 2026
             }
2027 2027
 
@@ -2036,9 +2036,9 @@  discard block
 block discarded – undo
2036 2036
      * @deprecated since 1.9.0
2037 2037
      *
2038 2038
      */
2039
-    public static function deprecate_sensei_single_course_modules_content(){
2039
+    public static function deprecate_sensei_single_course_modules_content() {
2040 2040
 
2041
-        sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' );
2041
+        sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after');
2042 2042
 
2043 2043
     }
2044 2044
 
@@ -2049,12 +2049,12 @@  discard block
 block discarded – undo
2049 2049
      *
2050 2050
      * @since 1.9.0
2051 2051
      */
2052
-    public static function setup_single_course_module_loop(){
2052
+    public static function setup_single_course_module_loop() {
2053 2053
 
2054 2054
         global $sensei_modules_loop, $post;
2055 2055
         $course_id = $post->ID;
2056 2056
 
2057
-        $modules = Sensei()->modules->get_course_modules( $course_id );
2057
+        $modules = Sensei()->modules->get_course_modules($course_id);
2058 2058
 
2059 2059
         //initial setup
2060 2060
         $sensei_modules_loop['total'] = 0;
@@ -2062,22 +2062,22 @@  discard block
 block discarded – undo
2062 2062
         $sensei_modules_loop['current'] = -1;
2063 2063
 
2064 2064
         // exit if this course doesn't have modules
2065
-        if( !$modules || empty( $modules )  ){
2065
+        if ( ! $modules || empty($modules)) {
2066 2066
             return;
2067 2067
         }
2068 2068
 
2069 2069
 
2070 2070
         $lessons_in_all_modules = array();
2071
-        foreach( $modules as $term ){
2071
+        foreach ($modules as $term) {
2072 2072
 
2073
-            $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id);
2074
-            $lessons_in_all_modules = array_merge(  $lessons_in_all_modules, $lessons_in_this_module  );
2073
+            $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id);
2074
+            $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module);
2075 2075
 
2076 2076
         }
2077 2077
 
2078 2078
 
2079 2079
         //setup all of the modules loop variables
2080
-        $sensei_modules_loop['total'] = count( $modules );
2080
+        $sensei_modules_loop['total'] = count($modules);
2081 2081
         $sensei_modules_loop['modules'] = $modules;
2082 2082
         $sensei_modules_loop['current'] = -1;
2083 2083
         $sensei_modules_loop['course_id'] = $course_id;
@@ -2090,7 +2090,7 @@  discard block
 block discarded – undo
2090 2090
      * @since 1.9.0
2091 2091
      *
2092 2092
      */
2093
-    public static function teardown_single_course_module_loop(){
2093
+    public static function teardown_single_course_module_loop() {
2094 2094
 
2095 2095
         global $sensei_modules_loop, $wp_query, $post;
2096 2096
 
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   +37 added lines, -37 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
 
@@ -296,10 +296,10 @@  discard block
 block discarded – undo
296 296
 				$percent_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_percentage', $grade_args, $item ), true ) );
297 297
 				$percent_total = Sensei_Grading::get_course_users_grades_sum( $item->ID );
298 298
 
299
-                $course_average_percent = 0;
300
-                if( $percent_count > 0 && $percent_total > 0 ){
301
-                    $course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) );
302
-                }
299
+				$course_average_percent = 0;
300
+				if( $percent_count > 0 && $percent_total > 0 ){
301
+					$course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) );
302
+				}
303 303
 
304 304
 
305 305
 				// Output course data
@@ -355,12 +355,12 @@  discard block
 block discarded – undo
355 355
 					$grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true ));
356 356
 					$grade_total = Sensei_Grading::get_lessons_users_grades_sum( $item->ID );
357 357
 
358
-                    $lesson_average_grade = 0;
359
-                    if( $grade_total > 0 && $grade_count > 0 ){
360
-                        $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
361
-                    }
358
+					$lesson_average_grade = 0;
359
+					if( $grade_total > 0 && $grade_count > 0 ){
360
+						$lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
361
+					}
362 362
 
363
-                }
363
+				}
364 364
 				// Output lesson data
365 365
 				if ( $this->csv_output ) {
366 366
 					$lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID );
@@ -417,15 +417,15 @@  discard block
 block discarded – undo
417 417
 				$grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_lesson_grades', $grade_args, $item ), true ));
418 418
 				$grade_total = Sensei_Grading::get_user_graded_lessons_sum( $item->ID );
419 419
 
420
-                $user_average_grade = 0;
421
-                if( $grade_total > 0 && $grade_count > 0 ){
422
-                    $user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
423
-                }
420
+				$user_average_grade = 0;
421
+				if( $grade_total > 0 && $grade_count > 0 ){
422
+					$user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
423
+				}
424 424
 
425 425
 				// Output the users data
426 426
 				if ( $this->csv_output ) {
427
-                    $user_name = Sensei_Learner::get_full_name( $item->ID );
428
-                }
427
+					$user_name = Sensei_Learner::get_full_name( $item->ID );
428
+				}
429 429
 				else {
430 430
 					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
431 431
 					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
@@ -519,17 +519,17 @@  discard block
 block discarded – undo
519 519
 		// This stops the full meta data of each user being loaded
520 520
 		$args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' );
521 521
 
522
-        /**
523
-         * Filter the WP_User_Query arguments
524
-         * @since 1.6.0
525
-         * @param $args
526
-         */
527
-        $args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
522
+		/**
523
+		 * Filter the WP_User_Query arguments
524
+		 * @since 1.6.0
525
+		 * @param $args
526
+		 */
527
+		$args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
528 528
 		$wp_user_search = new WP_User_Query( $args );
529
-        $learners = $wp_user_search->get_results();
529
+		$learners = $wp_user_search->get_results();
530 530
 		$this->total_items = $wp_user_search->get_total();
531 531
 
532
-        return $learners;
532
+		return $learners;
533 533
 
534 534
 	} // End get_learners()
535 535
 
@@ -546,15 +546,15 @@  discard block
 block discarded – undo
546 546
 		$total_courses = Sensei()->course->course_count( array('publish', 'private') );
547 547
 		$total_lessons = Sensei()->lesson->lesson_count( array('publish', 'private') );
548 548
 
549
-        /**
550
-         * filter the analysis tot grades query args
551
-         */
549
+		/**
550
+		 * filter the analysis tot grades query args
551
+		 */
552 552
 		$grade_args = apply_filters( 'sensei_analysis_total_quiz_grades', array(
553 553
 				'type' => 'sensei_lesson_status',
554 554
 				'status' => 'any',
555 555
 
556
-                'meta_key' => 'grade'
557
-        ));
556
+				'meta_key' => 'grade'
557
+		));
558 558
 
559 559
 		$total_grade_count = Sensei_Grading::get_graded_lessons_count();
560 560
 		$total_grade_total = Sensei_Grading::get_graded_lessons_sum();
Please login to merge, or discard this patch.
Spacing   +177 added lines, -177 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( 
@@ -293,31 +293,31 @@  discard block
 block discarded – undo
293 293
 						'meta_key' => 'percent',
294 294
 					);
295 295
 
296
-				$percent_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_percentage', $grade_args, $item ), true ) );
297
-				$percent_total = Sensei_Grading::get_course_users_grades_sum( $item->ID );
296
+				$percent_count = count(Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_percentage', $grade_args, $item), true));
297
+				$percent_total = Sensei_Grading::get_course_users_grades_sum($item->ID);
298 298
 
299 299
                 $course_average_percent = 0;
300
-                if( $percent_count > 0 && $percent_total > 0 ){
301
-                    $course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) );
300
+                if ($percent_count > 0 && $percent_total > 0) {
301
+                    $course_average_percent = abs(round(doubleval($percent_total / $percent_count), 2));
302 302
                 }
303 303
 
304 304
 
305 305
 				// Output course data
306
-				if ( $this->csv_output ) {
307
-					$course_title = apply_filters( 'the_title', $item->post_title, $item->ID );
306
+				if ($this->csv_output) {
307
+					$course_title = apply_filters('the_title', $item->post_title, $item->ID);
308 308
 				}
309 309
 				else {
310
-					$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID ), admin_url( 'admin.php' ) );
310
+					$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID), admin_url('admin.php'));
311 311
 
312
-					$course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>';
312
+					$course_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>';
313 313
 					$course_average_percent .= '%';
314 314
 				} // End If Statement
315
-				$column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $course_title,
315
+				$column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $course_title,
316 316
 												'students' => $course_students,
317 317
 												'lessons' => $course_lessons,
318 318
 												'completions' => $course_completions,
319 319
 												'average_percent' => $course_average_percent,
320
-											), $item, $this );
320
+											), $item, $this);
321 321
 				break;
322 322
 
323 323
 			case 'lessons' :
@@ -327,65 +327,65 @@  discard block
 block discarded – undo
327 327
 						'type' => 'sensei_lesson_status',
328 328
 						'status' => 'any',
329 329
 					);
330
-				$lesson_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_learners', $lesson_args, $item ) );
330
+				$lesson_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_learners', $lesson_args, $item));
331 331
 
332 332
 				// Get Course Completions
333 333
 				$lesson_args = array( 
334 334
 						'post_id' => $item->ID,
335 335
 						'type' => 'sensei_lesson_status',
336
-						'status' => array( 'complete', 'graded', 'passed', 'failed' ),
336
+						'status' => array('complete', 'graded', 'passed', 'failed'),
337 337
 						'count' => true,
338 338
 					);
339
-				$lesson_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_completions', $lesson_args, $item ) );
339
+				$lesson_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_completions', $lesson_args, $item));
340 340
 
341 341
 				// Course 
342
-				$course_id = get_post_meta( $item->ID, '_lesson_course', true );
343
-				$course_title = $course_id ? get_the_title( $course_id ) : '';
342
+				$course_id = get_post_meta($item->ID, '_lesson_course', true);
343
+				$course_title = $course_id ? get_the_title($course_id) : '';
344 344
 
345 345
 				$lesson_average_grade = __('n/a', 'woothemes-sensei');
346
-				if ( false != get_post_meta($item->ID, '_quiz_has_questions', true) ) {
346
+				if (false != get_post_meta($item->ID, '_quiz_has_questions', true)) {
347 347
 					// Get Percent Complete
348 348
 					$grade_args = array( 
349 349
 							'post_id' => $item->ID,
350 350
 							'type' => 'sensei_lesson_status',
351
-							'status' => array( 'graded', 'passed', 'failed' ),
351
+							'status' => array('graded', 'passed', 'failed'),
352 352
 							'meta_key' => 'grade',
353 353
 						);
354 354
 
355
-					$grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true ));
356
-					$grade_total = Sensei_Grading::get_lessons_users_grades_sum( $item->ID );
355
+					$grade_count = count(Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_grades', $grade_args, $item), true));
356
+					$grade_total = Sensei_Grading::get_lessons_users_grades_sum($item->ID);
357 357
 
358 358
                     $lesson_average_grade = 0;
359
-                    if( $grade_total > 0 && $grade_count > 0 ){
360
-                        $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
359
+                    if ($grade_total > 0 && $grade_count > 0) {
360
+                        $lesson_average_grade = abs(round(doubleval($grade_total / $grade_count), 2));
361 361
                     }
362 362
 
363 363
                 }
364 364
 				// Output lesson data
365
-				if ( $this->csv_output ) {
366
-					$lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID );
365
+				if ($this->csv_output) {
366
+					$lesson_title = apply_filters('the_title', $item->post_title, $item->ID);
367 367
 				}
368 368
 				else {
369
-					$url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) );
370
-					$lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>';
369
+					$url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php'));
370
+					$lesson_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>';
371 371
 
372
-					if ( $course_id ) {
373
-						$url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) );
374
-						$course_title = '<a href="' . esc_url( $url ) . '">' . $course_title . '</a>';
372
+					if ($course_id) {
373
+						$url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'));
374
+						$course_title = '<a href="'.esc_url($url).'">'.$course_title.'</a>';
375 375
 					}
376 376
 					else {
377 377
 						$course_title = __('n/a', 'woothemes-sensei');
378 378
 					}
379
-					if ( is_numeric( $lesson_average_grade ) ) {
379
+					if (is_numeric($lesson_average_grade)) {
380 380
 						$lesson_average_grade .= '%';
381 381
 					}
382 382
 				} // End If Statement
383
-				$column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $lesson_title,
383
+				$column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $lesson_title,
384 384
 												'course' => $course_title,
385 385
 												'students' => $lesson_students,
386 386
 												'completions' => $lesson_completions,
387 387
 												'average_grade' => $lesson_average_grade,
388
-											), $item, $this );
388
+											), $item, $this);
389 389
 				break;
390 390
 
391 391
 			case 'users' :
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 						'type' => 'sensei_course_status',
397 397
 						'status' => 'any',
398 398
 					);
399
-				$user_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_started', $course_args, $item ) );
399
+				$user_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_started', $course_args, $item));
400 400
 
401 401
 				// Get Completed Courses
402 402
 				$course_args = array( 
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 						'type' => 'sensei_course_status',
405 405
 						'status' => 'complete',
406 406
 					);
407
-				$user_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_ended', $course_args, $item ) );
407
+				$user_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_ended', $course_args, $item));
408 408
 
409 409
 				// Get Quiz Grades
410 410
 				$grade_args = array( 
@@ -414,29 +414,29 @@  discard block
 block discarded – undo
414 414
 						'meta_key' => 'grade',
415 415
 					);
416 416
 
417
-				$grade_count = count( Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_lesson_grades', $grade_args, $item ), true ));
418
-				$grade_total = Sensei_Grading::get_user_graded_lessons_sum( $item->ID );
417
+				$grade_count = count(Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_lesson_grades', $grade_args, $item), true));
418
+				$grade_total = Sensei_Grading::get_user_graded_lessons_sum($item->ID);
419 419
 
420 420
                 $user_average_grade = 0;
421
-                if( $grade_total > 0 && $grade_count > 0 ){
422
-                    $user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) );
421
+                if ($grade_total > 0 && $grade_count > 0) {
422
+                    $user_average_grade = abs(round(doubleval($grade_total / $grade_count), 2));
423 423
                 }
424 424
 
425 425
 				// Output the users data
426
-				if ( $this->csv_output ) {
427
-                    $user_name = Sensei_Learner::get_full_name( $item->ID );
426
+				if ($this->csv_output) {
427
+                    $user_name = Sensei_Learner::get_full_name($item->ID);
428 428
                 }
429 429
 				else {
430
-					$url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) );
431
-					$user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>';
430
+					$url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->ID), admin_url('admin.php'));
431
+					$user_name = '<strong><a class="row-title" href="'.esc_url($url).'">'.$item->display_name.'</a></strong>';
432 432
 					$user_average_grade .= '%';
433 433
 				} // End If Statement
434
-				$column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $user_name,
434
+				$column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $user_name,
435 435
 												'registered' => $item->user_registered,
436
-												'active_courses' => ( $user_courses_started - $user_courses_ended ),
436
+												'active_courses' => ($user_courses_started - $user_courses_ended),
437 437
 												'completed_courses' => $user_courses_ended,
438 438
 												'average_grade' => $user_average_grade,
439
-											), $item, $this );
439
+											), $item, $this);
440 440
 				break;
441 441
 		} // end switch
442 442
 		return $column_data;
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 	 * @since  1.7.0
448 448
 	 * @return array courses
449 449
 	 */
450
-	private function get_courses( $args ) {
450
+	private function get_courses($args) {
451 451
 		$course_args = array(
452 452
 			'post_type' => 'course',
453 453
 			'post_status' => array('publish', 'private'),
@@ -458,16 +458,16 @@  discard block
 block discarded – undo
458 458
 			'suppress_filters' => 0,
459 459
 		);
460 460
 
461
-		if ( $this->csv_output ) {
461
+		if ($this->csv_output) {
462 462
 			$course_args['posts_per_page'] = '-1';
463 463
 		}
464 464
 
465
-		if( isset( $args['search'] ) ) {
465
+		if (isset($args['search'])) {
466 466
 			$course_args['s'] = $args['search'];
467 467
 		}
468 468
 
469 469
 		// Using WP_Query as get_posts() doesn't support 'found_posts'
470
-		$courses_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_courses', $course_args ) );
470
+		$courses_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_courses', $course_args));
471 471
 		$this->total_items = $courses_query->found_posts;
472 472
 		return $courses_query->posts;
473 473
 
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 	 * @since  1.7.0
479 479
 	 * @return array lessons
480 480
 	 */
481
-	private function get_lessons( $args ) {
481
+	private function get_lessons($args) {
482 482
 		$lessons_args = array(
483 483
 			'post_type' => 'lesson',
484 484
 			'post_status' => array('publish', 'private'),
@@ -489,16 +489,16 @@  discard block
 block discarded – undo
489 489
 			'suppress_filters' => 0,
490 490
 		);
491 491
 
492
-		if ( $this->csv_output ) {
492
+		if ($this->csv_output) {
493 493
 			$lessons_args['posts_per_page'] = '-1';
494 494
 		}
495 495
 
496
-		if( isset( $args['search'] ) ) {
496
+		if (isset($args['search'])) {
497 497
 			$lessons_args['s'] = $args['search'];
498 498
 		}
499 499
 
500 500
 		// Using WP_Query as get_posts() doesn't support 'found_posts'
501
-		$lessons_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_lessons', $lessons_args ) );
501
+		$lessons_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_lessons', $lessons_args));
502 502
 		$this->total_items = $lessons_query->found_posts;
503 503
 		return $lessons_query->posts;
504 504
 	} // End get_lessons()
@@ -508,24 +508,24 @@  discard block
 block discarded – undo
508 508
 	 * @since  1.7.0
509 509
 	 * @return array learners
510 510
 	 */
511
-	private function get_learners( $args ) {
511
+	private function get_learners($args) {
512 512
 
513
-		if ( !empty($args['search']) ) {
513
+		if ( ! empty($args['search'])) {
514 514
 			$args = array(
515
-				'search' => '*' . trim( $args['search'], '*' ) . '*',
515
+				'search' => '*'.trim($args['search'], '*').'*',
516 516
 			);
517 517
 		}
518 518
 
519 519
 		// This stops the full meta data of each user being loaded
520
-		$args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' );
520
+		$args['fields'] = array('ID', 'user_login', 'user_email', 'user_registered', 'display_name');
521 521
 
522 522
         /**
523 523
          * Filter the WP_User_Query arguments
524 524
          * @since 1.6.0
525 525
          * @param $args
526 526
          */
527
-        $args = apply_filters( 'sensei_analysis_overview_filter_users', $args );
528
-		$wp_user_search = new WP_User_Query( $args );
527
+        $args = apply_filters('sensei_analysis_overview_filter_users', $args);
528
+		$wp_user_search = new WP_User_Query($args);
529 529
         $learners = $wp_user_search->get_results();
530 530
 		$this->total_items = $wp_user_search->get_total();
531 531
 
@@ -538,18 +538,18 @@  discard block
 block discarded – undo
538 538
 	 * @since  1.2.0
539 539
 	 * @return array $stats_to_render of stats boxes and values
540 540
 	 */
541
-	public function stats_boxes () {
541
+	public function stats_boxes() {
542 542
 
543 543
 		// Get the data required
544 544
 		$user_count = count_users();
545
-		$user_count = apply_filters( 'sensei_analysis_total_users', $user_count['total_users'], $user_count );
546
-		$total_courses = Sensei()->course->course_count( array('publish', 'private') );
547
-		$total_lessons = Sensei()->lesson->lesson_count( array('publish', 'private') );
545
+		$user_count = apply_filters('sensei_analysis_total_users', $user_count['total_users'], $user_count);
546
+		$total_courses = Sensei()->course->course_count(array('publish', 'private'));
547
+		$total_lessons = Sensei()->lesson->lesson_count(array('publish', 'private'));
548 548
 
549 549
         /**
550 550
          * filter the analysis tot grades query args
551 551
          */
552
-		$grade_args = apply_filters( 'sensei_analysis_total_quiz_grades', array(
552
+		$grade_args = apply_filters('sensei_analysis_total_quiz_grades', array(
553 553
 				'type' => 'sensei_lesson_status',
554 554
 				'status' => 'any',
555 555
 
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 		$total_grade_count = Sensei_Grading::get_graded_lessons_count();
560 560
 		$total_grade_total = Sensei_Grading::get_graded_lessons_sum();
561 561
 		$total_average_grade = 0;
562
-		if( $total_grade_total > 0 &&  $total_grade_count >0   ){
563
-			$total_average_grade = abs( round( doubleval( $total_grade_total / $total_grade_count ), 2 ) );
562
+		if ($total_grade_total > 0 && $total_grade_count > 0) {
563
+			$total_average_grade = abs(round(doubleval($total_grade_total / $total_grade_count), 2));
564 564
 		}
565 565
 
566 566
 
@@ -568,24 +568,24 @@  discard block
 block discarded – undo
568 568
 				'type' => 'sensei_course_status',
569 569
 				'status' => 'any',
570 570
 			);
571
-		$total_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_started', $course_args ) );
571
+		$total_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_started', $course_args));
572 572
 		$course_args = array( 
573 573
 				'type' => 'sensei_course_status',
574 574
 				'status' => 'complete',
575 575
 			);
576
-		$total_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_ended', $course_args ) );
577
-		$average_courses_per_learner = abs( round( doubleval( $total_courses_started / $user_count ), 2 ) );
576
+		$total_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_ended', $course_args));
577
+		$average_courses_per_learner = abs(round(doubleval($total_courses_started / $user_count), 2));
578 578
 
579 579
 		// Setup the boxes to render
580 580
 		$stats_to_render = array( 
581
-								__( 'Total Courses', 'woothemes-sensei' ) => $total_courses,
582
-								__( 'Total Lessons', 'woothemes-sensei' ) => $total_lessons,
583
-								__( 'Total Learners', 'woothemes-sensei' ) => $user_count,
584
-								__( 'Average Courses per Learner', 'woothemes-sensei' ) => $average_courses_per_learner,
585
-								__( 'Average Grade', 'woothemes-sensei' ) => $total_average_grade . '%',
586
-								__( 'Total Completed Courses', 'woothemes-sensei' ) => $total_courses_ended,
581
+								__('Total Courses', 'woothemes-sensei') => $total_courses,
582
+								__('Total Lessons', 'woothemes-sensei') => $total_lessons,
583
+								__('Total Learners', 'woothemes-sensei') => $user_count,
584
+								__('Average Courses per Learner', 'woothemes-sensei') => $average_courses_per_learner,
585
+								__('Average Grade', 'woothemes-sensei') => $total_average_grade.'%',
586
+								__('Total Completed Courses', 'woothemes-sensei') => $total_courses_ended,
587 587
 							);
588
-		return apply_filters( 'sensei_analysis_stats_boxes', $stats_to_render );
588
+		return apply_filters('sensei_analysis_stats_boxes', $stats_to_render);
589 589
 	} // End stats_boxes()
590 590
 
591 591
 	/**
@@ -595,12 +595,12 @@  discard block
 block discarded – undo
595 595
 	 * @return void
596 596
 	 */
597 597
 	public function no_items() {
598
-		if( ! $this->view || 'users' == $this->view ) {
598
+		if ( ! $this->view || 'users' == $this->view) {
599 599
 			$type = 'learners';
600 600
 		} else {
601 601
 			$type = $this->view;
602 602
 		}
603
-		echo  sprintf( __( '%1$sNo %2$s found%3$s', 'woothemes-sensei' ), '<em>', $type, '</em>' );
603
+		echo  sprintf(__('%1$sNo %2$s found%3$s', 'woothemes-sensei'), '<em>', $type, '</em>');
604 604
 	} // End no_items()
605 605
 
606 606
 	/**
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 			'page' => $this->page_slug,
616 616
 		);
617 617
 		$learners_class = $courses_class = $lessons_class = '';
618
-		switch( $this->type ) {
618
+		switch ($this->type) {
619 619
 			case 'courses':
620 620
 				$courses_class = 'current';
621 621
 				break;
@@ -633,18 +633,18 @@  discard block
 block discarded – undo
633 633
 		$lesson_args['view'] = 'lessons';
634 634
 		$courses_args['view'] = 'courses';
635 635
 
636
-		$menu['learners'] = '<a class="' . $learners_class . '" href="' . esc_url( add_query_arg( $learner_args, admin_url( 'admin.php' ) ) ). '">' . __( 'Learners', 'woothemes-sensei' ) . '</a>';
637
-		$menu['courses'] = '<a class="' . $courses_class . '" href="' . esc_url ( add_query_arg( $courses_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Courses', 'woothemes-sensei' ) . '</a>';
638
-		$menu['lessons'] = '<a class="' . $lessons_class . '" href="' . esc_url( add_query_arg( $lesson_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Lessons', 'woothemes-sensei' ) . '</a>';
636
+		$menu['learners'] = '<a class="'.$learners_class.'" href="'.esc_url(add_query_arg($learner_args, admin_url('admin.php'))).'">'.__('Learners', 'woothemes-sensei').'</a>';
637
+		$menu['courses'] = '<a class="'.$courses_class.'" href="'.esc_url(add_query_arg($courses_args, admin_url('admin.php'))).'">'.__('Courses', 'woothemes-sensei').'</a>';
638
+		$menu['lessons'] = '<a class="'.$lessons_class.'" href="'.esc_url(add_query_arg($lesson_args, admin_url('admin.php'))).'">'.__('Lessons', 'woothemes-sensei').'</a>';
639 639
 
640
-		$menu = apply_filters( 'sensei_analysis_overview_sub_menu', $menu );
641
-		if ( !empty($menu) ) {
642
-			echo '<ul class="subsubsub">' . "\n";
643
-			foreach ( $menu as $class => $item ) {
644
-				$menu[ $class ] = "\t<li class='$class'>$item";
640
+		$menu = apply_filters('sensei_analysis_overview_sub_menu', $menu);
641
+		if ( ! empty($menu)) {
642
+			echo '<ul class="subsubsub">'."\n";
643
+			foreach ($menu as $class => $item) {
644
+				$menu[$class] = "\t<li class='$class'>$item";
645 645
 			}
646
-			echo implode( " |</li>\n", $menu ) . "</li>\n";
647
-			echo '</ul>' . "\n";
646
+			echo implode(" |</li>\n", $menu)."</li>\n";
647
+			echo '</ul>'."\n";
648 648
 		}
649 649
 	} // End data_table_header()
650 650
 
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	 * @return void
655 655
 	 */
656 656
 	public function data_table_footer() {
657
-		switch ( $this->type ) {
657
+		switch ($this->type) {
658 658
 			case 'courses':
659 659
 				$report = 'courses-overview';
660 660
 				break;
@@ -668,8 +668,8 @@  discard block
 block discarded – undo
668 668
 				$report = 'user-overview';
669 669
 			break;
670 670
 		} // End Switch Statement
671
-		$url = add_query_arg( array( 'page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report ), admin_url( 'admin.php' ) );
672
-		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>';
671
+		$url = add_query_arg(array('page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report), admin_url('admin.php'));
672
+		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>';
673 673
 	} // End data_table_footer()
674 674
 
675 675
 	/**
@@ -677,19 +677,19 @@  discard block
 block discarded – undo
677 677
 	 * @since  1.7.0
678 678
 	 * @return string $text
679 679
 	 */
680
-	public function search_button( $text = '' ) {
681
-		switch( $this->type ) {
680
+	public function search_button($text = '') {
681
+		switch ($this->type) {
682 682
 			case 'courses':
683
-				$text = __( 'Search Courses', 'woothemes-sensei' );
683
+				$text = __('Search Courses', 'woothemes-sensei');
684 684
 			break;
685 685
 
686 686
 			case 'lessons':
687
-				$text = __( 'Search Lessons', 'woothemes-sensei' );
687
+				$text = __('Search Lessons', 'woothemes-sensei');
688 688
 			break;
689 689
 
690 690
 			case 'users':
691 691
 			default:
692
-				$text = __( 'Search Learners', 'woothemes-sensei' );
692
+				$text = __('Search Learners', 'woothemes-sensei');
693 693
 			break;
694 694
 		} // End Switch Statement
695 695
 
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( 'publish'== $old_status || '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 || current_user_can( 'manage_options' )){
879
-            return false;
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( 'publish'== $old_status || '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 || current_user_can( 'manage_options' )){
879
+			return false;
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( 'publish'== $old_status || '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 ('publish' == $old_status || '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 || current_user_can( 'manage_options' )){
878
+        if ($recipient == $teacher->user_email || current_user_can('manage_options')) {
879 879
             return false;
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.
includes/class-sensei-grading-user-quiz.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 
42 42
 	/**
43 43
 	 * Display output to the admin view
44
-     *
45
-     * This view is shown when grading a quiz for a single user in admin under grading
46
-     *
44
+	 *
45
+	 * This view is shown when grading a quiz for a single user in admin under grading
46
+	 *
47 47
 	 * @since  1.3.0
48 48
 	 * @return html
49 49
 	 */
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
 		$user_quiz_grade_total = 0;
58 58
 		$quiz_grade_total = 0;
59 59
 		$quiz_grade = 0;
60
-        $lesson_id = $this->lesson_id;
61
-        $user_id = $this->user_id;
60
+		$lesson_id = $this->lesson_id;
61
+		$user_id = $this->user_id;
62 62
 
63 63
 		?><form name="<?php esc_attr_e( 'quiz_' . $this->quiz_id ); ?>" action="" method="post">
64 64
 			<?php wp_nonce_field( 'sensei_manual_grading', '_wp_sensei_manual_grading_nonce' ); ?>
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
 						<p class="user-answer"><?php
207 207
 							foreach ( $user_answer_content as $_user_answer ) {
208 208
 
209
-                                if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){
209
+								if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){
210 210
 
211
-                                    $_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) );
211
+									$_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) );
212 212
 
213
-                                }
213
+								}
214 214
 
215 215
 								echo apply_filters( 'sensei_answer_text', $_user_answer ) . "<br>";
216 216
 							}
Please login to merge, or discard this patch.
Braces   +5 added lines, -3 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 Grading User Quiz Class
@@ -172,8 +175,7 @@  discard block
 block discarded – undo
172 175
 				++$correct_answers;
173 176
 				++$graded_count;
174 177
 				$user_question_grade = 0;
175
-			}
176
-			elseif( intval( $user_question_grade ) > 0 ) {
178
+			} elseif( intval( $user_question_grade ) > 0 ) {
177 179
 				$graded_class = 'user_right';
178 180
 				++$correct_answers;
179 181
 				$user_quiz_grade_total += $user_question_grade;
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 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 Grading User Quiz Class
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
 	 * @since  1.3.0
23 23
 	 * @return  void
24 24
 	 */
25
-	public function __construct ( $user_id = 0, $quiz_id = 0 ) {
26
-		$this->user_id = intval( $user_id );
27
-		$this->quiz_id = intval( $quiz_id );
28
-		$this->lesson_id = get_post_meta( $this->quiz_id, '_quiz_lesson', true );
25
+	public function __construct($user_id = 0, $quiz_id = 0) {
26
+		$this->user_id = intval($user_id);
27
+		$this->quiz_id = intval($quiz_id);
28
+		$this->lesson_id = get_post_meta($this->quiz_id, '_quiz_lesson', true);
29 29
 	} // End __construct()
30 30
 
31 31
 	/**
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	 * @return array
36 36
 	 */
37 37
 	public function build_data_array() {
38
-		$data_array = Sensei_Utils::sensei_get_quiz_questions( $this->quiz_id );
38
+		$data_array = Sensei_Utils::sensei_get_quiz_questions($this->quiz_id);
39 39
 		return $data_array;
40 40
 	} // End build_data_array()
41 41
 
@@ -60,94 +60,94 @@  discard block
 block discarded – undo
60 60
         $lesson_id = $this->lesson_id;
61 61
         $user_id = $this->user_id;
62 62
 
63
-		?><form name="<?php esc_attr_e( 'quiz_' . $this->quiz_id ); ?>" action="" method="post">
64
-			<?php wp_nonce_field( 'sensei_manual_grading', '_wp_sensei_manual_grading_nonce' ); ?>
65
-			<input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e( $this->quiz_id ); ?>" />
66
-			<input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e( $this->user_id ); ?>" />
63
+		?><form name="<?php esc_attr_e('quiz_'.$this->quiz_id); ?>" action="" method="post">
64
+			<?php wp_nonce_field('sensei_manual_grading', '_wp_sensei_manual_grading_nonce'); ?>
65
+			<input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e($this->quiz_id); ?>" />
66
+			<input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e($this->user_id); ?>" />
67 67
 			<div class="total_grade_display">
68
-				<span><?php esc_attr_e( __( 'Grade:', 'woothemes-sensei' ) ); ?></span>
68
+				<span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?></span>
69 69
 				<span class="total_grade_total"><?php echo $user_quiz_grade_total; ?></span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?></span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?></span>%)
70 70
 			</div>
71 71
 			<div class="buttons">
72
-				<input type="submit" value="<?php esc_attr_e( __( 'Save', 'woothemes-sensei' ) ); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" />
73
-				<input type="button" value="<?php esc_attr_e( __( 'Auto grade', 'woothemes-sensei' ) ); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" />
74
-				<input type="reset" value="<?php esc_attr_e( __( 'Reset', 'woothemes-sensei' ) ); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" />
72
+				<input type="submit" value="<?php esc_attr_e(__('Save', 'woothemes-sensei')); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" />
73
+				<input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" />
74
+				<input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" />
75 75
 			</div>
76 76
 			<div class="clear"></div><br/><?php
77 77
 
78
-		$lesson_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID' ) );
79
-		$user_quiz_grade = get_comment_meta( $lesson_status_id, 'grade', true );
78
+		$lesson_status_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID'));
79
+		$user_quiz_grade = get_comment_meta($lesson_status_id, 'grade', true);
80 80
 		$correct_answers = 0;
81 81
 
82
-		foreach( $questions as $question ) {
82
+		foreach ($questions as $question) {
83 83
 			$question_id = $question->ID;
84 84
 			++$count;
85 85
 
86 86
 			$type = false;
87 87
 			$type_name = '';
88 88
 
89
-			$type = Sensei()->question->get_question_type( $question_id );
89
+			$type = Sensei()->question->get_question_type($question_id);
90 90
 
91
-			$question_answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $user_id );
91
+			$question_answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $user_id);
92 92
 
93 93
 
94
-			$question_grade_total = Sensei()->question->get_question_grade( $question_id );
94
+			$question_grade_total = Sensei()->question->get_question_grade($question_id);
95 95
 			$quiz_grade_total += $question_grade_total;
96 96
 
97
-			$right_answer = get_post_meta( $question_id, '_question_right_answer', true );
98
-			$user_answer_content = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id, $user_id );
99
-			$type_name = __( 'Multiple Choice', 'woothemes-sensei' );
97
+			$right_answer = get_post_meta($question_id, '_question_right_answer', true);
98
+			$user_answer_content = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, $user_id);
99
+			$type_name = __('Multiple Choice', 'woothemes-sensei');
100 100
 			$grade_type = 'manual-grade';
101 101
 
102
-			switch( $type ) {
102
+			switch ($type) {
103 103
 				case 'boolean':
104
-					$type_name = __( 'True/False', 'woothemes-sensei' );
105
-					$right_answer = ucfirst( $right_answer );
106
-					$user_answer_content = ucfirst( $user_answer_content );
104
+					$type_name = __('True/False', 'woothemes-sensei');
105
+					$right_answer = ucfirst($right_answer);
106
+					$user_answer_content = ucfirst($user_answer_content);
107 107
 					$grade_type = 'auto-grade';
108 108
 				break;
109 109
 				case 'multiple-choice':
110
-					$type_name = __( 'Multiple Choice', 'woothemes-sensei' );
110
+					$type_name = __('Multiple Choice', 'woothemes-sensei');
111 111
 					$grade_type = 'auto-grade';
112 112
 				break;
113 113
 				case 'gap-fill':
114
-					$type_name = __( 'Gap Fill', 'woothemes-sensei' );
114
+					$type_name = __('Gap Fill', 'woothemes-sensei');
115 115
 
116
-					$right_answer_array = explode( '||', $right_answer );
117
-					if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
118
-					if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
119
-					if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
116
+					$right_answer_array = explode('||', $right_answer);
117
+					if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; }
118
+					if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; }
119
+					if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; }
120 120
 
121
-					if( ! $user_answer_content ) {
121
+					if ( ! $user_answer_content) {
122 122
 						$user_answer_content = '______';
123 123
 					}
124 124
 
125
-					$right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post;
126
-					$user_answer_content = $gapfill_pre . ' <span class="highlight">' . $user_answer_content . '</span> ' . $gapfill_post;
125
+					$right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post;
126
+					$user_answer_content = $gapfill_pre.' <span class="highlight">'.$user_answer_content.'</span> '.$gapfill_post;
127 127
 					$grade_type = 'auto-grade';
128 128
 
129 129
 				break;
130 130
 				case 'multi-line':
131
-					$type_name = __( 'Multi Line', 'woothemes-sensei' );
131
+					$type_name = __('Multi Line', 'woothemes-sensei');
132 132
 					$grade_type = 'manual-grade';
133 133
 				break;
134 134
 				case 'single-line':
135
-					$type_name = __( 'Single Line', 'woothemes-sensei' );
135
+					$type_name = __('Single Line', 'woothemes-sensei');
136 136
 					$grade_type = 'manual-grade';
137 137
 				break;
138 138
 				case 'file-upload':
139
-					$type_name = __( 'File Upload', 'woothemes-sensei' );
139
+					$type_name = __('File Upload', 'woothemes-sensei');
140 140
 					$grade_type = 'manual-grade';
141 141
 
142 142
 					// Get uploaded file
143
-					if( $user_answer_content ) {
143
+					if ($user_answer_content) {
144 144
 						$attachment_id = $user_answer_content;
145 145
 						$answer_media_url = $answer_media_filename = '';
146
-						if( 0 < intval( $attachment_id ) ) {
147
-							$answer_media_url = wp_get_attachment_url( $attachment_id );
148
-							$answer_media_filename = basename( $answer_media_url );
149
-							if( $answer_media_url && $answer_media_filename ) {
150
-								$user_answer_content = sprintf( __( 'Submitted file: %1$s', 'woothemes-sensei' ), '<a href="' . esc_url( $answer_media_url ) . '" target="_blank">' . esc_html( $answer_media_filename ) . '</a>' );
146
+						if (0 < intval($attachment_id)) {
147
+							$answer_media_url = wp_get_attachment_url($attachment_id);
148
+							$answer_media_filename = basename($answer_media_url);
149
+							if ($answer_media_url && $answer_media_filename) {
150
+								$user_answer_content = sprintf(__('Submitted file: %1$s', 'woothemes-sensei'), '<a href="'.esc_url($answer_media_url).'" target="_blank">'.esc_html($answer_media_filename).'</a>');
151 151
 							}
152 152
 						}
153 153
 					} else {
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 			}
161 161
 			$user_answer_content = (array) $user_answer_content;
162 162
 			$right_answer = (array) $right_answer;
163
-			$question_title = sprintf( __( 'Question %d: ', 'woothemes-sensei' ), $count ) . $type_name;
163
+			$question_title = sprintf(__('Question %d: ', 'woothemes-sensei'), $count).$type_name;
164 164
 
165 165
 			$graded_class = '';
166
-			$user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, $user_id );
166
+			$user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, $user_id);
167 167
 			$graded_class = 'ungraded';
168
-			if ( 0 == $question_grade_total && 0 == intval( $user_question_grade ) ) {
168
+			if (0 == $question_grade_total && 0 == intval($user_question_grade)) {
169 169
 				// Question skips grading
170 170
 				$grade_type = 'zero-graded';
171 171
 				$graded_class = '';
@@ -173,86 +173,86 @@  discard block
 block discarded – undo
173 173
 				++$graded_count;
174 174
 				$user_question_grade = 0;
175 175
 			}
176
-			elseif( intval( $user_question_grade ) > 0 ) {
176
+			elseif (intval($user_question_grade) > 0) {
177 177
 				$graded_class = 'user_right';
178 178
 				++$correct_answers;
179 179
 				$user_quiz_grade_total += $user_question_grade;
180 180
 				++$graded_count;
181 181
 			} else {
182
-				if( ! is_string( $user_question_grade ) && intval( $user_question_grade ) == 0 ) {
182
+				if ( ! is_string($user_question_grade) && intval($user_question_grade) == 0) {
183 183
 					$graded_class = 'user_wrong';
184 184
 					++$graded_count;
185 185
 				}
186 186
 				$user_question_grade = 0;
187 187
 			}
188 188
 
189
-			?><div class="postbox question_box <?php esc_attr_e( $type ); ?> <?php esc_attr_e( $grade_type ); ?> <?php esc_attr_e( $graded_class ); ?>" id="<?php esc_attr_e( 'question_' . $question_id . '_box' ); ?>">
189
+			?><div class="postbox question_box <?php esc_attr_e($type); ?> <?php esc_attr_e($grade_type); ?> <?php esc_attr_e($graded_class); ?>" id="<?php esc_attr_e('question_'.$question_id.'_box'); ?>">
190 190
 				<div class="handlediv" title="Click to toggle"><br></div>
191 191
 				<h3 class="hndle"><span><?php echo $question_title; ?></span></h3>
192 192
 				<div class="inside">
193 193
 					<div class="sensei-grading-actions">
194 194
 						<div class="actions">
195
-							<input type="hidden" class="question_id" value="<?php esc_attr_e( $question_id ); ?>" />
196
-							<input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo esc_attr( $question_grade_total ); ?>" />
197
-							<span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e( 'question_' . $question_id . '_right_option' ); ?>" name="<?php esc_attr_e( 'question_' . $question_id ); ?>" value="right" <?php checked( $graded_class, 'user_right', true ); ?> /></span>
198
-							<span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e( 'question_' . $question_id . '_wrong_option' ); ?>" name="<?php esc_attr_e( 'question_' . $question_id ); ?>" value="wrong" <?php checked( $graded_class, 'user_wrong', true ); ?> /></span>
199
-							<input type="number" class="question-grade" name="<?php esc_attr_e( 'question_' . $question_id . '_grade' ); ?>" id="<?php esc_attr_e( 'question_' . $question_id . '_grade' ); ?>" value="<?php echo esc_attr( $user_question_grade ); ?>" min="0" max="<?php echo esc_attr( $question_grade_total ); ?>" />
195
+							<input type="hidden" class="question_id" value="<?php esc_attr_e($question_id); ?>" />
196
+							<input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo esc_attr($question_grade_total); ?>" />
197
+							<span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e('question_'.$question_id.'_right_option'); ?>" name="<?php esc_attr_e('question_'.$question_id); ?>" value="right" <?php checked($graded_class, 'user_right', true); ?> /></span>
198
+							<span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e('question_'.$question_id.'_wrong_option'); ?>" name="<?php esc_attr_e('question_'.$question_id); ?>" value="wrong" <?php checked($graded_class, 'user_wrong', true); ?> /></span>
199
+							<input type="number" class="question-grade" name="<?php esc_attr_e('question_'.$question_id.'_grade'); ?>" id="<?php esc_attr_e('question_'.$question_id.'_grade'); ?>" value="<?php echo esc_attr($user_question_grade); ?>" min="0" max="<?php echo esc_attr($question_grade_total); ?>" />
200 200
 							<span class="question-grade-total"><?php echo $question_grade_total; ?></span>
201 201
 						</div>
202 202
 					</div>
203 203
 					<div class="sensei-grading-answer">
204
-						<h4><?php echo apply_filters( 'sensei_question_title', $question->post_title ); ?></h4>
205
-						<?php echo apply_filters( 'the_content', $question->post_content );?>
204
+						<h4><?php echo apply_filters('sensei_question_title', $question->post_title); ?></h4>
205
+						<?php echo apply_filters('the_content', $question->post_content); ?>
206 206
 						<p class="user-answer"><?php
207
-							foreach ( $user_answer_content as $_user_answer ) {
207
+							foreach ($user_answer_content as $_user_answer) {
208 208
 
209
-                                if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){
209
+                                if ('multi-line' == Sensei()->question->get_question_type($question->ID)) {
210 210
 
211
-                                    $_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) );
211
+                                    $_user_answer = htmlspecialchars_decode(nl2br(esc_html($_user_answer)));
212 212
 
213 213
                                 }
214 214
 
215
-								echo apply_filters( 'sensei_answer_text', $_user_answer ) . "<br>";
215
+								echo apply_filters('sensei_answer_text', $_user_answer)."<br>";
216 216
 							}
217 217
 						?></p>
218 218
 						<div class="right-answer">
219
-							<h5><?php _e( 'Correct answer', 'woothemes-sensei' ) ?></h5>
219
+							<h5><?php _e('Correct answer', 'woothemes-sensei') ?></h5>
220 220
 							<span class="correct-answer"><?php
221
-								foreach ( $right_answer as $_right_answer ) {
221
+								foreach ($right_answer as $_right_answer) {
222 222
 
223
-									echo apply_filters( 'sensei_answer_text', $_right_answer ) . "<br>";
223
+									echo apply_filters('sensei_answer_text', $_right_answer)."<br>";
224 224
 
225 225
 								}
226 226
 							?></span>
227 227
 						</div>
228 228
 						<div class="answer-notes">
229
-							<h5><?php _e( 'Grading Notes', 'woothemes-sensei' ) ?></h5>
230
-							<textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e( $question_id ); ?>]" placeholder="<?php _e( 'Add notes here...', 'woothemes-sensei' ) ?>"><?php echo $question_answer_notes; ?></textarea>
229
+							<h5><?php _e('Grading Notes', 'woothemes-sensei') ?></h5>
230
+							<textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e($question_id); ?>]" placeholder="<?php _e('Add notes here...', 'woothemes-sensei') ?>"><?php echo $question_answer_notes; ?></textarea>
231 231
 						</div>
232 232
 					</div>
233 233
 				</div>
234 234
 			</div><?php
235 235
 		}
236 236
 
237
-		$quiz_grade = intval( $user_quiz_grade );
237
+		$quiz_grade = intval($user_quiz_grade);
238 238
 		$all_graded = 'no';
239
-		if( intval( $count ) == intval( $graded_count ) ) {
239
+		if (intval($count) == intval($graded_count)) {
240 240
 			$all_graded = 'yes';
241 241
 		}
242 242
 
243
-		?>  <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e( $user_quiz_grade_total ); ?>" />
244
-			<input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e( $count ); ?>" />
245
-			<input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e( $quiz_grade_total ); ?>" />
246
-			<input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e( $graded_count ); ?>" />
247
-			<input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e( $all_graded ); ?>" />
243
+		?>  <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e($user_quiz_grade_total); ?>" />
244
+			<input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e($count); ?>" />
245
+			<input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e($quiz_grade_total); ?>" />
246
+			<input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e($graded_count); ?>" />
247
+			<input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e($all_graded); ?>" />
248 248
 			<div class="total_grade_display">
249
-				<span><?php esc_attr_e( __( 'Grade:', 'woothemes-sensei' ) ); ?></span>
249
+				<span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?></span>
250 250
 				<span class="total_grade_total"><?php echo $user_quiz_grade_total; ?></span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?></span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?></span>%)
251 251
 			</div>
252 252
 			<div class="buttons">
253
-				<input type="submit" value="<?php esc_attr_e( 'Save' ); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" />
254
-				<input type="button" value="<?php esc_attr_e( __( 'Auto grade', 'woothemes-sensei' ) ); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" />
255
-				<input type="reset" value="<?php esc_attr_e( __( 'Reset', 'woothemes-sensei' ) ); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" />
253
+				<input type="submit" value="<?php esc_attr_e('Save'); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" />
254
+				<input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" />
255
+				<input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" />
256 256
 			</div>
257 257
 			<div class="clear"></div>
258 258
 			<script type="text/javascript">
@@ -271,4 +271,4 @@  discard block
 block discarded – undo
271 271
  * for backward compatibility
272 272
  * @since 1.9.0
273 273
  */
274
-class WooThemes_Sensei_Grading_User_Quiz extends Sensei_Grading_User_Quiz{}
274
+class WooThemes_Sensei_Grading_User_Quiz extends Sensei_Grading_User_Quiz {}
Please login to merge, or discard this patch.
includes/class-sensei-grading-main.php 3 patches
Braces   +11 added lines, -15 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 Grading Overview List Table Class
@@ -155,8 +158,7 @@  discard block
 block discarded – undo
155 158
 
156 159
 		if( $this->lesson_id ) {
157 160
 			$activity_args['post_id'] = $this->lesson_id;
158
-		}
159
-		elseif( $this->course_id ) {
161
+		} elseif( $this->course_id ) {
160 162
 			// Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple
161 163
 			// post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 )
162 164
 			if ( version_compare($wp_version, '4.1', '>=') ) {
@@ -231,24 +233,19 @@  discard block
 block discarded – undo
231 233
 		if( 'complete' == $item->comment_approved ) {
232 234
 			$status_html = '<span class="graded">' . __( 'Completed', 'woothemes-sensei' ) . '</span>';
233 235
 			$grade =  __( 'No Grade', 'woothemes-sensei' );
234
-		}
235
-		elseif( 'graded' == $item->comment_approved ) {
236
+		} elseif( 'graded' == $item->comment_approved ) {
236 237
 			$status_html = '<span class="graded">' .  __( 'Graded', 'woothemes-sensei' )  . '</span>';
237 238
 			$grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%';
238
-		}
239
-		elseif( 'passed' == $item->comment_approved ) {
239
+		} elseif( 'passed' == $item->comment_approved ) {
240 240
 			$status_html = '<span class="passed">' .  __( 'Passed', 'woothemes-sensei' )  . '</span>';
241 241
 			$grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%';
242
-		}
243
-		elseif( 'failed' == $item->comment_approved ) {
242
+		} elseif( 'failed' == $item->comment_approved ) {
244 243
 			$status_html = '<span class="failed">' .  __( 'Failed', 'woothemes-sensei' )  . '</span>';
245 244
 			$grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%';
246
-		}
247
-		elseif( 'ungraded' == $item->comment_approved ) {
245
+		} elseif( 'ungraded' == $item->comment_approved ) {
248 246
 			$status_html = '<span class="ungraded">' .  __( 'Ungraded', 'woothemes-sensei' )  . '</span>';
249 247
 			$grade = __( 'N/A', 'woothemes-sensei' );
250
-		}
251
-		else {
248
+		} else {
252 249
 			$status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
253 250
 			$grade = __( 'N/A', 'woothemes-sensei' );
254 251
 		}
@@ -276,8 +273,7 @@  discard block
 block discarded – undo
276 273
 		$course_title = '';
277 274
 		if ( !empty($course_id) && version_compare($wp_version, '4.1', '>=') ) {
278 275
 			$course_title = '<a href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ) ) . '">' . get_the_title( $course_id ) . '</a>';
279
-		}
280
-		else if ( !empty($course_id) ) {
276
+		} else if ( !empty($course_id) ) {
281 277
 			$course_title = get_the_title( $course_id );
282 278
 		}
283 279
 		$lesson_title = '<a href="' . add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ) . '">' . get_the_title( $item->comment_post_ID ) . '</a>';
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Sensei_Grading_Main extends WooThemes_Sensei_List_Table {
12 12
 
13
-    public $user_id;
13
+	public $user_id;
14 14
 	public $course_id;
15 15
 	public $lesson_id;
16 16
 	public $view;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			$grade = __( 'N/A', 'woothemes-sensei' );
250 250
 		}
251 251
 
252
-        $title = Sensei_Learner::get_full_name( $item->user_id );
252
+		$title = Sensei_Learner::get_full_name( $item->user_id );
253 253
 
254 254
 		// QuizID to be deprecated
255 255
 		$quiz_id = get_post_meta( $item->comment_post_ID, '_lesson_quiz', true );
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 */
300 300
 	public function no_items() {
301 301
 
302
-        _e( 'No submissions found.', 'woothemes-sensei' );
302
+		_e( 'No submissions found.', 'woothemes-sensei' );
303 303
 
304 304
 	} // End no_items()
305 305
 
Please login to merge, or discard this patch.
Spacing   +130 added lines, -130 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
  * Admin Grading Overview Data Table in Sensei.
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	 * Constructor
22 22
 	 * @since  1.3.0
23 23
 	 */
24
-	public function __construct ( $args = null ) {
24
+	public function __construct($args = null) {
25 25
 
26 26
 		$defaults = array(
27 27
 			'course_id' => 0,
@@ -29,24 +29,24 @@  discard block
 block discarded – undo
29 29
 			'user_id' => false,
30 30
 			'view' => 'ungraded',
31 31
 		);
32
-		$args = wp_parse_args( $args, $defaults );
32
+		$args = wp_parse_args($args, $defaults);
33 33
 
34
-		$this->course_id = intval( $args['course_id'] );
35
-		$this->lesson_id = intval( $args['lesson_id'] );
36
-		if ( !empty($args['user_id']) ) {
37
-			$this->user_id = intval( $args['user_id'] );
34
+		$this->course_id = intval($args['course_id']);
35
+		$this->lesson_id = intval($args['lesson_id']);
36
+		if ( ! empty($args['user_id'])) {
37
+			$this->user_id = intval($args['user_id']);
38 38
 		}
39 39
 
40
-		if( !empty( $args['view'] ) && in_array( $args['view'], array( 'in-progress', 'graded', 'ungraded', 'all' ) ) ) {
40
+		if ( ! empty($args['view']) && in_array($args['view'], array('in-progress', 'graded', 'ungraded', 'all'))) {
41 41
 			$this->view = $args['view'];
42 42
 		}
43 43
 
44 44
 		// Load Parent token into constructor
45
-		parent::__construct( 'grading_main' );
45
+		parent::__construct('grading_main');
46 46
 
47 47
 		// Actions
48
-		add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) );
49
-		add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) );
48
+		add_action('sensei_before_list_table', array($this, 'data_table_header'));
49
+		add_action('sensei_after_list_table', array($this, 'data_table_footer'));
50 50
 	} // End __construct()
51 51
 
52 52
 	/**
@@ -56,16 +56,16 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	function get_columns() {
58 58
 		$columns = array(
59
-			'title' => __( 'Learner', 'woothemes-sensei' ),
60
-			'course' => __( 'Course', 'woothemes-sensei' ),
61
-			'lesson' => __( 'Lesson', 'woothemes-sensei' ),
62
-			'updated' => __( 'Updated', 'woothemes-sensei' ),
63
-			'user_status' => __( 'Status', 'woothemes-sensei' ),
64
-			'user_grade' => __( 'Grade', 'woothemes-sensei' ),
59
+			'title' => __('Learner', 'woothemes-sensei'),
60
+			'course' => __('Course', 'woothemes-sensei'),
61
+			'lesson' => __('Lesson', 'woothemes-sensei'),
62
+			'updated' => __('Updated', 'woothemes-sensei'),
63
+			'user_status' => __('Status', 'woothemes-sensei'),
64
+			'user_grade' => __('Grade', 'woothemes-sensei'),
65 65
 			'action' => '',
66 66
 		);
67 67
 
68
-		$columns = apply_filters( 'sensei_grading_default_columns', $columns, $this );
68
+		$columns = apply_filters('sensei_grading_default_columns', $columns, $this);
69 69
 		return $columns;
70 70
 	}
71 71
 
@@ -76,14 +76,14 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	function get_sortable_columns() {
78 78
 		$columns = array(
79
-			'title' => array( 'title', false ),
80
-			'course' => array( 'course', false ),
81
-			'lesson' => array( 'lesson', false ),
82
-			'updated' => array( 'updated', false ),
83
-			'user_status' => array( 'user_status', false ),
84
-			'user_grade' => array( 'user_grade', false ),
79
+			'title' => array('title', false),
80
+			'course' => array('course', false),
81
+			'lesson' => array('lesson', false),
82
+			'updated' => array('updated', false),
83
+			'user_status' => array('user_status', false),
84
+			'user_grade' => array('user_grade', false),
85 85
 		);
86
-		$columns = apply_filters( 'sensei_grading_default_columns_sortable', $columns, $this );
86
+		$columns = apply_filters('sensei_grading_default_columns_sortable', $columns, $this);
87 87
 		return $columns;
88 88
 	}
89 89
 
@@ -97,47 +97,47 @@  discard block
 block discarded – undo
97 97
 
98 98
 		// Handle orderby
99 99
 		$orderby = '';
100
-		if ( !empty( $_GET['orderby'] ) ) {
101
-			if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) {
102
-				$orderby = esc_html( $_GET['orderby'] );
100
+		if ( ! empty($_GET['orderby'])) {
101
+			if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) {
102
+				$orderby = esc_html($_GET['orderby']);
103 103
 			} // End If Statement
104 104
 		}
105 105
 
106 106
 		// Handle order
107 107
 		$order = 'DESC';
108
-		if ( !empty( $_GET['order'] ) ) {
109
-			$order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC';
108
+		if ( ! empty($_GET['order'])) {
109
+			$order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC';
110 110
 		}
111 111
 
112 112
 		// Handle search
113 113
 		$search = false;
114
-		if ( !empty( $_GET['s'] ) ) {
115
-			$search = esc_html( $_GET['s'] );
114
+		if ( ! empty($_GET['s'])) {
115
+			$search = esc_html($_GET['s']);
116 116
 		} // End If Statement
117 117
 		$this->search = $search;
118 118
 
119 119
 		// Searching users on statuses requires sub-selecting the statuses by user_ids
120
-		if ( $this->search ) {
120
+		if ($this->search) {
121 121
 			$user_args = array(
122
-				'search' => '*' . $this->search . '*',
122
+				'search' => '*'.$this->search.'*',
123 123
 				'fields' => 'ID',
124 124
 			);
125 125
 			// Filter for extending
126
-			$user_args = apply_filters( 'sensei_grading_search_users', $user_args );
127
-			if ( !empty( $user_args ) ) {
128
-				$learners_search = new WP_User_Query( $user_args );
126
+			$user_args = apply_filters('sensei_grading_search_users', $user_args);
127
+			if ( ! empty($user_args)) {
128
+				$learners_search = new WP_User_Query($user_args);
129 129
 				// Store for reuse on counts
130 130
 				$this->user_ids = $learners_search->get_results();
131 131
 			}
132 132
 		} // End If Statement
133 133
 
134
-		$per_page = $this->get_items_per_page( 'sensei_comments_per_page' );
135
-		$per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' );
134
+		$per_page = $this->get_items_per_page('sensei_comments_per_page');
135
+		$per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments');
136 136
 
137 137
 		$paged = $this->get_pagenum();
138 138
 		$offset = 0;
139
-		if ( !empty($paged) ) {
140
-			$offset = $per_page * ( $paged - 1 );
139
+		if ( ! empty($paged)) {
140
+			$offset = $per_page * ($paged - 1);
141 141
 		} // End If Statement
142 142
 
143 143
 		$activity_args = array(
@@ -149,27 +149,27 @@  discard block
 block discarded – undo
149 149
 			'status' => 'any',
150 150
 		);
151 151
 
152
-		if( $this->lesson_id ) {
152
+		if ($this->lesson_id) {
153 153
 			$activity_args['post_id'] = $this->lesson_id;
154 154
 		}
155
-		elseif( $this->course_id ) {
155
+		elseif ($this->course_id) {
156 156
 			// Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple
157 157
 			// post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 )
158
-			if ( version_compare($wp_version, '4.1', '>=') ) {
159
-				$activity_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' );
158
+			if (version_compare($wp_version, '4.1', '>=')) {
159
+				$activity_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids');
160 160
 			}
161 161
 		}
162 162
 		// Sub select to group of learners
163
-		if ( $this->user_ids ) {
163
+		if ($this->user_ids) {
164 164
 			$activity_args['user_id'] = (array) $this->user_ids;
165 165
 		}
166 166
 		// Restrict to a single Learner
167
-		if( $this->user_id ) {
167
+		if ($this->user_id) {
168 168
 			$activity_args['user_id'] = $this->user_id;
169 169
 		}
170 170
 
171 171
 
172
-		switch( $this->view ) {
172
+		switch ($this->view) {
173 173
 			case 'in-progress' :
174 174
 				$activity_args['status'] = 'in-progress';
175 175
 				break;
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 				break;
180 180
 
181 181
 			case 'graded' :
182
-				$activity_args['status'] = array( 'graded', 'passed', 'failed' );
182
+				$activity_args['status'] = array('graded', 'passed', 'failed');
183 183
 				break;
184 184
 
185 185
 			case 'all' :
@@ -188,31 +188,31 @@  discard block
 block discarded – undo
188 188
 				break;
189 189
 		} // End switch
190 190
 
191
-		$activity_args = apply_filters( 'sensei_grading_filter_statuses', $activity_args );
191
+		$activity_args = apply_filters('sensei_grading_filter_statuses', $activity_args);
192 192
 
193 193
 		// WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice
194
-		$total_statuses = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) );
194
+		$total_statuses = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0)));
195 195
 
196 196
 		// Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views?
197
-		if ( $total_statuses < $activity_args['offset'] ) {
198
-			$new_paged = floor( $total_statuses / $activity_args['number'] );
197
+		if ($total_statuses < $activity_args['offset']) {
198
+			$new_paged = floor($total_statuses / $activity_args['number']);
199 199
 			$activity_args['offset'] = $new_paged * $activity_args['number'];
200 200
 		}
201
-		$statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true );
201
+		$statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true);
202 202
 		// Need to always return an array, even with only 1 item
203
-		if ( !is_array($statuses) ) {
204
-			$statuses = array( $statuses );
203
+		if ( ! is_array($statuses)) {
204
+			$statuses = array($statuses);
205 205
 		}
206 206
 		$this->total_items = $total_statuses;
207 207
 		$this->items = $statuses;
208 208
 
209 209
 		$total_items = $this->total_items;
210
-		$total_pages = ceil( $total_items / $per_page );
211
-		$this->set_pagination_args( array(
210
+		$total_pages = ceil($total_items / $per_page);
211
+		$this->set_pagination_args(array(
212 212
 			'total_items' => $total_items,
213 213
 			'total_pages' => $total_pages,
214 214
 			'per_page' => $per_page
215
-		) );
215
+		));
216 216
 	}
217 217
 
218 218
 	/**
@@ -220,73 +220,73 @@  discard block
 block discarded – undo
220 220
 	 * @since  1.7.0
221 221
 	 * @param object $item The current item
222 222
 	 */
223
-	protected function get_row_data( $item ) {
223
+	protected function get_row_data($item) {
224 224
 		global $wp_version;
225 225
 
226 226
 		$grade = '';
227
-		if( 'complete' == $item->comment_approved ) {
228
-			$status_html = '<span class="graded">' . __( 'Completed', 'woothemes-sensei' ) . '</span>';
229
-			$grade =  __( 'No Grade', 'woothemes-sensei' );
227
+		if ('complete' == $item->comment_approved) {
228
+			$status_html = '<span class="graded">'.__('Completed', 'woothemes-sensei').'</span>';
229
+			$grade = __('No Grade', 'woothemes-sensei');
230 230
 		}
231
-		elseif( 'graded' == $item->comment_approved ) {
232
-			$status_html = '<span class="graded">' .  __( 'Graded', 'woothemes-sensei' )  . '</span>';
233
-			$grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%';
231
+		elseif ('graded' == $item->comment_approved) {
232
+			$status_html = '<span class="graded">'.__('Graded', 'woothemes-sensei').'</span>';
233
+			$grade = get_comment_meta($item->comment_ID, 'grade', true).'%';
234 234
 		}
235
-		elseif( 'passed' == $item->comment_approved ) {
236
-			$status_html = '<span class="passed">' .  __( 'Passed', 'woothemes-sensei' )  . '</span>';
237
-			$grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%';
235
+		elseif ('passed' == $item->comment_approved) {
236
+			$status_html = '<span class="passed">'.__('Passed', 'woothemes-sensei').'</span>';
237
+			$grade = get_comment_meta($item->comment_ID, 'grade', true).'%';
238 238
 		}
239
-		elseif( 'failed' == $item->comment_approved ) {
240
-			$status_html = '<span class="failed">' .  __( 'Failed', 'woothemes-sensei' )  . '</span>';
241
-			$grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%';
239
+		elseif ('failed' == $item->comment_approved) {
240
+			$status_html = '<span class="failed">'.__('Failed', 'woothemes-sensei').'</span>';
241
+			$grade = get_comment_meta($item->comment_ID, 'grade', true).'%';
242 242
 		}
243
-		elseif( 'ungraded' == $item->comment_approved ) {
244
-			$status_html = '<span class="ungraded">' .  __( 'Ungraded', 'woothemes-sensei' )  . '</span>';
245
-			$grade = __( 'N/A', 'woothemes-sensei' );
243
+		elseif ('ungraded' == $item->comment_approved) {
244
+			$status_html = '<span class="ungraded">'.__('Ungraded', 'woothemes-sensei').'</span>';
245
+			$grade = __('N/A', 'woothemes-sensei');
246 246
 		}
247 247
 		else {
248
-			$status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
249
-			$grade = __( 'N/A', 'woothemes-sensei' );
248
+			$status_html = '<span class="in-progress">'.__('In Progress', 'woothemes-sensei').'</span>';
249
+			$grade = __('N/A', 'woothemes-sensei');
250 250
 		}
251 251
 
252
-        $title = Sensei_Learner::get_full_name( $item->user_id );
252
+        $title = Sensei_Learner::get_full_name($item->user_id);
253 253
 
254 254
 		// QuizID to be deprecated
255
-		$quiz_id = get_post_meta( $item->comment_post_ID, '_lesson_quiz', true );
256
-		$quiz_link = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id ), admin_url( 'admin.php' ) ) );
255
+		$quiz_id = get_post_meta($item->comment_post_ID, '_lesson_quiz', true);
256
+		$quiz_link = esc_url(add_query_arg(array('page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id), admin_url('admin.php')));
257 257
 
258 258
 		$grade_link = '';
259
-		switch( $item->comment_approved ) {
259
+		switch ($item->comment_approved) {
260 260
 			case 'ungraded':
261
-				$grade_link = '<a class="button-primary button" href="' . $quiz_link . '">' . __('Grade quiz', 'woothemes-sensei' ) . '</a>';
261
+				$grade_link = '<a class="button-primary button" href="'.$quiz_link.'">'.__('Grade quiz', 'woothemes-sensei').'</a>';
262 262
 				break;
263 263
 
264 264
 			case 'graded':
265 265
 			case 'passed':
266 266
 			case 'failed':
267
-				$grade_link = '<a class="button-secondary button" href="' . $quiz_link . '">' . __('Review grade', 'woothemes-sensei' ) . '</a>';
267
+				$grade_link = '<a class="button-secondary button" href="'.$quiz_link.'">'.__('Review grade', 'woothemes-sensei').'</a>';
268 268
 				break;
269 269
 		}
270 270
 
271
-		$course_id = get_post_meta( $item->comment_post_ID, '_lesson_course', true );
271
+		$course_id = get_post_meta($item->comment_post_ID, '_lesson_course', true);
272 272
 		$course_title = '';
273
-		if ( !empty($course_id) && version_compare($wp_version, '4.1', '>=') ) {
274
-			$course_title = '<a href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ) ) . '">' . get_the_title( $course_id ) . '</a>';
273
+		if ( ! empty($course_id) && version_compare($wp_version, '4.1', '>=')) {
274
+			$course_title = '<a href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'))).'">'.get_the_title($course_id).'</a>';
275 275
 		}
276
-		else if ( !empty($course_id) ) {
277
-			$course_title = get_the_title( $course_id );
276
+		else if ( ! empty($course_id)) {
277
+			$course_title = get_the_title($course_id);
278 278
 		}
279
-		$lesson_title = '<a href="' . add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ) . '">' . get_the_title( $item->comment_post_ID ) . '</a>';
279
+		$lesson_title = '<a href="'.add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID), admin_url('admin.php')).'">'.get_the_title($item->comment_post_ID).'</a>';
280 280
 
281
-		$column_data = apply_filters( 'sensei_grading_main_column_data', array(
282
-				'title' => '<strong><a class="row-title" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->user_id ), admin_url( 'admin.php' ) ) ) . '"">' . $title . '</a></strong>',
281
+		$column_data = apply_filters('sensei_grading_main_column_data', array(
282
+				'title' => '<strong><a class="row-title" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id), admin_url('admin.php'))).'"">'.$title.'</a></strong>',
283 283
 				'course' => $course_title,
284 284
 				'lesson' => $lesson_title,
285 285
 				'updated' => $item->comment_date,
286 286
 				'user_status' => $status_html,
287 287
 				'user_grade' => $grade,
288 288
 				'action' => $grade_link,
289
-			), $item, $course_id );
289
+			), $item, $course_id);
290 290
 
291 291
 		return $column_data;
292 292
 	}
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 */
300 300
 	public function no_items() {
301 301
 
302
-        _e( 'No submissions found.', 'woothemes-sensei' );
302
+        _e('No submissions found.', 'woothemes-sensei');
303 303
 
304 304
 	} // End no_items()
305 305
 
@@ -312,35 +312,35 @@  discard block
 block discarded – undo
312 312
 		global  $wp_version;
313 313
 
314 314
 		echo '<div class="grading-selects">';
315
-		do_action( 'sensei_grading_before_dropdown_filters' );
315
+		do_action('sensei_grading_before_dropdown_filters');
316 316
 
317
-		echo '<div class="select-box">' . "\n";
317
+		echo '<div class="select-box">'."\n";
318 318
 
319
-			echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">' . "\n";
319
+			echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">'."\n";
320 320
 
321
-				echo Sensei()->grading->courses_drop_down_html( $this->course_id );
321
+				echo Sensei()->grading->courses_drop_down_html($this->course_id);
322 322
 
323
-			echo '</select>' . "\n";
323
+			echo '</select>'."\n";
324 324
 
325
-		echo '</div>' . "\n";
325
+		echo '</div>'."\n";
326 326
 
327
-		echo '<div class="select-box">' . "\n";
327
+		echo '<div class="select-box">'."\n";
328 328
 
329
-			echo '<select id="grading-lesson-options" data-placeholder="&larr; ' . __( 'Select a course', 'woothemes-sensei' ) . '" name="grading_lesson" class="chosen_select widefat">' . "\n";
329
+			echo '<select id="grading-lesson-options" data-placeholder="&larr; '.__('Select a course', 'woothemes-sensei').'" name="grading_lesson" class="chosen_select widefat">'."\n";
330 330
 
331
-				echo Sensei()->grading->lessons_drop_down_html( $this->course_id, $this->lesson_id );
331
+				echo Sensei()->grading->lessons_drop_down_html($this->course_id, $this->lesson_id);
332 332
 
333
-			echo '</select>' . "\n";
333
+			echo '</select>'."\n";
334 334
 
335
-		echo '</div>' . "\n";
335
+		echo '</div>'."\n";
336 336
 
337
-		if( $this->course_id && $this->lesson_id ) {
337
+		if ($this->course_id && $this->lesson_id) {
338 338
 
339
-			echo '<div class="select-box reset-filter">' . "\n";
339
+			echo '<div class="select-box reset-filter">'."\n";
340 340
 
341
-				echo '<a class="button-secondary" href="' . esc_url( remove_query_arg( array( 'lesson_id', 'course_id' ) ) ) . '">' . __( 'Reset filter', 'woothemes-sensei' ) . '</a>' . "\n";
341
+				echo '<a class="button-secondary" href="'.esc_url(remove_query_arg(array('lesson_id', 'course_id'))).'">'.__('Reset filter', 'woothemes-sensei').'</a>'."\n";
342 342
 
343
-			echo '</div>' . "\n";
343
+			echo '</div>'."\n";
344 344
 
345 345
 		}
346 346
 
@@ -355,26 +355,26 @@  discard block
 block discarded – undo
355 355
 		$query_args = array(
356 356
 			'page' => $this->page_slug,
357 357
 		);
358
-		if( $this->course_id ) {
358
+		if ($this->course_id) {
359 359
 			// Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple
360 360
 			// post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 )
361 361
 			$query_args['course_id'] = $this->course_id;
362
-			if ( version_compare($wp_version, '4.1', '>=') ) {
363
-				$count_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' );
362
+			if (version_compare($wp_version, '4.1', '>=')) {
363
+				$count_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids');
364 364
 			}
365 365
 		}
366
-		if( $this->lesson_id ) {
366
+		if ($this->lesson_id) {
367 367
 			$query_args['lesson_id'] = $this->lesson_id;
368 368
 			// Restrict to a single lesson
369 369
 			$count_args['post_id'] = $this->lesson_id;
370 370
 		}
371
-		if( $this->search ) {
371
+		if ($this->search) {
372 372
 			$query_args['s'] = $this->search;
373 373
 		}
374
-		if ( !empty($this->user_ids) ) {
374
+		if ( ! empty($this->user_ids)) {
375 375
 			$count_args['user_id'] = $this->user_ids;
376 376
 		}
377
-		if( !empty($this->user_id) ) {
377
+		if ( ! empty($this->user_id)) {
378 378
 			$query_args['user_id'] = $this->user_id;
379 379
 			$count_args['user_id'] = $this->user_id;
380 380
 		}
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 		$all_lessons_count = $ungraded_lessons_count = $graded_lessons_count = $inprogress_lessons_count = 0;
383 383
 		$all_class = $ungraded_class = $graded_class = $inprogress_class = '';
384 384
 
385
-		switch( $this->view ) :
385
+		switch ($this->view) :
386 386
 			case 'all':
387 387
 				$all_class = 'current';
388 388
 				break;
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 				break;
399 399
 		endswitch;
400 400
 
401
-		$counts = Sensei()->grading->count_statuses( apply_filters( 'sensei_grading_count_statues', $count_args ) );
401
+		$counts = Sensei()->grading->count_statuses(apply_filters('sensei_grading_count_statues', $count_args));
402 402
 
403 403
 		$inprogress_lessons_count = $counts['in-progress'];
404 404
 		$ungraded_lessons_count = $counts['ungraded'];
@@ -414,19 +414,19 @@  discard block
 block discarded – undo
414 414
 		$inprogress_args['view'] = 'in-progress';
415 415
 
416 416
 		$format = '<a class="%s" href="%s">%s <span class="count">(%s)</span></a>';
417
-		$menu['all'] = sprintf( $format, $all_class, esc_url( add_query_arg( $all_args, admin_url( 'admin.php' ) ) ), __( 'All', 'woothemes-sensei' ), number_format( (int) $all_lessons_count ) );
418
-		$menu['ungraded'] = sprintf( $format, $ungraded_class, esc_url( add_query_arg( $ungraded_args, admin_url( 'admin.php' ) ) ), __( 'Ungraded', 'woothemes-sensei' ), number_format( (int) $ungraded_lessons_count ) );
419
-		$menu['graded'] = sprintf( $format, $graded_class, esc_url( add_query_arg( $graded_args, admin_url( 'admin.php' ) ) ), __( 'Graded', 'woothemes-sensei' ), number_format( (int) $graded_lessons_count ) );
420
-		$menu['in-progress'] = sprintf( $format, $inprogress_class, esc_url( add_query_arg( $inprogress_args, admin_url( 'admin.php' ) ) ), __( 'In Progress', 'woothemes-sensei' ), number_format( (int) $inprogress_lessons_count ) );
421
-
422
-		$menu = apply_filters( 'sensei_grading_sub_menu', $menu );
423
-		if ( !empty($menu) ) {
424
-			echo '<ul class="subsubsub">' . "\n";
425
-			foreach ( $menu as $class => $item ) {
426
-				$menu[ $class ] = "\t<li class='$class'>$item";
417
+		$menu['all'] = sprintf($format, $all_class, esc_url(add_query_arg($all_args, admin_url('admin.php'))), __('All', 'woothemes-sensei'), number_format((int) $all_lessons_count));
418
+		$menu['ungraded'] = sprintf($format, $ungraded_class, esc_url(add_query_arg($ungraded_args, admin_url('admin.php'))), __('Ungraded', 'woothemes-sensei'), number_format((int) $ungraded_lessons_count));
419
+		$menu['graded'] = sprintf($format, $graded_class, esc_url(add_query_arg($graded_args, admin_url('admin.php'))), __('Graded', 'woothemes-sensei'), number_format((int) $graded_lessons_count));
420
+		$menu['in-progress'] = sprintf($format, $inprogress_class, esc_url(add_query_arg($inprogress_args, admin_url('admin.php'))), __('In Progress', 'woothemes-sensei'), number_format((int) $inprogress_lessons_count));
421
+
422
+		$menu = apply_filters('sensei_grading_sub_menu', $menu);
423
+		if ( ! empty($menu)) {
424
+			echo '<ul class="subsubsub">'."\n";
425
+			foreach ($menu as $class => $item) {
426
+				$menu[$class] = "\t<li class='$class'>$item";
427 427
 			}
428
-			echo implode( " |</li>\n", $menu ) . "</li>\n";
429
-			echo '</ul>' . "\n";
428
+			echo implode(" |</li>\n", $menu)."</li>\n";
429
+			echo '</ul>'."\n";
430 430
 		}
431 431
 
432 432
 	} // End data_table_header()
@@ -447,4 +447,4 @@  discard block
 block discarded – undo
447 447
  * @ignore only for backward compatibility
448 448
  * @since 1.9.0
449 449
  */
450
-class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main{}
450
+class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main {}
Please login to merge, or discard this patch.
includes/class-sensei-autoloader.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, don't load file outside WP
2
+if ( ! defined( 'ABSPATH' ) ) {
3
+	exit;
4
+}
5
+// security check, don't load file outside WP
3 6
 /**
4 7
  * Sensei Autoloader Class
5 8
  *
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, don't load file outside WP
2
+if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP
3 3
 /**
4 4
  * Sensei Autoloader Class
5 5
  *
@@ -27,21 +27,21 @@  discard block
 block discarded – undo
27 27
      * Constructor
28 28
      * @since 1.9.0
29 29
      */
30
-    public function __construct(){
30
+    public function __construct() {
31 31
 
32 32
         // make sure we do not override an existing autoload function
33
-        if( function_exists('__autoload') ){
34
-           spl_autoload_register( '__autoload' );
33
+        if (function_exists('__autoload')) {
34
+           spl_autoload_register('__autoload');
35 35
         }
36 36
 
37 37
         // setup a relative path for the current autoload instance
38
-        $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) );
38
+        $this->include_path = trailingslashit(untrailingslashit(dirname(__FILE__)));
39 39
 
40 40
         //setup the class file map
41 41
         $this->initialize_class_file_map();
42 42
 
43 43
         // add Sensei custom auto loader
44
-        spl_autoload_register( array( $this, 'autoload' )  );
44
+        spl_autoload_register(array($this, 'autoload'));
45 45
 
46 46
     }
47 47
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      *
52 52
      * @since 1.9.0
53 53
      */
54
-    public function initialize_class_file_map(){
54
+    public function initialize_class_file_map() {
55 55
 
56 56
         $this->class_file_map = array(
57 57
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
             /**
64 64
              * Admin
65 65
              */
66
-            'Sensei_Welcome'            => 'admin/class-sensei-welcome.php' ,
67
-            'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' ,
66
+            'Sensei_Welcome'            => 'admin/class-sensei-welcome.php',
67
+            'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php',
68 68
 
69 69
             /**
70 70
              * Shortcodes
@@ -93,38 +93,38 @@  discard block
 block discarded – undo
93 93
     /**
94 94
      * Autoload all sensei files as the class names are used.
95 95
      */
96
-    public function autoload( $class ){
96
+    public function autoload($class) {
97 97
 
98 98
         // only handle classes with the word `sensei` in it
99
-        if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){
99
+        if ( ! is_numeric(strpos(strtolower($class), 'sensei'))) {
100 100
 
101 101
             return;
102 102
 
103 103
         }
104 104
 
105 105
         // exit if we didn't provide mapping for this class
106
-        if( isset( $this->class_file_map[ $class ] ) ){
106
+        if (isset($this->class_file_map[$class])) {
107 107
 
108
-            $file_location = $this->include_path . $this->class_file_map[ $class ];
109
-            require_once( $file_location);
108
+            $file_location = $this->include_path.$this->class_file_map[$class];
109
+            require_once($file_location);
110 110
             return;
111 111
 
112 112
         }
113 113
 
114 114
         // check for file in the main includes directory
115
-        $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php';
116
-        if( file_exists( $class_file_path ) ){
115
+        $class_file_path = $this->include_path.'class-'.str_replace('_', '-', strtolower($class)).'.php';
116
+        if (file_exists($class_file_path)) {
117 117
 
118
-            require_once( $class_file_path );
118
+            require_once($class_file_path);
119 119
             return;
120 120
         }
121 121
 
122 122
         // lastly check legacy types
123
-        $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes
124
-        $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php';
125
-        if( file_exists( $legacy_class_file_path ) ){
123
+        $stripped_woothemes_from_class = str_replace('woothemes_', '', strtolower($class)); // remove woothemes
124
+        $legacy_class_file_path = $this->include_path.'class-'.str_replace('_', '-', strtolower($stripped_woothemes_from_class)).'.php';
125
+        if (file_exists($legacy_class_file_path)) {
126 126
 
127
-            require_once( $legacy_class_file_path );
127
+            require_once($legacy_class_file_path);
128 128
             return;
129 129
         }
130 130
 
Please login to merge, or discard this patch.
Indentation   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -13,137 +13,137 @@
 block discarded – undo
13 13
  */
14 14
 class Sensei_Autoloader {
15 15
 
16
-    /**
17
-     * @var path to the includes directory within Sensei.
18
-     */
19
-    private $include_path = 'includes';
20
-
21
-    /**
22
-     * @var array $class_file_map. List of classes mapped to their files
23
-     */
24
-    private $class_file_map = array();
25
-
26
-    /**
27
-     * Constructor
28
-     * @since 1.9.0
29
-     */
30
-    public function __construct(){
31
-
32
-        // make sure we do not override an existing autoload function
33
-        if( function_exists('__autoload') ){
34
-           spl_autoload_register( '__autoload' );
35
-        }
36
-
37
-        // setup a relative path for the current autoload instance
38
-        $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) );
39
-
40
-        //setup the class file map
41
-        $this->initialize_class_file_map();
42
-
43
-        // add Sensei custom auto loader
44
-        spl_autoload_register( array( $this, 'autoload' )  );
45
-
46
-    }
47
-
48
-    /**
49
-     * Generate a list of Sensei class and map them the their respective
50
-     * files within the includes directory
51
-     *
52
-     * @since 1.9.0
53
-     */
54
-    public function initialize_class_file_map(){
55
-
56
-        $this->class_file_map = array(
57
-
58
-            /**
59
-             * Main Sensei class
60
-             */
61
-            'Sensei_Main' => 'class-sensei.php',
62
-
63
-            /**
64
-             * Admin
65
-             */
66
-            'Sensei_Welcome'            => 'admin/class-sensei-welcome.php' ,
67
-            'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' ,
68
-
69
-            /**
70
-             * Shortcodes
71
-             */
72
-            'Sensei_Shortcode_Loader'              => 'shortcodes/class-sensei-shortcode-loader.php',
73
-            'Sensei_Shortcode_Interface'           => 'shortcodes/interface-sensei-shortcode.php',
74
-            'Sensei_Shortcode_Featured_Courses'    => 'shortcodes/class-sensei-shortcode-featured-courses.php',
75
-            'Sensei_Shortcode_User_Courses'        => 'shortcodes/class-sensei-shortcode-user-courses.php',
76
-            'Sensei_Shortcode_Courses'             => 'shortcodes/class-sensei-shortcode-courses.php',
77
-            'Sensei_Shortcode_Teachers'            => 'shortcodes/class-sensei-shortcode-teachers.php',
78
-            'Sensei_Shortcode_User_Messages'       => 'shortcodes/class-sensei-shortcode-user-messages.php',
79
-            'Sensei_Shortcode_Course_Page'         => 'shortcodes/class-sensei-shortcode-course-page.php',
80
-            'Sensei_Shortcode_Lesson_Page'         => 'shortcodes/class-sensei-shortcode-lesson-page.php',
81
-            'Sensei_Shortcode_Course_Categories'   => 'shortcodes/class-sensei-shortcode-course-categories.php',
82
-            'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php',
83
-            'Sensei_Legacy_Shortcodes'             => 'shortcodes/class-sensei-legacy-shortcodes.php',
84
-
85
-            /**
86
-             * Built in theme integration support
87
-             */
88
-            'Sensei_Theme_Integration_Loader' => 'theme-integrations/theme-integration-loader.php',
89
-            'Sensei__S'                       => 'theme-integrations/_s.php',
90
-            'Sensei_Twentyeleven'             => 'theme-integrations/twentyeleven.php',
91
-            'Sensei_Twentytwelve'             => 'theme-integrations/twentytwelve.php',
92
-            'Sensei_Twentythirteen'           => 'theme-integrations/Twentythirteen.php',
93
-            'Sensei_Twentyfourteen'           => 'theme-integrations/Twentyfourteen.php',
94
-            'Sensei_Twentyfifteen'            => 'theme-integrations/Twentyfifteen.php',
95
-            'Sensei_Twentysixteen'            => 'theme-integrations/Twentysixteen.php',
96
-            'Sensei_Storefront'               => 'theme-integrations/Storefront.php',
97
-
98
-            /**
99
-             * WooCommerce
100
-             */
101
-            'Sensei_WC' => 'class-sensei-wc.php',
102
-
103
-        );
104
-    }
105
-
106
-    /**
107
-     * Autoload all sensei files as the class names are used.
108
-     */
109
-    public function autoload( $class ){
110
-
111
-        // only handle classes with the word `sensei` in it
112
-        if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){
113
-
114
-            return;
115
-
116
-        }
117
-
118
-        // exit if we didn't provide mapping for this class
119
-        if( isset( $this->class_file_map[ $class ] ) ){
120
-
121
-            $file_location = $this->include_path . $this->class_file_map[ $class ];
122
-            require_once( $file_location);
123
-            return;
124
-
125
-        }
126
-
127
-        // check for file in the main includes directory
128
-        $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php';
129
-        if( file_exists( $class_file_path ) ){
130
-
131
-            require_once( $class_file_path );
132
-            return;
133
-        }
134
-
135
-        // lastly check legacy types
136
-        $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes
137
-        $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php';
138
-        if( file_exists( $legacy_class_file_path ) ){
139
-
140
-            require_once( $legacy_class_file_path );
141
-            return;
142
-        }
143
-
144
-        return;
145
-
146
-    }// end autoload
16
+	/**
17
+	 * @var path to the includes directory within Sensei.
18
+	 */
19
+	private $include_path = 'includes';
20
+
21
+	/**
22
+	 * @var array $class_file_map. List of classes mapped to their files
23
+	 */
24
+	private $class_file_map = array();
25
+
26
+	/**
27
+	 * Constructor
28
+	 * @since 1.9.0
29
+	 */
30
+	public function __construct(){
31
+
32
+		// make sure we do not override an existing autoload function
33
+		if( function_exists('__autoload') ){
34
+		   spl_autoload_register( '__autoload' );
35
+		}
36
+
37
+		// setup a relative path for the current autoload instance
38
+		$this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) );
39
+
40
+		//setup the class file map
41
+		$this->initialize_class_file_map();
42
+
43
+		// add Sensei custom auto loader
44
+		spl_autoload_register( array( $this, 'autoload' )  );
45
+
46
+	}
47
+
48
+	/**
49
+	 * Generate a list of Sensei class and map them the their respective
50
+	 * files within the includes directory
51
+	 *
52
+	 * @since 1.9.0
53
+	 */
54
+	public function initialize_class_file_map(){
55
+
56
+		$this->class_file_map = array(
57
+
58
+			/**
59
+			 * Main Sensei class
60
+			 */
61
+			'Sensei_Main' => 'class-sensei.php',
62
+
63
+			/**
64
+			 * Admin
65
+			 */
66
+			'Sensei_Welcome'            => 'admin/class-sensei-welcome.php' ,
67
+			'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' ,
68
+
69
+			/**
70
+			 * Shortcodes
71
+			 */
72
+			'Sensei_Shortcode_Loader'              => 'shortcodes/class-sensei-shortcode-loader.php',
73
+			'Sensei_Shortcode_Interface'           => 'shortcodes/interface-sensei-shortcode.php',
74
+			'Sensei_Shortcode_Featured_Courses'    => 'shortcodes/class-sensei-shortcode-featured-courses.php',
75
+			'Sensei_Shortcode_User_Courses'        => 'shortcodes/class-sensei-shortcode-user-courses.php',
76
+			'Sensei_Shortcode_Courses'             => 'shortcodes/class-sensei-shortcode-courses.php',
77
+			'Sensei_Shortcode_Teachers'            => 'shortcodes/class-sensei-shortcode-teachers.php',
78
+			'Sensei_Shortcode_User_Messages'       => 'shortcodes/class-sensei-shortcode-user-messages.php',
79
+			'Sensei_Shortcode_Course_Page'         => 'shortcodes/class-sensei-shortcode-course-page.php',
80
+			'Sensei_Shortcode_Lesson_Page'         => 'shortcodes/class-sensei-shortcode-lesson-page.php',
81
+			'Sensei_Shortcode_Course_Categories'   => 'shortcodes/class-sensei-shortcode-course-categories.php',
82
+			'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php',
83
+			'Sensei_Legacy_Shortcodes'             => 'shortcodes/class-sensei-legacy-shortcodes.php',
84
+
85
+			/**
86
+			 * Built in theme integration support
87
+			 */
88
+			'Sensei_Theme_Integration_Loader' => 'theme-integrations/theme-integration-loader.php',
89
+			'Sensei__S'                       => 'theme-integrations/_s.php',
90
+			'Sensei_Twentyeleven'             => 'theme-integrations/twentyeleven.php',
91
+			'Sensei_Twentytwelve'             => 'theme-integrations/twentytwelve.php',
92
+			'Sensei_Twentythirteen'           => 'theme-integrations/Twentythirteen.php',
93
+			'Sensei_Twentyfourteen'           => 'theme-integrations/Twentyfourteen.php',
94
+			'Sensei_Twentyfifteen'            => 'theme-integrations/Twentyfifteen.php',
95
+			'Sensei_Twentysixteen'            => 'theme-integrations/Twentysixteen.php',
96
+			'Sensei_Storefront'               => 'theme-integrations/Storefront.php',
97
+
98
+			/**
99
+			 * WooCommerce
100
+			 */
101
+			'Sensei_WC' => 'class-sensei-wc.php',
102
+
103
+		);
104
+	}
105
+
106
+	/**
107
+	 * Autoload all sensei files as the class names are used.
108
+	 */
109
+	public function autoload( $class ){
110
+
111
+		// only handle classes with the word `sensei` in it
112
+		if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){
113
+
114
+			return;
115
+
116
+		}
117
+
118
+		// exit if we didn't provide mapping for this class
119
+		if( isset( $this->class_file_map[ $class ] ) ){
120
+
121
+			$file_location = $this->include_path . $this->class_file_map[ $class ];
122
+			require_once( $file_location);
123
+			return;
124
+
125
+		}
126
+
127
+		// check for file in the main includes directory
128
+		$class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php';
129
+		if( file_exists( $class_file_path ) ){
130
+
131
+			require_once( $class_file_path );
132
+			return;
133
+		}
134
+
135
+		// lastly check legacy types
136
+		$stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes
137
+		$legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php';
138
+		if( file_exists( $legacy_class_file_path ) ){
139
+
140
+			require_once( $legacy_class_file_path );
141
+			return;
142
+		}
143
+
144
+		return;
145
+
146
+	}// end autoload
147 147
 
148 148
 }
149 149
 new Sensei_Autoloader();
Please login to merge, or discard this patch.