@@ -166,7 +166,7 @@ |
||
| 166 | 166 | |
| 167 | 167 | Sensei_Templates::get_template( 'user/my-courses.php' ); |
| 168 | 168 | |
| 169 | - }else{ |
|
| 169 | + } else{ |
|
| 170 | 170 | |
| 171 | 171 | Sensei()->frontend->sensei_login_form(); |
| 172 | 172 | |
@@ -111,7 +111,7 @@ |
||
| 111 | 111 | * @since 1.9.0 |
| 112 | 112 | * |
| 113 | 113 | * @param $title |
| 114 | - * @param $shortcode_specific_override |
|
| 114 | + * @param string $shortcode_specific_override |
|
| 115 | 115 | * @return string |
| 116 | 116 | */ |
| 117 | 117 | public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
@@ -17,323 +17,323 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class Sensei_Legacy_Shortcodes { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Add the legacy shortcodes to WordPress |
|
| 22 | - * |
|
| 23 | - * @since 1.9.0 |
|
| 24 | - */ |
|
| 25 | - public static function init(){ |
|
| 26 | - |
|
| 27 | - add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 28 | - add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 29 | - add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 30 | - add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 31 | - add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 32 | - add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 33 | - |
|
| 34 | - } |
|
| 35 | - /** |
|
| 36 | - * all_courses shortcode output function. |
|
| 37 | - * |
|
| 38 | - * The function should only be called indirectly through do_shortcode() |
|
| 39 | - * |
|
| 40 | - * @access public |
|
| 41 | - * @param mixed $atts |
|
| 42 | - * @param mixed $content (default: null) |
|
| 43 | - * @return string |
|
| 44 | - */ |
|
| 45 | - public static function all_courses( $atts, $content = null ) { |
|
| 46 | - |
|
| 47 | - return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 48 | - |
|
| 49 | - } // all_courses() |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * paid_courses function. |
|
| 53 | - * |
|
| 54 | - * @access public |
|
| 55 | - * @param mixed $atts |
|
| 56 | - * @param mixed $content (default: null) |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public static function paid_courses( $atts, $content = null ) { |
|
| 60 | - |
|
| 61 | - return self::generate_shortcode_courses( __( 'Paid Courses', 'woothemes-sensei' ), 'paidcourses' ); |
|
| 62 | - |
|
| 63 | - } // End paid_courses() |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * featured_courses function. |
|
| 68 | - * |
|
| 69 | - * @access public |
|
| 70 | - * @param mixed $atts |
|
| 71 | - * @param mixed $content (default: null) |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public static function featured_courses( $atts, $content = null ) { |
|
| 75 | - |
|
| 76 | - return self::generate_shortcode_courses( __( 'Featured Courses', 'woothemes-sensei' ), 'featuredcourses' ); |
|
| 20 | + /** |
|
| 21 | + * Add the legacy shortcodes to WordPress |
|
| 22 | + * |
|
| 23 | + * @since 1.9.0 |
|
| 24 | + */ |
|
| 25 | + public static function init(){ |
|
| 26 | + |
|
| 27 | + add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 28 | + add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 29 | + add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 30 | + add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 31 | + add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 32 | + add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 33 | + |
|
| 34 | + } |
|
| 35 | + /** |
|
| 36 | + * all_courses shortcode output function. |
|
| 37 | + * |
|
| 38 | + * The function should only be called indirectly through do_shortcode() |
|
| 39 | + * |
|
| 40 | + * @access public |
|
| 41 | + * @param mixed $atts |
|
| 42 | + * @param mixed $content (default: null) |
|
| 43 | + * @return string |
|
| 44 | + */ |
|
| 45 | + public static function all_courses( $atts, $content = null ) { |
|
| 46 | + |
|
| 47 | + return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 48 | + |
|
| 49 | + } // all_courses() |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * paid_courses function. |
|
| 53 | + * |
|
| 54 | + * @access public |
|
| 55 | + * @param mixed $atts |
|
| 56 | + * @param mixed $content (default: null) |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public static function paid_courses( $atts, $content = null ) { |
|
| 60 | + |
|
| 61 | + return self::generate_shortcode_courses( __( 'Paid Courses', 'woothemes-sensei' ), 'paidcourses' ); |
|
| 62 | + |
|
| 63 | + } // End paid_courses() |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * featured_courses function. |
|
| 68 | + * |
|
| 69 | + * @access public |
|
| 70 | + * @param mixed $atts |
|
| 71 | + * @param mixed $content (default: null) |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public static function featured_courses( $atts, $content = null ) { |
|
| 75 | + |
|
| 76 | + return self::generate_shortcode_courses( __( 'Featured Courses', 'woothemes-sensei' ), 'featuredcourses' ); |
|
| 77 | 77 | |
| 78 | - } // End featured_courses() |
|
| 78 | + } // End featured_courses() |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * shortcode_free_courses function. |
|
| 82 | - * |
|
| 83 | - * @access public |
|
| 84 | - * @param mixed $atts |
|
| 85 | - * @param mixed $content (default: null) |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 88 | - public static function free_courses( $atts, $content = null ) { |
|
| 80 | + /** |
|
| 81 | + * shortcode_free_courses function. |
|
| 82 | + * |
|
| 83 | + * @access public |
|
| 84 | + * @param mixed $atts |
|
| 85 | + * @param mixed $content (default: null) |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | + public static function free_courses( $atts, $content = null ) { |
|
| 89 | 89 | |
| 90 | - return self::generate_shortcode_courses( __( 'Free Courses', 'woothemes-sensei' ), 'freecourses' ); |
|
| 90 | + return self::generate_shortcode_courses( __( 'Free Courses', 'woothemes-sensei' ), 'freecourses' ); |
|
| 91 | 91 | |
| 92 | - } // End free_courses() |
|
| 92 | + } // End free_courses() |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * shortcode_new_courses function. |
|
| 96 | - * |
|
| 97 | - * @access public |
|
| 98 | - * @param mixed $atts |
|
| 99 | - * @param mixed $content (default: null) |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public static function new_courses( $atts, $content = null ) { |
|
| 94 | + /** |
|
| 95 | + * shortcode_new_courses function. |
|
| 96 | + * |
|
| 97 | + * @access public |
|
| 98 | + * @param mixed $atts |
|
| 99 | + * @param mixed $content (default: null) |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public static function new_courses( $atts, $content = null ) { |
|
| 103 | 103 | |
| 104 | - return self::generate_shortcode_courses( __( 'New Courses', 'woothemes-sensei' ), 'newcourses' ); |
|
| 104 | + return self::generate_shortcode_courses( __( 'New Courses', 'woothemes-sensei' ), 'newcourses' ); |
|
| 105 | 105 | |
| 106 | - } // End new_courses() |
|
| 106 | + } // End new_courses() |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Generate courses adding a title. |
|
| 110 | - * |
|
| 111 | - * @since 1.9.0 |
|
| 112 | - * |
|
| 113 | - * @param $title |
|
| 114 | - * @param $shortcode_specific_override |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 117 | - public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 108 | + /** |
|
| 109 | + * Generate courses adding a title. |
|
| 110 | + * |
|
| 111 | + * @since 1.9.0 |
|
| 112 | + * |
|
| 113 | + * @param $title |
|
| 114 | + * @param $shortcode_specific_override |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | + public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 118 | 118 | |
| 119 | - global $shortcode_override, $posts_array; |
|
| 119 | + global $shortcode_override, $posts_array; |
|
| 120 | 120 | |
| 121 | - $shortcode_override = $shortcode_specific_override; |
|
| 121 | + $shortcode_override = $shortcode_specific_override; |
|
| 122 | 122 | |
| 123 | - // do not show this short code if there is a shortcode int he url and |
|
| 124 | - // this specific shortcode is not the one requested in the ur. |
|
| 125 | - $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 126 | - if( ! empty( $specific_shortcode_requested) && |
|
| 127 | - $specific_shortcode_requested != $shortcode_override ){ |
|
| 123 | + // do not show this short code if there is a shortcode int he url and |
|
| 124 | + // this specific shortcode is not the one requested in the ur. |
|
| 125 | + $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 126 | + if( ! empty( $specific_shortcode_requested) && |
|
| 127 | + $specific_shortcode_requested != $shortcode_override ){ |
|
| 128 | 128 | |
| 129 | - return ''; |
|
| 129 | + return ''; |
|
| 130 | 130 | |
| 131 | - } |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - // loop and get all courses html |
|
| 134 | - ob_start(); |
|
| 135 | - self::initialise_legacy_course_loop(); |
|
| 136 | - $courses = ob_get_clean(); |
|
| 133 | + // loop and get all courses html |
|
| 134 | + ob_start(); |
|
| 135 | + self::initialise_legacy_course_loop(); |
|
| 136 | + $courses = ob_get_clean(); |
|
| 137 | 137 | |
| 138 | - $content = ''; |
|
| 139 | - if( count( $posts_array ) > 0 ){ |
|
| 138 | + $content = ''; |
|
| 139 | + if( count( $posts_array ) > 0 ){ |
|
| 140 | 140 | |
| 141 | - $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 142 | - $before .= '<section id="main-course" class="course-container">'; |
|
| 141 | + $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 142 | + $before .= '<section id="main-course" class="course-container">'; |
|
| 143 | 143 | |
| 144 | - $after = '</section>'; |
|
| 144 | + $after = '</section>'; |
|
| 145 | 145 | |
| 146 | - //assemble |
|
| 147 | - $content = $before . $courses . $after; |
|
| 146 | + //assemble |
|
| 147 | + $content = $before . $courses . $after; |
|
| 148 | 148 | |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - return $content; |
|
| 151 | + return $content; |
|
| 152 | 152 | |
| 153 | - }// end generate_shortcode_courses |
|
| 153 | + }// end generate_shortcode_courses |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * user_courses function. |
|
| 158 | - * |
|
| 159 | - * @access public |
|
| 160 | - * @param mixed $atts |
|
| 161 | - * @param mixed $content (default: null) |
|
| 162 | - * @return string |
|
| 163 | - */ |
|
| 164 | - public static function user_courses( $atts, $content = null ) { |
|
| 165 | - global $shortcode_override; |
|
| 166 | - extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 156 | + /** |
|
| 157 | + * user_courses function. |
|
| 158 | + * |
|
| 159 | + * @access public |
|
| 160 | + * @param mixed $atts |
|
| 161 | + * @param mixed $content (default: null) |
|
| 162 | + * @return string |
|
| 163 | + */ |
|
| 164 | + public static function user_courses( $atts, $content = null ) { |
|
| 165 | + global $shortcode_override; |
|
| 166 | + extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 167 | 167 | |
| 168 | - $shortcode_override = 'usercourses'; |
|
| 168 | + $shortcode_override = 'usercourses'; |
|
| 169 | 169 | |
| 170 | - ob_start(); |
|
| 170 | + ob_start(); |
|
| 171 | 171 | |
| 172 | - if( is_user_logged_in() ){ |
|
| 172 | + if( is_user_logged_in() ){ |
|
| 173 | 173 | |
| 174 | - Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 174 | + Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 175 | 175 | |
| 176 | - }else{ |
|
| 176 | + }else{ |
|
| 177 | 177 | |
| 178 | - Sensei()->frontend->sensei_login_form(); |
|
| 178 | + Sensei()->frontend->sensei_login_form(); |
|
| 179 | 179 | |
| 180 | - } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - $content = ob_get_clean(); |
|
| 183 | - return $content; |
|
| 182 | + $content = ob_get_clean(); |
|
| 183 | + return $content; |
|
| 184 | 184 | |
| 185 | - } // End user_courses() |
|
| 185 | + } // End user_courses() |
|
| 186 | 186 | |
| 187 | - /** |
|
| 188 | - * This function is simply to honor the legacy |
|
| 189 | - * loop-course.php for the old shortcodes. |
|
| 190 | - * @since 1.9.0 |
|
| 191 | - */ |
|
| 192 | - public static function initialise_legacy_course_loop(){ |
|
| 187 | + /** |
|
| 188 | + * This function is simply to honor the legacy |
|
| 189 | + * loop-course.php for the old shortcodes. |
|
| 190 | + * @since 1.9.0 |
|
| 191 | + */ |
|
| 192 | + public static function initialise_legacy_course_loop(){ |
|
| 193 | 193 | |
| 194 | - global $post, $wp_query, $shortcode_override, $course_excludes; |
|
| 194 | + global $post, $wp_query, $shortcode_override, $course_excludes; |
|
| 195 | 195 | |
| 196 | - // Handle Query Type |
|
| 197 | - $query_type = ''; |
|
| 196 | + // Handle Query Type |
|
| 197 | + $query_type = ''; |
|
| 198 | 198 | |
| 199 | - if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 200 | - $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 201 | - } // End If Statement |
|
| 199 | + if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 200 | + $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 201 | + } // End If Statement |
|
| 202 | 202 | |
| 203 | - if ( '' != $shortcode_override ) { |
|
| 204 | - $query_type = $shortcode_override; |
|
| 205 | - } // End If Statement |
|
| 203 | + if ( '' != $shortcode_override ) { |
|
| 204 | + $query_type = $shortcode_override; |
|
| 205 | + } // End If Statement |
|
| 206 | 206 | |
| 207 | - if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 207 | + if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 208 | 208 | |
| 209 | - // Check that query returns results |
|
| 210 | - // Handle Pagination |
|
| 211 | - $paged = $wp_query->get( 'paged' ); |
|
| 212 | - $paged = empty( $paged ) ? 1 : $paged; |
|
| 209 | + // Check that query returns results |
|
| 210 | + // Handle Pagination |
|
| 211 | + $paged = $wp_query->get( 'paged' ); |
|
| 212 | + $paged = empty( $paged ) ? 1 : $paged; |
|
| 213 | 213 | |
| 214 | 214 | |
| 215 | - // Check for pagination settings |
|
| 216 | - if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 215 | + // Check for pagination settings |
|
| 216 | + if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 217 | 217 | |
| 218 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 218 | + $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 219 | 219 | |
| 220 | - } else { |
|
| 220 | + } else { |
|
| 221 | 221 | |
| 222 | - $amount = $wp_query->get( 'posts_per_page' ); |
|
| 222 | + $amount = $wp_query->get( 'posts_per_page' ); |
|
| 223 | 223 | |
| 224 | - } // End If Statement |
|
| 224 | + } // End If Statement |
|
| 225 | 225 | |
| 226 | - // This is not a paginated page (or it's simply the first page of a paginated page/post) |
|
| 226 | + // This is not a paginated page (or it's simply the first page of a paginated page/post) |
|
| 227 | 227 | |
| 228 | - global $posts_array; |
|
| 229 | - $course_includes = array(); |
|
| 228 | + global $posts_array; |
|
| 229 | + $course_includes = array(); |
|
| 230 | 230 | |
| 231 | - $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 232 | - $course_query = new WP_Query( $query_args ); |
|
| 233 | - $posts_array = $course_query->get_posts(); |
|
| 231 | + $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 232 | + $course_query = new WP_Query( $query_args ); |
|
| 233 | + $posts_array = $course_query->get_posts(); |
|
| 234 | 234 | |
| 235 | - // output the courses |
|
| 236 | - if( ! empty( $posts_array ) ) { |
|
| 235 | + // output the courses |
|
| 236 | + if( ! empty( $posts_array ) ) { |
|
| 237 | 237 | |
| 238 | - //output all courses for current query |
|
| 239 | - self::loop_courses( $course_query, $amount ); |
|
| 238 | + //output all courses for current query |
|
| 239 | + self::loop_courses( $course_query, $amount ); |
|
| 240 | 240 | |
| 241 | - } |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - } |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Loop through courses in the query and output the infomration needed |
|
| 247 | - * |
|
| 248 | - * @since 1.9.0 |
|
| 249 | - * |
|
| 250 | - * @param WP_Query $course_query |
|
| 251 | - */ |
|
| 252 | - public static function loop_courses( $course_query, $amount ){ |
|
| 245 | + /** |
|
| 246 | + * Loop through courses in the query and output the infomration needed |
|
| 247 | + * |
|
| 248 | + * @since 1.9.0 |
|
| 249 | + * |
|
| 250 | + * @param WP_Query $course_query |
|
| 251 | + */ |
|
| 252 | + public static function loop_courses( $course_query, $amount ){ |
|
| 253 | 253 | |
| 254 | - global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
|
| 254 | + global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
|
| 255 | 255 | |
| 256 | - if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 256 | + if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 257 | 257 | |
| 258 | - do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 258 | + do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 259 | 259 | |
| 260 | - foreach ( $course_query->get_posts() as $course){ |
|
| 260 | + foreach ( $course_query->get_posts() as $course){ |
|
| 261 | 261 | |
| 262 | - // Make sure the other loops dont include the same post twice! |
|
| 263 | - array_push( $course_excludes, $course->ID ); |
|
| 262 | + // Make sure the other loops dont include the same post twice! |
|
| 263 | + array_push( $course_excludes, $course->ID ); |
|
| 264 | 264 | |
| 265 | - // output the course markup |
|
| 266 | - self::the_course( $course->ID ); |
|
| 265 | + // output the course markup |
|
| 266 | + self::the_course( $course->ID ); |
|
| 267 | 267 | |
| 268 | - } // End For Loop |
|
| 268 | + } // End For Loop |
|
| 269 | 269 | |
| 270 | - // More and Prev links |
|
| 271 | - $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 272 | - $posts_array = $posts_array_query->get_posts(); |
|
| 273 | - $max_pages = $course_query->found_posts / $amount; |
|
| 274 | - if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 270 | + // More and Prev links |
|
| 271 | + $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 272 | + $posts_array = $posts_array_query->get_posts(); |
|
| 273 | + $max_pages = $course_query->found_posts / $amount; |
|
| 274 | + if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 275 | 275 | |
| 276 | - switch( $shortcode_override ){ |
|
| 277 | - case 'paidcourses': |
|
| 278 | - $filter = 'paid'; |
|
| 279 | - break; |
|
| 280 | - case 'featuredcourses': |
|
| 281 | - $filter = 'featured'; |
|
| 282 | - break; |
|
| 283 | - case 'freecourses': |
|
| 284 | - $filter = 'free'; |
|
| 285 | - break; |
|
| 286 | - default: |
|
| 287 | - $filter = ''; |
|
| 288 | - break; |
|
| 289 | - } |
|
| 276 | + switch( $shortcode_override ){ |
|
| 277 | + case 'paidcourses': |
|
| 278 | + $filter = 'paid'; |
|
| 279 | + break; |
|
| 280 | + case 'featuredcourses': |
|
| 281 | + $filter = 'featured'; |
|
| 282 | + break; |
|
| 283 | + case 'freecourses': |
|
| 284 | + $filter = 'free'; |
|
| 285 | + break; |
|
| 286 | + default: |
|
| 287 | + $filter = ''; |
|
| 288 | + break; |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - $quer_args = array(); |
|
| 292 | - $quer_args[ 'paged' ] = '2'; |
|
| 293 | - if( !empty( $filter ) ){ |
|
| 294 | - $quer_args[ 'course_filter' ] = $filter; |
|
| 295 | - } |
|
| 291 | + $quer_args = array(); |
|
| 292 | + $quer_args[ 'paged' ] = '2'; |
|
| 293 | + if( !empty( $filter ) ){ |
|
| 294 | + $quer_args[ 'course_filter' ] = $filter; |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 298 | - $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 299 | - $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 297 | + $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 298 | + $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 299 | + $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 300 | 300 | |
| 301 | - // next/more |
|
| 302 | - $html = '<div class="navigation"><div class="nav-next">'; |
|
| 303 | - $html .= '<a href="' . $more_link_url . '">'; |
|
| 304 | - $html .= $more_link_text; |
|
| 305 | - $html .= '<span class="meta-nav"></span></a></div>'; |
|
| 301 | + // next/more |
|
| 302 | + $html = '<div class="navigation"><div class="nav-next">'; |
|
| 303 | + $html .= '<a href="' . $more_link_url . '">'; |
|
| 304 | + $html .= $more_link_text; |
|
| 305 | + $html .= '<span class="meta-nav"></span></a></div>'; |
|
| 306 | 306 | |
| 307 | - echo apply_filters( 'course_archive_next_link', $html ); |
|
| 307 | + echo apply_filters( 'course_archive_next_link', $html ); |
|
| 308 | 308 | |
| 309 | - } // End If Statement |
|
| 309 | + } // End If Statement |
|
| 310 | 310 | |
| 311 | - } // End If Statement |
|
| 312 | - } |
|
| 311 | + } // End If Statement |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Print a single course markup |
|
| 316 | - * |
|
| 317 | - * @param $course_id |
|
| 318 | - */ |
|
| 319 | - public static function the_course( $course_id ){ |
|
| 314 | + /** |
|
| 315 | + * Print a single course markup |
|
| 316 | + * |
|
| 317 | + * @param $course_id |
|
| 318 | + */ |
|
| 319 | + public static function the_course( $course_id ){ |
|
| 320 | 320 | |
| 321 | - // Get meta data |
|
| 322 | - $course = get_post( $course_id ); |
|
| 323 | - $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 324 | - $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 325 | - $author_display_name = $user_info->display_name; |
|
| 326 | - $author_id = $course->post_author; |
|
| 327 | - $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 328 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 329 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 330 | - ?> |
|
| 321 | + // Get meta data |
|
| 322 | + $course = get_post( $course_id ); |
|
| 323 | + $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 324 | + $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 325 | + $author_display_name = $user_info->display_name; |
|
| 326 | + $author_id = $course->post_author; |
|
| 327 | + $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 328 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 329 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 330 | + ?> |
|
| 331 | 331 | |
| 332 | 332 | <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>"> |
| 333 | 333 | <?php |
| 334 | - // so that legacy shortcodes work with the party plugins that wants to hook in |
|
| 335 | - do_action('sensei_course_content_before',$course->ID ); |
|
| 336 | - ?> |
|
| 334 | + // so that legacy shortcodes work with the party plugins that wants to hook in |
|
| 335 | + do_action('sensei_course_content_before',$course->ID ); |
|
| 336 | + ?> |
|
| 337 | 337 | <div class="course-content"> |
| 338 | 338 | |
| 339 | 339 | <?php Sensei()->course->course_image($course_id); ?> |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | </p> |
| 370 | 370 | |
| 371 | 371 | <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
| 372 | - $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 372 | + $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 373 | 373 | <p class="sensei-free-lessons"> |
| 374 | 374 | <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
| 375 | 375 | </a> - <?php echo $preview_lessons; ?> |
@@ -380,15 +380,15 @@ discard block |
||
| 380 | 380 | |
| 381 | 381 | </div> |
| 382 | 382 | <?php |
| 383 | - // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 384 | - do_action('sensei_course_content_after', $course->ID); |
|
| 385 | - ?> |
|
| 383 | + // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 384 | + do_action('sensei_course_content_after', $course->ID); |
|
| 385 | + ?> |
|
| 386 | 386 | |
| 387 | 387 | </article> |
| 388 | 388 | |
| 389 | 389 | <?php |
| 390 | 390 | |
| 391 | 391 | |
| 392 | - } // end the_course |
|
| 392 | + } // end the_course |
|
| 393 | 393 | |
| 394 | 394 | }// end class legacy shortcodes |
| 395 | 395 | \ No newline at end of file |
@@ -22,14 +22,14 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @since 1.9.0 |
| 24 | 24 | */ |
| 25 | - public static function init(){ |
|
| 25 | + public static function init() { |
|
| 26 | 26 | |
| 27 | - add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 28 | - add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 29 | - add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 30 | - add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 31 | - add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 32 | - add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 27 | + add_shortcode('allcourses', array(__CLASS__, 'all_courses')); |
|
| 28 | + add_shortcode('newcourses', array(__CLASS__, 'new_courses')); |
|
| 29 | + add_shortcode('featuredcourses', array(__CLASS__, 'featured_courses')); |
|
| 30 | + add_shortcode('freecourses', array(__CLASS__, 'free_courses')); |
|
| 31 | + add_shortcode('paidcourses', array(__CLASS__, 'paid_courses')); |
|
| 32 | + add_shortcode('usercourses', array(__CLASS__, 'user_courses')); |
|
| 33 | 33 | |
| 34 | 34 | } |
| 35 | 35 | /** |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | * @param mixed $content (default: null) |
| 43 | 43 | * @return string |
| 44 | 44 | */ |
| 45 | - public static function all_courses( $atts, $content = null ) { |
|
| 45 | + public static function all_courses($atts, $content = null) { |
|
| 46 | 46 | |
| 47 | - return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 47 | + return self::generate_shortcode_courses('', 'allcourses'); // all courses but no title |
|
| 48 | 48 | |
| 49 | 49 | } // all_courses() |
| 50 | 50 | |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | * @param mixed $content (default: null) |
| 57 | 57 | * @return string |
| 58 | 58 | */ |
| 59 | - public static function paid_courses( $atts, $content = null ) { |
|
| 59 | + public static function paid_courses($atts, $content = null) { |
|
| 60 | 60 | |
| 61 | - return self::generate_shortcode_courses( __( 'Paid Courses', 'woothemes-sensei' ), 'paidcourses' ); |
|
| 61 | + return self::generate_shortcode_courses(__('Paid Courses', 'woothemes-sensei'), 'paidcourses'); |
|
| 62 | 62 | |
| 63 | 63 | } // End paid_courses() |
| 64 | 64 | |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | * @param mixed $content (default: null) |
| 72 | 72 | * @return string |
| 73 | 73 | */ |
| 74 | - public static function featured_courses( $atts, $content = null ) { |
|
| 74 | + public static function featured_courses($atts, $content = null) { |
|
| 75 | 75 | |
| 76 | - return self::generate_shortcode_courses( __( 'Featured Courses', 'woothemes-sensei' ), 'featuredcourses' ); |
|
| 76 | + return self::generate_shortcode_courses(__('Featured Courses', 'woothemes-sensei'), 'featuredcourses'); |
|
| 77 | 77 | |
| 78 | 78 | } // End featured_courses() |
| 79 | 79 | |
@@ -85,9 +85,9 @@ discard block |
||
| 85 | 85 | * @param mixed $content (default: null) |
| 86 | 86 | * @return string |
| 87 | 87 | */ |
| 88 | - public static function free_courses( $atts, $content = null ) { |
|
| 88 | + public static function free_courses($atts, $content = null) { |
|
| 89 | 89 | |
| 90 | - return self::generate_shortcode_courses( __( 'Free Courses', 'woothemes-sensei' ), 'freecourses' ); |
|
| 90 | + return self::generate_shortcode_courses(__('Free Courses', 'woothemes-sensei'), 'freecourses'); |
|
| 91 | 91 | |
| 92 | 92 | } // End free_courses() |
| 93 | 93 | |
@@ -99,9 +99,9 @@ discard block |
||
| 99 | 99 | * @param mixed $content (default: null) |
| 100 | 100 | * @return string |
| 101 | 101 | */ |
| 102 | - public static function new_courses( $atts, $content = null ) { |
|
| 102 | + public static function new_courses($atts, $content = null) { |
|
| 103 | 103 | |
| 104 | - return self::generate_shortcode_courses( __( 'New Courses', 'woothemes-sensei' ), 'newcourses' ); |
|
| 104 | + return self::generate_shortcode_courses(__('New Courses', 'woothemes-sensei'), 'newcourses'); |
|
| 105 | 105 | |
| 106 | 106 | } // End new_courses() |
| 107 | 107 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @param $shortcode_specific_override |
| 115 | 115 | * @return string |
| 116 | 116 | */ |
| 117 | - public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 117 | + public static function generate_shortcode_courses($title, $shortcode_specific_override) { |
|
| 118 | 118 | |
| 119 | 119 | global $shortcode_override, $posts_array; |
| 120 | 120 | |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | // do not show this short code if there is a shortcode int he url and |
| 124 | 124 | // this specific shortcode is not the one requested in the ur. |
| 125 | - $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 126 | - if( ! empty( $specific_shortcode_requested) && |
|
| 127 | - $specific_shortcode_requested != $shortcode_override ){ |
|
| 125 | + $specific_shortcode_requested = isset($_GET['action']) ? sanitize_text_field($_GET['action']) : ''; |
|
| 126 | + if ( ! empty($specific_shortcode_requested) && |
|
| 127 | + $specific_shortcode_requested != $shortcode_override) { |
|
| 128 | 128 | |
| 129 | 129 | return ''; |
| 130 | 130 | |
@@ -136,15 +136,15 @@ discard block |
||
| 136 | 136 | $courses = ob_get_clean(); |
| 137 | 137 | |
| 138 | 138 | $content = ''; |
| 139 | - if( count( $posts_array ) > 0 ){ |
|
| 139 | + if (count($posts_array) > 0) { |
|
| 140 | 140 | |
| 141 | - $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 141 | + $before = empty($title) ? '' : '<header class="archive-header"><h2>'.$title.'</h2></header>'; |
|
| 142 | 142 | $before .= '<section id="main-course" class="course-container">'; |
| 143 | 143 | |
| 144 | 144 | $after = '</section>'; |
| 145 | 145 | |
| 146 | 146 | //assemble |
| 147 | - $content = $before . $courses . $after; |
|
| 147 | + $content = $before.$courses.$after; |
|
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | |
@@ -161,19 +161,19 @@ discard block |
||
| 161 | 161 | * @param mixed $content (default: null) |
| 162 | 162 | * @return string |
| 163 | 163 | */ |
| 164 | - public static function user_courses( $atts, $content = null ) { |
|
| 164 | + public static function user_courses($atts, $content = null) { |
|
| 165 | 165 | global $shortcode_override; |
| 166 | - extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 166 | + extract(shortcode_atts(array('amount' => 0), $atts)); |
|
| 167 | 167 | |
| 168 | 168 | $shortcode_override = 'usercourses'; |
| 169 | 169 | |
| 170 | 170 | ob_start(); |
| 171 | 171 | |
| 172 | - if( is_user_logged_in() ){ |
|
| 172 | + if (is_user_logged_in()) { |
|
| 173 | 173 | |
| 174 | - Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 174 | + Sensei_Templates::get_template('user/my-courses.php'); |
|
| 175 | 175 | |
| 176 | - }else{ |
|
| 176 | + } else { |
|
| 177 | 177 | |
| 178 | 178 | Sensei()->frontend->sensei_login_form(); |
| 179 | 179 | |
@@ -189,54 +189,54 @@ discard block |
||
| 189 | 189 | * loop-course.php for the old shortcodes. |
| 190 | 190 | * @since 1.9.0 |
| 191 | 191 | */ |
| 192 | - public static function initialise_legacy_course_loop(){ |
|
| 192 | + public static function initialise_legacy_course_loop() { |
|
| 193 | 193 | |
| 194 | 194 | global $post, $wp_query, $shortcode_override, $course_excludes; |
| 195 | 195 | |
| 196 | 196 | // Handle Query Type |
| 197 | 197 | $query_type = ''; |
| 198 | 198 | |
| 199 | - if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 200 | - $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 199 | + if (isset($_GET['action']) && ('' != esc_html($_GET['action']))) { |
|
| 200 | + $query_type = esc_html($_GET['action']); |
|
| 201 | 201 | } // End If Statement |
| 202 | 202 | |
| 203 | - if ( '' != $shortcode_override ) { |
|
| 203 | + if ('' != $shortcode_override) { |
|
| 204 | 204 | $query_type = $shortcode_override; |
| 205 | 205 | } // End If Statement |
| 206 | 206 | |
| 207 | - if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 207 | + if ( ! is_array($course_excludes)) { $course_excludes = array(); } |
|
| 208 | 208 | |
| 209 | 209 | // Check that query returns results |
| 210 | 210 | // Handle Pagination |
| 211 | - $paged = $wp_query->get( 'paged' ); |
|
| 212 | - $paged = empty( $paged ) ? 1 : $paged; |
|
| 211 | + $paged = $wp_query->get('paged'); |
|
| 212 | + $paged = empty($paged) ? 1 : $paged; |
|
| 213 | 213 | |
| 214 | 214 | |
| 215 | 215 | // Check for pagination settings |
| 216 | - if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 216 | + if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) { |
|
| 217 | 217 | |
| 218 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 218 | + $amount = absint(Sensei()->settings->settings['course_archive_amount']); |
|
| 219 | 219 | |
| 220 | 220 | } else { |
| 221 | 221 | |
| 222 | - $amount = $wp_query->get( 'posts_per_page' ); |
|
| 222 | + $amount = $wp_query->get('posts_per_page'); |
|
| 223 | 223 | |
| 224 | 224 | } // End If Statement |
| 225 | 225 | |
| 226 | 226 | // This is not a paginated page (or it's simply the first page of a paginated page/post) |
| 227 | 227 | |
| 228 | 228 | global $posts_array; |
| 229 | - $course_includes = array(); |
|
| 229 | + $course_includes = array(); |
|
| 230 | 230 | |
| 231 | - $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 232 | - $course_query = new WP_Query( $query_args ); |
|
| 231 | + $query_args = Sensei()->course->get_archive_query_args($shortcode_override, $amount, $course_includes, $course_excludes); |
|
| 232 | + $course_query = new WP_Query($query_args); |
|
| 233 | 233 | $posts_array = $course_query->get_posts(); |
| 234 | 234 | |
| 235 | 235 | // output the courses |
| 236 | - if( ! empty( $posts_array ) ) { |
|
| 236 | + if ( ! empty($posts_array)) { |
|
| 237 | 237 | |
| 238 | 238 | //output all courses for current query |
| 239 | - self::loop_courses( $course_query, $amount ); |
|
| 239 | + self::loop_courses($course_query, $amount); |
|
| 240 | 240 | |
| 241 | 241 | } |
| 242 | 242 | |
@@ -249,31 +249,31 @@ discard block |
||
| 249 | 249 | * |
| 250 | 250 | * @param WP_Query $course_query |
| 251 | 251 | */ |
| 252 | - public static function loop_courses( $course_query, $amount ){ |
|
| 252 | + public static function loop_courses($course_query, $amount) { |
|
| 253 | 253 | |
| 254 | 254 | global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
| 255 | 255 | |
| 256 | - if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 256 | + if (count($course_query->get_posts()) > 0) { |
|
| 257 | 257 | |
| 258 | - do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 258 | + do_action('sensei_course_archive_header', $shortcode_override); |
|
| 259 | 259 | |
| 260 | - foreach ( $course_query->get_posts() as $course){ |
|
| 260 | + foreach ($course_query->get_posts() as $course) { |
|
| 261 | 261 | |
| 262 | 262 | // Make sure the other loops dont include the same post twice! |
| 263 | - array_push( $course_excludes, $course->ID ); |
|
| 263 | + array_push($course_excludes, $course->ID); |
|
| 264 | 264 | |
| 265 | 265 | // output the course markup |
| 266 | - self::the_course( $course->ID ); |
|
| 266 | + self::the_course($course->ID); |
|
| 267 | 267 | |
| 268 | 268 | } // End For Loop |
| 269 | 269 | |
| 270 | 270 | // More and Prev links |
| 271 | - $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 271 | + $posts_array_query = new WP_Query(Sensei()->course->course_query($shortcode_override, $amount, $course_includes, $course_excludes)); |
|
| 272 | 272 | $posts_array = $posts_array_query->get_posts(); |
| 273 | 273 | $max_pages = $course_query->found_posts / $amount; |
| 274 | - if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 274 | + if ('' != $shortcode_override && ($max_pages > $course_query->get('paged'))) { |
|
| 275 | 275 | |
| 276 | - switch( $shortcode_override ){ |
|
| 276 | + switch ($shortcode_override) { |
|
| 277 | 277 | case 'paidcourses': |
| 278 | 278 | $filter = 'paid'; |
| 279 | 279 | break; |
@@ -289,22 +289,22 @@ discard block |
||
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | $quer_args = array(); |
| 292 | - $quer_args[ 'paged' ] = '2'; |
|
| 293 | - if( !empty( $filter ) ){ |
|
| 294 | - $quer_args[ 'course_filter' ] = $filter; |
|
| 292 | + $quer_args['paged'] = '2'; |
|
| 293 | + if ( ! empty($filter)) { |
|
| 294 | + $quer_args['course_filter'] = $filter; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 298 | - $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 299 | - $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 297 | + $course_pagination_link = get_post_type_archive_link('course'); |
|
| 298 | + $more_link_text = esc_html(Sensei()->settings->settings['course_archive_more_link_text']); |
|
| 299 | + $more_link_url = esc_url(add_query_arg($quer_args, $course_pagination_link)); |
|
| 300 | 300 | |
| 301 | 301 | // next/more |
| 302 | 302 | $html = '<div class="navigation"><div class="nav-next">'; |
| 303 | - $html .= '<a href="' . $more_link_url . '">'; |
|
| 303 | + $html .= '<a href="'.$more_link_url.'">'; |
|
| 304 | 304 | $html .= $more_link_text; |
| 305 | 305 | $html .= '<span class="meta-nav"></span></a></div>'; |
| 306 | 306 | |
| 307 | - echo apply_filters( 'course_archive_next_link', $html ); |
|
| 307 | + echo apply_filters('course_archive_next_link', $html); |
|
| 308 | 308 | |
| 309 | 309 | } // End If Statement |
| 310 | 310 | |
@@ -316,23 +316,23 @@ discard block |
||
| 316 | 316 | * |
| 317 | 317 | * @param $course_id |
| 318 | 318 | */ |
| 319 | - public static function the_course( $course_id ){ |
|
| 319 | + public static function the_course($course_id) { |
|
| 320 | 320 | |
| 321 | 321 | // Get meta data |
| 322 | - $course = get_post( $course_id ); |
|
| 323 | - $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 324 | - $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 322 | + $course = get_post($course_id); |
|
| 323 | + $user_info = get_userdata(absint($course->post_author)); |
|
| 324 | + $author_link = get_author_posts_url(absint($course->post_author)); |
|
| 325 | 325 | $author_display_name = $user_info->display_name; |
| 326 | 326 | $author_id = $course->post_author; |
| 327 | - $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 328 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 329 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 327 | + $category_output = get_the_term_list($course_id, 'course-category', '', ', ', ''); |
|
| 328 | + $preview_lesson_count = intval(Sensei()->course->course_lesson_preview_count($course_id)); |
|
| 329 | + $is_user_taking_course = Sensei_Utils::user_started_course($course_id, get_current_user_id()); |
|
| 330 | 330 | ?> |
| 331 | 331 | |
| 332 | - <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>"> |
|
| 332 | + <article class="<?php echo esc_attr(join(' ', get_post_class(array('course', 'post'), $course_id))); ?>"> |
|
| 333 | 333 | <?php |
| 334 | 334 | // so that legacy shortcodes work with the party plugins that wants to hook in |
| 335 | - do_action('sensei_course_content_before',$course->ID ); |
|
| 335 | + do_action('sensei_course_content_before', $course->ID); |
|
| 336 | 336 | ?> |
| 337 | 337 | <div class="course-content"> |
| 338 | 338 | |
@@ -348,19 +348,19 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | <p class="sensei-course-meta"> |
| 350 | 350 | |
| 351 | - <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?> |
|
| 352 | - <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr( $author_display_name ); ?>"><?php echo esc_html( $author_display_name ); ?></a></span> |
|
| 351 | + <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?> |
|
| 352 | + <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><a href="<?php echo $author_link; ?>" title="<?php echo esc_attr($author_display_name); ?>"><?php echo esc_html($author_display_name); ?></a></span> |
|
| 353 | 353 | <?php } // End If Statement ?> |
| 354 | 354 | |
| 355 | 355 | <span class="course-lesson-count"> |
| 356 | - <?php echo Sensei()->course->course_lesson_count( $course_id ) . ' ' . __( 'Lessons', 'woothemes-sensei' ); ?> |
|
| 356 | + <?php echo Sensei()->course->course_lesson_count($course_id).' '.__('Lessons', 'woothemes-sensei'); ?> |
|
| 357 | 357 | </span> |
| 358 | 358 | |
| 359 | - <?php if ( '' != $category_output ) { ?> |
|
| 360 | - <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span> |
|
| 359 | + <?php if ('' != $category_output) { ?> |
|
| 360 | + <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span> |
|
| 361 | 361 | <?php } // End If Statement ?> |
| 362 | 362 | |
| 363 | - <?php sensei_simple_course_price( $course_id ); ?> |
|
| 363 | + <?php sensei_simple_course_price($course_id); ?> |
|
| 364 | 364 | |
| 365 | 365 | </p> |
| 366 | 366 | |
@@ -368,10 +368,10 @@ discard block |
||
| 368 | 368 | |
| 369 | 369 | </p> |
| 370 | 370 | |
| 371 | - <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 372 | - $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 371 | + <?php if (0 < $preview_lesson_count && ! $is_user_taking_course) { |
|
| 372 | + $preview_lessons = sprintf(__('(%d preview lessons)', 'woothemes-sensei'), $preview_lesson_count); ?> |
|
| 373 | 373 | <p class="sensei-free-lessons"> |
| 374 | - <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
|
| 374 | + <a href="<?php echo get_permalink($course_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?> |
|
| 375 | 375 | </a> - <?php echo $preview_lessons; ?> |
| 376 | 376 | </p> |
| 377 | 377 | <?php } ?> |
@@ -1,6 +1,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 1378 | 1383 | |
| 1379 | 1384 | return $lesson_query->posts; |
| 1380 | 1385 | |
| 1381 | - }else{ |
|
| 1386 | + } else{ |
|
| 1382 | 1387 | |
| 1383 | 1388 | return array(); |
| 1384 | 1389 | |
@@ -21,6 +21,9 @@ discard block |
||
| 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 |
||
| 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 | { |
@@ -14,265 +14,265 @@ discard block |
||
| 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 |
||
| 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,872 +335,872 @@ discard block |
||
| 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 | - } |
|
| 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 | 1204 | |
| 1205 | 1205 | /** |
| 1206 | 1206 | * Get ordered array of all modules in course |
@@ -1259,485 +1259,485 @@ discard block |
||
| 1259 | 1259 | |
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | - /** |
|
| 1263 | - * Load frontend CSS |
|
| 1264 | - * |
|
| 1265 | - * @since 1.8.0 |
|
| 1266 | - * |
|
| 1267 | - * @return void |
|
| 1268 | - */ |
|
| 1269 | - public function enqueue_styles() { |
|
| 1270 | - |
|
| 1271 | - wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1272 | - wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1273 | - |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * Load admin Javascript |
|
| 1278 | - * |
|
| 1279 | - * @since 1.8.0 |
|
| 1280 | - * |
|
| 1281 | - * @return void |
|
| 1282 | - */ |
|
| 1283 | - public function admin_enqueue_scripts( $hook ) { |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * Filter the page hooks where modules admin script can be loaded on. |
|
| 1287 | - * |
|
| 1288 | - * @param array $white_listed_pages |
|
| 1289 | - */ |
|
| 1290 | - $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1291 | - 'edit-tags.php', |
|
| 1292 | - 'course_page_module-order', |
|
| 1293 | - 'post-new.php', |
|
| 1294 | - 'post.php' |
|
| 1295 | - ) ); |
|
| 1296 | - |
|
| 1297 | - if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1298 | - return; |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1302 | - |
|
| 1303 | - wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1304 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1305 | - 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 ); |
|
| 1306 | - |
|
| 1307 | - // localized module data |
|
| 1308 | - $localize_modulesAdmin = array( |
|
| 1309 | - 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1310 | - 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1311 | - ); |
|
| 1312 | - |
|
| 1313 | - wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1314 | - } |
|
| 1262 | + /** |
|
| 1263 | + * Load frontend CSS |
|
| 1264 | + * |
|
| 1265 | + * @since 1.8.0 |
|
| 1266 | + * |
|
| 1267 | + * @return void |
|
| 1268 | + */ |
|
| 1269 | + public function enqueue_styles() { |
|
| 1270 | + |
|
| 1271 | + wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1272 | + wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1273 | + |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * Load admin Javascript |
|
| 1278 | + * |
|
| 1279 | + * @since 1.8.0 |
|
| 1280 | + * |
|
| 1281 | + * @return void |
|
| 1282 | + */ |
|
| 1283 | + public function admin_enqueue_scripts( $hook ) { |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * Filter the page hooks where modules admin script can be loaded on. |
|
| 1287 | + * |
|
| 1288 | + * @param array $white_listed_pages |
|
| 1289 | + */ |
|
| 1290 | + $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1291 | + 'edit-tags.php', |
|
| 1292 | + 'course_page_module-order', |
|
| 1293 | + 'post-new.php', |
|
| 1294 | + 'post.php' |
|
| 1295 | + ) ); |
|
| 1296 | + |
|
| 1297 | + if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1298 | + return; |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1302 | + |
|
| 1303 | + wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1304 | + wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1305 | + 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 ); |
|
| 1306 | + |
|
| 1307 | + // localized module data |
|
| 1308 | + $localize_modulesAdmin = array( |
|
| 1309 | + 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1310 | + 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1311 | + ); |
|
| 1312 | + |
|
| 1313 | + wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * Load admin CSS |
|
| 1318 | + * |
|
| 1319 | + * @since 1.8.0 |
|
| 1320 | + * |
|
| 1321 | + * @return void |
|
| 1322 | + */ |
|
| 1323 | + public function admin_enqueue_styles() { |
|
| 1324 | + |
|
| 1325 | + wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1326 | + wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1327 | + |
|
| 1328 | + } |
|
| 1329 | + |
|
| 1330 | + /** |
|
| 1331 | + * Show the title modules on the single course template. |
|
| 1332 | + * |
|
| 1333 | + * Function is hooked into sensei_single_course_modules_before. |
|
| 1334 | + * |
|
| 1335 | + * @since 1.8.0 |
|
| 1336 | + * @return void |
|
| 1337 | + */ |
|
| 1338 | + public function course_modules_title( ) { |
|
| 1339 | + |
|
| 1340 | + if( sensei_module_has_lessons() ){ |
|
| 1341 | + |
|
| 1342 | + echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1343 | + |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + /** |
|
| 1349 | + * Display the single course modules content this will only show |
|
| 1350 | + * if the course has modules. |
|
| 1351 | + * |
|
| 1352 | + * @since 1.8.0 |
|
| 1353 | + * @return void |
|
| 1354 | + */ |
|
| 1355 | + public function load_course_module_content_template(){ |
|
| 1356 | + |
|
| 1357 | + if ( ! is_singular( 'course' ) ) { |
|
| 1358 | + return; |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + // load backwards compatible template name if it exists in the users theme |
|
| 1362 | + $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1363 | + if( $located_template ){ |
|
| 1364 | + |
|
| 1365 | + Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1366 | + return; |
|
| 1367 | + |
|
| 1368 | + } |
|
| 1369 | + |
|
| 1370 | + Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1371 | + |
|
| 1372 | + } // end course_module_content |
|
| 1373 | + |
|
| 1374 | + /** |
|
| 1375 | + * Returns all lessons for the given module ID |
|
| 1376 | + * |
|
| 1377 | + * @since 1.8.0 |
|
| 1378 | + * |
|
| 1379 | + * @param $course_id |
|
| 1380 | + * @param $term_id |
|
| 1381 | + * @return array $lessons |
|
| 1382 | + */ |
|
| 1383 | + public function get_lessons( $course_id , $term_id ){ |
|
| 1384 | + |
|
| 1385 | + $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 1386 | + |
|
| 1387 | + if( isset( $lesson_query->posts ) ){ |
|
| 1388 | + |
|
| 1389 | + return $lesson_query->posts; |
|
| 1390 | + |
|
| 1391 | + }else{ |
|
| 1392 | + |
|
| 1393 | + return array(); |
|
| 1394 | + |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + } // end get lessons |
|
| 1398 | + |
|
| 1399 | + /** |
|
| 1400 | + * Returns all lessons for the given module ID |
|
| 1401 | + * |
|
| 1402 | + * @since 1.8.0 |
|
| 1403 | + * |
|
| 1404 | + * @param $course_id |
|
| 1405 | + * @param $term_id |
|
| 1406 | + * @return WP_Query $lessons_query |
|
| 1407 | + */ |
|
| 1408 | + public function get_lessons_query( $course_id , $term_id ){ |
|
| 1409 | + |
|
| 1410 | + if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1411 | + |
|
| 1412 | + return array(); |
|
| 1413 | + |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + $args = array( |
|
| 1417 | + 'post_type' => 'lesson', |
|
| 1418 | + 'post_status' => 'publish', |
|
| 1419 | + 'posts_per_page' => -1, |
|
| 1420 | + 'meta_query' => array( |
|
| 1421 | + array( |
|
| 1422 | + 'key' => '_lesson_course', |
|
| 1423 | + 'value' => intval($course_id), |
|
| 1424 | + 'compare' => '=' |
|
| 1425 | + ) |
|
| 1426 | + ), |
|
| 1427 | + 'tax_query' => array( |
|
| 1428 | + array( |
|
| 1429 | + 'taxonomy' => 'module', |
|
| 1430 | + 'field' => 'id', |
|
| 1431 | + 'terms' => intval( $term_id ) |
|
| 1432 | + ) |
|
| 1433 | + ), |
|
| 1434 | + 'orderby' => 'menu_order', |
|
| 1435 | + 'order' => 'ASC', |
|
| 1436 | + 'suppress_filters' => 0 |
|
| 1437 | + ); |
|
| 1438 | + |
|
| 1439 | + if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1440 | + $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1441 | + $args['orderby'] = 'meta_value_num date'; |
|
| 1442 | + } |
|
| 1443 | + |
|
| 1444 | + $lessons_query = new WP_Query( $args ); |
|
| 1445 | + |
|
| 1446 | + return $lessons_query; |
|
| 1447 | + |
|
| 1448 | + } // end get lessons |
|
| 1449 | + |
|
| 1450 | + /** |
|
| 1451 | + * Find the lesson in the given course that doesn't belong |
|
| 1452 | + * to any of the courses modules |
|
| 1453 | + * |
|
| 1454 | + * |
|
| 1455 | + * @param $course_id |
|
| 1456 | + * |
|
| 1457 | + * @return array $non_module_lessons |
|
| 1458 | + */ |
|
| 1459 | + public function get_none_module_lessons( $course_id ){ |
|
| 1460 | + |
|
| 1461 | + $non_module_lessons = array(); |
|
| 1462 | + |
|
| 1463 | + //exit if there is no course id passed in |
|
| 1464 | + if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1465 | + |
|
| 1466 | + return $non_module_lessons; |
|
| 1467 | + } |
|
| 1468 | + |
|
| 1469 | + //save some time and check if we already have the saved |
|
| 1470 | + if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1471 | + |
|
| 1472 | + return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1473 | + |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + // create terms array which must be excluded from other arrays |
|
| 1477 | + $course_modules = $this->get_course_modules( $course_id ); |
|
| 1478 | + |
|
| 1479 | + //exit if there are no module on this course |
|
| 1480 | + if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1481 | + |
|
| 1482 | + return Sensei()->course->course_lessons( $course_id ); |
|
| 1483 | + |
|
| 1484 | + } |
|
| 1485 | + |
|
| 1486 | + $terms = array(); |
|
| 1487 | + foreach( $course_modules as $module ){ |
|
| 1488 | + |
|
| 1489 | + array_push( $terms , $module->term_id ); |
|
| 1490 | + |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + $args = array( |
|
| 1494 | + 'post_type' => 'lesson', |
|
| 1495 | + 'post_status' => 'publish', |
|
| 1496 | + 'posts_per_page' => -1, |
|
| 1497 | + 'meta_query' => array( |
|
| 1498 | + array( |
|
| 1499 | + 'key' => '_lesson_course', |
|
| 1500 | + 'value' => intval( $course_id ), |
|
| 1501 | + 'compare' => '=' |
|
| 1502 | + ) |
|
| 1503 | + ), |
|
| 1504 | + 'tax_query' => array( |
|
| 1505 | + array( |
|
| 1506 | + 'taxonomy' => 'module', |
|
| 1507 | + 'field' => 'id', |
|
| 1508 | + 'terms' => $terms, |
|
| 1509 | + 'operator' => 'NOT IN' |
|
| 1510 | + ) |
|
| 1511 | + ), |
|
| 1512 | + 'orderby' => 'menu_order', |
|
| 1513 | + 'order' => 'ASC', |
|
| 1514 | + 'suppress_filters' => 0 |
|
| 1515 | + ); |
|
| 1516 | + |
|
| 1517 | + $wp_lessons_query = new WP_Query( $args ); |
|
| 1518 | + |
|
| 1519 | + if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1520 | + $non_module_lessons = $wp_lessons_query->get_posts(); |
|
| 1521 | + set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1522 | + } |
|
| 1523 | + |
|
| 1524 | + return $non_module_lessons; |
|
| 1525 | + } // end get_none_module_lessons |
|
| 1526 | + |
|
| 1527 | + /** |
|
| 1528 | + * Register the modules taxonomy |
|
| 1529 | + * |
|
| 1530 | + * @since 1.8.0 |
|
| 1531 | + */ |
|
| 1532 | + public function setup_modules_taxonomy(){ |
|
| 1533 | + |
|
| 1534 | + $labels = array( |
|
| 1535 | + 'name' => __('Modules', 'woothemes-sensei'), |
|
| 1536 | + 'singular_name' => __('Module', 'woothemes-sensei'), |
|
| 1537 | + 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
| 1538 | + 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
| 1539 | + 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
| 1540 | + 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
| 1541 | + 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
| 1542 | + 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
| 1543 | + 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
| 1544 | + 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
| 1545 | + 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
| 1546 | + ); |
|
| 1547 | + |
|
| 1548 | + /** |
|
| 1549 | + * Filter to alter the Sensei Modules rewrite slug |
|
| 1550 | + * |
|
| 1551 | + * @since 1.8.0 |
|
| 1552 | + * @param string default 'modules' |
|
| 1553 | + */ |
|
| 1554 | + $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
| 1555 | + |
|
| 1556 | + $args = array( |
|
| 1557 | + 'public' => true, |
|
| 1558 | + 'hierarchical' => true, |
|
| 1559 | + 'show_admin_column' => true, |
|
| 1560 | + 'capabilities' => array( |
|
| 1561 | + 'manage_terms' => 'manage_categories', |
|
| 1562 | + 'edit_terms' => 'edit_courses', |
|
| 1563 | + 'delete_terms' => 'manage_categories', |
|
| 1564 | + 'assign_terms' => 'edit_courses' |
|
| 1565 | + ), |
|
| 1566 | + 'show_in_nav_menus' => false, |
|
| 1567 | + 'show_in_quick_edit' => false, |
|
| 1568 | + 'show_ui' => true, |
|
| 1569 | + 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1570 | + 'labels' => $labels |
|
| 1571 | + ); |
|
| 1572 | + |
|
| 1573 | + register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1574 | + |
|
| 1575 | + }// end setup_modules_taxonomy |
|
| 1576 | + |
|
| 1577 | + /** |
|
| 1578 | + * When the wants to edit the lesson modules redirect them to the course modules. |
|
| 1579 | + * |
|
| 1580 | + * This function is hooked into the admin_menu |
|
| 1581 | + * |
|
| 1582 | + * @since 1.8.0 |
|
| 1583 | + * @return void |
|
| 1584 | + */ |
|
| 1585 | + function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1586 | + |
|
| 1587 | + global $typenow , $taxnow; |
|
| 1588 | + |
|
| 1589 | + if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1590 | + wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + }// end redirect to course taxonomy |
|
| 1594 | + |
|
| 1595 | + /** |
|
| 1596 | + * Completely remove the module menu item under lessons. |
|
| 1597 | + * |
|
| 1598 | + * This function is hooked into the admin_menu |
|
| 1599 | + * |
|
| 1600 | + * @since 1.8.0 |
|
| 1601 | + * @return void |
|
| 1602 | + */ |
|
| 1603 | + public function remove_lessons_menu_model_taxonomy(){ |
|
| 1604 | + global $submenu; |
|
| 1605 | + |
|
| 1606 | + if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1607 | + return; // exit |
|
| 1608 | + } |
|
| 1609 | + |
|
| 1610 | + $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
| 1611 | + foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1612 | + |
|
| 1613 | + if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1614 | + unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1615 | + } |
|
| 1616 | + } |
|
| 1617 | + |
|
| 1618 | + }// end remove lesson module tax |
|
| 1619 | + |
|
| 1620 | + /** |
|
| 1621 | + * Completely remove the second modules under courses |
|
| 1622 | + * |
|
| 1623 | + * This function is hooked into the admin_menu |
|
| 1624 | + * |
|
| 1625 | + * @since 1.8.0 |
|
| 1626 | + * @return void |
|
| 1627 | + */ |
|
| 1628 | + public function remove_courses_menu_model_taxonomy(){ |
|
| 1629 | + global $submenu; |
|
| 1630 | + |
|
| 1631 | + if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1632 | + return; // exit |
|
| 1633 | + } |
|
| 1315 | 1634 | |
| 1316 | - /** |
|
| 1317 | - * Load admin CSS |
|
| 1318 | - * |
|
| 1319 | - * @since 1.8.0 |
|
| 1320 | - * |
|
| 1321 | - * @return void |
|
| 1322 | - */ |
|
| 1323 | - public function admin_enqueue_styles() { |
|
| 1324 | - |
|
| 1325 | - wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1326 | - wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1327 | - |
|
| 1328 | - } |
|
| 1329 | - |
|
| 1330 | - /** |
|
| 1331 | - * Show the title modules on the single course template. |
|
| 1332 | - * |
|
| 1333 | - * Function is hooked into sensei_single_course_modules_before. |
|
| 1334 | - * |
|
| 1335 | - * @since 1.8.0 |
|
| 1336 | - * @return void |
|
| 1337 | - */ |
|
| 1338 | - public function course_modules_title( ) { |
|
| 1339 | - |
|
| 1340 | - if( sensei_module_has_lessons() ){ |
|
| 1341 | - |
|
| 1342 | - echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1343 | - |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - /** |
|
| 1349 | - * Display the single course modules content this will only show |
|
| 1350 | - * if the course has modules. |
|
| 1351 | - * |
|
| 1352 | - * @since 1.8.0 |
|
| 1353 | - * @return void |
|
| 1354 | - */ |
|
| 1355 | - public function load_course_module_content_template(){ |
|
| 1356 | - |
|
| 1357 | - if ( ! is_singular( 'course' ) ) { |
|
| 1358 | - return; |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - // load backwards compatible template name if it exists in the users theme |
|
| 1362 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1363 | - if( $located_template ){ |
|
| 1364 | - |
|
| 1365 | - Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1366 | - return; |
|
| 1367 | - |
|
| 1368 | - } |
|
| 1369 | - |
|
| 1370 | - Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1371 | - |
|
| 1372 | - } // end course_module_content |
|
| 1373 | - |
|
| 1374 | - /** |
|
| 1375 | - * Returns all lessons for the given module ID |
|
| 1376 | - * |
|
| 1377 | - * @since 1.8.0 |
|
| 1378 | - * |
|
| 1379 | - * @param $course_id |
|
| 1380 | - * @param $term_id |
|
| 1381 | - * @return array $lessons |
|
| 1382 | - */ |
|
| 1383 | - public function get_lessons( $course_id , $term_id ){ |
|
| 1384 | - |
|
| 1385 | - $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 1386 | - |
|
| 1387 | - if( isset( $lesson_query->posts ) ){ |
|
| 1635 | + $course_main_menu = $submenu['edit.php?post_type=course']; |
|
| 1636 | + foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1388 | 1637 | |
| 1389 | - return $lesson_query->posts; |
|
| 1638 | + if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1639 | + unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1640 | + } |
|
| 1641 | + } |
|
| 1390 | 1642 | |
| 1391 | - }else{ |
|
| 1643 | + }// end remove courses module tax |
|
| 1392 | 1644 | |
| 1393 | - return array(); |
|
| 1645 | + /** |
|
| 1646 | + * Determine the author of a module term term by looking at |
|
| 1647 | + * the prefixed author id. This function will query the full term object. |
|
| 1648 | + * Will return the admin user author could not be determined. |
|
| 1649 | + * |
|
| 1650 | + * @since 1.8.0 |
|
| 1651 | + * |
|
| 1652 | + * @param string $term_name |
|
| 1653 | + * @return array $owners { type WP_User }. Empty array if none if found. |
|
| 1654 | + */ |
|
| 1655 | + public static function get_term_authors( $term_name ){ |
|
| 1394 | 1656 | |
| 1395 | - } |
|
| 1657 | + $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1396 | 1658 | |
| 1397 | - } // end get lessons |
|
| 1659 | + $owners = array(); |
|
| 1660 | + if( empty( $terms ) ){ |
|
| 1398 | 1661 | |
| 1399 | - /** |
|
| 1400 | - * Returns all lessons for the given module ID |
|
| 1401 | - * |
|
| 1402 | - * @since 1.8.0 |
|
| 1403 | - * |
|
| 1404 | - * @param $course_id |
|
| 1405 | - * @param $term_id |
|
| 1406 | - * @return WP_Query $lessons_query |
|
| 1407 | - */ |
|
| 1408 | - public function get_lessons_query( $course_id , $term_id ){ |
|
| 1409 | - |
|
| 1410 | - if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1411 | - |
|
| 1412 | - return array(); |
|
| 1413 | - |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - $args = array( |
|
| 1417 | - 'post_type' => 'lesson', |
|
| 1418 | - 'post_status' => 'publish', |
|
| 1419 | - 'posts_per_page' => -1, |
|
| 1420 | - 'meta_query' => array( |
|
| 1421 | - array( |
|
| 1422 | - 'key' => '_lesson_course', |
|
| 1423 | - 'value' => intval($course_id), |
|
| 1424 | - 'compare' => '=' |
|
| 1425 | - ) |
|
| 1426 | - ), |
|
| 1427 | - 'tax_query' => array( |
|
| 1428 | - array( |
|
| 1429 | - 'taxonomy' => 'module', |
|
| 1430 | - 'field' => 'id', |
|
| 1431 | - 'terms' => intval( $term_id ) |
|
| 1432 | - ) |
|
| 1433 | - ), |
|
| 1434 | - 'orderby' => 'menu_order', |
|
| 1435 | - 'order' => 'ASC', |
|
| 1436 | - 'suppress_filters' => 0 |
|
| 1437 | - ); |
|
| 1438 | - |
|
| 1439 | - if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1440 | - $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1441 | - $args['orderby'] = 'meta_value_num date'; |
|
| 1442 | - } |
|
| 1443 | - |
|
| 1444 | - $lessons_query = new WP_Query( $args ); |
|
| 1445 | - |
|
| 1446 | - return $lessons_query; |
|
| 1447 | - |
|
| 1448 | - } // end get lessons |
|
| 1449 | - |
|
| 1450 | - /** |
|
| 1451 | - * Find the lesson in the given course that doesn't belong |
|
| 1452 | - * to any of the courses modules |
|
| 1453 | - * |
|
| 1454 | - * |
|
| 1455 | - * @param $course_id |
|
| 1456 | - * |
|
| 1457 | - * @return array $non_module_lessons |
|
| 1458 | - */ |
|
| 1459 | - public function get_none_module_lessons( $course_id ){ |
|
| 1460 | - |
|
| 1461 | - $non_module_lessons = array(); |
|
| 1462 | - |
|
| 1463 | - //exit if there is no course id passed in |
|
| 1464 | - if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1465 | - |
|
| 1466 | - return $non_module_lessons; |
|
| 1467 | - } |
|
| 1468 | - |
|
| 1469 | - //save some time and check if we already have the saved |
|
| 1470 | - if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1471 | - |
|
| 1472 | - return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1473 | - |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - // create terms array which must be excluded from other arrays |
|
| 1477 | - $course_modules = $this->get_course_modules( $course_id ); |
|
| 1478 | - |
|
| 1479 | - //exit if there are no module on this course |
|
| 1480 | - if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1481 | - |
|
| 1482 | - return Sensei()->course->course_lessons( $course_id ); |
|
| 1483 | - |
|
| 1484 | - } |
|
| 1485 | - |
|
| 1486 | - $terms = array(); |
|
| 1487 | - foreach( $course_modules as $module ){ |
|
| 1488 | - |
|
| 1489 | - array_push( $terms , $module->term_id ); |
|
| 1490 | - |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - $args = array( |
|
| 1494 | - 'post_type' => 'lesson', |
|
| 1495 | - 'post_status' => 'publish', |
|
| 1496 | - 'posts_per_page' => -1, |
|
| 1497 | - 'meta_query' => array( |
|
| 1498 | - array( |
|
| 1499 | - 'key' => '_lesson_course', |
|
| 1500 | - 'value' => intval( $course_id ), |
|
| 1501 | - 'compare' => '=' |
|
| 1502 | - ) |
|
| 1503 | - ), |
|
| 1504 | - 'tax_query' => array( |
|
| 1505 | - array( |
|
| 1506 | - 'taxonomy' => 'module', |
|
| 1507 | - 'field' => 'id', |
|
| 1508 | - 'terms' => $terms, |
|
| 1509 | - 'operator' => 'NOT IN' |
|
| 1510 | - ) |
|
| 1511 | - ), |
|
| 1512 | - 'orderby' => 'menu_order', |
|
| 1513 | - 'order' => 'ASC', |
|
| 1514 | - 'suppress_filters' => 0 |
|
| 1515 | - ); |
|
| 1516 | - |
|
| 1517 | - $wp_lessons_query = new WP_Query( $args ); |
|
| 1518 | - |
|
| 1519 | - if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1520 | - $non_module_lessons = $wp_lessons_query->get_posts(); |
|
| 1521 | - set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1522 | - } |
|
| 1523 | - |
|
| 1524 | - return $non_module_lessons; |
|
| 1525 | - } // end get_none_module_lessons |
|
| 1526 | - |
|
| 1527 | - /** |
|
| 1528 | - * Register the modules taxonomy |
|
| 1529 | - * |
|
| 1530 | - * @since 1.8.0 |
|
| 1531 | - */ |
|
| 1532 | - public function setup_modules_taxonomy(){ |
|
| 1533 | - |
|
| 1534 | - $labels = array( |
|
| 1535 | - 'name' => __('Modules', 'woothemes-sensei'), |
|
| 1536 | - 'singular_name' => __('Module', 'woothemes-sensei'), |
|
| 1537 | - 'search_items' => __('Search Modules', 'woothemes-sensei'), |
|
| 1538 | - 'all_items' => __('All Modules', 'woothemes-sensei'), |
|
| 1539 | - 'parent_item' => __('Parent Module', 'woothemes-sensei'), |
|
| 1540 | - 'parent_item_colon' => __('Parent Module:', 'woothemes-sensei'), |
|
| 1541 | - 'edit_item' => __('Edit Module', 'woothemes-sensei'), |
|
| 1542 | - 'update_item' => __('Update Module', 'woothemes-sensei'), |
|
| 1543 | - 'add_new_item' => __('Add New Module', 'woothemes-sensei'), |
|
| 1544 | - 'new_item_name' => __('New Module Name', 'woothemes-sensei'), |
|
| 1545 | - 'menu_name' => __('Modules', 'woothemes-sensei'), |
|
| 1546 | - ); |
|
| 1547 | - |
|
| 1548 | - /** |
|
| 1549 | - * Filter to alter the Sensei Modules rewrite slug |
|
| 1550 | - * |
|
| 1551 | - * @since 1.8.0 |
|
| 1552 | - * @param string default 'modules' |
|
| 1553 | - */ |
|
| 1554 | - $modules_rewrite_slug = apply_filters('sensei_module_slug', 'modules'); |
|
| 1555 | - |
|
| 1556 | - $args = array( |
|
| 1557 | - 'public' => true, |
|
| 1558 | - 'hierarchical' => true, |
|
| 1559 | - 'show_admin_column' => true, |
|
| 1560 | - 'capabilities' => array( |
|
| 1561 | - 'manage_terms' => 'manage_categories', |
|
| 1562 | - 'edit_terms' => 'edit_courses', |
|
| 1563 | - 'delete_terms' => 'manage_categories', |
|
| 1564 | - 'assign_terms' => 'edit_courses' |
|
| 1565 | - ), |
|
| 1566 | - 'show_in_nav_menus' => false, |
|
| 1567 | - 'show_in_quick_edit' => false, |
|
| 1568 | - 'show_ui' => true, |
|
| 1569 | - 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1570 | - 'labels' => $labels |
|
| 1571 | - ); |
|
| 1572 | - |
|
| 1573 | - register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1574 | - |
|
| 1575 | - }// end setup_modules_taxonomy |
|
| 1576 | - |
|
| 1577 | - /** |
|
| 1578 | - * When the wants to edit the lesson modules redirect them to the course modules. |
|
| 1579 | - * |
|
| 1580 | - * This function is hooked into the admin_menu |
|
| 1581 | - * |
|
| 1582 | - * @since 1.8.0 |
|
| 1583 | - * @return void |
|
| 1584 | - */ |
|
| 1585 | - function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1586 | - |
|
| 1587 | - global $typenow , $taxnow; |
|
| 1588 | - |
|
| 1589 | - if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1590 | - wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - }// end redirect to course taxonomy |
|
| 1594 | - |
|
| 1595 | - /** |
|
| 1596 | - * Completely remove the module menu item under lessons. |
|
| 1597 | - * |
|
| 1598 | - * This function is hooked into the admin_menu |
|
| 1599 | - * |
|
| 1600 | - * @since 1.8.0 |
|
| 1601 | - * @return void |
|
| 1602 | - */ |
|
| 1603 | - public function remove_lessons_menu_model_taxonomy(){ |
|
| 1604 | - global $submenu; |
|
| 1605 | - |
|
| 1606 | - if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1607 | - return; // exit |
|
| 1608 | - } |
|
| 1609 | - |
|
| 1610 | - $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
|
| 1611 | - foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1612 | - |
|
| 1613 | - if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1614 | - unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1615 | - } |
|
| 1616 | - } |
|
| 1617 | - |
|
| 1618 | - }// end remove lesson module tax |
|
| 1619 | - |
|
| 1620 | - /** |
|
| 1621 | - * Completely remove the second modules under courses |
|
| 1622 | - * |
|
| 1623 | - * This function is hooked into the admin_menu |
|
| 1624 | - * |
|
| 1625 | - * @since 1.8.0 |
|
| 1626 | - * @return void |
|
| 1627 | - */ |
|
| 1628 | - public function remove_courses_menu_model_taxonomy(){ |
|
| 1629 | - global $submenu; |
|
| 1630 | - |
|
| 1631 | - if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1632 | - return; // exit |
|
| 1633 | - } |
|
| 1634 | - |
|
| 1635 | - $course_main_menu = $submenu['edit.php?post_type=course']; |
|
| 1636 | - foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1637 | - |
|
| 1638 | - if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1639 | - unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1640 | - } |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - }// end remove courses module tax |
|
| 1644 | - |
|
| 1645 | - /** |
|
| 1646 | - * Determine the author of a module term term by looking at |
|
| 1647 | - * the prefixed author id. This function will query the full term object. |
|
| 1648 | - * Will return the admin user author could not be determined. |
|
| 1649 | - * |
|
| 1650 | - * @since 1.8.0 |
|
| 1651 | - * |
|
| 1652 | - * @param string $term_name |
|
| 1653 | - * @return array $owners { type WP_User }. Empty array if none if found. |
|
| 1654 | - */ |
|
| 1655 | - public static function get_term_authors( $term_name ){ |
|
| 1656 | - |
|
| 1657 | - $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1658 | - |
|
| 1659 | - $owners = array(); |
|
| 1660 | - if( empty( $terms ) ){ |
|
| 1661 | - |
|
| 1662 | - return $owners; |
|
| 1662 | + return $owners; |
|
| 1663 | 1663 | |
| 1664 | - } |
|
| 1664 | + } |
|
| 1665 | 1665 | |
| 1666 | - // setup the admin user |
|
| 1666 | + // setup the admin user |
|
| 1667 | 1667 | |
| 1668 | 1668 | |
| 1669 | - //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
| 1670 | - foreach( $terms as $term){ |
|
| 1671 | - if( $term->name == $term_name ){ |
|
| 1669 | + //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
|
| 1670 | + foreach( $terms as $term){ |
|
| 1671 | + if( $term->name == $term_name ){ |
|
| 1672 | 1672 | |
| 1673 | - // look for the author in the slug |
|
| 1674 | - $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1673 | + // look for the author in the slug |
|
| 1674 | + $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1675 | 1675 | |
| 1676 | - }// end if term name |
|
| 1676 | + }// end if term name |
|
| 1677 | 1677 | |
| 1678 | - } // end for each |
|
| 1678 | + } // end for each |
|
| 1679 | 1679 | |
| 1680 | - return $owners; |
|
| 1680 | + return $owners; |
|
| 1681 | 1681 | |
| 1682 | - }// end get_term_author |
|
| 1682 | + }// end get_term_author |
|
| 1683 | 1683 | |
| 1684 | - /** |
|
| 1685 | - * Looks at a term slug and figures out |
|
| 1686 | - * which author created the slug. The author was |
|
| 1687 | - * appended when the user saved the module term in the course edit |
|
| 1688 | - * screen. |
|
| 1689 | - * |
|
| 1690 | - * @since 1.8.0 |
|
| 1691 | - * |
|
| 1692 | - * @param $slug |
|
| 1693 | - * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
| 1694 | - */ |
|
| 1695 | - public static function get_term_author( $slug='' ){ |
|
| 1684 | + /** |
|
| 1685 | + * Looks at a term slug and figures out |
|
| 1686 | + * which author created the slug. The author was |
|
| 1687 | + * appended when the user saved the module term in the course edit |
|
| 1688 | + * screen. |
|
| 1689 | + * |
|
| 1690 | + * @since 1.8.0 |
|
| 1691 | + * |
|
| 1692 | + * @param $slug |
|
| 1693 | + * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
|
| 1694 | + */ |
|
| 1695 | + public static function get_term_author( $slug='' ){ |
|
| 1696 | 1696 | |
| 1697 | - $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1697 | + $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1698 | 1698 | |
| 1699 | - if( empty( $slug ) ){ |
|
| 1699 | + if( empty( $slug ) ){ |
|
| 1700 | 1700 | |
| 1701 | - return $term_owner; |
|
| 1701 | + return $term_owner; |
|
| 1702 | 1702 | |
| 1703 | - } |
|
| 1703 | + } |
|
| 1704 | 1704 | |
| 1705 | - // look for the author in the slug |
|
| 1706 | - $slug_parts = explode( '-', $slug ); |
|
| 1705 | + // look for the author in the slug |
|
| 1706 | + $slug_parts = explode( '-', $slug ); |
|
| 1707 | 1707 | |
| 1708 | - if( count( $slug_parts ) > 1 ){ |
|
| 1708 | + if( count( $slug_parts ) > 1 ){ |
|
| 1709 | 1709 | |
| 1710 | - // get the user data |
|
| 1711 | - $possible_user_id = $slug_parts[0]; |
|
| 1712 | - $author = get_userdata( $possible_user_id ); |
|
| 1710 | + // get the user data |
|
| 1711 | + $possible_user_id = $slug_parts[0]; |
|
| 1712 | + $author = get_userdata( $possible_user_id ); |
|
| 1713 | 1713 | |
| 1714 | - // if the user doesnt exist for the first part of the slug |
|
| 1715 | - // then this slug was also created by admin |
|
| 1716 | - if( is_a( $author, 'WP_User' ) ){ |
|
| 1714 | + // if the user doesnt exist for the first part of the slug |
|
| 1715 | + // then this slug was also created by admin |
|
| 1716 | + if( is_a( $author, 'WP_User' ) ){ |
|
| 1717 | 1717 | |
| 1718 | - $term_owner = $author; |
|
| 1718 | + $term_owner = $author; |
|
| 1719 | 1719 | |
| 1720 | - } |
|
| 1721 | - } |
|
| 1720 | + } |
|
| 1721 | + } |
|
| 1722 | 1722 | |
| 1723 | - return $term_owner; |
|
| 1724 | - } |
|
| 1723 | + return $term_owner; |
|
| 1724 | + } |
|
| 1725 | 1725 | |
| 1726 | - /** |
|
| 1727 | - * Display the Sensei modules taxonomy terms metabox |
|
| 1728 | - * |
|
| 1729 | - * @since 1.8.0 |
|
| 1730 | - * |
|
| 1731 | - * @hooked into add_meta_box |
|
| 1732 | - * |
|
| 1733 | - * @param WP_Post $post Post object. |
|
| 1734 | - */ |
|
| 1735 | - public function course_module_metabox( $post ) { |
|
| 1726 | + /** |
|
| 1727 | + * Display the Sensei modules taxonomy terms metabox |
|
| 1728 | + * |
|
| 1729 | + * @since 1.8.0 |
|
| 1730 | + * |
|
| 1731 | + * @hooked into add_meta_box |
|
| 1732 | + * |
|
| 1733 | + * @param WP_Post $post Post object. |
|
| 1734 | + */ |
|
| 1735 | + public function course_module_metabox( $post ) { |
|
| 1736 | 1736 | |
| 1737 | - $tax_name = 'module'; |
|
| 1738 | - $taxonomy = get_taxonomy( 'module' ); |
|
| 1737 | + $tax_name = 'module'; |
|
| 1738 | + $taxonomy = get_taxonomy( 'module' ); |
|
| 1739 | 1739 | |
| 1740 | - ?> |
|
| 1740 | + ?> |
|
| 1741 | 1741 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
| 1742 | 1742 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
| 1743 | 1743 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> |
@@ -1752,9 +1752,9 @@ discard block |
||
| 1752 | 1752 | |
| 1753 | 1753 | <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> |
| 1754 | 1754 | <?php |
| 1755 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1756 | - 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. |
|
| 1757 | - ?> |
|
| 1755 | + $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1756 | + 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. |
|
| 1757 | + ?> |
|
| 1758 | 1758 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> |
| 1759 | 1759 | <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?> |
| 1760 | 1760 | </ul> |
@@ -1764,9 +1764,9 @@ discard block |
||
| 1764 | 1764 | <h4> |
| 1765 | 1765 | <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> |
| 1766 | 1766 | <?php |
| 1767 | - /* translators: %s: add new taxonomy label */ |
|
| 1768 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1769 | - ?> |
|
| 1767 | + /* translators: %s: add new taxonomy label */ |
|
| 1768 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1769 | + ?> |
|
| 1770 | 1770 | </a> |
| 1771 | 1771 | </h4> |
| 1772 | 1772 | <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
@@ -1781,331 +1781,331 @@ discard block |
||
| 1781 | 1781 | </div> |
| 1782 | 1782 | <?php |
| 1783 | 1783 | |
| 1784 | - } // end course_module_metabox |
|
| 1784 | + } // end course_module_metabox |
|
| 1785 | 1785 | |
| 1786 | 1786 | |
| 1787 | - /** |
|
| 1788 | - * Submits a new module term prefixed with the |
|
| 1789 | - * the current author id. |
|
| 1790 | - * |
|
| 1791 | - * @since 1.8.0 |
|
| 1792 | - */ |
|
| 1793 | - public static function add_new_module_term( ) { |
|
| 1787 | + /** |
|
| 1788 | + * Submits a new module term prefixed with the |
|
| 1789 | + * the current author id. |
|
| 1790 | + * |
|
| 1791 | + * @since 1.8.0 |
|
| 1792 | + */ |
|
| 1793 | + public static function add_new_module_term( ) { |
|
| 1794 | 1794 | |
| 1795 | 1795 | |
| 1796 | - if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1797 | - wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1798 | - } |
|
| 1796 | + if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1797 | + wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1798 | + } |
|
| 1799 | 1799 | |
| 1800 | - // get the term an create the new term storing infomration |
|
| 1801 | - $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1800 | + // get the term an create the new term storing infomration |
|
| 1801 | + $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1802 | 1802 | |
| 1803 | - if( current_user_can('manage_options' ) ) { |
|
| 1803 | + if( current_user_can('manage_options' ) ) { |
|
| 1804 | 1804 | |
| 1805 | - $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1805 | + $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1806 | 1806 | |
| 1807 | - } else { |
|
| 1807 | + } else { |
|
| 1808 | 1808 | |
| 1809 | - $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1809 | + $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1810 | 1810 | |
| 1811 | - } |
|
| 1811 | + } |
|
| 1812 | 1812 | |
| 1813 | - $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1813 | + $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1814 | 1814 | |
| 1815 | - // save the term |
|
| 1816 | - $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1815 | + // save the term |
|
| 1816 | + $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1817 | 1817 | |
| 1818 | - // send error for all errors except term exits |
|
| 1819 | - if( is_wp_error( $slug ) ){ |
|
| 1818 | + // send error for all errors except term exits |
|
| 1819 | + if( is_wp_error( $slug ) ){ |
|
| 1820 | 1820 | |
| 1821 | - // prepare for possible term name and id to be passed down if term exists |
|
| 1822 | - $term_data = array(); |
|
| 1821 | + // prepare for possible term name and id to be passed down if term exists |
|
| 1822 | + $term_data = array(); |
|
| 1823 | 1823 | |
| 1824 | - // if term exists also send back the term name and id |
|
| 1825 | - if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1824 | + // if term exists also send back the term name and id |
|
| 1825 | + if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1826 | 1826 | |
| 1827 | - $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1828 | - $term_data['name'] = $term_name; |
|
| 1829 | - $term_data['id'] = $term->term_id; |
|
| 1827 | + $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1828 | + $term_data['name'] = $term_name; |
|
| 1829 | + $term_data['id'] = $term->term_id; |
|
| 1830 | 1830 | |
| 1831 | - // set the object terms |
|
| 1832 | - wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1833 | - } |
|
| 1831 | + // set the object terms |
|
| 1832 | + wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1833 | + } |
|
| 1834 | 1834 | |
| 1835 | - wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1835 | + wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1836 | 1836 | |
| 1837 | - } |
|
| 1837 | + } |
|
| 1838 | 1838 | |
| 1839 | - //make sure the new term is checked for this course |
|
| 1839 | + //make sure the new term is checked for this course |
|
| 1840 | 1840 | |
| 1841 | - wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1841 | + wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1842 | 1842 | |
| 1843 | - // Handle request then generate response using WP_Ajax_Response |
|
| 1844 | - wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1843 | + // Handle request then generate response using WP_Ajax_Response |
|
| 1844 | + wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1845 | 1845 | |
| 1846 | - } |
|
| 1846 | + } |
|
| 1847 | 1847 | |
| 1848 | - /** |
|
| 1849 | - * Limit the course module metabox |
|
| 1850 | - * term list to only those on courses belonging to current teacher. |
|
| 1851 | - * |
|
| 1852 | - * Hooked into 'get_terms' |
|
| 1853 | - * |
|
| 1854 | - * @since 1.8.0 |
|
| 1855 | - */ |
|
| 1856 | - public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1848 | + /** |
|
| 1849 | + * Limit the course module metabox |
|
| 1850 | + * term list to only those on courses belonging to current teacher. |
|
| 1851 | + * |
|
| 1852 | + * Hooked into 'get_terms' |
|
| 1853 | + * |
|
| 1854 | + * @since 1.8.0 |
|
| 1855 | + */ |
|
| 1856 | + public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1857 | 1857 | |
| 1858 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1859 | - if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1860 | - return $terms; |
|
| 1861 | - } |
|
| 1858 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1859 | + if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1860 | + return $terms; |
|
| 1861 | + } |
|
| 1862 | 1862 | |
| 1863 | - // avoid infinite call loop |
|
| 1864 | - remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1863 | + // avoid infinite call loop |
|
| 1864 | + remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1865 | 1865 | |
| 1866 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1867 | - if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1868 | - // change only scrub the terms ids form the array keys |
|
| 1869 | - $terms = array_keys( $terms ); |
|
| 1870 | - } |
|
| 1866 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1867 | + if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1868 | + // change only scrub the terms ids form the array keys |
|
| 1869 | + $terms = array_keys( $terms ); |
|
| 1870 | + } |
|
| 1871 | 1871 | |
| 1872 | - $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1872 | + $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1873 | 1873 | |
| 1874 | - // add filter again as removed above |
|
| 1875 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1874 | + // add filter again as removed above |
|
| 1875 | + add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1876 | 1876 | |
| 1877 | - return $teachers_terms; |
|
| 1878 | - }// end filter_module_terms |
|
| 1877 | + return $teachers_terms; |
|
| 1878 | + }// end filter_module_terms |
|
| 1879 | 1879 | |
| 1880 | - /** |
|
| 1881 | - * For the selected items on a course module only return those |
|
| 1882 | - * for the current user. This does not apply to admin and super admin users. |
|
| 1883 | - * |
|
| 1884 | - * hooked into get_object_terms |
|
| 1885 | - * |
|
| 1886 | - * @since 1.8.0 |
|
| 1887 | - */ |
|
| 1888 | - public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1880 | + /** |
|
| 1881 | + * For the selected items on a course module only return those |
|
| 1882 | + * for the current user. This does not apply to admin and super admin users. |
|
| 1883 | + * |
|
| 1884 | + * hooked into get_object_terms |
|
| 1885 | + * |
|
| 1886 | + * @since 1.8.0 |
|
| 1887 | + */ |
|
| 1888 | + public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1889 | 1889 | |
| 1890 | - //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1891 | - if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1892 | - // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
| 1893 | - || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1894 | - return $terms; |
|
| 1895 | - } |
|
| 1890 | + //dont limit for admins and other taxonomies. This should also only apply to admin |
|
| 1891 | + if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1892 | + // only apply this to module only taxonomy queries so 1 taxonomy only: |
|
| 1893 | + || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1894 | + return $terms; |
|
| 1895 | + } |
|
| 1896 | 1896 | |
| 1897 | - $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1897 | + $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1898 | 1898 | |
| 1899 | - // if term objects were passed in send back objects |
|
| 1900 | - // if term id were passed in send that back |
|
| 1901 | - if( is_object( $terms[0] ) ){ |
|
| 1902 | - return $term_objects; |
|
| 1903 | - } |
|
| 1899 | + // if term objects were passed in send back objects |
|
| 1900 | + // if term id were passed in send that back |
|
| 1901 | + if( is_object( $terms[0] ) ){ |
|
| 1902 | + return $term_objects; |
|
| 1903 | + } |
|
| 1904 | 1904 | |
| 1905 | - $terms = array(); |
|
| 1906 | - foreach( $term_objects as $term_object ){ |
|
| 1907 | - $terms[] = $term_object->term_id; |
|
| 1908 | - } |
|
| 1905 | + $terms = array(); |
|
| 1906 | + foreach( $term_objects as $term_object ){ |
|
| 1907 | + $terms[] = $term_object->term_id; |
|
| 1908 | + } |
|
| 1909 | 1909 | |
| 1910 | - return $terms; |
|
| 1910 | + return $terms; |
|
| 1911 | 1911 | |
| 1912 | 1912 | |
| 1913 | - }// end filter_course_selected_terms |
|
| 1913 | + }// end filter_course_selected_terms |
|
| 1914 | 1914 | |
| 1915 | - /** |
|
| 1916 | - * Filter the given terms and only return the |
|
| 1917 | - * terms that belong to the given user id. |
|
| 1918 | - * |
|
| 1919 | - * @since 1.8.0 |
|
| 1920 | - * @param $terms |
|
| 1921 | - * @param $user_id |
|
| 1922 | - * @return array |
|
| 1923 | - */ |
|
| 1924 | - public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1915 | + /** |
|
| 1916 | + * Filter the given terms and only return the |
|
| 1917 | + * terms that belong to the given user id. |
|
| 1918 | + * |
|
| 1919 | + * @since 1.8.0 |
|
| 1920 | + * @param $terms |
|
| 1921 | + * @param $user_id |
|
| 1922 | + * @return array |
|
| 1923 | + */ |
|
| 1924 | + public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1925 | 1925 | |
| 1926 | - $users_terms = array(); |
|
| 1926 | + $users_terms = array(); |
|
| 1927 | 1927 | |
| 1928 | - foreach( $terms as $index => $term ){ |
|
| 1928 | + foreach( $terms as $index => $term ){ |
|
| 1929 | 1929 | |
| 1930 | - if( is_numeric( $term ) ){ |
|
| 1931 | - // the term id was given, get the term object |
|
| 1932 | - $term = get_term( $term, 'module' ); |
|
| 1933 | - } |
|
| 1930 | + if( is_numeric( $term ) ){ |
|
| 1931 | + // the term id was given, get the term object |
|
| 1932 | + $term = get_term( $term, 'module' ); |
|
| 1933 | + } |
|
| 1934 | 1934 | |
| 1935 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1935 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1936 | 1936 | |
| 1937 | - if ( $user_id == $author->ID ) { |
|
| 1938 | - // add the term to the teachers terms |
|
| 1939 | - $users_terms[] = $term; |
|
| 1940 | - } |
|
| 1937 | + if ( $user_id == $author->ID ) { |
|
| 1938 | + // add the term to the teachers terms |
|
| 1939 | + $users_terms[] = $term; |
|
| 1940 | + } |
|
| 1941 | 1941 | |
| 1942 | - } |
|
| 1942 | + } |
|
| 1943 | 1943 | |
| 1944 | - return $users_terms; |
|
| 1944 | + return $users_terms; |
|
| 1945 | 1945 | |
| 1946 | - } // end filter terms by owner |
|
| 1946 | + } // end filter terms by owner |
|
| 1947 | 1947 | |
| 1948 | - /** |
|
| 1949 | - * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
| 1950 | - * This will not add name to terms belonging to admin user. |
|
| 1951 | - * |
|
| 1952 | - * Hooked into 'get_terms' |
|
| 1953 | - * |
|
| 1954 | - * @since 1.8.0 |
|
| 1955 | - */ |
|
| 1956 | - public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1957 | - { |
|
| 1948 | + /** |
|
| 1949 | + * Add the teacher name next to modules. Only works in Admin for Admin users. |
|
| 1950 | + * This will not add name to terms belonging to admin user. |
|
| 1951 | + * |
|
| 1952 | + * Hooked into 'get_terms' |
|
| 1953 | + * |
|
| 1954 | + * @since 1.8.0 |
|
| 1955 | + */ |
|
| 1956 | + public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1957 | + { |
|
| 1958 | 1958 | |
| 1959 | - // only for admin users ont he module taxonomy |
|
| 1960 | - if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1961 | - return $terms; |
|
| 1962 | - } |
|
| 1959 | + // only for admin users ont he module taxonomy |
|
| 1960 | + if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1961 | + return $terms; |
|
| 1962 | + } |
|
| 1963 | 1963 | |
| 1964 | - // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1965 | - // simply return this as wp doesn't need an array of stdObject Term |
|
| 1966 | - if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1964 | + // in certain cases the array is passed in as reference to the parent term_id => parent_id |
|
| 1965 | + // simply return this as wp doesn't need an array of stdObject Term |
|
| 1966 | + if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1967 | 1967 | |
| 1968 | - return $terms; |
|
| 1968 | + return $terms; |
|
| 1969 | 1969 | |
| 1970 | - } |
|
| 1970 | + } |
|
| 1971 | 1971 | |
| 1972 | - // loop through and update all terms adding the author name |
|
| 1973 | - foreach( $terms as $index => $term ){ |
|
| 1972 | + // loop through and update all terms adding the author name |
|
| 1973 | + foreach( $terms as $index => $term ){ |
|
| 1974 | 1974 | |
| 1975 | - if( is_numeric( $term ) ){ |
|
| 1976 | - // the term id was given, get the term object |
|
| 1977 | - $term = get_term( $term, 'module' ); |
|
| 1978 | - } |
|
| 1975 | + if( is_numeric( $term ) ){ |
|
| 1976 | + // the term id was given, get the term object |
|
| 1977 | + $term = get_term( $term, 'module' ); |
|
| 1978 | + } |
|
| 1979 | 1979 | |
| 1980 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1980 | + $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1981 | 1981 | |
| 1982 | - if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) { |
|
| 1983 | - $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1984 | - } |
|
| 1982 | + if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) { |
|
| 1983 | + $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1984 | + } |
|
| 1985 | 1985 | |
| 1986 | - // add the term to the teachers terms |
|
| 1987 | - $users_terms[] = $term; |
|
| 1986 | + // add the term to the teachers terms |
|
| 1987 | + $users_terms[] = $term; |
|
| 1988 | 1988 | |
| 1989 | - } |
|
| 1989 | + } |
|
| 1990 | 1990 | |
| 1991 | - return $users_terms; |
|
| 1992 | - } |
|
| 1991 | + return $users_terms; |
|
| 1992 | + } |
|
| 1993 | 1993 | |
| 1994 | - /** |
|
| 1995 | - * Remove modules metabox that come by default |
|
| 1996 | - * with the modules taxonomy. We are removing this as |
|
| 1997 | - * we have created our own custom meta box. |
|
| 1998 | - */ |
|
| 1999 | - public static function remove_default_modules_box() { |
|
| 1994 | + /** |
|
| 1995 | + * Remove modules metabox that come by default |
|
| 1996 | + * with the modules taxonomy. We are removing this as |
|
| 1997 | + * we have created our own custom meta box. |
|
| 1998 | + */ |
|
| 1999 | + public static function remove_default_modules_box() { |
|
| 2000 | 2000 | |
| 2001 | - remove_meta_box('modulediv', 'course', 'side'); |
|
| 2001 | + remove_meta_box('modulediv', 'course', 'side'); |
|
| 2002 | 2002 | |
| 2003 | - } |
|
| 2003 | + } |
|
| 2004 | 2004 | |
| 2005 | - /** |
|
| 2006 | - * When a course is save make sure to reset the transient set |
|
| 2007 | - * for it when determining the none module lessons. |
|
| 2008 | - * |
|
| 2009 | - * @sine 1.9.0 |
|
| 2010 | - * @param $post_id |
|
| 2011 | - */ |
|
| 2012 | - public static function reset_none_modules_transient ( $post_id ){ |
|
| 2005 | + /** |
|
| 2006 | + * When a course is save make sure to reset the transient set |
|
| 2007 | + * for it when determining the none module lessons. |
|
| 2008 | + * |
|
| 2009 | + * @sine 1.9.0 |
|
| 2010 | + * @param $post_id |
|
| 2011 | + */ |
|
| 2012 | + public static function reset_none_modules_transient ( $post_id ){ |
|
| 2013 | 2013 | |
| 2014 | - // this should only apply to course and lesson post types |
|
| 2015 | - if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2014 | + // this should only apply to course and lesson post types |
|
| 2015 | + if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2016 | 2016 | |
| 2017 | - $course_id = ''; |
|
| 2017 | + $course_id = ''; |
|
| 2018 | 2018 | |
| 2019 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2019 | + if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2020 | 2020 | |
| 2021 | - $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2021 | + $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2022 | 2022 | |
| 2023 | - } |
|
| 2023 | + } |
|
| 2024 | 2024 | |
| 2025 | 2025 | |
| 2026 | - if( !empty( $course_id ) ){ |
|
| 2026 | + if( !empty( $course_id ) ){ |
|
| 2027 | 2027 | |
| 2028 | - delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2028 | + delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2029 | 2029 | |
| 2030 | - } |
|
| 2030 | + } |
|
| 2031 | 2031 | |
| 2032 | - } // end if is a course or a lesson |
|
| 2032 | + } // end if is a course or a lesson |
|
| 2033 | 2033 | |
| 2034 | - } // end reset_none_modules_transient |
|
| 2034 | + } // end reset_none_modules_transient |
|
| 2035 | 2035 | |
| 2036 | - /** |
|
| 2037 | - * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
| 2038 | - * |
|
| 2039 | - * @since 1.9.0 |
|
| 2040 | - * @deprecated since 1.9.0 |
|
| 2041 | - * |
|
| 2042 | - */ |
|
| 2043 | - public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2036 | + /** |
|
| 2037 | + * This function calls the deprecated hook 'sensei_single_course_modules_content' to fire |
|
| 2038 | + * |
|
| 2039 | + * @since 1.9.0 |
|
| 2040 | + * @deprecated since 1.9.0 |
|
| 2041 | + * |
|
| 2042 | + */ |
|
| 2043 | + public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2044 | 2044 | |
| 2045 | - sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2045 | + sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2046 | 2046 | |
| 2047 | - } |
|
| 2047 | + } |
|
| 2048 | 2048 | |
| 2049 | - /** |
|
| 2050 | - * Setup the single course module loop. |
|
| 2051 | - * |
|
| 2052 | - * Setup the global $sensei_modules_loop |
|
| 2053 | - * |
|
| 2054 | - * @since 1.9.0 |
|
| 2055 | - */ |
|
| 2056 | - public static function setup_single_course_module_loop(){ |
|
| 2049 | + /** |
|
| 2050 | + * Setup the single course module loop. |
|
| 2051 | + * |
|
| 2052 | + * Setup the global $sensei_modules_loop |
|
| 2053 | + * |
|
| 2054 | + * @since 1.9.0 |
|
| 2055 | + */ |
|
| 2056 | + public static function setup_single_course_module_loop(){ |
|
| 2057 | 2057 | |
| 2058 | - global $sensei_modules_loop, $post; |
|
| 2059 | - $course_id = $post->ID; |
|
| 2058 | + global $sensei_modules_loop, $post; |
|
| 2059 | + $course_id = $post->ID; |
|
| 2060 | 2060 | |
| 2061 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2061 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2062 | 2062 | |
| 2063 | - //initial setup |
|
| 2064 | - $sensei_modules_loop['total'] = 0; |
|
| 2065 | - $sensei_modules_loop['modules'] = array(); |
|
| 2066 | - $sensei_modules_loop['current'] = -1; |
|
| 2063 | + //initial setup |
|
| 2064 | + $sensei_modules_loop['total'] = 0; |
|
| 2065 | + $sensei_modules_loop['modules'] = array(); |
|
| 2066 | + $sensei_modules_loop['current'] = -1; |
|
| 2067 | 2067 | |
| 2068 | - // exit if this course doesn't have modules |
|
| 2069 | - if( !$modules || empty( $modules ) ){ |
|
| 2070 | - return; |
|
| 2071 | - } |
|
| 2068 | + // exit if this course doesn't have modules |
|
| 2069 | + if( !$modules || empty( $modules ) ){ |
|
| 2070 | + return; |
|
| 2071 | + } |
|
| 2072 | 2072 | |
| 2073 | 2073 | |
| 2074 | - $lessons_in_all_modules = array(); |
|
| 2075 | - foreach( $modules as $term ){ |
|
| 2074 | + $lessons_in_all_modules = array(); |
|
| 2075 | + foreach( $modules as $term ){ |
|
| 2076 | 2076 | |
| 2077 | - $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2078 | - $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2077 | + $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2078 | + $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2079 | 2079 | |
| 2080 | - } |
|
| 2080 | + } |
|
| 2081 | 2081 | |
| 2082 | 2082 | |
| 2083 | - //setup all of the modules loop variables |
|
| 2084 | - $sensei_modules_loop['total'] = count( $modules ); |
|
| 2085 | - $sensei_modules_loop['modules'] = $modules; |
|
| 2086 | - $sensei_modules_loop['current'] = -1; |
|
| 2087 | - $sensei_modules_loop['course_id'] = $course_id; |
|
| 2083 | + //setup all of the modules loop variables |
|
| 2084 | + $sensei_modules_loop['total'] = count( $modules ); |
|
| 2085 | + $sensei_modules_loop['modules'] = $modules; |
|
| 2086 | + $sensei_modules_loop['current'] = -1; |
|
| 2087 | + $sensei_modules_loop['course_id'] = $course_id; |
|
| 2088 | 2088 | |
| 2089 | - }// end setup_single_course_module_loop |
|
| 2089 | + }// end setup_single_course_module_loop |
|
| 2090 | 2090 | |
| 2091 | - /** |
|
| 2092 | - * Tear down the course module loop. |
|
| 2093 | - * |
|
| 2094 | - * @since 1.9.0 |
|
| 2095 | - * |
|
| 2096 | - */ |
|
| 2097 | - public static function teardown_single_course_module_loop(){ |
|
| 2091 | + /** |
|
| 2092 | + * Tear down the course module loop. |
|
| 2093 | + * |
|
| 2094 | + * @since 1.9.0 |
|
| 2095 | + * |
|
| 2096 | + */ |
|
| 2097 | + public static function teardown_single_course_module_loop(){ |
|
| 2098 | 2098 | |
| 2099 | - global $sensei_modules_loop, $wp_query, $post; |
|
| 2099 | + global $sensei_modules_loop, $wp_query, $post; |
|
| 2100 | 2100 | |
| 2101 | - //reset all of the modules loop variables |
|
| 2102 | - $sensei_modules_loop['total'] = 0; |
|
| 2103 | - $sensei_modules_loop['modules'] = array(); |
|
| 2104 | - $sensei_modules_loop['current'] = -1; |
|
| 2101 | + //reset all of the modules loop variables |
|
| 2102 | + $sensei_modules_loop['total'] = 0; |
|
| 2103 | + $sensei_modules_loop['modules'] = array(); |
|
| 2104 | + $sensei_modules_loop['current'] = -1; |
|
| 2105 | 2105 | |
| 2106 | - // set the current course to be the global post again |
|
| 2107 | - wp_reset_query(); |
|
| 2108 | - $post = $wp_query->post; |
|
| 2109 | - }// end teardown_single_course_module_loop |
|
| 2106 | + // set the current course to be the global post again |
|
| 2107 | + wp_reset_query(); |
|
| 2108 | + $post = $wp_query->post; |
|
| 2109 | + }// end teardown_single_course_module_loop |
|
| 2110 | 2110 | |
| 2111 | 2111 | } // end modules class |
@@ -1,6 +1,6 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -1213,12 +1213,12 @@ discard block |
||
| 1213 | 1213 | public function get_course_modules($course_id = 0) |
| 1214 | 1214 | { |
| 1215 | 1215 | $course_id = intval($course_id); |
| 1216 | - if ( empty( $course_id ) ) { |
|
| 1216 | + if (empty($course_id)) { |
|
| 1217 | 1217 | return array(); |
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | // Get modules for course |
| 1221 | - $modules = wp_get_post_terms( $course_id, $this->taxonomy ); |
|
| 1221 | + $modules = wp_get_post_terms($course_id, $this->taxonomy); |
|
| 1222 | 1222 | |
| 1223 | 1223 | // Get custom module order for course |
| 1224 | 1224 | $order = $this->get_course_module_order($course_id); |
@@ -1230,7 +1230,7 @@ discard block |
||
| 1230 | 1230 | // Sort by custom order |
| 1231 | 1231 | $ordered_modules = array(); |
| 1232 | 1232 | $unordered_modules = array(); |
| 1233 | - foreach ( $modules as $module ) { |
|
| 1233 | + foreach ($modules as $module) { |
|
| 1234 | 1234 | $order_key = array_search($module->term_id, $order); |
| 1235 | 1235 | if ($order_key !== false) { |
| 1236 | 1236 | $ordered_modules[$order_key] = $module; |
@@ -1240,16 +1240,16 @@ discard block |
||
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | 1242 | // Order modules correctly |
| 1243 | - ksort( $ordered_modules ); |
|
| 1243 | + ksort($ordered_modules); |
|
| 1244 | 1244 | |
| 1245 | 1245 | // Append modules that have not yet been ordered |
| 1246 | - if ( count($unordered_modules) > 0 ) { |
|
| 1246 | + if (count($unordered_modules) > 0) { |
|
| 1247 | 1247 | $ordered_modules = array_merge($ordered_modules, $unordered_modules); |
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | // remove order key but maintain order |
| 1251 | 1251 | $ordered_modules_with_keys_in_sequence = array(); |
| 1252 | - foreach ( $ordered_modules as $key => $module ) { |
|
| 1252 | + foreach ($ordered_modules as $key => $module) { |
|
| 1253 | 1253 | |
| 1254 | 1254 | $ordered_modules_with_keys_in_sequence[] = $module; |
| 1255 | 1255 | |
@@ -1268,8 +1268,8 @@ discard block |
||
| 1268 | 1268 | */ |
| 1269 | 1269 | public function enqueue_styles() { |
| 1270 | 1270 | |
| 1271 | - wp_register_style($this->taxonomy . '-frontend', esc_url($this->assets_url) . 'css/modules-frontend.css', Sensei()->version ); |
|
| 1272 | - wp_enqueue_style($this->taxonomy . '-frontend'); |
|
| 1271 | + wp_register_style($this->taxonomy.'-frontend', esc_url($this->assets_url).'css/modules-frontend.css', Sensei()->version); |
|
| 1272 | + wp_enqueue_style($this->taxonomy.'-frontend'); |
|
| 1273 | 1273 | |
| 1274 | 1274 | } |
| 1275 | 1275 | |
@@ -1280,37 +1280,37 @@ discard block |
||
| 1280 | 1280 | * |
| 1281 | 1281 | * @return void |
| 1282 | 1282 | */ |
| 1283 | - public function admin_enqueue_scripts( $hook ) { |
|
| 1283 | + public function admin_enqueue_scripts($hook) { |
|
| 1284 | 1284 | |
| 1285 | 1285 | /** |
| 1286 | 1286 | * Filter the page hooks where modules admin script can be loaded on. |
| 1287 | 1287 | * |
| 1288 | 1288 | * @param array $white_listed_pages |
| 1289 | 1289 | */ |
| 1290 | - $script_on_pages_white_list = apply_filters( 'sensei_module_admin_script_page_white_lists', array( |
|
| 1290 | + $script_on_pages_white_list = apply_filters('sensei_module_admin_script_page_white_lists', array( |
|
| 1291 | 1291 | 'edit-tags.php', |
| 1292 | 1292 | 'course_page_module-order', |
| 1293 | 1293 | 'post-new.php', |
| 1294 | 1294 | 'post.php' |
| 1295 | - ) ); |
|
| 1295 | + )); |
|
| 1296 | 1296 | |
| 1297 | - if ( ! in_array( $hook, $script_on_pages_white_list ) ) { |
|
| 1297 | + if ( ! in_array($hook, $script_on_pages_white_list)) { |
|
| 1298 | 1298 | return; |
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1301 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 1302 | 1302 | |
| 1303 | - wp_enqueue_script( 'sensei-chosen', Sensei()->plugin_url . 'assets/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), Sensei()->version , true); |
|
| 1304 | - wp_enqueue_script( 'sensei-chosen-ajax', Sensei()->plugin_url . 'assets/chosen/ajax-chosen.jquery' . $suffix . '.js', array( 'jquery', 'sensei-chosen' ), Sensei()->version , true ); |
|
| 1305 | - 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 ); |
|
| 1303 | + wp_enqueue_script('sensei-chosen', Sensei()->plugin_url.'assets/chosen/chosen.jquery'.$suffix.'.js', array('jquery'), Sensei()->version, true); |
|
| 1304 | + wp_enqueue_script('sensei-chosen-ajax', Sensei()->plugin_url.'assets/chosen/ajax-chosen.jquery'.$suffix.'.js', array('jquery', 'sensei-chosen'), Sensei()->version, true); |
|
| 1305 | + 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); |
|
| 1306 | 1306 | |
| 1307 | 1307 | // localized module data |
| 1308 | 1308 | $localize_modulesAdmin = array( |
| 1309 | - 'search_courses_nonce' => wp_create_nonce( 'search-courses' ), |
|
| 1310 | - 'selectPlaceholder' => __( 'Search for courses', 'woothemes-sensei' ) |
|
| 1309 | + 'search_courses_nonce' => wp_create_nonce('search-courses'), |
|
| 1310 | + 'selectPlaceholder' => __('Search for courses', 'woothemes-sensei') |
|
| 1311 | 1311 | ); |
| 1312 | 1312 | |
| 1313 | - wp_localize_script( $this->taxonomy . '-admin' ,'modulesAdmin', $localize_modulesAdmin ); |
|
| 1313 | + wp_localize_script($this->taxonomy.'-admin', 'modulesAdmin', $localize_modulesAdmin); |
|
| 1314 | 1314 | } |
| 1315 | 1315 | |
| 1316 | 1316 | /** |
@@ -1322,8 +1322,8 @@ discard block |
||
| 1322 | 1322 | */ |
| 1323 | 1323 | public function admin_enqueue_styles() { |
| 1324 | 1324 | |
| 1325 | - wp_register_style($this->taxonomy . '-sortable', esc_url($this->assets_url) . 'css/modules-admin.css','',Sensei()->version ); |
|
| 1326 | - wp_enqueue_style($this->taxonomy . '-sortable'); |
|
| 1325 | + wp_register_style($this->taxonomy.'-sortable', esc_url($this->assets_url).'css/modules-admin.css', '', Sensei()->version); |
|
| 1326 | + wp_enqueue_style($this->taxonomy.'-sortable'); |
|
| 1327 | 1327 | |
| 1328 | 1328 | } |
| 1329 | 1329 | |
@@ -1337,9 +1337,9 @@ discard block |
||
| 1337 | 1337 | */ |
| 1338 | 1338 | public function course_modules_title( ) { |
| 1339 | 1339 | |
| 1340 | - if( sensei_module_has_lessons() ){ |
|
| 1340 | + if (sensei_module_has_lessons()) { |
|
| 1341 | 1341 | |
| 1342 | - echo '<header><h2>' . __('Modules', 'woothemes-sensei') . '</h2></header>'; |
|
| 1342 | + echo '<header><h2>'.__('Modules', 'woothemes-sensei').'</h2></header>'; |
|
| 1343 | 1343 | |
| 1344 | 1344 | } |
| 1345 | 1345 | |
@@ -1352,22 +1352,22 @@ discard block |
||
| 1352 | 1352 | * @since 1.8.0 |
| 1353 | 1353 | * @return void |
| 1354 | 1354 | */ |
| 1355 | - public function load_course_module_content_template(){ |
|
| 1355 | + public function load_course_module_content_template() { |
|
| 1356 | 1356 | |
| 1357 | - if ( ! is_singular( 'course' ) ) { |
|
| 1357 | + if ( ! is_singular('course')) { |
|
| 1358 | 1358 | return; |
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | // load backwards compatible template name if it exists in the users theme |
| 1362 | - $located_template= locate_template( Sensei()->template_url . 'single-course/course-modules.php' ); |
|
| 1363 | - if( $located_template ){ |
|
| 1362 | + $located_template = locate_template(Sensei()->template_url.'single-course/course-modules.php'); |
|
| 1363 | + if ($located_template) { |
|
| 1364 | 1364 | |
| 1365 | - Sensei_Templates::get_template( 'single-course/course-modules.php' ); |
|
| 1365 | + Sensei_Templates::get_template('single-course/course-modules.php'); |
|
| 1366 | 1366 | return; |
| 1367 | 1367 | |
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | - Sensei_Templates::get_template( 'single-course/modules.php' ); |
|
| 1370 | + Sensei_Templates::get_template('single-course/modules.php'); |
|
| 1371 | 1371 | |
| 1372 | 1372 | } // end course_module_content |
| 1373 | 1373 | |
@@ -1380,15 +1380,15 @@ discard block |
||
| 1380 | 1380 | * @param $term_id |
| 1381 | 1381 | * @return array $lessons |
| 1382 | 1382 | */ |
| 1383 | - public function get_lessons( $course_id , $term_id ){ |
|
| 1383 | + public function get_lessons($course_id, $term_id) { |
|
| 1384 | 1384 | |
| 1385 | - $lesson_query = $this->get_lessons_query( $course_id, $term_id ); |
|
| 1385 | + $lesson_query = $this->get_lessons_query($course_id, $term_id); |
|
| 1386 | 1386 | |
| 1387 | - if( isset( $lesson_query->posts ) ){ |
|
| 1387 | + if (isset($lesson_query->posts)) { |
|
| 1388 | 1388 | |
| 1389 | 1389 | return $lesson_query->posts; |
| 1390 | 1390 | |
| 1391 | - }else{ |
|
| 1391 | + } else { |
|
| 1392 | 1392 | |
| 1393 | 1393 | return array(); |
| 1394 | 1394 | |
@@ -1405,9 +1405,9 @@ discard block |
||
| 1405 | 1405 | * @param $term_id |
| 1406 | 1406 | * @return WP_Query $lessons_query |
| 1407 | 1407 | */ |
| 1408 | - public function get_lessons_query( $course_id , $term_id ){ |
|
| 1408 | + public function get_lessons_query($course_id, $term_id) { |
|
| 1409 | 1409 | |
| 1410 | - if( empty( $term_id ) || empty( $course_id ) ){ |
|
| 1410 | + if (empty($term_id) || empty($course_id)) { |
|
| 1411 | 1411 | |
| 1412 | 1412 | return array(); |
| 1413 | 1413 | |
@@ -1428,7 +1428,7 @@ discard block |
||
| 1428 | 1428 | array( |
| 1429 | 1429 | 'taxonomy' => 'module', |
| 1430 | 1430 | 'field' => 'id', |
| 1431 | - 'terms' => intval( $term_id ) |
|
| 1431 | + 'terms' => intval($term_id) |
|
| 1432 | 1432 | ) |
| 1433 | 1433 | ), |
| 1434 | 1434 | 'orderby' => 'menu_order', |
@@ -1436,12 +1436,12 @@ discard block |
||
| 1436 | 1436 | 'suppress_filters' => 0 |
| 1437 | 1437 | ); |
| 1438 | 1438 | |
| 1439 | - if (version_compare( Sensei()->version, '1.6.0', '>=')) { |
|
| 1440 | - $args['meta_key'] = '_order_module_' . intval( $term_id ); |
|
| 1439 | + if (version_compare(Sensei()->version, '1.6.0', '>=')) { |
|
| 1440 | + $args['meta_key'] = '_order_module_'.intval($term_id); |
|
| 1441 | 1441 | $args['orderby'] = 'meta_value_num date'; |
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | - $lessons_query = new WP_Query( $args ); |
|
| 1444 | + $lessons_query = new WP_Query($args); |
|
| 1445 | 1445 | |
| 1446 | 1446 | return $lessons_query; |
| 1447 | 1447 | |
@@ -1456,37 +1456,37 @@ discard block |
||
| 1456 | 1456 | * |
| 1457 | 1457 | * @return array $non_module_lessons |
| 1458 | 1458 | */ |
| 1459 | - public function get_none_module_lessons( $course_id ){ |
|
| 1459 | + public function get_none_module_lessons($course_id) { |
|
| 1460 | 1460 | |
| 1461 | 1461 | $non_module_lessons = array(); |
| 1462 | 1462 | |
| 1463 | 1463 | //exit if there is no course id passed in |
| 1464 | - if( empty( $course_id ) || 'course' != get_post_type( $course_id ) ) { |
|
| 1464 | + if (empty($course_id) || 'course' != get_post_type($course_id)) { |
|
| 1465 | 1465 | |
| 1466 | 1466 | return $non_module_lessons; |
| 1467 | 1467 | } |
| 1468 | 1468 | |
| 1469 | 1469 | //save some time and check if we already have the saved |
| 1470 | - if( get_transient( 'sensei_'. $course_id .'_none_module_lessons') ){ |
|
| 1470 | + if (get_transient('sensei_'.$course_id.'_none_module_lessons')) { |
|
| 1471 | 1471 | |
| 1472 | - return get_transient( 'sensei_'. $course_id .'_none_module_lessons'); |
|
| 1472 | + return get_transient('sensei_'.$course_id.'_none_module_lessons'); |
|
| 1473 | 1473 | |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | 1476 | // create terms array which must be excluded from other arrays |
| 1477 | - $course_modules = $this->get_course_modules( $course_id ); |
|
| 1477 | + $course_modules = $this->get_course_modules($course_id); |
|
| 1478 | 1478 | |
| 1479 | 1479 | //exit if there are no module on this course |
| 1480 | - if( empty( $course_modules ) || ! is_array( $course_modules ) ){ |
|
| 1480 | + if (empty($course_modules) || ! is_array($course_modules)) { |
|
| 1481 | 1481 | |
| 1482 | - return Sensei()->course->course_lessons( $course_id ); |
|
| 1482 | + return Sensei()->course->course_lessons($course_id); |
|
| 1483 | 1483 | |
| 1484 | 1484 | } |
| 1485 | 1485 | |
| 1486 | 1486 | $terms = array(); |
| 1487 | - foreach( $course_modules as $module ){ |
|
| 1487 | + foreach ($course_modules as $module) { |
|
| 1488 | 1488 | |
| 1489 | - array_push( $terms , $module->term_id ); |
|
| 1489 | + array_push($terms, $module->term_id); |
|
| 1490 | 1490 | |
| 1491 | 1491 | } |
| 1492 | 1492 | |
@@ -1497,7 +1497,7 @@ discard block |
||
| 1497 | 1497 | 'meta_query' => array( |
| 1498 | 1498 | array( |
| 1499 | 1499 | 'key' => '_lesson_course', |
| 1500 | - 'value' => intval( $course_id ), |
|
| 1500 | + 'value' => intval($course_id), |
|
| 1501 | 1501 | 'compare' => '=' |
| 1502 | 1502 | ) |
| 1503 | 1503 | ), |
@@ -1514,11 +1514,11 @@ discard block |
||
| 1514 | 1514 | 'suppress_filters' => 0 |
| 1515 | 1515 | ); |
| 1516 | 1516 | |
| 1517 | - $wp_lessons_query = new WP_Query( $args ); |
|
| 1517 | + $wp_lessons_query = new WP_Query($args); |
|
| 1518 | 1518 | |
| 1519 | - if( isset( $wp_lessons_query->posts) && count( $wp_lessons_query->posts ) > 0 ){ |
|
| 1519 | + if (isset($wp_lessons_query->posts) && count($wp_lessons_query->posts) > 0) { |
|
| 1520 | 1520 | $non_module_lessons = $wp_lessons_query->get_posts(); |
| 1521 | - set_transient( 'sensei_'. $course_id .'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS ); |
|
| 1521 | + set_transient('sensei_'.$course_id.'_none_module_lessons', $non_module_lessons, 10 * DAY_IN_SECONDS); |
|
| 1522 | 1522 | } |
| 1523 | 1523 | |
| 1524 | 1524 | return $non_module_lessons; |
@@ -1529,7 +1529,7 @@ discard block |
||
| 1529 | 1529 | * |
| 1530 | 1530 | * @since 1.8.0 |
| 1531 | 1531 | */ |
| 1532 | - public function setup_modules_taxonomy(){ |
|
| 1532 | + public function setup_modules_taxonomy() { |
|
| 1533 | 1533 | |
| 1534 | 1534 | $labels = array( |
| 1535 | 1535 | 'name' => __('Modules', 'woothemes-sensei'), |
@@ -1566,11 +1566,11 @@ discard block |
||
| 1566 | 1566 | 'show_in_nav_menus' => false, |
| 1567 | 1567 | 'show_in_quick_edit' => false, |
| 1568 | 1568 | 'show_ui' => true, |
| 1569 | - 'rewrite' => array('slug' => $modules_rewrite_slug ), |
|
| 1569 | + 'rewrite' => array('slug' => $modules_rewrite_slug), |
|
| 1570 | 1570 | 'labels' => $labels |
| 1571 | 1571 | ); |
| 1572 | 1572 | |
| 1573 | - register_taxonomy( 'module' , array('course', 'lesson'), $args); |
|
| 1573 | + register_taxonomy('module', array('course', 'lesson'), $args); |
|
| 1574 | 1574 | |
| 1575 | 1575 | }// end setup_modules_taxonomy |
| 1576 | 1576 | |
@@ -1582,12 +1582,12 @@ discard block |
||
| 1582 | 1582 | * @since 1.8.0 |
| 1583 | 1583 | * @return void |
| 1584 | 1584 | */ |
| 1585 | - function redirect_to_lesson_module_taxonomy_to_course( ){ |
|
| 1585 | + function redirect_to_lesson_module_taxonomy_to_course( ) { |
|
| 1586 | 1586 | |
| 1587 | - global $typenow , $taxnow; |
|
| 1587 | + global $typenow, $taxnow; |
|
| 1588 | 1588 | |
| 1589 | - if( 'lesson'== $typenow && 'module'==$taxnow ){ |
|
| 1590 | - wp_safe_redirect( esc_url_raw( 'edit-tags.php?taxonomy=module&post_type=course' ) ); |
|
| 1589 | + if ('lesson' == $typenow && 'module' == $taxnow) { |
|
| 1590 | + wp_safe_redirect(esc_url_raw('edit-tags.php?taxonomy=module&post_type=course')); |
|
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 1593 | 1593 | }// end redirect to course taxonomy |
@@ -1600,18 +1600,18 @@ discard block |
||
| 1600 | 1600 | * @since 1.8.0 |
| 1601 | 1601 | * @return void |
| 1602 | 1602 | */ |
| 1603 | - public function remove_lessons_menu_model_taxonomy(){ |
|
| 1603 | + public function remove_lessons_menu_model_taxonomy() { |
|
| 1604 | 1604 | global $submenu; |
| 1605 | 1605 | |
| 1606 | - if( ! isset( $submenu['edit.php?post_type=lesson'] ) || !is_array( $submenu['edit.php?post_type=lesson'] ) ){ |
|
| 1606 | + if ( ! isset($submenu['edit.php?post_type=lesson']) || ! is_array($submenu['edit.php?post_type=lesson'])) { |
|
| 1607 | 1607 | return; // exit |
| 1608 | 1608 | } |
| 1609 | 1609 | |
| 1610 | 1610 | $lesson_main_menu = $submenu['edit.php?post_type=lesson']; |
| 1611 | - foreach( $lesson_main_menu as $index => $sub_item ){ |
|
| 1611 | + foreach ($lesson_main_menu as $index => $sub_item) { |
|
| 1612 | 1612 | |
| 1613 | - if( 'edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2] ){ |
|
| 1614 | - unset( $submenu['edit.php?post_type=lesson'][ $index ]); |
|
| 1613 | + if ('edit-tags.php?taxonomy=module&post_type=lesson' == $sub_item[2]) { |
|
| 1614 | + unset($submenu['edit.php?post_type=lesson'][$index]); |
|
| 1615 | 1615 | } |
| 1616 | 1616 | } |
| 1617 | 1617 | |
@@ -1625,18 +1625,18 @@ discard block |
||
| 1625 | 1625 | * @since 1.8.0 |
| 1626 | 1626 | * @return void |
| 1627 | 1627 | */ |
| 1628 | - public function remove_courses_menu_model_taxonomy(){ |
|
| 1628 | + public function remove_courses_menu_model_taxonomy() { |
|
| 1629 | 1629 | global $submenu; |
| 1630 | 1630 | |
| 1631 | - if( ! isset( $submenu['edit.php?post_type=course'] ) || !is_array( $submenu['edit.php?post_type=course'] ) ){ |
|
| 1631 | + if ( ! isset($submenu['edit.php?post_type=course']) || ! is_array($submenu['edit.php?post_type=course'])) { |
|
| 1632 | 1632 | return; // exit |
| 1633 | 1633 | } |
| 1634 | 1634 | |
| 1635 | 1635 | $course_main_menu = $submenu['edit.php?post_type=course']; |
| 1636 | - foreach( $course_main_menu as $index => $sub_item ){ |
|
| 1636 | + foreach ($course_main_menu as $index => $sub_item) { |
|
| 1637 | 1637 | |
| 1638 | - if( 'edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2] ){ |
|
| 1639 | - unset( $submenu['edit.php?post_type=course'][ $index ]); |
|
| 1638 | + if ('edit-tags.php?taxonomy=module&post_type=course' == $sub_item[2]) { |
|
| 1639 | + unset($submenu['edit.php?post_type=course'][$index]); |
|
| 1640 | 1640 | } |
| 1641 | 1641 | } |
| 1642 | 1642 | |
@@ -1652,12 +1652,12 @@ discard block |
||
| 1652 | 1652 | * @param string $term_name |
| 1653 | 1653 | * @return array $owners { type WP_User }. Empty array if none if found. |
| 1654 | 1654 | */ |
| 1655 | - public static function get_term_authors( $term_name ){ |
|
| 1655 | + public static function get_term_authors($term_name) { |
|
| 1656 | 1656 | |
| 1657 | - $terms = get_terms( array( 'module') , array( 'name__like'=>$term_name, 'hide_empty' => false ) ); |
|
| 1657 | + $terms = get_terms(array('module'), array('name__like'=>$term_name, 'hide_empty' => false)); |
|
| 1658 | 1658 | |
| 1659 | 1659 | $owners = array(); |
| 1660 | - if( empty( $terms ) ){ |
|
| 1660 | + if (empty($terms)) { |
|
| 1661 | 1661 | |
| 1662 | 1662 | return $owners; |
| 1663 | 1663 | |
@@ -1667,11 +1667,11 @@ discard block |
||
| 1667 | 1667 | |
| 1668 | 1668 | |
| 1669 | 1669 | //if there are more handle them appropriately and get the ones we really need that matches the desired name exactly |
| 1670 | - foreach( $terms as $term){ |
|
| 1671 | - if( $term->name == $term_name ){ |
|
| 1670 | + foreach ($terms as $term) { |
|
| 1671 | + if ($term->name == $term_name) { |
|
| 1672 | 1672 | |
| 1673 | 1673 | // look for the author in the slug |
| 1674 | - $owners[] = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1674 | + $owners[] = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 1675 | 1675 | |
| 1676 | 1676 | }// end if term name |
| 1677 | 1677 | |
@@ -1692,30 +1692,30 @@ discard block |
||
| 1692 | 1692 | * @param $slug |
| 1693 | 1693 | * @return WP_User $author if no author is found or invalid term is passed the admin user will be returned. |
| 1694 | 1694 | */ |
| 1695 | - public static function get_term_author( $slug='' ){ |
|
| 1695 | + public static function get_term_author($slug = '') { |
|
| 1696 | 1696 | |
| 1697 | - $term_owner = get_user_by( 'email', get_bloginfo( 'admin_email' ) ); |
|
| 1697 | + $term_owner = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1698 | 1698 | |
| 1699 | - if( empty( $slug ) ){ |
|
| 1699 | + if (empty($slug)) { |
|
| 1700 | 1700 | |
| 1701 | 1701 | return $term_owner; |
| 1702 | 1702 | |
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | // look for the author in the slug |
| 1706 | - $slug_parts = explode( '-', $slug ); |
|
| 1706 | + $slug_parts = explode('-', $slug); |
|
| 1707 | 1707 | |
| 1708 | - if( count( $slug_parts ) > 1 ){ |
|
| 1708 | + if (count($slug_parts) > 1) { |
|
| 1709 | 1709 | |
| 1710 | 1710 | // get the user data |
| 1711 | 1711 | $possible_user_id = $slug_parts[0]; |
| 1712 | - $author = get_userdata( $possible_user_id ); |
|
| 1712 | + $author = get_userdata($possible_user_id); |
|
| 1713 | 1713 | |
| 1714 | 1714 | // if the user doesnt exist for the first part of the slug |
| 1715 | 1715 | // then this slug was also created by admin |
| 1716 | - if( is_a( $author, 'WP_User' ) ){ |
|
| 1716 | + if (is_a($author, 'WP_User')) { |
|
| 1717 | 1717 | |
| 1718 | - $term_owner = $author; |
|
| 1718 | + $term_owner = $author; |
|
| 1719 | 1719 | |
| 1720 | 1720 | } |
| 1721 | 1721 | } |
@@ -1732,48 +1732,48 @@ discard block |
||
| 1732 | 1732 | * |
| 1733 | 1733 | * @param WP_Post $post Post object. |
| 1734 | 1734 | */ |
| 1735 | - public function course_module_metabox( $post ) { |
|
| 1735 | + public function course_module_metabox($post) { |
|
| 1736 | 1736 | |
| 1737 | 1737 | $tax_name = 'module'; |
| 1738 | - $taxonomy = get_taxonomy( 'module' ); |
|
| 1738 | + $taxonomy = get_taxonomy('module'); |
|
| 1739 | 1739 | |
| 1740 | 1740 | ?> |
| 1741 | 1741 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
| 1742 | 1742 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
| 1743 | 1743 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a></li> |
| 1744 | - <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e( 'Most Used' ); ?></a></li> |
|
| 1744 | + <li class="hide-if-no-js"><a href="#<?php echo $tax_name; ?>-pop"><?php _e('Most Used'); ?></a></li> |
|
| 1745 | 1745 | </ul> |
| 1746 | 1746 | |
| 1747 | 1747 | <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;"> |
| 1748 | 1748 | <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear" > |
| 1749 | - <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?> |
|
| 1749 | + <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?> |
|
| 1750 | 1750 | </ul> |
| 1751 | 1751 | </div> |
| 1752 | 1752 | |
| 1753 | 1753 | <div id="<?php echo $tax_name; ?>-all" class="tabs-panel"> |
| 1754 | 1754 | <?php |
| 1755 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 1755 | + $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']'; |
|
| 1756 | 1756 | 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. |
| 1757 | 1757 | ?> |
| 1758 | 1758 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" class="categorychecklist form-no-clear"> |
| 1759 | - <?php wp_terms_checklist( $post->ID, array( 'taxonomy'=>$tax_name , 'popular_cats' => $popular_ids ) ); ?> |
|
| 1759 | + <?php wp_terms_checklist($post->ID, array('taxonomy'=>$tax_name, 'popular_cats' => $popular_ids)); ?> |
|
| 1760 | 1760 | </ul> |
| 1761 | 1761 | </div> |
| 1762 | - <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?> |
|
| 1762 | + <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?> |
|
| 1763 | 1763 | <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children"> |
| 1764 | 1764 | <h4> |
| 1765 | 1765 | <a id="sensei-<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" class="hide-if-no-js"> |
| 1766 | 1766 | <?php |
| 1767 | 1767 | /* translators: %s: add new taxonomy label */ |
| 1768 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 1768 | + printf(__('+ %s'), $taxonomy->labels->add_new_item); |
|
| 1769 | 1769 | ?> |
| 1770 | 1770 | </a> |
| 1771 | 1771 | </h4> |
| 1772 | 1772 | <p id="sensei-<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
| 1773 | 1773 | <label class="screen-reader-text" for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label> |
| 1774 | - <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"/> |
|
| 1775 | - <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> |
|
| 1776 | - <?php wp_nonce_field( '_ajax_nonce-add-' . $tax_name, 'add_module_nonce' ); ?> |
|
| 1774 | + <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"/> |
|
| 1775 | + <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> |
|
| 1776 | + <?php wp_nonce_field('_ajax_nonce-add-'.$tax_name, 'add_module_nonce'); ?> |
|
| 1777 | 1777 | <span id="<?php echo $tax_name; ?>-ajax-response"></span> |
| 1778 | 1778 | </p> |
| 1779 | 1779 | </div> |
@@ -1793,55 +1793,55 @@ discard block |
||
| 1793 | 1793 | public static function add_new_module_term( ) { |
| 1794 | 1794 | |
| 1795 | 1795 | |
| 1796 | - if( ! isset( $_POST[ 'security' ] ) || ! wp_verify_nonce( $_POST[ 'security' ], '_ajax_nonce-add-module' ) ){ |
|
| 1797 | - wp_send_json_error( array('error'=> 'wrong security nonce') ); |
|
| 1796 | + if ( ! isset($_POST['security']) || ! wp_verify_nonce($_POST['security'], '_ajax_nonce-add-module')) { |
|
| 1797 | + wp_send_json_error(array('error'=> 'wrong security nonce')); |
|
| 1798 | 1798 | } |
| 1799 | 1799 | |
| 1800 | 1800 | // get the term an create the new term storing infomration |
| 1801 | - $term_name = sanitize_text_field( $_POST['newTerm'] ); |
|
| 1801 | + $term_name = sanitize_text_field($_POST['newTerm']); |
|
| 1802 | 1802 | |
| 1803 | - if( current_user_can('manage_options' ) ) { |
|
| 1803 | + if (current_user_can('manage_options')) { |
|
| 1804 | 1804 | |
| 1805 | - $term_slug = str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1805 | + $term_slug = str_ireplace(' ', '-', trim($term_name)); |
|
| 1806 | 1806 | |
| 1807 | 1807 | } else { |
| 1808 | 1808 | |
| 1809 | - $term_slug = get_current_user_id() . '-' . str_ireplace(' ', '-', trim( $term_name ) ); |
|
| 1809 | + $term_slug = get_current_user_id().'-'.str_ireplace(' ', '-', trim($term_name)); |
|
| 1810 | 1810 | |
| 1811 | 1811 | } |
| 1812 | 1812 | |
| 1813 | - $course_id = sanitize_text_field( $_POST['course_id'] ); |
|
| 1813 | + $course_id = sanitize_text_field($_POST['course_id']); |
|
| 1814 | 1814 | |
| 1815 | 1815 | // save the term |
| 1816 | - $slug = wp_insert_term( $term_name,'module', array('slug'=> $term_slug) ); |
|
| 1816 | + $slug = wp_insert_term($term_name, 'module', array('slug'=> $term_slug)); |
|
| 1817 | 1817 | |
| 1818 | 1818 | // send error for all errors except term exits |
| 1819 | - if( is_wp_error( $slug ) ){ |
|
| 1819 | + if (is_wp_error($slug)) { |
|
| 1820 | 1820 | |
| 1821 | 1821 | // prepare for possible term name and id to be passed down if term exists |
| 1822 | 1822 | $term_data = array(); |
| 1823 | 1823 | |
| 1824 | 1824 | // if term exists also send back the term name and id |
| 1825 | - if( isset( $slug->errors['term_exists'] ) ){ |
|
| 1825 | + if (isset($slug->errors['term_exists'])) { |
|
| 1826 | 1826 | |
| 1827 | - $term = get_term_by( 'slug', $term_slug, 'module'); |
|
| 1827 | + $term = get_term_by('slug', $term_slug, 'module'); |
|
| 1828 | 1828 | $term_data['name'] = $term_name; |
| 1829 | 1829 | $term_data['id'] = $term->term_id; |
| 1830 | 1830 | |
| 1831 | 1831 | // set the object terms |
| 1832 | - wp_set_object_terms( $course_id, $term->term_id, 'module', true ); |
|
| 1832 | + wp_set_object_terms($course_id, $term->term_id, 'module', true); |
|
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | - wp_send_json_error(array( 'errors'=>$slug->errors , 'term'=> $term_data ) ); |
|
| 1835 | + wp_send_json_error(array('errors'=>$slug->errors, 'term'=> $term_data)); |
|
| 1836 | 1836 | |
| 1837 | 1837 | } |
| 1838 | 1838 | |
| 1839 | 1839 | //make sure the new term is checked for this course |
| 1840 | 1840 | |
| 1841 | - wp_set_object_terms( $course_id, $slug['term_id'], 'module', true ); |
|
| 1841 | + wp_set_object_terms($course_id, $slug['term_id'], 'module', true); |
|
| 1842 | 1842 | |
| 1843 | 1843 | // Handle request then generate response using WP_Ajax_Response |
| 1844 | - wp_send_json_success( array( 'termId' => $slug['term_id'], 'termName' => $term_name ) ); |
|
| 1844 | + wp_send_json_success(array('termId' => $slug['term_id'], 'termName' => $term_name)); |
|
| 1845 | 1845 | |
| 1846 | 1846 | } |
| 1847 | 1847 | |
@@ -1853,26 +1853,26 @@ discard block |
||
| 1853 | 1853 | * |
| 1854 | 1854 | * @since 1.8.0 |
| 1855 | 1855 | */ |
| 1856 | - public function filter_module_terms( $terms, $taxonomies, $args ){ |
|
| 1856 | + public function filter_module_terms($terms, $taxonomies, $args) { |
|
| 1857 | 1857 | |
| 1858 | 1858 | //dont limit for admins and other taxonomies. This should also only apply to admin |
| 1859 | - if( current_user_can( 'manage_options' ) || !in_array( 'module', $taxonomies ) || ! is_admin() ){ |
|
| 1859 | + if (current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) { |
|
| 1860 | 1860 | return $terms; |
| 1861 | 1861 | } |
| 1862 | 1862 | |
| 1863 | 1863 | // avoid infinite call loop |
| 1864 | - remove_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1864 | + remove_filter('get_terms', array($this, 'filter_module_terms'), 20, 3); |
|
| 1865 | 1865 | |
| 1866 | 1866 | // in certain cases the array is passed in as reference to the parent term_id => parent_id |
| 1867 | - if( isset( $args['fields'] ) && 'id=>parent' == $args['fields'] ){ |
|
| 1867 | + if (isset($args['fields']) && 'id=>parent' == $args['fields']) { |
|
| 1868 | 1868 | // change only scrub the terms ids form the array keys |
| 1869 | - $terms = array_keys( $terms ); |
|
| 1869 | + $terms = array_keys($terms); |
|
| 1870 | 1870 | } |
| 1871 | 1871 | |
| 1872 | - $teachers_terms = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1872 | + $teachers_terms = $this->filter_terms_by_owner($terms, get_current_user_id()); |
|
| 1873 | 1873 | |
| 1874 | 1874 | // add filter again as removed above |
| 1875 | - add_filter('get_terms', array( $this, 'filter_module_terms' ), 20, 3 ); |
|
| 1875 | + add_filter('get_terms', array($this, 'filter_module_terms'), 20, 3); |
|
| 1876 | 1876 | |
| 1877 | 1877 | return $teachers_terms; |
| 1878 | 1878 | }// end filter_module_terms |
@@ -1885,25 +1885,25 @@ discard block |
||
| 1885 | 1885 | * |
| 1886 | 1886 | * @since 1.8.0 |
| 1887 | 1887 | */ |
| 1888 | - public function filter_course_selected_terms( $terms, $course_ids_array, $taxonomies ){ |
|
| 1888 | + public function filter_course_selected_terms($terms, $course_ids_array, $taxonomies) { |
|
| 1889 | 1889 | |
| 1890 | 1890 | //dont limit for admins and other taxonomies. This should also only apply to admin |
| 1891 | - if( current_user_can( 'manage_options' ) || ! is_admin() || empty( $terms ) |
|
| 1891 | + if (current_user_can('manage_options') || ! is_admin() || empty($terms) |
|
| 1892 | 1892 | // only apply this to module only taxonomy queries so 1 taxonomy only: |
| 1893 | - || count( $taxonomies ) > 1 || !in_array( 'module', $taxonomies ) ){ |
|
| 1893 | + || count($taxonomies) > 1 || ! in_array('module', $taxonomies)) { |
|
| 1894 | 1894 | return $terms; |
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | - $term_objects = $this->filter_terms_by_owner( $terms, get_current_user_id() ); |
|
| 1897 | + $term_objects = $this->filter_terms_by_owner($terms, get_current_user_id()); |
|
| 1898 | 1898 | |
| 1899 | 1899 | // if term objects were passed in send back objects |
| 1900 | 1900 | // if term id were passed in send that back |
| 1901 | - if( is_object( $terms[0] ) ){ |
|
| 1901 | + if (is_object($terms[0])) { |
|
| 1902 | 1902 | return $term_objects; |
| 1903 | 1903 | } |
| 1904 | 1904 | |
| 1905 | 1905 | $terms = array(); |
| 1906 | - foreach( $term_objects as $term_object ){ |
|
| 1906 | + foreach ($term_objects as $term_object) { |
|
| 1907 | 1907 | $terms[] = $term_object->term_id; |
| 1908 | 1908 | } |
| 1909 | 1909 | |
@@ -1921,20 +1921,20 @@ discard block |
||
| 1921 | 1921 | * @param $user_id |
| 1922 | 1922 | * @return array |
| 1923 | 1923 | */ |
| 1924 | - public function filter_terms_by_owner( $terms, $user_id ){ |
|
| 1924 | + public function filter_terms_by_owner($terms, $user_id) { |
|
| 1925 | 1925 | |
| 1926 | 1926 | $users_terms = array(); |
| 1927 | 1927 | |
| 1928 | - foreach( $terms as $index => $term ){ |
|
| 1928 | + foreach ($terms as $index => $term) { |
|
| 1929 | 1929 | |
| 1930 | - if( is_numeric( $term ) ){ |
|
| 1930 | + if (is_numeric($term)) { |
|
| 1931 | 1931 | // the term id was given, get the term object |
| 1932 | - $term = get_term( $term, 'module' ); |
|
| 1932 | + $term = get_term($term, 'module'); |
|
| 1933 | 1933 | } |
| 1934 | 1934 | |
| 1935 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1935 | + $author = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 1936 | 1936 | |
| 1937 | - if ( $user_id == $author->ID ) { |
|
| 1937 | + if ($user_id == $author->ID) { |
|
| 1938 | 1938 | // add the term to the teachers terms |
| 1939 | 1939 | $users_terms[] = $term; |
| 1940 | 1940 | } |
@@ -1953,34 +1953,34 @@ discard block |
||
| 1953 | 1953 | * |
| 1954 | 1954 | * @since 1.8.0 |
| 1955 | 1955 | */ |
| 1956 | - public function append_teacher_name_to_module( $terms, $taxonomies, $args ) |
|
| 1956 | + public function append_teacher_name_to_module($terms, $taxonomies, $args) |
|
| 1957 | 1957 | { |
| 1958 | 1958 | |
| 1959 | 1959 | // only for admin users ont he module taxonomy |
| 1960 | - if ( empty( $terms ) || !current_user_can('manage_options') || !in_array('module', $taxonomies) || !is_admin()) { |
|
| 1960 | + if (empty($terms) || ! current_user_can('manage_options') || ! in_array('module', $taxonomies) || ! is_admin()) { |
|
| 1961 | 1961 | return $terms; |
| 1962 | 1962 | } |
| 1963 | 1963 | |
| 1964 | 1964 | // in certain cases the array is passed in as reference to the parent term_id => parent_id |
| 1965 | 1965 | // simply return this as wp doesn't need an array of stdObject Term |
| 1966 | - if (isset( $args['fields'] ) && 'id=>parent' == $args['fields']) { |
|
| 1966 | + if (isset($args['fields']) && 'id=>parent' == $args['fields']) { |
|
| 1967 | 1967 | |
| 1968 | 1968 | return $terms; |
| 1969 | 1969 | |
| 1970 | 1970 | } |
| 1971 | 1971 | |
| 1972 | 1972 | // loop through and update all terms adding the author name |
| 1973 | - foreach( $terms as $index => $term ){ |
|
| 1973 | + foreach ($terms as $index => $term) { |
|
| 1974 | 1974 | |
| 1975 | - if( is_numeric( $term ) ){ |
|
| 1975 | + if (is_numeric($term)) { |
|
| 1976 | 1976 | // the term id was given, get the term object |
| 1977 | - $term = get_term( $term, 'module' ); |
|
| 1977 | + $term = get_term($term, 'module'); |
|
| 1978 | 1978 | } |
| 1979 | 1979 | |
| 1980 | - $author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 1980 | + $author = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 1981 | 1981 | |
| 1982 | - if( ! user_can( $author, 'manage_options' ) && isset( $term->name ) ) { |
|
| 1983 | - $term->name = $term->name . ' (' . $author->display_name . ') '; |
|
| 1982 | + if ( ! user_can($author, 'manage_options') && isset($term->name)) { |
|
| 1983 | + $term->name = $term->name.' ('.$author->display_name.') '; |
|
| 1984 | 1984 | } |
| 1985 | 1985 | |
| 1986 | 1986 | // add the term to the teachers terms |
@@ -2009,23 +2009,23 @@ discard block |
||
| 2009 | 2009 | * @sine 1.9.0 |
| 2010 | 2010 | * @param $post_id |
| 2011 | 2011 | */ |
| 2012 | - public static function reset_none_modules_transient ( $post_id ){ |
|
| 2012 | + public static function reset_none_modules_transient($post_id) { |
|
| 2013 | 2013 | |
| 2014 | 2014 | // this should only apply to course and lesson post types |
| 2015 | - if( in_array( get_post_type( $post_id ), array( 'course', 'lesson' ) ) ){ |
|
| 2015 | + if (in_array(get_post_type($post_id), array('course', 'lesson'))) { |
|
| 2016 | 2016 | |
| 2017 | 2017 | $course_id = ''; |
| 2018 | 2018 | |
| 2019 | - if( 'lesson' == get_post_type( $post_id ) ){ |
|
| 2019 | + if ('lesson' == get_post_type($post_id)) { |
|
| 2020 | 2020 | |
| 2021 | - $course_id = Sensei()->lesson->get_course_id( $post_id ); |
|
| 2021 | + $course_id = Sensei()->lesson->get_course_id($post_id); |
|
| 2022 | 2022 | |
| 2023 | 2023 | } |
| 2024 | 2024 | |
| 2025 | 2025 | |
| 2026 | - if( !empty( $course_id ) ){ |
|
| 2026 | + if ( ! empty($course_id)) { |
|
| 2027 | 2027 | |
| 2028 | - delete_transient( 'sensei_'. $course_id .'_none_module_lessons' ); |
|
| 2028 | + delete_transient('sensei_'.$course_id.'_none_module_lessons'); |
|
| 2029 | 2029 | |
| 2030 | 2030 | } |
| 2031 | 2031 | |
@@ -2040,9 +2040,9 @@ discard block |
||
| 2040 | 2040 | * @deprecated since 1.9.0 |
| 2041 | 2041 | * |
| 2042 | 2042 | */ |
| 2043 | - public static function deprecate_sensei_single_course_modules_content(){ |
|
| 2043 | + public static function deprecate_sensei_single_course_modules_content() { |
|
| 2044 | 2044 | |
| 2045 | - sensei_do_deprecated_action( 'sensei_single_course_modules_content','1.9.0','sensei_single_course_modules_before or sensei_single_course_modules_after' ); |
|
| 2045 | + sensei_do_deprecated_action('sensei_single_course_modules_content', '1.9.0', 'sensei_single_course_modules_before or sensei_single_course_modules_after'); |
|
| 2046 | 2046 | |
| 2047 | 2047 | } |
| 2048 | 2048 | |
@@ -2053,12 +2053,12 @@ discard block |
||
| 2053 | 2053 | * |
| 2054 | 2054 | * @since 1.9.0 |
| 2055 | 2055 | */ |
| 2056 | - public static function setup_single_course_module_loop(){ |
|
| 2056 | + public static function setup_single_course_module_loop() { |
|
| 2057 | 2057 | |
| 2058 | 2058 | global $sensei_modules_loop, $post; |
| 2059 | 2059 | $course_id = $post->ID; |
| 2060 | 2060 | |
| 2061 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2061 | + $modules = Sensei()->modules->get_course_modules($course_id); |
|
| 2062 | 2062 | |
| 2063 | 2063 | //initial setup |
| 2064 | 2064 | $sensei_modules_loop['total'] = 0; |
@@ -2066,22 +2066,22 @@ discard block |
||
| 2066 | 2066 | $sensei_modules_loop['current'] = -1; |
| 2067 | 2067 | |
| 2068 | 2068 | // exit if this course doesn't have modules |
| 2069 | - if( !$modules || empty( $modules ) ){ |
|
| 2069 | + if ( ! $modules || empty($modules)) { |
|
| 2070 | 2070 | return; |
| 2071 | 2071 | } |
| 2072 | 2072 | |
| 2073 | 2073 | |
| 2074 | 2074 | $lessons_in_all_modules = array(); |
| 2075 | - foreach( $modules as $term ){ |
|
| 2075 | + foreach ($modules as $term) { |
|
| 2076 | 2076 | |
| 2077 | - $lessons_in_this_module = Sensei()->modules->get_lessons( $course_id , $term->term_id); |
|
| 2078 | - $lessons_in_all_modules = array_merge( $lessons_in_all_modules, $lessons_in_this_module ); |
|
| 2077 | + $lessons_in_this_module = Sensei()->modules->get_lessons($course_id, $term->term_id); |
|
| 2078 | + $lessons_in_all_modules = array_merge($lessons_in_all_modules, $lessons_in_this_module); |
|
| 2079 | 2079 | |
| 2080 | 2080 | } |
| 2081 | 2081 | |
| 2082 | 2082 | |
| 2083 | 2083 | //setup all of the modules loop variables |
| 2084 | - $sensei_modules_loop['total'] = count( $modules ); |
|
| 2084 | + $sensei_modules_loop['total'] = count($modules); |
|
| 2085 | 2085 | $sensei_modules_loop['modules'] = $modules; |
| 2086 | 2086 | $sensei_modules_loop['current'] = -1; |
| 2087 | 2087 | $sensei_modules_loop['course_id'] = $course_id; |
@@ -2094,7 +2094,7 @@ discard block |
||
| 2094 | 2094 | * @since 1.9.0 |
| 2095 | 2095 | * |
| 2096 | 2096 | */ |
| 2097 | - public static function teardown_single_course_module_loop(){ |
|
| 2097 | + public static function teardown_single_course_module_loop() { |
|
| 2098 | 2098 | |
| 2099 | 2099 | global $sensei_modules_loop, $wp_query, $post; |
| 2100 | 2100 | |
@@ -1,5 +1,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 .= '%'; |
@@ -159,10 +159,10 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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(); |
@@ -1,5 +1,5 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -1,5 +1,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 1534 | 1537 | |
| 1535 | 1538 | return true; |
| 1536 | 1539 | |
| 1537 | - }else{ |
|
| 1540 | + } else{ |
|
| 1538 | 1541 | |
| 1539 | 1542 | return false; |
| 1540 | 1543 | |
@@ -452,7 +452,7 @@ discard block |
||
| 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 |
||
| 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 | |
@@ -12,251 +12,251 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
@@ -1,5 +1,5 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -41,9 +41,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | } |
@@ -1,5 +1,8 @@ discard block |
||
| 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 |
||
| 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; |
@@ -1,5 +1,5 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 {} |
|
@@ -1,5 +1,8 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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>'; |
@@ -10,7 +10,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -1,5 +1,5 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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="← ' . __( 'Select a course', 'woothemes-sensei' ) . '" name="grading_lesson" class="chosen_select widefat">' . "\n"; |
|
| 329 | + echo '<select id="grading-lesson-options" data-placeholder="← '.__('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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 {} |
|
@@ -1,5 +1,8 @@ |
||
| 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 | * |
@@ -1,5 +1,5 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 | |
@@ -13,137 +13,137 @@ |
||
| 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(); |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Post Types Class |
@@ -146,7 +149,7 @@ discard block |
||
| 146 | 149 | |
| 147 | 150 | return get_page_uri( $settings_course_page->ID ); |
| 148 | 151 | |
| 149 | - }else{ |
|
| 152 | + } else{ |
|
| 150 | 153 | |
| 151 | 154 | return 'courses'; |
| 152 | 155 | |
@@ -16,25 +16,25 @@ discard block |
||
| 16 | 16 | public $slider_labels; |
| 17 | 17 | public $role_caps; |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var Sensei_Course |
|
| 21 | - */ |
|
| 22 | - public $course; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var Sensei_Lesson |
|
| 26 | - */ |
|
| 27 | - public $lesson; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var Sensei_Question |
|
| 31 | - */ |
|
| 32 | - public $question; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var Sensei_Quiz |
|
| 36 | - */ |
|
| 37 | - public $quiz; |
|
| 19 | + /** |
|
| 20 | + * @var Sensei_Course |
|
| 21 | + */ |
|
| 22 | + public $course; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var Sensei_Lesson |
|
| 26 | + */ |
|
| 27 | + public $lesson; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var Sensei_Question |
|
| 31 | + */ |
|
| 32 | + public $question; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var Sensei_Quiz |
|
| 36 | + */ |
|
| 37 | + public $quiz; |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * Constructor |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | // Setup Post Types |
| 46 | 46 | $this->labels = array(); |
| 47 | - $this->token = 'woothemes-sensei-posttypes'; |
|
| 47 | + $this->token = 'woothemes-sensei-posttypes'; |
|
| 48 | 48 | |
| 49 | 49 | $this->setup_post_type_labels_base(); |
| 50 | 50 | add_action( 'init', array( $this, 'setup_course_post_type' ), 100 ); |
@@ -103,94 +103,94 @@ discard block |
||
| 103 | 103 | /** |
| 104 | 104 | * Setup the "course" post type, it's admin menu item and the appropriate labels and permissions. |
| 105 | 105 | * @since 1.0.0 |
| 106 | - * @uses Sensei() |
|
| 106 | + * @uses Sensei() |
|
| 107 | 107 | * @return void |
| 108 | 108 | */ |
| 109 | 109 | public function setup_course_post_type () { |
| 110 | 110 | |
| 111 | 111 | $args = array( |
| 112 | - 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
| 113 | - 'public' => true, |
|
| 114 | - 'publicly_queryable' => true, |
|
| 115 | - 'show_ui' => true, |
|
| 116 | - 'show_in_menu' => true, |
|
| 117 | - 'show_in_admin_bar' => true, |
|
| 118 | - 'query_var' => true, |
|
| 119 | - 'rewrite' => array( |
|
| 120 | - 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
| 121 | - 'with_front' => true, |
|
| 122 | - 'feeds' => true, |
|
| 123 | - 'pages' => true |
|
| 124 | - ), |
|
| 125 | - 'map_meta_cap' => true, |
|
| 126 | - 'capability_type' => 'course', |
|
| 127 | - 'has_archive' => $this->get_course_post_type_archive_slug(), |
|
| 128 | - 'hierarchical' => false, |
|
| 129 | - 'menu_position' => 51, |
|
| 130 | - 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
| 112 | + 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
| 113 | + 'public' => true, |
|
| 114 | + 'publicly_queryable' => true, |
|
| 115 | + 'show_ui' => true, |
|
| 116 | + 'show_in_menu' => true, |
|
| 117 | + 'show_in_admin_bar' => true, |
|
| 118 | + 'query_var' => true, |
|
| 119 | + 'rewrite' => array( |
|
| 120 | + 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
| 121 | + 'with_front' => true, |
|
| 122 | + 'feeds' => true, |
|
| 123 | + 'pages' => true |
|
| 124 | + ), |
|
| 125 | + 'map_meta_cap' => true, |
|
| 126 | + 'capability_type' => 'course', |
|
| 127 | + 'has_archive' => $this->get_course_post_type_archive_slug(), |
|
| 128 | + 'hierarchical' => false, |
|
| 129 | + 'menu_position' => 51, |
|
| 130 | + 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Filter the arguments passed in when registering the Sensei Course post type. |
|
| 135 | - * |
|
| 136 | - * @since 1.9.0 |
|
| 137 | - * @param array $args |
|
| 138 | - */ |
|
| 133 | + /** |
|
| 134 | + * Filter the arguments passed in when registering the Sensei Course post type. |
|
| 135 | + * |
|
| 136 | + * @since 1.9.0 |
|
| 137 | + * @param array $args |
|
| 138 | + */ |
|
| 139 | 139 | register_post_type( 'course', apply_filters( 'sensei_register_post_type_course', $args ) ); |
| 140 | 140 | |
| 141 | 141 | } // End setup_course_post_type() |
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Figure out of the course post type has an archive and what it should be. |
|
| 145 | - * |
|
| 146 | - * This function should return 'courses' or the page_uri for the course page setting. |
|
| 147 | - * |
|
| 148 | - * For backward compatibility sake ( pre 1.9 )If the course page set in settings |
|
| 149 | - * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the |
|
| 150 | - * page slug will not be returned. For any other pages without it the page URI will be returned. |
|
| 151 | - * |
|
| 152 | - * |
|
| 153 | - * @sine 1.9.0 |
|
| 154 | - * |
|
| 155 | - * |
|
| 156 | - * @return false|string |
|
| 157 | - */ |
|
| 158 | - public function get_course_post_type_archive_slug(){ |
|
| 143 | + /** |
|
| 144 | + * Figure out of the course post type has an archive and what it should be. |
|
| 145 | + * |
|
| 146 | + * This function should return 'courses' or the page_uri for the course page setting. |
|
| 147 | + * |
|
| 148 | + * For backward compatibility sake ( pre 1.9 )If the course page set in settings |
|
| 149 | + * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the |
|
| 150 | + * page slug will not be returned. For any other pages without it the page URI will be returned. |
|
| 151 | + * |
|
| 152 | + * |
|
| 153 | + * @sine 1.9.0 |
|
| 154 | + * |
|
| 155 | + * |
|
| 156 | + * @return false|string |
|
| 157 | + */ |
|
| 158 | + public function get_course_post_type_archive_slug(){ |
|
| 159 | 159 | |
| 160 | - $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
| 160 | + $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
| 161 | 161 | |
| 162 | - // for a valid post that doesn't have any of the old short codes set the archive the same |
|
| 163 | - // as the page URI |
|
| 164 | - if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
| 162 | + // for a valid post that doesn't have any of the old short codes set the archive the same |
|
| 163 | + // as the page URI |
|
| 164 | + if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
| 165 | 165 | |
| 166 | - return get_page_uri( $settings_course_page->ID ); |
|
| 166 | + return get_page_uri( $settings_course_page->ID ); |
|
| 167 | 167 | |
| 168 | - }else{ |
|
| 168 | + }else{ |
|
| 169 | 169 | |
| 170 | - return 'courses'; |
|
| 170 | + return 'courses'; |
|
| 171 | 171 | |
| 172 | - } |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - }// end course_post_type_determine_archive |
|
| 174 | + }// end course_post_type_determine_archive |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Check if given content has any of these old shortcodes: |
|
| 178 | - * [newcourses][featuredcourses][freecourses][paidcourses] |
|
| 179 | - * |
|
| 180 | - * @since 1.9.0 |
|
| 181 | - * |
|
| 182 | - * @param string $content |
|
| 183 | - * |
|
| 184 | - * @return bool |
|
| 185 | - */ |
|
| 186 | - public function has_old_shortcodes( $content ){ |
|
| 176 | + /** |
|
| 177 | + * Check if given content has any of these old shortcodes: |
|
| 178 | + * [newcourses][featuredcourses][freecourses][paidcourses] |
|
| 179 | + * |
|
| 180 | + * @since 1.9.0 |
|
| 181 | + * |
|
| 182 | + * @param string $content |
|
| 183 | + * |
|
| 184 | + * @return bool |
|
| 185 | + */ |
|
| 186 | + public function has_old_shortcodes( $content ){ |
|
| 187 | 187 | |
| 188 | - return ( has_shortcode( $content, 'newcourses') |
|
| 189 | - || has_shortcode( $content, 'featuredcourses') |
|
| 190 | - || has_shortcode( $content, 'freecourses') |
|
| 191 | - || has_shortcode( $content, 'paidcourses') ); |
|
| 188 | + return ( has_shortcode( $content, 'newcourses') |
|
| 189 | + || has_shortcode( $content, 'featuredcourses') |
|
| 190 | + || has_shortcode( $content, 'freecourses') |
|
| 191 | + || has_shortcode( $content, 'paidcourses') ); |
|
| 192 | 192 | |
| 193 | - }// end has old shortcodes |
|
| 193 | + }// end has old shortcodes |
|
| 194 | 194 | |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -211,32 +211,32 @@ discard block |
||
| 211 | 211 | } // End If Statement |
| 212 | 212 | |
| 213 | 213 | $args = array( |
| 214 | - 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
| 215 | - 'public' => true, |
|
| 216 | - 'publicly_queryable' => true, |
|
| 217 | - 'show_ui' => true, |
|
| 218 | - 'show_in_menu' => true, |
|
| 219 | - 'query_var' => true, |
|
| 220 | - 'rewrite' => array( |
|
| 221 | - 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 222 | - 'with_front' => true, |
|
| 223 | - 'feeds' => true, |
|
| 224 | - 'pages' => true |
|
| 225 | - ), |
|
| 226 | - 'map_meta_cap' => true, |
|
| 227 | - 'capability_type' => 'lesson', |
|
| 228 | - 'has_archive' => true, |
|
| 229 | - 'hierarchical' => false, |
|
| 230 | - 'menu_position' => 52, |
|
| 231 | - 'supports' => $supports_array |
|
| 214 | + 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
| 215 | + 'public' => true, |
|
| 216 | + 'publicly_queryable' => true, |
|
| 217 | + 'show_ui' => true, |
|
| 218 | + 'show_in_menu' => true, |
|
| 219 | + 'query_var' => true, |
|
| 220 | + 'rewrite' => array( |
|
| 221 | + 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 222 | + 'with_front' => true, |
|
| 223 | + 'feeds' => true, |
|
| 224 | + 'pages' => true |
|
| 225 | + ), |
|
| 226 | + 'map_meta_cap' => true, |
|
| 227 | + 'capability_type' => 'lesson', |
|
| 228 | + 'has_archive' => true, |
|
| 229 | + 'hierarchical' => false, |
|
| 230 | + 'menu_position' => 52, |
|
| 231 | + 'supports' => $supports_array |
|
| 232 | 232 | ); |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Filter the arguments passed in when registering the Sensei Lesson post type. |
|
| 236 | - * |
|
| 237 | - * @since 1.9.0 |
|
| 238 | - * @param array $args |
|
| 239 | - */ |
|
| 234 | + /** |
|
| 235 | + * Filter the arguments passed in when registering the Sensei Lesson post type. |
|
| 236 | + * |
|
| 237 | + * @since 1.9.0 |
|
| 238 | + * @param array $args |
|
| 239 | + */ |
|
| 240 | 240 | register_post_type( 'lesson', apply_filters( 'sensei_register_post_type_lesson', $args ) ); |
| 241 | 241 | |
| 242 | 242 | } // End setup_lesson_post_type() |
@@ -244,44 +244,44 @@ discard block |
||
| 244 | 244 | /** |
| 245 | 245 | * Setup the "quiz" post type, it's admin menu item and the appropriate labels and permissions. |
| 246 | 246 | * @since 1.0.0 |
| 247 | - * @uses Sensei() |
|
| 247 | + * @uses Sensei() |
|
| 248 | 248 | * @return void |
| 249 | 249 | */ |
| 250 | 250 | public function setup_quiz_post_type () { |
| 251 | 251 | |
| 252 | 252 | $args = array( |
| 253 | - 'labels' => $this->create_post_type_labels( |
|
| 254 | - $this->labels['quiz']['singular'], |
|
| 255 | - $this->labels['quiz']['plural'], |
|
| 256 | - $this->labels['quiz']['menu'] |
|
| 257 | - ), |
|
| 258 | - 'public' => true, |
|
| 259 | - 'publicly_queryable' => true, |
|
| 260 | - 'show_ui' => true, |
|
| 261 | - 'show_in_menu' => false, |
|
| 262 | - 'show_in_nav_menus' => false, |
|
| 263 | - 'query_var' => true, |
|
| 264 | - 'exclude_from_search' => true, |
|
| 265 | - 'rewrite' => array( |
|
| 266 | - 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 267 | - 'with_front' => true, |
|
| 268 | - 'feeds' => true, |
|
| 269 | - 'pages' => true |
|
| 270 | - ), |
|
| 271 | - 'map_meta_cap' => true, |
|
| 272 | - 'capability_type' => 'quiz', |
|
| 273 | - 'has_archive' => false, |
|
| 274 | - 'hierarchical' => false, |
|
| 275 | - 'menu_position' => 20, // Below "Pages" |
|
| 276 | - 'supports' => array( '' ) |
|
| 253 | + 'labels' => $this->create_post_type_labels( |
|
| 254 | + $this->labels['quiz']['singular'], |
|
| 255 | + $this->labels['quiz']['plural'], |
|
| 256 | + $this->labels['quiz']['menu'] |
|
| 257 | + ), |
|
| 258 | + 'public' => true, |
|
| 259 | + 'publicly_queryable' => true, |
|
| 260 | + 'show_ui' => true, |
|
| 261 | + 'show_in_menu' => false, |
|
| 262 | + 'show_in_nav_menus' => false, |
|
| 263 | + 'query_var' => true, |
|
| 264 | + 'exclude_from_search' => true, |
|
| 265 | + 'rewrite' => array( |
|
| 266 | + 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 267 | + 'with_front' => true, |
|
| 268 | + 'feeds' => true, |
|
| 269 | + 'pages' => true |
|
| 270 | + ), |
|
| 271 | + 'map_meta_cap' => true, |
|
| 272 | + 'capability_type' => 'quiz', |
|
| 273 | + 'has_archive' => false, |
|
| 274 | + 'hierarchical' => false, |
|
| 275 | + 'menu_position' => 20, // Below "Pages" |
|
| 276 | + 'supports' => array( '' ) |
|
| 277 | 277 | ); |
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * Filter the arguments passed in when registering the Sensei Quiz post type. |
|
| 281 | - * |
|
| 282 | - * @since 1.9.0 |
|
| 283 | - * @param array $args |
|
| 284 | - */ |
|
| 279 | + /** |
|
| 280 | + * Filter the arguments passed in when registering the Sensei Quiz post type. |
|
| 281 | + * |
|
| 282 | + * @since 1.9.0 |
|
| 283 | + * @param array $args |
|
| 284 | + */ |
|
| 285 | 285 | register_post_type( 'quiz', apply_filters( 'sensei_register_post_type_quiz', $args ) ); |
| 286 | 286 | |
| 287 | 287 | } // End setup_quiz_post_type() |
@@ -295,34 +295,34 @@ discard block |
||
| 295 | 295 | public function setup_question_post_type () { |
| 296 | 296 | |
| 297 | 297 | $args = array( |
| 298 | - 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
| 299 | - 'public' => false, |
|
| 300 | - 'publicly_queryable' => true, |
|
| 301 | - 'show_ui' => true, |
|
| 302 | - 'show_in_menu' => true, |
|
| 303 | - 'show_in_nav_menus' => false, |
|
| 304 | - 'query_var' => true, |
|
| 305 | - 'exclude_from_search' => true, |
|
| 306 | - 'rewrite' => array( |
|
| 307 | - 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 308 | - 'with_front' => true, |
|
| 309 | - 'feeds' => true, |
|
| 310 | - 'pages' => true |
|
| 311 | - ), |
|
| 312 | - 'map_meta_cap' => true, |
|
| 313 | - 'capability_type' => 'question', |
|
| 314 | - 'has_archive' => true, |
|
| 315 | - 'hierarchical' => false, |
|
| 316 | - 'menu_position' => 51, |
|
| 317 | - 'supports' => array( 'title' ) |
|
| 298 | + 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
| 299 | + 'public' => false, |
|
| 300 | + 'publicly_queryable' => true, |
|
| 301 | + 'show_ui' => true, |
|
| 302 | + 'show_in_menu' => true, |
|
| 303 | + 'show_in_nav_menus' => false, |
|
| 304 | + 'query_var' => true, |
|
| 305 | + 'exclude_from_search' => true, |
|
| 306 | + 'rewrite' => array( |
|
| 307 | + 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 308 | + 'with_front' => true, |
|
| 309 | + 'feeds' => true, |
|
| 310 | + 'pages' => true |
|
| 311 | + ), |
|
| 312 | + 'map_meta_cap' => true, |
|
| 313 | + 'capability_type' => 'question', |
|
| 314 | + 'has_archive' => true, |
|
| 315 | + 'hierarchical' => false, |
|
| 316 | + 'menu_position' => 51, |
|
| 317 | + 'supports' => array( 'title' ) |
|
| 318 | 318 | ); |
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * Filter the arguments passed in when registering the Sensei Question post type. |
|
| 322 | - * |
|
| 323 | - * @since 1.9.0 |
|
| 324 | - * @param array $args |
|
| 325 | - */ |
|
| 320 | + /** |
|
| 321 | + * Filter the arguments passed in when registering the Sensei Question post type. |
|
| 322 | + * |
|
| 323 | + * @since 1.9.0 |
|
| 324 | + * @param array $args |
|
| 325 | + */ |
|
| 326 | 326 | register_post_type( 'question', apply_filters('sensei_register_post_type_question', $args ) ); |
| 327 | 327 | |
| 328 | 328 | } // End setup_question_post_type() |
@@ -335,26 +335,26 @@ discard block |
||
| 335 | 335 | public function setup_multiple_question_post_type () { |
| 336 | 336 | |
| 337 | 337 | $args = array( |
| 338 | - 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
| 339 | - 'public' => false, |
|
| 340 | - 'publicly_queryable' => false, |
|
| 341 | - 'show_ui' => false, |
|
| 342 | - 'show_in_menu' => false, |
|
| 343 | - 'show_in_nav_menus' => false, |
|
| 344 | - 'query_var' => false, |
|
| 345 | - 'exclude_from_search' => true, |
|
| 346 | - 'rewrite' => array( |
|
| 347 | - 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 348 | - 'with_front' => false, |
|
| 349 | - 'feeds' => false, |
|
| 350 | - 'pages' => false |
|
| 351 | - ), |
|
| 352 | - 'map_meta_cap' => true, |
|
| 353 | - 'capability_type' => 'question', |
|
| 354 | - 'has_archive' => false, |
|
| 355 | - 'hierarchical' => false, |
|
| 356 | - 'menu_position' => 51, |
|
| 357 | - 'supports' => array( 'title', 'custom-fields' ) |
|
| 338 | + 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
| 339 | + 'public' => false, |
|
| 340 | + 'publicly_queryable' => false, |
|
| 341 | + 'show_ui' => false, |
|
| 342 | + 'show_in_menu' => false, |
|
| 343 | + 'show_in_nav_menus' => false, |
|
| 344 | + 'query_var' => false, |
|
| 345 | + 'exclude_from_search' => true, |
|
| 346 | + 'rewrite' => array( |
|
| 347 | + 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 348 | + 'with_front' => false, |
|
| 349 | + 'feeds' => false, |
|
| 350 | + 'pages' => false |
|
| 351 | + ), |
|
| 352 | + 'map_meta_cap' => true, |
|
| 353 | + 'capability_type' => 'question', |
|
| 354 | + 'has_archive' => false, |
|
| 355 | + 'hierarchical' => false, |
|
| 356 | + 'menu_position' => 51, |
|
| 357 | + 'supports' => array( 'title', 'custom-fields' ) |
|
| 358 | 358 | ); |
| 359 | 359 | |
| 360 | 360 | register_post_type( 'multiple_question', $args ); |
@@ -370,34 +370,34 @@ discard block |
||
| 370 | 370 | if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
| 371 | 371 | |
| 372 | 372 | $args = array( |
| 373 | - 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
| 374 | - 'public' => true, |
|
| 375 | - 'publicly_queryable' => true, |
|
| 376 | - 'show_ui' => true, |
|
| 377 | - 'show_in_menu' => 'admin.php?page=sensei', |
|
| 378 | - 'show_in_nav_menus' => true, |
|
| 379 | - 'query_var' => true, |
|
| 380 | - 'exclude_from_search' => true, |
|
| 381 | - 'rewrite' => array( |
|
| 382 | - 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 383 | - 'with_front' => false, |
|
| 384 | - 'feeds' => false, |
|
| 385 | - 'pages' => true |
|
| 386 | - ), |
|
| 387 | - 'map_meta_cap' => true, |
|
| 388 | - 'capability_type' => 'question', |
|
| 389 | - 'has_archive' => true, |
|
| 390 | - 'hierarchical' => false, |
|
| 391 | - 'menu_position' => 50, |
|
| 392 | - 'supports' => array( 'title', 'editor', 'comments' ), |
|
| 373 | + 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
| 374 | + 'public' => true, |
|
| 375 | + 'publicly_queryable' => true, |
|
| 376 | + 'show_ui' => true, |
|
| 377 | + 'show_in_menu' => 'admin.php?page=sensei', |
|
| 378 | + 'show_in_nav_menus' => true, |
|
| 379 | + 'query_var' => true, |
|
| 380 | + 'exclude_from_search' => true, |
|
| 381 | + 'rewrite' => array( |
|
| 382 | + 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 383 | + 'with_front' => false, |
|
| 384 | + 'feeds' => false, |
|
| 385 | + 'pages' => true |
|
| 386 | + ), |
|
| 387 | + 'map_meta_cap' => true, |
|
| 388 | + 'capability_type' => 'question', |
|
| 389 | + 'has_archive' => true, |
|
| 390 | + 'hierarchical' => false, |
|
| 391 | + 'menu_position' => 50, |
|
| 392 | + 'supports' => array( 'title', 'editor', 'comments' ), |
|
| 393 | 393 | ); |
| 394 | 394 | |
| 395 | - /** |
|
| 396 | - * Filter the arguments passed in when registering the Sensei sensei_message post type. |
|
| 397 | - * |
|
| 398 | - * @since 1.9.0 |
|
| 399 | - * @param array $args |
|
| 400 | - */ |
|
| 395 | + /** |
|
| 396 | + * Filter the arguments passed in when registering the Sensei sensei_message post type. |
|
| 397 | + * |
|
| 398 | + * @since 1.9.0 |
|
| 399 | + * @param array $args |
|
| 400 | + */ |
|
| 401 | 401 | register_post_type( 'sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args ) ); |
| 402 | 402 | } |
| 403 | 403 | } // End setup_sensei_message_post_type() |
@@ -430,11 +430,11 @@ discard block |
||
| 430 | 430 | 'show_ui' => true, |
| 431 | 431 | 'query_var' => true, |
| 432 | 432 | 'show_in_nav_menus' => true, |
| 433 | - 'capabilities' => array( |
|
| 434 | - 'manage_terms' => 'manage_categories', |
|
| 435 | - 'edit_terms' => 'edit_courses', |
|
| 436 | - 'delete_terms' => 'manage_categories', |
|
| 437 | - 'assign_terms' => 'edit_courses',), |
|
| 433 | + 'capabilities' => array( |
|
| 434 | + 'manage_terms' => 'manage_categories', |
|
| 435 | + 'edit_terms' => 'edit_courses', |
|
| 436 | + 'delete_terms' => 'manage_categories', |
|
| 437 | + 'assign_terms' => 'edit_courses',), |
|
| 438 | 438 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_course_category_slug', _x( 'course-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
| 439 | 439 | ); |
| 440 | 440 | |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | 'show_ui' => true, /* TO DO - future releases */ |
| 472 | 472 | 'query_var' => true, |
| 473 | 473 | 'show_in_nav_menus' => false, |
| 474 | - 'public' => false, |
|
| 474 | + 'public' => false, |
|
| 475 | 475 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_quiz_type_slug', _x( 'quiz-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
| 476 | 476 | ); |
| 477 | 477 | |
@@ -544,11 +544,11 @@ discard block |
||
| 544 | 544 | 'query_var' => false, |
| 545 | 545 | 'show_in_nav_menus' => false, |
| 546 | 546 | 'show_admin_column' => true, |
| 547 | - 'capabilities' => array( |
|
| 548 | - 'manage_terms' => 'manage_categories', |
|
| 549 | - 'edit_terms' => 'edit_questions', |
|
| 550 | - 'delete_terms' => 'manage_categories', |
|
| 551 | - 'assign_terms' => 'edit_questions',), |
|
| 547 | + 'capabilities' => array( |
|
| 548 | + 'manage_terms' => 'manage_categories', |
|
| 549 | + 'edit_terms' => 'edit_questions', |
|
| 550 | + 'delete_terms' => 'manage_categories', |
|
| 551 | + 'assign_terms' => 'edit_questions',), |
|
| 552 | 552 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_category_slug', _x( 'question-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
| 553 | 553 | ); |
| 554 | 554 | |
@@ -582,11 +582,11 @@ discard block |
||
| 582 | 582 | 'show_ui' => true, |
| 583 | 583 | 'query_var' => true, |
| 584 | 584 | 'show_in_nav_menus' => true, |
| 585 | - 'capabilities' => array( |
|
| 586 | - 'manage_terms' => 'manage_categories', |
|
| 587 | - 'edit_terms' => 'edit_lessons', |
|
| 588 | - 'delete_terms' => 'manage_categories', |
|
| 589 | - 'assign_terms' => 'edit_lessons',), |
|
| 585 | + 'capabilities' => array( |
|
| 586 | + 'manage_terms' => 'manage_categories', |
|
| 587 | + 'edit_terms' => 'edit_lessons', |
|
| 588 | + 'delete_terms' => 'manage_categories', |
|
| 589 | + 'assign_terms' => 'edit_lessons',), |
|
| 590 | 590 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_lesson_tag_slug', _x( 'lesson-tag', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
| 591 | 591 | ); |
| 592 | 592 | |
@@ -623,19 +623,19 @@ discard block |
||
| 623 | 623 | $lower_case_plural = function_exists( 'mb_strtolower' ) ? mb_strtolower( $plural, 'UTF-8') : strtolower( $plural ); |
| 624 | 624 | |
| 625 | 625 | $labels = array( |
| 626 | - 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
| 627 | - 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
| 628 | - 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
| 629 | - 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
| 630 | - 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
| 631 | - 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
| 632 | - 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
| 633 | - 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
| 634 | - 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
| 635 | - 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), $lower_case_plural ) , |
|
| 636 | - 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), $lower_case_plural ), |
|
| 637 | - 'parent_item_colon' => '', |
|
| 638 | - 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
| 626 | + 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
| 627 | + 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
| 628 | + 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
| 629 | + 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
| 630 | + 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
| 631 | + 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
| 632 | + 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
| 633 | + 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
| 634 | + 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
| 635 | + 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), $lower_case_plural ) , |
|
| 636 | + 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), $lower_case_plural ), |
|
| 637 | + 'parent_item_colon' => '', |
|
| 638 | + 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
| 639 | 639 | ); |
| 640 | 640 | |
| 641 | 641 | return $labels; |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * Assigns the defaults for each user role capabilities. |
| 709 | 709 | * |
| 710 | 710 | * @since 1.1.0 |
| 711 | - * |
|
| 711 | + * |
|
| 712 | 712 | * @param array $post_types |
| 713 | 713 | * @return void |
| 714 | 714 | */ |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | * Adds a 'Edit Quiz' link to the admin bar when viewing a Quiz linked to a corresponding Lesson |
| 777 | 777 | * |
| 778 | 778 | * @since 1.7.0 |
| 779 | - * @param WP_Admin_Bar $bar |
|
| 779 | + * @param WP_Admin_Bar $bar |
|
| 780 | 780 | * @return void |
| 781 | 781 | */ |
| 782 | 782 | public function quiz_admin_bar_menu( $bar ) { |
@@ -1,5 +1,5 @@ discard block |
||
| 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 Post Types Class |
@@ -40,43 +40,43 @@ discard block |
||
| 40 | 40 | * Constructor |
| 41 | 41 | * @since 1.0.0 |
| 42 | 42 | */ |
| 43 | - public function __construct () { |
|
| 43 | + public function __construct() { |
|
| 44 | 44 | |
| 45 | 45 | // Setup Post Types |
| 46 | 46 | $this->labels = array(); |
| 47 | 47 | $this->token = 'woothemes-sensei-posttypes'; |
| 48 | 48 | |
| 49 | 49 | $this->setup_post_type_labels_base(); |
| 50 | - add_action( 'init', array( $this, 'setup_course_post_type' ), 100 ); |
|
| 51 | - add_action( 'init', array( $this, 'setup_lesson_post_type' ), 100 ); |
|
| 52 | - add_action( 'init', array( $this, 'setup_quiz_post_type' ), 100 ); |
|
| 53 | - add_action( 'init', array( $this, 'setup_question_post_type' ), 100 ); |
|
| 54 | - add_action( 'init', array( $this, 'setup_multiple_question_post_type' ), 100 ); |
|
| 55 | - add_action( 'init', array( $this, 'setup_sensei_message_post_type' ), 100 ); |
|
| 50 | + add_action('init', array($this, 'setup_course_post_type'), 100); |
|
| 51 | + add_action('init', array($this, 'setup_lesson_post_type'), 100); |
|
| 52 | + add_action('init', array($this, 'setup_quiz_post_type'), 100); |
|
| 53 | + add_action('init', array($this, 'setup_question_post_type'), 100); |
|
| 54 | + add_action('init', array($this, 'setup_multiple_question_post_type'), 100); |
|
| 55 | + add_action('init', array($this, 'setup_sensei_message_post_type'), 100); |
|
| 56 | 56 | |
| 57 | 57 | // Setup Taxonomies |
| 58 | - add_action( 'init', array( $this, 'setup_course_category_taxonomy' ), 100 ); |
|
| 59 | - add_action( 'init', array( $this, 'setup_quiz_type_taxonomy' ), 100 ); |
|
| 60 | - add_action( 'init', array( $this, 'setup_question_type_taxonomy' ), 100 ); |
|
| 61 | - add_action( 'init', array( $this, 'setup_question_category_taxonomy' ), 100 ); |
|
| 62 | - add_action( 'init', array( $this, 'setup_lesson_tag_taxonomy' ), 100 ); |
|
| 58 | + add_action('init', array($this, 'setup_course_category_taxonomy'), 100); |
|
| 59 | + add_action('init', array($this, 'setup_quiz_type_taxonomy'), 100); |
|
| 60 | + add_action('init', array($this, 'setup_question_type_taxonomy'), 100); |
|
| 61 | + add_action('init', array($this, 'setup_question_category_taxonomy'), 100); |
|
| 62 | + add_action('init', array($this, 'setup_lesson_tag_taxonomy'), 100); |
|
| 63 | 63 | |
| 64 | 64 | // Load Post Type Objects |
| 65 | - $default_post_types = array( 'course' => 'Course', 'lesson' => 'Lesson', 'quiz' => 'Quiz', 'question' => 'Question', 'messages' => 'Messages' ) ; |
|
| 66 | - $this->load_posttype_objects( $default_post_types ); |
|
| 65 | + $default_post_types = array('course' => 'Course', 'lesson' => 'Lesson', 'quiz' => 'Quiz', 'question' => 'Question', 'messages' => 'Messages'); |
|
| 66 | + $this->load_posttype_objects($default_post_types); |
|
| 67 | 67 | |
| 68 | 68 | // Admin functions |
| 69 | - if ( is_admin() ) { |
|
| 70 | - $this->set_role_cap_defaults( $default_post_types ); |
|
| 69 | + if (is_admin()) { |
|
| 70 | + $this->set_role_cap_defaults($default_post_types); |
|
| 71 | 71 | global $pagenow; |
| 72 | - if ( ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) ) { |
|
| 73 | - add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 10 ); |
|
| 74 | - add_filter( 'post_updated_messages', array( $this, 'setup_post_type_messages' ) ); |
|
| 72 | + if (($pagenow == 'post.php' || $pagenow == 'post-new.php')) { |
|
| 73 | + add_filter('enter_title_here', array($this, 'enter_title_here'), 10); |
|
| 74 | + add_filter('post_updated_messages', array($this, 'setup_post_type_messages')); |
|
| 75 | 75 | } // End If Statement |
| 76 | 76 | } // End If Statement |
| 77 | 77 | |
| 78 | 78 | // Add 'Edit Quiz' link to admin bar |
| 79 | - add_action( 'admin_bar_menu', array( $this, 'quiz_admin_bar_menu' ), 81 ); |
|
| 79 | + add_action('admin_bar_menu', array($this, 'quiz_admin_bar_menu'), 81); |
|
| 80 | 80 | |
| 81 | 81 | } // End __construct() |
| 82 | 82 | |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | * @param array $posttypes (default: array()) |
| 88 | 88 | * @return void |
| 89 | 89 | */ |
| 90 | - public function load_posttype_objects( $posttypes = array() ) { |
|
| 90 | + public function load_posttype_objects($posttypes = array()) { |
|
| 91 | 91 | |
| 92 | - foreach ( $posttypes as $posttype_token => $posttype_name ) { |
|
| 92 | + foreach ($posttypes as $posttype_token => $posttype_name) { |
|
| 93 | 93 | |
| 94 | 94 | // Load the files |
| 95 | - $class_name = 'WooThemes_Sensei_' . $posttype_name; |
|
| 95 | + $class_name = 'WooThemes_Sensei_'.$posttype_name; |
|
| 96 | 96 | $this->$posttype_token = new $class_name(); |
| 97 | 97 | $this->$posttype_token->token = $posttype_token; |
| 98 | 98 | |
@@ -106,10 +106,10 @@ discard block |
||
| 106 | 106 | * @uses Sensei() |
| 107 | 107 | * @return void |
| 108 | 108 | */ |
| 109 | - public function setup_course_post_type () { |
|
| 109 | + public function setup_course_post_type() { |
|
| 110 | 110 | |
| 111 | 111 | $args = array( |
| 112 | - 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
| 112 | + 'labels' => $this->create_post_type_labels($this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu']), |
|
| 113 | 113 | 'public' => true, |
| 114 | 114 | 'publicly_queryable' => true, |
| 115 | 115 | 'show_ui' => true, |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | 'show_in_admin_bar' => true, |
| 118 | 118 | 'query_var' => true, |
| 119 | 119 | 'rewrite' => array( |
| 120 | - 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
| 120 | + 'slug' => esc_attr(apply_filters('sensei_course_slug', _x('course', 'post type single url base', 'woothemes-sensei'))), |
|
| 121 | 121 | 'with_front' => true, |
| 122 | 122 | 'feeds' => true, |
| 123 | 123 | 'pages' => true |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | 'has_archive' => $this->get_course_post_type_archive_slug(), |
| 128 | 128 | 'hierarchical' => false, |
| 129 | 129 | 'menu_position' => 51, |
| 130 | - 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
| 130 | + 'supports' => array('title', 'editor', 'excerpt', 'thumbnail') |
|
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | * @since 1.9.0 |
| 137 | 137 | * @param array $args |
| 138 | 138 | */ |
| 139 | - register_post_type( 'course', apply_filters( 'sensei_register_post_type_course', $args ) ); |
|
| 139 | + register_post_type('course', apply_filters('sensei_register_post_type_course', $args)); |
|
| 140 | 140 | |
| 141 | 141 | } // End setup_course_post_type() |
| 142 | 142 | |
@@ -155,17 +155,17 @@ discard block |
||
| 155 | 155 | * |
| 156 | 156 | * @return false|string |
| 157 | 157 | */ |
| 158 | - public function get_course_post_type_archive_slug(){ |
|
| 158 | + public function get_course_post_type_archive_slug() { |
|
| 159 | 159 | |
| 160 | - $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
| 160 | + $settings_course_page = get_post(Sensei()->settings->get('course_page')); |
|
| 161 | 161 | |
| 162 | 162 | // for a valid post that doesn't have any of the old short codes set the archive the same |
| 163 | 163 | // as the page URI |
| 164 | - if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
| 164 | + if (is_a($settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes($settings_course_page->post_content)) { |
|
| 165 | 165 | |
| 166 | - return get_page_uri( $settings_course_page->ID ); |
|
| 166 | + return get_page_uri($settings_course_page->ID); |
|
| 167 | 167 | |
| 168 | - }else{ |
|
| 168 | + } else { |
|
| 169 | 169 | |
| 170 | 170 | return 'courses'; |
| 171 | 171 | |
@@ -183,12 +183,12 @@ discard block |
||
| 183 | 183 | * |
| 184 | 184 | * @return bool |
| 185 | 185 | */ |
| 186 | - public function has_old_shortcodes( $content ){ |
|
| 186 | + public function has_old_shortcodes($content) { |
|
| 187 | 187 | |
| 188 | - return ( has_shortcode( $content, 'newcourses') |
|
| 189 | - || has_shortcode( $content, 'featuredcourses') |
|
| 190 | - || has_shortcode( $content, 'freecourses') |
|
| 191 | - || has_shortcode( $content, 'paidcourses') ); |
|
| 188 | + return (has_shortcode($content, 'newcourses') |
|
| 189 | + || has_shortcode($content, 'featuredcourses') |
|
| 190 | + || has_shortcode($content, 'freecourses') |
|
| 191 | + || has_shortcode($content, 'paidcourses')); |
|
| 192 | 192 | |
| 193 | 193 | }// end has old shortcodes |
| 194 | 194 | |
@@ -199,26 +199,26 @@ discard block |
||
| 199 | 199 | * @uses Sensei() |
| 200 | 200 | * @return void |
| 201 | 201 | */ |
| 202 | - public function setup_lesson_post_type () { |
|
| 202 | + public function setup_lesson_post_type() { |
|
| 203 | 203 | |
| 204 | - $supports_array = array( 'title', 'editor', 'excerpt', 'thumbnail', 'page-attributes' ); |
|
| 204 | + $supports_array = array('title', 'editor', 'excerpt', 'thumbnail', 'page-attributes'); |
|
| 205 | 205 | $allow_comments = false; |
| 206 | - if ( isset( Sensei()->settings->settings[ 'lesson_comments' ] ) ) { |
|
| 207 | - $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ]; |
|
| 206 | + if (isset(Sensei()->settings->settings['lesson_comments'])) { |
|
| 207 | + $allow_comments = Sensei()->settings->settings['lesson_comments']; |
|
| 208 | 208 | } // End If Statement |
| 209 | - if ( $allow_comments ) { |
|
| 210 | - array_push( $supports_array, 'comments' ); |
|
| 209 | + if ($allow_comments) { |
|
| 210 | + array_push($supports_array, 'comments'); |
|
| 211 | 211 | } // End If Statement |
| 212 | 212 | |
| 213 | 213 | $args = array( |
| 214 | - 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
| 214 | + 'labels' => $this->create_post_type_labels($this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu']), |
|
| 215 | 215 | 'public' => true, |
| 216 | 216 | 'publicly_queryable' => true, |
| 217 | 217 | 'show_ui' => true, |
| 218 | 218 | 'show_in_menu' => true, |
| 219 | 219 | 'query_var' => true, |
| 220 | 220 | 'rewrite' => array( |
| 221 | - 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 221 | + 'slug' => esc_attr(apply_filters('sensei_lesson_slug', _x('lesson', 'post type single slug', 'woothemes-sensei'))), |
|
| 222 | 222 | 'with_front' => true, |
| 223 | 223 | 'feeds' => true, |
| 224 | 224 | 'pages' => true |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * @since 1.9.0 |
| 238 | 238 | * @param array $args |
| 239 | 239 | */ |
| 240 | - register_post_type( 'lesson', apply_filters( 'sensei_register_post_type_lesson', $args ) ); |
|
| 240 | + register_post_type('lesson', apply_filters('sensei_register_post_type_lesson', $args)); |
|
| 241 | 241 | |
| 242 | 242 | } // End setup_lesson_post_type() |
| 243 | 243 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * @uses Sensei() |
| 248 | 248 | * @return void |
| 249 | 249 | */ |
| 250 | - public function setup_quiz_post_type () { |
|
| 250 | + public function setup_quiz_post_type() { |
|
| 251 | 251 | |
| 252 | 252 | $args = array( |
| 253 | 253 | 'labels' => $this->create_post_type_labels( |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | 'query_var' => true, |
| 264 | 264 | 'exclude_from_search' => true, |
| 265 | 265 | 'rewrite' => array( |
| 266 | - 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 266 | + 'slug' => esc_attr(apply_filters('sensei_quiz_slug', _x('quiz', 'post type single slug', 'woothemes-sensei'))), |
|
| 267 | 267 | 'with_front' => true, |
| 268 | 268 | 'feeds' => true, |
| 269 | 269 | 'pages' => true |
@@ -273,7 +273,7 @@ discard block |
||
| 273 | 273 | 'has_archive' => false, |
| 274 | 274 | 'hierarchical' => false, |
| 275 | 275 | 'menu_position' => 20, // Below "Pages" |
| 276 | - 'supports' => array( '' ) |
|
| 276 | + 'supports' => array('') |
|
| 277 | 277 | ); |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | * @since 1.9.0 |
| 283 | 283 | * @param array $args |
| 284 | 284 | */ |
| 285 | - register_post_type( 'quiz', apply_filters( 'sensei_register_post_type_quiz', $args ) ); |
|
| 285 | + register_post_type('quiz', apply_filters('sensei_register_post_type_quiz', $args)); |
|
| 286 | 286 | |
| 287 | 287 | } // End setup_quiz_post_type() |
| 288 | 288 | |
@@ -292,10 +292,10 @@ discard block |
||
| 292 | 292 | * @since 1.0.0 |
| 293 | 293 | * @return void |
| 294 | 294 | */ |
| 295 | - public function setup_question_post_type () { |
|
| 295 | + public function setup_question_post_type() { |
|
| 296 | 296 | |
| 297 | 297 | $args = array( |
| 298 | - 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
| 298 | + 'labels' => $this->create_post_type_labels($this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu']), |
|
| 299 | 299 | 'public' => false, |
| 300 | 300 | 'publicly_queryable' => true, |
| 301 | 301 | 'show_ui' => true, |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | 'query_var' => true, |
| 305 | 305 | 'exclude_from_search' => true, |
| 306 | 306 | 'rewrite' => array( |
| 307 | - 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 307 | + 'slug' => esc_attr(apply_filters('sensei_question_slug', _x('question', 'post type single slug', 'woothemes-sensei'))), |
|
| 308 | 308 | 'with_front' => true, |
| 309 | 309 | 'feeds' => true, |
| 310 | 310 | 'pages' => true |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | 'has_archive' => true, |
| 315 | 315 | 'hierarchical' => false, |
| 316 | 316 | 'menu_position' => 51, |
| 317 | - 'supports' => array( 'title' ) |
|
| 317 | + 'supports' => array('title') |
|
| 318 | 318 | ); |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | * @since 1.9.0 |
| 324 | 324 | * @param array $args |
| 325 | 325 | */ |
| 326 | - register_post_type( 'question', apply_filters('sensei_register_post_type_question', $args ) ); |
|
| 326 | + register_post_type('question', apply_filters('sensei_register_post_type_question', $args)); |
|
| 327 | 327 | |
| 328 | 328 | } // End setup_question_post_type() |
| 329 | 329 | |
@@ -332,10 +332,10 @@ discard block |
||
| 332 | 332 | * @since 1.6.0 |
| 333 | 333 | * @return void |
| 334 | 334 | */ |
| 335 | - public function setup_multiple_question_post_type () { |
|
| 335 | + public function setup_multiple_question_post_type() { |
|
| 336 | 336 | |
| 337 | 337 | $args = array( |
| 338 | - 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
| 338 | + 'labels' => $this->create_post_type_labels($this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu']), |
|
| 339 | 339 | 'public' => false, |
| 340 | 340 | 'publicly_queryable' => false, |
| 341 | 341 | 'show_ui' => false, |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | 'query_var' => false, |
| 345 | 345 | 'exclude_from_search' => true, |
| 346 | 346 | 'rewrite' => array( |
| 347 | - 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 347 | + 'slug' => esc_attr(apply_filters('sensei_multiple_question_slug', _x('multiple_question', 'post type single slug', 'woothemes-sensei'))), |
|
| 348 | 348 | 'with_front' => false, |
| 349 | 349 | 'feeds' => false, |
| 350 | 350 | 'pages' => false |
@@ -354,10 +354,10 @@ discard block |
||
| 354 | 354 | 'has_archive' => false, |
| 355 | 355 | 'hierarchical' => false, |
| 356 | 356 | 'menu_position' => 51, |
| 357 | - 'supports' => array( 'title', 'custom-fields' ) |
|
| 357 | + 'supports' => array('title', 'custom-fields') |
|
| 358 | 358 | ); |
| 359 | 359 | |
| 360 | - register_post_type( 'multiple_question', $args ); |
|
| 360 | + register_post_type('multiple_question', $args); |
|
| 361 | 361 | } // End setup_multiple_question_post_type() |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -365,12 +365,12 @@ discard block |
||
| 365 | 365 | * @since 1.6.0 |
| 366 | 366 | * @return void |
| 367 | 367 | */ |
| 368 | - public function setup_sensei_message_post_type () { |
|
| 368 | + public function setup_sensei_message_post_type() { |
|
| 369 | 369 | |
| 370 | - if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
|
| 370 | + if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) { |
|
| 371 | 371 | |
| 372 | 372 | $args = array( |
| 373 | - 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
| 373 | + 'labels' => $this->create_post_type_labels($this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu']), |
|
| 374 | 374 | 'public' => true, |
| 375 | 375 | 'publicly_queryable' => true, |
| 376 | 376 | 'show_ui' => true, |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | 'query_var' => true, |
| 380 | 380 | 'exclude_from_search' => true, |
| 381 | 381 | 'rewrite' => array( |
| 382 | - 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 382 | + 'slug' => esc_attr(apply_filters('sensei_messages_slug', _x('messages', 'post type single slug', 'woothemes-sensei'))), |
|
| 383 | 383 | 'with_front' => false, |
| 384 | 384 | 'feeds' => false, |
| 385 | 385 | 'pages' => true |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | 'has_archive' => true, |
| 390 | 390 | 'hierarchical' => false, |
| 391 | 391 | 'menu_position' => 50, |
| 392 | - 'supports' => array( 'title', 'editor', 'comments' ), |
|
| 392 | + 'supports' => array('title', 'editor', 'comments'), |
|
| 393 | 393 | ); |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @since 1.9.0 |
| 399 | 399 | * @param array $args |
| 400 | 400 | */ |
| 401 | - register_post_type( 'sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args ) ); |
|
| 401 | + register_post_type('sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args)); |
|
| 402 | 402 | } |
| 403 | 403 | } // End setup_sensei_message_post_type() |
| 404 | 404 | |
@@ -407,20 +407,20 @@ discard block |
||
| 407 | 407 | * @since 1.1.0 |
| 408 | 408 | * @return void |
| 409 | 409 | */ |
| 410 | - public function setup_course_category_taxonomy () { |
|
| 410 | + public function setup_course_category_taxonomy() { |
|
| 411 | 411 | // "Course Categories" Custom Taxonomy |
| 412 | 412 | $labels = array( |
| 413 | - 'name' => _x( 'Course Categories', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 414 | - 'singular_name' => _x( 'Course Category', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 415 | - 'search_items' => __( 'Search Course Categories', 'woothemes-sensei' ), |
|
| 416 | - 'all_items' => __( 'All Course Categories', 'woothemes-sensei' ), |
|
| 417 | - 'parent_item' => __( 'Parent Course Category', 'woothemes-sensei' ), |
|
| 418 | - 'parent_item_colon' => __( 'Parent Course Category:', 'woothemes-sensei' ), |
|
| 419 | - 'edit_item' => __( 'Edit Course Category', 'woothemes-sensei' ), |
|
| 420 | - 'update_item' => __( 'Update Course Category', 'woothemes-sensei' ), |
|
| 421 | - 'add_new_item' => __( 'Add New Course Category', 'woothemes-sensei' ), |
|
| 422 | - 'new_item_name' => __( 'New Course Category Name', 'woothemes-sensei' ), |
|
| 423 | - 'menu_name' => __( 'Course Categories', 'woothemes-sensei' ), |
|
| 413 | + 'name' => _x('Course Categories', 'taxonomy general name', 'woothemes-sensei'), |
|
| 414 | + 'singular_name' => _x('Course Category', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 415 | + 'search_items' => __('Search Course Categories', 'woothemes-sensei'), |
|
| 416 | + 'all_items' => __('All Course Categories', 'woothemes-sensei'), |
|
| 417 | + 'parent_item' => __('Parent Course Category', 'woothemes-sensei'), |
|
| 418 | + 'parent_item_colon' => __('Parent Course Category:', 'woothemes-sensei'), |
|
| 419 | + 'edit_item' => __('Edit Course Category', 'woothemes-sensei'), |
|
| 420 | + 'update_item' => __('Update Course Category', 'woothemes-sensei'), |
|
| 421 | + 'add_new_item' => __('Add New Course Category', 'woothemes-sensei'), |
|
| 422 | + 'new_item_name' => __('New Course Category Name', 'woothemes-sensei'), |
|
| 423 | + 'menu_name' => __('Course Categories', 'woothemes-sensei'), |
|
| 424 | 424 | 'popular_items' => null // Hides the "Popular" section above the "add" form in the admin. |
| 425 | 425 | ); |
| 426 | 426 | |
@@ -435,10 +435,10 @@ discard block |
||
| 435 | 435 | 'edit_terms' => 'edit_courses', |
| 436 | 436 | 'delete_terms' => 'manage_categories', |
| 437 | 437 | 'assign_terms' => 'edit_courses',), |
| 438 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_course_category_slug', _x( 'course-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 438 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_course_category_slug', _x('course-category', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 439 | 439 | ); |
| 440 | 440 | |
| 441 | - register_taxonomy( 'course-category', array( 'course' ), $args ); |
|
| 441 | + register_taxonomy('course-category', array('course'), $args); |
|
| 442 | 442 | |
| 443 | 443 | } // End setup_course_category_taxonomy() |
| 444 | 444 | |
@@ -447,21 +447,21 @@ discard block |
||
| 447 | 447 | * @since 1.0.0 |
| 448 | 448 | * @return void |
| 449 | 449 | */ |
| 450 | - public function setup_quiz_type_taxonomy () { |
|
| 450 | + public function setup_quiz_type_taxonomy() { |
|
| 451 | 451 | |
| 452 | 452 | // "Quiz Types" Custom Taxonomy |
| 453 | 453 | $labels = array( |
| 454 | - 'name' => _x( 'Quiz Types', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 455 | - 'singular_name' => _x( 'Quiz Type', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 456 | - 'search_items' => __( 'Search Quiz Types', 'woothemes-sensei' ), |
|
| 457 | - 'all_items' => __( 'All Quiz Types', 'woothemes-sensei' ), |
|
| 458 | - 'parent_item' => __( 'Parent Quiz Type', 'woothemes-sensei' ), |
|
| 459 | - 'parent_item_colon' => __( 'Parent Quiz Type:', 'woothemes-sensei' ), |
|
| 460 | - 'edit_item' => __( 'Edit Quiz Type', 'woothemes-sensei' ), |
|
| 461 | - 'update_item' => __( 'Update Quiz Type', 'woothemes-sensei' ), |
|
| 462 | - 'add_new_item' => __( 'Add New Quiz Type', 'woothemes-sensei' ), |
|
| 463 | - 'new_item_name' => __( 'New Quiz Type Name', 'woothemes-sensei' ), |
|
| 464 | - 'menu_name' => __( 'Quiz Types', 'woothemes-sensei' ), |
|
| 454 | + 'name' => _x('Quiz Types', 'taxonomy general name', 'woothemes-sensei'), |
|
| 455 | + 'singular_name' => _x('Quiz Type', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 456 | + 'search_items' => __('Search Quiz Types', 'woothemes-sensei'), |
|
| 457 | + 'all_items' => __('All Quiz Types', 'woothemes-sensei'), |
|
| 458 | + 'parent_item' => __('Parent Quiz Type', 'woothemes-sensei'), |
|
| 459 | + 'parent_item_colon' => __('Parent Quiz Type:', 'woothemes-sensei'), |
|
| 460 | + 'edit_item' => __('Edit Quiz Type', 'woothemes-sensei'), |
|
| 461 | + 'update_item' => __('Update Quiz Type', 'woothemes-sensei'), |
|
| 462 | + 'add_new_item' => __('Add New Quiz Type', 'woothemes-sensei'), |
|
| 463 | + 'new_item_name' => __('New Quiz Type Name', 'woothemes-sensei'), |
|
| 464 | + 'menu_name' => __('Quiz Types', 'woothemes-sensei'), |
|
| 465 | 465 | 'popular_items' => null // Hides the "Popular" section above the "add" form in the admin. |
| 466 | 466 | ); |
| 467 | 467 | |
@@ -472,10 +472,10 @@ discard block |
||
| 472 | 472 | 'query_var' => true, |
| 473 | 473 | 'show_in_nav_menus' => false, |
| 474 | 474 | 'public' => false, |
| 475 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_quiz_type_slug', _x( 'quiz-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 475 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_quiz_type_slug', _x('quiz-type', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 476 | 476 | ); |
| 477 | 477 | |
| 478 | - register_taxonomy( 'quiz-type', array( 'quiz' ), $args ); |
|
| 478 | + register_taxonomy('quiz-type', array('quiz'), $args); |
|
| 479 | 479 | } // End setup_quiz_type_taxonomy() |
| 480 | 480 | |
| 481 | 481 | /** |
@@ -483,21 +483,21 @@ discard block |
||
| 483 | 483 | * @since 1.3.0 |
| 484 | 484 | * @return void |
| 485 | 485 | */ |
| 486 | - public function setup_question_type_taxonomy () { |
|
| 486 | + public function setup_question_type_taxonomy() { |
|
| 487 | 487 | |
| 488 | 488 | // "Question Types" Custom Taxonomy |
| 489 | 489 | $labels = array( |
| 490 | - 'name' => _x( 'Question Types', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 491 | - 'singular_name' => _x( 'Question Type', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 492 | - 'search_items' => __( 'Search Question Types', 'woothemes-sensei' ), |
|
| 493 | - 'all_items' => __( 'All Question Types', 'woothemes-sensei' ), |
|
| 494 | - 'parent_item' => __( 'Parent Question Type', 'woothemes-sensei' ), |
|
| 495 | - 'parent_item_colon' => __( 'Parent Question Type:', 'woothemes-sensei' ), |
|
| 496 | - 'edit_item' => __( 'Edit Question Type', 'woothemes-sensei' ), |
|
| 497 | - 'update_item' => __( 'Update Question Type', 'woothemes-sensei' ), |
|
| 498 | - 'add_new_item' => __( 'Add New Question Type', 'woothemes-sensei' ), |
|
| 499 | - 'new_item_name' => __( 'New Question Type Name', 'woothemes-sensei' ), |
|
| 500 | - 'menu_name' => __( 'Question Types', 'woothemes-sensei' ), |
|
| 490 | + 'name' => _x('Question Types', 'taxonomy general name', 'woothemes-sensei'), |
|
| 491 | + 'singular_name' => _x('Question Type', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 492 | + 'search_items' => __('Search Question Types', 'woothemes-sensei'), |
|
| 493 | + 'all_items' => __('All Question Types', 'woothemes-sensei'), |
|
| 494 | + 'parent_item' => __('Parent Question Type', 'woothemes-sensei'), |
|
| 495 | + 'parent_item_colon' => __('Parent Question Type:', 'woothemes-sensei'), |
|
| 496 | + 'edit_item' => __('Edit Question Type', 'woothemes-sensei'), |
|
| 497 | + 'update_item' => __('Update Question Type', 'woothemes-sensei'), |
|
| 498 | + 'add_new_item' => __('Add New Question Type', 'woothemes-sensei'), |
|
| 499 | + 'new_item_name' => __('New Question Type Name', 'woothemes-sensei'), |
|
| 500 | + 'menu_name' => __('Question Types', 'woothemes-sensei'), |
|
| 501 | 501 | 'popular_items' => null // Hides the "Popular" section above the "add" form in the admin. |
| 502 | 502 | ); |
| 503 | 503 | |
@@ -509,10 +509,10 @@ discard block |
||
| 509 | 509 | 'query_var' => false, |
| 510 | 510 | 'show_in_nav_menus' => false, |
| 511 | 511 | 'show_admin_column' => true, |
| 512 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_type_slug', _x( 'question-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 512 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_question_type_slug', _x('question-type', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 513 | 513 | ); |
| 514 | 514 | |
| 515 | - register_taxonomy( 'question-type', array( 'question' ), $args ); |
|
| 515 | + register_taxonomy('question-type', array('question'), $args); |
|
| 516 | 516 | } // End setup_question_type_taxonomy() |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -520,20 +520,20 @@ discard block |
||
| 520 | 520 | * @since 1.3.0 |
| 521 | 521 | * @return void |
| 522 | 522 | */ |
| 523 | - public function setup_question_category_taxonomy () { |
|
| 523 | + public function setup_question_category_taxonomy() { |
|
| 524 | 524 | // "Question Categories" Custom Taxonomy |
| 525 | 525 | $labels = array( |
| 526 | - 'name' => _x( 'Question Categories', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 527 | - 'singular_name' => _x( 'Question Category', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 528 | - 'search_items' => __( 'Search Question Categories', 'woothemes-sensei' ), |
|
| 529 | - 'all_items' => __( 'All Question Categories', 'woothemes-sensei' ), |
|
| 530 | - 'parent_item' => __( 'Parent Question Category', 'woothemes-sensei' ), |
|
| 531 | - 'parent_item_colon' => __( 'Parent Question Category:', 'woothemes-sensei' ), |
|
| 532 | - 'edit_item' => __( 'Edit Question Category', 'woothemes-sensei' ), |
|
| 533 | - 'update_item' => __( 'Update Question Category', 'woothemes-sensei' ), |
|
| 534 | - 'add_new_item' => __( 'Add New Question Category', 'woothemes-sensei' ), |
|
| 535 | - 'new_item_name' => __( 'New Question Category Name', 'woothemes-sensei' ), |
|
| 536 | - 'menu_name' => __( 'Categories', 'woothemes-sensei' ), |
|
| 526 | + 'name' => _x('Question Categories', 'taxonomy general name', 'woothemes-sensei'), |
|
| 527 | + 'singular_name' => _x('Question Category', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 528 | + 'search_items' => __('Search Question Categories', 'woothemes-sensei'), |
|
| 529 | + 'all_items' => __('All Question Categories', 'woothemes-sensei'), |
|
| 530 | + 'parent_item' => __('Parent Question Category', 'woothemes-sensei'), |
|
| 531 | + 'parent_item_colon' => __('Parent Question Category:', 'woothemes-sensei'), |
|
| 532 | + 'edit_item' => __('Edit Question Category', 'woothemes-sensei'), |
|
| 533 | + 'update_item' => __('Update Question Category', 'woothemes-sensei'), |
|
| 534 | + 'add_new_item' => __('Add New Question Category', 'woothemes-sensei'), |
|
| 535 | + 'new_item_name' => __('New Question Category Name', 'woothemes-sensei'), |
|
| 536 | + 'menu_name' => __('Categories', 'woothemes-sensei'), |
|
| 537 | 537 | ); |
| 538 | 538 | |
| 539 | 539 | $args = array( |
@@ -549,10 +549,10 @@ discard block |
||
| 549 | 549 | 'edit_terms' => 'edit_questions', |
| 550 | 550 | 'delete_terms' => 'manage_categories', |
| 551 | 551 | 'assign_terms' => 'edit_questions',), |
| 552 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_category_slug', _x( 'question-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 552 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_question_category_slug', _x('question-category', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 553 | 553 | ); |
| 554 | 554 | |
| 555 | - register_taxonomy( 'question-category', array( 'question' ), $args ); |
|
| 555 | + register_taxonomy('question-category', array('question'), $args); |
|
| 556 | 556 | } // End setup_question_type_taxonomy() |
| 557 | 557 | |
| 558 | 558 | /** |
@@ -560,20 +560,20 @@ discard block |
||
| 560 | 560 | * @since 1.5.0 |
| 561 | 561 | * @return void |
| 562 | 562 | */ |
| 563 | - public function setup_lesson_tag_taxonomy () { |
|
| 563 | + public function setup_lesson_tag_taxonomy() { |
|
| 564 | 564 | // "Lesson Tags" Custom Taxonomy |
| 565 | 565 | $labels = array( |
| 566 | - 'name' => _x( 'Lesson Tags', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 567 | - 'singular_name' => _x( 'Lesson Tag', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 568 | - 'search_items' => __( 'Search Lesson Tags', 'woothemes-sensei' ), |
|
| 569 | - 'all_items' => __( 'All Lesson Tags', 'woothemes-sensei' ), |
|
| 570 | - 'parent_item' => __( 'Parent Tag', 'woothemes-sensei' ), |
|
| 571 | - 'parent_item_colon' => __( 'Parent Tag:', 'woothemes-sensei' ), |
|
| 572 | - 'edit_item' => __( 'Edit Lesson Tag', 'woothemes-sensei' ), |
|
| 573 | - 'update_item' => __( 'Update Lesson Tag', 'woothemes-sensei' ), |
|
| 574 | - 'add_new_item' => __( 'Add New Lesson Tag', 'woothemes-sensei' ), |
|
| 575 | - 'new_item_name' => __( 'New Tag Name', 'woothemes-sensei' ), |
|
| 576 | - 'menu_name' => __( 'Lesson Tags', 'woothemes-sensei' ) |
|
| 566 | + 'name' => _x('Lesson Tags', 'taxonomy general name', 'woothemes-sensei'), |
|
| 567 | + 'singular_name' => _x('Lesson Tag', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 568 | + 'search_items' => __('Search Lesson Tags', 'woothemes-sensei'), |
|
| 569 | + 'all_items' => __('All Lesson Tags', 'woothemes-sensei'), |
|
| 570 | + 'parent_item' => __('Parent Tag', 'woothemes-sensei'), |
|
| 571 | + 'parent_item_colon' => __('Parent Tag:', 'woothemes-sensei'), |
|
| 572 | + 'edit_item' => __('Edit Lesson Tag', 'woothemes-sensei'), |
|
| 573 | + 'update_item' => __('Update Lesson Tag', 'woothemes-sensei'), |
|
| 574 | + 'add_new_item' => __('Add New Lesson Tag', 'woothemes-sensei'), |
|
| 575 | + 'new_item_name' => __('New Tag Name', 'woothemes-sensei'), |
|
| 576 | + 'menu_name' => __('Lesson Tags', 'woothemes-sensei') |
|
| 577 | 577 | ); |
| 578 | 578 | |
| 579 | 579 | $args = array( |
@@ -587,10 +587,10 @@ discard block |
||
| 587 | 587 | 'edit_terms' => 'edit_lessons', |
| 588 | 588 | 'delete_terms' => 'manage_categories', |
| 589 | 589 | 'assign_terms' => 'edit_lessons',), |
| 590 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_lesson_tag_slug', _x( 'lesson-tag', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 590 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_lesson_tag_slug', _x('lesson-tag', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 591 | 591 | ); |
| 592 | 592 | |
| 593 | - register_taxonomy( 'lesson-tag', array( 'lesson' ), $args ); |
|
| 593 | + register_taxonomy('lesson-tag', array('lesson'), $args); |
|
| 594 | 594 | } // End setup_lesson_tag_taxonomy() |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -598,15 +598,15 @@ discard block |
||
| 598 | 598 | * @since 1.0.0 |
| 599 | 599 | * @return void |
| 600 | 600 | */ |
| 601 | - private function setup_post_type_labels_base () { |
|
| 602 | - $this->labels = array( 'course' => array(), 'lesson' => array(), 'quiz' => array(), 'question' => array() ); |
|
| 601 | + private function setup_post_type_labels_base() { |
|
| 602 | + $this->labels = array('course' => array(), 'lesson' => array(), 'quiz' => array(), 'question' => array()); |
|
| 603 | 603 | |
| 604 | - $this->labels['course'] = array( 'singular' => __( 'Course', 'woothemes-sensei' ), 'plural' => __( 'Courses', 'woothemes-sensei' ), 'menu' => __( 'Courses', 'woothemes-sensei' ) ); |
|
| 605 | - $this->labels['lesson'] = array( 'singular' => __( 'Lesson', 'woothemes-sensei' ), 'plural' => __( 'Lessons', 'woothemes-sensei' ), 'menu' => __( 'Lessons', 'woothemes-sensei' ) ); |
|
| 606 | - $this->labels['quiz'] = array( 'singular' => __( 'Quiz', 'woothemes-sensei' ), 'plural' => __( 'Quizzes', 'woothemes-sensei' ), 'menu' => __( 'Quizzes', 'woothemes-sensei' ) ); |
|
| 607 | - $this->labels['question'] = array( 'singular' => __( 'Question', 'woothemes-sensei' ), 'plural' => __( 'Questions', 'woothemes-sensei' ), 'menu' => __( 'Questions', 'woothemes-sensei' ) ); |
|
| 608 | - $this->labels['multiple_question'] = array( 'singular' => __( 'Multiple Question', 'woothemes-sensei' ), 'plural' => __( 'Multiple Questions', 'woothemes-sensei' ), 'menu' => __( 'Multiple Questions', 'woothemes-sensei' ) ); |
|
| 609 | - $this->labels['sensei_message'] = array( 'singular' => __( 'Message', 'woothemes-sensei' ), 'plural' => __( 'Messages', 'woothemes-sensei' ), 'menu' => __( 'Messages', 'woothemes-sensei' ) ); |
|
| 604 | + $this->labels['course'] = array('singular' => __('Course', 'woothemes-sensei'), 'plural' => __('Courses', 'woothemes-sensei'), 'menu' => __('Courses', 'woothemes-sensei')); |
|
| 605 | + $this->labels['lesson'] = array('singular' => __('Lesson', 'woothemes-sensei'), 'plural' => __('Lessons', 'woothemes-sensei'), 'menu' => __('Lessons', 'woothemes-sensei')); |
|
| 606 | + $this->labels['quiz'] = array('singular' => __('Quiz', 'woothemes-sensei'), 'plural' => __('Quizzes', 'woothemes-sensei'), 'menu' => __('Quizzes', 'woothemes-sensei')); |
|
| 607 | + $this->labels['question'] = array('singular' => __('Question', 'woothemes-sensei'), 'plural' => __('Questions', 'woothemes-sensei'), 'menu' => __('Questions', 'woothemes-sensei')); |
|
| 608 | + $this->labels['multiple_question'] = array('singular' => __('Multiple Question', 'woothemes-sensei'), 'plural' => __('Multiple Questions', 'woothemes-sensei'), 'menu' => __('Multiple Questions', 'woothemes-sensei')); |
|
| 609 | + $this->labels['sensei_message'] = array('singular' => __('Message', 'woothemes-sensei'), 'plural' => __('Messages', 'woothemes-sensei'), 'menu' => __('Messages', 'woothemes-sensei')); |
|
| 610 | 610 | |
| 611 | 611 | } // End setup_post_type_labels_base() |
| 612 | 612 | |
@@ -618,24 +618,24 @@ discard block |
||
| 618 | 618 | * @param string $menu The menu item label |
| 619 | 619 | * @return array An array of the labels to be used |
| 620 | 620 | */ |
| 621 | - private function create_post_type_labels ( $singular, $plural, $menu ) { |
|
| 621 | + private function create_post_type_labels($singular, $plural, $menu) { |
|
| 622 | 622 | |
| 623 | - $lower_case_plural = function_exists( 'mb_strtolower' ) ? mb_strtolower( $plural, 'UTF-8') : strtolower( $plural ); |
|
| 623 | + $lower_case_plural = function_exists('mb_strtolower') ? mb_strtolower($plural, 'UTF-8') : strtolower($plural); |
|
| 624 | 624 | |
| 625 | 625 | $labels = array( |
| 626 | - 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
| 627 | - 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
| 628 | - 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
| 629 | - 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
| 630 | - 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
| 631 | - 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
| 632 | - 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
| 633 | - 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
| 634 | - 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
| 635 | - 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), $lower_case_plural ) , |
|
| 636 | - 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), $lower_case_plural ), |
|
| 626 | + 'name' => sprintf(_x('%s', 'post type general name', 'woothemes-sensei'), $plural), |
|
| 627 | + 'singular_name' => sprintf(_x('%s', 'post type singular name', 'woothemes-sensei'), $singular), |
|
| 628 | + 'add_new' => __('Add New', 'woothemes-sensei'), |
|
| 629 | + 'add_new_item' => sprintf(__('Add New %s', 'woothemes-sensei'), $singular), |
|
| 630 | + 'edit_item' => sprintf(__('Edit %s', 'woothemes-sensei'), $singular), |
|
| 631 | + 'new_item' => sprintf(__('New %s', 'woothemes-sensei'), $singular), |
|
| 632 | + 'all_items' => sprintf(__('All %s', 'woothemes-sensei'), $plural), |
|
| 633 | + 'view_item' => sprintf(__('View %s', 'woothemes-sensei'), $singular), |
|
| 634 | + 'search_items' => sprintf(__('Search %s', 'woothemes-sensei'), $plural), |
|
| 635 | + 'not_found' => sprintf(__('No %s found', 'woothemes-sensei'), $lower_case_plural), |
|
| 636 | + 'not_found_in_trash' => sprintf(__('No %s found in Trash', 'woothemes-sensei'), $lower_case_plural), |
|
| 637 | 637 | 'parent_item_colon' => '', |
| 638 | - 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
| 638 | + 'menu_name' => sprintf(__('%s', 'woothemes-sensei'), $menu) |
|
| 639 | 639 | ); |
| 640 | 640 | |
| 641 | 641 | return $labels; |
@@ -647,14 +647,14 @@ discard block |
||
| 647 | 647 | * @param array $messages The existing array of messages for post types. |
| 648 | 648 | * @return array The modified array of messages for post types. |
| 649 | 649 | */ |
| 650 | - public function setup_post_type_messages ( $messages ) { |
|
| 650 | + public function setup_post_type_messages($messages) { |
|
| 651 | 651 | global $post, $post_ID; |
| 652 | 652 | |
| 653 | - $messages['course'] = $this->create_post_type_messages( 'course' ); |
|
| 654 | - $messages['lesson'] = $this->create_post_type_messages( 'lesson' ); |
|
| 655 | - $messages['quiz'] = $this->create_post_type_messages( 'quiz' ); |
|
| 656 | - $messages['question'] = $this->create_post_type_messages( 'question' ); |
|
| 657 | - $messages['multiple_question'] = $this->create_post_type_messages( 'multiple_question' ); |
|
| 653 | + $messages['course'] = $this->create_post_type_messages('course'); |
|
| 654 | + $messages['lesson'] = $this->create_post_type_messages('lesson'); |
|
| 655 | + $messages['quiz'] = $this->create_post_type_messages('quiz'); |
|
| 656 | + $messages['question'] = $this->create_post_type_messages('question'); |
|
| 657 | + $messages['multiple_question'] = $this->create_post_type_messages('multiple_question'); |
|
| 658 | 658 | |
| 659 | 659 | return $messages; |
| 660 | 660 | } // End setup_post_type_messages() |
@@ -665,23 +665,23 @@ discard block |
||
| 665 | 665 | * @param string $post_type The post type for which to create messages. |
| 666 | 666 | * @return array An array of messages (empty array if the post type isn't one we're looking to work with). |
| 667 | 667 | */ |
| 668 | - private function create_post_type_messages ( $post_type ) { |
|
| 668 | + private function create_post_type_messages($post_type) { |
|
| 669 | 669 | global $post, $post_ID; |
| 670 | 670 | |
| 671 | - if ( ! isset( $this->labels[$post_type] ) ) { return array(); } |
|
| 671 | + if ( ! isset($this->labels[$post_type])) { return array(); } |
|
| 672 | 672 | |
| 673 | 673 | $messages = array( |
| 674 | 674 | 0 => '', |
| 675 | - 1 => sprintf( __( '%1$s updated. %2$sView %1$s%3$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>' ), |
|
| 676 | - 2 => __( 'Custom field updated.' , 'woothemes-sensei' ), |
|
| 677 | - 3 => __( 'Custom field deleted.' , 'woothemes-sensei' ), |
|
| 678 | - 4 => sprintf( __( '%1$s updated.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'] ), |
|
| 679 | - 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 680 | - 6 => sprintf( __( '%1$s published. %2$sView %1$s%3$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>' ), |
|
| 681 | - 7 => sprintf( __( '%1$s saved.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'] ), |
|
| 682 | - 8 => sprintf( __( '%1$s submitted. %2$sPreview %1$s%3$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', '</a>' ), |
|
| 683 | - 9 => sprintf( __( '%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<strong>' . date_i18n( __( 'M j, Y @ G:i' , 'woothemes-sensei' ), strtotime( $post->post_date ) ) . '</strong>', '<a target="_blank" href="' . esc_url( get_permalink( $post_ID ) ) . '">', $this->labels[$post_type]['singular'], '</a>' ), |
|
| 684 | - 10 => sprintf( __( '%1$s draft updated. %2$sPreview %3$s%4$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', $this->labels[$post_type]['singular'], '</a>' ), |
|
| 675 | + 1 => sprintf(__('%1$s updated. %2$sView %1$s%3$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a href="'.esc_url(get_permalink($post_ID)).'">', '</a>'), |
|
| 676 | + 2 => __('Custom field updated.', 'woothemes-sensei'), |
|
| 677 | + 3 => __('Custom field deleted.', 'woothemes-sensei'), |
|
| 678 | + 4 => sprintf(__('%1$s updated.', 'woothemes-sensei'), $this->labels[$post_type]['singular']), |
|
| 679 | + 5 => isset($_GET['revision']) ? sprintf(__('%1$s restored to revision from %2$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
| 680 | + 6 => sprintf(__('%1$s published. %2$sView %1$s%3$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a href="'.esc_url(get_permalink($post_ID)).'">', '</a>'), |
|
| 681 | + 7 => sprintf(__('%1$s saved.', 'woothemes-sensei'), $this->labels[$post_type]['singular']), |
|
| 682 | + 8 => sprintf(__('%1$s submitted. %2$sPreview %1$s%3$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))).'">', '</a>'), |
|
| 683 | + 9 => sprintf(__('%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<strong>'.date_i18n(__('M j, Y @ G:i', 'woothemes-sensei'), strtotime($post->post_date)).'</strong>', '<a target="_blank" href="'.esc_url(get_permalink($post_ID)).'">', $this->labels[$post_type]['singular'], '</a>'), |
|
| 684 | + 10 => sprintf(__('%1$s draft updated. %2$sPreview %3$s%4$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))).'">', $this->labels[$post_type]['singular'], '</a>'), |
|
| 685 | 685 | ); |
| 686 | 686 | |
| 687 | 687 | return $messages; |
@@ -694,11 +694,11 @@ discard block |
||
| 694 | 694 | * @param string $title |
| 695 | 695 | * @return string $title |
| 696 | 696 | */ |
| 697 | - public function enter_title_here ( $title ) { |
|
| 698 | - if ( get_post_type() == 'course' ) { |
|
| 699 | - $title = __( 'Enter a title for this course here', 'woothemes-sensei' ); |
|
| 700 | - } elseif ( get_post_type() == 'lesson' ) { |
|
| 701 | - $title = __( 'Enter a title for this lesson here', 'woothemes-sensei' ); |
|
| 697 | + public function enter_title_here($title) { |
|
| 698 | + if (get_post_type() == 'course') { |
|
| 699 | + $title = __('Enter a title for this course here', 'woothemes-sensei'); |
|
| 700 | + } elseif (get_post_type() == 'lesson') { |
|
| 701 | + $title = __('Enter a title for this lesson here', 'woothemes-sensei'); |
|
| 702 | 702 | } |
| 703 | 703 | |
| 704 | 704 | return $title; |
@@ -712,60 +712,60 @@ discard block |
||
| 712 | 712 | * @param array $post_types |
| 713 | 713 | * @return void |
| 714 | 714 | */ |
| 715 | - public function set_role_cap_defaults( $post_types = array() ) { |
|
| 715 | + public function set_role_cap_defaults($post_types = array()) { |
|
| 716 | 716 | |
| 717 | - foreach ( $post_types as $post_type_item => $post_type_name ) { |
|
| 717 | + foreach ($post_types as $post_type_item => $post_type_name) { |
|
| 718 | 718 | // Super Admin |
| 719 | - $this->role_caps[] = array( 'administrator' => array( 'edit_' . $post_type_item, |
|
| 720 | - 'read_' . $post_type_item, |
|
| 721 | - 'delete_' . $post_type_item, |
|
| 722 | - 'create_' . $post_type_item . 's', |
|
| 723 | - 'edit_' . $post_type_item . 's', |
|
| 724 | - 'edit_others_' . $post_type_item . 's', |
|
| 725 | - 'publish_' . $post_type_item . 's', |
|
| 726 | - 'read_private_' . $post_type_item . 's', |
|
| 719 | + $this->role_caps[] = array('administrator' => array('edit_'.$post_type_item, |
|
| 720 | + 'read_'.$post_type_item, |
|
| 721 | + 'delete_'.$post_type_item, |
|
| 722 | + 'create_'.$post_type_item.'s', |
|
| 723 | + 'edit_'.$post_type_item.'s', |
|
| 724 | + 'edit_others_'.$post_type_item.'s', |
|
| 725 | + 'publish_'.$post_type_item.'s', |
|
| 726 | + 'read_private_'.$post_type_item.'s', |
|
| 727 | 727 | 'read', |
| 728 | - 'delete_' . $post_type_item . 's', |
|
| 729 | - 'delete_private_' . $post_type_item . 's', |
|
| 730 | - 'delete_published_' . $post_type_item . 's', |
|
| 731 | - 'delete_others_' . $post_type_item . 's', |
|
| 732 | - 'edit_private_' . $post_type_item . 's', |
|
| 733 | - 'edit_published_' . $post_type_item . 's', |
|
| 728 | + 'delete_'.$post_type_item.'s', |
|
| 729 | + 'delete_private_'.$post_type_item.'s', |
|
| 730 | + 'delete_published_'.$post_type_item.'s', |
|
| 731 | + 'delete_others_'.$post_type_item.'s', |
|
| 732 | + 'edit_private_'.$post_type_item.'s', |
|
| 733 | + 'edit_published_'.$post_type_item.'s', |
|
| 734 | 734 | 'manage_sensei', |
| 735 | - 'manage_sensei_grades' ), |
|
| 736 | - 'editor' => array( 'edit_' . $post_type_item, |
|
| 737 | - 'read_' . $post_type_item, |
|
| 738 | - 'delete_' . $post_type_item, |
|
| 739 | - 'create_' . $post_type_item . 's', |
|
| 740 | - 'edit_' . $post_type_item . 's', |
|
| 741 | - 'edit_others_' . $post_type_item . 's', |
|
| 742 | - 'publish_' . $post_type_item . 's', |
|
| 743 | - 'read_private_' . $post_type_item . 's', |
|
| 735 | + 'manage_sensei_grades'), |
|
| 736 | + 'editor' => array('edit_'.$post_type_item, |
|
| 737 | + 'read_'.$post_type_item, |
|
| 738 | + 'delete_'.$post_type_item, |
|
| 739 | + 'create_'.$post_type_item.'s', |
|
| 740 | + 'edit_'.$post_type_item.'s', |
|
| 741 | + 'edit_others_'.$post_type_item.'s', |
|
| 742 | + 'publish_'.$post_type_item.'s', |
|
| 743 | + 'read_private_'.$post_type_item.'s', |
|
| 744 | 744 | 'read', |
| 745 | - 'delete_' . $post_type_item . 's', |
|
| 746 | - 'delete_private_' . $post_type_item . 's', |
|
| 747 | - 'delete_published_' . $post_type_item . 's', |
|
| 748 | - 'delete_others_' . $post_type_item . 's', |
|
| 749 | - 'edit_private_' . $post_type_item . 's', |
|
| 750 | - 'edit_published_' . $post_type_item . 's' ), |
|
| 751 | - 'author' => array( 'edit_' . $post_type_item, |
|
| 752 | - 'read_' . $post_type_item, |
|
| 753 | - 'delete_' . $post_type_item, |
|
| 754 | - 'create_' . $post_type_item . 's', |
|
| 755 | - 'edit_' . $post_type_item . 's', |
|
| 756 | - 'publish_' . $post_type_item . 's', |
|
| 745 | + 'delete_'.$post_type_item.'s', |
|
| 746 | + 'delete_private_'.$post_type_item.'s', |
|
| 747 | + 'delete_published_'.$post_type_item.'s', |
|
| 748 | + 'delete_others_'.$post_type_item.'s', |
|
| 749 | + 'edit_private_'.$post_type_item.'s', |
|
| 750 | + 'edit_published_'.$post_type_item.'s'), |
|
| 751 | + 'author' => array('edit_'.$post_type_item, |
|
| 752 | + 'read_'.$post_type_item, |
|
| 753 | + 'delete_'.$post_type_item, |
|
| 754 | + 'create_'.$post_type_item.'s', |
|
| 755 | + 'edit_'.$post_type_item.'s', |
|
| 756 | + 'publish_'.$post_type_item.'s', |
|
| 757 | 757 | 'read', |
| 758 | - 'delete_' . $post_type_item . 's', |
|
| 759 | - 'delete_published_' . $post_type_item . 's', |
|
| 760 | - 'edit_published_' . $post_type_item . 's' ), |
|
| 761 | - 'contributor' => array( 'edit_' . $post_type_item, |
|
| 762 | - 'read_' . $post_type_item, |
|
| 763 | - 'delete_' . $post_type_item, |
|
| 764 | - 'create_' . $post_type_item . 's', |
|
| 765 | - 'edit_' . $post_type_item . 's', |
|
| 758 | + 'delete_'.$post_type_item.'s', |
|
| 759 | + 'delete_published_'.$post_type_item.'s', |
|
| 760 | + 'edit_published_'.$post_type_item.'s'), |
|
| 761 | + 'contributor' => array('edit_'.$post_type_item, |
|
| 762 | + 'read_'.$post_type_item, |
|
| 763 | + 'delete_'.$post_type_item, |
|
| 764 | + 'create_'.$post_type_item.'s', |
|
| 765 | + 'edit_'.$post_type_item.'s', |
|
| 766 | 766 | 'read', |
| 767 | - 'delete_' . $post_type_item . 's' ), |
|
| 768 | - 'subscriber' => array( 'read' ) |
|
| 767 | + 'delete_'.$post_type_item.'s'), |
|
| 768 | + 'subscriber' => array('read') |
|
| 769 | 769 | |
| 770 | 770 | ); |
| 771 | 771 | } // End For Loop |
@@ -779,16 +779,16 @@ discard block |
||
| 779 | 779 | * @param WP_Admin_Bar $bar |
| 780 | 780 | * @return void |
| 781 | 781 | */ |
| 782 | - public function quiz_admin_bar_menu( $bar ) { |
|
| 783 | - if ( is_single() && 'quiz' == get_queried_object()->post_type ) { |
|
| 784 | - $lesson_id = get_post_meta( get_queried_object()->ID, '_quiz_lesson', true ); |
|
| 785 | - if ( $lesson_id ) { |
|
| 782 | + public function quiz_admin_bar_menu($bar) { |
|
| 783 | + if (is_single() && 'quiz' == get_queried_object()->post_type) { |
|
| 784 | + $lesson_id = get_post_meta(get_queried_object()->ID, '_quiz_lesson', true); |
|
| 785 | + if ($lesson_id) { |
|
| 786 | 786 | $object_type = get_post_type_object('quiz'); |
| 787 | - $bar->add_menu( array( |
|
| 787 | + $bar->add_menu(array( |
|
| 788 | 788 | 'id' => 'edit', |
| 789 | 789 | 'title' => $object_type->labels->edit_item, |
| 790 | - 'href' => get_edit_post_link( $lesson_id ), |
|
| 791 | - ) ); |
|
| 790 | + 'href' => get_edit_post_link($lesson_id), |
|
| 791 | + )); |
|
| 792 | 792 | } |
| 793 | 793 | } |
| 794 | 794 | } |
@@ -800,4 +800,4 @@ discard block |
||
| 800 | 800 | * @ignore only for backward compatibility |
| 801 | 801 | * @since 1.9.0 |
| 802 | 802 | */ |
| 803 | -class WooThemes_Sensei_PostTypes extends Sensei_PostTypes{} |
|
| 803 | +class WooThemes_Sensei_PostTypes extends Sensei_PostTypes {} |
|
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 3 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 4 | 4 | |
| 5 | -if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_Completed_Lesson' ) ) : |
|
| 5 | +if ( ! class_exists('WooThemes_Sensei_Email_Teacher_Completed_Lesson')) : |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Teacher Completed Lesson |
@@ -31,8 +31,8 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | function __construct() { |
| 33 | 33 | $this->template = 'teacher-completed-lesson'; |
| 34 | - $this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your student has completed a lesson', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template ); |
|
| 35 | - $this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has completed a lesson', 'woothemes-sensei' ), $this->template ); |
|
| 34 | + $this->subject = apply_filters('sensei_email_subject', sprintf(__('[%1$s] Your student has completed a lesson', 'woothemes-sensei'), get_bloginfo('name')), $this->template); |
|
| 35 | + $this->heading = apply_filters('sensei_email_heading', __('Your student has completed a lesson', 'woothemes-sensei'), $this->template); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -41,31 +41,31 @@ discard block |
||
| 41 | 41 | * @access public |
| 42 | 42 | * @return void |
| 43 | 43 | */ |
| 44 | - function trigger( $learner_id = 0, $lesson_id = 0 ) { |
|
| 44 | + function trigger($learner_id = 0, $lesson_id = 0) { |
|
| 45 | 45 | global $sensei_email_data; |
| 46 | 46 | |
| 47 | 47 | // Get learner user object |
| 48 | - $this->learner = new WP_User( $learner_id ); |
|
| 48 | + $this->learner = new WP_User($learner_id); |
|
| 49 | 49 | |
| 50 | 50 | // Get teacher ID and user object |
| 51 | - $teacher_id = get_post_field( 'post_author', $lesson_id, 'raw' ); |
|
| 52 | - $this->teacher = new WP_User( $teacher_id ); |
|
| 51 | + $teacher_id = get_post_field('post_author', $lesson_id, 'raw'); |
|
| 52 | + $this->teacher = new WP_User($teacher_id); |
|
| 53 | 53 | |
| 54 | 54 | // Construct data array |
| 55 | - $sensei_email_data = apply_filters( 'sensei_email_data', array( |
|
| 55 | + $sensei_email_data = apply_filters('sensei_email_data', array( |
|
| 56 | 56 | 'template' => $this->template, |
| 57 | 57 | 'heading' => $this->heading, |
| 58 | 58 | 'teacher_id' => $teacher_id, |
| 59 | 59 | 'learner_id' => $learner_id, |
| 60 | 60 | 'learner_name' => $this->learner->display_name, |
| 61 | 61 | 'lesson_id' => $lesson_id, |
| 62 | - ), $this->template ); |
|
| 62 | + ), $this->template); |
|
| 63 | 63 | |
| 64 | 64 | // Set recipient (teacher) |
| 65 | - $this->recipient = stripslashes( $this->teacher->user_email ); |
|
| 65 | + $this->recipient = stripslashes($this->teacher->user_email); |
|
| 66 | 66 | |
| 67 | 67 | // Send mail |
| 68 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
| 68 | + Sensei()->emails->send($this->recipient, $this->subject, Sensei()->emails->get_content($this->template)); |
|
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |
@@ -1,5 +1,8 @@ |
||
| 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 |
@@ -35,9 +35,9 @@ discard block |
||
| 35 | 35 | /** |
| 36 | 36 | * trigger function. |
| 37 | 37 | * |
| 38 | - * @param int $learner_id |
|
| 39 | - * @param int $lesson_id |
|
| 40 | - * |
|
| 38 | + * @param int $learner_id |
|
| 39 | + * @param int $lesson_id |
|
| 40 | + * |
|
| 41 | 41 | * @return void |
| 42 | 42 | */ |
| 43 | 43 | function trigger( $learner_id = 0, $lesson_id = 0 ) { |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $teacher_id = get_post_field( 'post_author', $lesson_id, 'raw' ); |
| 52 | 52 | $this->teacher = new WP_User( $teacher_id ); |
| 53 | 53 | |
| 54 | - // Construct data array |
|
| 54 | + // Construct data array |
|
| 55 | 55 | $sensei_email_data = apply_filters( 'sensei_email_data', array( |
| 56 | 56 | 'template' => $this->template, |
| 57 | 57 | 'heading' => $this->heading, |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | $this->recipient = stripslashes( $this->teacher->user_email ); |
| 66 | 66 | |
| 67 | 67 | // Send mail |
| 68 | - Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
| 68 | + Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) ); |
|
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | |