@@ -1,13 +1,13 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Content wrappers Start |
|
| 4 | - * |
|
| 5 | - * All support theme wrappers can be found in includes/theme-integrations |
|
| 6 | - * |
|
| 7 | - * @author WooThemes |
|
| 8 | - * @package WooCommerce/Templates |
|
| 9 | - * @version 1.6.4 |
|
| 10 | - */ |
|
| 3 | + * Content wrappers Start |
|
| 4 | + * |
|
| 5 | + * All support theme wrappers can be found in includes/theme-integrations |
|
| 6 | + * |
|
| 7 | + * @author WooThemes |
|
| 8 | + * @package WooCommerce/Templates |
|
| 9 | + * @version 1.6.4 |
|
| 10 | + */ |
|
| 11 | 11 | ?> |
| 12 | 12 | <div id="container"> |
| 13 | 13 | <div id="content" role="main"> |
@@ -23,165 +23,165 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class Sensei_Shortcode_User_Courses implements Sensei_Shortcode_Interface { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var WP_Query to help setup the query needed by the render method. |
|
| 28 | - */ |
|
| 29 | - protected $query; |
|
| 26 | + /** |
|
| 27 | + * @var WP_Query to help setup the query needed by the render method. |
|
| 28 | + */ |
|
| 29 | + protected $query; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var string number of items to show on the current page |
|
| 33 | - * Default: -1. |
|
| 34 | - */ |
|
| 35 | - protected $number; |
|
| 31 | + /** |
|
| 32 | + * @var string number of items to show on the current page |
|
| 33 | + * Default: -1. |
|
| 34 | + */ |
|
| 35 | + protected $number; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string ordery by course field |
|
| 39 | - * Default: date |
|
| 40 | - */ |
|
| 41 | - protected $orderby; |
|
| 37 | + /** |
|
| 38 | + * @var string ordery by course field |
|
| 39 | + * Default: date |
|
| 40 | + */ |
|
| 41 | + protected $orderby; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var string ASC or DESC |
|
| 45 | - * Default: 'DESC' |
|
| 46 | - */ |
|
| 47 | - protected $order; |
|
| 43 | + /** |
|
| 44 | + * @var string ASC or DESC |
|
| 45 | + * Default: 'DESC' |
|
| 46 | + */ |
|
| 47 | + protected $order; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var status can be completed or active. If none is specified all will be shown |
|
| 51 | - */ |
|
| 52 | - protected $status; |
|
| 49 | + /** |
|
| 50 | + * @var status can be completed or active. If none is specified all will be shown |
|
| 51 | + */ |
|
| 52 | + protected $status; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Setup the shortcode object |
|
| 56 | - * |
|
| 57 | - * @since 1.9.0 |
|
| 58 | - * @param array $attributes |
|
| 59 | - * @param string $content |
|
| 60 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 61 | - */ |
|
| 62 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 54 | + /** |
|
| 55 | + * Setup the shortcode object |
|
| 56 | + * |
|
| 57 | + * @since 1.9.0 |
|
| 58 | + * @param array $attributes |
|
| 59 | + * @param string $content |
|
| 60 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 61 | + */ |
|
| 62 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 63 | 63 | |
| 64 | - if(! is_user_logged_in() ) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 64 | + if(! is_user_logged_in() ) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - // set up all argument need for constructing the course query |
|
| 69 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 70 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 71 | - $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all'; |
|
| 68 | + // set up all argument need for constructing the course query |
|
| 69 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 70 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title'; |
|
| 71 | + $this->status = isset( $attributes['status'] ) ? $attributes['status'] : 'all'; |
|
| 72 | 72 | |
| 73 | - // set the default for menu_order to be ASC |
|
| 74 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 73 | + // set the default for menu_order to be ASC |
|
| 74 | + if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 75 | 75 | |
| 76 | - $this->order = 'ASC'; |
|
| 76 | + $this->order = 'ASC'; |
|
| 77 | 77 | |
| 78 | - }else{ |
|
| 78 | + }else{ |
|
| 79 | 79 | |
| 80 | - // for everything else use the value passed or the default DESC |
|
| 81 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 80 | + // for everything else use the value passed or the default DESC |
|
| 81 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'ASC'; |
|
| 82 | 82 | |
| 83 | - } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // setup the course query that will be used when rendering |
|
| 86 | - $this->setup_course_query(); |
|
| 87 | - } |
|
| 85 | + // setup the course query that will be used when rendering |
|
| 86 | + $this->setup_course_query(); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Sets up the object course query |
|
| 91 | - * that will be used in the render method. |
|
| 92 | - * |
|
| 93 | - * @since 1.9.0 |
|
| 94 | - */ |
|
| 95 | - protected function setup_course_query(){ |
|
| 89 | + /** |
|
| 90 | + * Sets up the object course query |
|
| 91 | + * that will be used in the render method. |
|
| 92 | + * |
|
| 93 | + * @since 1.9.0 |
|
| 94 | + */ |
|
| 95 | + protected function setup_course_query(){ |
|
| 96 | 96 | |
| 97 | - $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' ); |
|
| 98 | - $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true ); |
|
| 99 | - if ( !is_array($user_courses_logs) ) { |
|
| 97 | + $status_query = array( 'user_id' => get_current_user_id(), 'type' => 'sensei_course_status' ); |
|
| 98 | + $user_courses_logs = Sensei_Utils::sensei_check_for_activity( $status_query , true ); |
|
| 99 | + if ( !is_array($user_courses_logs) ) { |
|
| 100 | 100 | |
| 101 | - $user_courses_logs = array( $user_courses_logs ); |
|
| 101 | + $user_courses_logs = array( $user_courses_logs ); |
|
| 102 | 102 | |
| 103 | - } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - $completed_ids = $active_ids = array(); |
|
| 106 | - foreach( $user_courses_logs as $course_status ) { |
|
| 105 | + $completed_ids = $active_ids = array(); |
|
| 106 | + foreach( $user_courses_logs as $course_status ) { |
|
| 107 | 107 | |
| 108 | - if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) { |
|
| 108 | + if ( Sensei_Utils::user_completed_course( $course_status, get_current_user_id() ) ) { |
|
| 109 | 109 | |
| 110 | - $completed_ids[] = $course_status->comment_post_ID; |
|
| 110 | + $completed_ids[] = $course_status->comment_post_ID; |
|
| 111 | 111 | |
| 112 | - } else { |
|
| 112 | + } else { |
|
| 113 | 113 | |
| 114 | - $active_ids[] = $course_status->comment_post_ID; |
|
| 114 | + $active_ids[] = $course_status->comment_post_ID; |
|
| 115 | 115 | |
| 116 | - } |
|
| 117 | - } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - if( 'completed' == $this->status ){ |
|
| 119 | + if( 'completed' == $this->status ){ |
|
| 120 | 120 | |
| 121 | - $included_courses = $completed_ids; |
|
| 121 | + $included_courses = $completed_ids; |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | - }elseif( 'active'==$this->status ){ |
|
| 124 | + }elseif( 'active'==$this->status ){ |
|
| 125 | 125 | |
| 126 | - $included_courses = $active_ids; |
|
| 126 | + $included_courses = $active_ids; |
|
| 127 | 127 | |
| 128 | - }else{ // all courses |
|
| 128 | + }else{ // all courses |
|
| 129 | 129 | |
| 130 | - if( empty( $completed_ids ) ){ |
|
| 130 | + if( empty( $completed_ids ) ){ |
|
| 131 | 131 | |
| 132 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) ); |
|
| 133 | - } |
|
| 132 | + add_action( 'sensei_loop_course_inside_before', array( $this, 'completed_no_course_message_output' ) ); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - if( empty( $active_ids ) ){ |
|
| 135 | + if( empty( $active_ids ) ){ |
|
| 136 | 136 | |
| 137 | - add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) ); |
|
| 137 | + add_action( 'sensei_loop_course_inside_before', array( $this, 'active_no_course_message_output' ) ); |
|
| 138 | 138 | |
| 139 | - } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - if( empty( $completed_ids ) && empty( $active_ids ) ){ |
|
| 141 | + if( empty( $completed_ids ) && empty( $active_ids ) ){ |
|
| 142 | 142 | |
| 143 | - $included_courses = array('-1000'); // don't show any courses |
|
| 143 | + $included_courses = array('-1000'); // don't show any courses |
|
| 144 | 144 | |
| 145 | - }else{ |
|
| 146 | - $included_courses = Sensei_Utils::array_zip_merge( (array)$active_ids, (array)$completed_ids ); |
|
| 147 | - } |
|
| 145 | + }else{ |
|
| 146 | + $included_courses = Sensei_Utils::array_zip_merge( (array)$active_ids, (array)$completed_ids ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // temporary work around to hide pagination on the courses page |
|
| 153 | + // this is in place until we can load the course for each tab via ajax |
|
| 154 | + // if the shortcode is not active or in active and the active and completed |
|
| 155 | + // tabs show up. |
|
| 156 | + $number_of_posts = $this->number; |
|
| 157 | + if( 'active' != $this->status && 'complete' != $this->status ){ |
|
| 158 | + $number_of_posts = 1000; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // course query parameters |
|
| 162 | + $query_var_paged = get_query_var('paged'); |
|
| 163 | + $query_args = array( |
|
| 164 | + 'post_type' => 'course', |
|
| 165 | + 'post_status' => 'publish', |
|
| 166 | + 'orderby' => $this->orderby, |
|
| 167 | + 'order' => $this->order, |
|
| 168 | + 'paged' => empty( $query_var_paged )? 1 : $query_var_paged, |
|
| 169 | + 'posts_per_page' => $number_of_posts, |
|
| 170 | + 'post__in' => $included_courses, |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + $this->query = new WP_Query( $query_args ); |
|
| 148 | 174 | |
| 175 | + }// end setup _course_query |
|
| 149 | 176 | |
| 150 | - } |
|
| 151 | - |
|
| 152 | - // temporary work around to hide pagination on the courses page |
|
| 153 | - // this is in place until we can load the course for each tab via ajax |
|
| 154 | - // if the shortcode is not active or in active and the active and completed |
|
| 155 | - // tabs show up. |
|
| 156 | - $number_of_posts = $this->number; |
|
| 157 | - if( 'active' != $this->status && 'complete' != $this->status ){ |
|
| 158 | - $number_of_posts = 1000; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // course query parameters |
|
| 162 | - $query_var_paged = get_query_var('paged'); |
|
| 163 | - $query_args = array( |
|
| 164 | - 'post_type' => 'course', |
|
| 165 | - 'post_status' => 'publish', |
|
| 166 | - 'orderby' => $this->orderby, |
|
| 167 | - 'order' => $this->order, |
|
| 168 | - 'paged' => empty( $query_var_paged )? 1 : $query_var_paged, |
|
| 169 | - 'posts_per_page' => $number_of_posts, |
|
| 170 | - 'post__in' => $included_courses, |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - $this->query = new WP_Query( $query_args ); |
|
| 174 | - |
|
| 175 | - }// end setup _course_query |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Output the message that tells the user they have |
|
| 179 | - * no completed courses. |
|
| 180 | - * |
|
| 181 | - * @since 1.9.0 |
|
| 182 | - */ |
|
| 183 | - public function completed_no_course_message_output(){ |
|
| 184 | - ?> |
|
| 177 | + /** |
|
| 178 | + * Output the message that tells the user they have |
|
| 179 | + * no completed courses. |
|
| 180 | + * |
|
| 181 | + * @since 1.9.0 |
|
| 182 | + */ |
|
| 183 | + public function completed_no_course_message_output(){ |
|
| 184 | + ?> |
|
| 185 | 185 | <li class="user-completed"> |
| 186 | 186 | <div class="sensei-message info"> |
| 187 | 187 | |
@@ -190,16 +190,16 @@ discard block |
||
| 190 | 190 | </div> |
| 191 | 191 | </li> |
| 192 | 192 | <?php |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Output the message that tells the user they have |
|
| 197 | - * no active courses. |
|
| 198 | - * |
|
| 199 | - * @since 1.9.0 |
|
| 200 | - */ |
|
| 201 | - public function active_no_course_message_output(){ |
|
| 202 | - ?> |
|
| 195 | + /** |
|
| 196 | + * Output the message that tells the user they have |
|
| 197 | + * no active courses. |
|
| 198 | + * |
|
| 199 | + * @since 1.9.0 |
|
| 200 | + */ |
|
| 201 | + public function active_no_course_message_output(){ |
|
| 202 | + ?> |
|
| 203 | 203 | |
| 204 | 204 | <li class="user-active"> |
| 205 | 205 | <div class="sensei-message info"> |
@@ -215,141 +215,141 @@ discard block |
||
| 215 | 215 | </div> |
| 216 | 216 | </li> |
| 217 | 217 | <?php |
| 218 | - } |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Rendering the shortcode this class is responsible for. |
|
| 222 | - * |
|
| 223 | - * @return string $content |
|
| 224 | - */ |
|
| 225 | - public function render(){ |
|
| 220 | + /** |
|
| 221 | + * Rendering the shortcode this class is responsible for. |
|
| 222 | + * |
|
| 223 | + * @return string $content |
|
| 224 | + */ |
|
| 225 | + public function render(){ |
|
| 226 | 226 | |
| 227 | - global $wp_query; |
|
| 227 | + global $wp_query; |
|
| 228 | 228 | |
| 229 | - if(! is_user_logged_in() ) { |
|
| 230 | - return ''; |
|
| 231 | - } |
|
| 229 | + if(! is_user_logged_in() ) { |
|
| 230 | + return ''; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - // keep a reference to old query |
|
| 234 | - $current_global_query = $wp_query; |
|
| 233 | + // keep a reference to old query |
|
| 234 | + $current_global_query = $wp_query; |
|
| 235 | 235 | |
| 236 | - // assign the query setup in $this-> setup_course_query |
|
| 237 | - $wp_query = $this->query; |
|
| 236 | + // assign the query setup in $this-> setup_course_query |
|
| 237 | + $wp_query = $this->query; |
|
| 238 | 238 | |
| 239 | - $this->attach_shortcode_hooks(); |
|
| 239 | + $this->attach_shortcode_hooks(); |
|
| 240 | 240 | |
| 241 | - ob_start(); |
|
| 242 | - echo '<section id="sensei-user-courses">'; |
|
| 243 | - Sensei_Messages::the_my_messages_link(); |
|
| 244 | - Sensei_Templates::get_template('loop-course.php'); |
|
| 245 | - Sensei_Templates::get_template('globals/pagination.php'); |
|
| 246 | - echo '</section>'; |
|
| 241 | + ob_start(); |
|
| 242 | + echo '<section id="sensei-user-courses">'; |
|
| 243 | + Sensei_Messages::the_my_messages_link(); |
|
| 244 | + Sensei_Templates::get_template('loop-course.php'); |
|
| 245 | + Sensei_Templates::get_template('globals/pagination.php'); |
|
| 246 | + echo '</section>'; |
|
| 247 | 247 | |
| 248 | - $shortcode_output = ob_get_clean(); |
|
| 248 | + $shortcode_output = ob_get_clean(); |
|
| 249 | 249 | |
| 250 | - $this->detach_shortcode_hooks(); |
|
| 250 | + $this->detach_shortcode_hooks(); |
|
| 251 | 251 | |
| 252 | - //restore old query |
|
| 253 | - $wp_query = $current_global_query; |
|
| 252 | + //restore old query |
|
| 253 | + $wp_query = $current_global_query; |
|
| 254 | 254 | |
| 255 | - return $shortcode_output; |
|
| 255 | + return $shortcode_output; |
|
| 256 | 256 | |
| 257 | - }// end render |
|
| 257 | + }// end render |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Add hooks for the shortcode |
|
| 261 | - * |
|
| 262 | - * @since 1.9.0 |
|
| 263 | - */ |
|
| 264 | - public function attach_shortcode_hooks(){ |
|
| 259 | + /** |
|
| 260 | + * Add hooks for the shortcode |
|
| 261 | + * |
|
| 262 | + * @since 1.9.0 |
|
| 263 | + */ |
|
| 264 | + public function attach_shortcode_hooks(){ |
|
| 265 | 265 | |
| 266 | - // attach the toggle functionality |
|
| 267 | - // don't show the toggle action if the user specified complete or active for this shortcode |
|
| 268 | - if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){ |
|
| 266 | + // attach the toggle functionality |
|
| 267 | + // don't show the toggle action if the user specified complete or active for this shortcode |
|
| 268 | + if( ! in_array( $this->status, array( 'active', 'complete' ) ) ){ |
|
| 269 | 269 | |
| 270 | - add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 271 | - add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 ); |
|
| 270 | + add_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 271 | + add_action( 'wp_footer', array( $this, 'print_course_toggle_actions_inline_script' ), 90 ); |
|
| 272 | 272 | |
| 273 | - } |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - // add extra classes to distinguish the course based on user completed or active |
|
| 276 | - add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 275 | + // add extra classes to distinguish the course based on user completed or active |
|
| 276 | + add_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 277 | 277 | |
| 278 | - // attach progress meter below course |
|
| 279 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 280 | - add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 278 | + // attach progress meter below course |
|
| 279 | + add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 280 | + add_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 281 | 281 | |
| 282 | - } |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * Remove hooks for the shortcode |
|
| 286 | - * |
|
| 287 | - * @since 1.9.0 |
|
| 288 | - */ |
|
| 289 | - public function detach_shortcode_hooks(){ |
|
| 284 | + /** |
|
| 285 | + * Remove hooks for the shortcode |
|
| 286 | + * |
|
| 287 | + * @since 1.9.0 |
|
| 288 | + */ |
|
| 289 | + public function detach_shortcode_hooks(){ |
|
| 290 | 290 | |
| 291 | - //remove all hooks after the output is generated |
|
| 292 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 293 | - remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 294 | - remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 295 | - remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 296 | - } |
|
| 291 | + //remove all hooks after the output is generated |
|
| 292 | + remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_progress' ) ); |
|
| 293 | + remove_action( 'sensei_course_content_inside_after', array( $this, 'attach_course_buttons' ) ); |
|
| 294 | + remove_filter( 'sensei_course_loop_content_class', array( $this, 'course_status_class_tagging' ), 20, 2 ); |
|
| 295 | + remove_action( 'sensei_loop_course_before', array( $this, 'course_toggle_actions' ) ); |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | - /** |
|
| 299 | - * Hooks into sensei_course_content_inside_after |
|
| 300 | - * |
|
| 301 | - * @param $course |
|
| 302 | - */ |
|
| 303 | - public function attach_course_progress( $course ){ |
|
| 298 | + /** |
|
| 299 | + * Hooks into sensei_course_content_inside_after |
|
| 300 | + * |
|
| 301 | + * @param $course |
|
| 302 | + */ |
|
| 303 | + public function attach_course_progress( $course ){ |
|
| 304 | 304 | |
| 305 | - $percentage = Sensei()->course->get_completion_percentage( $course->ID, get_current_user_id() ); |
|
| 306 | - echo Sensei()->course->get_progress_meter( $percentage ); |
|
| 305 | + $percentage = Sensei()->course->get_completion_percentage( $course->ID, get_current_user_id() ); |
|
| 306 | + echo Sensei()->course->get_progress_meter( $percentage ); |
|
| 307 | 307 | |
| 308 | - }// attach_course_progress |
|
| 308 | + }// attach_course_progress |
|
| 309 | 309 | |
| 310 | 310 | |
| 311 | - /** |
|
| 312 | - * Hooked into sensei_course_content_inside_after |
|
| 313 | - * |
|
| 314 | - * Prints out the course action buttons |
|
| 315 | - * |
|
| 316 | - * @param $course |
|
| 317 | - */ |
|
| 318 | - public function attach_course_buttons( $course ){ |
|
| 311 | + /** |
|
| 312 | + * Hooked into sensei_course_content_inside_after |
|
| 313 | + * |
|
| 314 | + * Prints out the course action buttons |
|
| 315 | + * |
|
| 316 | + * @param $course |
|
| 317 | + */ |
|
| 318 | + public function attach_course_buttons( $course ){ |
|
| 319 | 319 | |
| 320 | - Sensei()->course->the_course_action_buttons( $course ); |
|
| 320 | + Sensei()->course->the_course_action_buttons( $course ); |
|
| 321 | 321 | |
| 322 | - }// attach_course_buttons |
|
| 322 | + }// attach_course_buttons |
|
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Add a the user status class for the given course. |
|
| 326 | - * |
|
| 327 | - * @since 1.9 |
|
| 328 | - * |
|
| 329 | - * @param array $classes |
|
| 330 | - * @param WP_Post $course |
|
| 331 | - * @return array $classes |
|
| 332 | - */ |
|
| 333 | - public function course_status_class_tagging($classes, $course){ |
|
| 324 | + /** |
|
| 325 | + * Add a the user status class for the given course. |
|
| 326 | + * |
|
| 327 | + * @since 1.9 |
|
| 328 | + * |
|
| 329 | + * @param array $classes |
|
| 330 | + * @param WP_Post $course |
|
| 331 | + * @return array $classes |
|
| 332 | + */ |
|
| 333 | + public function course_status_class_tagging($classes, $course){ |
|
| 334 | 334 | |
| 335 | - if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) { |
|
| 335 | + if ( Sensei_Utils::user_completed_course( $course, get_current_user_id() ) ) { |
|
| 336 | 336 | |
| 337 | - $classes[] = 'user-completed'; |
|
| 337 | + $classes[] = 'user-completed'; |
|
| 338 | 338 | |
| 339 | - } else { |
|
| 339 | + } else { |
|
| 340 | 340 | |
| 341 | - $classes[] = 'user-active'; |
|
| 341 | + $classes[] = 'user-active'; |
|
| 342 | 342 | |
| 343 | - } |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - return $classes; |
|
| 345 | + return $classes; |
|
| 346 | 346 | |
| 347 | - }// end course_status_class_tagging |
|
| 347 | + }// end course_status_class_tagging |
|
| 348 | 348 | |
| 349 | - /** |
|
| 350 | - * Output the course toggle functionality |
|
| 351 | - */ |
|
| 352 | - public function course_toggle_actions(){ ?> |
|
| 349 | + /** |
|
| 350 | + * Output the course toggle functionality |
|
| 351 | + */ |
|
| 352 | + public function course_toggle_actions(){ ?> |
|
| 353 | 353 | |
| 354 | 354 | <section id="user-course-status-toggle"> |
| 355 | 355 | <a id="sensei-user-courses-active-action" href=""><?php _e('Active Courses'); ?></a> |
@@ -359,12 +359,12 @@ discard block |
||
| 359 | 359 | |
| 360 | 360 | <?php } |
| 361 | 361 | |
| 362 | - /** |
|
| 363 | - * Load the javascript for the toggle functionality |
|
| 364 | - * |
|
| 365 | - * @since 1.9.0 |
|
| 366 | - */ |
|
| 367 | - function print_course_toggle_actions_inline_script() { ?> |
|
| 362 | + /** |
|
| 363 | + * Load the javascript for the toggle functionality |
|
| 364 | + * |
|
| 365 | + * @since 1.9.0 |
|
| 366 | + */ |
|
| 367 | + function print_course_toggle_actions_inline_script() { ?> |
|
| 368 | 368 | |
| 369 | 369 | <script type="text/javascript"> |
| 370 | 370 | var buttonContainer = jQuery('#user-course-status-toggle'); |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Course_Results { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - public $courses_url_base; |
|
| 17 | + /** |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + public $courses_url_base; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Constructor. |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | global $wp_query, $current_user; |
| 99 | 99 | |
| 100 | 100 | if( isset( $wp_query->query_vars['course_results'] ) ) { |
| 101 | - Sensei_Templates::get_template( 'course-results/course-info.php' ); |
|
| 101 | + Sensei_Templates::get_template( 'course-results/course-info.php' ); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | } |
@@ -117,20 +117,20 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | sensei_do_deprecated_action( 'sensei_course_results_lessons','1.9.','sensei_course_results_content_inside_after', $course ); |
| 119 | 119 | |
| 120 | - sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID ); |
|
| 120 | + sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID ); |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Load template for displaying course lessons |
| 126 | - * |
|
| 126 | + * |
|
| 127 | 127 | * @since 1.4.0 |
| 128 | 128 | * @return void |
| 129 | 129 | */ |
| 130 | 130 | public function course_lessons() { |
| 131 | 131 | |
| 132 | 132 | global $course; |
| 133 | - _deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' ); |
|
| 133 | + _deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' ); |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | |
@@ -147,62 +147,62 @@ discard block |
||
| 147 | 147 | return $classes; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Deprecate the sensei_course_results_content hook |
|
| 152 | - * |
|
| 153 | - * @deprecated since 1.9.0 |
|
| 154 | - */ |
|
| 155 | - public static function deprecate_sensei_course_results_content_hook(){ |
|
| 150 | + /** |
|
| 151 | + * Deprecate the sensei_course_results_content hook |
|
| 152 | + * |
|
| 153 | + * @deprecated since 1.9.0 |
|
| 154 | + */ |
|
| 155 | + public static function deprecate_sensei_course_results_content_hook(){ |
|
| 156 | 156 | |
| 157 | - sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before'); |
|
| 157 | + sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before'); |
|
| 158 | 158 | |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Fire the sensei frontend message hook |
|
| 163 | - * |
|
| 164 | - * @since 1.9.0 |
|
| 165 | - */ |
|
| 166 | - public static function fire_sensei_message_hook(){ |
|
| 161 | + /** |
|
| 162 | + * Fire the sensei frontend message hook |
|
| 163 | + * |
|
| 164 | + * @since 1.9.0 |
|
| 165 | + */ |
|
| 166 | + public static function fire_sensei_message_hook(){ |
|
| 167 | 167 | |
| 168 | - do_action( 'sensei_frontend_messages' ); |
|
| 168 | + do_action( 'sensei_frontend_messages' ); |
|
| 169 | 169 | |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Deprecate the course_results info hook |
|
| 174 | - * |
|
| 175 | - * @since 1.9.0 |
|
| 176 | - */ |
|
| 177 | - public static function deprecate_course_result_info_hook(){ |
|
| 172 | + /** |
|
| 173 | + * Deprecate the course_results info hook |
|
| 174 | + * |
|
| 175 | + * @since 1.9.0 |
|
| 176 | + */ |
|
| 177 | + public static function deprecate_course_result_info_hook(){ |
|
| 178 | 178 | |
| 179 | - sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' ); |
|
| 179 | + sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' ); |
|
| 180 | 180 | |
| 181 | - } |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Deprecate the sensei_course_results_top hook |
|
| 185 | - * |
|
| 186 | - * @deprecate since 1.9.0 |
|
| 187 | - */ |
|
| 188 | - public static function deprecate_course_results_top_hook(){ |
|
| 183 | + /** |
|
| 184 | + * Deprecate the sensei_course_results_top hook |
|
| 185 | + * |
|
| 186 | + * @deprecate since 1.9.0 |
|
| 187 | + */ |
|
| 188 | + public static function deprecate_course_results_top_hook(){ |
|
| 189 | 189 | |
| 190 | - global $course; |
|
| 191 | - sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID ); |
|
| 190 | + global $course; |
|
| 191 | + sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID ); |
|
| 192 | 192 | |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Fire the course image hook |
|
| 197 | - * |
|
| 198 | - * @since 1.8.0 |
|
| 199 | - */ |
|
| 200 | - public static function fire_course_image_hook(){ |
|
| 195 | + /** |
|
| 196 | + * Fire the course image hook |
|
| 197 | + * |
|
| 198 | + * @since 1.8.0 |
|
| 199 | + */ |
|
| 200 | + public static function fire_course_image_hook(){ |
|
| 201 | 201 | |
| 202 | - global $course; |
|
| 203 | - sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 202 | + global $course; |
|
| 203 | + sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 204 | 204 | |
| 205 | - } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | 207 | } // End Class |
| 208 | 208 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public static function has_language_pack_available( $locale = null ) { |
| 93 | 93 | |
| 94 | - if ( is_null( $locale ) ) { |
|
| 94 | + if ( is_null( $locale ) ) { |
|
| 95 | 95 | |
| 96 | 96 | $locale = get_locale(); |
| 97 | 97 | |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - if( isset( $_GET['translation_updated'] ) && 5 == $_GET['translation_updated'] ){ |
|
| 112 | + if( isset( $_GET['translation_updated'] ) && 5 == $_GET['translation_updated'] ){ |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 114 | + return false; |
|
| 115 | 115 | |
| 116 | - } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | $version = get_option( 'woothemes_sensei_language_pack_version', array( '0', $locale ) ); |
| 119 | 119 | |
@@ -14,1347 +14,1347 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Main { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var string |
|
| 19 | - * Reference to the main plugin file |
|
| 20 | - */ |
|
| 21 | - private $file; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
| 25 | - * @since 1.8.0 |
|
| 26 | - */ |
|
| 27 | - protected static $_instance = null; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Main reference to the plugins current version |
|
| 31 | - */ |
|
| 32 | - public $version; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Public token, referencing for the text domain. |
|
| 36 | - */ |
|
| 37 | - public $token = 'woothemes-sensei'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Plugin url and path for use when access resources. |
|
| 41 | - */ |
|
| 42 | - public $plugin_url; |
|
| 43 | - public $plugin_path; |
|
| 44 | - public $template_url; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var Sensei_PostTypes |
|
| 48 | - * All Sensei sub classes. Currently used to access functionality contained within |
|
| 49 | - * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
| 50 | - */ |
|
| 51 | - public $post_types; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var WooThemes_Sensei_Settings |
|
| 55 | - */ |
|
| 56 | - public $settings; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var WooThemes_Sensei_Course_Results |
|
| 60 | - */ |
|
| 61 | - public $course_results; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var Sensei_Updates |
|
| 65 | - */ |
|
| 66 | - public $updates; |
|
| 67 | - /** |
|
| 68 | - * @var WooThemes_Sensei_Course |
|
| 69 | - */ |
|
| 70 | - public $course; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var WooThemes_Sensei_Lesson |
|
| 74 | - */ |
|
| 75 | - public $lesson; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var WooThemes_Sensei_Quiz |
|
| 79 | - */ |
|
| 80 | - public $quiz; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @var WooThemes_Sensei_Question |
|
| 84 | - */ |
|
| 85 | - public $question; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @var WooThemes_Sensei_Admin |
|
| 89 | - */ |
|
| 90 | - public $admin; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @var WooThemes_Sensei_Frontend |
|
| 94 | - */ |
|
| 95 | - public $frontend; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @var Sensei_Notices |
|
| 99 | - */ |
|
| 100 | - public $notices; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @var WooThemes_Sensei_Grading |
|
| 104 | - */ |
|
| 105 | - public $grading; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @var WooThemes_Sensei_Emails |
|
| 109 | - */ |
|
| 110 | - public $emails; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @var WooThemes_Sensei_Learner_Profiles |
|
| 114 | - */ |
|
| 115 | - public $learner_profiles; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @var Sensei_Teacher |
|
| 119 | - */ |
|
| 120 | - public $teacher; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @var WooThemes_Sensei_Learners |
|
| 124 | - */ |
|
| 125 | - public $learners; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var array |
|
| 129 | - * Global instance for access to the permissions message shown |
|
| 130 | - * when users do not have the right privileges to access resources. |
|
| 131 | - */ |
|
| 132 | - public $permissions_message; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 136 | - */ |
|
| 137 | - public $modules; |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @var Sensei_Analysis |
|
| 141 | - */ |
|
| 142 | - public $analysis; |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Constructor method. |
|
| 146 | - * @param string $file The base file of the plugin. |
|
| 147 | - * @since 1.0.0 |
|
| 148 | - */ |
|
| 149 | - public function __construct ( $file ) { |
|
| 150 | - |
|
| 151 | - // Setup object data |
|
| 152 | - $this->file = $file; |
|
| 153 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 154 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 155 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 156 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 157 | - |
|
| 158 | - // Initialize the core Sensei functionality |
|
| 159 | - $this->init(); |
|
| 160 | - |
|
| 161 | - // Installation |
|
| 162 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 163 | - |
|
| 164 | - // Run this on activation. |
|
| 165 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 166 | - |
|
| 167 | - // Image Sizes |
|
| 168 | - $this->init_image_sizes(); |
|
| 169 | - |
|
| 170 | - // Force WooCommerce Required Settings |
|
| 171 | - $this->set_woocommerce_functionality(); |
|
| 172 | - |
|
| 173 | - // load all hooks |
|
| 174 | - $this->load_hooks(); |
|
| 175 | - |
|
| 176 | - } // End __construct() |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Load the foundations of Sensei. |
|
| 180 | - * @since 1.9.0 |
|
| 181 | - */ |
|
| 182 | - protected function init(){ |
|
| 183 | - |
|
| 184 | - // Localisation |
|
| 185 | - $this->load_plugin_textdomain(); |
|
| 186 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 187 | - |
|
| 188 | - // load the shortcode loader into memory, so as to listen to all for |
|
| 189 | - // all shortcodes on the front end |
|
| 190 | - new Sensei_Shortcode_Loader(); |
|
| 191 | - |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Global Sensei Instance |
|
| 196 | - * |
|
| 197 | - * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 198 | - * |
|
| 199 | - * @since 1.8.0 |
|
| 200 | - * @static |
|
| 201 | - * @see WC() |
|
| 202 | - * @return WooThemes_Sensei Instance. |
|
| 203 | - */ |
|
| 204 | - public static function instance() { |
|
| 17 | + /** |
|
| 18 | + * @var string |
|
| 19 | + * Reference to the main plugin file |
|
| 20 | + */ |
|
| 21 | + private $file; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
| 25 | + * @since 1.8.0 |
|
| 26 | + */ |
|
| 27 | + protected static $_instance = null; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Main reference to the plugins current version |
|
| 31 | + */ |
|
| 32 | + public $version; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Public token, referencing for the text domain. |
|
| 36 | + */ |
|
| 37 | + public $token = 'woothemes-sensei'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Plugin url and path for use when access resources. |
|
| 41 | + */ |
|
| 42 | + public $plugin_url; |
|
| 43 | + public $plugin_path; |
|
| 44 | + public $template_url; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var Sensei_PostTypes |
|
| 48 | + * All Sensei sub classes. Currently used to access functionality contained within |
|
| 49 | + * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
| 50 | + */ |
|
| 51 | + public $post_types; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var WooThemes_Sensei_Settings |
|
| 55 | + */ |
|
| 56 | + public $settings; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var WooThemes_Sensei_Course_Results |
|
| 60 | + */ |
|
| 61 | + public $course_results; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var Sensei_Updates |
|
| 65 | + */ |
|
| 66 | + public $updates; |
|
| 67 | + /** |
|
| 68 | + * @var WooThemes_Sensei_Course |
|
| 69 | + */ |
|
| 70 | + public $course; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var WooThemes_Sensei_Lesson |
|
| 74 | + */ |
|
| 75 | + public $lesson; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @var WooThemes_Sensei_Quiz |
|
| 79 | + */ |
|
| 80 | + public $quiz; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @var WooThemes_Sensei_Question |
|
| 84 | + */ |
|
| 85 | + public $question; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @var WooThemes_Sensei_Admin |
|
| 89 | + */ |
|
| 90 | + public $admin; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @var WooThemes_Sensei_Frontend |
|
| 94 | + */ |
|
| 95 | + public $frontend; |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @var Sensei_Notices |
|
| 99 | + */ |
|
| 100 | + public $notices; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @var WooThemes_Sensei_Grading |
|
| 104 | + */ |
|
| 105 | + public $grading; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @var WooThemes_Sensei_Emails |
|
| 109 | + */ |
|
| 110 | + public $emails; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @var WooThemes_Sensei_Learner_Profiles |
|
| 114 | + */ |
|
| 115 | + public $learner_profiles; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @var Sensei_Teacher |
|
| 119 | + */ |
|
| 120 | + public $teacher; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @var WooThemes_Sensei_Learners |
|
| 124 | + */ |
|
| 125 | + public $learners; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var array |
|
| 129 | + * Global instance for access to the permissions message shown |
|
| 130 | + * when users do not have the right privileges to access resources. |
|
| 131 | + */ |
|
| 132 | + public $permissions_message; |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 136 | + */ |
|
| 137 | + public $modules; |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @var Sensei_Analysis |
|
| 141 | + */ |
|
| 142 | + public $analysis; |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Constructor method. |
|
| 146 | + * @param string $file The base file of the plugin. |
|
| 147 | + * @since 1.0.0 |
|
| 148 | + */ |
|
| 149 | + public function __construct ( $file ) { |
|
| 150 | + |
|
| 151 | + // Setup object data |
|
| 152 | + $this->file = $file; |
|
| 153 | + $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 154 | + $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 155 | + $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 156 | + $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 157 | + |
|
| 158 | + // Initialize the core Sensei functionality |
|
| 159 | + $this->init(); |
|
| 160 | + |
|
| 161 | + // Installation |
|
| 162 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 163 | + |
|
| 164 | + // Run this on activation. |
|
| 165 | + register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 166 | + |
|
| 167 | + // Image Sizes |
|
| 168 | + $this->init_image_sizes(); |
|
| 169 | + |
|
| 170 | + // Force WooCommerce Required Settings |
|
| 171 | + $this->set_woocommerce_functionality(); |
|
| 172 | + |
|
| 173 | + // load all hooks |
|
| 174 | + $this->load_hooks(); |
|
| 175 | + |
|
| 176 | + } // End __construct() |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Load the foundations of Sensei. |
|
| 180 | + * @since 1.9.0 |
|
| 181 | + */ |
|
| 182 | + protected function init(){ |
|
| 183 | + |
|
| 184 | + // Localisation |
|
| 185 | + $this->load_plugin_textdomain(); |
|
| 186 | + add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 187 | + |
|
| 188 | + // load the shortcode loader into memory, so as to listen to all for |
|
| 189 | + // all shortcodes on the front end |
|
| 190 | + new Sensei_Shortcode_Loader(); |
|
| 191 | + |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Global Sensei Instance |
|
| 196 | + * |
|
| 197 | + * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 198 | + * |
|
| 199 | + * @since 1.8.0 |
|
| 200 | + * @static |
|
| 201 | + * @see WC() |
|
| 202 | + * @return WooThemes_Sensei Instance. |
|
| 203 | + */ |
|
| 204 | + public static function instance() { |
|
| 205 | 205 | |
| 206 | - if ( is_null( self::$_instance ) ) { |
|
| 206 | + if ( is_null( self::$_instance ) ) { |
|
| 207 | 207 | |
| 208 | - //Sensei requires a reference to the main Sensei plugin file |
|
| 209 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 208 | + //Sensei requires a reference to the main Sensei plugin file |
|
| 209 | + $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 210 | 210 | |
| 211 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 211 | + self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 212 | 212 | |
| 213 | - // load the global class objects needed throughout Sensei |
|
| 214 | - self::$_instance->initialize_global_objects(); |
|
| 213 | + // load the global class objects needed throughout Sensei |
|
| 214 | + self::$_instance->initialize_global_objects(); |
|
| 215 | 215 | |
| 216 | - } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - return self::$_instance; |
|
| 218 | + return self::$_instance; |
|
| 219 | 219 | |
| 220 | - } // end instance() |
|
| 220 | + } // end instance() |
|
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * This function is linked into the activation |
|
| 224 | - * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 225 | - * |
|
| 226 | - * @since 1.9.0 |
|
| 227 | - * |
|
| 228 | - * @param $plugin |
|
| 229 | - */ |
|
| 230 | - public static function activation_flush_rules( $plugin ){ |
|
| 222 | + /** |
|
| 223 | + * This function is linked into the activation |
|
| 224 | + * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 225 | + * |
|
| 226 | + * @since 1.9.0 |
|
| 227 | + * |
|
| 228 | + * @param $plugin |
|
| 229 | + */ |
|
| 230 | + public static function activation_flush_rules( $plugin ){ |
|
| 231 | 231 | |
| 232 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 232 | + if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 233 | 233 | |
| 234 | - flush_rewrite_rules(true); |
|
| 234 | + flush_rewrite_rules(true); |
|
| 235 | 235 | |
| 236 | - } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * Cloning is forbidden. |
|
| 242 | - * @since 1.8.0 |
|
| 243 | - */ |
|
| 244 | - public function __clone() { |
|
| 245 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
| 246 | - } |
|
| 240 | + /** |
|
| 241 | + * Cloning is forbidden. |
|
| 242 | + * @since 1.8.0 |
|
| 243 | + */ |
|
| 244 | + public function __clone() { |
|
| 245 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Unserializing instances of this class is forbidden. |
|
| 250 | - * @since 1.8.0 |
|
| 251 | - */ |
|
| 252 | - public function __wakeup() { |
|
| 253 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
| 254 | - } |
|
| 248 | + /** |
|
| 249 | + * Unserializing instances of this class is forbidden. |
|
| 250 | + * @since 1.8.0 |
|
| 251 | + */ |
|
| 252 | + public function __wakeup() { |
|
| 253 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '1.8' ); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * Load the properties for the main Sensei object |
|
| 258 | - * |
|
| 259 | - * @since 1.9.0 |
|
| 260 | - */ |
|
| 261 | - public function initialize_global_objects(){ |
|
| 256 | + /** |
|
| 257 | + * Load the properties for the main Sensei object |
|
| 258 | + * |
|
| 259 | + * @since 1.9.0 |
|
| 260 | + */ |
|
| 261 | + public function initialize_global_objects(){ |
|
| 262 | 262 | |
| 263 | - // Setup post types. |
|
| 264 | - $this->post_types = new Sensei_PostTypes(); |
|
| 263 | + // Setup post types. |
|
| 264 | + $this->post_types = new Sensei_PostTypes(); |
|
| 265 | 265 | |
| 266 | - // Lad the updates class |
|
| 267 | - $this->updates = new Sensei_Updates( $this ); |
|
| 266 | + // Lad the updates class |
|
| 267 | + $this->updates = new Sensei_Updates( $this ); |
|
| 268 | 268 | |
| 269 | - // Setup settings |
|
| 270 | - $this->settings = new Sensei_Settings(); |
|
| 269 | + // Setup settings |
|
| 270 | + $this->settings = new Sensei_Settings(); |
|
| 271 | 271 | |
| 272 | - // Load Course Results Class |
|
| 273 | - $this->course_results = new Sensei_Course_Results(); |
|
| 272 | + // Load Course Results Class |
|
| 273 | + $this->course_results = new Sensei_Course_Results(); |
|
| 274 | 274 | |
| 275 | - // Load the teacher role |
|
| 276 | - $this->teacher = new Sensei_Teacher(); |
|
| 275 | + // Load the teacher role |
|
| 276 | + $this->teacher = new Sensei_Teacher(); |
|
| 277 | 277 | |
| 278 | - // Add the Course class |
|
| 279 | - $this->course = $this->post_types->course; |
|
| 278 | + // Add the Course class |
|
| 279 | + $this->course = $this->post_types->course; |
|
| 280 | 280 | |
| 281 | - // Add the lesson class |
|
| 282 | - $this->lesson = $this->post_types->lesson; |
|
| 281 | + // Add the lesson class |
|
| 282 | + $this->lesson = $this->post_types->lesson; |
|
| 283 | 283 | |
| 284 | - // Add the question class |
|
| 285 | - $this->question = $this->post_types->question; |
|
| 284 | + // Add the question class |
|
| 285 | + $this->question = $this->post_types->question; |
|
| 286 | 286 | |
| 287 | - //Add the quiz class |
|
| 288 | - $this->quiz = $this->post_types->quiz; |
|
| 287 | + //Add the quiz class |
|
| 288 | + $this->quiz = $this->post_types->quiz; |
|
| 289 | 289 | |
| 290 | - // load the modules class after all plugsin are loaded |
|
| 291 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 290 | + // load the modules class after all plugsin are loaded |
|
| 291 | + add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 292 | 292 | |
| 293 | - // Load Learner Management Functionality |
|
| 294 | - $this->learners = new Sensei_Learner_Management( $this->file ); |
|
| 293 | + // Load Learner Management Functionality |
|
| 294 | + $this->learners = new Sensei_Learner_Management( $this->file ); |
|
| 295 | 295 | |
| 296 | - // Differentiate between administration and frontend logic. |
|
| 297 | - if ( is_admin() ) { |
|
| 296 | + // Differentiate between administration and frontend logic. |
|
| 297 | + if ( is_admin() ) { |
|
| 298 | 298 | |
| 299 | - // Load Admin Welcome class |
|
| 300 | - new Sensei_Welcome(); |
|
| 299 | + // Load Admin Welcome class |
|
| 300 | + new Sensei_Welcome(); |
|
| 301 | 301 | |
| 302 | - // Load Admin Class |
|
| 303 | - $this->admin = new Sensei_Admin( $this->file ); |
|
| 302 | + // Load Admin Class |
|
| 303 | + $this->admin = new Sensei_Admin( $this->file ); |
|
| 304 | 304 | |
| 305 | - // Load Analysis Reports |
|
| 306 | - $this->analysis = new Sensei_Analysis( $this->file ); |
|
| 305 | + // Load Analysis Reports |
|
| 306 | + $this->analysis = new Sensei_Analysis( $this->file ); |
|
| 307 | 307 | |
| 308 | - } else { |
|
| 308 | + } else { |
|
| 309 | 309 | |
| 310 | - // Load Frontend Class |
|
| 311 | - $this->frontend = new Sensei_Frontend(); |
|
| 310 | + // Load Frontend Class |
|
| 311 | + $this->frontend = new Sensei_Frontend(); |
|
| 312 | 312 | |
| 313 | - // Load notice Class |
|
| 314 | - $this->notices = new Sensei_Notices(); |
|
| 313 | + // Load notice Class |
|
| 314 | + $this->notices = new Sensei_Notices(); |
|
| 315 | 315 | |
| 316 | - // Load built in themes support integration |
|
| 317 | - new Sensei_Theme_Integration_Loader(); |
|
| 316 | + // Load built in themes support integration |
|
| 317 | + new Sensei_Theme_Integration_Loader(); |
|
| 318 | 318 | |
| 319 | 319 | |
| 320 | - } |
|
| 320 | + } |
|
| 321 | 321 | |
| 322 | - // Load Grading Functionality |
|
| 323 | - $this->grading = new Sensei_Grading( $this->file ); |
|
| 322 | + // Load Grading Functionality |
|
| 323 | + $this->grading = new Sensei_Grading( $this->file ); |
|
| 324 | 324 | |
| 325 | - // Load Email Class |
|
| 326 | - $this->emails = new Sensei_Emails( $this->file ); |
|
| 325 | + // Load Email Class |
|
| 326 | + $this->emails = new Sensei_Emails( $this->file ); |
|
| 327 | 327 | |
| 328 | - // Load Learner Profiles Class |
|
| 329 | - $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 328 | + // Load Learner Profiles Class |
|
| 329 | + $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 330 | 330 | |
| 331 | - } |
|
| 331 | + } |
|
| 332 | 332 | |
| 333 | - /** |
|
| 334 | - * Initialize all Sensei hooks |
|
| 335 | - * |
|
| 336 | - * @since 1.9.0 |
|
| 337 | - */ |
|
| 338 | - public function load_hooks(){ |
|
| 339 | - |
|
| 340 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 341 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 342 | - |
|
| 343 | - // WooCommerce Payment Actions |
|
| 344 | - add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 345 | - add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 346 | - add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 347 | - add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 348 | - add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 349 | - add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 350 | - add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 351 | - |
|
| 352 | - // WooCommerce Subscriptions Actions |
|
| 353 | - add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 354 | - add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 355 | - add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 356 | - add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 357 | - add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 358 | - |
|
| 359 | - // Add Email link to course orders |
|
| 360 | - add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 361 | - |
|
| 362 | - // Filter comment counts |
|
| 363 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 364 | - |
|
| 365 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 366 | - |
|
| 367 | - // Check for and activate JetPack LaTeX support |
|
| 368 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 369 | - |
|
| 370 | - // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 371 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 372 | - |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Run Sensei updates. |
|
| 377 | - * @access public |
|
| 378 | - * @since 1.1.0 |
|
| 379 | - * @return void |
|
| 380 | - */ |
|
| 381 | - public function run_updates() { |
|
| 382 | - // Run updates if administrator |
|
| 383 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 384 | - |
|
| 385 | - $this->updates->update(); |
|
| 386 | - |
|
| 387 | - } // End If Statement |
|
| 388 | - } // End run_updates() |
|
| 389 | - |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Setup required WooCommerce settings. |
|
| 394 | - * @access public |
|
| 395 | - * @since 1.1.0 |
|
| 396 | - * @return void |
|
| 397 | - */ |
|
| 398 | - public function set_woocommerce_functionality() { |
|
| 399 | - // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
|
| 400 | - add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 401 | - |
|
| 402 | - // Mark orders with virtual products as complete rather then stay processing |
|
| 403 | - add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 404 | - |
|
| 405 | - } // End set_woocommerce_functionality() |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Disable guest checkout if a course product is in the cart |
|
| 409 | - * @param boolean $guest_checkout Current guest checkout setting |
|
| 410 | - * @return boolean Modified guest checkout setting |
|
| 411 | - */ |
|
| 412 | - public function disable_guest_checkout( $guest_checkout ) { |
|
| 413 | - global $woocommerce; |
|
| 414 | - |
|
| 415 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 416 | - |
|
| 417 | - if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 418 | - foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 419 | - if( isset( $product['product_id'] ) ) { |
|
| 420 | - $args = array( |
|
| 421 | - 'posts_per_page' => -1, |
|
| 422 | - 'post_type' => 'course', |
|
| 423 | - 'meta_query' => array( |
|
| 424 | - array( |
|
| 425 | - 'key' => '_course_woocommerce_product', |
|
| 426 | - 'value' => $product['product_id'] |
|
| 427 | - ) |
|
| 428 | - ) |
|
| 429 | - ); |
|
| 430 | - $posts = get_posts( $args ); |
|
| 431 | - if( $posts && count( $posts ) > 0 ) { |
|
| 432 | - foreach( $posts as $course ) { |
|
| 433 | - $guest_checkout = ''; |
|
| 434 | - break; |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - return $guest_checkout; |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Change order status with virtual products to completed |
|
| 447 | - * @since 1.1.0 |
|
| 448 | - * @param string $order_status |
|
| 449 | - * @param int $order_id |
|
| 450 | - * @return string |
|
| 451 | - **/ |
|
| 452 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 453 | - $order = new WC_Order( $order_id ); |
|
| 454 | - if ( ! isset ( $order ) ) return ''; |
|
| 455 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 456 | - $virtual_order = true; |
|
| 457 | - |
|
| 458 | - if ( count( $order->get_items() ) > 0 ) { |
|
| 459 | - foreach( $order->get_items() as $item ) { |
|
| 460 | - if ( $item['product_id'] > 0 ) { |
|
| 461 | - $_product = $order->get_product_from_item( $item ); |
|
| 462 | - if ( ! $_product->is_virtual() ) { |
|
| 463 | - $virtual_order = false; |
|
| 464 | - break; |
|
| 465 | - } // End If Statement |
|
| 466 | - } // End If Statement |
|
| 467 | - } // End For Loop |
|
| 468 | - } // End If Statement |
|
| 469 | - |
|
| 470 | - // virtual order, mark as completed |
|
| 471 | - if ( $virtual_order ) { |
|
| 472 | - return 'completed'; |
|
| 473 | - } // End If Statement |
|
| 474 | - } // End If Statement |
|
| 475 | - return $order_status; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Register the widgets. |
|
| 480 | - * @access public |
|
| 481 | - * @since 1.0.0 |
|
| 482 | - * @return void |
|
| 483 | - */ |
|
| 484 | - public function register_widgets () { |
|
| 485 | - // Widget List (key => value is filename => widget class). |
|
| 486 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 487 | - 'lesson-component' => 'Lesson_Component', |
|
| 488 | - 'course-categories' => 'Course_Categories', |
|
| 489 | - 'category-courses' => 'Category_Courses' ) |
|
| 490 | - ); |
|
| 491 | - foreach ( $widget_list as $key => $value ) { |
|
| 492 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
| 493 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
| 494 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 495 | - } |
|
| 496 | - } // End For Loop |
|
| 497 | - |
|
| 498 | - do_action( 'sensei_register_widgets' ); |
|
| 499 | - |
|
| 500 | - } // End register_widgets() |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Load the plugin's localisation file. |
|
| 504 | - * @access public |
|
| 505 | - * @since 1.0.0 |
|
| 506 | - * @return void |
|
| 507 | - */ |
|
| 508 | - public function load_localisation () { |
|
| 509 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 510 | - } // End load_localisation() |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 514 | - * @access public |
|
| 515 | - * @since 1.0.0 |
|
| 516 | - * @return void |
|
| 517 | - */ |
|
| 518 | - public function load_plugin_textdomain () { |
|
| 519 | - $domain = 'woothemes-sensei'; |
|
| 520 | - // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 521 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 522 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 523 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 524 | - } // End load_plugin_textdomain() |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Run on activation. |
|
| 528 | - * @access public |
|
| 529 | - * @since 1.0.0 |
|
| 530 | - * @return void |
|
| 531 | - */ |
|
| 532 | - public function activation () { |
|
| 533 | - $this->register_plugin_version(); |
|
| 534 | - } // End activation() |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * Register activation hooks. |
|
| 539 | - * @access public |
|
| 540 | - * @since 1.0.0 |
|
| 541 | - * @return void |
|
| 542 | - */ |
|
| 543 | - public function install () { |
|
| 544 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 545 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 546 | - } // End install() |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Run on activation of the plugin. |
|
| 551 | - * @access public |
|
| 552 | - * @since 1.0.0 |
|
| 553 | - * @return void |
|
| 554 | - */ |
|
| 555 | - public function activate_sensei () { |
|
| 556 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
| 557 | - update_option( 'sensei_installed', 1 ); |
|
| 558 | - } // End activate_sensei() |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Register the plugin's version. |
|
| 562 | - * @access public |
|
| 563 | - * @since 1.0.0 |
|
| 564 | - * @return void |
|
| 565 | - */ |
|
| 566 | - private function register_plugin_version () { |
|
| 567 | - if ( $this->version != '' ) { |
|
| 568 | - |
|
| 569 | - // Check previous version to see if forced updates must run |
|
| 570 | - // $old_version = get_option( 'woothemes-sensei-version', false ); |
|
| 571 | - // if( $old_version && version_compare( $old_version, '1.7.0', '<' ) ) { |
|
| 572 | - // update_option( 'woothemes-sensei-force-updates', $this->version ); |
|
| 573 | - // } else { |
|
| 574 | - // delete_option( 'woothemes-sensei-force-updates' ); |
|
| 575 | - // } |
|
| 576 | - |
|
| 577 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
| 578 | - } |
|
| 579 | - } // End register_plugin_version() |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 583 | - * @access public |
|
| 584 | - * @since 1.0.1 |
|
| 585 | - * @return void |
|
| 586 | - */ |
|
| 587 | - public function ensure_post_thumbnails_support () { |
|
| 588 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 589 | - } // End ensure_post_thumbnails_support() |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * template_loader function. |
|
| 594 | - * |
|
| 595 | - * @access public |
|
| 596 | - * @param mixed $template |
|
| 597 | - * @return void |
|
| 598 | - * @deprecated |
|
| 599 | - */ |
|
| 600 | - public function template_loader ( $template = '' ) { |
|
| 601 | - |
|
| 602 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 603 | - Sensei_Templates::template_loader( $template ); |
|
| 604 | - |
|
| 605 | - } // End template_loader() |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Determine the relative path to the plugin's directory. |
|
| 609 | - * @access public |
|
| 610 | - * @since 1.0.0 |
|
| 611 | - * @return string $sensei_plugin_path |
|
| 612 | - */ |
|
| 613 | - public function plugin_path () { |
|
| 614 | - |
|
| 615 | - if ( $this->plugin_path ) { |
|
| 616 | - |
|
| 617 | - $sensei_plugin_path = $this->plugin_path; |
|
| 618 | - |
|
| 619 | - }else{ |
|
| 620 | - |
|
| 621 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 622 | - |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - return $sensei_plugin_path; |
|
| 626 | - |
|
| 627 | - } // End plugin_path() |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * Retrieve the ID of a specified page setting. |
|
| 632 | - * @access public |
|
| 633 | - * @since 1.0.0 |
|
| 634 | - * @param string $page |
|
| 635 | - * @return int |
|
| 636 | - */ |
|
| 637 | - public function get_page_id ( $page ) { |
|
| 638 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 639 | - return ( $page ) ? $page : -1; |
|
| 640 | - } // End get_page_id() |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 645 | - * @access public |
|
| 646 | - * @since 1.0.0 |
|
| 647 | - * @param int $course_id (default: 0) |
|
| 648 | - * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 649 | - * @return bool|int |
|
| 650 | - */ |
|
| 651 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 652 | - global $current_user; |
|
| 653 | - |
|
| 654 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
| 655 | - |
|
| 656 | - $data_update = false; |
|
| 657 | - |
|
| 658 | - // Get the product ID |
|
| 659 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 660 | - |
|
| 661 | - // Check if in the admin |
|
| 662 | - if ( is_admin() ) { |
|
| 663 | - $user_login = $order_user['user_login']; |
|
| 664 | - $user_email = $order_user['user_email']; |
|
| 665 | - $user_url = $order_user['user_url']; |
|
| 666 | - $user_id = $order_user['ID']; |
|
| 667 | - } else { |
|
| 668 | - $user_login = $current_user->user_login; |
|
| 669 | - $user_email = $current_user->user_email; |
|
| 670 | - $user_url = $current_user->user_url; |
|
| 671 | - $user_id = $current_user->ID; |
|
| 672 | - } // End If Statement |
|
| 673 | - |
|
| 674 | - // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 675 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 676 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 677 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 678 | - if ( ! $prereq_course_complete ) { |
|
| 679 | - // Remove all course user meta |
|
| 680 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 685 | - |
|
| 686 | - if( ! $is_user_taking_course ) { |
|
| 687 | - |
|
| 688 | - if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 689 | - |
|
| 690 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 691 | - |
|
| 692 | - $is_user_taking_course = false; |
|
| 693 | - if ( true == $activity_logged ) { |
|
| 694 | - $is_user_taking_course = true; |
|
| 695 | - } // End If Statement |
|
| 696 | - } // End If Statement |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return $is_user_taking_course; |
|
| 700 | - } // End woocommerce_course_update() |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - /** |
|
| 704 | - * check_user_permissions function. |
|
| 705 | - * |
|
| 706 | - * @access public |
|
| 707 | - * @param string $page (default: '') |
|
| 708 | - * |
|
| 709 | - * @return bool |
|
| 710 | - */ |
|
| 711 | - public function check_user_permissions ( $page = '' ) { |
|
| 712 | - // REFACTOR |
|
| 713 | - global $current_user, $post; |
|
| 714 | - |
|
| 715 | - // if use is not logged in |
|
| 716 | - // skipped for single lesson |
|
| 717 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') |
|
| 718 | - && 'lesson-single' != $page ){ |
|
| 719 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 720 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 721 | - return false; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - |
|
| 725 | - // Get User Meta |
|
| 726 | - get_currentuserinfo(); |
|
| 727 | - |
|
| 728 | - $user_allowed = false; |
|
| 729 | - |
|
| 730 | - switch ( $page ) { |
|
| 731 | - case 'course-single': |
|
| 732 | - // check for prerequisite course or lesson, |
|
| 733 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 734 | - $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 735 | - // Count completed lessons |
|
| 736 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 737 | - |
|
| 738 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 739 | - |
|
| 740 | - } |
|
| 741 | - else { |
|
| 742 | - $prerequisite_complete = true; |
|
| 743 | - } // End If Statement |
|
| 744 | - // Handles restrictions |
|
| 745 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 746 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 747 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 748 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 749 | - } else { |
|
| 750 | - $user_allowed = true; |
|
| 751 | - } // End If Statement |
|
| 752 | - break; |
|
| 753 | - case 'lesson-single': |
|
| 754 | - // Check for WC purchase |
|
| 755 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 756 | - |
|
| 757 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 758 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 759 | - |
|
| 760 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 761 | - $user_allowed = true; |
|
| 762 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 763 | - |
|
| 764 | - $user_allowed = true; |
|
| 765 | - |
|
| 766 | - } else { |
|
| 767 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 768 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 769 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 770 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 771 | - if ( $is_preview ) { |
|
| 772 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 773 | - } else { |
|
| 774 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 775 | - } |
|
| 776 | - } else { |
|
| 777 | - if ( $is_preview ) { |
|
| 778 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 779 | - } else { |
|
| 780 | - /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 781 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 782 | - } |
|
| 783 | - } // End If Statement |
|
| 784 | - } // End If Statement |
|
| 785 | - break; |
|
| 786 | - case 'quiz-single': |
|
| 787 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 788 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 789 | - |
|
| 790 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 791 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 792 | - |
|
| 793 | - // Check for prerequisite lesson for this quiz |
|
| 794 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 795 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 796 | - |
|
| 797 | - // Handle restrictions |
|
| 798 | - if( sensei_all_access() ) { |
|
| 799 | - $user_allowed = true; |
|
| 800 | - } else { |
|
| 801 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 802 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 803 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 804 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 805 | - } else { |
|
| 806 | - $user_allowed = true; |
|
| 807 | - } // End If Statement |
|
| 808 | - } // End If Statement |
|
| 809 | - } elseif( $this->access_settings() ) { |
|
| 810 | - // Check if the user has started the course |
|
| 811 | - |
|
| 812 | - if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
| 813 | - |
|
| 814 | - $user_allowed = false; |
|
| 815 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 816 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 817 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 818 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 819 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 820 | - } else { |
|
| 821 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 822 | - } // End If Statement |
|
| 823 | - } else { |
|
| 824 | - $user_allowed = true; |
|
| 825 | - } // End If Statement |
|
| 826 | - } else { |
|
| 827 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 828 | - $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 829 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 830 | - } // End If Statement |
|
| 831 | - break; |
|
| 832 | - default: |
|
| 833 | - $user_allowed = true; |
|
| 834 | - break; |
|
| 835 | - |
|
| 836 | - } // End Switch Statement |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * filter the permissions message shown on sensei post types. |
|
| 840 | - * |
|
| 841 | - * @since 1.8.7 |
|
| 842 | - * |
|
| 843 | - * @param array $permissions_message{ |
|
| 844 | - * |
|
| 845 | - * @type string $title |
|
| 846 | - * @type string $message |
|
| 847 | - * |
|
| 848 | - * } |
|
| 849 | - * @param string $post_id |
|
| 850 | - */ |
|
| 851 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 855 | - $user_allowed = true; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 859 | - } // End get_placeholder_image() |
|
| 860 | - |
|
| 861 | - |
|
| 862 | - /** |
|
| 863 | - * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 864 | - * @since 1.0.0 |
|
| 865 | - * @access public |
|
| 866 | - * @return bool |
|
| 867 | - */ |
|
| 868 | - public function access_settings () { |
|
| 869 | - |
|
| 870 | - if( sensei_all_access() ) return true; |
|
| 871 | - |
|
| 872 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 873 | - if ( is_user_logged_in() ) { |
|
| 874 | - return true; |
|
| 875 | - } else { |
|
| 876 | - return false; |
|
| 877 | - } // End If Statement |
|
| 878 | - } else { |
|
| 879 | - return true; |
|
| 880 | - } // End If Statement |
|
| 881 | - } // End access_settings() |
|
| 882 | - |
|
| 883 | - /** |
|
| 884 | - * sensei_woocommerce_complete_order description |
|
| 885 | - * @since 1.0.3 |
|
| 886 | - * @access public |
|
| 887 | - * @param int $order_id WC order ID |
|
| 888 | - * @return void |
|
| 889 | - */ |
|
| 890 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 891 | - $order_user = array(); |
|
| 892 | - // Check for WooCommerce |
|
| 893 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 894 | - // Get order object |
|
| 895 | - $order = new WC_Order( $order_id ); |
|
| 896 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 897 | - $order_user['ID'] = $user->ID; |
|
| 898 | - $order_user['user_login'] = $user->user_login; |
|
| 899 | - $order_user['user_email'] = $user->user_email; |
|
| 900 | - $order_user['user_url'] = $user->user_url; |
|
| 901 | - // Run through each product ordered |
|
| 902 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 903 | - foreach( $order->get_items() as $item ) { |
|
| 904 | - $product_type = ''; |
|
| 905 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 906 | - $item_id = $item['variation_id']; |
|
| 907 | - $product_type = 'variation'; |
|
| 908 | - } else { |
|
| 909 | - $item_id = $item['product_id']; |
|
| 910 | - } // End If Statement |
|
| 911 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 912 | - // Get courses that use the WC product |
|
| 913 | - $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 914 | - // Loop and update those courses |
|
| 915 | - foreach ( $courses as $course_item ) { |
|
| 916 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 917 | - } // End For Loop |
|
| 918 | - } // End For Loop |
|
| 919 | - } // End If Statement |
|
| 920 | - // Add meta to indicate that payment has been completed successfully |
|
| 921 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 922 | - } // End If Statement |
|
| 923 | - } // End sensei_woocommerce_complete_order() |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * Runs when an order is cancelled. |
|
| 927 | - * @since 1.2.0 |
|
| 928 | - * @access public |
|
| 929 | - * @param integer $order_id order ID |
|
| 930 | - * @return void |
|
| 931 | - */ |
|
| 932 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 933 | - |
|
| 934 | - // Get order object |
|
| 935 | - $order = new WC_Order( $order_id ); |
|
| 936 | - |
|
| 937 | - // Run through each product ordered |
|
| 938 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 939 | - |
|
| 940 | - // Get order user |
|
| 941 | - $user_id = $order->__get( 'user_id' ); |
|
| 942 | - |
|
| 943 | - foreach( $order->get_items() as $item ) { |
|
| 944 | - |
|
| 945 | - $product_type = ''; |
|
| 946 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 947 | - $item_id = $item['variation_id']; |
|
| 948 | - $product_type = 'variation'; |
|
| 949 | - } else { |
|
| 950 | - $item_id = $item['product_id']; |
|
| 951 | - } // End If Statement |
|
| 952 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 953 | - |
|
| 954 | - // Get courses that use the WC product |
|
| 955 | - $courses = array(); |
|
| 956 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 957 | - |
|
| 958 | - // Loop and update those courses |
|
| 959 | - foreach ($courses as $course_item){ |
|
| 960 | - // Check and Remove course from courses user meta |
|
| 961 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 962 | - } // End For Loop |
|
| 963 | - } // End For Loop |
|
| 964 | - } // End If Statement |
|
| 965 | - } // End sensei_woocommerce_cancel_order() |
|
| 966 | - |
|
| 967 | - /** |
|
| 968 | - * Runs when an subscription is cancelled or expires. |
|
| 969 | - * @since 1.3.3 |
|
| 970 | - * @access public |
|
| 971 | - * @param integer $user_id User ID |
|
| 972 | - * @param integer $subscription_key Subscription Unique Key |
|
| 973 | - * @return void |
|
| 974 | - */ |
|
| 975 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 976 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 977 | - self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - /** |
|
| 981 | - * Runs when an subscription is re-activated after suspension. |
|
| 982 | - * @since 1.3.3 |
|
| 983 | - * @access public |
|
| 984 | - * @param integer $user_id User ID |
|
| 985 | - * @param integer $subscription_key Subscription Unique Key |
|
| 986 | - * @return void |
|
| 987 | - */ |
|
| 988 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 989 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 990 | - $order = new WC_Order( $subscription['order_id'] ); |
|
| 991 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 992 | - $order_user = array(); |
|
| 993 | - $order_user['ID'] = $user->ID; |
|
| 994 | - $order_user['user_login'] = $user->user_login; |
|
| 995 | - $order_user['user_email'] = $user->user_email; |
|
| 996 | - $order_user['user_url'] = $user->user_url; |
|
| 997 | - $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 998 | - foreach ( $courses as $course_item ){ |
|
| 999 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1000 | - } // End For Loop |
|
| 1001 | - } // End sensei_woocommerce_reactivate_subscription |
|
| 1002 | - |
|
| 1003 | - /** |
|
| 1004 | - * Returns the WooCommerce Product Object |
|
| 1005 | - * |
|
| 1006 | - * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 1007 | - * |
|
| 1008 | - * @since 1.1.1 |
|
| 1009 | - * @access public |
|
| 1010 | - * @param integer $wc_product_id Product ID or Variation ID |
|
| 1011 | - * @param string $product_type '' or 'variation' |
|
| 1012 | - * @return WC_Product $wc_product_object |
|
| 1013 | - */ |
|
| 1014 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1015 | - |
|
| 1016 | - $wc_product_object = false; |
|
| 1017 | - if ( 0 < intval( $wc_product_id ) ) { |
|
| 1018 | - |
|
| 1019 | - // Get the product |
|
| 1020 | - if ( function_exists( 'wc_get_product' ) ) { |
|
| 1021 | - |
|
| 1022 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1023 | - |
|
| 1024 | - } elseif ( function_exists( 'get_product' ) ) { |
|
| 1025 | - |
|
| 1026 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1027 | - |
|
| 1028 | - } else { |
|
| 1029 | - |
|
| 1030 | - // Pre WC 2.0 |
|
| 1031 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1032 | - |
|
| 1033 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1034 | - |
|
| 1035 | - } else { |
|
| 1036 | - |
|
| 1037 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1038 | - |
|
| 1039 | - } // End If Statement |
|
| 1040 | - |
|
| 1041 | - } // End If Statement |
|
| 1042 | - |
|
| 1043 | - } // End If Statement |
|
| 1044 | - |
|
| 1045 | - return $wc_product_object; |
|
| 1046 | - |
|
| 1047 | - } // End sensei_get_woocommerce_product_object() |
|
| 1048 | - |
|
| 1049 | - /** |
|
| 1050 | - * load_class loads in class files |
|
| 1051 | - * @since 1.2.0 |
|
| 1052 | - * @access public |
|
| 1053 | - * @return void |
|
| 1054 | - */ |
|
| 1055 | - public function load_class ( $class_name = '' ) { |
|
| 1056 | - if ( '' != $class_name && '' != $this->token ) { |
|
| 1057 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1058 | - } // End If Statement |
|
| 1059 | - } // End load_class() |
|
| 1060 | - |
|
| 1061 | - /** |
|
| 1062 | - * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1063 | - * @since 1.2.0 |
|
| 1064 | - * @access public |
|
| 1065 | - * @param integer $order_id order ID |
|
| 1066 | - * @return void |
|
| 1067 | - */ |
|
| 1068 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1069 | - if ( 0 < intval( $order_id ) ) { |
|
| 1070 | - $order = new WC_Order( $order_id ); |
|
| 1071 | - $user = get_user_by('id', $order->user_id); |
|
| 1072 | - $order_user['ID'] = $user->ID; |
|
| 1073 | - $order_user['user_login'] = $user->user_login; |
|
| 1074 | - $order_user['user_email'] = $user->user_email; |
|
| 1075 | - $order_user['user_url'] = $user->user_url; |
|
| 1076 | - // Run through each product ordered |
|
| 1077 | - if (sizeof($order->get_items())>0) { |
|
| 1078 | - foreach($order->get_items() as $item) { |
|
| 1079 | - $product_type = ''; |
|
| 1080 | - if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1081 | - $item_id = $item['variation_id']; |
|
| 1082 | - $product_type = 'subscription_variation'; |
|
| 1083 | - } else { |
|
| 1084 | - $item_id = $item['product_id']; |
|
| 1085 | - } // End If Statement |
|
| 1086 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1087 | - // Get courses that use the WC product |
|
| 1088 | - $courses = array(); |
|
| 1089 | - if ( $product_type == 'subscription_variation' ) { |
|
| 1090 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1091 | - } // End If Statement |
|
| 1092 | - // Loop and update those courses |
|
| 1093 | - foreach ($courses as $course_item){ |
|
| 1094 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1095 | - } // End For Loop |
|
| 1096 | - } // End For Loop |
|
| 1097 | - } // End If Statement |
|
| 1098 | - } // End If Statement |
|
| 1099 | - } // End sensei_activate_subscription() |
|
| 1100 | - |
|
| 1101 | - /** |
|
| 1102 | - * sensei_woocommerce_email_course_details adds detail to email |
|
| 1103 | - * @since 1.4.5 |
|
| 1104 | - * @access public |
|
| 1105 | - * @param WC_Order $order |
|
| 1106 | - * @return void |
|
| 1107 | - */ |
|
| 1108 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1109 | - global $woocommerce; |
|
| 1110 | - |
|
| 1111 | - // exit early if not wc-completed or wc-processing |
|
| 1112 | - if( 'wc-completed' != $order->post_status |
|
| 1113 | - && 'wc-processing' != $order->post_status ) { |
|
| 1114 | - return; |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - $order_items = $order->get_items(); |
|
| 1118 | - $order_id = $order->id; |
|
| 1119 | - |
|
| 1120 | - //If object have items go through them all to find course |
|
| 1121 | - if ( 0 < sizeof( $order_items ) ) { |
|
| 1122 | - |
|
| 1123 | - $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1124 | - $order_contains_courses = false; |
|
| 1125 | - |
|
| 1126 | - |
|
| 1127 | - foreach ( $order_items as $item ) { |
|
| 1128 | - |
|
| 1129 | - $product_type = ''; |
|
| 1130 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1131 | - // If item has variation_id then its from variation |
|
| 1132 | - $item_id = $item['variation_id']; |
|
| 1133 | - $product_type = 'variation'; |
|
| 1134 | - } else { |
|
| 1135 | - // If not its real product set its id to item_id |
|
| 1136 | - $item_id = $item['product_id']; |
|
| 1137 | - } // End If Statement |
|
| 1138 | - |
|
| 1139 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1140 | - |
|
| 1141 | - if( $user_id ) { |
|
| 1142 | - |
|
| 1143 | - // Get all courses for product |
|
| 1144 | - $args = array( |
|
| 1145 | - 'posts_per_page' => -1, |
|
| 1146 | - 'post_type' => 'course', |
|
| 1147 | - 'meta_query' => array( |
|
| 1148 | - array( |
|
| 1149 | - 'key' => '_course_woocommerce_product', |
|
| 1150 | - 'value' => $item_id |
|
| 1151 | - ) |
|
| 1152 | - ), |
|
| 1153 | - 'orderby' => 'menu_order date', |
|
| 1154 | - 'order' => 'ASC', |
|
| 1155 | - ); |
|
| 1156 | - $courses = get_posts( $args ); |
|
| 1157 | - |
|
| 1158 | - if( $courses && count( $courses ) > 0 ) { |
|
| 1159 | - |
|
| 1160 | - foreach( $courses as $course ) { |
|
| 1161 | - |
|
| 1162 | - $title = $course->post_title; |
|
| 1163 | - $permalink = get_permalink( $course->ID ); |
|
| 1164 | - $order_contains_courses = true; |
|
| 1165 | - $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - |
|
| 1169 | - } // end if has courses |
|
| 1170 | - |
|
| 1171 | - } // end if $userPid |
|
| 1172 | - |
|
| 1173 | - } // end for each order item |
|
| 1174 | - |
|
| 1175 | - // Output Course details |
|
| 1176 | - if( $order_contains_courses ){ |
|
| 1177 | - |
|
| 1178 | - echo $course_details_html; |
|
| 1179 | - |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - |
|
| 1183 | - } // end if order items not empty |
|
| 1184 | - |
|
| 1185 | - } // end func email course details |
|
| 1186 | - |
|
| 1187 | - /** |
|
| 1188 | - * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 1189 | - * @since 1.4.0 |
|
| 1190 | - * @access public |
|
| 1191 | - * @param array $comments |
|
| 1192 | - * @param integer $post_id |
|
| 1193 | - * @return array |
|
| 1194 | - */ |
|
| 1195 | - public function sensei_count_comments( $comments, $post_id ) { |
|
| 1196 | - global $wpdb; |
|
| 1197 | - |
|
| 1198 | - $post_id = (int) $post_id; |
|
| 1199 | - |
|
| 1200 | - $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 1201 | - |
|
| 1202 | - if ( false !== $count ) { |
|
| 1203 | - return $count; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - $statuses = array( '' ); // Default to the WP normal comments |
|
| 1207 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1208 | - foreach ( (array) $stati AS $status ) { |
|
| 1209 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1210 | - $statuses[] = $status['comment_type']; |
|
| 1211 | - } |
|
| 1212 | - } |
|
| 1213 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1214 | - |
|
| 1215 | - if ( $post_id > 0 ) |
|
| 1216 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1217 | - |
|
| 1218 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1219 | - |
|
| 1220 | - $total = 0; |
|
| 1221 | - $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 1222 | - foreach ( (array) $count as $row ) { |
|
| 1223 | - // Don't count post-trashed toward totals |
|
| 1224 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1225 | - $total += $row['num_comments']; |
|
| 1226 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1227 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - $stats['total_comments'] = $total; |
|
| 1231 | - foreach ( $approved as $key ) { |
|
| 1232 | - if ( empty($stats[$key]) ) |
|
| 1233 | - $stats[$key] = 0; |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - $stats = (object) $stats; |
|
| 1237 | - wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 1238 | - |
|
| 1239 | - return $stats; |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - /** |
|
| 1243 | - * Init images. |
|
| 1244 | - * |
|
| 1245 | - * @since 1.4.5 |
|
| 1246 | - * @access public |
|
| 1247 | - * @return void |
|
| 1248 | - */ |
|
| 1249 | - public function init_image_sizes() { |
|
| 1250 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1251 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1252 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1253 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1254 | - |
|
| 1255 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1256 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1257 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1258 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - /** |
|
| 1262 | - * Get an image size. |
|
| 1263 | - * |
|
| 1264 | - * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 1265 | - * |
|
| 1266 | - * @since 1.4.5 |
|
| 1267 | - * @access public |
|
| 1268 | - * @param mixed $image_size |
|
| 1269 | - * @return string |
|
| 1270 | - */ |
|
| 1271 | - public function get_image_size( $image_size ) { |
|
| 1272 | - |
|
| 1273 | - // Only return sizes we define in settings |
|
| 1274 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1275 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1276 | - |
|
| 1277 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1278 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1279 | - } |
|
| 1280 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1281 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1282 | - } |
|
| 1283 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1284 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1285 | - } |
|
| 1286 | - |
|
| 1287 | - $size = array_filter( array( |
|
| 1288 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1289 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1290 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1291 | - ) ); |
|
| 1292 | - |
|
| 1293 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1294 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1295 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1296 | - |
|
| 1297 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - public function body_class( $classes ) { |
|
| 1301 | - if( is_sensei() ) { |
|
| 1302 | - $classes[] = 'sensei'; |
|
| 1303 | - } |
|
| 1304 | - return $classes; |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - /** |
|
| 1308 | - * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 1309 | - * |
|
| 1310 | - * @return null |
|
| 1311 | - * @since 1.7.0 |
|
| 1312 | - */ |
|
| 1313 | - public function jetpack_latex_support() { |
|
| 1314 | - if ( function_exists( 'latex_markup') ) { |
|
| 1315 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1316 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1317 | - } |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - /** |
|
| 1321 | - * Load the module functionality. |
|
| 1322 | - * |
|
| 1323 | - * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 1324 | - * the retired modules extension. |
|
| 1325 | - * |
|
| 1326 | - * @since 1.8.0 |
|
| 1327 | - */ |
|
| 1328 | - public function load_modules_class(){ |
|
| 1329 | - global $sensei_modules; |
|
| 1330 | - |
|
| 1331 | - if( !class_exists( 'Sensei_Modules' ) |
|
| 1332 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1333 | - |
|
| 1334 | - //Load the modules class |
|
| 1335 | - require_once( 'class-sensei-modules.php'); |
|
| 1336 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1337 | - |
|
| 1338 | - }else{ |
|
| 1339 | - // fallback for people still using the modules extension. |
|
| 1340 | - global $sensei_modules; |
|
| 1341 | - Sensei()->modules = $sensei_modules; |
|
| 1342 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1343 | - } |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - /** |
|
| 1347 | - * Tell the user to that the modules extension is no longer needed. |
|
| 1348 | - * |
|
| 1349 | - * @since 1.8.0 |
|
| 1350 | - */ |
|
| 1351 | - public function disable_sensei_modules_extension(){ ?> |
|
| 333 | + /** |
|
| 334 | + * Initialize all Sensei hooks |
|
| 335 | + * |
|
| 336 | + * @since 1.9.0 |
|
| 337 | + */ |
|
| 338 | + public function load_hooks(){ |
|
| 339 | + |
|
| 340 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 341 | + add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 342 | + |
|
| 343 | + // WooCommerce Payment Actions |
|
| 344 | + add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 345 | + add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 346 | + add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 347 | + add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 348 | + add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 349 | + add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 350 | + add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 351 | + |
|
| 352 | + // WooCommerce Subscriptions Actions |
|
| 353 | + add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 354 | + add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 355 | + add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 356 | + add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 357 | + add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 358 | + |
|
| 359 | + // Add Email link to course orders |
|
| 360 | + add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 361 | + |
|
| 362 | + // Filter comment counts |
|
| 363 | + add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 364 | + |
|
| 365 | + add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 366 | + |
|
| 367 | + // Check for and activate JetPack LaTeX support |
|
| 368 | + add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 369 | + |
|
| 370 | + // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 371 | + add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 372 | + |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Run Sensei updates. |
|
| 377 | + * @access public |
|
| 378 | + * @since 1.1.0 |
|
| 379 | + * @return void |
|
| 380 | + */ |
|
| 381 | + public function run_updates() { |
|
| 382 | + // Run updates if administrator |
|
| 383 | + if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 384 | + |
|
| 385 | + $this->updates->update(); |
|
| 386 | + |
|
| 387 | + } // End If Statement |
|
| 388 | + } // End run_updates() |
|
| 389 | + |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Setup required WooCommerce settings. |
|
| 394 | + * @access public |
|
| 395 | + * @since 1.1.0 |
|
| 396 | + * @return void |
|
| 397 | + */ |
|
| 398 | + public function set_woocommerce_functionality() { |
|
| 399 | + // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
|
| 400 | + add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 401 | + |
|
| 402 | + // Mark orders with virtual products as complete rather then stay processing |
|
| 403 | + add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 404 | + |
|
| 405 | + } // End set_woocommerce_functionality() |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Disable guest checkout if a course product is in the cart |
|
| 409 | + * @param boolean $guest_checkout Current guest checkout setting |
|
| 410 | + * @return boolean Modified guest checkout setting |
|
| 411 | + */ |
|
| 412 | + public function disable_guest_checkout( $guest_checkout ) { |
|
| 413 | + global $woocommerce; |
|
| 414 | + |
|
| 415 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 416 | + |
|
| 417 | + if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 418 | + foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 419 | + if( isset( $product['product_id'] ) ) { |
|
| 420 | + $args = array( |
|
| 421 | + 'posts_per_page' => -1, |
|
| 422 | + 'post_type' => 'course', |
|
| 423 | + 'meta_query' => array( |
|
| 424 | + array( |
|
| 425 | + 'key' => '_course_woocommerce_product', |
|
| 426 | + 'value' => $product['product_id'] |
|
| 427 | + ) |
|
| 428 | + ) |
|
| 429 | + ); |
|
| 430 | + $posts = get_posts( $args ); |
|
| 431 | + if( $posts && count( $posts ) > 0 ) { |
|
| 432 | + foreach( $posts as $course ) { |
|
| 433 | + $guest_checkout = ''; |
|
| 434 | + break; |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return $guest_checkout; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Change order status with virtual products to completed |
|
| 447 | + * @since 1.1.0 |
|
| 448 | + * @param string $order_status |
|
| 449 | + * @param int $order_id |
|
| 450 | + * @return string |
|
| 451 | + **/ |
|
| 452 | + public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 453 | + $order = new WC_Order( $order_id ); |
|
| 454 | + if ( ! isset ( $order ) ) return ''; |
|
| 455 | + if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 456 | + $virtual_order = true; |
|
| 457 | + |
|
| 458 | + if ( count( $order->get_items() ) > 0 ) { |
|
| 459 | + foreach( $order->get_items() as $item ) { |
|
| 460 | + if ( $item['product_id'] > 0 ) { |
|
| 461 | + $_product = $order->get_product_from_item( $item ); |
|
| 462 | + if ( ! $_product->is_virtual() ) { |
|
| 463 | + $virtual_order = false; |
|
| 464 | + break; |
|
| 465 | + } // End If Statement |
|
| 466 | + } // End If Statement |
|
| 467 | + } // End For Loop |
|
| 468 | + } // End If Statement |
|
| 469 | + |
|
| 470 | + // virtual order, mark as completed |
|
| 471 | + if ( $virtual_order ) { |
|
| 472 | + return 'completed'; |
|
| 473 | + } // End If Statement |
|
| 474 | + } // End If Statement |
|
| 475 | + return $order_status; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Register the widgets. |
|
| 480 | + * @access public |
|
| 481 | + * @since 1.0.0 |
|
| 482 | + * @return void |
|
| 483 | + */ |
|
| 484 | + public function register_widgets () { |
|
| 485 | + // Widget List (key => value is filename => widget class). |
|
| 486 | + $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 487 | + 'lesson-component' => 'Lesson_Component', |
|
| 488 | + 'course-categories' => 'Course_Categories', |
|
| 489 | + 'category-courses' => 'Category_Courses' ) |
|
| 490 | + ); |
|
| 491 | + foreach ( $widget_list as $key => $value ) { |
|
| 492 | + if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
| 493 | + require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
| 494 | + register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 495 | + } |
|
| 496 | + } // End For Loop |
|
| 497 | + |
|
| 498 | + do_action( 'sensei_register_widgets' ); |
|
| 499 | + |
|
| 500 | + } // End register_widgets() |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Load the plugin's localisation file. |
|
| 504 | + * @access public |
|
| 505 | + * @since 1.0.0 |
|
| 506 | + * @return void |
|
| 507 | + */ |
|
| 508 | + public function load_localisation () { |
|
| 509 | + load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 510 | + } // End load_localisation() |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 514 | + * @access public |
|
| 515 | + * @since 1.0.0 |
|
| 516 | + * @return void |
|
| 517 | + */ |
|
| 518 | + public function load_plugin_textdomain () { |
|
| 519 | + $domain = 'woothemes-sensei'; |
|
| 520 | + // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 521 | + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 522 | + load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 523 | + load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 524 | + } // End load_plugin_textdomain() |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Run on activation. |
|
| 528 | + * @access public |
|
| 529 | + * @since 1.0.0 |
|
| 530 | + * @return void |
|
| 531 | + */ |
|
| 532 | + public function activation () { |
|
| 533 | + $this->register_plugin_version(); |
|
| 534 | + } // End activation() |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * Register activation hooks. |
|
| 539 | + * @access public |
|
| 540 | + * @since 1.0.0 |
|
| 541 | + * @return void |
|
| 542 | + */ |
|
| 543 | + public function install () { |
|
| 544 | + register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 545 | + register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 546 | + } // End install() |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Run on activation of the plugin. |
|
| 551 | + * @access public |
|
| 552 | + * @since 1.0.0 |
|
| 553 | + * @return void |
|
| 554 | + */ |
|
| 555 | + public function activate_sensei () { |
|
| 556 | + update_option( 'skip_install_sensei_pages', 0 ); |
|
| 557 | + update_option( 'sensei_installed', 1 ); |
|
| 558 | + } // End activate_sensei() |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Register the plugin's version. |
|
| 562 | + * @access public |
|
| 563 | + * @since 1.0.0 |
|
| 564 | + * @return void |
|
| 565 | + */ |
|
| 566 | + private function register_plugin_version () { |
|
| 567 | + if ( $this->version != '' ) { |
|
| 568 | + |
|
| 569 | + // Check previous version to see if forced updates must run |
|
| 570 | + // $old_version = get_option( 'woothemes-sensei-version', false ); |
|
| 571 | + // if( $old_version && version_compare( $old_version, '1.7.0', '<' ) ) { |
|
| 572 | + // update_option( 'woothemes-sensei-force-updates', $this->version ); |
|
| 573 | + // } else { |
|
| 574 | + // delete_option( 'woothemes-sensei-force-updates' ); |
|
| 575 | + // } |
|
| 576 | + |
|
| 577 | + update_option( 'woothemes-sensei-version', $this->version ); |
|
| 578 | + } |
|
| 579 | + } // End register_plugin_version() |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 583 | + * @access public |
|
| 584 | + * @since 1.0.1 |
|
| 585 | + * @return void |
|
| 586 | + */ |
|
| 587 | + public function ensure_post_thumbnails_support () { |
|
| 588 | + if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 589 | + } // End ensure_post_thumbnails_support() |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * template_loader function. |
|
| 594 | + * |
|
| 595 | + * @access public |
|
| 596 | + * @param mixed $template |
|
| 597 | + * @return void |
|
| 598 | + * @deprecated |
|
| 599 | + */ |
|
| 600 | + public function template_loader ( $template = '' ) { |
|
| 601 | + |
|
| 602 | + _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 603 | + Sensei_Templates::template_loader( $template ); |
|
| 604 | + |
|
| 605 | + } // End template_loader() |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Determine the relative path to the plugin's directory. |
|
| 609 | + * @access public |
|
| 610 | + * @since 1.0.0 |
|
| 611 | + * @return string $sensei_plugin_path |
|
| 612 | + */ |
|
| 613 | + public function plugin_path () { |
|
| 614 | + |
|
| 615 | + if ( $this->plugin_path ) { |
|
| 616 | + |
|
| 617 | + $sensei_plugin_path = $this->plugin_path; |
|
| 618 | + |
|
| 619 | + }else{ |
|
| 620 | + |
|
| 621 | + $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 622 | + |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + return $sensei_plugin_path; |
|
| 626 | + |
|
| 627 | + } // End plugin_path() |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * Retrieve the ID of a specified page setting. |
|
| 632 | + * @access public |
|
| 633 | + * @since 1.0.0 |
|
| 634 | + * @param string $page |
|
| 635 | + * @return int |
|
| 636 | + */ |
|
| 637 | + public function get_page_id ( $page ) { |
|
| 638 | + $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 639 | + return ( $page ) ? $page : -1; |
|
| 640 | + } // End get_page_id() |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 645 | + * @access public |
|
| 646 | + * @since 1.0.0 |
|
| 647 | + * @param int $course_id (default: 0) |
|
| 648 | + * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 649 | + * @return bool|int |
|
| 650 | + */ |
|
| 651 | + public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 652 | + global $current_user; |
|
| 653 | + |
|
| 654 | + if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
| 655 | + |
|
| 656 | + $data_update = false; |
|
| 657 | + |
|
| 658 | + // Get the product ID |
|
| 659 | + $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 660 | + |
|
| 661 | + // Check if in the admin |
|
| 662 | + if ( is_admin() ) { |
|
| 663 | + $user_login = $order_user['user_login']; |
|
| 664 | + $user_email = $order_user['user_email']; |
|
| 665 | + $user_url = $order_user['user_url']; |
|
| 666 | + $user_id = $order_user['ID']; |
|
| 667 | + } else { |
|
| 668 | + $user_login = $current_user->user_login; |
|
| 669 | + $user_email = $current_user->user_email; |
|
| 670 | + $user_url = $current_user->user_url; |
|
| 671 | + $user_id = $current_user->ID; |
|
| 672 | + } // End If Statement |
|
| 673 | + |
|
| 674 | + // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 675 | + $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 676 | + if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 677 | + $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 678 | + if ( ! $prereq_course_complete ) { |
|
| 679 | + // Remove all course user meta |
|
| 680 | + return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 685 | + |
|
| 686 | + if( ! $is_user_taking_course ) { |
|
| 687 | + |
|
| 688 | + if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 689 | + |
|
| 690 | + $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 691 | + |
|
| 692 | + $is_user_taking_course = false; |
|
| 693 | + if ( true == $activity_logged ) { |
|
| 694 | + $is_user_taking_course = true; |
|
| 695 | + } // End If Statement |
|
| 696 | + } // End If Statement |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return $is_user_taking_course; |
|
| 700 | + } // End woocommerce_course_update() |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + /** |
|
| 704 | + * check_user_permissions function. |
|
| 705 | + * |
|
| 706 | + * @access public |
|
| 707 | + * @param string $page (default: '') |
|
| 708 | + * |
|
| 709 | + * @return bool |
|
| 710 | + */ |
|
| 711 | + public function check_user_permissions ( $page = '' ) { |
|
| 712 | + // REFACTOR |
|
| 713 | + global $current_user, $post; |
|
| 714 | + |
|
| 715 | + // if use is not logged in |
|
| 716 | + // skipped for single lesson |
|
| 717 | + if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') |
|
| 718 | + && 'lesson-single' != $page ){ |
|
| 719 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 720 | + $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 721 | + return false; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + |
|
| 725 | + // Get User Meta |
|
| 726 | + get_currentuserinfo(); |
|
| 727 | + |
|
| 728 | + $user_allowed = false; |
|
| 729 | + |
|
| 730 | + switch ( $page ) { |
|
| 731 | + case 'course-single': |
|
| 732 | + // check for prerequisite course or lesson, |
|
| 733 | + $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 734 | + $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 735 | + // Count completed lessons |
|
| 736 | + if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 737 | + |
|
| 738 | + $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 739 | + |
|
| 740 | + } |
|
| 741 | + else { |
|
| 742 | + $prerequisite_complete = true; |
|
| 743 | + } // End If Statement |
|
| 744 | + // Handles restrictions |
|
| 745 | + if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 746 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 747 | + $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 748 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 749 | + } else { |
|
| 750 | + $user_allowed = true; |
|
| 751 | + } // End If Statement |
|
| 752 | + break; |
|
| 753 | + case 'lesson-single': |
|
| 754 | + // Check for WC purchase |
|
| 755 | + $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 756 | + |
|
| 757 | + $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 758 | + $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 759 | + |
|
| 760 | + if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 761 | + $user_allowed = true; |
|
| 762 | + } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 763 | + |
|
| 764 | + $user_allowed = true; |
|
| 765 | + |
|
| 766 | + } else { |
|
| 767 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 768 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 769 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 770 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 771 | + if ( $is_preview ) { |
|
| 772 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 773 | + } else { |
|
| 774 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 775 | + } |
|
| 776 | + } else { |
|
| 777 | + if ( $is_preview ) { |
|
| 778 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please sign up for the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 779 | + } else { |
|
| 780 | + /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 781 | + $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 782 | + } |
|
| 783 | + } // End If Statement |
|
| 784 | + } // End If Statement |
|
| 785 | + break; |
|
| 786 | + case 'quiz-single': |
|
| 787 | + $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 788 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 789 | + |
|
| 790 | + $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 791 | + if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 792 | + |
|
| 793 | + // Check for prerequisite lesson for this quiz |
|
| 794 | + $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 795 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 796 | + |
|
| 797 | + // Handle restrictions |
|
| 798 | + if( sensei_all_access() ) { |
|
| 799 | + $user_allowed = true; |
|
| 800 | + } else { |
|
| 801 | + if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 802 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 803 | + $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 804 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 805 | + } else { |
|
| 806 | + $user_allowed = true; |
|
| 807 | + } // End If Statement |
|
| 808 | + } // End If Statement |
|
| 809 | + } elseif( $this->access_settings() ) { |
|
| 810 | + // Check if the user has started the course |
|
| 811 | + |
|
| 812 | + if ( is_user_logged_in() && ! Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) && ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) ) { |
|
| 813 | + |
|
| 814 | + $user_allowed = false; |
|
| 815 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 816 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 817 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 818 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 819 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 820 | + } else { |
|
| 821 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 822 | + } // End If Statement |
|
| 823 | + } else { |
|
| 824 | + $user_allowed = true; |
|
| 825 | + } // End If Statement |
|
| 826 | + } else { |
|
| 827 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 828 | + $course_link = '<a href="' . esc_url( get_permalink( get_post_meta( get_post_meta( $post->ID, '_quiz_lesson', true ), '_lesson_course', true ) ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 829 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 830 | + } // End If Statement |
|
| 831 | + break; |
|
| 832 | + default: |
|
| 833 | + $user_allowed = true; |
|
| 834 | + break; |
|
| 835 | + |
|
| 836 | + } // End Switch Statement |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * filter the permissions message shown on sensei post types. |
|
| 840 | + * |
|
| 841 | + * @since 1.8.7 |
|
| 842 | + * |
|
| 843 | + * @param array $permissions_message{ |
|
| 844 | + * |
|
| 845 | + * @type string $title |
|
| 846 | + * @type string $message |
|
| 847 | + * |
|
| 848 | + * } |
|
| 849 | + * @param string $post_id |
|
| 850 | + */ |
|
| 851 | + $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 855 | + $user_allowed = true; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 859 | + } // End get_placeholder_image() |
|
| 860 | + |
|
| 861 | + |
|
| 862 | + /** |
|
| 863 | + * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 864 | + * @since 1.0.0 |
|
| 865 | + * @access public |
|
| 866 | + * @return bool |
|
| 867 | + */ |
|
| 868 | + public function access_settings () { |
|
| 869 | + |
|
| 870 | + if( sensei_all_access() ) return true; |
|
| 871 | + |
|
| 872 | + if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 873 | + if ( is_user_logged_in() ) { |
|
| 874 | + return true; |
|
| 875 | + } else { |
|
| 876 | + return false; |
|
| 877 | + } // End If Statement |
|
| 878 | + } else { |
|
| 879 | + return true; |
|
| 880 | + } // End If Statement |
|
| 881 | + } // End access_settings() |
|
| 882 | + |
|
| 883 | + /** |
|
| 884 | + * sensei_woocommerce_complete_order description |
|
| 885 | + * @since 1.0.3 |
|
| 886 | + * @access public |
|
| 887 | + * @param int $order_id WC order ID |
|
| 888 | + * @return void |
|
| 889 | + */ |
|
| 890 | + public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 891 | + $order_user = array(); |
|
| 892 | + // Check for WooCommerce |
|
| 893 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 894 | + // Get order object |
|
| 895 | + $order = new WC_Order( $order_id ); |
|
| 896 | + $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 897 | + $order_user['ID'] = $user->ID; |
|
| 898 | + $order_user['user_login'] = $user->user_login; |
|
| 899 | + $order_user['user_email'] = $user->user_email; |
|
| 900 | + $order_user['user_url'] = $user->user_url; |
|
| 901 | + // Run through each product ordered |
|
| 902 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 903 | + foreach( $order->get_items() as $item ) { |
|
| 904 | + $product_type = ''; |
|
| 905 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 906 | + $item_id = $item['variation_id']; |
|
| 907 | + $product_type = 'variation'; |
|
| 908 | + } else { |
|
| 909 | + $item_id = $item['product_id']; |
|
| 910 | + } // End If Statement |
|
| 911 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 912 | + // Get courses that use the WC product |
|
| 913 | + $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 914 | + // Loop and update those courses |
|
| 915 | + foreach ( $courses as $course_item ) { |
|
| 916 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 917 | + } // End For Loop |
|
| 918 | + } // End For Loop |
|
| 919 | + } // End If Statement |
|
| 920 | + // Add meta to indicate that payment has been completed successfully |
|
| 921 | + update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 922 | + } // End If Statement |
|
| 923 | + } // End sensei_woocommerce_complete_order() |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * Runs when an order is cancelled. |
|
| 927 | + * @since 1.2.0 |
|
| 928 | + * @access public |
|
| 929 | + * @param integer $order_id order ID |
|
| 930 | + * @return void |
|
| 931 | + */ |
|
| 932 | + public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 933 | + |
|
| 934 | + // Get order object |
|
| 935 | + $order = new WC_Order( $order_id ); |
|
| 936 | + |
|
| 937 | + // Run through each product ordered |
|
| 938 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 939 | + |
|
| 940 | + // Get order user |
|
| 941 | + $user_id = $order->__get( 'user_id' ); |
|
| 942 | + |
|
| 943 | + foreach( $order->get_items() as $item ) { |
|
| 944 | + |
|
| 945 | + $product_type = ''; |
|
| 946 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 947 | + $item_id = $item['variation_id']; |
|
| 948 | + $product_type = 'variation'; |
|
| 949 | + } else { |
|
| 950 | + $item_id = $item['product_id']; |
|
| 951 | + } // End If Statement |
|
| 952 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 953 | + |
|
| 954 | + // Get courses that use the WC product |
|
| 955 | + $courses = array(); |
|
| 956 | + $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 957 | + |
|
| 958 | + // Loop and update those courses |
|
| 959 | + foreach ($courses as $course_item){ |
|
| 960 | + // Check and Remove course from courses user meta |
|
| 961 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 962 | + } // End For Loop |
|
| 963 | + } // End For Loop |
|
| 964 | + } // End If Statement |
|
| 965 | + } // End sensei_woocommerce_cancel_order() |
|
| 966 | + |
|
| 967 | + /** |
|
| 968 | + * Runs when an subscription is cancelled or expires. |
|
| 969 | + * @since 1.3.3 |
|
| 970 | + * @access public |
|
| 971 | + * @param integer $user_id User ID |
|
| 972 | + * @param integer $subscription_key Subscription Unique Key |
|
| 973 | + * @return void |
|
| 974 | + */ |
|
| 975 | + public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 976 | + $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 977 | + self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + /** |
|
| 981 | + * Runs when an subscription is re-activated after suspension. |
|
| 982 | + * @since 1.3.3 |
|
| 983 | + * @access public |
|
| 984 | + * @param integer $user_id User ID |
|
| 985 | + * @param integer $subscription_key Subscription Unique Key |
|
| 986 | + * @return void |
|
| 987 | + */ |
|
| 988 | + public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 989 | + $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 990 | + $order = new WC_Order( $subscription['order_id'] ); |
|
| 991 | + $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 992 | + $order_user = array(); |
|
| 993 | + $order_user['ID'] = $user->ID; |
|
| 994 | + $order_user['user_login'] = $user->user_login; |
|
| 995 | + $order_user['user_email'] = $user->user_email; |
|
| 996 | + $order_user['user_url'] = $user->user_url; |
|
| 997 | + $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 998 | + foreach ( $courses as $course_item ){ |
|
| 999 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1000 | + } // End For Loop |
|
| 1001 | + } // End sensei_woocommerce_reactivate_subscription |
|
| 1002 | + |
|
| 1003 | + /** |
|
| 1004 | + * Returns the WooCommerce Product Object |
|
| 1005 | + * |
|
| 1006 | + * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 1007 | + * |
|
| 1008 | + * @since 1.1.1 |
|
| 1009 | + * @access public |
|
| 1010 | + * @param integer $wc_product_id Product ID or Variation ID |
|
| 1011 | + * @param string $product_type '' or 'variation' |
|
| 1012 | + * @return WC_Product $wc_product_object |
|
| 1013 | + */ |
|
| 1014 | + public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1015 | + |
|
| 1016 | + $wc_product_object = false; |
|
| 1017 | + if ( 0 < intval( $wc_product_id ) ) { |
|
| 1018 | + |
|
| 1019 | + // Get the product |
|
| 1020 | + if ( function_exists( 'wc_get_product' ) ) { |
|
| 1021 | + |
|
| 1022 | + $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1023 | + |
|
| 1024 | + } elseif ( function_exists( 'get_product' ) ) { |
|
| 1025 | + |
|
| 1026 | + $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1027 | + |
|
| 1028 | + } else { |
|
| 1029 | + |
|
| 1030 | + // Pre WC 2.0 |
|
| 1031 | + if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1032 | + |
|
| 1033 | + $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1034 | + |
|
| 1035 | + } else { |
|
| 1036 | + |
|
| 1037 | + $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1038 | + |
|
| 1039 | + } // End If Statement |
|
| 1040 | + |
|
| 1041 | + } // End If Statement |
|
| 1042 | + |
|
| 1043 | + } // End If Statement |
|
| 1044 | + |
|
| 1045 | + return $wc_product_object; |
|
| 1046 | + |
|
| 1047 | + } // End sensei_get_woocommerce_product_object() |
|
| 1048 | + |
|
| 1049 | + /** |
|
| 1050 | + * load_class loads in class files |
|
| 1051 | + * @since 1.2.0 |
|
| 1052 | + * @access public |
|
| 1053 | + * @return void |
|
| 1054 | + */ |
|
| 1055 | + public function load_class ( $class_name = '' ) { |
|
| 1056 | + if ( '' != $class_name && '' != $this->token ) { |
|
| 1057 | + require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1058 | + } // End If Statement |
|
| 1059 | + } // End load_class() |
|
| 1060 | + |
|
| 1061 | + /** |
|
| 1062 | + * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1063 | + * @since 1.2.0 |
|
| 1064 | + * @access public |
|
| 1065 | + * @param integer $order_id order ID |
|
| 1066 | + * @return void |
|
| 1067 | + */ |
|
| 1068 | + public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1069 | + if ( 0 < intval( $order_id ) ) { |
|
| 1070 | + $order = new WC_Order( $order_id ); |
|
| 1071 | + $user = get_user_by('id', $order->user_id); |
|
| 1072 | + $order_user['ID'] = $user->ID; |
|
| 1073 | + $order_user['user_login'] = $user->user_login; |
|
| 1074 | + $order_user['user_email'] = $user->user_email; |
|
| 1075 | + $order_user['user_url'] = $user->user_url; |
|
| 1076 | + // Run through each product ordered |
|
| 1077 | + if (sizeof($order->get_items())>0) { |
|
| 1078 | + foreach($order->get_items() as $item) { |
|
| 1079 | + $product_type = ''; |
|
| 1080 | + if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1081 | + $item_id = $item['variation_id']; |
|
| 1082 | + $product_type = 'subscription_variation'; |
|
| 1083 | + } else { |
|
| 1084 | + $item_id = $item['product_id']; |
|
| 1085 | + } // End If Statement |
|
| 1086 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1087 | + // Get courses that use the WC product |
|
| 1088 | + $courses = array(); |
|
| 1089 | + if ( $product_type == 'subscription_variation' ) { |
|
| 1090 | + $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1091 | + } // End If Statement |
|
| 1092 | + // Loop and update those courses |
|
| 1093 | + foreach ($courses as $course_item){ |
|
| 1094 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1095 | + } // End For Loop |
|
| 1096 | + } // End For Loop |
|
| 1097 | + } // End If Statement |
|
| 1098 | + } // End If Statement |
|
| 1099 | + } // End sensei_activate_subscription() |
|
| 1100 | + |
|
| 1101 | + /** |
|
| 1102 | + * sensei_woocommerce_email_course_details adds detail to email |
|
| 1103 | + * @since 1.4.5 |
|
| 1104 | + * @access public |
|
| 1105 | + * @param WC_Order $order |
|
| 1106 | + * @return void |
|
| 1107 | + */ |
|
| 1108 | + public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1109 | + global $woocommerce; |
|
| 1110 | + |
|
| 1111 | + // exit early if not wc-completed or wc-processing |
|
| 1112 | + if( 'wc-completed' != $order->post_status |
|
| 1113 | + && 'wc-processing' != $order->post_status ) { |
|
| 1114 | + return; |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + $order_items = $order->get_items(); |
|
| 1118 | + $order_id = $order->id; |
|
| 1119 | + |
|
| 1120 | + //If object have items go through them all to find course |
|
| 1121 | + if ( 0 < sizeof( $order_items ) ) { |
|
| 1122 | + |
|
| 1123 | + $course_details_html = '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1124 | + $order_contains_courses = false; |
|
| 1125 | + |
|
| 1126 | + |
|
| 1127 | + foreach ( $order_items as $item ) { |
|
| 1128 | + |
|
| 1129 | + $product_type = ''; |
|
| 1130 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1131 | + // If item has variation_id then its from variation |
|
| 1132 | + $item_id = $item['variation_id']; |
|
| 1133 | + $product_type = 'variation'; |
|
| 1134 | + } else { |
|
| 1135 | + // If not its real product set its id to item_id |
|
| 1136 | + $item_id = $item['product_id']; |
|
| 1137 | + } // End If Statement |
|
| 1138 | + |
|
| 1139 | + $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1140 | + |
|
| 1141 | + if( $user_id ) { |
|
| 1142 | + |
|
| 1143 | + // Get all courses for product |
|
| 1144 | + $args = array( |
|
| 1145 | + 'posts_per_page' => -1, |
|
| 1146 | + 'post_type' => 'course', |
|
| 1147 | + 'meta_query' => array( |
|
| 1148 | + array( |
|
| 1149 | + 'key' => '_course_woocommerce_product', |
|
| 1150 | + 'value' => $item_id |
|
| 1151 | + ) |
|
| 1152 | + ), |
|
| 1153 | + 'orderby' => 'menu_order date', |
|
| 1154 | + 'order' => 'ASC', |
|
| 1155 | + ); |
|
| 1156 | + $courses = get_posts( $args ); |
|
| 1157 | + |
|
| 1158 | + if( $courses && count( $courses ) > 0 ) { |
|
| 1159 | + |
|
| 1160 | + foreach( $courses as $course ) { |
|
| 1161 | + |
|
| 1162 | + $title = $course->post_title; |
|
| 1163 | + $permalink = get_permalink( $course->ID ); |
|
| 1164 | + $order_contains_courses = true; |
|
| 1165 | + $course_details_html .= '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + |
|
| 1169 | + } // end if has courses |
|
| 1170 | + |
|
| 1171 | + } // end if $userPid |
|
| 1172 | + |
|
| 1173 | + } // end for each order item |
|
| 1174 | + |
|
| 1175 | + // Output Course details |
|
| 1176 | + if( $order_contains_courses ){ |
|
| 1177 | + |
|
| 1178 | + echo $course_details_html; |
|
| 1179 | + |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + |
|
| 1183 | + } // end if order items not empty |
|
| 1184 | + |
|
| 1185 | + } // end func email course details |
|
| 1186 | + |
|
| 1187 | + /** |
|
| 1188 | + * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 1189 | + * @since 1.4.0 |
|
| 1190 | + * @access public |
|
| 1191 | + * @param array $comments |
|
| 1192 | + * @param integer $post_id |
|
| 1193 | + * @return array |
|
| 1194 | + */ |
|
| 1195 | + public function sensei_count_comments( $comments, $post_id ) { |
|
| 1196 | + global $wpdb; |
|
| 1197 | + |
|
| 1198 | + $post_id = (int) $post_id; |
|
| 1199 | + |
|
| 1200 | + $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 1201 | + |
|
| 1202 | + if ( false !== $count ) { |
|
| 1203 | + return $count; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + $statuses = array( '' ); // Default to the WP normal comments |
|
| 1207 | + $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1208 | + foreach ( (array) $stati AS $status ) { |
|
| 1209 | + if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1210 | + $statuses[] = $status['comment_type']; |
|
| 1211 | + } |
|
| 1212 | + } |
|
| 1213 | + $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1214 | + |
|
| 1215 | + if ( $post_id > 0 ) |
|
| 1216 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1217 | + |
|
| 1218 | + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1219 | + |
|
| 1220 | + $total = 0; |
|
| 1221 | + $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 1222 | + foreach ( (array) $count as $row ) { |
|
| 1223 | + // Don't count post-trashed toward totals |
|
| 1224 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1225 | + $total += $row['num_comments']; |
|
| 1226 | + if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1227 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + $stats['total_comments'] = $total; |
|
| 1231 | + foreach ( $approved as $key ) { |
|
| 1232 | + if ( empty($stats[$key]) ) |
|
| 1233 | + $stats[$key] = 0; |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + $stats = (object) $stats; |
|
| 1237 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 1238 | + |
|
| 1239 | + return $stats; |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + /** |
|
| 1243 | + * Init images. |
|
| 1244 | + * |
|
| 1245 | + * @since 1.4.5 |
|
| 1246 | + * @access public |
|
| 1247 | + * @return void |
|
| 1248 | + */ |
|
| 1249 | + public function init_image_sizes() { |
|
| 1250 | + $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1251 | + $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1252 | + $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1253 | + $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1254 | + |
|
| 1255 | + add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1256 | + add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1257 | + add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1258 | + add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + /** |
|
| 1262 | + * Get an image size. |
|
| 1263 | + * |
|
| 1264 | + * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 1265 | + * |
|
| 1266 | + * @since 1.4.5 |
|
| 1267 | + * @access public |
|
| 1268 | + * @param mixed $image_size |
|
| 1269 | + * @return string |
|
| 1270 | + */ |
|
| 1271 | + public function get_image_size( $image_size ) { |
|
| 1272 | + |
|
| 1273 | + // Only return sizes we define in settings |
|
| 1274 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1275 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1276 | + |
|
| 1277 | + if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1278 | + $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1279 | + } |
|
| 1280 | + if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1281 | + $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1282 | + } |
|
| 1283 | + if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1284 | + $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1285 | + } |
|
| 1286 | + |
|
| 1287 | + $size = array_filter( array( |
|
| 1288 | + 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1289 | + 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1290 | + 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1291 | + ) ); |
|
| 1292 | + |
|
| 1293 | + $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1294 | + $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1295 | + $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1296 | + |
|
| 1297 | + return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1298 | + } |
|
| 1299 | + |
|
| 1300 | + public function body_class( $classes ) { |
|
| 1301 | + if( is_sensei() ) { |
|
| 1302 | + $classes[] = 'sensei'; |
|
| 1303 | + } |
|
| 1304 | + return $classes; |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + /** |
|
| 1308 | + * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 1309 | + * |
|
| 1310 | + * @return null |
|
| 1311 | + * @since 1.7.0 |
|
| 1312 | + */ |
|
| 1313 | + public function jetpack_latex_support() { |
|
| 1314 | + if ( function_exists( 'latex_markup') ) { |
|
| 1315 | + add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1316 | + add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1317 | + } |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + /** |
|
| 1321 | + * Load the module functionality. |
|
| 1322 | + * |
|
| 1323 | + * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 1324 | + * the retired modules extension. |
|
| 1325 | + * |
|
| 1326 | + * @since 1.8.0 |
|
| 1327 | + */ |
|
| 1328 | + public function load_modules_class(){ |
|
| 1329 | + global $sensei_modules; |
|
| 1330 | + |
|
| 1331 | + if( !class_exists( 'Sensei_Modules' ) |
|
| 1332 | + && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1333 | + |
|
| 1334 | + //Load the modules class |
|
| 1335 | + require_once( 'class-sensei-modules.php'); |
|
| 1336 | + Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1337 | + |
|
| 1338 | + }else{ |
|
| 1339 | + // fallback for people still using the modules extension. |
|
| 1340 | + global $sensei_modules; |
|
| 1341 | + Sensei()->modules = $sensei_modules; |
|
| 1342 | + add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1343 | + } |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + /** |
|
| 1347 | + * Tell the user to that the modules extension is no longer needed. |
|
| 1348 | + * |
|
| 1349 | + * @since 1.8.0 |
|
| 1350 | + */ |
|
| 1351 | + public function disable_sensei_modules_extension(){ ?> |
|
| 1352 | 1352 | <div class="notice updated fade"> |
| 1353 | 1353 | <p> |
| 1354 | 1354 | <?php |
| 1355 | - $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 1356 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1357 | - ?> |
|
| 1355 | + $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 1356 | + $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1357 | + ?> |
|
| 1358 | 1358 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
| 1359 | 1359 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
| 1360 | 1360 | </p> |
@@ -1362,46 +1362,46 @@ discard block |
||
| 1362 | 1362 | |
| 1363 | 1363 | <?php }// end function |
| 1364 | 1364 | |
| 1365 | - /** |
|
| 1366 | - * Sensei wide rewrite flush call. |
|
| 1367 | - * |
|
| 1368 | - * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 1369 | - * |
|
| 1370 | - * After the option is one the Rules will be flushed. |
|
| 1371 | - * |
|
| 1372 | - * @since 1.9.0 |
|
| 1373 | - */ |
|
| 1374 | - public function flush_rewrite_rules(){ |
|
| 1365 | + /** |
|
| 1366 | + * Sensei wide rewrite flush call. |
|
| 1367 | + * |
|
| 1368 | + * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 1369 | + * |
|
| 1370 | + * After the option is one the Rules will be flushed. |
|
| 1371 | + * |
|
| 1372 | + * @since 1.9.0 |
|
| 1373 | + */ |
|
| 1374 | + public function flush_rewrite_rules(){ |
|
| 1375 | 1375 | |
| 1376 | - // ensures that the rewrite rules are flushed on the second |
|
| 1377 | - // attempt. This ensure that the settings for any other process |
|
| 1378 | - // have been completed and saved to the database before we refresh the |
|
| 1379 | - // rewrite rules. |
|
| 1380 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1381 | - if( '1' == $option ) { |
|
| 1376 | + // ensures that the rewrite rules are flushed on the second |
|
| 1377 | + // attempt. This ensure that the settings for any other process |
|
| 1378 | + // have been completed and saved to the database before we refresh the |
|
| 1379 | + // rewrite rules. |
|
| 1380 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1381 | + if( '1' == $option ) { |
|
| 1382 | 1382 | |
| 1383 | - update_option('sensei_flush_rewrite_rules', '2'); |
|
| 1383 | + update_option('sensei_flush_rewrite_rules', '2'); |
|
| 1384 | 1384 | |
| 1385 | - }elseif( '2' == $option ) { |
|
| 1385 | + }elseif( '2' == $option ) { |
|
| 1386 | 1386 | |
| 1387 | - flush_rewrite_rules(); |
|
| 1388 | - update_option('sensei_flush_rewrite_rules', '0'); |
|
| 1387 | + flush_rewrite_rules(); |
|
| 1388 | + update_option('sensei_flush_rewrite_rules', '0'); |
|
| 1389 | 1389 | |
| 1390 | - } |
|
| 1390 | + } |
|
| 1391 | 1391 | |
| 1392 | - } // end flush_rewrite_rules |
|
| 1392 | + } // end flush_rewrite_rules |
|
| 1393 | 1393 | |
| 1394 | - /** |
|
| 1395 | - * Calling this function will tell Sensei to flush rewrite |
|
| 1396 | - * rules on the next load. |
|
| 1397 | - * |
|
| 1398 | - * @since 1.9.0 |
|
| 1399 | - */ |
|
| 1400 | - public function initiate_rewrite_rules_flush(){ |
|
| 1394 | + /** |
|
| 1395 | + * Calling this function will tell Sensei to flush rewrite |
|
| 1396 | + * rules on the next load. |
|
| 1397 | + * |
|
| 1398 | + * @since 1.9.0 |
|
| 1399 | + */ |
|
| 1400 | + public function initiate_rewrite_rules_flush(){ |
|
| 1401 | 1401 | |
| 1402 | - update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1402 | + update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1403 | 1403 | |
| 1404 | - } |
|
| 1404 | + } |
|
| 1405 | 1405 | |
| 1406 | 1406 | } // End Class |
| 1407 | 1407 | |
@@ -12,735 +12,735 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | Class Sensei_WC{ |
| 15 | - /** |
|
| 16 | - * Load the files needed for the woocommerce integration. |
|
| 17 | - * |
|
| 18 | - * @since 1.9.0 |
|
| 19 | - */ |
|
| 20 | - public static function load_woocommerce_integration_hooks(){ |
|
| 15 | + /** |
|
| 16 | + * Load the files needed for the woocommerce integration. |
|
| 17 | + * |
|
| 18 | + * @since 1.9.0 |
|
| 19 | + */ |
|
| 20 | + public static function load_woocommerce_integration_hooks(){ |
|
| 21 | 21 | |
| 22 | - require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 22 | + require_once( __DIR__ . '/hooks/woocommerce.php' ); |
|
| 23 | 23 | |
| 24 | - } |
|
| 25 | - /** |
|
| 26 | - * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 27 | - * |
|
| 28 | - * @since 1.9.0 |
|
| 29 | - * @return bool |
|
| 30 | - */ |
|
| 31 | - public static function is_woocommerce_active(){ |
|
| 24 | + } |
|
| 25 | + /** |
|
| 26 | + * check if WooCommerce plugin is loaded and allowed by Sensei |
|
| 27 | + * |
|
| 28 | + * @since 1.9.0 |
|
| 29 | + * @return bool |
|
| 30 | + */ |
|
| 31 | + public static function is_woocommerce_active(){ |
|
| 32 | 32 | |
| 33 | - $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | - return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 33 | + $is_woocommerce_enabled_in_settings = isset( Sensei()->settings->settings['woocommerce_enabled'] ) && Sensei()->settings->settings['woocommerce_enabled']; |
|
| 34 | + return self::is_woocommerce_present() && $is_woocommerce_enabled_in_settings; |
|
| 35 | 35 | |
| 36 | - } // end is_woocommerce_active |
|
| 36 | + } // end is_woocommerce_active |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Checks if the WooCommerce plugin is installed and activation. |
|
| 40 | - * |
|
| 41 | - * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 42 | - * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 43 | - * |
|
| 44 | - * @since 1.9.0 |
|
| 45 | - * |
|
| 46 | - * @return bool |
|
| 47 | - */ |
|
| 48 | - public static function is_woocommerce_present(){ |
|
| 38 | + /** |
|
| 39 | + * Checks if the WooCommerce plugin is installed and activation. |
|
| 40 | + * |
|
| 41 | + * If you need to check if WooCommerce is activated use Sensei_Utils::is_woocommerce_active(). |
|
| 42 | + * This function does nott check to see if the Sensei setting for WooCommerce is enabled. |
|
| 43 | + * |
|
| 44 | + * @since 1.9.0 |
|
| 45 | + * |
|
| 46 | + * @return bool |
|
| 47 | + */ |
|
| 48 | + public static function is_woocommerce_present(){ |
|
| 49 | 49 | |
| 50 | - $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 50 | + $active_plugins = (array) get_option( 'active_plugins', array() ); |
|
| 51 | 51 | |
| 52 | - if ( is_multisite() ){ |
|
| 52 | + if ( is_multisite() ){ |
|
| 53 | 53 | |
| 54 | - $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 54 | + $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
|
| 55 | 55 | |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 58 | + $is_woocommerce_plugin_present_and_activated = in_array( 'woocommerce/woocommerce.php', $active_plugins ) || array_key_exists( 'woocommerce/woocommerce.php', $active_plugins ); |
|
| 59 | 59 | |
| 60 | - return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 60 | + return class_exists( 'Woocommerce' ) || $is_woocommerce_plugin_present_and_activated; |
|
| 61 | 61 | |
| 62 | - }// end is_woocommerce_present |
|
| 62 | + }// end is_woocommerce_present |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 66 | - * |
|
| 67 | - * If multiple exist we will return the latest order. |
|
| 68 | - * |
|
| 69 | - * @param $user_id |
|
| 70 | - * @param $course_id |
|
| 71 | - * @return array $user_course_orders |
|
| 72 | - */ |
|
| 73 | - public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 64 | + /** |
|
| 65 | + * Find the order active number (completed or processing ) for a given user on a course. It will return the latest order. |
|
| 66 | + * |
|
| 67 | + * If multiple exist we will return the latest order. |
|
| 68 | + * |
|
| 69 | + * @param $user_id |
|
| 70 | + * @param $course_id |
|
| 71 | + * @return array $user_course_orders |
|
| 72 | + */ |
|
| 73 | + public static function get_learner_course_active_order_id( $user_id, $course_id ){ |
|
| 74 | 74 | |
| 75 | - $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 75 | + $course_product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 76 | 76 | |
| 77 | - $orders_query = new WP_Query( array( |
|
| 78 | - 'post_type' => 'shop_order', |
|
| 79 | - 'posts_per_page' => -1, |
|
| 80 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 81 | - 'meta_key'=> '_customer_user', |
|
| 82 | - 'meta_value'=> $user_id, |
|
| 83 | - ) ); |
|
| 77 | + $orders_query = new WP_Query( array( |
|
| 78 | + 'post_type' => 'shop_order', |
|
| 79 | + 'posts_per_page' => -1, |
|
| 80 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 81 | + 'meta_key'=> '_customer_user', |
|
| 82 | + 'meta_value'=> $user_id, |
|
| 83 | + ) ); |
|
| 84 | 84 | |
| 85 | - if( $orders_query->post_count == 0 ){ |
|
| 85 | + if( $orders_query->post_count == 0 ){ |
|
| 86 | 86 | |
| 87 | - return false; |
|
| 87 | + return false; |
|
| 88 | 88 | |
| 89 | - } |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - foreach( $orders_query->get_posts() as $order ){ |
|
| 91 | + foreach( $orders_query->get_posts() as $order ){ |
|
| 92 | 92 | |
| 93 | - $order = new WC_Order( $order->ID ); |
|
| 94 | - $items = $order->get_items(); |
|
| 93 | + $order = new WC_Order( $order->ID ); |
|
| 94 | + $items = $order->get_items(); |
|
| 95 | 95 | |
| 96 | - $user_orders = array(); |
|
| 96 | + $user_orders = array(); |
|
| 97 | 97 | |
| 98 | - foreach( $items as $item ){ |
|
| 98 | + foreach( $items as $item ){ |
|
| 99 | 99 | |
| 100 | - // if the product id on the order and the one given to this function |
|
| 101 | - // this order has been placed by the given user on the given course. |
|
| 102 | - $product = wc_get_product( $item['product_id'] ); |
|
| 100 | + // if the product id on the order and the one given to this function |
|
| 101 | + // this order has been placed by the given user on the given course. |
|
| 102 | + $product = wc_get_product( $item['product_id'] ); |
|
| 103 | 103 | |
| 104 | - if ( $product->is_type( 'variable' )) { |
|
| 104 | + if ( $product->is_type( 'variable' )) { |
|
| 105 | 105 | |
| 106 | - $item_product_id = $item['variation_id']; |
|
| 106 | + $item_product_id = $item['variation_id']; |
|
| 107 | 107 | |
| 108 | - } else { |
|
| 108 | + } else { |
|
| 109 | 109 | |
| 110 | - $item_product_id = $item['product_id']; |
|
| 110 | + $item_product_id = $item['product_id']; |
|
| 111 | 111 | |
| 112 | - } |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - if( $course_product_id == $item_product_id ){ |
|
| 114 | + if( $course_product_id == $item_product_id ){ |
|
| 115 | 115 | |
| 116 | - return $order->id; |
|
| 116 | + return $order->id; |
|
| 117 | 117 | |
| 118 | - } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | |
| 121 | - }//end for each order item |
|
| 121 | + }//end for each order item |
|
| 122 | 122 | |
| 123 | - } // end for each order |
|
| 123 | + } // end for each order |
|
| 124 | 124 | |
| 125 | - // if we reach this place we found no order |
|
| 126 | - return false; |
|
| 125 | + // if we reach this place we found no order |
|
| 126 | + return false; |
|
| 127 | 127 | |
| 128 | - } // end get_learner_course_active_order_ids |
|
| 128 | + } // end get_learner_course_active_order_ids |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Output WooCommerce specific course filters |
|
| 132 | - * Removing the paged argument |
|
| 133 | - * |
|
| 134 | - * @since 1.9.0 |
|
| 135 | - * @param $filter_links |
|
| 136 | - * @return mixed |
|
| 137 | - */ |
|
| 138 | - public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 130 | + /** |
|
| 131 | + * Output WooCommerce specific course filters |
|
| 132 | + * Removing the paged argument |
|
| 133 | + * |
|
| 134 | + * @since 1.9.0 |
|
| 135 | + * @param $filter_links |
|
| 136 | + * @return mixed |
|
| 137 | + */ |
|
| 138 | + public static function add_course_archive_wc_filter_links( $filter_links ){ |
|
| 139 | 139 | |
| 140 | - $free_courses = self::get_free_courses(); |
|
| 141 | - $paid_courses = self::get_paid_courses(); |
|
| 140 | + $free_courses = self::get_free_courses(); |
|
| 141 | + $paid_courses = self::get_paid_courses(); |
|
| 142 | 142 | |
| 143 | - if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 144 | - // do not show any WooCommerce filters if all courses are |
|
| 145 | - // free or if all courses are paid |
|
| 146 | - return $filter_links; |
|
| 143 | + if ( empty( $free_courses ) || empty( $paid_courses ) ){ |
|
| 144 | + // do not show any WooCommerce filters if all courses are |
|
| 145 | + // free or if all courses are paid |
|
| 146 | + return $filter_links; |
|
| 147 | 147 | |
| 148 | - } |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - $filter_links[] = array( |
|
| 151 | - 'id'=>'paid' , |
|
| 152 | - 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 153 | - 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 154 | - ); |
|
| 150 | + $filter_links[] = array( |
|
| 151 | + 'id'=>'paid' , |
|
| 152 | + 'url'=> add_query_arg( array( 'course_filter'=>'paid'), Sensei_Course::get_courses_page_url() ), |
|
| 153 | + 'title'=>__( 'Paid', 'woothemes-sensei' ) |
|
| 154 | + ); |
|
| 155 | 155 | |
| 156 | - $filter_links[] = array( |
|
| 157 | - 'id'=>'free', |
|
| 158 | - 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 159 | - 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 160 | - ); |
|
| 156 | + $filter_links[] = array( |
|
| 157 | + 'id'=>'free', |
|
| 158 | + 'url'=> add_query_arg( array( 'course_filter'=>'free'), Sensei_Course::get_courses_page_url() ), |
|
| 159 | + 'title'=>__( 'Free', 'woothemes-sensei' ) |
|
| 160 | + ); |
|
| 161 | 161 | |
| 162 | - return $filter_links; |
|
| 162 | + return $filter_links; |
|
| 163 | 163 | |
| 164 | - }// end add_course_archive_wc_filter_links |
|
| 164 | + }// end add_course_archive_wc_filter_links |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Apply the free filter the the course query |
|
| 168 | - * getting all course with no products or products with zero price |
|
| 169 | - * |
|
| 170 | - * hooked into pre_get_posts |
|
| 171 | - * |
|
| 172 | - * @since 1.9.0 |
|
| 173 | - * @param WP_Query $query |
|
| 174 | - * @return WP_Query $query |
|
| 175 | - */ |
|
| 176 | - public static function course_archive_wc_filter_free( $query ){ |
|
| 166 | + /** |
|
| 167 | + * Apply the free filter the the course query |
|
| 168 | + * getting all course with no products or products with zero price |
|
| 169 | + * |
|
| 170 | + * hooked into pre_get_posts |
|
| 171 | + * |
|
| 172 | + * @since 1.9.0 |
|
| 173 | + * @param WP_Query $query |
|
| 174 | + * @return WP_Query $query |
|
| 175 | + */ |
|
| 176 | + public static function course_archive_wc_filter_free( $query ){ |
|
| 177 | 177 | |
| 178 | - if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 178 | + if( isset( $_GET['course_filter'] ) && 'free' == $_GET['course_filter'] |
|
| 179 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 180 | 180 | |
| 181 | - // setup the course meta query |
|
| 182 | - $meta_query = self::get_free_courses_meta_query_args(); |
|
| 181 | + // setup the course meta query |
|
| 182 | + $meta_query = self::get_free_courses_meta_query_args(); |
|
| 183 | 183 | |
| 184 | - // manipulate the query to return free courses |
|
| 185 | - $query->set('meta_query', $meta_query ); |
|
| 184 | + // manipulate the query to return free courses |
|
| 185 | + $query->set('meta_query', $meta_query ); |
|
| 186 | 186 | |
| 187 | - // don't show any paid courses |
|
| 188 | - $courses = self::get_paid_courses(); |
|
| 189 | - $ids = array(); |
|
| 190 | - foreach( $courses as $course ){ |
|
| 191 | - $ids[] = $course->ID; |
|
| 192 | - } |
|
| 193 | - $query->set( 'post__not_in', $ids ); |
|
| 187 | + // don't show any paid courses |
|
| 188 | + $courses = self::get_paid_courses(); |
|
| 189 | + $ids = array(); |
|
| 190 | + foreach( $courses as $course ){ |
|
| 191 | + $ids[] = $course->ID; |
|
| 192 | + } |
|
| 193 | + $query->set( 'post__not_in', $ids ); |
|
| 194 | 194 | |
| 195 | - }// end if course_filter |
|
| 195 | + }// end if course_filter |
|
| 196 | 196 | |
| 197 | - return $query; |
|
| 197 | + return $query; |
|
| 198 | 198 | |
| 199 | - }// course_archive_wc_filter_free |
|
| 199 | + }// course_archive_wc_filter_free |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Apply the paid filter to the course query on the courses page |
|
| 203 | - * will include all course with a product attached with a price |
|
| 204 | - * more than 0 |
|
| 205 | - * |
|
| 206 | - * hooked into pre_get_posts |
|
| 207 | - * |
|
| 208 | - * @since 1.9.0 |
|
| 209 | - * @param WP_Query $query |
|
| 210 | - * @return WP_Query $query |
|
| 211 | - */ |
|
| 212 | - public static function course_archive_wc_filter_paid( $query ){ |
|
| 201 | + /** |
|
| 202 | + * Apply the paid filter to the course query on the courses page |
|
| 203 | + * will include all course with a product attached with a price |
|
| 204 | + * more than 0 |
|
| 205 | + * |
|
| 206 | + * hooked into pre_get_posts |
|
| 207 | + * |
|
| 208 | + * @since 1.9.0 |
|
| 209 | + * @param WP_Query $query |
|
| 210 | + * @return WP_Query $query |
|
| 211 | + */ |
|
| 212 | + public static function course_archive_wc_filter_paid( $query ){ |
|
| 213 | 213 | |
| 214 | - if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | - && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 216 | - |
|
| 217 | - // setup the course meta query |
|
| 218 | - $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 219 | - |
|
| 220 | - // manipulate the query to return free courses |
|
| 221 | - $query->set('meta_query', $meta_query ); |
|
| 222 | - |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $query; |
|
| 226 | - |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Load the WooCommerce single product actions above |
|
| 231 | - * single courses if woocommerce is active allowing purchase |
|
| 232 | - * information and actions to be hooked from WooCommerce. |
|
| 233 | - */ |
|
| 234 | - public static function do_single_course_wc_single_product_action(){ |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * this hooks is documented within the WooCommerce plugin. |
|
| 238 | - */ |
|
| 239 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 240 | - |
|
| 241 | - do_action( 'woocommerce_before_single_product' ); |
|
| 242 | - |
|
| 243 | - } // End If Statement |
|
| 244 | - |
|
| 245 | - }// end do_single_course_wc_single_product_action |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Hooking into the single lesson page to alter the |
|
| 249 | - * user access permissions based on if they have purchased the |
|
| 250 | - * course the lesson belongs to. |
|
| 251 | - * |
|
| 252 | - * This function will only return false or the passed in user_access value. |
|
| 253 | - * It doesn't return true in order to avoid altering other options. |
|
| 254 | - * |
|
| 255 | - * @since 1.9.0 |
|
| 256 | - * |
|
| 257 | - * @param $can_user_view_lesson |
|
| 258 | - * @param $lesson_id |
|
| 259 | - * @param $user_id |
|
| 260 | - * @return bool |
|
| 261 | - */ |
|
| 262 | - public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 263 | - |
|
| 264 | - // check if the course has a valid product attached to it |
|
| 265 | - // which the user should have purchased if they want to access |
|
| 266 | - // the current lesson |
|
| 267 | - $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 269 | - $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 270 | - if( isset ($product) && is_object($product) ){ |
|
| 271 | - |
|
| 272 | - // valid product found |
|
| 273 | - $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 274 | - |
|
| 275 | - // product has a successful order so this user may access the content |
|
| 276 | - // this function may only return false or the default |
|
| 277 | - // returning true may override other negatives which we don't want |
|
| 278 | - if( ! $order_id ){ |
|
| 279 | - |
|
| 280 | - return false; |
|
| 281 | - |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - // return the passed in value |
|
| 287 | - return $can_user_view_lesson; |
|
| 288 | - |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * Add course link to order thank you and details pages. |
|
| 293 | - * |
|
| 294 | - * @since 1.4.5 |
|
| 295 | - * @access public |
|
| 296 | - * |
|
| 297 | - * @return void |
|
| 298 | - */ |
|
| 299 | - public static function course_link_from_order( ) { |
|
| 300 | - |
|
| 301 | - if( ! is_order_received_page() ){ |
|
| 302 | - return; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $order_id = get_query_var( 'order-received' ); |
|
| 214 | + if( isset( $_GET['course_filter'] ) && 'paid' == $_GET['course_filter'] |
|
| 215 | + && 'course' == $query->get( 'post_type') && $query->is_main_query() ){ |
|
| 216 | + |
|
| 217 | + // setup the course meta query |
|
| 218 | + $meta_query = self::get_paid_courses_meta_query_args(); |
|
| 219 | + |
|
| 220 | + // manipulate the query to return free courses |
|
| 221 | + $query->set('meta_query', $meta_query ); |
|
| 222 | + |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $query; |
|
| 226 | + |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Load the WooCommerce single product actions above |
|
| 231 | + * single courses if woocommerce is active allowing purchase |
|
| 232 | + * information and actions to be hooked from WooCommerce. |
|
| 233 | + */ |
|
| 234 | + public static function do_single_course_wc_single_product_action(){ |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * this hooks is documented within the WooCommerce plugin. |
|
| 238 | + */ |
|
| 239 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 240 | + |
|
| 241 | + do_action( 'woocommerce_before_single_product' ); |
|
| 242 | + |
|
| 243 | + } // End If Statement |
|
| 244 | + |
|
| 245 | + }// end do_single_course_wc_single_product_action |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Hooking into the single lesson page to alter the |
|
| 249 | + * user access permissions based on if they have purchased the |
|
| 250 | + * course the lesson belongs to. |
|
| 251 | + * |
|
| 252 | + * This function will only return false or the passed in user_access value. |
|
| 253 | + * It doesn't return true in order to avoid altering other options. |
|
| 254 | + * |
|
| 255 | + * @since 1.9.0 |
|
| 256 | + * |
|
| 257 | + * @param $can_user_view_lesson |
|
| 258 | + * @param $lesson_id |
|
| 259 | + * @param $user_id |
|
| 260 | + * @return bool |
|
| 261 | + */ |
|
| 262 | + public static function alter_can_user_view_lesson ( $can_user_view_lesson, $lesson_id, $user_id ){ |
|
| 263 | + |
|
| 264 | + // check if the course has a valid product attached to it |
|
| 265 | + // which the user should have purchased if they want to access |
|
| 266 | + // the current lesson |
|
| 267 | + $course_id = get_post_meta( $lesson_id , '_lesson_course', true); |
|
| 268 | + $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 269 | + $product = Sensei()->sensei_get_woocommerce_product_object($wc_post_id); |
|
| 270 | + if( isset ($product) && is_object($product) ){ |
|
| 271 | + |
|
| 272 | + // valid product found |
|
| 273 | + $order_id = self::get_learner_course_active_order_id( $user_id, $course_id ); |
|
| 274 | + |
|
| 275 | + // product has a successful order so this user may access the content |
|
| 276 | + // this function may only return false or the default |
|
| 277 | + // returning true may override other negatives which we don't want |
|
| 278 | + if( ! $order_id ){ |
|
| 279 | + |
|
| 280 | + return false; |
|
| 281 | + |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + // return the passed in value |
|
| 287 | + return $can_user_view_lesson; |
|
| 288 | + |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * Add course link to order thank you and details pages. |
|
| 293 | + * |
|
| 294 | + * @since 1.4.5 |
|
| 295 | + * @access public |
|
| 296 | + * |
|
| 297 | + * @return void |
|
| 298 | + */ |
|
| 299 | + public static function course_link_from_order( ) { |
|
| 300 | + |
|
| 301 | + if( ! is_order_received_page() ){ |
|
| 302 | + return; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $order_id = get_query_var( 'order-received' ); |
|
| 306 | 306 | $order = new WC_Order( $order_id ); |
| 307 | 307 | |
| 308 | 308 | // exit early if not wc-completed or wc-processing |
| 309 | 309 | if( 'wc-completed' != $order->post_status |
| 310 | - && 'wc-processing' != $order->post_status ) { |
|
| 311 | - return; |
|
| 312 | - } |
|
| 310 | + && 'wc-processing' != $order->post_status ) { |
|
| 311 | + return; |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - $course_links = array(); // store the for links for courses purchased |
|
| 314 | + $course_links = array(); // store the for links for courses purchased |
|
| 315 | 315 | foreach ( $order->get_items() as $item ) { |
| 316 | 316 | |
| 317 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 317 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 318 | 318 | |
| 319 | - // If item has variation_id then its a variation of the product |
|
| 320 | - $item_id = $item['variation_id']; |
|
| 319 | + // If item has variation_id then its a variation of the product |
|
| 320 | + $item_id = $item['variation_id']; |
|
| 321 | 321 | |
| 322 | - } else { |
|
| 322 | + } else { |
|
| 323 | 323 | |
| 324 | - //If not its real product set its id to item_id |
|
| 325 | - $item_id = $item['product_id']; |
|
| 324 | + //If not its real product set its id to item_id |
|
| 325 | + $item_id = $item['product_id']; |
|
| 326 | 326 | |
| 327 | - } // End If Statement |
|
| 327 | + } // End If Statement |
|
| 328 | 328 | |
| 329 | - $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 329 | + $user_id = get_post_meta( $order->id, '_customer_user', true ); |
|
| 330 | 330 | |
| 331 | - if( $user_id ) { |
|
| 331 | + if( $user_id ) { |
|
| 332 | 332 | |
| 333 | - // Get all courses for product |
|
| 334 | - $args = Sensei_Course::get_default_query_args(); |
|
| 335 | - $args['meta_query'] = array( array( |
|
| 336 | - 'key' => '_course_woocommerce_product', |
|
| 337 | - 'value' => $item_id |
|
| 338 | - ) ); |
|
| 339 | - $args['orderby'] = 'menu_order date'; |
|
| 340 | - $args['order'] = 'ASC'; |
|
| 333 | + // Get all courses for product |
|
| 334 | + $args = Sensei_Course::get_default_query_args(); |
|
| 335 | + $args['meta_query'] = array( array( |
|
| 336 | + 'key' => '_course_woocommerce_product', |
|
| 337 | + 'value' => $item_id |
|
| 338 | + ) ); |
|
| 339 | + $args['orderby'] = 'menu_order date'; |
|
| 340 | + $args['order'] = 'ASC'; |
|
| 341 | 341 | |
| 342 | - // loop through courses |
|
| 343 | - $courses = get_posts( $args ); |
|
| 344 | - if( $courses && count( $courses ) > 0 ) { |
|
| 342 | + // loop through courses |
|
| 343 | + $courses = get_posts( $args ); |
|
| 344 | + if( $courses && count( $courses ) > 0 ) { |
|
| 345 | 345 | |
| 346 | - foreach( $courses as $course ) { |
|
| 346 | + foreach( $courses as $course ) { |
|
| 347 | 347 | |
| 348 | - $title = $course->post_title; |
|
| 349 | - $permalink = get_permalink( $course->ID ); |
|
| 350 | - $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 348 | + $title = $course->post_title; |
|
| 349 | + $permalink = get_permalink( $course->ID ); |
|
| 350 | + $course_links[] .= '<a href="' . esc_url( $permalink ) . '" >' . $title . '</a> '; |
|
| 351 | 351 | |
| 352 | - } // end for each |
|
| 352 | + } // end for each |
|
| 353 | 353 | |
| 354 | - // close the message div |
|
| 354 | + // close the message div |
|
| 355 | 355 | |
| 356 | - }// end if $courses check |
|
| 357 | - } |
|
| 358 | - }// end loop through orders |
|
| 356 | + }// end if $courses check |
|
| 357 | + } |
|
| 358 | + }// end loop through orders |
|
| 359 | 359 | |
| 360 | - // add the courses to the WooCommerce notice |
|
| 361 | - if( ! empty( $course_links) ){ |
|
| 360 | + // add the courses to the WooCommerce notice |
|
| 361 | + if( ! empty( $course_links) ){ |
|
| 362 | 362 | |
| 363 | - $courses_html = _nx( |
|
| 364 | - 'You have purchased the following course:', |
|
| 365 | - 'You have purchased the following courses:', |
|
| 366 | - count( $course_links ), |
|
| 367 | - 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 368 | - ); |
|
| 363 | + $courses_html = _nx( |
|
| 364 | + 'You have purchased the following course:', |
|
| 365 | + 'You have purchased the following courses:', |
|
| 366 | + count( $course_links ), |
|
| 367 | + 'Purchase thank you note on Checkout page. The course link(s) will be show', 'woothemes-sensei' |
|
| 368 | + ); |
|
| 369 | 369 | |
| 370 | - foreach( $course_links as $link ){ |
|
| 370 | + foreach( $course_links as $link ){ |
|
| 371 | 371 | |
| 372 | - $courses_html .= '<li>' . $link . '</li>'; |
|
| 372 | + $courses_html .= '<li>' . $link . '</li>'; |
|
| 373 | 373 | |
| 374 | - } |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - $courses_html .= ' </ul>'; |
|
| 376 | + $courses_html .= ' </ul>'; |
|
| 377 | 377 | |
| 378 | - wc_add_notice( $courses_html, 'success' ); |
|
| 379 | - } |
|
| 378 | + wc_add_notice( $courses_html, 'success' ); |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | 381 | } // end course_link_order_form |
| 382 | 382 | |
| 383 | - /** |
|
| 384 | - * Show the message that a user should complete |
|
| 385 | - * their purchase if the course is in the cart |
|
| 386 | - * |
|
| 387 | - * This should be used within the course loop or single course page |
|
| 388 | - * |
|
| 389 | - * @since 1.9.0 |
|
| 390 | - */ |
|
| 391 | - public static function course_in_cart_message(){ |
|
| 383 | + /** |
|
| 384 | + * Show the message that a user should complete |
|
| 385 | + * their purchase if the course is in the cart |
|
| 386 | + * |
|
| 387 | + * This should be used within the course loop or single course page |
|
| 388 | + * |
|
| 389 | + * @since 1.9.0 |
|
| 390 | + */ |
|
| 391 | + public static function course_in_cart_message(){ |
|
| 392 | 392 | |
| 393 | - global $post; |
|
| 393 | + global $post; |
|
| 394 | 394 | |
| 395 | - if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 395 | + if( self::is_course_in_cart( $post->ID ) ){ ?> |
|
| 396 | 396 | |
| 397 | 397 | <div class="sensei-message info"> |
| 398 | 398 | <?php |
| 399 | 399 | |
| 400 | - $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | - . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | - . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 400 | + $cart_link = '<a class="cart-complete" href="' . WC()->cart->get_checkout_url() |
|
| 401 | + . '" title="' . __('complete purchase', 'woothemes-sensei') . '">' |
|
| 402 | + . __('complete the purchase', 'woothemes-sensei') . '</a>'; |
|
| 403 | 403 | |
| 404 | - echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 404 | + echo sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei'), $cart_link ); |
|
| 405 | 405 | |
| 406 | - ?> |
|
| 406 | + ?> |
|
| 407 | 407 | </div> |
| 408 | 408 | <?php } |
| 409 | 409 | |
| 410 | - } // End sensei_woocommerce_in_cart_message() |
|
| 410 | + } // End sensei_woocommerce_in_cart_message() |
|
| 411 | 411 | |
| 412 | - /** |
|
| 413 | - * Checks the cart to see if a course is in the cart. |
|
| 414 | - * |
|
| 415 | - * @param $course_id |
|
| 416 | - * @return bool |
|
| 417 | - */ |
|
| 418 | - public static function is_course_in_cart( $course_id ){ |
|
| 419 | - |
|
| 420 | - $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | - $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 422 | - |
|
| 423 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 424 | - |
|
| 425 | - if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 426 | - |
|
| 427 | - return true; |
|
| 428 | - |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - return false; |
|
| 434 | - |
|
| 435 | - }// is_course_in_cart |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Check the cart to see if the product is in the cart |
|
| 439 | - * |
|
| 440 | - * @param $product_id |
|
| 441 | - * @return bool |
|
| 442 | - */ |
|
| 443 | - public static function is_product_in_cart( $product_id ){ |
|
| 444 | - |
|
| 445 | - if ( 0 < $product_id ) { |
|
| 446 | - |
|
| 447 | - $product = wc_get_product( $product_id ); |
|
| 448 | - |
|
| 449 | - $parent_id = ''; |
|
| 450 | - if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 451 | - $wc_product_id = $product->parent->id; |
|
| 452 | - } |
|
| 453 | - foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 454 | - |
|
| 455 | - $cart_product = $values['data']; |
|
| 456 | - if( $product_id == $cart_product->id ) { |
|
| 457 | - |
|
| 458 | - return true; |
|
| 459 | - |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - } |
|
| 463 | - } // End If Statement |
|
| 464 | - |
|
| 465 | - return false; |
|
| 466 | - |
|
| 467 | - } // end is_product_in_car |
|
| 468 | - |
|
| 469 | - /** |
|
| 470 | - * Get all free WooCommerce products |
|
| 471 | - * |
|
| 472 | - * @since 1.9.0 |
|
| 473 | - * |
|
| 474 | - * @return array $free_products{ |
|
| 475 | - * @type int $wp_post_id |
|
| 476 | - * } |
|
| 477 | - */ |
|
| 478 | - public static function get_free_product_ids(){ |
|
| 479 | - |
|
| 480 | - return get_posts( array( |
|
| 481 | - 'post_type' => 'product', |
|
| 482 | - 'posts_per_page' => '1000', |
|
| 483 | - 'fields' => 'ids', |
|
| 484 | - 'meta_query'=> array( |
|
| 485 | - 'relation' => 'OR', |
|
| 486 | - array( |
|
| 487 | - 'key'=> '_regular_price', |
|
| 488 | - 'value' => 0, |
|
| 489 | - ), |
|
| 490 | - array( |
|
| 491 | - 'key'=> '_sale_price', |
|
| 492 | - 'value' => 0, |
|
| 493 | - ), |
|
| 494 | - ), |
|
| 495 | - )); |
|
| 496 | - |
|
| 497 | - }// end get free product query |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * The metat query for courses that are free |
|
| 501 | - * |
|
| 502 | - * @since 1.9.0 |
|
| 503 | - * @return array $wp_meta_query_param |
|
| 504 | - */ |
|
| 505 | - public static function get_free_courses_meta_query_args(){ |
|
| 506 | - |
|
| 507 | - return array( |
|
| 508 | - 'relation' => 'OR', |
|
| 509 | - array( |
|
| 510 | - 'key' => '_course_woocommerce_product', |
|
| 511 | - 'value' => '-', |
|
| 512 | - 'compare' => '=', |
|
| 513 | - ), |
|
| 514 | - array( |
|
| 515 | - 'key' => '_course_woocommerce_product', |
|
| 516 | - 'value' => self::get_free_product_ids(), |
|
| 517 | - 'compare' => 'IN', |
|
| 518 | - ), |
|
| 519 | - ); |
|
| 520 | - |
|
| 521 | - }// get_free_courses_meta_query |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * The metat query for courses that are free |
|
| 525 | - * |
|
| 526 | - * @since 1.9.0 |
|
| 527 | - * @return array $wp_query_meta_query_args_param |
|
| 528 | - */ |
|
| 529 | - public static function get_paid_courses_meta_query_args(){ |
|
| 530 | - |
|
| 531 | - $paid_product_ids = self::get_paid_product_ids(); |
|
| 532 | - |
|
| 533 | - return array( |
|
| 534 | - array( |
|
| 535 | - 'key' => '_course_woocommerce_product', |
|
| 536 | - // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 537 | - // query |
|
| 538 | - 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 539 | - 'compare' => 'IN', |
|
| 540 | - ), |
|
| 541 | - ); |
|
| 542 | - |
|
| 543 | - }// get_free_courses_meta_query |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * The WordPress Query args |
|
| 547 | - * for paid products on sale |
|
| 548 | - * |
|
| 549 | - * @since 1.9.0 |
|
| 550 | - * @return array $product_query_args |
|
| 551 | - */ |
|
| 552 | - public static function get_paid_products_on_sale_query_args(){ |
|
| 553 | - |
|
| 554 | - $args = array( |
|
| 555 | - 'post_type' => 'product', |
|
| 556 | - 'posts_per_page' => 1000, |
|
| 557 | - 'orderby' => 'date', |
|
| 558 | - 'order' => 'DESC', |
|
| 559 | - 'suppress_filters' => 0 |
|
| 560 | - ); |
|
| 561 | - |
|
| 562 | - $args[ 'fields' ] = 'ids'; |
|
| 563 | - |
|
| 564 | - $args[ 'meta_query' ] = array( |
|
| 565 | - 'relation' => 'AND', |
|
| 566 | - array( |
|
| 567 | - 'key'=> '_regular_price', |
|
| 568 | - 'compare' => '>', |
|
| 569 | - 'value' => 0, |
|
| 570 | - ), |
|
| 571 | - array( |
|
| 572 | - 'key'=> '_sale_price', |
|
| 573 | - 'compare' => '>', |
|
| 574 | - 'value' => 0, |
|
| 575 | - ), |
|
| 576 | - ); |
|
| 577 | - |
|
| 578 | - return $args; |
|
| 579 | - |
|
| 580 | - } // get_paid_products_on_sale_query_args |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Return the WordPress query args for |
|
| 585 | - * products not on sale but that is not a free |
|
| 586 | - * |
|
| 587 | - * @since 1.9.0 |
|
| 588 | - * |
|
| 589 | - * @return array |
|
| 590 | - */ |
|
| 591 | - public static function get_paid_products_not_on_sale_query_args(){ |
|
| 592 | - |
|
| 593 | - $args = array( |
|
| 594 | - 'post_type' => 'product', |
|
| 595 | - 'posts_per_page' => 1000, |
|
| 596 | - 'orderby' => 'date', |
|
| 597 | - 'order' => 'DESC', |
|
| 598 | - 'suppress_filters' => 0 |
|
| 599 | - ); |
|
| 600 | - |
|
| 601 | - $args[ 'fields' ] = 'ids'; |
|
| 602 | - $args[ 'meta_query' ] = array( |
|
| 603 | - 'relation' => 'AND', |
|
| 604 | - array( |
|
| 605 | - 'key'=> '_regular_price', |
|
| 606 | - 'compare' => '>', |
|
| 607 | - 'value' => 0, |
|
| 608 | - ), |
|
| 609 | - array( |
|
| 610 | - 'key'=> '_sale_price', |
|
| 611 | - 'compare' => '=', |
|
| 612 | - 'value' => '', |
|
| 613 | - ), |
|
| 614 | - ); |
|
| 615 | - |
|
| 616 | - return $args; |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - } // get_paid_courses_meta_query |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Get all WooCommerce non-free product id's |
|
| 623 | - * |
|
| 624 | - * @since 1.9.0 |
|
| 625 | - * |
|
| 626 | - * @return array $woocommerce_paid_product_ids |
|
| 627 | - */ |
|
| 628 | - public static function get_paid_product_ids(){ |
|
| 629 | - |
|
| 630 | - // get all the paid WooCommerce products that has regular |
|
| 631 | - // and sale price greater than 0 |
|
| 632 | - // will be used later to check for course with the id as meta |
|
| 633 | - $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 634 | - |
|
| 635 | - // get all the paid WooCommerce products that has regular price |
|
| 636 | - // greater than 0 without a sale price |
|
| 637 | - // will be used later to check for course with the id as meta |
|
| 638 | - $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 639 | - |
|
| 640 | - // combine products ID's with regular and sale price grater than zero and those without |
|
| 641 | - // sale but regular price greater than zero |
|
| 642 | - $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 643 | - |
|
| 644 | - // if |
|
| 645 | - if( empty($woocommerce_paid_product_ids) ){ |
|
| 646 | - return array( ); |
|
| 647 | - } |
|
| 648 | - return $woocommerce_paid_product_ids; |
|
| 649 | - |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - /** |
|
| 653 | - * Get all free courses. |
|
| 654 | - * |
|
| 655 | - * This course that have a WC product attached |
|
| 656 | - * that has a price or sale price of zero and |
|
| 657 | - * other courses with no WooCommerce products |
|
| 658 | - * attached. |
|
| 659 | - * |
|
| 660 | - * @since 1.9.0 |
|
| 661 | - * |
|
| 662 | - * @return array |
|
| 663 | - */ |
|
| 664 | - public static function get_free_courses(){ |
|
| 665 | - |
|
| 666 | - $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 667 | - $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 668 | - |
|
| 669 | - // don't show any paid courses |
|
| 670 | - $courses = self::get_paid_courses(); |
|
| 671 | - $ids = array(); |
|
| 672 | - foreach( $courses as $course ){ |
|
| 673 | - $ids[] = $course->ID; |
|
| 674 | - } |
|
| 675 | - $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 676 | - |
|
| 677 | - return get_posts( $free_course_query_args ); |
|
| 678 | - |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Return all products that are not free |
|
| 683 | - * |
|
| 684 | - * @since 1.9.0 |
|
| 685 | - * @return array |
|
| 686 | - */ |
|
| 687 | - public static function get_paid_courses(){ |
|
| 688 | - |
|
| 689 | - $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 690 | - |
|
| 691 | - $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 692 | - |
|
| 693 | - return get_posts( $paid_course_query_args ); |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Show the WooCommerce add to cart button for the current course |
|
| 698 | - * |
|
| 699 | - * The function will only show the button if |
|
| 700 | - * 1- the user can buy the course |
|
| 701 | - * 2- if they have completed their pre-requisite |
|
| 702 | - * 3- if the course has a valid product attached |
|
| 703 | - * |
|
| 704 | - * @since 1.9.0 |
|
| 705 | - * @param int $course_id |
|
| 706 | - * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 707 | - */ |
|
| 708 | - public static function the_add_to_cart_button_html( $course_id ){ |
|
| 709 | - |
|
| 710 | - if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 711 | - return ''; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 715 | - |
|
| 716 | - // Check if customer purchased the product |
|
| 717 | - if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | - || empty( $wc_post_id ) ) { |
|
| 719 | - |
|
| 720 | - return ''; |
|
| 721 | - |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 725 | - // Get the product |
|
| 726 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 727 | - |
|
| 728 | - // do not show the button for invalid products, non purchasable products, out |
|
| 729 | - // of stock product or if course is already in cart |
|
| 730 | - if ( ! isset ( $product ) |
|
| 731 | - || ! is_object( $product ) |
|
| 732 | - || ! $product->is_purchasable() |
|
| 733 | - || ! $product->is_in_stock() |
|
| 734 | - || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 735 | - |
|
| 736 | - return ''; |
|
| 737 | - |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - // |
|
| 741 | - // button output: |
|
| 742 | - // |
|
| 743 | - ?> |
|
| 412 | + /** |
|
| 413 | + * Checks the cart to see if a course is in the cart. |
|
| 414 | + * |
|
| 415 | + * @param $course_id |
|
| 416 | + * @return bool |
|
| 417 | + */ |
|
| 418 | + public static function is_course_in_cart( $course_id ){ |
|
| 419 | + |
|
| 420 | + $wc_post_id = absint( get_post_meta( $course_id, '_course_woocommerce_product', true ) ); |
|
| 421 | + $user_course_status_id = Sensei_Utils::user_started_course( $course_id , get_current_user_id() ); |
|
| 422 | + |
|
| 423 | + if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 424 | + |
|
| 425 | + if ( self::is_product_in_cart( $wc_post_id ) ) { |
|
| 426 | + |
|
| 427 | + return true; |
|
| 428 | + |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + return false; |
|
| 434 | + |
|
| 435 | + }// is_course_in_cart |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Check the cart to see if the product is in the cart |
|
| 439 | + * |
|
| 440 | + * @param $product_id |
|
| 441 | + * @return bool |
|
| 442 | + */ |
|
| 443 | + public static function is_product_in_cart( $product_id ){ |
|
| 444 | + |
|
| 445 | + if ( 0 < $product_id ) { |
|
| 446 | + |
|
| 447 | + $product = wc_get_product( $product_id ); |
|
| 448 | + |
|
| 449 | + $parent_id = ''; |
|
| 450 | + if( isset( $product->variation_id ) && 0 < intval( $product->variation_id ) ) { |
|
| 451 | + $wc_product_id = $product->parent->id; |
|
| 452 | + } |
|
| 453 | + foreach( WC()->cart->get_cart() as $cart_item_key => $values ) { |
|
| 454 | + |
|
| 455 | + $cart_product = $values['data']; |
|
| 456 | + if( $product_id == $cart_product->id ) { |
|
| 457 | + |
|
| 458 | + return true; |
|
| 459 | + |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + } |
|
| 463 | + } // End If Statement |
|
| 464 | + |
|
| 465 | + return false; |
|
| 466 | + |
|
| 467 | + } // end is_product_in_car |
|
| 468 | + |
|
| 469 | + /** |
|
| 470 | + * Get all free WooCommerce products |
|
| 471 | + * |
|
| 472 | + * @since 1.9.0 |
|
| 473 | + * |
|
| 474 | + * @return array $free_products{ |
|
| 475 | + * @type int $wp_post_id |
|
| 476 | + * } |
|
| 477 | + */ |
|
| 478 | + public static function get_free_product_ids(){ |
|
| 479 | + |
|
| 480 | + return get_posts( array( |
|
| 481 | + 'post_type' => 'product', |
|
| 482 | + 'posts_per_page' => '1000', |
|
| 483 | + 'fields' => 'ids', |
|
| 484 | + 'meta_query'=> array( |
|
| 485 | + 'relation' => 'OR', |
|
| 486 | + array( |
|
| 487 | + 'key'=> '_regular_price', |
|
| 488 | + 'value' => 0, |
|
| 489 | + ), |
|
| 490 | + array( |
|
| 491 | + 'key'=> '_sale_price', |
|
| 492 | + 'value' => 0, |
|
| 493 | + ), |
|
| 494 | + ), |
|
| 495 | + )); |
|
| 496 | + |
|
| 497 | + }// end get free product query |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * The metat query for courses that are free |
|
| 501 | + * |
|
| 502 | + * @since 1.9.0 |
|
| 503 | + * @return array $wp_meta_query_param |
|
| 504 | + */ |
|
| 505 | + public static function get_free_courses_meta_query_args(){ |
|
| 506 | + |
|
| 507 | + return array( |
|
| 508 | + 'relation' => 'OR', |
|
| 509 | + array( |
|
| 510 | + 'key' => '_course_woocommerce_product', |
|
| 511 | + 'value' => '-', |
|
| 512 | + 'compare' => '=', |
|
| 513 | + ), |
|
| 514 | + array( |
|
| 515 | + 'key' => '_course_woocommerce_product', |
|
| 516 | + 'value' => self::get_free_product_ids(), |
|
| 517 | + 'compare' => 'IN', |
|
| 518 | + ), |
|
| 519 | + ); |
|
| 520 | + |
|
| 521 | + }// get_free_courses_meta_query |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * The metat query for courses that are free |
|
| 525 | + * |
|
| 526 | + * @since 1.9.0 |
|
| 527 | + * @return array $wp_query_meta_query_args_param |
|
| 528 | + */ |
|
| 529 | + public static function get_paid_courses_meta_query_args(){ |
|
| 530 | + |
|
| 531 | + $paid_product_ids = self::get_paid_product_ids(); |
|
| 532 | + |
|
| 533 | + return array( |
|
| 534 | + array( |
|
| 535 | + 'key' => '_course_woocommerce_product', |
|
| 536 | + // when empty we give a false post_id to ensure the caller doesn't get any courses for their |
|
| 537 | + // query |
|
| 538 | + 'value' => empty( $paid_product_ids )? '-1000' : $paid_product_ids, |
|
| 539 | + 'compare' => 'IN', |
|
| 540 | + ), |
|
| 541 | + ); |
|
| 542 | + |
|
| 543 | + }// get_free_courses_meta_query |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * The WordPress Query args |
|
| 547 | + * for paid products on sale |
|
| 548 | + * |
|
| 549 | + * @since 1.9.0 |
|
| 550 | + * @return array $product_query_args |
|
| 551 | + */ |
|
| 552 | + public static function get_paid_products_on_sale_query_args(){ |
|
| 553 | + |
|
| 554 | + $args = array( |
|
| 555 | + 'post_type' => 'product', |
|
| 556 | + 'posts_per_page' => 1000, |
|
| 557 | + 'orderby' => 'date', |
|
| 558 | + 'order' => 'DESC', |
|
| 559 | + 'suppress_filters' => 0 |
|
| 560 | + ); |
|
| 561 | + |
|
| 562 | + $args[ 'fields' ] = 'ids'; |
|
| 563 | + |
|
| 564 | + $args[ 'meta_query' ] = array( |
|
| 565 | + 'relation' => 'AND', |
|
| 566 | + array( |
|
| 567 | + 'key'=> '_regular_price', |
|
| 568 | + 'compare' => '>', |
|
| 569 | + 'value' => 0, |
|
| 570 | + ), |
|
| 571 | + array( |
|
| 572 | + 'key'=> '_sale_price', |
|
| 573 | + 'compare' => '>', |
|
| 574 | + 'value' => 0, |
|
| 575 | + ), |
|
| 576 | + ); |
|
| 577 | + |
|
| 578 | + return $args; |
|
| 579 | + |
|
| 580 | + } // get_paid_products_on_sale_query_args |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Return the WordPress query args for |
|
| 585 | + * products not on sale but that is not a free |
|
| 586 | + * |
|
| 587 | + * @since 1.9.0 |
|
| 588 | + * |
|
| 589 | + * @return array |
|
| 590 | + */ |
|
| 591 | + public static function get_paid_products_not_on_sale_query_args(){ |
|
| 592 | + |
|
| 593 | + $args = array( |
|
| 594 | + 'post_type' => 'product', |
|
| 595 | + 'posts_per_page' => 1000, |
|
| 596 | + 'orderby' => 'date', |
|
| 597 | + 'order' => 'DESC', |
|
| 598 | + 'suppress_filters' => 0 |
|
| 599 | + ); |
|
| 600 | + |
|
| 601 | + $args[ 'fields' ] = 'ids'; |
|
| 602 | + $args[ 'meta_query' ] = array( |
|
| 603 | + 'relation' => 'AND', |
|
| 604 | + array( |
|
| 605 | + 'key'=> '_regular_price', |
|
| 606 | + 'compare' => '>', |
|
| 607 | + 'value' => 0, |
|
| 608 | + ), |
|
| 609 | + array( |
|
| 610 | + 'key'=> '_sale_price', |
|
| 611 | + 'compare' => '=', |
|
| 612 | + 'value' => '', |
|
| 613 | + ), |
|
| 614 | + ); |
|
| 615 | + |
|
| 616 | + return $args; |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + } // get_paid_courses_meta_query |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Get all WooCommerce non-free product id's |
|
| 623 | + * |
|
| 624 | + * @since 1.9.0 |
|
| 625 | + * |
|
| 626 | + * @return array $woocommerce_paid_product_ids |
|
| 627 | + */ |
|
| 628 | + public static function get_paid_product_ids(){ |
|
| 629 | + |
|
| 630 | + // get all the paid WooCommerce products that has regular |
|
| 631 | + // and sale price greater than 0 |
|
| 632 | + // will be used later to check for course with the id as meta |
|
| 633 | + $paid_product_ids_with_sale = get_posts( self::get_paid_products_on_sale_query_args() ); |
|
| 634 | + |
|
| 635 | + // get all the paid WooCommerce products that has regular price |
|
| 636 | + // greater than 0 without a sale price |
|
| 637 | + // will be used later to check for course with the id as meta |
|
| 638 | + $paid_product_ids_without_sale = get_posts( self::get_paid_products_not_on_sale_query_args() ); |
|
| 639 | + |
|
| 640 | + // combine products ID's with regular and sale price grater than zero and those without |
|
| 641 | + // sale but regular price greater than zero |
|
| 642 | + $woocommerce_paid_product_ids = array_merge( $paid_product_ids_with_sale, $paid_product_ids_without_sale ); |
|
| 643 | + |
|
| 644 | + // if |
|
| 645 | + if( empty($woocommerce_paid_product_ids) ){ |
|
| 646 | + return array( ); |
|
| 647 | + } |
|
| 648 | + return $woocommerce_paid_product_ids; |
|
| 649 | + |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + /** |
|
| 653 | + * Get all free courses. |
|
| 654 | + * |
|
| 655 | + * This course that have a WC product attached |
|
| 656 | + * that has a price or sale price of zero and |
|
| 657 | + * other courses with no WooCommerce products |
|
| 658 | + * attached. |
|
| 659 | + * |
|
| 660 | + * @since 1.9.0 |
|
| 661 | + * |
|
| 662 | + * @return array |
|
| 663 | + */ |
|
| 664 | + public static function get_free_courses(){ |
|
| 665 | + |
|
| 666 | + $free_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 667 | + $free_course_query_args[ 'meta_query' ] = self::get_free_courses_meta_query_args(); |
|
| 668 | + |
|
| 669 | + // don't show any paid courses |
|
| 670 | + $courses = self::get_paid_courses(); |
|
| 671 | + $ids = array(); |
|
| 672 | + foreach( $courses as $course ){ |
|
| 673 | + $ids[] = $course->ID; |
|
| 674 | + } |
|
| 675 | + $free_course_query_args[ 'post__not_in' ] = $ids; |
|
| 676 | + |
|
| 677 | + return get_posts( $free_course_query_args ); |
|
| 678 | + |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Return all products that are not free |
|
| 683 | + * |
|
| 684 | + * @since 1.9.0 |
|
| 685 | + * @return array |
|
| 686 | + */ |
|
| 687 | + public static function get_paid_courses(){ |
|
| 688 | + |
|
| 689 | + $paid_course_query_args = Sensei_Course::get_default_query_args(); |
|
| 690 | + |
|
| 691 | + $paid_course_query_args[ 'meta_query' ] = self::get_paid_courses_meta_query_args(); |
|
| 692 | + |
|
| 693 | + return get_posts( $paid_course_query_args ); |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Show the WooCommerce add to cart button for the current course |
|
| 698 | + * |
|
| 699 | + * The function will only show the button if |
|
| 700 | + * 1- the user can buy the course |
|
| 701 | + * 2- if they have completed their pre-requisite |
|
| 702 | + * 3- if the course has a valid product attached |
|
| 703 | + * |
|
| 704 | + * @since 1.9.0 |
|
| 705 | + * @param int $course_id |
|
| 706 | + * @return string $html markup for the button or nothing if user not allowed to buy |
|
| 707 | + */ |
|
| 708 | + public static function the_add_to_cart_button_html( $course_id ){ |
|
| 709 | + |
|
| 710 | + if ( ! Sensei_Course::is_prerequisite_complete( $course_id )) { |
|
| 711 | + return ''; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + $wc_post_id = self::get_course_product_id( $course_id ); |
|
| 715 | + |
|
| 716 | + // Check if customer purchased the product |
|
| 717 | + if ( self::has_customer_bought_product( get_current_user_id(), $wc_post_id ) |
|
| 718 | + || empty( $wc_post_id ) ) { |
|
| 719 | + |
|
| 720 | + return ''; |
|
| 721 | + |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + // based on simple.php in WC templates/single-product/add-to-cart/ |
|
| 725 | + // Get the product |
|
| 726 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 727 | + |
|
| 728 | + // do not show the button for invalid products, non purchasable products, out |
|
| 729 | + // of stock product or if course is already in cart |
|
| 730 | + if ( ! isset ( $product ) |
|
| 731 | + || ! is_object( $product ) |
|
| 732 | + || ! $product->is_purchasable() |
|
| 733 | + || ! $product->is_in_stock() |
|
| 734 | + || self::is_course_in_cart( $wc_post_id ) ) { |
|
| 735 | + |
|
| 736 | + return ''; |
|
| 737 | + |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + // |
|
| 741 | + // button output: |
|
| 742 | + // |
|
| 743 | + ?> |
|
| 744 | 744 | |
| 745 | 745 | <form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" |
| 746 | 746 | class="cart" |
@@ -773,54 +773,54 @@ discard block |
||
| 773 | 773 | </form> |
| 774 | 774 | |
| 775 | 775 | <?php |
| 776 | - } // end the_add_to_cart_button_html |
|
| 776 | + } // end the_add_to_cart_button_html |
|
| 777 | 777 | |
| 778 | - /** |
|
| 779 | - * Alter the no permissions message on the single course page |
|
| 780 | - * Changes the message to a WooCommerce specific message. |
|
| 781 | - * |
|
| 782 | - * @since 1.9.0 |
|
| 783 | - * |
|
| 784 | - * @param $message |
|
| 785 | - * @param $post_id |
|
| 786 | - * |
|
| 787 | - * @return string $message |
|
| 788 | - */ |
|
| 789 | - public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 778 | + /** |
|
| 779 | + * Alter the no permissions message on the single course page |
|
| 780 | + * Changes the message to a WooCommerce specific message. |
|
| 781 | + * |
|
| 782 | + * @since 1.9.0 |
|
| 783 | + * |
|
| 784 | + * @param $message |
|
| 785 | + * @param $post_id |
|
| 786 | + * |
|
| 787 | + * @return string $message |
|
| 788 | + */ |
|
| 789 | + public static function alter_no_permissions_message( $message, $post_id ){ |
|
| 790 | 790 | |
| 791 | - if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 792 | - return $message; |
|
| 793 | - } |
|
| 791 | + if( empty( $post_id ) || 'course'!=get_post_type( $post_id ) ){ |
|
| 792 | + return $message; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - $product_id = self::get_course_product_id( $post_id ); |
|
| 795 | + $product_id = self::get_course_product_id( $post_id ); |
|
| 796 | 796 | |
| 797 | - if( ! $product_id |
|
| 798 | - || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 797 | + if( ! $product_id |
|
| 798 | + || self::has_customer_bought_product( get_current_user_id(),$product_id ) ){ |
|
| 799 | 799 | |
| 800 | - return $message; |
|
| 800 | + return $message; |
|
| 801 | 801 | |
| 802 | - } |
|
| 802 | + } |
|
| 803 | 803 | |
| 804 | - ob_start(); |
|
| 805 | - self::the_course_no_permissions_message( $post_id ); |
|
| 806 | - $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 804 | + ob_start(); |
|
| 805 | + self::the_course_no_permissions_message( $post_id ); |
|
| 806 | + $woocommerce_course_no_permissions_message = ob_get_clean(); |
|
| 807 | 807 | |
| 808 | - return $woocommerce_course_no_permissions_message ; |
|
| 808 | + return $woocommerce_course_no_permissions_message ; |
|
| 809 | 809 | |
| 810 | - } |
|
| 811 | - /** |
|
| 812 | - * Show the no permissions message when a user is logged in |
|
| 813 | - * and have not yet purchased the current course |
|
| 814 | - * |
|
| 815 | - * @since 1.9.0 |
|
| 816 | - */ |
|
| 817 | - public static function the_course_no_permissions_message( $course_id ){ |
|
| 810 | + } |
|
| 811 | + /** |
|
| 812 | + * Show the no permissions message when a user is logged in |
|
| 813 | + * and have not yet purchased the current course |
|
| 814 | + * |
|
| 815 | + * @since 1.9.0 |
|
| 816 | + */ |
|
| 817 | + public static function the_course_no_permissions_message( $course_id ){ |
|
| 818 | 818 | |
| 819 | - // login link |
|
| 820 | - $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | - $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 819 | + // login link |
|
| 820 | + $my_courses_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 821 | + $login_link = '<a href="' . esc_url( get_permalink( $my_courses_page_id ) ) . '">' . __( 'log in', 'woothemes-sensei' ) . '</a>'; |
|
| 822 | 822 | |
| 823 | - ?> |
|
| 823 | + ?> |
|
| 824 | 824 | |
| 825 | 825 | <span class="add-to-cart-login"> |
| 826 | 826 | <?php echo sprintf( __( 'Or %1$s to access your purchased courses', 'woothemes-sensei' ), $login_link ); ?> |
@@ -828,110 +828,110 @@ discard block |
||
| 828 | 828 | |
| 829 | 829 | <?php } |
| 830 | 830 | |
| 831 | - /** |
|
| 832 | - * Checks if a user has bought a product item. |
|
| 833 | - * |
|
| 834 | - * @since 1.9.0 |
|
| 835 | - * |
|
| 836 | - * @param int $user_id |
|
| 837 | - * @param int $product_id |
|
| 838 | - * |
|
| 839 | - * @return bool |
|
| 840 | - */ |
|
| 841 | - public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 831 | + /** |
|
| 832 | + * Checks if a user has bought a product item. |
|
| 833 | + * |
|
| 834 | + * @since 1.9.0 |
|
| 835 | + * |
|
| 836 | + * @param int $user_id |
|
| 837 | + * @param int $product_id |
|
| 838 | + * |
|
| 839 | + * @return bool |
|
| 840 | + */ |
|
| 841 | + public static function has_customer_bought_product ( $user_id, $product_id ){ |
|
| 842 | 842 | |
| 843 | - $orders = get_posts( array( |
|
| 844 | - 'posts_per_page' => -1, |
|
| 845 | - 'meta_key' => '_customer_user', |
|
| 846 | - 'meta_value' => intval( $user_id ), |
|
| 847 | - 'post_type' => 'shop_order', |
|
| 848 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | - ) ); |
|
| 843 | + $orders = get_posts( array( |
|
| 844 | + 'posts_per_page' => -1, |
|
| 845 | + 'meta_key' => '_customer_user', |
|
| 846 | + 'meta_value' => intval( $user_id ), |
|
| 847 | + 'post_type' => 'shop_order', |
|
| 848 | + 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 849 | + ) ); |
|
| 850 | 850 | |
| 851 | - foreach ( $orders as $order_id ) { |
|
| 851 | + foreach ( $orders as $order_id ) { |
|
| 852 | 852 | |
| 853 | - $order = new WC_Order( $order_id->ID ); |
|
| 853 | + $order = new WC_Order( $order_id->ID ); |
|
| 854 | 854 | |
| 855 | - if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 855 | + if ( $order->post_status != 'wc-completed' && $order->post_status != 'wc-processing' ) { |
|
| 856 | 856 | |
| 857 | - continue; |
|
| 858 | - } |
|
| 857 | + continue; |
|
| 858 | + } |
|
| 859 | 859 | |
| 860 | - if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 860 | + if ( ! ( 0 < sizeof( $order->get_items() ) ) ) { |
|
| 861 | 861 | |
| 862 | - continue; |
|
| 862 | + continue; |
|
| 863 | 863 | |
| 864 | - } |
|
| 864 | + } |
|
| 865 | 865 | |
| 866 | - foreach( $order->get_items() as $item ) { |
|
| 866 | + foreach( $order->get_items() as $item ) { |
|
| 867 | 867 | |
| 868 | - // Check if user has bought product |
|
| 869 | - if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 868 | + // Check if user has bought product |
|
| 869 | + if ( $item['product_id'] == $product_id || $item['variation_id'] == $product_id ) { |
|
| 870 | 870 | |
| 871 | - // Check if user has an active subscription for product |
|
| 872 | - if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | - $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | - if( $sub_key ) { |
|
| 875 | - $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | - if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | - if( 'active' == $sub['status'] ) { |
|
| 878 | - return true; |
|
| 879 | - } else { |
|
| 880 | - return false; |
|
| 881 | - } |
|
| 882 | - } |
|
| 883 | - } |
|
| 884 | - } |
|
| 871 | + // Check if user has an active subscription for product |
|
| 872 | + if( class_exists( 'WC_Subscriptions_Manager' ) ) { |
|
| 873 | + $sub_key = WC_Subscriptions_Manager::get_subscription_key( $order_id->ID, $product_id ); |
|
| 874 | + if( $sub_key ) { |
|
| 875 | + $sub = WC_Subscriptions_Manager::get_subscription( $sub_key ); |
|
| 876 | + if( $sub && isset( $sub['status'] ) ) { |
|
| 877 | + if( 'active' == $sub['status'] ) { |
|
| 878 | + return true; |
|
| 879 | + } else { |
|
| 880 | + return false; |
|
| 881 | + } |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | + } |
|
| 885 | 885 | |
| 886 | - // Customer has bought product |
|
| 887 | - return true; |
|
| 888 | - } // End If Statement |
|
| 886 | + // Customer has bought product |
|
| 887 | + return true; |
|
| 888 | + } // End If Statement |
|
| 889 | 889 | |
| 890 | - } // End For each item |
|
| 890 | + } // End For each item |
|
| 891 | 891 | |
| 892 | - } // End For each order |
|
| 892 | + } // End For each order |
|
| 893 | 893 | |
| 894 | - } // end has customer bought product |
|
| 894 | + } // end has customer bought product |
|
| 895 | 895 | |
| 896 | - /** |
|
| 897 | - * Return the product id for the given course |
|
| 898 | - * |
|
| 899 | - * @since 1.9.0 |
|
| 900 | - * |
|
| 901 | - * @param int $course_id |
|
| 902 | - * |
|
| 903 | - * @return string $woocommerce_product_id or false if none exist |
|
| 904 | - * |
|
| 905 | - */ |
|
| 906 | - public static function get_course_product_id( $course_id ){ |
|
| 896 | + /** |
|
| 897 | + * Return the product id for the given course |
|
| 898 | + * |
|
| 899 | + * @since 1.9.0 |
|
| 900 | + * |
|
| 901 | + * @param int $course_id |
|
| 902 | + * |
|
| 903 | + * @return string $woocommerce_product_id or false if none exist |
|
| 904 | + * |
|
| 905 | + */ |
|
| 906 | + public static function get_course_product_id( $course_id ){ |
|
| 907 | 907 | |
| 908 | - $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 908 | + $product_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 909 | 909 | |
| 910 | - if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 911 | - return false; |
|
| 912 | - } |
|
| 910 | + if( empty( $product_id ) || 'product' != get_post_type( $product_id ) ){ |
|
| 911 | + return false; |
|
| 912 | + } |
|
| 913 | 913 | |
| 914 | - return $product_id; |
|
| 914 | + return $product_id; |
|
| 915 | 915 | |
| 916 | - } |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - /** |
|
| 919 | - * Alter the body classes adding WooCommerce to the body |
|
| 920 | - * |
|
| 921 | - * @param array $classes |
|
| 922 | - * @return array |
|
| 923 | - */ |
|
| 924 | - public static function add_woocommerce_body_class( $classes ){ |
|
| 918 | + /** |
|
| 919 | + * Alter the body classes adding WooCommerce to the body |
|
| 920 | + * |
|
| 921 | + * @param array $classes |
|
| 922 | + * @return array |
|
| 923 | + */ |
|
| 924 | + public static function add_woocommerce_body_class( $classes ){ |
|
| 925 | 925 | |
| 926 | - if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 926 | + if( ! in_array( 'woocommerce', $classes ) ){ |
|
| 927 | 927 | |
| 928 | - $classes[] ='woocommerce'; |
|
| 928 | + $classes[] ='woocommerce'; |
|
| 929 | 929 | |
| 930 | - } |
|
| 930 | + } |
|
| 931 | 931 | |
| 932 | 932 | |
| 933 | - return $classes; |
|
| 933 | + return $classes; |
|
| 934 | 934 | |
| 935 | - } |
|
| 935 | + } |
|
| 936 | 936 | |
| 937 | 937 | }// end Sensei_WC |
@@ -10,323 +10,323 @@ discard block |
||
| 10 | 10 | */ |
| 11 | 11 | class Sensei_Legacy_Shortcodes { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Add the legacy shortcodes to WordPress |
|
| 15 | - * |
|
| 16 | - * @since 1.9.0 |
|
| 17 | - */ |
|
| 18 | - public static function init(){ |
|
| 19 | - |
|
| 20 | - add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 21 | - add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 22 | - add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 23 | - add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 24 | - add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 25 | - add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 26 | - |
|
| 27 | - } |
|
| 28 | - /** |
|
| 29 | - * all_courses shortcode output function. |
|
| 30 | - * |
|
| 31 | - * The function should only be called indirectly through do_shortcode() |
|
| 32 | - * |
|
| 33 | - * @access public |
|
| 34 | - * @param mixed $atts |
|
| 35 | - * @param mixed $content (default: null) |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public static function all_courses( $atts, $content = null ) { |
|
| 39 | - |
|
| 40 | - return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 41 | - |
|
| 42 | - } // all_courses() |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * paid_courses function. |
|
| 46 | - * |
|
| 47 | - * @access public |
|
| 48 | - * @param mixed $atts |
|
| 49 | - * @param mixed $content (default: null) |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - public static function paid_courses( $atts, $content = null ) { |
|
| 53 | - |
|
| 54 | - return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); |
|
| 55 | - |
|
| 56 | - } // End paid_courses() |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * featured_courses function. |
|
| 61 | - * |
|
| 62 | - * @access public |
|
| 63 | - * @param mixed $atts |
|
| 64 | - * @param mixed $content (default: null) |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 67 | - public static function featured_courses( $atts, $content = null ) { |
|
| 68 | - |
|
| 69 | - return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); |
|
| 13 | + /** |
|
| 14 | + * Add the legacy shortcodes to WordPress |
|
| 15 | + * |
|
| 16 | + * @since 1.9.0 |
|
| 17 | + */ |
|
| 18 | + public static function init(){ |
|
| 19 | + |
|
| 20 | + add_shortcode( 'allcourses', array( __CLASS__, 'all_courses' ) ); |
|
| 21 | + add_shortcode( 'newcourses', array( __CLASS__,'new_courses' ) ); |
|
| 22 | + add_shortcode( 'featuredcourses', array( __CLASS__,'featured_courses') ); |
|
| 23 | + add_shortcode( 'freecourses', array( __CLASS__,'free_courses') ); |
|
| 24 | + add_shortcode( 'paidcourses', array( __CLASS__,'paid_courses') ); |
|
| 25 | + add_shortcode( 'usercourses', array( __CLASS__,'user_courses' ) ); |
|
| 26 | + |
|
| 27 | + } |
|
| 28 | + /** |
|
| 29 | + * all_courses shortcode output function. |
|
| 30 | + * |
|
| 31 | + * The function should only be called indirectly through do_shortcode() |
|
| 32 | + * |
|
| 33 | + * @access public |
|
| 34 | + * @param mixed $atts |
|
| 35 | + * @param mixed $content (default: null) |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public static function all_courses( $atts, $content = null ) { |
|
| 39 | + |
|
| 40 | + return self::generate_shortcode_courses( '', 'allcourses' ); // all courses but no title |
|
| 41 | + |
|
| 42 | + } // all_courses() |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * paid_courses function. |
|
| 46 | + * |
|
| 47 | + * @access public |
|
| 48 | + * @param mixed $atts |
|
| 49 | + * @param mixed $content (default: null) |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + public static function paid_courses( $atts, $content = null ) { |
|
| 53 | + |
|
| 54 | + return self::generate_shortcode_courses( 'Paid Courses', 'paidcourses' ); |
|
| 55 | + |
|
| 56 | + } // End paid_courses() |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * featured_courses function. |
|
| 61 | + * |
|
| 62 | + * @access public |
|
| 63 | + * @param mixed $atts |
|
| 64 | + * @param mixed $content (default: null) |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | + public static function featured_courses( $atts, $content = null ) { |
|
| 68 | + |
|
| 69 | + return self::generate_shortcode_courses( 'Featured Courses', 'featuredcourses' ); |
|
| 70 | 70 | |
| 71 | - } // End featured_courses() |
|
| 71 | + } // End featured_courses() |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * shortcode_free_courses function. |
|
| 75 | - * |
|
| 76 | - * @access public |
|
| 77 | - * @param mixed $atts |
|
| 78 | - * @param mixed $content (default: null) |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public static function free_courses( $atts, $content = null ) { |
|
| 73 | + /** |
|
| 74 | + * shortcode_free_courses function. |
|
| 75 | + * |
|
| 76 | + * @access public |
|
| 77 | + * @param mixed $atts |
|
| 78 | + * @param mixed $content (default: null) |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public static function free_courses( $atts, $content = null ) { |
|
| 82 | 82 | |
| 83 | - return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); |
|
| 83 | + return self::generate_shortcode_courses( 'Free Courses', 'freecourses' ); |
|
| 84 | 84 | |
| 85 | - } // End free_courses() |
|
| 85 | + } // End free_courses() |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * shortcode_new_courses function. |
|
| 89 | - * |
|
| 90 | - * @access public |
|
| 91 | - * @param mixed $atts |
|
| 92 | - * @param mixed $content (default: null) |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public static function new_courses( $atts, $content = null ) { |
|
| 87 | + /** |
|
| 88 | + * shortcode_new_courses function. |
|
| 89 | + * |
|
| 90 | + * @access public |
|
| 91 | + * @param mixed $atts |
|
| 92 | + * @param mixed $content (default: null) |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public static function new_courses( $atts, $content = null ) { |
|
| 96 | 96 | |
| 97 | - return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); |
|
| 97 | + return self::generate_shortcode_courses( 'New Courses', 'newcourses' ); |
|
| 98 | 98 | |
| 99 | - } // End new_courses() |
|
| 99 | + } // End new_courses() |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Generate courses adding a title. |
|
| 103 | - * |
|
| 104 | - * @since 1.9.0 |
|
| 105 | - * |
|
| 106 | - * @param $title |
|
| 107 | - * @param $shortcode_specific_override |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 101 | + /** |
|
| 102 | + * Generate courses adding a title. |
|
| 103 | + * |
|
| 104 | + * @since 1.9.0 |
|
| 105 | + * |
|
| 106 | + * @param $title |
|
| 107 | + * @param $shortcode_specific_override |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public static function generate_shortcode_courses( $title , $shortcode_specific_override ){ |
|
| 111 | 111 | |
| 112 | - global $shortcode_override, $posts_array; |
|
| 112 | + global $shortcode_override, $posts_array; |
|
| 113 | 113 | |
| 114 | - $shortcode_override = $shortcode_specific_override; |
|
| 114 | + $shortcode_override = $shortcode_specific_override; |
|
| 115 | 115 | |
| 116 | - // do not show this short code if there is a shortcode int he url and |
|
| 117 | - // this specific shortcode is not the one requested in the ur. |
|
| 118 | - $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 119 | - if( ! empty( $specific_shortcode_requested) && |
|
| 120 | - $specific_shortcode_requested != $shortcode_override ){ |
|
| 116 | + // do not show this short code if there is a shortcode int he url and |
|
| 117 | + // this specific shortcode is not the one requested in the ur. |
|
| 118 | + $specific_shortcode_requested = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ''; |
|
| 119 | + if( ! empty( $specific_shortcode_requested) && |
|
| 120 | + $specific_shortcode_requested != $shortcode_override ){ |
|
| 121 | 121 | |
| 122 | - return ''; |
|
| 122 | + return ''; |
|
| 123 | 123 | |
| 124 | - } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - // loop and get all courses html |
|
| 127 | - ob_start(); |
|
| 128 | - self::initialise_legacy_course_loop(); |
|
| 129 | - $courses = ob_get_clean(); |
|
| 126 | + // loop and get all courses html |
|
| 127 | + ob_start(); |
|
| 128 | + self::initialise_legacy_course_loop(); |
|
| 129 | + $courses = ob_get_clean(); |
|
| 130 | 130 | |
| 131 | - $content = ''; |
|
| 132 | - if( count( $posts_array ) > 0 ){ |
|
| 131 | + $content = ''; |
|
| 132 | + if( count( $posts_array ) > 0 ){ |
|
| 133 | 133 | |
| 134 | - $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 135 | - $before .= '<section id="main-course" class="course-container">'; |
|
| 134 | + $before = empty($title)? '' : '<header class="archive-header"><h2>'. $title .'</h2></header>'; |
|
| 135 | + $before .= '<section id="main-course" class="course-container">'; |
|
| 136 | 136 | |
| 137 | - $after = '</section>'; |
|
| 137 | + $after = '</section>'; |
|
| 138 | 138 | |
| 139 | - //assemble |
|
| 140 | - $content = $before . $courses . $after; |
|
| 139 | + //assemble |
|
| 140 | + $content = $before . $courses . $after; |
|
| 141 | 141 | |
| 142 | - } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - return $content; |
|
| 144 | + return $content; |
|
| 145 | 145 | |
| 146 | - }// end generate_shortcode_courses |
|
| 146 | + }// end generate_shortcode_courses |
|
| 147 | 147 | |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * user_courses function. |
|
| 151 | - * |
|
| 152 | - * @access public |
|
| 153 | - * @param mixed $atts |
|
| 154 | - * @param mixed $content (default: null) |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public static function user_courses( $atts, $content = null ) { |
|
| 158 | - global $shortcode_override; |
|
| 159 | - extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 149 | + /** |
|
| 150 | + * user_courses function. |
|
| 151 | + * |
|
| 152 | + * @access public |
|
| 153 | + * @param mixed $atts |
|
| 154 | + * @param mixed $content (default: null) |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public static function user_courses( $atts, $content = null ) { |
|
| 158 | + global $shortcode_override; |
|
| 159 | + extract( shortcode_atts( array( 'amount' => 0 ), $atts ) ); |
|
| 160 | 160 | |
| 161 | - $shortcode_override = 'usercourses'; |
|
| 161 | + $shortcode_override = 'usercourses'; |
|
| 162 | 162 | |
| 163 | - ob_start(); |
|
| 163 | + ob_start(); |
|
| 164 | 164 | |
| 165 | - if( is_user_logged_in() ){ |
|
| 165 | + if( is_user_logged_in() ){ |
|
| 166 | 166 | |
| 167 | - Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 167 | + Sensei_Templates::get_template( 'user/my-courses.php' ); |
|
| 168 | 168 | |
| 169 | - }else{ |
|
| 169 | + }else{ |
|
| 170 | 170 | |
| 171 | - Sensei()->frontend->sensei_login_form(); |
|
| 171 | + Sensei()->frontend->sensei_login_form(); |
|
| 172 | 172 | |
| 173 | - } |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - $content = ob_get_clean(); |
|
| 176 | - return $content; |
|
| 175 | + $content = ob_get_clean(); |
|
| 176 | + return $content; |
|
| 177 | 177 | |
| 178 | - } // End user_courses() |
|
| 178 | + } // End user_courses() |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * This function is simply to honor the legacy |
|
| 182 | - * loop-course.php for the old shortcodes. |
|
| 183 | - * @since 1.9.0 |
|
| 184 | - */ |
|
| 185 | - public static function initialise_legacy_course_loop(){ |
|
| 180 | + /** |
|
| 181 | + * This function is simply to honor the legacy |
|
| 182 | + * loop-course.php for the old shortcodes. |
|
| 183 | + * @since 1.9.0 |
|
| 184 | + */ |
|
| 185 | + public static function initialise_legacy_course_loop(){ |
|
| 186 | 186 | |
| 187 | - global $post, $wp_query, $shortcode_override, $course_excludes; |
|
| 187 | + global $post, $wp_query, $shortcode_override, $course_excludes; |
|
| 188 | 188 | |
| 189 | - // Handle Query Type |
|
| 190 | - $query_type = ''; |
|
| 189 | + // Handle Query Type |
|
| 190 | + $query_type = ''; |
|
| 191 | 191 | |
| 192 | - if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 193 | - $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 194 | - } // End If Statement |
|
| 192 | + if ( isset( $_GET[ 'action' ] ) && ( '' != esc_html( $_GET[ 'action' ] ) ) ) { |
|
| 193 | + $query_type = esc_html( $_GET[ 'action' ] ); |
|
| 194 | + } // End If Statement |
|
| 195 | 195 | |
| 196 | - if ( '' != $shortcode_override ) { |
|
| 197 | - $query_type = $shortcode_override; |
|
| 198 | - } // End If Statement |
|
| 196 | + if ( '' != $shortcode_override ) { |
|
| 197 | + $query_type = $shortcode_override; |
|
| 198 | + } // End If Statement |
|
| 199 | 199 | |
| 200 | - if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 200 | + if ( !is_array( $course_excludes ) ) { $course_excludes = array(); } |
|
| 201 | 201 | |
| 202 | - // Check that query returns results |
|
| 203 | - // Handle Pagination |
|
| 204 | - $paged = $wp_query->get( 'paged' ); |
|
| 205 | - $paged = empty( $paged ) ? 1 : $paged; |
|
| 202 | + // Check that query returns results |
|
| 203 | + // Handle Pagination |
|
| 204 | + $paged = $wp_query->get( 'paged' ); |
|
| 205 | + $paged = empty( $paged ) ? 1 : $paged; |
|
| 206 | 206 | |
| 207 | 207 | |
| 208 | - // Check for pagination settings |
|
| 209 | - if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 208 | + // Check for pagination settings |
|
| 209 | + if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 210 | 210 | |
| 211 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 211 | + $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 212 | 212 | |
| 213 | - } else { |
|
| 213 | + } else { |
|
| 214 | 214 | |
| 215 | - $amount = $wp_query->get( 'posts_per_page' ); |
|
| 215 | + $amount = $wp_query->get( 'posts_per_page' ); |
|
| 216 | 216 | |
| 217 | - } // End If Statement |
|
| 217 | + } // End If Statement |
|
| 218 | 218 | |
| 219 | - // This is not a paginated page (or it's simply the first page of a paginated page/post) |
|
| 219 | + // This is not a paginated page (or it's simply the first page of a paginated page/post) |
|
| 220 | 220 | |
| 221 | - global $posts_array; |
|
| 222 | - $course_includes = array(); |
|
| 221 | + global $posts_array; |
|
| 222 | + $course_includes = array(); |
|
| 223 | 223 | |
| 224 | - $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 225 | - $course_query = new WP_Query( $query_args ); |
|
| 226 | - $posts_array = $course_query->get_posts(); |
|
| 224 | + $query_args = Sensei()->course->get_archive_query_args( $shortcode_override, $amount, $course_includes, $course_excludes ); |
|
| 225 | + $course_query = new WP_Query( $query_args ); |
|
| 226 | + $posts_array = $course_query->get_posts(); |
|
| 227 | 227 | |
| 228 | - // output the courses |
|
| 229 | - if( ! empty( $posts_array ) ) { |
|
| 228 | + // output the courses |
|
| 229 | + if( ! empty( $posts_array ) ) { |
|
| 230 | 230 | |
| 231 | - //output all courses for current query |
|
| 232 | - self::loop_courses( $course_query, $amount ); |
|
| 231 | + //output all courses for current query |
|
| 232 | + self::loop_courses( $course_query, $amount ); |
|
| 233 | 233 | |
| 234 | - } |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Loop through courses in the query and output the infomration needed |
|
| 240 | - * |
|
| 241 | - * @since 1.9.0 |
|
| 242 | - * |
|
| 243 | - * @param WP_Query $course_query |
|
| 244 | - */ |
|
| 245 | - public static function loop_courses( $course_query, $amount ){ |
|
| 238 | + /** |
|
| 239 | + * Loop through courses in the query and output the infomration needed |
|
| 240 | + * |
|
| 241 | + * @since 1.9.0 |
|
| 242 | + * |
|
| 243 | + * @param WP_Query $course_query |
|
| 244 | + */ |
|
| 245 | + public static function loop_courses( $course_query, $amount ){ |
|
| 246 | 246 | |
| 247 | - global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
|
| 247 | + global $shortcode_override, $posts_array, $post, $wp_query, $shortcode_override, $course_excludes, $course_includes; |
|
| 248 | 248 | |
| 249 | - if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 249 | + if ( count( $course_query->get_posts() ) > 0 ) { |
|
| 250 | 250 | |
| 251 | - do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 251 | + do_action( 'sensei_course_archive_header', $shortcode_override ); |
|
| 252 | 252 | |
| 253 | - foreach ( $course_query->get_posts() as $course){ |
|
| 253 | + foreach ( $course_query->get_posts() as $course){ |
|
| 254 | 254 | |
| 255 | - // Make sure the other loops dont include the same post twice! |
|
| 256 | - array_push( $course_excludes, $course->ID ); |
|
| 255 | + // Make sure the other loops dont include the same post twice! |
|
| 256 | + array_push( $course_excludes, $course->ID ); |
|
| 257 | 257 | |
| 258 | - // output the course markup |
|
| 259 | - self::the_course( $course->ID ); |
|
| 258 | + // output the course markup |
|
| 259 | + self::the_course( $course->ID ); |
|
| 260 | 260 | |
| 261 | - } // End For Loop |
|
| 261 | + } // End For Loop |
|
| 262 | 262 | |
| 263 | - // More and Prev links |
|
| 264 | - $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 265 | - $posts_array = $posts_array_query->get_posts(); |
|
| 266 | - $max_pages = $course_query->found_posts / $amount; |
|
| 267 | - if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 263 | + // More and Prev links |
|
| 264 | + $posts_array_query = new WP_Query(Sensei()->course->course_query( $shortcode_override, $amount, $course_includes, $course_excludes ) ); |
|
| 265 | + $posts_array = $posts_array_query->get_posts(); |
|
| 266 | + $max_pages = $course_query->found_posts / $amount; |
|
| 267 | + if ( '' != $shortcode_override && ( $max_pages > $course_query->get( 'paged' ) ) ) { |
|
| 268 | 268 | |
| 269 | - switch( $shortcode_override ){ |
|
| 270 | - case 'paidcourses': |
|
| 271 | - $filter = 'paid'; |
|
| 272 | - break; |
|
| 273 | - case 'featuredcourses': |
|
| 274 | - $filter = 'featured'; |
|
| 275 | - break; |
|
| 276 | - case 'freecourses': |
|
| 277 | - $filter = 'free'; |
|
| 278 | - break; |
|
| 279 | - default: |
|
| 280 | - $filter = ''; |
|
| 281 | - break; |
|
| 282 | - } |
|
| 269 | + switch( $shortcode_override ){ |
|
| 270 | + case 'paidcourses': |
|
| 271 | + $filter = 'paid'; |
|
| 272 | + break; |
|
| 273 | + case 'featuredcourses': |
|
| 274 | + $filter = 'featured'; |
|
| 275 | + break; |
|
| 276 | + case 'freecourses': |
|
| 277 | + $filter = 'free'; |
|
| 278 | + break; |
|
| 279 | + default: |
|
| 280 | + $filter = ''; |
|
| 281 | + break; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - $quer_args = array(); |
|
| 285 | - $quer_args[ 'paged' ] = '2'; |
|
| 286 | - if( !empty( $filter ) ){ |
|
| 287 | - $quer_args[ 'course_filter' ] = $filter; |
|
| 288 | - } |
|
| 284 | + $quer_args = array(); |
|
| 285 | + $quer_args[ 'paged' ] = '2'; |
|
| 286 | + if( !empty( $filter ) ){ |
|
| 287 | + $quer_args[ 'course_filter' ] = $filter; |
|
| 288 | + } |
|
| 289 | 289 | |
| 290 | - $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 291 | - $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 292 | - $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 290 | + $course_pagination_link = get_post_type_archive_link( 'course' ); |
|
| 291 | + $more_link_text = esc_html( Sensei()->settings->settings[ 'course_archive_more_link_text' ] ); |
|
| 292 | + $more_link_url = esc_url( add_query_arg( $quer_args, $course_pagination_link ) ); |
|
| 293 | 293 | |
| 294 | - // next/more |
|
| 295 | - $html = '<div class="navigation"><div class="nav-next">'; |
|
| 296 | - $html .= '<a href="' . $more_link_url . '">'; |
|
| 297 | - $html .= $more_link_text; |
|
| 298 | - $html .= '<span class="meta-nav"></span></a></div>'; |
|
| 294 | + // next/more |
|
| 295 | + $html = '<div class="navigation"><div class="nav-next">'; |
|
| 296 | + $html .= '<a href="' . $more_link_url . '">'; |
|
| 297 | + $html .= $more_link_text; |
|
| 298 | + $html .= '<span class="meta-nav"></span></a></div>'; |
|
| 299 | 299 | |
| 300 | - echo apply_filters( 'course_archive_next_link', $html ); |
|
| 300 | + echo apply_filters( 'course_archive_next_link', $html ); |
|
| 301 | 301 | |
| 302 | - } // End If Statement |
|
| 302 | + } // End If Statement |
|
| 303 | 303 | |
| 304 | - } // End If Statement |
|
| 305 | - } |
|
| 304 | + } // End If Statement |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * Print a single course markup |
|
| 309 | - * |
|
| 310 | - * @param $course_id |
|
| 311 | - */ |
|
| 312 | - public static function the_course( $course_id ){ |
|
| 307 | + /** |
|
| 308 | + * Print a single course markup |
|
| 309 | + * |
|
| 310 | + * @param $course_id |
|
| 311 | + */ |
|
| 312 | + public static function the_course( $course_id ){ |
|
| 313 | 313 | |
| 314 | - // Get meta data |
|
| 315 | - $course = get_post( $course_id ); |
|
| 316 | - $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 317 | - $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 318 | - $author_display_name = $user_info->display_name; |
|
| 319 | - $author_id = $course->post_author; |
|
| 320 | - $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 321 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 322 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 323 | - ?> |
|
| 314 | + // Get meta data |
|
| 315 | + $course = get_post( $course_id ); |
|
| 316 | + $user_info = get_userdata( absint( $course->post_author ) ); |
|
| 317 | + $author_link = get_author_posts_url( absint( $course->post_author ) ); |
|
| 318 | + $author_display_name = $user_info->display_name; |
|
| 319 | + $author_id = $course->post_author; |
|
| 320 | + $category_output = get_the_term_list( $course_id, 'course-category', '', ', ', '' ); |
|
| 321 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course_id ) ); |
|
| 322 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course_id, get_current_user_id() ); |
|
| 323 | + ?> |
|
| 324 | 324 | |
| 325 | 325 | <article class="<?php echo esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_id ) ) ); ?>"> |
| 326 | 326 | <?php |
| 327 | - // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 328 | - do_action('sensei_course_content_before',$course ); |
|
| 329 | - ?> |
|
| 327 | + // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 328 | + do_action('sensei_course_content_before',$course ); |
|
| 329 | + ?> |
|
| 330 | 330 | <div class="course-content"> |
| 331 | 331 | |
| 332 | 332 | <?php Sensei()->course->course_image($course_id); ?> |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | </p> |
| 363 | 363 | |
| 364 | 364 | <?php if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
| 365 | - $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 365 | + $preview_lessons = sprintf( __( '(%d preview lessons)', 'woothemes-sensei' ), $preview_lesson_count ); ?> |
|
| 366 | 366 | <p class="sensei-free-lessons"> |
| 367 | 367 | <a href="<?php echo get_permalink( $course_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
| 368 | 368 | </a> - <?php echo $preview_lessons; ?> |
@@ -373,15 +373,15 @@ discard block |
||
| 373 | 373 | |
| 374 | 374 | </div> |
| 375 | 375 | <?php |
| 376 | - // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 377 | - do_action('sensei_course_content_after', $course->ID); |
|
| 378 | - ?> |
|
| 376 | + // so that legacy shortcodes work with thir party plugins that wants to hook in |
|
| 377 | + do_action('sensei_course_content_after', $course->ID); |
|
| 378 | + ?> |
|
| 379 | 379 | |
| 380 | 380 | </article> |
| 381 | 381 | |
| 382 | 382 | <?php |
| 383 | 383 | |
| 384 | 384 | |
| 385 | - } // end the_course |
|
| 385 | + } // end the_course |
|
| 386 | 386 | |
| 387 | 387 | }// end class legacy shortcodes |
| 388 | 388 | \ No newline at end of file |
@@ -11,681 +11,681 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class Sensei_Templates { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Load the template files from within sensei/templates/ or the the theme if overrided within the theme. |
|
| 16 | - * |
|
| 17 | - * @since 1.9.0 |
|
| 18 | - * @param string $slug |
|
| 19 | - * @param string $name default: '' |
|
| 20 | - * |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - public static function get_part( $slug, $name = '' ){ |
|
| 14 | + /** |
|
| 15 | + * Load the template files from within sensei/templates/ or the the theme if overrided within the theme. |
|
| 16 | + * |
|
| 17 | + * @since 1.9.0 |
|
| 18 | + * @param string $slug |
|
| 19 | + * @param string $name default: '' |
|
| 20 | + * |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + public static function get_part( $slug, $name = '' ){ |
|
| 24 | 24 | |
| 25 | - $template = ''; |
|
| 26 | - $plugin_template_url = Sensei()->template_url; |
|
| 27 | - $plugin_template_path = Sensei()->plugin_path() . "/templates/"; |
|
| 25 | + $template = ''; |
|
| 26 | + $plugin_template_url = Sensei()->template_url; |
|
| 27 | + $plugin_template_path = Sensei()->plugin_path() . "/templates/"; |
|
| 28 | 28 | |
| 29 | - // Look in yourtheme/slug-name.php and yourtheme/sensei/slug-name.php |
|
| 30 | - if ( $name ){ |
|
| 29 | + // Look in yourtheme/slug-name.php and yourtheme/sensei/slug-name.php |
|
| 30 | + if ( $name ){ |
|
| 31 | 31 | |
| 32 | - $template = locate_template( array ( "{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php" ) ); |
|
| 32 | + $template = locate_template( array ( "{$slug}-{$name}.php", "{$plugin_template_url}{$slug}-{$name}.php" ) ); |
|
| 33 | 33 | |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - // Get default slug-name.php |
|
| 37 | - if ( ! $template && $name && file_exists( $plugin_template_path . "{$slug}-{$name}.php" ) ){ |
|
| 36 | + // Get default slug-name.php |
|
| 37 | + if ( ! $template && $name && file_exists( $plugin_template_path . "{$slug}-{$name}.php" ) ){ |
|
| 38 | 38 | |
| 39 | - $template = $plugin_template_path . "{$slug}-{$name}.php"; |
|
| 39 | + $template = $plugin_template_path . "{$slug}-{$name}.php"; |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | - // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/sensei/slug.php |
|
| 45 | - if ( !$template ){ |
|
| 44 | + // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/sensei/slug.php |
|
| 45 | + if ( !$template ){ |
|
| 46 | 46 | |
| 47 | - $template = locate_template( array ( "{$slug}.php", "{$plugin_template_url}{$slug}.php" ) ); |
|
| 47 | + $template = locate_template( array ( "{$slug}.php", "{$plugin_template_url}{$slug}.php" ) ); |
|
| 48 | 48 | |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - if ( $template ){ |
|
| 52 | + if ( $template ){ |
|
| 53 | 53 | |
| 54 | - load_template( $template, false ); |
|
| 54 | + load_template( $template, false ); |
|
| 55 | 55 | |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - } // end get part |
|
| 58 | + } // end get part |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Get the template. |
|
| 62 | - * |
|
| 63 | - * @since 1.9.0 |
|
| 64 | - * |
|
| 65 | - * @param $template_name |
|
| 66 | - * @param array $args |
|
| 67 | - * @param string $template_path |
|
| 68 | - * @param string $default_path |
|
| 69 | - */ |
|
| 70 | - public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 60 | + /** |
|
| 61 | + * Get the template. |
|
| 62 | + * |
|
| 63 | + * @since 1.9.0 |
|
| 64 | + * |
|
| 65 | + * @param $template_name |
|
| 66 | + * @param array $args |
|
| 67 | + * @param string $template_path |
|
| 68 | + * @param string $default_path |
|
| 69 | + */ |
|
| 70 | + public static function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 71 | 71 | |
| 72 | - if ( $args && is_array($args) ) |
|
| 73 | - extract( $args ); |
|
| 72 | + if ( $args && is_array($args) ) |
|
| 73 | + extract( $args ); |
|
| 74 | 74 | |
| 75 | - $located = self::locate_template( $template_name, $template_path, $default_path ); |
|
| 75 | + $located = self::locate_template( $template_name, $template_path, $default_path ); |
|
| 76 | 76 | |
| 77 | - if( ! empty( $located ) ){ |
|
| 77 | + if( ! empty( $located ) ){ |
|
| 78 | 78 | |
| 79 | - do_action( 'sensei_before_template_part', $template_name, $template_path, $located ); |
|
| 79 | + do_action( 'sensei_before_template_part', $template_name, $template_path, $located ); |
|
| 80 | 80 | |
| 81 | - include( $located ); |
|
| 81 | + include( $located ); |
|
| 82 | 82 | |
| 83 | - do_action( 'sensei_after_template_part', $template_name, $template_path, $located ); |
|
| 83 | + do_action( 'sensei_after_template_part', $template_name, $template_path, $located ); |
|
| 84 | 84 | |
| 85 | - } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - } // end get template |
|
| 87 | + } // end get template |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Check if the template file exists. A wrapper for WP locate_template. |
|
| 91 | - * |
|
| 92 | - * @since 1.9.0 |
|
| 93 | - * |
|
| 94 | - * @param $template_name |
|
| 95 | - * @param string $template_path |
|
| 96 | - * @param string $default_path |
|
| 97 | - * |
|
| 98 | - * @return mixed|void |
|
| 99 | - */ |
|
| 100 | - public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 89 | + /** |
|
| 90 | + * Check if the template file exists. A wrapper for WP locate_template. |
|
| 91 | + * |
|
| 92 | + * @since 1.9.0 |
|
| 93 | + * |
|
| 94 | + * @param $template_name |
|
| 95 | + * @param string $template_path |
|
| 96 | + * @param string $default_path |
|
| 97 | + * |
|
| 98 | + * @return mixed|void |
|
| 99 | + */ |
|
| 100 | + public static function locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 101 | 101 | |
| 102 | - if ( ! $template_path ) $template_path = Sensei()->template_url; |
|
| 103 | - if ( ! $default_path ) $default_path = Sensei()->plugin_path() . '/templates/'; |
|
| 102 | + if ( ! $template_path ) $template_path = Sensei()->template_url; |
|
| 103 | + if ( ! $default_path ) $default_path = Sensei()->plugin_path() . '/templates/'; |
|
| 104 | 104 | |
| 105 | - // Look within passed path within the theme - this is priority |
|
| 106 | - $template = locate_template( |
|
| 107 | - array( |
|
| 108 | - $template_path . $template_name, |
|
| 109 | - $template_name |
|
| 110 | - ) |
|
| 111 | - ); |
|
| 105 | + // Look within passed path within the theme - this is priority |
|
| 106 | + $template = locate_template( |
|
| 107 | + array( |
|
| 108 | + $template_path . $template_name, |
|
| 109 | + $template_name |
|
| 110 | + ) |
|
| 111 | + ); |
|
| 112 | 112 | |
| 113 | - // Get default template |
|
| 114 | - if ( ! $template ){ |
|
| 113 | + // Get default template |
|
| 114 | + if ( ! $template ){ |
|
| 115 | 115 | |
| 116 | - $template = $default_path . $template_name; |
|
| 116 | + $template = $default_path . $template_name; |
|
| 117 | 117 | |
| 118 | - } |
|
| 119 | - // return nothing for file that do not exist |
|
| 120 | - if( !file_exists( $template ) ){ |
|
| 121 | - $template = ''; |
|
| 122 | - } |
|
| 118 | + } |
|
| 119 | + // return nothing for file that do not exist |
|
| 120 | + if( !file_exists( $template ) ){ |
|
| 121 | + $template = ''; |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - // Return what we found |
|
| 125 | - return apply_filters( 'sensei_locate_template', $template, $template_name, $template_path ); |
|
| 124 | + // Return what we found |
|
| 125 | + return apply_filters( 'sensei_locate_template', $template, $template_name, $template_path ); |
|
| 126 | 126 | |
| 127 | - } // end locate |
|
| 127 | + } // end locate |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Determine which Sensei template to load based on the |
|
| 131 | - * current page context. |
|
| 132 | - * |
|
| 133 | - * @since 1.0 |
|
| 134 | - * |
|
| 135 | - * @param string $template |
|
| 136 | - * @return string $template |
|
| 137 | - */ |
|
| 138 | - public static function template_loader ( $template = '' ) { |
|
| 129 | + /** |
|
| 130 | + * Determine which Sensei template to load based on the |
|
| 131 | + * current page context. |
|
| 132 | + * |
|
| 133 | + * @since 1.0 |
|
| 134 | + * |
|
| 135 | + * @param string $template |
|
| 136 | + * @return string $template |
|
| 137 | + */ |
|
| 138 | + public static function template_loader ( $template = '' ) { |
|
| 139 | 139 | |
| 140 | - global $wp_query, $email_template; |
|
| 140 | + global $wp_query, $email_template; |
|
| 141 | 141 | |
| 142 | - $find = array( 'woothemes-sensei.php' ); |
|
| 143 | - $file = ''; |
|
| 142 | + $find = array( 'woothemes-sensei.php' ); |
|
| 143 | + $file = ''; |
|
| 144 | 144 | |
| 145 | - if ( isset( $email_template ) && $email_template ) { |
|
| 145 | + if ( isset( $email_template ) && $email_template ) { |
|
| 146 | 146 | |
| 147 | - $file = 'emails/' . $email_template; |
|
| 148 | - $find[] = $file; |
|
| 149 | - $find[] = Sensei()->template_url . $file; |
|
| 147 | + $file = 'emails/' . $email_template; |
|
| 148 | + $find[] = $file; |
|
| 149 | + $find[] = Sensei()->template_url . $file; |
|
| 150 | 150 | |
| 151 | - } elseif ( is_single() && get_post_type() == 'course' ) { |
|
| 151 | + } elseif ( is_single() && get_post_type() == 'course' ) { |
|
| 152 | 152 | |
| 153 | - if ( Sensei()->check_user_permissions( 'course-single' ) ) { |
|
| 153 | + if ( Sensei()->check_user_permissions( 'course-single' ) ) { |
|
| 154 | 154 | |
| 155 | - // possible backward compatible template include if theme overrides content-single-course.php |
|
| 156 | - // this template was removed in 1.9.0 and code all moved into the main single-course.php file |
|
| 157 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-course.php', true ); |
|
| 155 | + // possible backward compatible template include if theme overrides content-single-course.php |
|
| 156 | + // this template was removed in 1.9.0 and code all moved into the main single-course.php file |
|
| 157 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-course.php', true ); |
|
| 158 | 158 | |
| 159 | - $file = 'single-course.php'; |
|
| 160 | - $find[] = $file; |
|
| 161 | - $find[] = Sensei()->template_url . $file; |
|
| 159 | + $file = 'single-course.php'; |
|
| 160 | + $find[] = $file; |
|
| 161 | + $find[] = Sensei()->template_url . $file; |
|
| 162 | 162 | |
| 163 | - } else { |
|
| 163 | + } else { |
|
| 164 | 164 | |
| 165 | - // No Permissions Page |
|
| 166 | - return self::get_no_permission_template(); |
|
| 165 | + // No Permissions Page |
|
| 166 | + return self::get_no_permission_template(); |
|
| 167 | 167 | |
| 168 | - } // End If Statement |
|
| 168 | + } // End If Statement |
|
| 169 | 169 | |
| 170 | - } elseif ( is_single() && get_post_type() == 'lesson' ) { |
|
| 170 | + } elseif ( is_single() && get_post_type() == 'lesson' ) { |
|
| 171 | 171 | |
| 172 | - if ( Sensei()->check_user_permissions( 'lesson-single' ) ) { |
|
| 172 | + if ( Sensei()->check_user_permissions( 'lesson-single' ) ) { |
|
| 173 | 173 | |
| 174 | - // possible backward compatible template include if theme overrides content-single-lesson.php |
|
| 175 | - // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file |
|
| 176 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-lesson.php', true ); |
|
| 174 | + // possible backward compatible template include if theme overrides content-single-lesson.php |
|
| 175 | + // this template was removed in 1.9.0 and code all moved into the main single-lesson.php file |
|
| 176 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-lesson.php', true ); |
|
| 177 | 177 | |
| 178 | - $file = 'single-lesson.php'; |
|
| 179 | - $find[] = $file; |
|
| 180 | - $find[] = Sensei()->template_url . $file; |
|
| 178 | + $file = 'single-lesson.php'; |
|
| 179 | + $find[] = $file; |
|
| 180 | + $find[] = Sensei()->template_url . $file; |
|
| 181 | 181 | |
| 182 | - } else { |
|
| 182 | + } else { |
|
| 183 | 183 | |
| 184 | - // No Permissions Page |
|
| 185 | - return self::get_no_permission_template(); |
|
| 184 | + // No Permissions Page |
|
| 185 | + return self::get_no_permission_template(); |
|
| 186 | 186 | |
| 187 | - } // End If Statement |
|
| 187 | + } // End If Statement |
|
| 188 | 188 | |
| 189 | - } elseif ( is_single() && get_post_type() == 'quiz' ) { |
|
| 189 | + } elseif ( is_single() && get_post_type() == 'quiz' ) { |
|
| 190 | 190 | |
| 191 | - if ( Sensei()->check_user_permissions( 'quiz-single' ) ) { |
|
| 191 | + if ( Sensei()->check_user_permissions( 'quiz-single' ) ) { |
|
| 192 | 192 | |
| 193 | - // possible backward compatible template include if theme overrides content-single-quiz.php |
|
| 194 | - // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file |
|
| 195 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-quiz.php' , true); |
|
| 193 | + // possible backward compatible template include if theme overrides content-single-quiz.php |
|
| 194 | + // this template was removed in 1.9.0 and code all moved into the main single-quiz.php file |
|
| 195 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-quiz.php' , true); |
|
| 196 | 196 | |
| 197 | - $file = 'single-quiz.php'; |
|
| 198 | - $find[] = $file; |
|
| 199 | - $find[] = Sensei()->template_url . $file; |
|
| 197 | + $file = 'single-quiz.php'; |
|
| 198 | + $find[] = $file; |
|
| 199 | + $find[] = Sensei()->template_url . $file; |
|
| 200 | 200 | |
| 201 | - } else { |
|
| 201 | + } else { |
|
| 202 | 202 | |
| 203 | - // No Permissions Page |
|
| 204 | - return self::get_no_permission_template(); |
|
| 203 | + // No Permissions Page |
|
| 204 | + return self::get_no_permission_template(); |
|
| 205 | 205 | |
| 206 | - } // End If Statement |
|
| 206 | + } // End If Statement |
|
| 207 | 207 | |
| 208 | - } elseif ( is_single() && get_post_type() == 'sensei_message' ) { |
|
| 208 | + } elseif ( is_single() && get_post_type() == 'sensei_message' ) { |
|
| 209 | 209 | |
| 210 | - // possible backward compatible template include if theme overrides content-single-message.php |
|
| 211 | - // this template was removed in 1.9.0 and code all moved into the main single-message.php file |
|
| 212 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-message.php', true ); |
|
| 210 | + // possible backward compatible template include if theme overrides content-single-message.php |
|
| 211 | + // this template was removed in 1.9.0 and code all moved into the main single-message.php file |
|
| 212 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-single-message.php', true ); |
|
| 213 | 213 | |
| 214 | - $file = 'single-message.php'; |
|
| 215 | - $find[] = $file; |
|
| 216 | - $find[] = Sensei()->template_url . $file; |
|
| 214 | + $file = 'single-message.php'; |
|
| 215 | + $find[] = $file; |
|
| 216 | + $find[] = Sensei()->template_url . $file; |
|
| 217 | 217 | |
| 218 | - } elseif ( is_post_type_archive( 'course' ) |
|
| 219 | - || is_page( Sensei()->get_page_id( 'courses' ) ) |
|
| 220 | - || is_tax( 'course-category' )) { |
|
| 218 | + } elseif ( is_post_type_archive( 'course' ) |
|
| 219 | + || is_page( Sensei()->get_page_id( 'courses' ) ) |
|
| 220 | + || is_tax( 'course-category' )) { |
|
| 221 | 221 | |
| 222 | - // possible backward compatible template include if theme overrides 'taxonomy-course-category' |
|
| 223 | - // this template was removed in 1.9.0 and replaced by archive-course.php |
|
| 224 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-course-category.php'); |
|
| 222 | + // possible backward compatible template include if theme overrides 'taxonomy-course-category' |
|
| 223 | + // this template was removed in 1.9.0 and replaced by archive-course.php |
|
| 224 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-course-category.php'); |
|
| 225 | 225 | |
| 226 | - $file = 'archive-course.php'; |
|
| 227 | - $find[] = $file; |
|
| 228 | - $find[] = Sensei()->template_url . $file; |
|
| 226 | + $file = 'archive-course.php'; |
|
| 227 | + $find[] = $file; |
|
| 228 | + $find[] = Sensei()->template_url . $file; |
|
| 229 | 229 | |
| 230 | - } elseif ( is_post_type_archive( 'sensei_message' ) ) { |
|
| 230 | + } elseif ( is_post_type_archive( 'sensei_message' ) ) { |
|
| 231 | 231 | |
| 232 | - $file = 'archive-message.php'; |
|
| 233 | - $find[] = $file; |
|
| 234 | - $find[] = Sensei()->template_url . $file; |
|
| 232 | + $file = 'archive-message.php'; |
|
| 233 | + $find[] = $file; |
|
| 234 | + $find[] = Sensei()->template_url . $file; |
|
| 235 | 235 | |
| 236 | - } elseif( is_tax( 'lesson-tag' ) ) { |
|
| 236 | + } elseif( is_tax( 'lesson-tag' ) ) { |
|
| 237 | 237 | |
| 238 | - // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php' |
|
| 239 | - // this template was removed in 1.9.0 and replaced by archive-lesson.php |
|
| 240 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-lesson-tag.php' ); |
|
| 238 | + // possible backward compatible template include if theme overrides 'taxonomy-lesson-tag.php' |
|
| 239 | + // this template was removed in 1.9.0 and replaced by archive-lesson.php |
|
| 240 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'taxonomy-lesson-tag.php' ); |
|
| 241 | 241 | |
| 242 | - $file = 'archive-lesson.php'; |
|
| 243 | - $find[] = $file; |
|
| 244 | - $find[] = Sensei()->template_url . $file; |
|
| 242 | + $file = 'archive-lesson.php'; |
|
| 243 | + $find[] = $file; |
|
| 244 | + $find[] = Sensei()->template_url . $file; |
|
| 245 | 245 | |
| 246 | - } elseif ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
| 246 | + } elseif ( isset( $wp_query->query_vars['learner_profile'] ) ) { |
|
| 247 | 247 | |
| 248 | - // Override for sites with static home page |
|
| 249 | - $wp_query->is_home = false; |
|
| 248 | + // Override for sites with static home page |
|
| 249 | + $wp_query->is_home = false; |
|
| 250 | 250 | |
| 251 | - $file = 'learner-profile.php'; |
|
| 252 | - $find[] = $file; |
|
| 253 | - $find[] = Sensei()->template_url . $file; |
|
| 251 | + $file = 'learner-profile.php'; |
|
| 252 | + $find[] = $file; |
|
| 253 | + $find[] = Sensei()->template_url . $file; |
|
| 254 | 254 | |
| 255 | - } elseif ( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 255 | + } elseif ( isset( $wp_query->query_vars['course_results'] ) ) { |
|
| 256 | 256 | |
| 257 | - // Override for sites with static home page |
|
| 258 | - $wp_query->is_home = false; |
|
| 257 | + // Override for sites with static home page |
|
| 258 | + $wp_query->is_home = false; |
|
| 259 | 259 | |
| 260 | - $file = 'course-results.php'; |
|
| 261 | - $find[] = $file; |
|
| 262 | - $find[] = Sensei()->template_url . $file; |
|
| 260 | + $file = 'course-results.php'; |
|
| 261 | + $find[] = $file; |
|
| 262 | + $find[] = Sensei()->template_url . $file; |
|
| 263 | 263 | |
| 264 | - }elseif( is_author() |
|
| 265 | - && Sensei_Teacher::is_a_teacher( get_query_var('author') ) |
|
| 266 | - && ! user_can( get_query_var('author'), 'manage_options' ) ){ |
|
| 264 | + }elseif( is_author() |
|
| 265 | + && Sensei_Teacher::is_a_teacher( get_query_var('author') ) |
|
| 266 | + && ! user_can( get_query_var('author'), 'manage_options' ) ){ |
|
| 267 | 267 | |
| 268 | - $file = 'teacher-archive.php'; |
|
| 269 | - $find[] = $file; |
|
| 270 | - $find[] = Sensei()->template_url . $file; |
|
| 268 | + $file = 'teacher-archive.php'; |
|
| 269 | + $find[] = $file; |
|
| 270 | + $find[] = Sensei()->template_url . $file; |
|
| 271 | 271 | |
| 272 | - } // Load the template file |
|
| 272 | + } // Load the template file |
|
| 273 | 273 | |
| 274 | - if ( $file ) { |
|
| 274 | + if ( $file ) { |
|
| 275 | 275 | |
| 276 | - $template = locate_template( $find ); |
|
| 277 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 276 | + $template = locate_template( $find ); |
|
| 277 | + if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 278 | 278 | |
| 279 | - } // End If Statement |
|
| 279 | + } // End If Statement |
|
| 280 | 280 | |
| 281 | - return $template; |
|
| 281 | + return $template; |
|
| 282 | 282 | |
| 283 | - } // End template_loader() |
|
| 283 | + } // End template_loader() |
|
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * This function loads the no-permissions template for users with no access |
|
| 287 | - * if a Sensei template was loaded. |
|
| 288 | - * |
|
| 289 | - * This function doesn't determine the permissions. Permissions must be determined |
|
| 290 | - * before loading this function as it only gets the template. |
|
| 291 | - * |
|
| 292 | - * This function also checks the user theme for overrides to ensure the right template |
|
| 293 | - * file is returned. |
|
| 294 | - * |
|
| 295 | - * @since 1.9.0 |
|
| 296 | - */ |
|
| 297 | - public static function get_no_permission_template( ){ |
|
| 285 | + /** |
|
| 286 | + * This function loads the no-permissions template for users with no access |
|
| 287 | + * if a Sensei template was loaded. |
|
| 288 | + * |
|
| 289 | + * This function doesn't determine the permissions. Permissions must be determined |
|
| 290 | + * before loading this function as it only gets the template. |
|
| 291 | + * |
|
| 292 | + * This function also checks the user theme for overrides to ensure the right template |
|
| 293 | + * file is returned. |
|
| 294 | + * |
|
| 295 | + * @since 1.9.0 |
|
| 296 | + */ |
|
| 297 | + public static function get_no_permission_template( ){ |
|
| 298 | 298 | |
| 299 | - // possible backward compatible template loading |
|
| 300 | - // this template was removed in 1.9.0 and code all moved into the no-permissions.php file |
|
| 301 | - self::locate_and_load_template_overrides( Sensei()->template_url . 'content-no-permissions.php', true ); |
|
| 299 | + // possible backward compatible template loading |
|
| 300 | + // this template was removed in 1.9.0 and code all moved into the no-permissions.php file |
|
| 301 | + self::locate_and_load_template_overrides( Sensei()->template_url . 'content-no-permissions.php', true ); |
|
| 302 | 302 | |
| 303 | - $file = 'no-permissions.php'; |
|
| 304 | - $find[] = $file; |
|
| 305 | - $find[] = Sensei()->template_url . $file; |
|
| 303 | + $file = 'no-permissions.php'; |
|
| 304 | + $find[] = $file; |
|
| 305 | + $find[] = Sensei()->template_url . $file; |
|
| 306 | 306 | |
| 307 | - $template = locate_template( $find ); |
|
| 308 | - if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 307 | + $template = locate_template( $find ); |
|
| 308 | + if ( ! $template ) $template = Sensei()->plugin_path() . '/templates/' . $file; |
|
| 309 | 309 | |
| 310 | - return $template; |
|
| 310 | + return $template; |
|
| 311 | 311 | |
| 312 | - } |
|
| 312 | + } |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * This function is specifically created for loading template files from the theme. |
|
| 316 | - * |
|
| 317 | - * This function checks if the user has overwritten the templates like in their theme. If they have it in their theme it will load the header and the footer |
|
| 318 | - * around the singular content file from their theme and exit. |
|
| 319 | - * |
|
| 320 | - * If none is found this function will do nothing. If a template is found this funciton |
|
| 321 | - * will exit execution of the script an not continue. |
|
| 322 | - * |
|
| 323 | - * @since 1.9.0 |
|
| 324 | - * @param string $template |
|
| 325 | - * @param bool $load_header_footer should the file be wrapped in between header and footer? Default: true |
|
| 326 | - */ |
|
| 327 | - public static function locate_and_load_template_overrides( $template = '', $load_header_footer = false ){ |
|
| 314 | + /** |
|
| 315 | + * This function is specifically created for loading template files from the theme. |
|
| 316 | + * |
|
| 317 | + * This function checks if the user has overwritten the templates like in their theme. If they have it in their theme it will load the header and the footer |
|
| 318 | + * around the singular content file from their theme and exit. |
|
| 319 | + * |
|
| 320 | + * If none is found this function will do nothing. If a template is found this funciton |
|
| 321 | + * will exit execution of the script an not continue. |
|
| 322 | + * |
|
| 323 | + * @since 1.9.0 |
|
| 324 | + * @param string $template |
|
| 325 | + * @param bool $load_header_footer should the file be wrapped in between header and footer? Default: true |
|
| 326 | + */ |
|
| 327 | + public static function locate_and_load_template_overrides( $template = '', $load_header_footer = false ){ |
|
| 328 | 328 | |
| 329 | - $found_template = locate_template( array( $template ) ); |
|
| 330 | - if( $found_template ){ |
|
| 329 | + $found_template = locate_template( array( $template ) ); |
|
| 330 | + if( $found_template ){ |
|
| 331 | 331 | |
| 332 | - if( $load_header_footer ){ |
|
| 332 | + if( $load_header_footer ){ |
|
| 333 | 333 | |
| 334 | - get_sensei_header(); |
|
| 335 | - include( $found_template ); |
|
| 336 | - get_sensei_footer(); |
|
| 337 | - |
|
| 338 | - }else{ |
|
| 339 | - |
|
| 340 | - include( $found_template ); |
|
| 341 | - |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - exit; |
|
| 334 | + get_sensei_header(); |
|
| 335 | + include( $found_template ); |
|
| 336 | + get_sensei_footer(); |
|
| 337 | + |
|
| 338 | + }else{ |
|
| 339 | + |
|
| 340 | + include( $found_template ); |
|
| 341 | + |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + exit; |
|
| 345 | 345 | |
| 346 | - } |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - } |
|
| 348 | + } |
|
| 349 | 349 | |
| 350 | 350 | |
| 351 | - /** |
|
| 352 | - * Hooks the deprecated archive content hook into the hook again just in |
|
| 353 | - * case other developers have used it. |
|
| 354 | - * |
|
| 355 | - * @deprecated since 1.9.0 |
|
| 356 | - */ |
|
| 357 | - public static function deprecated_archive_course_content_hook(){ |
|
| 358 | - |
|
| 359 | - sensei_do_deprecated_action( 'sensei_course_archive_main_content','1.9.0', 'sensei_loop_course_before' ); |
|
| 360 | - |
|
| 361 | - }// end deprecated_archive_hook |
|
| 351 | + /** |
|
| 352 | + * Hooks the deprecated archive content hook into the hook again just in |
|
| 353 | + * case other developers have used it. |
|
| 354 | + * |
|
| 355 | + * @deprecated since 1.9.0 |
|
| 356 | + */ |
|
| 357 | + public static function deprecated_archive_course_content_hook(){ |
|
| 358 | + |
|
| 359 | + sensei_do_deprecated_action( 'sensei_course_archive_main_content','1.9.0', 'sensei_loop_course_before' ); |
|
| 360 | + |
|
| 361 | + }// end deprecated_archive_hook |
|
| 362 | 362 | |
| 363 | - /** |
|
| 364 | - * A generic function for echoing the post title |
|
| 365 | - * |
|
| 366 | - * @since 1.9.0 |
|
| 367 | - * @param WP_Post $post |
|
| 368 | - */ |
|
| 369 | - public static function the_title( $post ){ |
|
| 370 | - |
|
| 371 | - // ID passed in |
|
| 372 | - if( is_numeric( $post ) ){ |
|
| 373 | - $post = get_post( $post ); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Filter the template html tag for the title |
|
| 378 | - * |
|
| 379 | - * @since 1.9.0 |
|
| 380 | - * |
|
| 381 | - * @param $title_html_tag default is 'h3' |
|
| 382 | - */ |
|
| 383 | - $title_html_tag = apply_filters('sensei_the_title_html_tag','h3'); |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Filter the title classes |
|
| 387 | - * |
|
| 388 | - * @since 1.9.0 |
|
| 389 | - * @param string $title_classes defaults to $post_type-title |
|
| 390 | - */ |
|
| 391 | - $title_classes = apply_filters('sensei_the_title_classes', $post->post_type . '-title' ); |
|
| 392 | - |
|
| 393 | - $html= ''; |
|
| 394 | - $html .= '<'. $title_html_tag .' class="'. $title_classes .'" >'; |
|
| 395 | - $html .= '<a href="' . get_permalink( $post->ID ) . '" >'; |
|
| 396 | - $html .= $post->post_title ; |
|
| 397 | - $html .= '</a>'; |
|
| 398 | - $html .= '</'. $title_html_tag. '>'; |
|
| 399 | - echo $html; |
|
| 400 | - |
|
| 401 | - }// end the title |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * This function adds the hooks inside and above the single course content for |
|
| 405 | - * backwards compatibility sake. |
|
| 406 | - * |
|
| 407 | - * @since 1.9.0 |
|
| 408 | - * @deprecated 1.9.0 |
|
| 409 | - */ |
|
| 410 | - public static function deprecated_single_course_inside_before_hooks(){ |
|
| 411 | - |
|
| 412 | - sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 413 | - sensei_do_deprecated_action('sensei_course_single_title','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 414 | - sensei_do_deprecated_action('sensei_course_single_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 415 | - |
|
| 416 | - }// end deprecated_single_course_inside_before_hooks |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * This function adds the hooks to sensei_course_single_lessons for |
|
| 420 | - * backwards compatibility sake. and provides developers with an alternative. |
|
| 421 | - * |
|
| 422 | - * @since 1.9.0 |
|
| 423 | - * @deprecated 1.9.0 |
|
| 424 | - */ |
|
| 425 | - public static function deprecate_sensei_course_single_lessons_hook(){ |
|
| 363 | + /** |
|
| 364 | + * A generic function for echoing the post title |
|
| 365 | + * |
|
| 366 | + * @since 1.9.0 |
|
| 367 | + * @param WP_Post $post |
|
| 368 | + */ |
|
| 369 | + public static function the_title( $post ){ |
|
| 370 | + |
|
| 371 | + // ID passed in |
|
| 372 | + if( is_numeric( $post ) ){ |
|
| 373 | + $post = get_post( $post ); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Filter the template html tag for the title |
|
| 378 | + * |
|
| 379 | + * @since 1.9.0 |
|
| 380 | + * |
|
| 381 | + * @param $title_html_tag default is 'h3' |
|
| 382 | + */ |
|
| 383 | + $title_html_tag = apply_filters('sensei_the_title_html_tag','h3'); |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Filter the title classes |
|
| 387 | + * |
|
| 388 | + * @since 1.9.0 |
|
| 389 | + * @param string $title_classes defaults to $post_type-title |
|
| 390 | + */ |
|
| 391 | + $title_classes = apply_filters('sensei_the_title_classes', $post->post_type . '-title' ); |
|
| 392 | + |
|
| 393 | + $html= ''; |
|
| 394 | + $html .= '<'. $title_html_tag .' class="'. $title_classes .'" >'; |
|
| 395 | + $html .= '<a href="' . get_permalink( $post->ID ) . '" >'; |
|
| 396 | + $html .= $post->post_title ; |
|
| 397 | + $html .= '</a>'; |
|
| 398 | + $html .= '</'. $title_html_tag. '>'; |
|
| 399 | + echo $html; |
|
| 400 | + |
|
| 401 | + }// end the title |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * This function adds the hooks inside and above the single course content for |
|
| 405 | + * backwards compatibility sake. |
|
| 406 | + * |
|
| 407 | + * @since 1.9.0 |
|
| 408 | + * @deprecated 1.9.0 |
|
| 409 | + */ |
|
| 410 | + public static function deprecated_single_course_inside_before_hooks(){ |
|
| 411 | + |
|
| 412 | + sensei_do_deprecated_action('sensei_course_image','1.9.0', 'sensei_single_course_content_inside_before', array( get_the_ID()) ); |
|
| 413 | + sensei_do_deprecated_action('sensei_course_single_title','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 414 | + sensei_do_deprecated_action('sensei_course_single_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 415 | + |
|
| 416 | + }// end deprecated_single_course_inside_before_hooks |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * This function adds the hooks to sensei_course_single_lessons for |
|
| 420 | + * backwards compatibility sake. and provides developers with an alternative. |
|
| 421 | + * |
|
| 422 | + * @since 1.9.0 |
|
| 423 | + * @deprecated 1.9.0 |
|
| 424 | + */ |
|
| 425 | + public static function deprecate_sensei_course_single_lessons_hook(){ |
|
| 426 | 426 | |
| 427 | - sensei_do_deprecated_action('sensei_course_single_lessons','1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 427 | + sensei_do_deprecated_action('sensei_course_single_lessons','1.9.0', 'sensei_single_course_content_inside_after'); |
|
| 428 | 428 | |
| 429 | - }// deprecate_sensei_course_single_lessons_hook |
|
| 429 | + }// deprecate_sensei_course_single_lessons_hook |
|
| 430 | 430 | |
| 431 | - /** |
|
| 432 | - * Deprecated all deprecated_single_main_content_hook hooked actions. |
|
| 433 | - * |
|
| 434 | - * The content must be dealt with inside the respective templates. |
|
| 435 | - * |
|
| 436 | - * @since 1.9.0 |
|
| 437 | - * @deprecated 1.9.0 |
|
| 438 | - */ |
|
| 439 | - public static function deprecated_single_main_content_hook(){ |
|
| 431 | + /** |
|
| 432 | + * Deprecated all deprecated_single_main_content_hook hooked actions. |
|
| 433 | + * |
|
| 434 | + * The content must be dealt with inside the respective templates. |
|
| 435 | + * |
|
| 436 | + * @since 1.9.0 |
|
| 437 | + * @deprecated 1.9.0 |
|
| 438 | + */ |
|
| 439 | + public static function deprecated_single_main_content_hook(){ |
|
| 440 | 440 | |
| 441 | - if( is_singular( 'course' ) ) { |
|
| 441 | + if( is_singular( 'course' ) ) { |
|
| 442 | 442 | |
| 443 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_course_content_inside_before or sensei_single_course_content_inside_after'); |
|
| 444 | - |
|
| 445 | - } elseif( is_singular( 'message' ) ){ |
|
| 446 | - |
|
| 447 | - sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_message_content_inside_before or sensei_single_message_content_inside_after'); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - }// end deprecated_single_course_single_main_content_hook |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Deprecate the old sensei modules |
|
| 454 | - * @since 1.9.0 |
|
| 455 | - * @deprecated since 1.9.0 |
|
| 456 | - */ |
|
| 457 | - public static function deprecate_module_before_hook(){ |
|
| 443 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_course_content_inside_before or sensei_single_course_content_inside_after'); |
|
| 444 | + |
|
| 445 | + } elseif( is_singular( 'message' ) ){ |
|
| 446 | + |
|
| 447 | + sensei_do_deprecated_action('sensei_single_main_content', '1.9.0', 'sensei_single_message_content_inside_before or sensei_single_message_content_inside_after'); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + }// end deprecated_single_course_single_main_content_hook |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Deprecate the old sensei modules |
|
| 454 | + * @since 1.9.0 |
|
| 455 | + * @deprecated since 1.9.0 |
|
| 456 | + */ |
|
| 457 | + public static function deprecate_module_before_hook(){ |
|
| 458 | 458 | |
| 459 | - sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0','sensei_single_course_modules_after' ); |
|
| 459 | + sensei_do_deprecated_action('sensei_modules_page_before', '1.9.0','sensei_single_course_modules_after' ); |
|
| 460 | 460 | |
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Deprecate the old sensei modules after hooks |
|
| 465 | - * @since 1.9.0 |
|
| 466 | - * @deprecated since 1.9.0 |
|
| 467 | - */ |
|
| 468 | - public static function deprecate_module_after_hook(){ |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Deprecate the old sensei modules after hooks |
|
| 465 | + * @since 1.9.0 |
|
| 466 | + * @deprecated since 1.9.0 |
|
| 467 | + */ |
|
| 468 | + public static function deprecate_module_after_hook(){ |
|
| 469 | 469 | |
| 470 | - sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0','sensei_single_course_modules_after' ); |
|
| 470 | + sensei_do_deprecated_action('sensei_modules_page_after', '1.9.0','sensei_single_course_modules_after' ); |
|
| 471 | 471 | |
| 472 | - } |
|
| 472 | + } |
|
| 473 | 473 | |
| 474 | - /** |
|
| 475 | - * Deprecate the single message hooks for post types. |
|
| 476 | - * |
|
| 477 | - * @since 1.9.0 |
|
| 478 | - * @deprecated since 1.9.0 |
|
| 479 | - */ |
|
| 480 | - public static function deprecate_all_post_type_single_title_hooks(){ |
|
| 474 | + /** |
|
| 475 | + * Deprecate the single message hooks for post types. |
|
| 476 | + * |
|
| 477 | + * @since 1.9.0 |
|
| 478 | + * @deprecated since 1.9.0 |
|
| 479 | + */ |
|
| 480 | + public static function deprecate_all_post_type_single_title_hooks(){ |
|
| 481 | 481 | |
| 482 | - if( is_singular( 'sensei_message' ) ){ |
|
| 482 | + if( is_singular( 'sensei_message' ) ){ |
|
| 483 | 483 | |
| 484 | - sensei_do_deprecated_action( 'sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before' ); |
|
| 484 | + sensei_do_deprecated_action( 'sensei_message_single_title', '1.9.0', 'sensei_single_message_content_inside_before' ); |
|
| 485 | 485 | |
| 486 | - } |
|
| 486 | + } |
|
| 487 | 487 | |
| 488 | - } |
|
| 488 | + } |
|
| 489 | 489 | |
| 490 | - /** |
|
| 491 | - * course_single_meta function. |
|
| 492 | - * |
|
| 493 | - * @access public |
|
| 494 | - * @return void |
|
| 495 | - * @deprecated since 1.9.0 |
|
| 496 | - */ |
|
| 497 | - public static function deprecate_course_single_meta_hooks() { |
|
| 490 | + /** |
|
| 491 | + * course_single_meta function. |
|
| 492 | + * |
|
| 493 | + * @access public |
|
| 494 | + * @return void |
|
| 495 | + * @deprecated since 1.9.0 |
|
| 496 | + */ |
|
| 497 | + public static function deprecate_course_single_meta_hooks() { |
|
| 498 | 498 | |
| 499 | - // deprecate all these hooks |
|
| 500 | - sensei_do_deprecated_action('sensei_course_start','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 501 | - sensei_do_deprecated_action('sensei_woocommerce_in_cart_message','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 502 | - sensei_do_deprecated_action('sensei_course_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 503 | - sensei_do_deprecated_action('sensei_course_meta_video','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 499 | + // deprecate all these hooks |
|
| 500 | + sensei_do_deprecated_action('sensei_course_start','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 501 | + sensei_do_deprecated_action('sensei_woocommerce_in_cart_message','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 502 | + sensei_do_deprecated_action('sensei_course_meta','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 503 | + sensei_do_deprecated_action('sensei_course_meta_video','1.9.0', 'sensei_single_course_content_inside_before' ); |
|
| 504 | 504 | |
| 505 | - } // End deprecate_course_single_meta_hooks |
|
| 505 | + } // End deprecate_course_single_meta_hooks |
|
| 506 | 506 | |
| 507 | - /** |
|
| 508 | - * Run the deprecated hooks on the single lesson page |
|
| 509 | - * @deprecated since 1.9.0 |
|
| 510 | - */ |
|
| 511 | - public static function deprecate_single_lesson_breadcrumbs_and_comments_hooks() { |
|
| 507 | + /** |
|
| 508 | + * Run the deprecated hooks on the single lesson page |
|
| 509 | + * @deprecated since 1.9.0 |
|
| 510 | + */ |
|
| 511 | + public static function deprecate_single_lesson_breadcrumbs_and_comments_hooks() { |
|
| 512 | 512 | |
| 513 | - if( is_singular( 'lesson' ) ){ |
|
| 513 | + if( is_singular( 'lesson' ) ){ |
|
| 514 | 514 | |
| 515 | - sensei_do_deprecated_action( 'sensei_breadcrumb','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 516 | - sensei_do_deprecated_action( 'sensei_comments','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 515 | + sensei_do_deprecated_action( 'sensei_breadcrumb','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 516 | + sensei_do_deprecated_action( 'sensei_comments','1.9.0','sensei_after_main_content', get_the_ID() ); |
|
| 517 | 517 | |
| 518 | - } |
|
| 518 | + } |
|
| 519 | 519 | |
| 520 | - }// end sensei_deprecate_single_lesson_breadcrumbs_and_comments_hooks |
|
| 520 | + }// end sensei_deprecate_single_lesson_breadcrumbs_and_comments_hooks |
|
| 521 | 521 | |
| 522 | - /** |
|
| 523 | - * Deprecate the hook sensei_lesson_course_signup. |
|
| 524 | - * |
|
| 525 | - * The hook content will be linked directly on the recommended |
|
| 526 | - * sensei_single_lesson_content_inside_after |
|
| 527 | - * |
|
| 528 | - * @deprecated since 1.9.0 |
|
| 529 | - */ |
|
| 530 | - public static function deprecate_sensei_lesson_course_signup_hook(){ |
|
| 522 | + /** |
|
| 523 | + * Deprecate the hook sensei_lesson_course_signup. |
|
| 524 | + * |
|
| 525 | + * The hook content will be linked directly on the recommended |
|
| 526 | + * sensei_single_lesson_content_inside_after |
|
| 527 | + * |
|
| 528 | + * @deprecated since 1.9.0 |
|
| 529 | + */ |
|
| 530 | + public static function deprecate_sensei_lesson_course_signup_hook(){ |
|
| 531 | 531 | |
| 532 | - $lesson_course_id = get_post_meta( get_the_ID(), '_lesson_course', true ); |
|
| 533 | - $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 532 | + $lesson_course_id = get_post_meta( get_the_ID(), '_lesson_course', true ); |
|
| 533 | + $user_taking_course = Sensei_Utils::user_started_course( $lesson_course_id, get_current_user_id() ); |
|
| 534 | 534 | |
| 535 | - if( !$user_taking_course ) { |
|
| 535 | + if( !$user_taking_course ) { |
|
| 536 | 536 | |
| 537 | - sensei_do_deprecated_action( 'sensei_lesson_course_signup','1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id ); |
|
| 537 | + sensei_do_deprecated_action( 'sensei_lesson_course_signup','1.9.0', 'sensei_single_lesson_content_inside_after', $lesson_course_id ); |
|
| 538 | 538 | |
| 539 | - } |
|
| 540 | - }// end deprecate_sensei_lesson_course_signup_hook |
|
| 539 | + } |
|
| 540 | + }// end deprecate_sensei_lesson_course_signup_hook |
|
| 541 | 541 | |
| 542 | - /** |
|
| 543 | - * Running the deprecated hook: sensei_lesson_single_meta |
|
| 544 | - * |
|
| 545 | - * @since 1.9.0 |
|
| 546 | - * @deprecated since 1.9.0 |
|
| 547 | - */ |
|
| 548 | - public static function deprecate_sensei_lesson_single_meta_hook(){ |
|
| 542 | + /** |
|
| 543 | + * Running the deprecated hook: sensei_lesson_single_meta |
|
| 544 | + * |
|
| 545 | + * @since 1.9.0 |
|
| 546 | + * @deprecated since 1.9.0 |
|
| 547 | + */ |
|
| 548 | + public static function deprecate_sensei_lesson_single_meta_hook(){ |
|
| 549 | 549 | |
| 550 | - if ( sensei_can_user_view_lesson() ) { |
|
| 550 | + if ( sensei_can_user_view_lesson() ) { |
|
| 551 | 551 | |
| 552 | - sensei_do_deprecated_action( 'sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after' ); |
|
| 552 | + sensei_do_deprecated_action( 'sensei_lesson_single_meta', '1.9.0', 'sensei_single_lesson_content_inside_after' ); |
|
| 553 | 553 | |
| 554 | 554 | |
| 555 | - } |
|
| 555 | + } |
|
| 556 | 556 | |
| 557 | - }// end deprecate_sensei_lesson_single_meta_hook |
|
| 557 | + }// end deprecate_sensei_lesson_single_meta_hook |
|
| 558 | 558 | |
| 559 | - /** |
|
| 560 | - * Deprecate the sensei lesson single title hook |
|
| 561 | - * @deprecated since 1.9.0 |
|
| 562 | - */ |
|
| 563 | - public static function deprecate_sensei_lesson_single_title(){ |
|
| 559 | + /** |
|
| 560 | + * Deprecate the sensei lesson single title hook |
|
| 561 | + * @deprecated since 1.9.0 |
|
| 562 | + */ |
|
| 563 | + public static function deprecate_sensei_lesson_single_title(){ |
|
| 564 | 564 | |
| 565 | - sensei_do_deprecated_action( 'sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 565 | + sensei_do_deprecated_action( 'sensei_lesson_single_title', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 566 | 566 | |
| 567 | - }// end deprecate_sensei_lesson_single_title |
|
| 567 | + }// end deprecate_sensei_lesson_single_title |
|
| 568 | 568 | |
| 569 | - /** |
|
| 570 | - * hook in the deperecated single main content to the lesson |
|
| 571 | - * @deprecated since 1.9.0 |
|
| 572 | - */ |
|
| 573 | - public static function deprecate_lesson_single_main_content_hook(){ |
|
| 569 | + /** |
|
| 570 | + * hook in the deperecated single main content to the lesson |
|
| 571 | + * @deprecated since 1.9.0 |
|
| 572 | + */ |
|
| 573 | + public static function deprecate_lesson_single_main_content_hook(){ |
|
| 574 | 574 | |
| 575 | - sensei_do_deprecated_action( 'sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before' ); |
|
| 575 | + sensei_do_deprecated_action( 'sensei_single_main_content', '1.9.0', 'sensei_single_lesson_content_inside_before' ); |
|
| 576 | 576 | |
| 577 | - }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 577 | + }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 578 | 578 | |
| 579 | - /** |
|
| 580 | - * hook in the deperecated single main content to the lesson |
|
| 581 | - * @deprecated since 1.9.0 |
|
| 582 | - */ |
|
| 583 | - public static function deprecate_lesson_image_hook(){ |
|
| 579 | + /** |
|
| 580 | + * hook in the deperecated single main content to the lesson |
|
| 581 | + * @deprecated since 1.9.0 |
|
| 582 | + */ |
|
| 583 | + public static function deprecate_lesson_image_hook(){ |
|
| 584 | 584 | |
| 585 | - sensei_do_deprecated_action( 'sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 585 | + sensei_do_deprecated_action( 'sensei_lesson_image', '1.9.0', 'sensei_single_lesson_content_inside_before', get_the_ID() ); |
|
| 586 | 586 | |
| 587 | - }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 587 | + }// end sensei_deprecate_lesson_single_main_content_hook |
|
| 588 | 588 | |
| 589 | - /** |
|
| 590 | - * hook in the deprecated sensei_login_form hook for backwards |
|
| 591 | - * compatibility |
|
| 592 | - * |
|
| 593 | - * @since 1.9.0 |
|
| 594 | - * @deprecated since 1.9.0 |
|
| 595 | - */ |
|
| 596 | - public static function deprecate_sensei_login_form_hook(){ |
|
| 589 | + /** |
|
| 590 | + * hook in the deprecated sensei_login_form hook for backwards |
|
| 591 | + * compatibility |
|
| 592 | + * |
|
| 593 | + * @since 1.9.0 |
|
| 594 | + * @deprecated since 1.9.0 |
|
| 595 | + */ |
|
| 596 | + public static function deprecate_sensei_login_form_hook(){ |
|
| 597 | 597 | |
| 598 | - sensei_do_deprecated_action( 'sensei_login_form', '1.9.0', 'sensei_login_form_before' ); |
|
| 598 | + sensei_do_deprecated_action( 'sensei_login_form', '1.9.0', 'sensei_login_form_before' ); |
|
| 599 | 599 | |
| 600 | - } // end deprecate_sensei_login_form_hook |
|
| 600 | + } // end deprecate_sensei_login_form_hook |
|
| 601 | 601 | |
| 602 | - /** |
|
| 603 | - * Fire the sensei_complete_course action. |
|
| 604 | - * |
|
| 605 | - * This is just a backwards compatible function to add the action |
|
| 606 | - * to a template. This should not be used as the function from this |
|
| 607 | - * hook will be added directly to my-courses page via one of the hooks there. |
|
| 608 | - * |
|
| 609 | - * @since 1.9.0 |
|
| 610 | - */ |
|
| 611 | - public static function fire_sensei_complete_course_hook(){ |
|
| 602 | + /** |
|
| 603 | + * Fire the sensei_complete_course action. |
|
| 604 | + * |
|
| 605 | + * This is just a backwards compatible function to add the action |
|
| 606 | + * to a template. This should not be used as the function from this |
|
| 607 | + * hook will be added directly to my-courses page via one of the hooks there. |
|
| 608 | + * |
|
| 609 | + * @since 1.9.0 |
|
| 610 | + */ |
|
| 611 | + public static function fire_sensei_complete_course_hook(){ |
|
| 612 | 612 | |
| 613 | - do_action( 'sensei_complete_course' ); |
|
| 613 | + do_action( 'sensei_complete_course' ); |
|
| 614 | 614 | |
| 615 | - } //fire_sensei_complete_course_hook |
|
| 615 | + } //fire_sensei_complete_course_hook |
|
| 616 | 616 | |
| 617 | - /** |
|
| 618 | - * Fire the frontend message hook |
|
| 619 | - * |
|
| 620 | - * @since 1.9.0 |
|
| 621 | - */ |
|
| 622 | - public static function fire_frontend_messages_hook(){ |
|
| 617 | + /** |
|
| 618 | + * Fire the frontend message hook |
|
| 619 | + * |
|
| 620 | + * @since 1.9.0 |
|
| 621 | + */ |
|
| 622 | + public static function fire_frontend_messages_hook(){ |
|
| 623 | 623 | |
| 624 | - do_action( 'sensei_frontend_messages' ); |
|
| 624 | + do_action( 'sensei_frontend_messages' ); |
|
| 625 | 625 | |
| 626 | - }// end sensei_complete_course_action |
|
| 626 | + }// end sensei_complete_course_action |
|
| 627 | 627 | |
| 628 | - /** |
|
| 629 | - * deprecate the sensei_before_user_course_content hook in favor |
|
| 630 | - * of sensei_my_courses_content_inside_before. |
|
| 631 | - * |
|
| 632 | - * @deprected since 1.9.0 |
|
| 633 | - */ |
|
| 634 | - public static function deprecate_sensei_before_user_course_content_hook(){ |
|
| 628 | + /** |
|
| 629 | + * deprecate the sensei_before_user_course_content hook in favor |
|
| 630 | + * of sensei_my_courses_content_inside_before. |
|
| 631 | + * |
|
| 632 | + * @deprected since 1.9.0 |
|
| 633 | + */ |
|
| 634 | + public static function deprecate_sensei_before_user_course_content_hook(){ |
|
| 635 | 635 | |
| 636 | - sensei_do_deprecated_action( 'sensei_before_user_course_content','1.9.0', 'sensei_my_courses_content_inside_before' , wp_get_current_user() ); |
|
| 636 | + sensei_do_deprecated_action( 'sensei_before_user_course_content','1.9.0', 'sensei_my_courses_content_inside_before' , wp_get_current_user() ); |
|
| 637 | 637 | |
| 638 | - }// deprecate_sensei_before_user_course_content_hook |
|
| 638 | + }// deprecate_sensei_before_user_course_content_hook |
|
| 639 | 639 | |
| 640 | - /** |
|
| 641 | - * deprecate the sensei_before_user_course_content hook in favor |
|
| 642 | - * of sensei_my_courses_content_inside_after hook. |
|
| 643 | - * |
|
| 644 | - * @deprected since 1.9.0 |
|
| 645 | - */ |
|
| 646 | - public static function deprecate_sensei_after_user_course_content_hook(){ |
|
| 640 | + /** |
|
| 641 | + * deprecate the sensei_before_user_course_content hook in favor |
|
| 642 | + * of sensei_my_courses_content_inside_after hook. |
|
| 643 | + * |
|
| 644 | + * @deprected since 1.9.0 |
|
| 645 | + */ |
|
| 646 | + public static function deprecate_sensei_after_user_course_content_hook(){ |
|
| 647 | 647 | |
| 648 | - sensei_do_deprecated_action( 'sensei_after_user_course_content','1.9.0', 'sensei_my_courses_content_inside_after' , wp_get_current_user() ); |
|
| 648 | + sensei_do_deprecated_action( 'sensei_after_user_course_content','1.9.0', 'sensei_my_courses_content_inside_after' , wp_get_current_user() ); |
|
| 649 | 649 | |
| 650 | - }// deprecate_sensei_after_user_course_content_hook |
|
| 650 | + }// deprecate_sensei_after_user_course_content_hook |
|
| 651 | 651 | |
| 652 | - /** |
|
| 653 | - * Deprecate the 2 main hooks on the archive message template |
|
| 654 | - * |
|
| 655 | - * @deprecated since 1.9.0 |
|
| 656 | - * @since 1.9.0 |
|
| 657 | - */ |
|
| 658 | - public static function deprecated_archive_message_hooks (){ |
|
| 659 | - |
|
| 660 | - sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop' ); |
|
| 661 | - sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop' ); |
|
| 652 | + /** |
|
| 653 | + * Deprecate the 2 main hooks on the archive message template |
|
| 654 | + * |
|
| 655 | + * @deprecated since 1.9.0 |
|
| 656 | + * @since 1.9.0 |
|
| 657 | + */ |
|
| 658 | + public static function deprecated_archive_message_hooks (){ |
|
| 659 | + |
|
| 660 | + sensei_do_deprecated_action('sensei_message_archive_main_content', '1.9.0', 'sensei_archive_before_message_loop OR sensei_archive_after_message_loop' ); |
|
| 661 | + sensei_do_deprecated_action('sensei_message_archive_header', '1.9.0', 'sensei_archive_before_message_loop' ); |
|
| 662 | 662 | |
| 663 | - } |
|
| 663 | + } |
|
| 664 | 664 | |
| 665 | - /** |
|
| 666 | - * Run the sensei_complete_quiz for those still hooking |
|
| 667 | - * into but deprecated it. |
|
| 668 | - * |
|
| 669 | - * @deprecated since 1.9.0 |
|
| 670 | - */ |
|
| 671 | - public static function deprecate_sensei_complete_quiz_action(){ |
|
| 665 | + /** |
|
| 666 | + * Run the sensei_complete_quiz for those still hooking |
|
| 667 | + * into but deprecated it. |
|
| 668 | + * |
|
| 669 | + * @deprecated since 1.9.0 |
|
| 670 | + */ |
|
| 671 | + public static function deprecate_sensei_complete_quiz_action(){ |
|
| 672 | 672 | |
| 673 | - sensei_do_deprecated_action( 'sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before' ); |
|
| 673 | + sensei_do_deprecated_action( 'sensei_complete_quiz', '1.9.0', 'sensei_single_quiz_content_inside_before' ); |
|
| 674 | 674 | |
| 675 | - } |
|
| 675 | + } |
|
| 676 | 676 | |
| 677 | - /** |
|
| 678 | - * Run the sensei_quiz_question_type action for those still hooing into it, but depreate |
|
| 679 | - * it to provide user with a better alternative. |
|
| 680 | - * |
|
| 681 | - * @deprecated since 1.9.0 |
|
| 682 | - */ |
|
| 683 | - public static function deprecate_sensei_quiz_question_type_action(){ |
|
| 677 | + /** |
|
| 678 | + * Run the sensei_quiz_question_type action for those still hooing into it, but depreate |
|
| 679 | + * it to provide user with a better alternative. |
|
| 680 | + * |
|
| 681 | + * @deprecated since 1.9.0 |
|
| 682 | + */ |
|
| 683 | + public static function deprecate_sensei_quiz_question_type_action(){ |
|
| 684 | 684 | |
| 685 | - // Question Type |
|
| 686 | - global $sensei_question_loop; |
|
| 687 | - $question_type = Sensei()->question->get_question_type($sensei_question_loop['current_question']->ID); |
|
| 688 | - sensei_do_deprecated_action('sensei_quiz_question_type', '1.9.0', 'sensei_quiz_question_inside_after', $question_type); |
|
| 689 | - |
|
| 690 | - } |
|
| 685 | + // Question Type |
|
| 686 | + global $sensei_question_loop; |
|
| 687 | + $question_type = Sensei()->question->get_question_type($sensei_question_loop['current_question']->ID); |
|
| 688 | + sensei_do_deprecated_action('sensei_quiz_question_type', '1.9.0', 'sensei_quiz_question_inside_after', $question_type); |
|
| 689 | + |
|
| 690 | + } |
|
| 691 | 691 | }//end class |
@@ -13,21 +13,21 @@ discard block |
||
| 13 | 13 | * @since 1.0.0 |
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Course { |
| 16 | - /** |
|
| 17 | - * @var $token |
|
| 18 | - */ |
|
| 16 | + /** |
|
| 17 | + * @var $token |
|
| 18 | + */ |
|
| 19 | 19 | public $token; |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array $meta_fields |
|
| 23 | - */ |
|
| 21 | + /** |
|
| 22 | + * @var array $meta_fields |
|
| 23 | + */ |
|
| 24 | 24 | public $meta_fields; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var string|bool $my_courses_page reference to the sites |
|
| 28 | - * my courses page, false if none was set |
|
| 29 | - */ |
|
| 30 | - public $my_courses_page; |
|
| 26 | + /** |
|
| 27 | + * @var string|bool $my_courses_page reference to the sites |
|
| 28 | + * my courses page, false if none was set |
|
| 29 | + */ |
|
| 30 | + public $my_courses_page; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Constructor. |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function __construct () { |
| 37 | 37 | |
| 38 | - $this->token = 'course'; |
|
| 38 | + $this->token = 'course'; |
|
| 39 | 39 | |
| 40 | 40 | // Setup meta fields for this post type |
| 41 | 41 | $this->meta_fields = array( 'course_prerequisite', 'course_featured', 'course_video_embed', 'course_woocommerce_product' ); |
| 42 | 42 | // Admin actions |
| 43 | 43 | if ( is_admin() ) { |
| 44 | 44 | // Metabox functions |
| 45 | - add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 45 | + add_action( 'add_meta_boxes', array( $this, 'meta_box_setup' ), 20 ); |
|
| 46 | 46 | add_action( 'save_post', array( $this, 'meta_box_save' ) ); |
| 47 | 47 | // Custom Write Panel Columns |
| 48 | 48 | add_filter( 'manage_edit-course_columns', array( $this, 'add_column_headings' ), 10, 1 ); |
@@ -58,47 +58,47 @@ discard block |
||
| 58 | 58 | // Update course completion upon grading of a quiz |
| 59 | 59 | add_action( 'sensei_user_quiz_grade', array( $this, 'update_status_after_quiz_submission' ), 10, 2 ); |
| 60 | 60 | |
| 61 | - // show the progress bar ont he single course page |
|
| 62 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 63 | - add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 61 | + // show the progress bar ont he single course page |
|
| 62 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_statement' ), 15 ); |
|
| 63 | + add_action( 'sensei_single_course_content_inside_before' , array( $this, 'the_progress_meter' ), 16 ); |
|
| 64 | 64 | |
| 65 | - // provide an option to block all emails related to a selected course |
|
| 66 | - add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 67 | - add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 65 | + // provide an option to block all emails related to a selected course |
|
| 66 | + add_filter( 'sensei_send_emails', array( $this, 'block_notification_emails' ) ); |
|
| 67 | + add_action( 'save_post', array( $this, 'save_course_notification_meta_box' ) ); |
|
| 68 | 68 | |
| 69 | - // preview lessons on the course content |
|
| 70 | - add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 69 | + // preview lessons on the course content |
|
| 70 | + add_action( 'sensei_course_content_inside_after',array( $this, 'the_course_free_lesson_preview' ) ); |
|
| 71 | 71 | |
| 72 | - // the course meta |
|
| 73 | - add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 72 | + // the course meta |
|
| 73 | + add_action('sensei_course_content_inside_before', array( $this, 'the_course_meta' ) ); |
|
| 74 | 74 | |
| 75 | - // backwards compatible template hooks |
|
| 76 | - add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 77 | - add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 75 | + // backwards compatible template hooks |
|
| 76 | + add_action('sensei_course_content_inside_before', array( $this, 'content_before_backwards_compatibility_hooks' )); |
|
| 77 | + add_action('sensei_loop_course_before', array( $this,'loop_before_backwards_compatibility_hooks' ) ); |
|
| 78 | 78 | |
| 79 | - // add the user status on the course to the markup as a class |
|
| 80 | - add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 79 | + // add the user status on the course to the markup as a class |
|
| 80 | + add_filter('post_class', array( __CLASS__ , 'add_course_user_status_class' ), 20, 3 ); |
|
| 81 | 81 | |
| 82 | - //filter the course query in Sensei specific instances |
|
| 83 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 82 | + //filter the course query in Sensei specific instances |
|
| 83 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_query_filter' ) ); |
|
| 84 | 84 | |
| 85 | - //attache the sorting to the course archive |
|
| 86 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 85 | + //attache the sorting to the course archive |
|
| 86 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_sorting' ) ); |
|
| 87 | 87 | |
| 88 | - //attach the filter links to the course archive |
|
| 89 | - add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 88 | + //attach the filter links to the course archive |
|
| 89 | + add_action ( 'sensei_archive_before_course_loop' , array( 'Sensei_Course', 'course_archive_filters' ) ); |
|
| 90 | 90 | |
| 91 | - //filter the course query when featured filter is applied |
|
| 92 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 91 | + //filter the course query when featured filter is applied |
|
| 92 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_featured_filter')); |
|
| 93 | 93 | |
| 94 | - // handle the order by title post submission |
|
| 95 | - add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 94 | + // handle the order by title post submission |
|
| 95 | + add_filter( 'pre_get_posts', array( __CLASS__, 'course_archive_order_by_title')); |
|
| 96 | 96 | |
| 97 | - // ensure the course category page respects the manual order set for courses |
|
| 98 | - add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 97 | + // ensure the course category page respects the manual order set for courses |
|
| 98 | + add_filter( 'pre_get_posts', array( __CLASS__, 'alter_course_category_order')); |
|
| 99 | 99 | |
| 100 | - // flush rewrite rules when saving a course |
|
| 101 | - add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 100 | + // flush rewrite rules when saving a course |
|
| 101 | + add_action('save_post', array( 'Sensei_Course', 'flush_rewrite_rules' ) ); |
|
| 102 | 102 | |
| 103 | 103 | } // End __construct() |
| 104 | 104 | |
@@ -151,13 +151,13 @@ discard block |
||
| 151 | 151 | add_meta_box( 'course-video', __( 'Course Video', 'woothemes-sensei' ), array( $this, 'course_video_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 152 | 152 | // Add Meta Box for Course Lessons |
| 153 | 153 | add_meta_box( 'course-lessons', __( 'Course Lessons', 'woothemes-sensei' ), array( $this, 'course_lessons_meta_box_content' ), $this->token, 'normal', 'default' ); |
| 154 | - // Add Meta Box to link to Manage Learners |
|
| 155 | - add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 156 | - // Remove "Custom Settings" meta box. |
|
| 154 | + // Add Meta Box to link to Manage Learners |
|
| 155 | + add_meta_box( 'course-manage', __( 'Course Management', 'woothemes-sensei' ), array( $this, 'course_manage_meta_box_content' ), $this->token, 'side', 'default' ); |
|
| 156 | + // Remove "Custom Settings" meta box. |
|
| 157 | 157 | remove_meta_box( 'woothemes-settings', $this->token, 'normal' ); |
| 158 | 158 | |
| 159 | - // add Disable email notification box |
|
| 160 | - add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 159 | + // add Disable email notification box |
|
| 160 | + add_meta_box( 'course-notifications', __( 'Course Notifications', 'woothemes-sensei' ), array( $this, 'course_notification_meta_box_content' ), 'course', 'normal', 'default' ); |
|
| 161 | 161 | |
| 162 | 162 | } // End meta_box_setup() |
| 163 | 163 | |
@@ -175,10 +175,10 @@ discard block |
||
| 175 | 175 | $post_args = array( 'post_type' => array( 'product', 'product_variation' ), |
| 176 | 176 | 'posts_per_page' => -1, |
| 177 | 177 | 'orderby' => 'title', |
| 178 | - 'order' => 'DESC', |
|
| 179 | - 'exclude' => $post->ID, |
|
| 180 | - 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 181 | - 'tax_query' => array( |
|
| 178 | + 'order' => 'DESC', |
|
| 179 | + 'exclude' => $post->ID, |
|
| 180 | + 'post_status' => array( 'publish', 'private', 'draft' ), |
|
| 181 | + 'tax_query' => array( |
|
| 182 | 182 | array( |
| 183 | 183 | 'taxonomy' => 'product_type', |
| 184 | 184 | 'field' => 'slug', |
@@ -206,21 +206,21 @@ discard block |
||
| 206 | 206 | $product_object = get_product( $post_item->ID ); |
| 207 | 207 | $parent_id = wp_get_post_parent_id( $post_item->ID ); |
| 208 | 208 | |
| 209 | - if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 209 | + if( sensei_check_woocommerce_version( '2.1' ) ) { |
|
| 210 | 210 | $formatted_variation = wc_get_formatted_variation( $product_object->variation_data, true ); |
| 211 | 211 | |
| 212 | 212 | } else { |
| 213 | - // fall back to pre wc 2.1 |
|
| 213 | + // fall back to pre wc 2.1 |
|
| 214 | 214 | $formatted_variation = woocommerce_get_formatted_variation( $product_object->variation_data, true ); |
| 215 | 215 | |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - $product_name = ucwords( $formatted_variation ); |
|
| 219 | - if( empty( $product_name ) ){ |
|
| 218 | + $product_name = ucwords( $formatted_variation ); |
|
| 219 | + if( empty( $product_name ) ){ |
|
| 220 | 220 | |
| 221 | - $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 221 | + $product_name = __( 'Variation #', 'woothemes-sensei' ) . $product_object->variation_id; |
|
| 222 | 222 | |
| 223 | - } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | } else { |
| 226 | 226 | |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | |
| 271 | 271 | } else { |
| 272 | 272 | |
| 273 | - $html .= '<p>' . "\n"; |
|
| 273 | + $html .= '<p>' . "\n"; |
|
| 274 | 274 | $html .= esc_html( __( 'No products exist yet.', 'woothemes-sensei' ) ) . "\n"; |
| 275 | 275 | $html .= '</p>'."\n"; |
| 276 | 276 | |
@@ -296,8 +296,8 @@ discard block |
||
| 296 | 296 | $post_args = array( 'post_type' => 'course', |
| 297 | 297 | 'posts_per_page' => -1, |
| 298 | 298 | 'orderby' => 'title', |
| 299 | - 'order' => 'DESC', |
|
| 300 | - 'exclude' => $post->ID, |
|
| 299 | + 'order' => 'DESC', |
|
| 300 | + 'exclude' => $post->ID, |
|
| 301 | 301 | 'suppress_filters' => 0 |
| 302 | 302 | ); |
| 303 | 303 | $posts_array = get_posts( $post_args ); |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | |
| 339 | 339 | $checked = ''; |
| 340 | 340 | if ( isset( $course_featured ) && ( '' != $course_featured ) ) { |
| 341 | - $checked = checked( 'featured', $course_featured, false ); |
|
| 341 | + $checked = checked( 'featured', $course_featured, false ); |
|
| 342 | 342 | } // End If Statement |
| 343 | 343 | |
| 344 | 344 | $html .= '<input type="checkbox" name="course_featured" value="featured" ' . $checked . '> ' . __( 'Feature this course', 'woothemes-sensei' ) . '<br>'; |
@@ -433,8 +433,8 @@ discard block |
||
| 433 | 433 | $new_meta_value = ( isset( $_POST[$post_key] ) ? sanitize_html_class( $_POST[$post_key] ) : '' ); |
| 434 | 434 | } // End If Statement |
| 435 | 435 | |
| 436 | - // update field with the new value |
|
| 437 | - return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 436 | + // update field with the new value |
|
| 437 | + return update_post_meta( $post_id, $meta_key, $new_meta_value ); |
|
| 438 | 438 | |
| 439 | 439 | } // End save_post_meta() |
| 440 | 440 | |
@@ -458,8 +458,8 @@ discard block |
||
| 458 | 458 | |
| 459 | 459 | $html = ''; |
| 460 | 460 | $html .= '<input type="hidden" name="' . esc_attr( 'woo_' . $this->token . '_noonce' ) . '" id="' |
| 461 | - . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 462 | - . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 461 | + . esc_attr( 'woo_' . $this->token . '_noonce' ) |
|
| 462 | + . '" value="' . esc_attr( wp_create_nonce( plugin_basename(__FILE__) ) ) . '" />'; |
|
| 463 | 463 | |
| 464 | 464 | if ( count( $posts_array ) > 0 ) { |
| 465 | 465 | |
@@ -480,8 +480,8 @@ discard block |
||
| 480 | 480 | $html .= '<p>' . esc_html( __( 'No lessons exist yet for this course.', 'woothemes-sensei' ) ) . "\n"; |
| 481 | 481 | |
| 482 | 482 | $html .= '<a href="' . admin_url( 'post-new.php?post_type=lesson' . $course_id ) |
| 483 | - . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 484 | - . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 483 | + . '" title="' . esc_attr( __( 'Add a Lesson', 'woothemes-sensei' ) ) . '">' |
|
| 484 | + . __( 'Please add some.', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 485 | 485 | |
| 486 | 486 | $html .= '</p>'."\n"; |
| 487 | 487 | } // End If Statement |
@@ -490,29 +490,29 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | } // End course_lessons_meta_box_content() |
| 492 | 492 | |
| 493 | - /** |
|
| 494 | - * course_manage_meta_box_content function. |
|
| 495 | - * |
|
| 496 | - * @since 1.9.0 |
|
| 497 | - * @access public |
|
| 498 | - * @return void |
|
| 499 | - */ |
|
| 493 | + /** |
|
| 494 | + * course_manage_meta_box_content function. |
|
| 495 | + * |
|
| 496 | + * @since 1.9.0 |
|
| 497 | + * @access public |
|
| 498 | + * @return void |
|
| 499 | + */ |
|
| 500 | 500 | |
| 501 | - public function course_manage_meta_box_content () { |
|
| 502 | - global $post; |
|
| 501 | + public function course_manage_meta_box_content () { |
|
| 502 | + global $post; |
|
| 503 | 503 | |
| 504 | - $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 504 | + $manage_url = esc_url( add_query_arg( array( 'page' => 'sensei_learners', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 505 | 505 | |
| 506 | - $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 506 | + $grading_url = esc_url( add_query_arg( array( 'page' => 'sensei_grading', 'course_id' => $post->ID, 'view' => 'learners' ), admin_url( 'admin.php') ) ); |
|
| 507 | 507 | |
| 508 | 508 | |
| 509 | - echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 509 | + echo "<ul><li><a href='$manage_url'>".__("Manage Learners", 'woothemes-sensei')."</a></li>"; |
|
| 510 | 510 | |
| 511 | - echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 511 | + echo "<li><a href='$grading_url'>".__("Manage Grading", 'woothemes-sensei')."</a></li></ul>"; |
|
| 512 | 512 | |
| 513 | 513 | |
| 514 | 514 | |
| 515 | - } // End course_manage_meta_box_content() |
|
| 515 | + } // End course_manage_meta_box_content() |
|
| 516 | 516 | |
| 517 | 517 | /** |
| 518 | 518 | * Add column headings to the "lesson" post list screen. |
@@ -653,92 +653,92 @@ discard block |
||
| 653 | 653 | } // End If Statement |
| 654 | 654 | } // End If Statement |
| 655 | 655 | |
| 656 | - $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 657 | - $order = 'ASC'; |
|
| 658 | - $orderby = 'menu_order'; |
|
| 659 | - if( empty( $stored_order ) ){ |
|
| 656 | + $stored_order = get_option( 'sensei_course_order', '' ); |
|
| 657 | + $order = 'ASC'; |
|
| 658 | + $orderby = 'menu_order'; |
|
| 659 | + if( empty( $stored_order ) ){ |
|
| 660 | 660 | |
| 661 | - $order = 'DESC'; |
|
| 662 | - $orderby = 'date'; |
|
| 661 | + $order = 'DESC'; |
|
| 662 | + $orderby = 'date'; |
|
| 663 | 663 | |
| 664 | - } |
|
| 664 | + } |
|
| 665 | 665 | |
| 666 | 666 | switch ($type) { |
| 667 | 667 | |
| 668 | 668 | case 'usercourses': |
| 669 | 669 | $post_args = array( 'post_type' => 'course', |
| 670 | 670 | 'orderby' => $orderby, |
| 671 | - 'order' => $order, |
|
| 672 | - 'post_status' => 'publish', |
|
| 673 | - 'include' => $includes, |
|
| 674 | - 'exclude' => $excludes, |
|
| 675 | - 'suppress_filters' => 0 |
|
| 671 | + 'order' => $order, |
|
| 672 | + 'post_status' => 'publish', |
|
| 673 | + 'include' => $includes, |
|
| 674 | + 'exclude' => $excludes, |
|
| 675 | + 'suppress_filters' => 0 |
|
| 676 | 676 | ); |
| 677 | 677 | break; |
| 678 | 678 | case 'freecourses': |
| 679 | 679 | |
| 680 | - $post_args = array( |
|
| 681 | - 'post_type' => 'course', |
|
| 682 | - 'orderby' => $orderby, |
|
| 683 | - 'order' => $order, |
|
| 684 | - 'post_status' => 'publish', |
|
| 685 | - 'exclude' => $excludes, |
|
| 686 | - 'suppress_filters' => 0 |
|
| 687 | - ); |
|
| 688 | - // Sub Query to get all WooCommerce Products that have Zero price |
|
| 689 | - $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 680 | + $post_args = array( |
|
| 681 | + 'post_type' => 'course', |
|
| 682 | + 'orderby' => $orderby, |
|
| 683 | + 'order' => $order, |
|
| 684 | + 'post_status' => 'publish', |
|
| 685 | + 'exclude' => $excludes, |
|
| 686 | + 'suppress_filters' => 0 |
|
| 687 | + ); |
|
| 688 | + // Sub Query to get all WooCommerce Products that have Zero price |
|
| 689 | + $post_args['meta_query'] = Sensei_WC::get_free_courses_meta_query_args(); |
|
| 690 | 690 | |
| 691 | - break; |
|
| 691 | + break; |
|
| 692 | 692 | |
| 693 | 693 | case 'paidcourses': |
| 694 | 694 | |
| 695 | - $post_args = array( |
|
| 696 | - 'post_type' => 'course', |
|
| 697 | - 'orderby' => $orderby, |
|
| 698 | - 'order' => $order, |
|
| 699 | - 'post_status' => 'publish', |
|
| 700 | - 'exclude' => $excludes, |
|
| 701 | - 'suppress_filters' => 0 |
|
| 702 | - ); |
|
| 695 | + $post_args = array( |
|
| 696 | + 'post_type' => 'course', |
|
| 697 | + 'orderby' => $orderby, |
|
| 698 | + 'order' => $order, |
|
| 699 | + 'post_status' => 'publish', |
|
| 700 | + 'exclude' => $excludes, |
|
| 701 | + 'suppress_filters' => 0 |
|
| 702 | + ); |
|
| 703 | 703 | |
| 704 | - // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 705 | - $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 704 | + // Sub Query to get all WooCommerce Products that have price greater than zero |
|
| 705 | + $post_args['meta_query'] = Sensei_WC::get_paid_courses_meta_query_args(); |
|
| 706 | 706 | |
| 707 | 707 | break; |
| 708 | 708 | |
| 709 | 709 | case 'featuredcourses': |
| 710 | - $post_args = array( 'post_type' => 'course', |
|
| 711 | - 'orderby' => $orderby, |
|
| 712 | - 'order' => $order, |
|
| 713 | - 'post_status' => 'publish', |
|
| 714 | - 'meta_value' => 'featured', |
|
| 715 | - 'meta_key' => '_course_featured', |
|
| 716 | - 'meta_compare' => '=', |
|
| 717 | - 'exclude' => $excludes, |
|
| 718 | - 'suppress_filters' => 0 |
|
| 710 | + $post_args = array( 'post_type' => 'course', |
|
| 711 | + 'orderby' => $orderby, |
|
| 712 | + 'order' => $order, |
|
| 713 | + 'post_status' => 'publish', |
|
| 714 | + 'meta_value' => 'featured', |
|
| 715 | + 'meta_key' => '_course_featured', |
|
| 716 | + 'meta_compare' => '=', |
|
| 717 | + 'exclude' => $excludes, |
|
| 718 | + 'suppress_filters' => 0 |
|
| 719 | 719 | ); |
| 720 | 720 | break; |
| 721 | 721 | default: |
| 722 | 722 | $post_args = array( 'post_type' => 'course', |
| 723 | - 'orderby' => $orderby, |
|
| 724 | - 'order' => $order, |
|
| 725 | - 'post_status' => 'publish', |
|
| 726 | - 'exclude' => $excludes, |
|
| 727 | - 'suppress_filters' => 0 |
|
| 723 | + 'orderby' => $orderby, |
|
| 724 | + 'order' => $order, |
|
| 725 | + 'post_status' => 'publish', |
|
| 726 | + 'exclude' => $excludes, |
|
| 727 | + 'suppress_filters' => 0 |
|
| 728 | 728 | ); |
| 729 | 729 | break; |
| 730 | 730 | |
| 731 | 731 | } |
| 732 | 732 | |
| 733 | - $post_args['posts_per_page'] = $amount; |
|
| 734 | - $paged = $wp_query->get( 'paged' ); |
|
| 735 | - $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 733 | + $post_args['posts_per_page'] = $amount; |
|
| 734 | + $paged = $wp_query->get( 'paged' ); |
|
| 735 | + $post_args['paged'] = empty( $paged) ? 1 : $paged; |
|
| 736 | 736 | |
| 737 | - if( 'newcourses' == $type ){ |
|
| 737 | + if( 'newcourses' == $type ){ |
|
| 738 | 738 | |
| 739 | - $post_args[ 'orderby' ] = 'date'; |
|
| 740 | - $post_args[ 'order' ] = 'DESC'; |
|
| 741 | - } |
|
| 739 | + $post_args[ 'orderby' ] = 'date'; |
|
| 740 | + $post_args[ 'order' ] = 'DESC'; |
|
| 741 | + } |
|
| 742 | 742 | |
| 743 | 743 | return $post_args; |
| 744 | 744 | } |
@@ -748,22 +748,22 @@ discard block |
||
| 748 | 748 | * course_image function. |
| 749 | 749 | * |
| 750 | 750 | * Outputs the courses image, or first image from a lesson within a course |
| 751 | - * |
|
| 752 | - * Will echo the image unless return true is specified. |
|
| 751 | + * |
|
| 752 | + * Will echo the image unless return true is specified. |
|
| 753 | 753 | * |
| 754 | 754 | * @access public |
| 755 | 755 | * @param int | WP_Post $course_id (default: 0) |
| 756 | 756 | * @param string $width (default: '100') |
| 757 | 757 | * @param string $height (default: '100') |
| 758 | - * @param bool $return default false |
|
| 759 | - * |
|
| 758 | + * @param bool $return default false |
|
| 759 | + * |
|
| 760 | 760 | * @return string | void |
| 761 | 761 | */ |
| 762 | 762 | public function course_image( $course_id = 0, $width = '100', $height = '100', $return = false ) { |
| 763 | 763 | |
| 764 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 765 | - $course_id = $course_id->ID; |
|
| 766 | - } |
|
| 764 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 765 | + $course_id = $course_id->ID; |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | 768 | $html = ''; |
| 769 | 769 | |
@@ -820,7 +820,7 @@ discard block |
||
| 820 | 820 | // Display Image Placeholder if none |
| 821 | 821 | if ( Sensei()->settings->get( 'placeholder_images_enable' ) ) { |
| 822 | 822 | |
| 823 | - $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 823 | + $img_url = apply_filters( 'sensei_course_placeholder_image_url', '<img src="http://placehold.it/' . $width . 'x' . $height . '" class="woo-image thumbnail alignleft" />' ); |
|
| 824 | 824 | |
| 825 | 825 | } // End If Statement |
| 826 | 826 | |
@@ -834,15 +834,15 @@ discard block |
||
| 834 | 834 | |
| 835 | 835 | } // End If Statement |
| 836 | 836 | |
| 837 | - if( $return ){ |
|
| 837 | + if( $return ){ |
|
| 838 | 838 | |
| 839 | - return $html; |
|
| 839 | + return $html; |
|
| 840 | 840 | |
| 841 | - }else{ |
|
| 841 | + }else{ |
|
| 842 | 842 | |
| 843 | - echo $html; |
|
| 843 | + echo $html; |
|
| 844 | 844 | |
| 845 | - } |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | 847 | } // End course_image() |
| 848 | 848 | |
@@ -886,9 +886,9 @@ discard block |
||
| 886 | 886 | */ |
| 887 | 887 | public function course_lessons( $course_id = 0, $post_status = 'publish', $fields = 'all' ) { |
| 888 | 888 | |
| 889 | - if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 890 | - $course_id = $course_id->ID; |
|
| 891 | - } |
|
| 889 | + if( is_a( $course_id, 'WP_Post' ) ){ |
|
| 890 | + $course_id = $course_id->ID; |
|
| 891 | + } |
|
| 892 | 892 | |
| 893 | 893 | $post_args = array( 'post_type' => 'lesson', |
| 894 | 894 | 'posts_per_page' => -1, |
@@ -904,67 +904,67 @@ discard block |
||
| 904 | 904 | 'suppress_filters' => 0, |
| 905 | 905 | ); |
| 906 | 906 | $query_results = new WP_Query( $post_args ); |
| 907 | - $lessons = $query_results->posts; |
|
| 908 | - |
|
| 909 | - // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 910 | - // with the course order for a different course and this should not be included. It could also not |
|
| 911 | - // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 912 | - // that have been added to the course. |
|
| 913 | - if( count( $lessons) > 1 ){ |
|
| 914 | - |
|
| 915 | - foreach( $lessons as $lesson ){ |
|
| 916 | - |
|
| 917 | - $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 918 | - // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 919 | - $lesson->course_order = $order ? $order : 100000; |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - /** |
|
| 926 | - * Filter runs inside Sensei_Course::course_lessons function |
|
| 927 | - * |
|
| 928 | - * Returns all lessons for a given course |
|
| 929 | - * |
|
| 930 | - * @param array $lessons |
|
| 931 | - * @param int $course_id |
|
| 932 | - */ |
|
| 933 | - $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 934 | - |
|
| 935 | - //return the requested fields |
|
| 936 | - // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 937 | - // objects |
|
| 938 | - if( 'ids' == $fields ) { |
|
| 939 | - $lesson_objects = $lessons; |
|
| 940 | - $lessons = array(); |
|
| 941 | - |
|
| 942 | - foreach ($lesson_objects as $lesson) { |
|
| 943 | - $lessons[] = $lesson->ID; |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - return $lessons; |
|
| 907 | + $lessons = $query_results->posts; |
|
| 908 | + |
|
| 909 | + // re order the lessons. This could not be done via the OR meta query as there may be lessons |
|
| 910 | + // with the course order for a different course and this should not be included. It could also not |
|
| 911 | + // be done via the AND meta query as it excludes lesson that does not have the _order_$course_id but |
|
| 912 | + // that have been added to the course. |
|
| 913 | + if( count( $lessons) > 1 ){ |
|
| 914 | + |
|
| 915 | + foreach( $lessons as $lesson ){ |
|
| 916 | + |
|
| 917 | + $order = intval( get_post_meta( $lesson->ID, '_order_'. $course_id, true ) ); |
|
| 918 | + // for lessons with no order set it to be 10000 so that it show up at the end |
|
| 919 | + $lesson->course_order = $order ? $order : 100000; |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + uasort( $lessons, array( $this, '_short_course_lessons_callback' ) ); |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + /** |
|
| 926 | + * Filter runs inside Sensei_Course::course_lessons function |
|
| 927 | + * |
|
| 928 | + * Returns all lessons for a given course |
|
| 929 | + * |
|
| 930 | + * @param array $lessons |
|
| 931 | + * @param int $course_id |
|
| 932 | + */ |
|
| 933 | + $lessons = apply_filters( 'sensei_course_get_lessons', $lessons, $course_id ); |
|
| 934 | + |
|
| 935 | + //return the requested fields |
|
| 936 | + // runs after the sensei_course_get_lessons filter so the filter always give an array of lesson |
|
| 937 | + // objects |
|
| 938 | + if( 'ids' == $fields ) { |
|
| 939 | + $lesson_objects = $lessons; |
|
| 940 | + $lessons = array(); |
|
| 941 | + |
|
| 942 | + foreach ($lesson_objects as $lesson) { |
|
| 943 | + $lessons[] = $lesson->ID; |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + return $lessons; |
|
| 948 | 948 | |
| 949 | 949 | } // End course_lessons() |
| 950 | 950 | |
| 951 | - /** |
|
| 952 | - * Used for the uasort in $this->course_lessons() |
|
| 953 | - * @since 1.8.0 |
|
| 954 | - * @access protected |
|
| 955 | - * |
|
| 956 | - * @param array $lesson_1 |
|
| 957 | - * @param array $lesson_2 |
|
| 958 | - * @return int |
|
| 959 | - */ |
|
| 960 | - protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 951 | + /** |
|
| 952 | + * Used for the uasort in $this->course_lessons() |
|
| 953 | + * @since 1.8.0 |
|
| 954 | + * @access protected |
|
| 955 | + * |
|
| 956 | + * @param array $lesson_1 |
|
| 957 | + * @param array $lesson_2 |
|
| 958 | + * @return int |
|
| 959 | + */ |
|
| 960 | + protected function _short_course_lessons_callback( $lesson_1, $lesson_2 ){ |
|
| 961 | 961 | |
| 962 | - if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 963 | - return 0; |
|
| 964 | - } |
|
| 962 | + if ( $lesson_1->course_order == $lesson_2->course_order ) { |
|
| 963 | + return 0; |
|
| 964 | + } |
|
| 965 | 965 | |
| 966 | - return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 967 | - } |
|
| 966 | + return ($lesson_1->course_order < $lesson_2->course_order) ? -1 : 1; |
|
| 967 | + } |
|
| 968 | 968 | |
| 969 | 969 | /** |
| 970 | 970 | * Fetch all quiz ids in a course |
@@ -1027,15 +1027,15 @@ discard block |
||
| 1027 | 1027 | */ |
| 1028 | 1028 | public function course_author_lesson_count( $author_id = 0, $course_id = 0 ) { |
| 1029 | 1029 | |
| 1030 | - $lesson_args = array( 'post_type' => 'lesson', |
|
| 1030 | + $lesson_args = array( 'post_type' => 'lesson', |
|
| 1031 | 1031 | 'posts_per_page' => -1, |
| 1032 | - 'author' => $author_id, |
|
| 1033 | - 'meta_key' => '_lesson_course', |
|
| 1034 | - 'meta_value' => $course_id, |
|
| 1035 | - 'post_status' => 'publish', |
|
| 1036 | - 'suppress_filters' => 0, |
|
| 1032 | + 'author' => $author_id, |
|
| 1033 | + 'meta_key' => '_lesson_course', |
|
| 1034 | + 'meta_value' => $course_id, |
|
| 1035 | + 'post_status' => 'publish', |
|
| 1036 | + 'suppress_filters' => 0, |
|
| 1037 | 1037 | 'fields' => 'ids', // less data to retrieve |
| 1038 | - ); |
|
| 1038 | + ); |
|
| 1039 | 1039 | $lessons_array = get_posts( $lesson_args ); |
| 1040 | 1040 | $count = count( $lessons_array ); |
| 1041 | 1041 | return $count; |
@@ -1053,17 +1053,17 @@ discard block |
||
| 1053 | 1053 | |
| 1054 | 1054 | $lesson_args = array( 'post_type' => 'lesson', |
| 1055 | 1055 | 'posts_per_page' => -1, |
| 1056 | - 'meta_key' => '_lesson_course', |
|
| 1057 | - 'meta_value' => $course_id, |
|
| 1058 | - 'post_status' => 'publish', |
|
| 1059 | - 'suppress_filters' => 0, |
|
| 1056 | + 'meta_key' => '_lesson_course', |
|
| 1057 | + 'meta_value' => $course_id, |
|
| 1058 | + 'post_status' => 'publish', |
|
| 1059 | + 'suppress_filters' => 0, |
|
| 1060 | 1060 | 'fields' => 'ids', // less data to retrieve |
| 1061 | - ); |
|
| 1061 | + ); |
|
| 1062 | 1062 | $lessons_array = get_posts( $lesson_args ); |
| 1063 | 1063 | |
| 1064 | - $count = count( $lessons_array ); |
|
| 1064 | + $count = count( $lessons_array ); |
|
| 1065 | 1065 | |
| 1066 | - return $count; |
|
| 1066 | + return $count; |
|
| 1067 | 1067 | |
| 1068 | 1068 | } // End course_lesson_count() |
| 1069 | 1069 | |
@@ -1078,9 +1078,9 @@ discard block |
||
| 1078 | 1078 | |
| 1079 | 1079 | $lesson_args = array( 'post_type' => 'lesson', |
| 1080 | 1080 | 'posts_per_page' => -1, |
| 1081 | - 'post_status' => 'publish', |
|
| 1082 | - 'suppress_filters' => 0, |
|
| 1083 | - 'meta_query' => array( |
|
| 1081 | + 'post_status' => 'publish', |
|
| 1082 | + 'suppress_filters' => 0, |
|
| 1083 | + 'meta_query' => array( |
|
| 1084 | 1084 | array( |
| 1085 | 1085 | 'key' => '_lesson_course', |
| 1086 | 1086 | 'value' => $course_id |
@@ -1091,12 +1091,12 @@ discard block |
||
| 1091 | 1091 | ) |
| 1092 | 1092 | ), |
| 1093 | 1093 | 'fields' => 'ids', // less data to retrieve |
| 1094 | - ); |
|
| 1094 | + ); |
|
| 1095 | 1095 | $lessons_array = get_posts( $lesson_args ); |
| 1096 | 1096 | |
| 1097 | 1097 | $count = count( $lessons_array ); |
| 1098 | 1098 | |
| 1099 | - return $count; |
|
| 1099 | + return $count; |
|
| 1100 | 1100 | |
| 1101 | 1101 | } // End course_lesson_count() |
| 1102 | 1102 | |
@@ -1115,8 +1115,8 @@ discard block |
||
| 1115 | 1115 | $post_args = array( 'post_type' => 'course', |
| 1116 | 1116 | 'posts_per_page' => -1, |
| 1117 | 1117 | 'meta_key' => '_course_woocommerce_product', |
| 1118 | - 'meta_value' => $product_id, |
|
| 1119 | - 'post_status' => 'publish', |
|
| 1118 | + 'meta_value' => $product_id, |
|
| 1119 | + 'post_status' => 'publish', |
|
| 1120 | 1120 | 'suppress_filters' => 0, |
| 1121 | 1121 | 'orderby' => 'menu_order date', |
| 1122 | 1122 | 'order' => 'ASC', |
@@ -1157,9 +1157,9 @@ discard block |
||
| 1157 | 1157 | |
| 1158 | 1158 | /** |
| 1159 | 1159 | * load_user_courses_content generates HTML for user's active & completed courses |
| 1160 | - * |
|
| 1161 | - * This function also ouputs the html so no need to echo the content. |
|
| 1162 | - * |
|
| 1160 | + * |
|
| 1161 | + * This function also ouputs the html so no need to echo the content. |
|
| 1162 | + * |
|
| 1163 | 1163 | * @since 1.4.0 |
| 1164 | 1164 | * @param object $user Queried user object |
| 1165 | 1165 | * @param boolean $manage Whether the user has permission to manage the courses |
@@ -1168,17 +1168,17 @@ discard block |
||
| 1168 | 1168 | public function load_user_courses_content( $user = false ) { |
| 1169 | 1169 | global $course, $my_courses_page, $my_courses_section; |
| 1170 | 1170 | |
| 1171 | - if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1172 | - || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1171 | + if( ! isset( Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) |
|
| 1172 | + || ! Sensei()->settings->settings[ 'learner_profile_show_courses' ] ) { |
|
| 1173 | 1173 | |
| 1174 | - // do not show the content if the settings doesn't allow for it |
|
| 1175 | - return; |
|
| 1174 | + // do not show the content if the settings doesn't allow for it |
|
| 1175 | + return; |
|
| 1176 | 1176 | |
| 1177 | - } |
|
| 1177 | + } |
|
| 1178 | 1178 | |
| 1179 | - $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1179 | + $manage = ( $user->ID == get_current_user_id() ) ? true : false; |
|
| 1180 | 1180 | |
| 1181 | - do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1181 | + do_action( 'sensei_before_learner_course_content', $user ); |
|
| 1182 | 1182 | |
| 1183 | 1183 | // Build Output HTML |
| 1184 | 1184 | $complete_html = $active_html = ''; |
@@ -1193,7 +1193,7 @@ discard block |
||
| 1193 | 1193 | // Logic for Active and Completed Courses |
| 1194 | 1194 | $per_page = 20; |
| 1195 | 1195 | if ( isset( Sensei()->settings->settings[ 'my_course_amount' ] ) |
| 1196 | - && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1196 | + && ( 0 < absint( Sensei()->settings->settings[ 'my_course_amount' ] ) ) ) { |
|
| 1197 | 1197 | |
| 1198 | 1198 | $per_page = absint( Sensei()->settings->settings[ 'my_course_amount' ] ); |
| 1199 | 1199 | |
@@ -1239,111 +1239,111 @@ discard block |
||
| 1239 | 1239 | } |
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | - // Get Course Categories |
|
| 1243 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1242 | + // Get Course Categories |
|
| 1243 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1244 | 1244 | |
| 1245 | - $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1245 | + $active_html .= '<article class="' . esc_attr( join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) ) . '">'; |
|
| 1246 | 1246 | |
| 1247 | - // Image |
|
| 1248 | - $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1247 | + // Image |
|
| 1248 | + $active_html .= Sensei()->course->course_image( absint( $course_item->ID ), '100','100', true ); |
|
| 1249 | 1249 | |
| 1250 | - // Title |
|
| 1251 | - $active_html .= '<header>'; |
|
| 1250 | + // Title |
|
| 1251 | + $active_html .= '<header>'; |
|
| 1252 | 1252 | |
| 1253 | - $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1253 | + $active_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1254 | 1254 | |
| 1255 | - $active_html .= '</header>'; |
|
| 1255 | + $active_html .= '</header>'; |
|
| 1256 | 1256 | |
| 1257 | - $active_html .= '<section class="entry">'; |
|
| 1257 | + $active_html .= '<section class="entry">'; |
|
| 1258 | 1258 | |
| 1259 | - $active_html .= '<p class="sensei-course-meta">'; |
|
| 1259 | + $active_html .= '<p class="sensei-course-meta">'; |
|
| 1260 | 1260 | |
| 1261 | - // Author |
|
| 1262 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1263 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1264 | - && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1261 | + // Author |
|
| 1262 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1263 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) |
|
| 1264 | + && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1265 | 1265 | |
| 1266 | - $active_html .= '<span class="course-author">' |
|
| 1267 | - . __( 'by ', 'woothemes-sensei' ) |
|
| 1268 | - . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1269 | - . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1270 | - . esc_html( $user_info->display_name ) |
|
| 1271 | - . '</a></span>'; |
|
| 1266 | + $active_html .= '<span class="course-author">' |
|
| 1267 | + . __( 'by ', 'woothemes-sensei' ) |
|
| 1268 | + . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) |
|
| 1269 | + . '" title="' . esc_attr( $user_info->display_name ) . '">' |
|
| 1270 | + . esc_html( $user_info->display_name ) |
|
| 1271 | + . '</a></span>'; |
|
| 1272 | 1272 | |
| 1273 | - } // End If Statement |
|
| 1273 | + } // End If Statement |
|
| 1274 | 1274 | |
| 1275 | - // Lesson count for this author |
|
| 1276 | - $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1277 | - // Handle Division by Zero |
|
| 1278 | - if ( 0 == $lesson_count ) { |
|
| 1275 | + // Lesson count for this author |
|
| 1276 | + $lesson_count = Sensei()->course->course_lesson_count( absint( $course_item->ID ) ); |
|
| 1277 | + // Handle Division by Zero |
|
| 1278 | + if ( 0 == $lesson_count ) { |
|
| 1279 | 1279 | |
| 1280 | - $lesson_count = 1; |
|
| 1280 | + $lesson_count = 1; |
|
| 1281 | 1281 | |
| 1282 | - } // End If Statement |
|
| 1283 | - $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1284 | - // Course Categories |
|
| 1285 | - if ( '' != $category_output ) { |
|
| 1282 | + } // End If Statement |
|
| 1283 | + $active_html .= '<span class="course-lesson-count">' . $lesson_count . ' ' . __( 'Lessons', 'woothemes-sensei' ) . '</span>'; |
|
| 1284 | + // Course Categories |
|
| 1285 | + if ( '' != $category_output ) { |
|
| 1286 | 1286 | |
| 1287 | - $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1287 | + $active_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1288 | 1288 | |
| 1289 | - } // End If Statement |
|
| 1290 | - $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1289 | + } // End If Statement |
|
| 1290 | + $active_html .= '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $lessons_completed, $lesson_count ) . '</span>'; |
|
| 1291 | 1291 | |
| 1292 | - $active_html .= '</p>'; |
|
| 1292 | + $active_html .= '</p>'; |
|
| 1293 | 1293 | |
| 1294 | - $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1294 | + $active_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
|
| 1295 | 1295 | |
| 1296 | 1296 | |
| 1297 | 1297 | |
| 1298 | - $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1298 | + $progress_percentage = abs( round( ( doubleval( $lessons_completed ) * 100 ) / ( $lesson_count ), 0 ) ); |
|
| 1299 | 1299 | |
| 1300 | - $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1300 | + $active_html .= $this->get_progress_meter( $progress_percentage ); |
|
| 1301 | 1301 | |
| 1302 | - $active_html .= '</section>'; |
|
| 1302 | + $active_html .= '</section>'; |
|
| 1303 | 1303 | |
| 1304 | - if( is_user_logged_in() ) { |
|
| 1304 | + if( is_user_logged_in() ) { |
|
| 1305 | 1305 | |
| 1306 | - $active_html .= '<section class="entry-actions">'; |
|
| 1306 | + $active_html .= '<section class="entry-actions">'; |
|
| 1307 | 1307 | |
| 1308 | - $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1308 | + $active_html .= '<form method="POST" action="' . esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ) . '">'; |
|
| 1309 | 1309 | |
| 1310 | - $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />'; |
|
| 1310 | + $active_html .= '<input type="hidden" name="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" id="' . esc_attr( 'woothemes_sensei_complete_course_noonce' ) . '" value="' . esc_attr( wp_create_nonce( 'woothemes_sensei_complete_course_noonce' ) ) . '" />'; |
|
| 1311 | 1311 | |
| 1312 | - $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1312 | + $active_html .= '<input type="hidden" name="course_complete_id" id="course-complete-id" value="' . esc_attr( absint( $course_item->ID ) ) . '" />'; |
|
| 1313 | 1313 | |
| 1314 | - if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1314 | + if ( 0 < absint( count( $course_lessons ) ) && Sensei()->settings->settings['course_completion'] == 'complete' ) { |
|
| 1315 | 1315 | |
| 1316 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1317 | - . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1316 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-complete" value="' |
|
| 1317 | + . __( 'Mark as Complete', 'woothemes-sensei' ) . '"/> </span>'; |
|
| 1318 | 1318 | |
| 1319 | - } // End If Statement |
|
| 1319 | + } // End If Statement |
|
| 1320 | 1320 | |
| 1321 | - $course_purchased = false; |
|
| 1322 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1321 | + $course_purchased = false; |
|
| 1322 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1323 | 1323 | |
| 1324 | - // Get the product ID |
|
| 1325 | - $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1326 | - if ( 0 < $wc_post_id ) { |
|
| 1324 | + // Get the product ID |
|
| 1325 | + $wc_post_id = get_post_meta( absint( $course_item->ID ), '_course_woocommerce_product', true ); |
|
| 1326 | + if ( 0 < $wc_post_id ) { |
|
| 1327 | 1327 | |
| 1328 | - $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1328 | + $course_purchased = Sensei_WC::has_customer_bought_product( $user->ID, $wc_post_id ); |
|
| 1329 | 1329 | |
| 1330 | - } // End If Statement |
|
| 1330 | + } // End If Statement |
|
| 1331 | 1331 | |
| 1332 | - } // End If Statement |
|
| 1332 | + } // End If Statement |
|
| 1333 | 1333 | |
| 1334 | - if ( false == $course_purchased ) { |
|
| 1334 | + if ( false == $course_purchased ) { |
|
| 1335 | 1335 | |
| 1336 | - $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1337 | - . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1336 | + $active_html .= '<span><input name="course_complete" type="submit" class="course-delete" value="' |
|
| 1337 | + . __( 'Delete Course', 'woothemes-sensei' ) . '"/></span>'; |
|
| 1338 | 1338 | |
| 1339 | - } // End If Statement |
|
| 1339 | + } // End If Statement |
|
| 1340 | 1340 | |
| 1341 | - $active_html .= '</form>'; |
|
| 1341 | + $active_html .= '</form>'; |
|
| 1342 | 1342 | |
| 1343 | - $active_html .= '</section>'; |
|
| 1344 | - } |
|
| 1343 | + $active_html .= '</section>'; |
|
| 1344 | + } |
|
| 1345 | 1345 | |
| 1346 | - $active_html .= '</article>'; |
|
| 1346 | + $active_html .= '</article>'; |
|
| 1347 | 1347 | } |
| 1348 | 1348 | |
| 1349 | 1349 | // Active pagination |
@@ -1383,49 +1383,49 @@ discard block |
||
| 1383 | 1383 | foreach ( $completed_courses as $course_item ) { |
| 1384 | 1384 | $course = $course_item; |
| 1385 | 1385 | |
| 1386 | - // Get Course Categories |
|
| 1387 | - $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1386 | + // Get Course Categories |
|
| 1387 | + $category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' ); |
|
| 1388 | 1388 | |
| 1389 | - $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1389 | + $complete_html .= '<article class="' . join( ' ', get_post_class( array( 'course', 'post' ), $course_item->ID ) ) . '">'; |
|
| 1390 | 1390 | |
| 1391 | - // Image |
|
| 1392 | - $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1391 | + // Image |
|
| 1392 | + $complete_html .= Sensei()->course->course_image( absint( $course_item->ID ),100, 100, true ); |
|
| 1393 | 1393 | |
| 1394 | - // Title |
|
| 1395 | - $complete_html .= '<header>'; |
|
| 1394 | + // Title |
|
| 1395 | + $complete_html .= '<header>'; |
|
| 1396 | 1396 | |
| 1397 | - $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1397 | + $complete_html .= '<h2><a href="' . esc_url( get_permalink( absint( $course_item->ID ) ) ) . '" title="' . esc_attr( $course_item->post_title ) . '">' . esc_html( $course_item->post_title ) . '</a></h2>'; |
|
| 1398 | 1398 | |
| 1399 | - $complete_html .= '</header>'; |
|
| 1399 | + $complete_html .= '</header>'; |
|
| 1400 | 1400 | |
| 1401 | - $complete_html .= '<section class="entry">'; |
|
| 1401 | + $complete_html .= '<section class="entry">'; |
|
| 1402 | 1402 | |
| 1403 | - $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1403 | + $complete_html .= '<p class="sensei-course-meta">'; |
|
| 1404 | 1404 | |
| 1405 | - // Author |
|
| 1406 | - $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1407 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1408 | - $complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 1409 | - } // End If Statement |
|
| 1405 | + // Author |
|
| 1406 | + $user_info = get_userdata( absint( $course_item->post_author ) ); |
|
| 1407 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { |
|
| 1408 | + $complete_html .= '<span class="course-author">' . __( 'by ', 'woothemes-sensei' ) . '<a href="' . esc_url( get_author_posts_url( absint( $course_item->post_author ) ) ) . '" title="' . esc_attr( $user_info->display_name ) . '">' . esc_html( $user_info->display_name ) . '</a></span>'; |
|
| 1409 | + } // End If Statement |
|
| 1410 | 1410 | |
| 1411 | - // Lesson count for this author |
|
| 1412 | - $complete_html .= '<span class="course-lesson-count">' |
|
| 1413 | - . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1414 | - . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1415 | - . '</span>'; |
|
| 1411 | + // Lesson count for this author |
|
| 1412 | + $complete_html .= '<span class="course-lesson-count">' |
|
| 1413 | + . Sensei()->course->course_lesson_count( absint( $course_item->ID ) ) |
|
| 1414 | + . ' ' . __( 'Lessons', 'woothemes-sensei' ) |
|
| 1415 | + . '</span>'; |
|
| 1416 | 1416 | |
| 1417 | - // Course Categories |
|
| 1418 | - if ( '' != $category_output ) { |
|
| 1417 | + // Course Categories |
|
| 1418 | + if ( '' != $category_output ) { |
|
| 1419 | 1419 | |
| 1420 | - $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1420 | + $complete_html .= '<span class="course-category">' . sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ) . '</span>'; |
|
| 1421 | 1421 | |
| 1422 | - } // End If Statement |
|
| 1422 | + } // End If Statement |
|
| 1423 | 1423 | |
| 1424 | 1424 | $complete_html .= '</p>'; |
| 1425 | 1425 | |
| 1426 | 1426 | $complete_html .= '<p class="course-excerpt">' . $course_item->post_excerpt . '</p>'; |
| 1427 | 1427 | |
| 1428 | - $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1428 | + $complete_html .= $this->get_progress_meter( 100 ); |
|
| 1429 | 1429 | |
| 1430 | 1430 | if( $manage ) { |
| 1431 | 1431 | $has_quizzes = Sensei()->course->course_quizzes( $course_item->ID, true ); |
@@ -1438,9 +1438,9 @@ discard block |
||
| 1438 | 1438 | if( $has_quizzes ) { |
| 1439 | 1439 | |
| 1440 | 1440 | $results_link = '<a class="button view-results" href="' |
| 1441 | - . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1442 | - . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1443 | - . '</a>'; |
|
| 1441 | + . Sensei()->course_results->get_permalink( $course_item->ID ) |
|
| 1442 | + . '">' . __( 'View results', 'woothemes-sensei' ) |
|
| 1443 | + . '</a>'; |
|
| 1444 | 1444 | } |
| 1445 | 1445 | $complete_html .= apply_filters( 'sensei_results_links', $results_link ); |
| 1446 | 1446 | $complete_html .= '</p>'; |
@@ -1448,9 +1448,9 @@ discard block |
||
| 1448 | 1448 | } |
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | - $complete_html .= '</section>'; |
|
| 1451 | + $complete_html .= '</section>'; |
|
| 1452 | 1452 | |
| 1453 | - $complete_html .= '</article>'; |
|
| 1453 | + $complete_html .= '</article>'; |
|
| 1454 | 1454 | } |
| 1455 | 1455 | |
| 1456 | 1456 | // Active pagination |
@@ -1525,16 +1525,16 @@ discard block |
||
| 1525 | 1525 | <?php do_action( 'sensei_before_active_user_courses' ); ?> |
| 1526 | 1526 | |
| 1527 | 1527 | <?php |
| 1528 | - $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1529 | - ?> |
|
| 1528 | + $course_page_url = Sensei_Course::get_courses_page_url(); |
|
| 1529 | + ?> |
|
| 1530 | 1530 | |
| 1531 | 1531 | <div id="active-courses"> |
| 1532 | 1532 | |
| 1533 | 1533 | <?php if ( '' != $active_html ) { |
| 1534 | 1534 | |
| 1535 | - echo $active_html; |
|
| 1535 | + echo $active_html; |
|
| 1536 | 1536 | |
| 1537 | - } else { ?> |
|
| 1537 | + } else { ?> |
|
| 1538 | 1538 | |
| 1539 | 1539 | <div class="sensei-message info"> |
| 1540 | 1540 | |
@@ -1560,9 +1560,9 @@ discard block |
||
| 1560 | 1560 | |
| 1561 | 1561 | <?php if ( '' != $complete_html ) { |
| 1562 | 1562 | |
| 1563 | - echo $complete_html; |
|
| 1563 | + echo $complete_html; |
|
| 1564 | 1564 | |
| 1565 | - } else { ?> |
|
| 1565 | + } else { ?> |
|
| 1566 | 1566 | |
| 1567 | 1567 | <div class="sensei-message info"> |
| 1568 | 1568 | |
@@ -1581,356 +1581,356 @@ discard block |
||
| 1581 | 1581 | <?php do_action( 'sensei_after_user_courses' ); ?> |
| 1582 | 1582 | |
| 1583 | 1583 | <?php |
| 1584 | - echo ob_get_clean(); |
|
| 1584 | + echo ob_get_clean(); |
|
| 1585 | 1585 | |
| 1586 | - do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1586 | + do_action( 'sensei_after_learner_course_content', $user ); |
|
| 1587 | 1587 | |
| 1588 | 1588 | } // end load_user_courses_content |
| 1589 | 1589 | |
| 1590 | - /** |
|
| 1591 | - * Returns a list of all courses |
|
| 1592 | - * |
|
| 1593 | - * @since 1.8.0 |
|
| 1594 | - * @return array $courses{ |
|
| 1595 | - * @type $course WP_Post |
|
| 1596 | - * } |
|
| 1597 | - */ |
|
| 1598 | - public static function get_all_courses(){ |
|
| 1599 | - |
|
| 1600 | - $args = array( |
|
| 1601 | - 'post_type' => 'course', |
|
| 1602 | - 'posts_per_page' => -1, |
|
| 1603 | - 'orderby' => 'title', |
|
| 1604 | - 'order' => 'ASC', |
|
| 1605 | - 'post_status' => 'any', |
|
| 1606 | - 'suppress_filters' => 0, |
|
| 1607 | - ); |
|
| 1608 | - |
|
| 1609 | - $wp_query_obj = new WP_Query( $args ); |
|
| 1610 | - |
|
| 1611 | - /** |
|
| 1612 | - * sensei_get_all_courses filter |
|
| 1613 | - * |
|
| 1614 | - * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1615 | - * |
|
| 1616 | - * @param array $courses{ |
|
| 1617 | - * @type WP_Post |
|
| 1618 | - * } |
|
| 1619 | - * @param array $attributes |
|
| 1620 | - */ |
|
| 1621 | - return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1622 | - |
|
| 1623 | - }// end get_all_courses |
|
| 1624 | - |
|
| 1625 | - /** |
|
| 1626 | - * Generate the course meter component |
|
| 1627 | - * |
|
| 1628 | - * @since 1.8.0 |
|
| 1629 | - * @param int $progress_percentage 0 - 100 |
|
| 1630 | - * @return string $progress_bar_html |
|
| 1631 | - */ |
|
| 1632 | - public function get_progress_meter( $progress_percentage ){ |
|
| 1633 | - |
|
| 1634 | - if ( 50 < $progress_percentage ) { |
|
| 1635 | - $class = ' green'; |
|
| 1636 | - } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1637 | - $class = ' orange'; |
|
| 1638 | - } else { |
|
| 1639 | - $class = ' red'; |
|
| 1640 | - } |
|
| 1641 | - $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1642 | - |
|
| 1643 | - return $progress_bar_html; |
|
| 1644 | - |
|
| 1645 | - }// end get_progress_meter |
|
| 1646 | - |
|
| 1647 | - /** |
|
| 1648 | - * Generate a statement that tells users |
|
| 1649 | - * how far they are in the course. |
|
| 1650 | - * |
|
| 1651 | - * @param int $course_id |
|
| 1652 | - * @param int $user_id |
|
| 1653 | - * |
|
| 1654 | - * @return string $statement_html |
|
| 1655 | - */ |
|
| 1656 | - public function get_progress_statement( $course_id, $user_id ){ |
|
| 1657 | - |
|
| 1658 | - if( empty( $course_id ) || empty( $user_id ) |
|
| 1659 | - || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1660 | - return ''; |
|
| 1661 | - } |
|
| 1662 | - |
|
| 1663 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1664 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1665 | - |
|
| 1666 | - $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons ); |
|
| 1667 | - |
|
| 1668 | - /** |
|
| 1669 | - * Filter the course completion statement. |
|
| 1670 | - * Default Currently completed $var lesson($plural) of $var in total |
|
| 1671 | - * |
|
| 1672 | - * @param string $statement |
|
| 1673 | - */ |
|
| 1674 | - return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1675 | - |
|
| 1676 | - }// end generate_progress_statement |
|
| 1677 | - |
|
| 1678 | - /** |
|
| 1679 | - * Output the course progress statement |
|
| 1680 | - * |
|
| 1681 | - * @param $course_id |
|
| 1682 | - * @return void |
|
| 1683 | - */ |
|
| 1684 | - public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1685 | - if( empty( $course_id ) ){ |
|
| 1686 | - global $post; |
|
| 1687 | - $course_id = $post->ID; |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - if( empty( $user_id ) ){ |
|
| 1691 | - $user_id = get_current_user_id(); |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1695 | - } |
|
| 1696 | - |
|
| 1697 | - /** |
|
| 1698 | - * Output the course progress bar |
|
| 1699 | - * |
|
| 1700 | - * @param $course_id |
|
| 1701 | - * @return void |
|
| 1702 | - */ |
|
| 1703 | - public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1704 | - |
|
| 1705 | - if( empty( $course_id ) ){ |
|
| 1706 | - global $post; |
|
| 1707 | - $course_id = $post->ID; |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - if( empty( $user_id ) ){ |
|
| 1711 | - $user_id = get_current_user_id(); |
|
| 1712 | - } |
|
| 1713 | - |
|
| 1714 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1715 | - || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1716 | - return; |
|
| 1717 | - } |
|
| 1718 | - $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1719 | - |
|
| 1720 | - echo $this->get_progress_meter( $percentage_completed ); |
|
| 1721 | - |
|
| 1722 | - }// end the_progress_meter |
|
| 1723 | - |
|
| 1724 | - /** |
|
| 1725 | - * Checks how many lessons are completed |
|
| 1726 | - * |
|
| 1727 | - * @since 1.8.0 |
|
| 1728 | - * |
|
| 1729 | - * @param int $course_id |
|
| 1730 | - * @param int $user_id |
|
| 1731 | - * @return array $completed_lesson_ids |
|
| 1732 | - */ |
|
| 1733 | - public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1734 | - |
|
| 1735 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1736 | - $user_id = get_current_user_id(); |
|
| 1737 | - } |
|
| 1590 | + /** |
|
| 1591 | + * Returns a list of all courses |
|
| 1592 | + * |
|
| 1593 | + * @since 1.8.0 |
|
| 1594 | + * @return array $courses{ |
|
| 1595 | + * @type $course WP_Post |
|
| 1596 | + * } |
|
| 1597 | + */ |
|
| 1598 | + public static function get_all_courses(){ |
|
| 1599 | + |
|
| 1600 | + $args = array( |
|
| 1601 | + 'post_type' => 'course', |
|
| 1602 | + 'posts_per_page' => -1, |
|
| 1603 | + 'orderby' => 'title', |
|
| 1604 | + 'order' => 'ASC', |
|
| 1605 | + 'post_status' => 'any', |
|
| 1606 | + 'suppress_filters' => 0, |
|
| 1607 | + ); |
|
| 1608 | + |
|
| 1609 | + $wp_query_obj = new WP_Query( $args ); |
|
| 1610 | + |
|
| 1611 | + /** |
|
| 1612 | + * sensei_get_all_courses filter |
|
| 1613 | + * |
|
| 1614 | + * This filter runs inside Sensei_Course::get_all_courses. |
|
| 1615 | + * |
|
| 1616 | + * @param array $courses{ |
|
| 1617 | + * @type WP_Post |
|
| 1618 | + * } |
|
| 1619 | + * @param array $attributes |
|
| 1620 | + */ |
|
| 1621 | + return apply_filters( 'sensei_get_all_courses' , $wp_query_obj->posts ); |
|
| 1622 | + |
|
| 1623 | + }// end get_all_courses |
|
| 1624 | + |
|
| 1625 | + /** |
|
| 1626 | + * Generate the course meter component |
|
| 1627 | + * |
|
| 1628 | + * @since 1.8.0 |
|
| 1629 | + * @param int $progress_percentage 0 - 100 |
|
| 1630 | + * @return string $progress_bar_html |
|
| 1631 | + */ |
|
| 1632 | + public function get_progress_meter( $progress_percentage ){ |
|
| 1633 | + |
|
| 1634 | + if ( 50 < $progress_percentage ) { |
|
| 1635 | + $class = ' green'; |
|
| 1636 | + } elseif ( 25 <= $progress_percentage && 50 >= $progress_percentage ) { |
|
| 1637 | + $class = ' orange'; |
|
| 1638 | + } else { |
|
| 1639 | + $class = ' red'; |
|
| 1640 | + } |
|
| 1641 | + $progress_bar_html = '<div class="meter' . esc_attr( $class ) . '"><span style="width: ' . $progress_percentage . '%">' . round( $progress_percentage ) . '%</span></div>'; |
|
| 1642 | + |
|
| 1643 | + return $progress_bar_html; |
|
| 1644 | + |
|
| 1645 | + }// end get_progress_meter |
|
| 1646 | + |
|
| 1647 | + /** |
|
| 1648 | + * Generate a statement that tells users |
|
| 1649 | + * how far they are in the course. |
|
| 1650 | + * |
|
| 1651 | + * @param int $course_id |
|
| 1652 | + * @param int $user_id |
|
| 1653 | + * |
|
| 1654 | + * @return string $statement_html |
|
| 1655 | + */ |
|
| 1656 | + public function get_progress_statement( $course_id, $user_id ){ |
|
| 1657 | + |
|
| 1658 | + if( empty( $course_id ) || empty( $user_id ) |
|
| 1659 | + || ! Sensei_Utils::user_started_course( $course_id, $user_id ) ){ |
|
| 1660 | + return ''; |
|
| 1661 | + } |
|
| 1662 | + |
|
| 1663 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1664 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1665 | + |
|
| 1666 | + $statement = sprintf( _n('Currently completed %s lesson of %s in total', 'Currently completed %s lessons of %s in total', $completed, 'woothemes-sensei'), $completed, $total_lessons ); |
|
| 1667 | + |
|
| 1668 | + /** |
|
| 1669 | + * Filter the course completion statement. |
|
| 1670 | + * Default Currently completed $var lesson($plural) of $var in total |
|
| 1671 | + * |
|
| 1672 | + * @param string $statement |
|
| 1673 | + */ |
|
| 1674 | + return apply_filters( 'sensei_course_completion_statement', $statement ); |
|
| 1675 | + |
|
| 1676 | + }// end generate_progress_statement |
|
| 1677 | + |
|
| 1678 | + /** |
|
| 1679 | + * Output the course progress statement |
|
| 1680 | + * |
|
| 1681 | + * @param $course_id |
|
| 1682 | + * @return void |
|
| 1683 | + */ |
|
| 1684 | + public function the_progress_statement( $course_id = 0, $user_id = 0 ){ |
|
| 1685 | + if( empty( $course_id ) ){ |
|
| 1686 | + global $post; |
|
| 1687 | + $course_id = $post->ID; |
|
| 1688 | + } |
|
| 1689 | + |
|
| 1690 | + if( empty( $user_id ) ){ |
|
| 1691 | + $user_id = get_current_user_id(); |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + echo '<span class="progress statement course-completion-rate">' . $this->get_progress_statement( $course_id, $user_id ) . '</span>'; |
|
| 1695 | + } |
|
| 1696 | + |
|
| 1697 | + /** |
|
| 1698 | + * Output the course progress bar |
|
| 1699 | + * |
|
| 1700 | + * @param $course_id |
|
| 1701 | + * @return void |
|
| 1702 | + */ |
|
| 1703 | + public function the_progress_meter( $course_id = 0, $user_id = 0 ){ |
|
| 1704 | + |
|
| 1705 | + if( empty( $course_id ) ){ |
|
| 1706 | + global $post; |
|
| 1707 | + $course_id = $post->ID; |
|
| 1708 | + } |
|
| 1709 | + |
|
| 1710 | + if( empty( $user_id ) ){ |
|
| 1711 | + $user_id = get_current_user_id(); |
|
| 1712 | + } |
|
| 1713 | + |
|
| 1714 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $user_id ) |
|
| 1715 | + || ! Sensei_Utils::user_started_course( $course_id ,$user_id ) ){ |
|
| 1716 | + return; |
|
| 1717 | + } |
|
| 1718 | + $percentage_completed = $this->get_completion_percentage( $course_id, $user_id ); |
|
| 1719 | + |
|
| 1720 | + echo $this->get_progress_meter( $percentage_completed ); |
|
| 1738 | 1721 | |
| 1739 | - $completed_lesson_ids = array(); |
|
| 1722 | + }// end the_progress_meter |
|
| 1740 | 1723 | |
| 1741 | - $course_lessons = $this->course_lessons( $course_id ); |
|
| 1724 | + /** |
|
| 1725 | + * Checks how many lessons are completed |
|
| 1726 | + * |
|
| 1727 | + * @since 1.8.0 |
|
| 1728 | + * |
|
| 1729 | + * @param int $course_id |
|
| 1730 | + * @param int $user_id |
|
| 1731 | + * @return array $completed_lesson_ids |
|
| 1732 | + */ |
|
| 1733 | + public function get_completed_lesson_ids( $course_id, $user_id = 0 ){ |
|
| 1734 | + |
|
| 1735 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1736 | + $user_id = get_current_user_id(); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + $completed_lesson_ids = array(); |
|
| 1740 | + |
|
| 1741 | + $course_lessons = $this->course_lessons( $course_id ); |
|
| 1742 | + |
|
| 1743 | + foreach( $course_lessons as $lesson ){ |
|
| 1744 | + |
|
| 1745 | + $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1746 | + if( $is_lesson_completed ){ |
|
| 1747 | + $completed_lesson_ids[] = $lesson->ID; |
|
| 1748 | + } |
|
| 1749 | + |
|
| 1750 | + } |
|
| 1751 | + |
|
| 1752 | + return $completed_lesson_ids; |
|
| 1753 | + |
|
| 1754 | + }// end get_completed_lesson_ids |
|
| 1755 | + |
|
| 1756 | + /** |
|
| 1757 | + * Calculate the perceantage completed in the course |
|
| 1758 | + * |
|
| 1759 | + * @since 1.8.0 |
|
| 1760 | + * |
|
| 1761 | + * @param int $course_id |
|
| 1762 | + * @param int $user_id |
|
| 1763 | + * @return int $percentage |
|
| 1764 | + */ |
|
| 1765 | + public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1766 | + |
|
| 1767 | + if( !( intval( $user_id ) ) > 0 ){ |
|
| 1768 | + $user_id = get_current_user_id(); |
|
| 1769 | + } |
|
| 1770 | + |
|
| 1771 | + $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1772 | + |
|
| 1773 | + if( ! ( $completed > 0 ) ){ |
|
| 1774 | + return 0; |
|
| 1775 | + } |
|
| 1776 | + |
|
| 1777 | + $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1778 | + $percentage = $completed / $total_lessons * 100; |
|
| 1779 | + |
|
| 1780 | + /** |
|
| 1781 | + * |
|
| 1782 | + * Filter the percentage returned for a users course. |
|
| 1783 | + * |
|
| 1784 | + * @param $percentage |
|
| 1785 | + * @param $course_id |
|
| 1786 | + * @param $user_id |
|
| 1787 | + * @since 1.8.0 |
|
| 1788 | + */ |
|
| 1789 | + return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1790 | + |
|
| 1791 | + }// end get_completed_lesson_ids |
|
| 1792 | + |
|
| 1793 | + /** |
|
| 1794 | + * Block email notifications for the specific courses |
|
| 1795 | + * that the user disabled the notifications. |
|
| 1796 | + * |
|
| 1797 | + * @since 1.8.0 |
|
| 1798 | + * @param $should_send |
|
| 1799 | + * @return bool |
|
| 1800 | + */ |
|
| 1801 | + public function block_notification_emails( $should_send ){ |
|
| 1802 | + global $sensei_email_data; |
|
| 1803 | + $email = $sensei_email_data; |
|
| 1804 | + |
|
| 1805 | + $course_id = ''; |
|
| 1806 | + |
|
| 1807 | + if( isset( $email['course_id'] ) ){ |
|
| 1808 | + |
|
| 1809 | + $course_id = $email['course_id']; |
|
| 1810 | + |
|
| 1811 | + }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1812 | + |
|
| 1813 | + $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1814 | + |
|
| 1815 | + }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1816 | + |
|
| 1817 | + $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1818 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1819 | + |
|
| 1820 | + } |
|
| 1821 | + |
|
| 1822 | + if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1823 | + |
|
| 1824 | + $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1825 | + |
|
| 1826 | + if ($course_emails_disabled) { |
|
| 1827 | + |
|
| 1828 | + return false; |
|
| 1829 | + |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + }// end if |
|
| 1833 | + |
|
| 1834 | + return $should_send; |
|
| 1835 | + }// end block_notification_emails |
|
| 1836 | + |
|
| 1837 | + /** |
|
| 1838 | + * Render the course notification setting meta box |
|
| 1839 | + * |
|
| 1840 | + * @since 1.8.0 |
|
| 1841 | + * @param $course |
|
| 1842 | + */ |
|
| 1843 | + public function course_notification_meta_box_content( $course ){ |
|
| 1742 | 1844 | |
| 1743 | - foreach( $course_lessons as $lesson ){ |
|
| 1845 | + $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1744 | 1846 | |
| 1745 | - $is_lesson_completed = Sensei_Utils::user_completed_lesson( $lesson->ID, $user_id ); |
|
| 1746 | - if( $is_lesson_completed ){ |
|
| 1747 | - $completed_lesson_ids[] = $lesson->ID; |
|
| 1748 | - } |
|
| 1749 | - |
|
| 1750 | - } |
|
| 1751 | - |
|
| 1752 | - return $completed_lesson_ids; |
|
| 1847 | + // generate checked html |
|
| 1848 | + $checked_html = ''; |
|
| 1849 | + if( $checked ){ |
|
| 1850 | + $checked_html = 'checked="checked"'; |
|
| 1851 | + } |
|
| 1852 | + wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1853 | + |
|
| 1854 | + echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1855 | + echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1753 | 1856 | |
| 1754 | - }// end get_completed_lesson_ids |
|
| 1857 | + }// end course_notification_meta_box_content |
|
| 1858 | + |
|
| 1859 | + /** |
|
| 1860 | + * Store the setting for the course notification setting. |
|
| 1861 | + * |
|
| 1862 | + * @hooked int save_post |
|
| 1863 | + * @since 1.8.0 |
|
| 1864 | + * |
|
| 1865 | + * @param $course_id |
|
| 1866 | + */ |
|
| 1867 | + public function save_course_notification_meta_box( $course_id ){ |
|
| 1755 | 1868 | |
| 1756 | - /** |
|
| 1757 | - * Calculate the perceantage completed in the course |
|
| 1758 | - * |
|
| 1759 | - * @since 1.8.0 |
|
| 1760 | - * |
|
| 1761 | - * @param int $course_id |
|
| 1762 | - * @param int $user_id |
|
| 1763 | - * @return int $percentage |
|
| 1764 | - */ |
|
| 1765 | - public function get_completion_percentage( $course_id, $user_id = 0 ){ |
|
| 1766 | - |
|
| 1767 | - if( !( intval( $user_id ) ) > 0 ){ |
|
| 1768 | - $user_id = get_current_user_id(); |
|
| 1769 | - } |
|
| 1770 | - |
|
| 1771 | - $completed = count( $this->get_completed_lesson_ids( $course_id, $user_id ) ); |
|
| 1772 | - |
|
| 1773 | - if( ! ( $completed > 0 ) ){ |
|
| 1774 | - return 0; |
|
| 1775 | - } |
|
| 1776 | - |
|
| 1777 | - $total_lessons = count( $this->course_lessons( $course_id ) ); |
|
| 1778 | - $percentage = $completed / $total_lessons * 100; |
|
| 1779 | - |
|
| 1780 | - /** |
|
| 1781 | - * |
|
| 1782 | - * Filter the percentage returned for a users course. |
|
| 1783 | - * |
|
| 1784 | - * @param $percentage |
|
| 1785 | - * @param $course_id |
|
| 1786 | - * @param $user_id |
|
| 1787 | - * @since 1.8.0 |
|
| 1788 | - */ |
|
| 1789 | - return apply_filters( 'sensei_course_completion_percentage', $percentage, $course_id, $user_id ); |
|
| 1869 | + if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1870 | + || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1871 | + return; |
|
| 1872 | + } |
|
| 1790 | 1873 | |
| 1791 | - }// end get_completed_lesson_ids |
|
| 1874 | + if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1875 | + $new_val = true; |
|
| 1876 | + }else{ |
|
| 1877 | + $new_val = false; |
|
| 1878 | + } |
|
| 1792 | 1879 | |
| 1793 | - /** |
|
| 1794 | - * Block email notifications for the specific courses |
|
| 1795 | - * that the user disabled the notifications. |
|
| 1796 | - * |
|
| 1797 | - * @since 1.8.0 |
|
| 1798 | - * @param $should_send |
|
| 1799 | - * @return bool |
|
| 1800 | - */ |
|
| 1801 | - public function block_notification_emails( $should_send ){ |
|
| 1802 | - global $sensei_email_data; |
|
| 1803 | - $email = $sensei_email_data; |
|
| 1880 | + update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1804 | 1881 | |
| 1805 | - $course_id = ''; |
|
| 1882 | + }// end save notification meta box |
|
| 1806 | 1883 | |
| 1807 | - if( isset( $email['course_id'] ) ){ |
|
| 1884 | + /** |
|
| 1885 | + * Backwards compatibility hooks added to ensure that |
|
| 1886 | + * plugins and other parts of sensei still works. |
|
| 1887 | + * |
|
| 1888 | + * This function hooks into `sensei_course_content_inside_before` |
|
| 1889 | + * |
|
| 1890 | + * @since 1.9 |
|
| 1891 | + * |
|
| 1892 | + * @param WP_Post $post |
|
| 1893 | + */ |
|
| 1894 | + public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1808 | 1895 | |
| 1809 | - $course_id = $email['course_id']; |
|
| 1810 | - |
|
| 1811 | - }elseif( isset( $email['lesson_id'] ) ){ |
|
| 1896 | + sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' ); |
|
| 1897 | + sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' ); |
|
| 1812 | 1898 | |
| 1813 | - $course_id = Sensei()->lesson->get_course_id( $email['lesson_id'] ); |
|
| 1899 | + } |
|
| 1814 | 1900 | |
| 1815 | - }elseif( isset( $email['quiz_id'] ) ){ |
|
| 1901 | + /** |
|
| 1902 | + * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1903 | + * |
|
| 1904 | + * hooked into 'sensei_loop_course_before' |
|
| 1905 | + * |
|
| 1906 | + * @since 1.9 |
|
| 1907 | + * |
|
| 1908 | + * @global WP_Post $post |
|
| 1909 | + */ |
|
| 1910 | + public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1816 | 1911 | |
| 1817 | - $lesson_id = Sensei()->quiz->get_lesson_id( $email['quiz_id'] ); |
|
| 1818 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1912 | + global $post; |
|
| 1913 | + sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1819 | 1914 | |
| 1820 | - } |
|
| 1915 | + } |
|
| 1821 | 1916 | |
| 1822 | - if( !empty( $course_id ) && 'course'== get_post_type( $course_id ) ) { |
|
| 1823 | - |
|
| 1824 | - $course_emails_disabled = get_post_meta($course_id, 'disable_notification', true); |
|
| 1825 | - |
|
| 1826 | - if ($course_emails_disabled) { |
|
| 1827 | - |
|
| 1828 | - return false; |
|
| 1829 | - |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - }// end if |
|
| 1833 | - |
|
| 1834 | - return $should_send; |
|
| 1835 | - }// end block_notification_emails |
|
| 1836 | - |
|
| 1837 | - /** |
|
| 1838 | - * Render the course notification setting meta box |
|
| 1839 | - * |
|
| 1840 | - * @since 1.8.0 |
|
| 1841 | - * @param $course |
|
| 1842 | - */ |
|
| 1843 | - public function course_notification_meta_box_content( $course ){ |
|
| 1844 | - |
|
| 1845 | - $checked = get_post_meta( $course->ID , 'disable_notification', true ); |
|
| 1846 | - |
|
| 1847 | - // generate checked html |
|
| 1848 | - $checked_html = ''; |
|
| 1849 | - if( $checked ){ |
|
| 1850 | - $checked_html = 'checked="checked"'; |
|
| 1851 | - } |
|
| 1852 | - wp_nonce_field( 'update-course-notification-setting','_sensei_course_notification' ); |
|
| 1853 | - |
|
| 1854 | - echo '<input id="disable_sensei_course_notification" '.$checked_html .' type="checkbox" name="disable_sensei_course_notification" >'; |
|
| 1855 | - echo '<label for="disable_sensei_course_notification">'.__('Disable notifications on this course ?', 'woothemes-sensei'). '</label>'; |
|
| 1856 | - |
|
| 1857 | - }// end course_notification_meta_box_content |
|
| 1858 | - |
|
| 1859 | - /** |
|
| 1860 | - * Store the setting for the course notification setting. |
|
| 1861 | - * |
|
| 1862 | - * @hooked int save_post |
|
| 1863 | - * @since 1.8.0 |
|
| 1864 | - * |
|
| 1865 | - * @param $course_id |
|
| 1866 | - */ |
|
| 1867 | - public function save_course_notification_meta_box( $course_id ){ |
|
| 1868 | - |
|
| 1869 | - if( !isset( $_POST['_sensei_course_notification'] ) |
|
| 1870 | - || ! wp_verify_nonce( $_POST['_sensei_course_notification'], 'update-course-notification-setting' ) ){ |
|
| 1871 | - return; |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - if( isset( $_POST['disable_sensei_course_notification'] ) && 'on'== $_POST['disable_sensei_course_notification'] ) { |
|
| 1875 | - $new_val = true; |
|
| 1876 | - }else{ |
|
| 1877 | - $new_val = false; |
|
| 1878 | - } |
|
| 1879 | - |
|
| 1880 | - update_post_meta( $course_id , 'disable_notification', $new_val ); |
|
| 1881 | - |
|
| 1882 | - }// end save notification meta box |
|
| 1883 | - |
|
| 1884 | - /** |
|
| 1885 | - * Backwards compatibility hooks added to ensure that |
|
| 1886 | - * plugins and other parts of sensei still works. |
|
| 1887 | - * |
|
| 1888 | - * This function hooks into `sensei_course_content_inside_before` |
|
| 1889 | - * |
|
| 1890 | - * @since 1.9 |
|
| 1891 | - * |
|
| 1892 | - * @param WP_Post $post |
|
| 1893 | - */ |
|
| 1894 | - public function content_before_backwards_compatibility_hooks( $post ){ |
|
| 1895 | - |
|
| 1896 | - sensei_do_deprecated_action( 'sensei_course_image','1.9.0','sensei_course_content_inside_before' ); |
|
| 1897 | - sensei_do_deprecated_action( 'sensei_course_archive_course_title','1.9.0','sensei_course_content_inside_before' ); |
|
| 1898 | - |
|
| 1899 | - } |
|
| 1917 | + /** |
|
| 1918 | + * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1919 | + * |
|
| 1920 | + * hooked into 'sensei_course_content_inside_after' |
|
| 1921 | + * |
|
| 1922 | + * @since 1.9.0 |
|
| 1923 | + * |
|
| 1924 | + * @param integer $course_id |
|
| 1925 | + */ |
|
| 1926 | + public function the_course_free_lesson_preview( $course_id ){ |
|
| 1927 | + // Meta data |
|
| 1928 | + $course = get_post( $course_id ); |
|
| 1929 | + $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1930 | + $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1900 | 1931 | |
| 1901 | - /** |
|
| 1902 | - * Backwards compatibility hooks that should be hooked into sensei_loop_course_before |
|
| 1903 | - * |
|
| 1904 | - * hooked into 'sensei_loop_course_before' |
|
| 1905 | - * |
|
| 1906 | - * @since 1.9 |
|
| 1907 | - * |
|
| 1908 | - * @global WP_Post $post |
|
| 1909 | - */ |
|
| 1910 | - public function loop_before_backwards_compatibility_hooks( ){ |
|
| 1911 | - |
|
| 1912 | - global $post; |
|
| 1913 | - sensei_do_deprecated_action( 'sensei_course_archive_header','1.9.0','sensei_course_content_inside_before', $post->post_type ); |
|
| 1914 | - |
|
| 1915 | - } |
|
| 1916 | - |
|
| 1917 | - /** |
|
| 1918 | - * Output a link to view course. The button text is different depending on the amount of preview lesson available. |
|
| 1919 | - * |
|
| 1920 | - * hooked into 'sensei_course_content_inside_after' |
|
| 1921 | - * |
|
| 1922 | - * @since 1.9.0 |
|
| 1923 | - * |
|
| 1924 | - * @param integer $course_id |
|
| 1925 | - */ |
|
| 1926 | - public function the_course_free_lesson_preview( $course_id ){ |
|
| 1927 | - // Meta data |
|
| 1928 | - $course = get_post( $course_id ); |
|
| 1929 | - $preview_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $course->ID ) ); |
|
| 1930 | - $is_user_taking_course = Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ); |
|
| 1931 | - |
|
| 1932 | - if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1933 | - ?> |
|
| 1932 | + if ( 0 < $preview_lesson_count && !$is_user_taking_course ) { |
|
| 1933 | + ?> |
|
| 1934 | 1934 | <p class="sensei-free-lessons"> |
| 1935 | 1935 | <a href="<?php echo get_permalink(); ?>"> |
| 1936 | 1936 | <?php _e( 'Preview this course', 'woothemes-sensei' ) ?> |
@@ -1939,23 +1939,23 @@ discard block |
||
| 1939 | 1939 | </p> |
| 1940 | 1940 | |
| 1941 | 1941 | <?php |
| 1942 | - } |
|
| 1943 | - } |
|
| 1942 | + } |
|
| 1943 | + } |
|
| 1944 | 1944 | |
| 1945 | - /** |
|
| 1946 | - * Add course mata to the course meta hook |
|
| 1947 | - * |
|
| 1948 | - * @since 1.9.0 |
|
| 1949 | - * @param integer $course_id |
|
| 1950 | - */ |
|
| 1951 | - public function the_course_meta( $course_id ){ |
|
| 1952 | - echo '<p class="sensei-course-meta">'; |
|
| 1945 | + /** |
|
| 1946 | + * Add course mata to the course meta hook |
|
| 1947 | + * |
|
| 1948 | + * @since 1.9.0 |
|
| 1949 | + * @param integer $course_id |
|
| 1950 | + */ |
|
| 1951 | + public function the_course_meta( $course_id ){ |
|
| 1952 | + echo '<p class="sensei-course-meta">'; |
|
| 1953 | 1953 | |
| 1954 | - $course = get_post( $course_id ); |
|
| 1955 | - $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1956 | - $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1954 | + $course = get_post( $course_id ); |
|
| 1955 | + $category_output = get_the_term_list( $course->ID, 'course-category', '', ', ', '' ); |
|
| 1956 | + $author_display_name = get_the_author_meta( 'display_name', $course->post_author ); |
|
| 1957 | 1957 | |
| 1958 | - if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1958 | + if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) {?> |
|
| 1959 | 1959 | |
| 1960 | 1960 | <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?> |
| 1961 | 1961 | |
@@ -1973,62 +1973,62 @@ discard block |
||
| 1973 | 1973 | |
| 1974 | 1974 | <?php } // End If Statement |
| 1975 | 1975 | |
| 1976 | - // number of completed lessons |
|
| 1977 | - if( Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ) |
|
| 1978 | - || Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ){ |
|
| 1976 | + // number of completed lessons |
|
| 1977 | + if( Sensei_Utils::user_started_course( $course->ID, get_current_user_id() ) |
|
| 1978 | + || Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ){ |
|
| 1979 | 1979 | |
| 1980 | - $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1981 | - $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1982 | - echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1980 | + $completed = count( $this->get_completed_lesson_ids( $course->ID, get_current_user_id() ) ); |
|
| 1981 | + $lesson_count = count( $this->course_lessons( $course->ID ) ); |
|
| 1982 | + echo '<span class="course-lesson-progress">' . sprintf( __( '%1$d of %2$d lessons completed', 'woothemes-sensei' ) , $completed, $lesson_count ) . '</span>'; |
|
| 1983 | 1983 | |
| 1984 | - } |
|
| 1984 | + } |
|
| 1985 | 1985 | |
| 1986 | - sensei_simple_course_price( $course->ID ); |
|
| 1986 | + sensei_simple_course_price( $course->ID ); |
|
| 1987 | 1987 | |
| 1988 | - echo '</p>'; |
|
| 1989 | - } // end the course meta |
|
| 1988 | + echo '</p>'; |
|
| 1989 | + } // end the course meta |
|
| 1990 | 1990 | |
| 1991 | - /** |
|
| 1992 | - * Filter the classes attached to a post types for courses |
|
| 1993 | - * and add a status class for when the user is logged in. |
|
| 1994 | - * |
|
| 1995 | - * @param $classes |
|
| 1996 | - * @param $class |
|
| 1997 | - * @param $post_id |
|
| 1998 | - * |
|
| 1999 | - * @return array $classes |
|
| 2000 | - */ |
|
| 2001 | - public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 1991 | + /** |
|
| 1992 | + * Filter the classes attached to a post types for courses |
|
| 1993 | + * and add a status class for when the user is logged in. |
|
| 1994 | + * |
|
| 1995 | + * @param $classes |
|
| 1996 | + * @param $class |
|
| 1997 | + * @param $post_id |
|
| 1998 | + * |
|
| 1999 | + * @return array $classes |
|
| 2000 | + */ |
|
| 2001 | + public static function add_course_user_status_class( $classes, $class, $course_id ){ |
|
| 2002 | 2002 | |
| 2003 | - if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 2003 | + if( 'course' == get_post_type( $course_id ) && is_user_logged_in() ){ |
|
| 2004 | 2004 | |
| 2005 | - if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2005 | + if( Sensei_Utils::user_completed_course( $course_id, get_current_user_id() ) ){ |
|
| 2006 | 2006 | |
| 2007 | - $classes[] = 'user-status-completed'; |
|
| 2007 | + $classes[] = 'user-status-completed'; |
|
| 2008 | 2008 | |
| 2009 | - }else{ |
|
| 2009 | + }else{ |
|
| 2010 | 2010 | |
| 2011 | - $classes[] = 'user-status-active'; |
|
| 2011 | + $classes[] = 'user-status-active'; |
|
| 2012 | 2012 | |
| 2013 | - } |
|
| 2013 | + } |
|
| 2014 | 2014 | |
| 2015 | - } |
|
| 2015 | + } |
|
| 2016 | 2016 | |
| 2017 | - return $classes; |
|
| 2017 | + return $classes; |
|
| 2018 | 2018 | |
| 2019 | - }// end add_course_user_status_class |
|
| 2019 | + }// end add_course_user_status_class |
|
| 2020 | 2020 | |
| 2021 | - /** |
|
| 2022 | - * Prints out the course action buttons links |
|
| 2023 | - * |
|
| 2024 | - * - complete course |
|
| 2025 | - * - delete course |
|
| 2026 | - * |
|
| 2027 | - * @param WP_Post $course |
|
| 2028 | - */ |
|
| 2029 | - public static function the_course_action_buttons( $course ){ |
|
| 2021 | + /** |
|
| 2022 | + * Prints out the course action buttons links |
|
| 2023 | + * |
|
| 2024 | + * - complete course |
|
| 2025 | + * - delete course |
|
| 2026 | + * |
|
| 2027 | + * @param WP_Post $course |
|
| 2028 | + */ |
|
| 2029 | + public static function the_course_action_buttons( $course ){ |
|
| 2030 | 2030 | |
| 2031 | - if( is_user_logged_in() ) { ?> |
|
| 2031 | + if( is_user_logged_in() ) { ?> |
|
| 2032 | 2032 | |
| 2033 | 2033 | <section class="entry-actions"> |
| 2034 | 2034 | <form method="POST" action="<?php echo esc_url( remove_query_arg( array( 'active_page', 'completed_page' ) ) ); ?>"> |
@@ -2047,32 +2047,32 @@ discard block |
||
| 2047 | 2047 | |
| 2048 | 2048 | <?php } // End If Statement |
| 2049 | 2049 | |
| 2050 | - $course_purchased = false; |
|
| 2051 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 2052 | - // Get the product ID |
|
| 2053 | - $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2054 | - if ( 0 < $wc_post_id ) { |
|
| 2050 | + $course_purchased = false; |
|
| 2051 | + if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 2052 | + // Get the product ID |
|
| 2053 | + $wc_post_id = get_post_meta( intval( $course->ID ), '_course_woocommerce_product', true ); |
|
| 2054 | + if ( 0 < $wc_post_id ) { |
|
| 2055 | 2055 | |
| 2056 | - $user = wp_get_current_user(); |
|
| 2057 | - $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2056 | + $user = wp_get_current_user(); |
|
| 2057 | + $course_purchased = Sensei_Utils::sensei_customer_bought_product( $user->user_email, $user->ID, $wc_post_id ); |
|
| 2058 | 2058 | |
| 2059 | - } // End If Statement |
|
| 2060 | - } // End If Statement |
|
| 2059 | + } // End If Statement |
|
| 2060 | + } // End If Statement |
|
| 2061 | 2061 | |
| 2062 | - if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2062 | + if ( ! $course_purchased && ! Sensei_Utils::user_completed_course( $course->ID, get_current_user_id() ) ) {?> |
|
| 2063 | 2063 | |
| 2064 | 2064 | <span><input name="course_complete" type="submit" class="course-delete" value="<?php echo __( 'Delete Course', 'woothemes-sensei' ); ?>"/></span> |
| 2065 | 2065 | |
| 2066 | 2066 | <?php } // End If Statement |
| 2067 | 2067 | |
| 2068 | - $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2069 | - $results_link = ''; |
|
| 2070 | - if( $has_quizzes ){ |
|
| 2071 | - $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2072 | - } |
|
| 2068 | + $has_quizzes = Sensei()->course->course_quizzes( $course->ID, true ); |
|
| 2069 | + $results_link = ''; |
|
| 2070 | + if( $has_quizzes ){ |
|
| 2071 | + $results_link = '<a class="button view-results" href="' . Sensei()->course_results->get_permalink( $course->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2072 | + } |
|
| 2073 | 2073 | |
| 2074 | - // Output only if there is content to display |
|
| 2075 | - if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2074 | + // Output only if there is content to display |
|
| 2075 | + if ( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2076 | 2076 | |
| 2077 | 2077 | <p class="sensei-results-links"> |
| 2078 | 2078 | <?php echo apply_filters( 'sensei_results_links', $results_link ); ?> |
@@ -2084,456 +2084,456 @@ discard block |
||
| 2084 | 2084 | |
| 2085 | 2085 | <?php }// end if is user logged in |
| 2086 | 2086 | |
| 2087 | - }// end the_course_action_buttons |
|
| 2088 | - |
|
| 2089 | - /** |
|
| 2090 | - * This function alter the main query on the course archive page. |
|
| 2091 | - * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2092 | - * |
|
| 2093 | - * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2094 | - * query parameters via the arguments. |
|
| 2095 | - * |
|
| 2096 | - * This function is hooked into pre_get_posts filter |
|
| 2097 | - * |
|
| 2098 | - * @since 1.9.0 |
|
| 2099 | - * |
|
| 2100 | - * @param WP_Query $query |
|
| 2101 | - * @return WP_Query $query |
|
| 2102 | - */ |
|
| 2103 | - public static function course_query_filter( $query ){ |
|
| 2104 | - |
|
| 2105 | - // exit early for no course queries and admin queries |
|
| 2106 | - if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2107 | - return $query; |
|
| 2108 | - } |
|
| 2109 | - |
|
| 2110 | - global $post; // used to get the current page id for my courses |
|
| 2111 | - |
|
| 2112 | - // for the course archive page |
|
| 2113 | - if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2114 | - { |
|
| 2115 | - /** |
|
| 2116 | - * sensei_archive_courses_per_page |
|
| 2117 | - * |
|
| 2118 | - * Sensei courses per page on the course |
|
| 2119 | - * archive |
|
| 2120 | - * |
|
| 2121 | - * @since 1.9.0 |
|
| 2122 | - * @param integer $posts_per_page default 10 |
|
| 2123 | - */ |
|
| 2124 | - $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) ); |
|
| 2125 | - |
|
| 2126 | - } |
|
| 2127 | - // for the my courses page |
|
| 2128 | - elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2129 | - { |
|
| 2130 | - /** |
|
| 2131 | - * sensei_my_courses_per_page |
|
| 2132 | - * |
|
| 2133 | - * Sensei courses per page on the my courses page |
|
| 2134 | - * as set in the settings |
|
| 2135 | - * |
|
| 2136 | - * @since 1.9.0 |
|
| 2137 | - * @param integer $posts_per_page default 10 |
|
| 2138 | - */ |
|
| 2139 | - $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) ); |
|
| 2140 | - |
|
| 2141 | - } |
|
| 2142 | - |
|
| 2143 | - return $query; |
|
| 2144 | - |
|
| 2145 | - }// end course_query_filter |
|
| 2146 | - |
|
| 2147 | - /** |
|
| 2148 | - * Determine the class of the course loop |
|
| 2149 | - * |
|
| 2150 | - * This will output .first or .last and .course-item-number-x |
|
| 2151 | - * |
|
| 2152 | - * @return array $extra_classes |
|
| 2153 | - * @since 1.9.0 |
|
| 2154 | - */ |
|
| 2155 | - public static function get_course_loop_content_class () |
|
| 2156 | - { |
|
| 2157 | - |
|
| 2158 | - global $sensei_course_loop; |
|
| 2159 | - |
|
| 2160 | - |
|
| 2161 | - if( !isset( $sensei_course_loop ) ){ |
|
| 2162 | - $sensei_course_loop = array(); |
|
| 2163 | - } |
|
| 2164 | - |
|
| 2165 | - if (!isset($sensei_course_loop['counter'])) { |
|
| 2166 | - $sensei_course_loop['counter'] = 0; |
|
| 2167 | - } |
|
| 2168 | - |
|
| 2169 | - if (!isset($sensei_course_loop['columns'])) { |
|
| 2170 | - $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2171 | - } |
|
| 2172 | - |
|
| 2173 | - // increment the counter |
|
| 2174 | - $sensei_course_loop['counter']++; |
|
| 2175 | - |
|
| 2176 | - $extra_classes = array(); |
|
| 2177 | - if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2178 | - $extra_classes[] = 'first'; |
|
| 2179 | - } |
|
| 2180 | - |
|
| 2181 | - if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2182 | - $extra_classes[] = 'last'; |
|
| 2183 | - } |
|
| 2184 | - |
|
| 2185 | - // add the item number to the classes as well. |
|
| 2186 | - $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2187 | - |
|
| 2188 | - /** |
|
| 2189 | - * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2190 | - * which is called from the course loop content-course.php |
|
| 2191 | - * |
|
| 2192 | - * @since 1.9.0 |
|
| 2193 | - * |
|
| 2194 | - * @param array $extra_classes |
|
| 2195 | - * @param WP_Post $loop_current_course |
|
| 2196 | - */ |
|
| 2197 | - return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2198 | - |
|
| 2199 | - }// end get_course_loop_class |
|
| 2200 | - |
|
| 2201 | - /** |
|
| 2202 | - * Get the number of columns set for Sensei courses |
|
| 2203 | - * |
|
| 2204 | - * @since 1.9.0 |
|
| 2205 | - * @return mixed|void |
|
| 2206 | - */ |
|
| 2207 | - public static function get_loop_number_of_columns(){ |
|
| 2208 | - |
|
| 2209 | - /** |
|
| 2210 | - * Filter the number of columns on the course archive page. |
|
| 2211 | - * |
|
| 2212 | - * @since 1.9.0 |
|
| 2213 | - * @param int $number_of_columns default 1 |
|
| 2214 | - */ |
|
| 2215 | - return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2216 | - |
|
| 2217 | - } |
|
| 2218 | - |
|
| 2219 | - /** |
|
| 2220 | - * Output the course archive filter markup |
|
| 2221 | - * |
|
| 2222 | - * hooked into sensei_loop_course_before |
|
| 2223 | - * |
|
| 2224 | - * @since 1.9.0 |
|
| 2225 | - * @param |
|
| 2226 | - */ |
|
| 2227 | - public static function course_archive_sorting( $query ){ |
|
| 2228 | - |
|
| 2229 | - // don't show on category pages and other pages |
|
| 2230 | - if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2231 | - return; |
|
| 2232 | - } |
|
| 2233 | - |
|
| 2234 | - /** |
|
| 2235 | - * Filter the sensei archive course order by values |
|
| 2236 | - * |
|
| 2237 | - * @since 1.9.0 |
|
| 2238 | - * @param array $options { |
|
| 2239 | - * @type string $option_value |
|
| 2240 | - * @type string $option_string |
|
| 2241 | - * } |
|
| 2242 | - */ |
|
| 2243 | - $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2244 | - "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2245 | - "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2246 | - )); |
|
| 2247 | - |
|
| 2248 | - // setup the currently selected item |
|
| 2249 | - $selected = 'newness'; |
|
| 2250 | - if( isset( $_GET['orderby'] ) ){ |
|
| 2251 | - |
|
| 2252 | - $selected = $_GET[ 'orderby' ]; |
|
| 2253 | - |
|
| 2254 | - } |
|
| 2255 | - |
|
| 2256 | - ?> |
|
| 2087 | + }// end the_course_action_buttons |
|
| 2088 | + |
|
| 2089 | + /** |
|
| 2090 | + * This function alter the main query on the course archive page. |
|
| 2091 | + * This also gives Sensei specific filters that allows variables to be altered specifically on the course archive. |
|
| 2092 | + * |
|
| 2093 | + * This function targets only the course archives and the my courses page. Shortcodes can set their own |
|
| 2094 | + * query parameters via the arguments. |
|
| 2095 | + * |
|
| 2096 | + * This function is hooked into pre_get_posts filter |
|
| 2097 | + * |
|
| 2098 | + * @since 1.9.0 |
|
| 2099 | + * |
|
| 2100 | + * @param WP_Query $query |
|
| 2101 | + * @return WP_Query $query |
|
| 2102 | + */ |
|
| 2103 | + public static function course_query_filter( $query ){ |
|
| 2104 | + |
|
| 2105 | + // exit early for no course queries and admin queries |
|
| 2106 | + if( is_admin( ) || 'course' != $query->get( 'post_type' ) ){ |
|
| 2107 | + return $query; |
|
| 2108 | + } |
|
| 2109 | + |
|
| 2110 | + global $post; // used to get the current page id for my courses |
|
| 2111 | + |
|
| 2112 | + // for the course archive page |
|
| 2113 | + if( $query->is_main_query() && is_post_type_archive('course') ) |
|
| 2114 | + { |
|
| 2115 | + /** |
|
| 2116 | + * sensei_archive_courses_per_page |
|
| 2117 | + * |
|
| 2118 | + * Sensei courses per page on the course |
|
| 2119 | + * archive |
|
| 2120 | + * |
|
| 2121 | + * @since 1.9.0 |
|
| 2122 | + * @param integer $posts_per_page default 10 |
|
| 2123 | + */ |
|
| 2124 | + $query->set( 'posts_per_page', apply_filters( 'sensei_archive_courses_per_page', 10 ) ); |
|
| 2125 | + |
|
| 2126 | + } |
|
| 2127 | + // for the my courses page |
|
| 2128 | + elseif( is_page() && Sensei()->settings->get( 'my_course_page' ) == $post->ID ) |
|
| 2129 | + { |
|
| 2130 | + /** |
|
| 2131 | + * sensei_my_courses_per_page |
|
| 2132 | + * |
|
| 2133 | + * Sensei courses per page on the my courses page |
|
| 2134 | + * as set in the settings |
|
| 2135 | + * |
|
| 2136 | + * @since 1.9.0 |
|
| 2137 | + * @param integer $posts_per_page default 10 |
|
| 2138 | + */ |
|
| 2139 | + $query->set( 'posts_per_page', apply_filters( 'sensei_my_courses_per_page', 10 ) ); |
|
| 2140 | + |
|
| 2141 | + } |
|
| 2142 | + |
|
| 2143 | + return $query; |
|
| 2144 | + |
|
| 2145 | + }// end course_query_filter |
|
| 2146 | + |
|
| 2147 | + /** |
|
| 2148 | + * Determine the class of the course loop |
|
| 2149 | + * |
|
| 2150 | + * This will output .first or .last and .course-item-number-x |
|
| 2151 | + * |
|
| 2152 | + * @return array $extra_classes |
|
| 2153 | + * @since 1.9.0 |
|
| 2154 | + */ |
|
| 2155 | + public static function get_course_loop_content_class () |
|
| 2156 | + { |
|
| 2157 | + |
|
| 2158 | + global $sensei_course_loop; |
|
| 2159 | + |
|
| 2160 | + |
|
| 2161 | + if( !isset( $sensei_course_loop ) ){ |
|
| 2162 | + $sensei_course_loop = array(); |
|
| 2163 | + } |
|
| 2164 | + |
|
| 2165 | + if (!isset($sensei_course_loop['counter'])) { |
|
| 2166 | + $sensei_course_loop['counter'] = 0; |
|
| 2167 | + } |
|
| 2168 | + |
|
| 2169 | + if (!isset($sensei_course_loop['columns'])) { |
|
| 2170 | + $sensei_course_loop['columns'] = self::get_loop_number_of_columns(); |
|
| 2171 | + } |
|
| 2172 | + |
|
| 2173 | + // increment the counter |
|
| 2174 | + $sensei_course_loop['counter']++; |
|
| 2175 | + |
|
| 2176 | + $extra_classes = array(); |
|
| 2177 | + if( 0 == ( $sensei_course_loop['counter'] - 1 ) % $sensei_course_loop['columns'] || 1 == $sensei_course_loop['columns'] ){ |
|
| 2178 | + $extra_classes[] = 'first'; |
|
| 2179 | + } |
|
| 2180 | + |
|
| 2181 | + if( 0 == $sensei_course_loop['counter'] % $sensei_course_loop['columns'] ){ |
|
| 2182 | + $extra_classes[] = 'last'; |
|
| 2183 | + } |
|
| 2184 | + |
|
| 2185 | + // add the item number to the classes as well. |
|
| 2186 | + $extra_classes[] = 'loop-item-number-'. $sensei_course_loop['counter']; |
|
| 2187 | + |
|
| 2188 | + /** |
|
| 2189 | + * Filter the course loop class the fires in the in get_course_loop_content_class function |
|
| 2190 | + * which is called from the course loop content-course.php |
|
| 2191 | + * |
|
| 2192 | + * @since 1.9.0 |
|
| 2193 | + * |
|
| 2194 | + * @param array $extra_classes |
|
| 2195 | + * @param WP_Post $loop_current_course |
|
| 2196 | + */ |
|
| 2197 | + return apply_filters( 'sensei_course_loop_content_class', $extra_classes ,get_post() ); |
|
| 2198 | + |
|
| 2199 | + }// end get_course_loop_class |
|
| 2200 | + |
|
| 2201 | + /** |
|
| 2202 | + * Get the number of columns set for Sensei courses |
|
| 2203 | + * |
|
| 2204 | + * @since 1.9.0 |
|
| 2205 | + * @return mixed|void |
|
| 2206 | + */ |
|
| 2207 | + public static function get_loop_number_of_columns(){ |
|
| 2208 | + |
|
| 2209 | + /** |
|
| 2210 | + * Filter the number of columns on the course archive page. |
|
| 2211 | + * |
|
| 2212 | + * @since 1.9.0 |
|
| 2213 | + * @param int $number_of_columns default 1 |
|
| 2214 | + */ |
|
| 2215 | + return apply_filters('sensei_course_loop_number_of_columns', 1); |
|
| 2216 | + |
|
| 2217 | + } |
|
| 2218 | + |
|
| 2219 | + /** |
|
| 2220 | + * Output the course archive filter markup |
|
| 2221 | + * |
|
| 2222 | + * hooked into sensei_loop_course_before |
|
| 2223 | + * |
|
| 2224 | + * @since 1.9.0 |
|
| 2225 | + * @param |
|
| 2226 | + */ |
|
| 2227 | + public static function course_archive_sorting( $query ){ |
|
| 2228 | + |
|
| 2229 | + // don't show on category pages and other pages |
|
| 2230 | + if( ! is_archive( 'course ') || is_tax('course-category') ){ |
|
| 2231 | + return; |
|
| 2232 | + } |
|
| 2233 | + |
|
| 2234 | + /** |
|
| 2235 | + * Filter the sensei archive course order by values |
|
| 2236 | + * |
|
| 2237 | + * @since 1.9.0 |
|
| 2238 | + * @param array $options { |
|
| 2239 | + * @type string $option_value |
|
| 2240 | + * @type string $option_string |
|
| 2241 | + * } |
|
| 2242 | + */ |
|
| 2243 | + $course_order_by_options = apply_filters( 'sensei_archive_course_order_by_options', array( |
|
| 2244 | + "newness" => __( "Sort by newest first", "woothemes-sensei"), |
|
| 2245 | + "title" => __( "Sort by title A-Z", "woothemes-sensei" ), |
|
| 2246 | + )); |
|
| 2247 | + |
|
| 2248 | + // setup the currently selected item |
|
| 2249 | + $selected = 'newness'; |
|
| 2250 | + if( isset( $_GET['orderby'] ) ){ |
|
| 2251 | + |
|
| 2252 | + $selected = $_GET[ 'orderby' ]; |
|
| 2253 | + |
|
| 2254 | + } |
|
| 2255 | + |
|
| 2256 | + ?> |
|
| 2257 | 2257 | |
| 2258 | 2258 | <form class="sensei-ordering" name="sensei-course-order" action="<?php echo esc_attr( Sensei_Utils::get_current_url() ) ; ?>" method="POST"> |
| 2259 | 2259 | <select name="course-orderby" class="orderby"> |
| 2260 | 2260 | <?php |
| 2261 | - foreach( $course_order_by_options as $value => $text ){ |
|
| 2261 | + foreach( $course_order_by_options as $value => $text ){ |
|
| 2262 | 2262 | |
| 2263 | - echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2263 | + echo '<option value="'. $value . ' "' . selected( $selected, $value, false ) . '>'. $text. '</option>'; |
|
| 2264 | 2264 | |
| 2265 | - } |
|
| 2266 | - ?> |
|
| 2265 | + } |
|
| 2266 | + ?> |
|
| 2267 | 2267 | </select> |
| 2268 | 2268 | </form> |
| 2269 | 2269 | |
| 2270 | 2270 | <?php |
| 2271 | - }// end course archive filters |
|
| 2272 | - |
|
| 2273 | - /** |
|
| 2274 | - * Output the course archive filter markup |
|
| 2275 | - * |
|
| 2276 | - * hooked into sensei_loop_course_before |
|
| 2277 | - * |
|
| 2278 | - * @since 1.9.0 |
|
| 2279 | - * @param |
|
| 2280 | - */ |
|
| 2281 | - public static function course_archive_filters( $query ){ |
|
| 2282 | - |
|
| 2283 | - // don't show on category pages |
|
| 2284 | - if( is_tax('course-category') ){ |
|
| 2285 | - return; |
|
| 2286 | - } |
|
| 2287 | - |
|
| 2288 | - /** |
|
| 2289 | - * filter the course archive filter buttons |
|
| 2290 | - * |
|
| 2291 | - * @since 1.9.0 |
|
| 2292 | - * @param array $filters{ |
|
| 2293 | - * @type array ( $id, $url , $title ) |
|
| 2294 | - * } |
|
| 2295 | - * |
|
| 2296 | - */ |
|
| 2297 | - $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2298 | - array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2299 | - array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2300 | - )); |
|
| 2301 | - |
|
| 2302 | - |
|
| 2303 | - ?> |
|
| 2271 | + }// end course archive filters |
|
| 2272 | + |
|
| 2273 | + /** |
|
| 2274 | + * Output the course archive filter markup |
|
| 2275 | + * |
|
| 2276 | + * hooked into sensei_loop_course_before |
|
| 2277 | + * |
|
| 2278 | + * @since 1.9.0 |
|
| 2279 | + * @param |
|
| 2280 | + */ |
|
| 2281 | + public static function course_archive_filters( $query ){ |
|
| 2282 | + |
|
| 2283 | + // don't show on category pages |
|
| 2284 | + if( is_tax('course-category') ){ |
|
| 2285 | + return; |
|
| 2286 | + } |
|
| 2287 | + |
|
| 2288 | + /** |
|
| 2289 | + * filter the course archive filter buttons |
|
| 2290 | + * |
|
| 2291 | + * @since 1.9.0 |
|
| 2292 | + * @param array $filters{ |
|
| 2293 | + * @type array ( $id, $url , $title ) |
|
| 2294 | + * } |
|
| 2295 | + * |
|
| 2296 | + */ |
|
| 2297 | + $filters = apply_filters( 'sensei_archive_course_filter_by_options', array( |
|
| 2298 | + array( 'id' => 'all', 'url' => self::get_courses_page_url(), 'title'=> __( 'All', 'woothemes-sensei' ) ), |
|
| 2299 | + array( 'id' => 'featured', 'url' => add_query_arg( array( 'course_filter'=>'featured'), self::get_courses_page_url() ), 'title'=> __( 'Featured', 'woothemes-sensei' ) ), |
|
| 2300 | + )); |
|
| 2301 | + |
|
| 2302 | + |
|
| 2303 | + ?> |
|
| 2304 | 2304 | <ul class="sensei-course-filters clearfix" > |
| 2305 | 2305 | <?php |
| 2306 | 2306 | |
| 2307 | - //determine the current active url |
|
| 2308 | - $current_url = Sensei_Utils::get_current_url(); |
|
| 2307 | + //determine the current active url |
|
| 2308 | + $current_url = Sensei_Utils::get_current_url(); |
|
| 2309 | 2309 | |
| 2310 | - foreach( $filters as $filter ) { |
|
| 2310 | + foreach( $filters as $filter ) { |
|
| 2311 | 2311 | |
| 2312 | - $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2312 | + $active_class = $current_url == $filter['url'] ? ' class="active" ' : ''; |
|
| 2313 | 2313 | |
| 2314 | - echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2314 | + echo '<li><a '. $active_class .' id="'. $filter['id'] .'" href="'. esc_url( $filter['url'] ).'" >'. $filter['title'] .'</a></li>'; |
|
| 2315 | 2315 | |
| 2316 | - } |
|
| 2317 | - ?> |
|
| 2316 | + } |
|
| 2317 | + ?> |
|
| 2318 | 2318 | |
| 2319 | 2319 | </ul> |
| 2320 | 2320 | |
| 2321 | 2321 | <?php |
| 2322 | 2322 | |
| 2323 | - } |
|
| 2323 | + } |
|
| 2324 | 2324 | |
| 2325 | - /** |
|
| 2326 | - * if the featured link is clicked on the course archive page |
|
| 2327 | - * filter the courses returned to only show those featured |
|
| 2328 | - * |
|
| 2329 | - * Hooked into pre_get_posts |
|
| 2330 | - * |
|
| 2331 | - * @since 1.9.0 |
|
| 2332 | - * @param WP_Query $query |
|
| 2333 | - * @return WP_Query $query |
|
| 2334 | - */ |
|
| 2335 | - public static function course_archive_featured_filter( $query ){ |
|
| 2336 | - |
|
| 2337 | - if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2338 | - //setup meta query for featured courses |
|
| 2339 | - $query->set( 'meta_value', 'featured' ); |
|
| 2340 | - $query->set( 'meta_key', '_course_featured' ); |
|
| 2341 | - $query->set( 'meta_compare', '=' ); |
|
| 2342 | - } |
|
| 2343 | - |
|
| 2344 | - return $query; |
|
| 2345 | - } |
|
| 2346 | - |
|
| 2347 | - /** |
|
| 2348 | - * if the course order drop down is changed |
|
| 2349 | - * |
|
| 2350 | - * Hooked into pre_get_posts |
|
| 2351 | - * |
|
| 2352 | - * @since 1.9.0 |
|
| 2353 | - * @param WP_Query $query |
|
| 2354 | - * @return WP_Query $query |
|
| 2355 | - */ |
|
| 2356 | - public static function course_archive_order_by_title( $query ){ |
|
| 2357 | - |
|
| 2358 | - if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2359 | - && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2360 | - // setup the order by title for this query |
|
| 2361 | - $query->set( 'orderby', 'title' ); |
|
| 2362 | - $query->set( 'order', 'ASC' ); |
|
| 2363 | - } |
|
| 2364 | - |
|
| 2365 | - return $query; |
|
| 2366 | - } |
|
| 2367 | - |
|
| 2368 | - |
|
| 2369 | - /** |
|
| 2370 | - * Get the link to the courses page. This will be the course post type archive |
|
| 2371 | - * page link or the page the user set in their settings |
|
| 2372 | - * |
|
| 2373 | - * @since 1.9.0 |
|
| 2374 | - * @return string $course_page_url |
|
| 2375 | - */ |
|
| 2376 | - public static function get_courses_page_url(){ |
|
| 2377 | - |
|
| 2378 | - $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2379 | - $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2325 | + /** |
|
| 2326 | + * if the featured link is clicked on the course archive page |
|
| 2327 | + * filter the courses returned to only show those featured |
|
| 2328 | + * |
|
| 2329 | + * Hooked into pre_get_posts |
|
| 2330 | + * |
|
| 2331 | + * @since 1.9.0 |
|
| 2332 | + * @param WP_Query $query |
|
| 2333 | + * @return WP_Query $query |
|
| 2334 | + */ |
|
| 2335 | + public static function course_archive_featured_filter( $query ){ |
|
| 2380 | 2336 | |
| 2381 | - return $course_page_url; |
|
| 2382 | - |
|
| 2383 | - }// get_course_url |
|
| 2337 | + if( isset ( $_GET[ 'course_filter' ] ) && 'featured'== $_GET['course_filter'] && $query->is_main_query() ){ |
|
| 2338 | + //setup meta query for featured courses |
|
| 2339 | + $query->set( 'meta_value', 'featured' ); |
|
| 2340 | + $query->set( 'meta_key', '_course_featured' ); |
|
| 2341 | + $query->set( 'meta_compare', '=' ); |
|
| 2342 | + } |
|
| 2384 | 2343 | |
| 2385 | - /** |
|
| 2386 | - * Output the headers on the course archive page |
|
| 2387 | - * |
|
| 2388 | - * Hooked into the sensei_archive_title |
|
| 2389 | - * |
|
| 2390 | - * @since 1.9.0 |
|
| 2391 | - * @param string $query_type |
|
| 2392 | - * @param string $before_html |
|
| 2393 | - * @param string $after_html |
|
| 2394 | - * @return void |
|
| 2395 | - */ |
|
| 2396 | - public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2344 | + return $query; |
|
| 2345 | + } |
|
| 2397 | 2346 | |
| 2398 | - if( ! is_post_type_archive('course') ){ |
|
| 2399 | - return; |
|
| 2400 | - } |
|
| 2347 | + /** |
|
| 2348 | + * if the course order drop down is changed |
|
| 2349 | + * |
|
| 2350 | + * Hooked into pre_get_posts |
|
| 2351 | + * |
|
| 2352 | + * @since 1.9.0 |
|
| 2353 | + * @param WP_Query $query |
|
| 2354 | + * @return WP_Query $query |
|
| 2355 | + */ |
|
| 2356 | + public static function course_archive_order_by_title( $query ){ |
|
| 2401 | 2357 | |
| 2402 | - // deprecated since 1.9.0 |
|
| 2403 | - sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2358 | + if( isset ( $_POST[ 'course-orderby' ] ) && 'title '== $_POST['course-orderby'] |
|
| 2359 | + && 'course'== $query->get('post_type') && $query->is_main_query() ){ |
|
| 2360 | + // setup the order by title for this query |
|
| 2361 | + $query->set( 'orderby', 'title' ); |
|
| 2362 | + $query->set( 'order', 'ASC' ); |
|
| 2363 | + } |
|
| 2404 | 2364 | |
| 2405 | - $html = ''; |
|
| 2365 | + return $query; |
|
| 2366 | + } |
|
| 2406 | 2367 | |
| 2407 | - if( empty( $before_html ) ){ |
|
| 2408 | 2368 | |
| 2409 | - $before_html = '<header class="archive-header"><h1>'; |
|
| 2369 | + /** |
|
| 2370 | + * Get the link to the courses page. This will be the course post type archive |
|
| 2371 | + * page link or the page the user set in their settings |
|
| 2372 | + * |
|
| 2373 | + * @since 1.9.0 |
|
| 2374 | + * @return string $course_page_url |
|
| 2375 | + */ |
|
| 2376 | + public static function get_courses_page_url(){ |
|
| 2410 | 2377 | |
| 2411 | - } |
|
| 2378 | + $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 2379 | + $course_page_url = empty( $course_page_id ) ? get_post_type_archive_link('course') : get_permalink( $course_page_id ); |
|
| 2412 | 2380 | |
| 2413 | - if( empty( $after_html ) ){ |
|
| 2381 | + return $course_page_url; |
|
| 2414 | 2382 | |
| 2415 | - $after_html = '</h1></header>'; |
|
| 2383 | + }// get_course_url |
|
| 2416 | 2384 | |
| 2417 | - } |
|
| 2385 | + /** |
|
| 2386 | + * Output the headers on the course archive page |
|
| 2387 | + * |
|
| 2388 | + * Hooked into the sensei_archive_title |
|
| 2389 | + * |
|
| 2390 | + * @since 1.9.0 |
|
| 2391 | + * @param string $query_type |
|
| 2392 | + * @param string $before_html |
|
| 2393 | + * @param string $after_html |
|
| 2394 | + * @return void |
|
| 2395 | + */ |
|
| 2396 | + public static function archive_header( $query_type ='' , $before_html='', $after_html ='' ){ |
|
| 2397 | + |
|
| 2398 | + if( ! is_post_type_archive('course') ){ |
|
| 2399 | + return; |
|
| 2400 | + } |
|
| 2401 | + |
|
| 2402 | + // deprecated since 1.9.0 |
|
| 2403 | + sensei_do_deprecated_action('sensei_archive_title','1.9.0','sensei_archive_before_course_loop'); |
|
| 2404 | + |
|
| 2405 | + $html = ''; |
|
| 2406 | + |
|
| 2407 | + if( empty( $before_html ) ){ |
|
| 2418 | 2408 | |
| 2419 | - if ( is_tax( 'course-category' ) ) { |
|
| 2409 | + $before_html = '<header class="archive-header"><h1>'; |
|
| 2420 | 2410 | |
| 2421 | - global $wp_query; |
|
| 2411 | + } |
|
| 2412 | + |
|
| 2413 | + if( empty( $after_html ) ){ |
|
| 2422 | 2414 | |
| 2423 | - $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2424 | - $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2425 | - $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2426 | - $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2427 | - echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2428 | - return; |
|
| 2415 | + $after_html = '</h1></header>'; |
|
| 2429 | 2416 | |
| 2430 | - } // End If Statement |
|
| 2417 | + } |
|
| 2431 | 2418 | |
| 2432 | - switch ( $query_type ) { |
|
| 2433 | - case 'newcourses': |
|
| 2434 | - $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2435 | - break; |
|
| 2436 | - case 'featuredcourses': |
|
| 2437 | - $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2438 | - break; |
|
| 2439 | - case 'freecourses': |
|
| 2440 | - $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2441 | - break; |
|
| 2442 | - case 'paidcourses': |
|
| 2443 | - $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2444 | - break; |
|
| 2445 | - default: |
|
| 2446 | - $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2447 | - break; |
|
| 2448 | - } // End Switch Statement |
|
| 2419 | + if ( is_tax( 'course-category' ) ) { |
|
| 2449 | 2420 | |
| 2450 | - echo apply_filters( 'course_archive_title', $html ); |
|
| 2421 | + global $wp_query; |
|
| 2451 | 2422 | |
| 2452 | - }//course_archive_header |
|
| 2423 | + $taxonomy_obj = $wp_query->get_queried_object(); |
|
| 2424 | + $taxonomy_short_name = $taxonomy_obj->taxonomy; |
|
| 2425 | + $taxonomy_raw_obj = get_taxonomy( $taxonomy_short_name ); |
|
| 2426 | + $title = sprintf( __( '%1$s Archives: %2$s', 'woothemes-sensei' ), $taxonomy_raw_obj->labels->name, $taxonomy_obj->name ); |
|
| 2427 | + echo apply_filters( 'course_category_archive_title', $before_html . $title . $after_html ); |
|
| 2428 | + return; |
|
| 2453 | 2429 | |
| 2430 | + } // End If Statement |
|
| 2454 | 2431 | |
| 2455 | - /** |
|
| 2456 | - * Filter the single course content |
|
| 2457 | - * taking into account if the user has access. |
|
| 2458 | - * |
|
| 2459 | - * @1.9.0 |
|
| 2460 | - * |
|
| 2461 | - * @param string $content |
|
| 2462 | - * @return string $content or $excerpt |
|
| 2463 | - */ |
|
| 2464 | - public static function single_course_content( $content ){ |
|
| 2432 | + switch ( $query_type ) { |
|
| 2433 | + case 'newcourses': |
|
| 2434 | + $html .= $before_html . __( 'New Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2435 | + break; |
|
| 2436 | + case 'featuredcourses': |
|
| 2437 | + $html .= $before_html . __( 'Featured Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2438 | + break; |
|
| 2439 | + case 'freecourses': |
|
| 2440 | + $html .= $before_html . __( 'Free Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2441 | + break; |
|
| 2442 | + case 'paidcourses': |
|
| 2443 | + $html .= $before_html . __( 'Paid Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2444 | + break; |
|
| 2445 | + default: |
|
| 2446 | + $html .= $before_html . __( 'Courses', 'woothemes-sensei' ) . $after_html; |
|
| 2447 | + break; |
|
| 2448 | + } // End Switch Statement |
|
| 2449 | + |
|
| 2450 | + echo apply_filters( 'course_archive_title', $html ); |
|
| 2451 | + |
|
| 2452 | + }//course_archive_header |
|
| 2453 | + |
|
| 2454 | + |
|
| 2455 | + /** |
|
| 2456 | + * Filter the single course content |
|
| 2457 | + * taking into account if the user has access. |
|
| 2458 | + * |
|
| 2459 | + * @1.9.0 |
|
| 2460 | + * |
|
| 2461 | + * @param string $content |
|
| 2462 | + * @return string $content or $excerpt |
|
| 2463 | + */ |
|
| 2464 | + public static function single_course_content( $content ){ |
|
| 2465 | 2465 | |
| 2466 | - if( ! is_singular('course') ){ |
|
| 2466 | + if( ! is_singular('course') ){ |
|
| 2467 | 2467 | |
| 2468 | - return $content; |
|
| 2468 | + return $content; |
|
| 2469 | 2469 | |
| 2470 | - } |
|
| 2470 | + } |
|
| 2471 | 2471 | |
| 2472 | - // Content Access Permissions |
|
| 2473 | - $access_permission = false; |
|
| 2472 | + // Content Access Permissions |
|
| 2473 | + $access_permission = false; |
|
| 2474 | 2474 | |
| 2475 | - if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2475 | + if ( ! Sensei()->settings->get('access_permission') || sensei_all_access() ) { |
|
| 2476 | 2476 | |
| 2477 | - $access_permission = true; |
|
| 2477 | + $access_permission = true; |
|
| 2478 | 2478 | |
| 2479 | - } // End If Statement |
|
| 2479 | + } // End If Statement |
|
| 2480 | 2480 | |
| 2481 | - // Check if the user is taking the course |
|
| 2482 | - $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2481 | + // Check if the user is taking the course |
|
| 2482 | + $is_user_taking_course = Sensei_Utils::user_started_course( get_the_ID(), get_current_user_id() ); |
|
| 2483 | 2483 | |
| 2484 | - if(Sensei_WC::is_woocommerce_active()) { |
|
| 2484 | + if(Sensei_WC::is_woocommerce_active()) { |
|
| 2485 | 2485 | |
| 2486 | - $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2487 | - $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2486 | + $wc_post_id = get_post_meta( get_the_ID(), '_course_woocommerce_product', true ); |
|
| 2487 | + $product = Sensei()->sensei_get_woocommerce_product_object( $wc_post_id ); |
|
| 2488 | 2488 | |
| 2489 | - $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2489 | + $has_product_attached = isset ( $product ) && is_object ( $product ); |
|
| 2490 | 2490 | |
| 2491 | - } else { |
|
| 2491 | + } else { |
|
| 2492 | 2492 | |
| 2493 | - $has_product_attached = false; |
|
| 2493 | + $has_product_attached = false; |
|
| 2494 | 2494 | |
| 2495 | - } |
|
| 2495 | + } |
|
| 2496 | 2496 | |
| 2497 | - if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2498 | - || ( $access_permission && !$has_product_attached) |
|
| 2499 | - || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2497 | + if ( ( is_user_logged_in() && $is_user_taking_course ) |
|
| 2498 | + || ( $access_permission && !$has_product_attached) |
|
| 2499 | + || 'full' == Sensei()->settings->get( 'course_single_content_display' ) ) { |
|
| 2500 | 2500 | |
| 2501 | - return $content; |
|
| 2501 | + return $content; |
|
| 2502 | 2502 | |
| 2503 | - } else { |
|
| 2503 | + } else { |
|
| 2504 | 2504 | |
| 2505 | - return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2505 | + return '<p class="course-excerpt">' . get_post( get_the_ID() )->post_excerpt . '</p>'; |
|
| 2506 | 2506 | |
| 2507 | - } |
|
| 2507 | + } |
|
| 2508 | 2508 | |
| 2509 | - }// end single_course_content |
|
| 2509 | + }// end single_course_content |
|
| 2510 | 2510 | |
| 2511 | - /** |
|
| 2512 | - * Output the the single course lessons title with markup. |
|
| 2513 | - * |
|
| 2514 | - * @since 1.9.0 |
|
| 2515 | - */ |
|
| 2516 | - public static function the_course_lessons_title(){ |
|
| 2517 | - global $post; |
|
| 2518 | - $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2519 | - $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2511 | + /** |
|
| 2512 | + * Output the the single course lessons title with markup. |
|
| 2513 | + * |
|
| 2514 | + * @since 1.9.0 |
|
| 2515 | + */ |
|
| 2516 | + public static function the_course_lessons_title(){ |
|
| 2517 | + global $post; |
|
| 2518 | + $none_module_lessons = Sensei()->modules->get_none_module_lessons( $post->ID ); |
|
| 2519 | + $course_lessons = Sensei()->course->course_lessons( $post->ID ); |
|
| 2520 | 2520 | |
| 2521 | - // title should be Other Lessons if there are lessons belonging to models. |
|
| 2522 | - $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2523 | - if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2521 | + // title should be Other Lessons if there are lessons belonging to models. |
|
| 2522 | + $title = __('Other Lessons', 'woothemes-sensei'); |
|
| 2523 | + if( count( $course_lessons ) == count( $none_module_lessons ) ){ |
|
| 2524 | 2524 | |
| 2525 | - $title = __('Lessons', 'woothemes-sensei'); |
|
| 2525 | + $title = __('Lessons', 'woothemes-sensei'); |
|
| 2526 | 2526 | |
| 2527 | - } |
|
| 2527 | + } |
|
| 2528 | 2528 | |
| 2529 | - /** |
|
| 2530 | - * hook document in class-woothemes-sensei-message.php |
|
| 2531 | - */ |
|
| 2532 | - $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2529 | + /** |
|
| 2530 | + * hook document in class-woothemes-sensei-message.php |
|
| 2531 | + */ |
|
| 2532 | + $title = apply_filters( 'sensei_single_title', $title, $post->post_type ); |
|
| 2533 | 2533 | |
| 2534 | - ob_start(); // start capturing the following output. |
|
| 2534 | + ob_start(); // start capturing the following output. |
|
| 2535 | 2535 | |
| 2536 | - ?> |
|
| 2536 | + ?> |
|
| 2537 | 2537 | |
| 2538 | 2538 | <header> |
| 2539 | 2539 | <h2> <?php echo $title; ?> </h2> |
@@ -2541,277 +2541,277 @@ discard block |
||
| 2541 | 2541 | |
| 2542 | 2542 | <?php |
| 2543 | 2543 | |
| 2544 | - /** |
|
| 2545 | - * Filter the title and markup that appears above the lessons on a single course |
|
| 2546 | - * page. |
|
| 2547 | - * |
|
| 2548 | - * @since 1.9.0 |
|
| 2549 | - * @param string $lessons_title_html |
|
| 2550 | - */ |
|
| 2551 | - echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2552 | - |
|
| 2553 | - }// end the_course_lessons_title |
|
| 2554 | - |
|
| 2555 | - /** |
|
| 2556 | - * This function loads the global wp_query object with with lessons |
|
| 2557 | - * of the current course. It is designed to be used on the single-course template |
|
| 2558 | - * and expects the global post to be a singular course. |
|
| 2559 | - * |
|
| 2560 | - * This function excludes lessons belonging to modules as they are |
|
| 2561 | - * queried separately. |
|
| 2562 | - * |
|
| 2563 | - * @since 1.9.0 |
|
| 2564 | - * @global $wp_query |
|
| 2565 | - */ |
|
| 2566 | - public static function load_single_course_lessons_query(){ |
|
| 2567 | - |
|
| 2568 | - global $post, $wp_query; |
|
| 2544 | + /** |
|
| 2545 | + * Filter the title and markup that appears above the lessons on a single course |
|
| 2546 | + * page. |
|
| 2547 | + * |
|
| 2548 | + * @since 1.9.0 |
|
| 2549 | + * @param string $lessons_title_html |
|
| 2550 | + */ |
|
| 2551 | + echo apply_filters('the_course_lessons_title', ob_get_clean() ); // output and filter the captured output and stop capturing. |
|
| 2569 | 2552 | |
| 2570 | - $course_id = $post->ID; |
|
| 2553 | + }// end the_course_lessons_title |
|
| 2571 | 2554 | |
| 2572 | - if( 'course' != get_post_type( $course_id ) ){ |
|
| 2573 | - return; |
|
| 2574 | - } |
|
| 2555 | + /** |
|
| 2556 | + * This function loads the global wp_query object with with lessons |
|
| 2557 | + * of the current course. It is designed to be used on the single-course template |
|
| 2558 | + * and expects the global post to be a singular course. |
|
| 2559 | + * |
|
| 2560 | + * This function excludes lessons belonging to modules as they are |
|
| 2561 | + * queried separately. |
|
| 2562 | + * |
|
| 2563 | + * @since 1.9.0 |
|
| 2564 | + * @global $wp_query |
|
| 2565 | + */ |
|
| 2566 | + public static function load_single_course_lessons_query(){ |
|
| 2575 | 2567 | |
| 2576 | - $course_lesson_query_args = array( |
|
| 2577 | - 'post_type' => 'lesson', |
|
| 2578 | - 'posts_per_page' => 500, |
|
| 2579 | - 'orderby' => 'date', |
|
| 2580 | - 'order' => 'ASC', |
|
| 2581 | - 'meta_query' => array( |
|
| 2582 | - array( |
|
| 2583 | - 'key' => '_lesson_course', |
|
| 2584 | - 'value' => intval( $course_id ), |
|
| 2585 | - ), |
|
| 2586 | - ), |
|
| 2587 | - 'post_status' => 'public', |
|
| 2588 | - 'suppress_filters' => 0, |
|
| 2589 | - ); |
|
| 2568 | + global $post, $wp_query; |
|
| 2590 | 2569 | |
| 2591 | - // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2592 | - $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2593 | - if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2570 | + $course_id = $post->ID; |
|
| 2594 | 2571 | |
| 2595 | - $terms_ids = array(); |
|
| 2596 | - foreach( $modules as $term ){ |
|
| 2572 | + if( 'course' != get_post_type( $course_id ) ){ |
|
| 2573 | + return; |
|
| 2574 | + } |
|
| 2597 | 2575 | |
| 2598 | - $terms_ids[] = $term->term_id; |
|
| 2576 | + $course_lesson_query_args = array( |
|
| 2577 | + 'post_type' => 'lesson', |
|
| 2578 | + 'posts_per_page' => 500, |
|
| 2579 | + 'orderby' => 'date', |
|
| 2580 | + 'order' => 'ASC', |
|
| 2581 | + 'meta_query' => array( |
|
| 2582 | + array( |
|
| 2583 | + 'key' => '_lesson_course', |
|
| 2584 | + 'value' => intval( $course_id ), |
|
| 2585 | + ), |
|
| 2586 | + ), |
|
| 2587 | + 'post_status' => 'public', |
|
| 2588 | + 'suppress_filters' => 0, |
|
| 2589 | + ); |
|
| 2590 | + |
|
| 2591 | + // Exclude lessons belonging to modules as they are queried along with the modules. |
|
| 2592 | + $modules = Sensei()->modules->get_course_modules( $course_id ); |
|
| 2593 | + if( !is_wp_error( $modules ) && ! empty( $modules ) && is_array( $modules ) ){ |
|
| 2594 | + |
|
| 2595 | + $terms_ids = array(); |
|
| 2596 | + foreach( $modules as $term ){ |
|
| 2597 | + |
|
| 2598 | + $terms_ids[] = $term->term_id; |
|
| 2599 | 2599 | |
| 2600 | - } |
|
| 2600 | + } |
|
| 2601 | 2601 | |
| 2602 | - $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2603 | - array( |
|
| 2604 | - 'taxonomy' => 'module', |
|
| 2605 | - 'field' => 'id', |
|
| 2606 | - 'terms' => $terms_ids, |
|
| 2607 | - 'operator' => 'NOT IN', |
|
| 2608 | - ), |
|
| 2609 | - ); |
|
| 2610 | - } |
|
| 2602 | + $course_lesson_query_args[ 'tax_query'] = array( |
|
| 2603 | + array( |
|
| 2604 | + 'taxonomy' => 'module', |
|
| 2605 | + 'field' => 'id', |
|
| 2606 | + 'terms' => $terms_ids, |
|
| 2607 | + 'operator' => 'NOT IN', |
|
| 2608 | + ), |
|
| 2609 | + ); |
|
| 2610 | + } |
|
| 2611 | 2611 | |
| 2612 | - $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2612 | + $wp_query = new WP_Query( $course_lesson_query_args ); |
|
| 2613 | 2613 | |
| 2614 | - }// load_single_course_lessons |
|
| 2614 | + }// load_single_course_lessons |
|
| 2615 | 2615 | |
| 2616 | - /** |
|
| 2617 | - * Flush the rewrite rules for a course post type |
|
| 2618 | - * |
|
| 2619 | - * @since 1.9.0 |
|
| 2620 | - * |
|
| 2621 | - * @param $post_id |
|
| 2622 | - */ |
|
| 2623 | - public static function flush_rewrite_rules( $post_id ){ |
|
| 2616 | + /** |
|
| 2617 | + * Flush the rewrite rules for a course post type |
|
| 2618 | + * |
|
| 2619 | + * @since 1.9.0 |
|
| 2620 | + * |
|
| 2621 | + * @param $post_id |
|
| 2622 | + */ |
|
| 2623 | + public static function flush_rewrite_rules( $post_id ){ |
|
| 2624 | 2624 | |
| 2625 | - if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2625 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE){ |
|
| 2626 | 2626 | |
| 2627 | - return; |
|
| 2627 | + return; |
|
| 2628 | 2628 | |
| 2629 | - } |
|
| 2629 | + } |
|
| 2630 | 2630 | |
| 2631 | 2631 | |
| 2632 | - if( 'course' == get_post_type( $post_id ) ){ |
|
| 2632 | + if( 'course' == get_post_type( $post_id ) ){ |
|
| 2633 | 2633 | |
| 2634 | - Sensei()->initiate_rewrite_rules_flush(); |
|
| 2634 | + Sensei()->initiate_rewrite_rules_flush(); |
|
| 2635 | 2635 | |
| 2636 | - } |
|
| 2636 | + } |
|
| 2637 | 2637 | |
| 2638 | - } |
|
| 2638 | + } |
|
| 2639 | 2639 | |
| 2640 | - /** |
|
| 2641 | - * Optionally return the full content on the single course pages |
|
| 2642 | - * depending on the users course_single_content_display setting |
|
| 2643 | - * |
|
| 2644 | - * @since 1.9.0 |
|
| 2645 | - * @param $excerpt |
|
| 2646 | - * @return string |
|
| 2647 | - */ |
|
| 2648 | - public static function full_content_excerpt_override( $excerpt ){ |
|
| 2640 | + /** |
|
| 2641 | + * Optionally return the full content on the single course pages |
|
| 2642 | + * depending on the users course_single_content_display setting |
|
| 2643 | + * |
|
| 2644 | + * @since 1.9.0 |
|
| 2645 | + * @param $excerpt |
|
| 2646 | + * @return string |
|
| 2647 | + */ |
|
| 2648 | + public static function full_content_excerpt_override( $excerpt ){ |
|
| 2649 | 2649 | |
| 2650 | - if ( is_singular('course') && |
|
| 2651 | - 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2650 | + if ( is_singular('course') && |
|
| 2651 | + 'full' == Sensei()->settings->get( 'course_single_content_display' ) ){ |
|
| 2652 | 2652 | |
| 2653 | - return get_the_content(); |
|
| 2653 | + return get_the_content(); |
|
| 2654 | 2654 | |
| 2655 | - } else { |
|
| 2655 | + } else { |
|
| 2656 | 2656 | |
| 2657 | - return $excerpt; |
|
| 2657 | + return $excerpt; |
|
| 2658 | 2658 | |
| 2659 | - } |
|
| 2659 | + } |
|
| 2660 | 2660 | |
| 2661 | - } |
|
| 2661 | + } |
|
| 2662 | 2662 | |
| 2663 | - /** |
|
| 2664 | - * Output the course actions like start taking course, register, add to cart etc. |
|
| 2665 | - * |
|
| 2666 | - * @since 1.9.0 |
|
| 2667 | - */ |
|
| 2668 | - public static function the_course_enrolment_actions(){ |
|
| 2669 | - ?> |
|
| 2663 | + /** |
|
| 2664 | + * Output the course actions like start taking course, register, add to cart etc. |
|
| 2665 | + * |
|
| 2666 | + * @since 1.9.0 |
|
| 2667 | + */ |
|
| 2668 | + public static function the_course_enrolment_actions(){ |
|
| 2669 | + ?> |
|
| 2670 | 2670 | <section class="course-meta course-enrolment"> |
| 2671 | 2671 | <?php |
| 2672 | - global $post, $current_user; |
|
| 2673 | - $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2674 | - if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2675 | - |
|
| 2676 | - // Get the product ID |
|
| 2677 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2678 | - |
|
| 2679 | - // Check for woocommerce |
|
| 2680 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2681 | - sensei_wc_add_to_cart($post->ID); |
|
| 2682 | - } else { |
|
| 2683 | - sensei_start_course_form($post->ID); |
|
| 2684 | - } // End If Statement |
|
| 2685 | - |
|
| 2686 | - } elseif ( is_user_logged_in() ) { |
|
| 2687 | - |
|
| 2688 | - // Check if course is completed |
|
| 2689 | - $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2690 | - $completed_course = Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2691 | - // Success message |
|
| 2692 | - if ( $completed_course ) { ?> |
|
| 2672 | + global $post, $current_user; |
|
| 2673 | + $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 2674 | + if ( is_user_logged_in() && ! $is_user_taking_course ) { |
|
| 2675 | + |
|
| 2676 | + // Get the product ID |
|
| 2677 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2678 | + |
|
| 2679 | + // Check for woocommerce |
|
| 2680 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2681 | + sensei_wc_add_to_cart($post->ID); |
|
| 2682 | + } else { |
|
| 2683 | + sensei_start_course_form($post->ID); |
|
| 2684 | + } // End If Statement |
|
| 2685 | + |
|
| 2686 | + } elseif ( is_user_logged_in() ) { |
|
| 2687 | + |
|
| 2688 | + // Check if course is completed |
|
| 2689 | + $user_course_status = Sensei_Utils::user_course_status( $post->ID, $current_user->ID ); |
|
| 2690 | + $completed_course = Sensei_Utils::user_completed_course( $user_course_status ); |
|
| 2691 | + // Success message |
|
| 2692 | + if ( $completed_course ) { ?> |
|
| 2693 | 2693 | <div class="status completed"><?php _e( 'Completed', 'woothemes-sensei' ); ?></div> |
| 2694 | 2694 | <?php |
| 2695 | - $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2696 | - if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2695 | + $has_quizzes = Sensei()->course->course_quizzes( $post->ID, true ); |
|
| 2696 | + if( has_filter( 'sensei_results_links' ) || $has_quizzes ) { ?> |
|
| 2697 | 2697 | <p class="sensei-results-links"> |
| 2698 | 2698 | <?php |
| 2699 | - $results_link = ''; |
|
| 2700 | - if( $has_quizzes ) { |
|
| 2701 | - $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2702 | - } |
|
| 2703 | - $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2704 | - echo $results_link; |
|
| 2705 | - ?></p> |
|
| 2699 | + $results_link = ''; |
|
| 2700 | + if( $has_quizzes ) { |
|
| 2701 | + $results_link = '<a class="view-results" href="' . Sensei()->course_results->get_permalink( $post->ID ) . '">' . __( 'View results', 'woothemes-sensei' ) . '</a>'; |
|
| 2702 | + } |
|
| 2703 | + $results_link = apply_filters( 'sensei_results_links', $results_link ); |
|
| 2704 | + echo $results_link; |
|
| 2705 | + ?></p> |
|
| 2706 | 2706 | <?php } ?> |
| 2707 | 2707 | <?php } else { ?> |
| 2708 | 2708 | <div class="status in-progress"><?php echo __( 'In Progress', 'woothemes-sensei' ); ?></div> |
| 2709 | 2709 | <?php } |
| 2710 | 2710 | |
| 2711 | - } else { |
|
| 2712 | - // Get the product ID |
|
| 2713 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2714 | - // Check for woocommerce |
|
| 2715 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2711 | + } else { |
|
| 2712 | + // Get the product ID |
|
| 2713 | + $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 2714 | + // Check for woocommerce |
|
| 2715 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < intval( $wc_post_id ) ) ) { |
|
| 2716 | 2716 | |
| 2717 | - sensei_wc_add_to_cart($post->ID); |
|
| 2717 | + sensei_wc_add_to_cart($post->ID); |
|
| 2718 | 2718 | |
| 2719 | - } else { |
|
| 2719 | + } else { |
|
| 2720 | 2720 | |
| 2721 | - if( get_option( 'users_can_register') ) { |
|
| 2721 | + if( get_option( 'users_can_register') ) { |
|
| 2722 | 2722 | |
| 2723 | 2723 | |
| 2724 | - $my_courses_page_id = ''; |
|
| 2724 | + $my_courses_page_id = ''; |
|
| 2725 | 2725 | |
| 2726 | - /** |
|
| 2727 | - * Filter to force Sensei to output the default WordPress user |
|
| 2728 | - * registration link. |
|
| 2729 | - * |
|
| 2730 | - * @since 1.9.0 |
|
| 2731 | - * @param bool $wp_register_link default false |
|
| 2732 | - */ |
|
| 2726 | + /** |
|
| 2727 | + * Filter to force Sensei to output the default WordPress user |
|
| 2728 | + * registration link. |
|
| 2729 | + * |
|
| 2730 | + * @since 1.9.0 |
|
| 2731 | + * @param bool $wp_register_link default false |
|
| 2732 | + */ |
|
| 2733 | 2733 | |
| 2734 | - $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2734 | + $wp_register_link = apply_filters('sensei_use_wp_register_link', false); |
|
| 2735 | 2735 | |
| 2736 | - $settings = Sensei()->settings->get_settings(); |
|
| 2737 | - if( isset( $settings[ 'my_course_page' ] ) |
|
| 2738 | - && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2736 | + $settings = Sensei()->settings->get_settings(); |
|
| 2737 | + if( isset( $settings[ 'my_course_page' ] ) |
|
| 2738 | + && 0 < intval( $settings[ 'my_course_page' ] ) ){ |
|
| 2739 | 2739 | |
| 2740 | - $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2740 | + $my_courses_page_id = $settings[ 'my_course_page' ]; |
|
| 2741 | 2741 | |
| 2742 | - } |
|
| 2742 | + } |
|
| 2743 | 2743 | |
| 2744 | - // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2745 | - // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2746 | - if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2744 | + // If a My Courses page was set in Settings, and 'sensei_use_wp_register_link' |
|
| 2745 | + // is false, link to My Courses. If not, link to default WordPress registration page. |
|
| 2746 | + if( !empty( $my_courses_page_id ) && $my_courses_page_id && !$wp_register_link){ |
|
| 2747 | 2747 | |
| 2748 | - $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2749 | - $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2750 | - echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2748 | + $my_courses_url = get_permalink( $my_courses_page_id ); |
|
| 2749 | + $register_link = '<a href="'.$my_courses_url. '">' . __('Register', 'woothemes-sensei') .'</a>'; |
|
| 2750 | + echo '<div class="status register">' . $register_link . '</div>' ; |
|
| 2751 | 2751 | |
| 2752 | - } else{ |
|
| 2752 | + } else{ |
|
| 2753 | 2753 | |
| 2754 | - wp_register( '<div class="status register">', '</div>' ); |
|
| 2754 | + wp_register( '<div class="status register">', '</div>' ); |
|
| 2755 | 2755 | |
| 2756 | - } |
|
| 2756 | + } |
|
| 2757 | 2757 | |
| 2758 | - } // end if user can register |
|
| 2758 | + } // end if user can register |
|
| 2759 | 2759 | |
| 2760 | - } // End If Statement |
|
| 2760 | + } // End If Statement |
|
| 2761 | 2761 | |
| 2762 | - } // End If Statement ?> |
|
| 2762 | + } // End If Statement ?> |
|
| 2763 | 2763 | |
| 2764 | 2764 | </section><?php |
| 2765 | 2765 | |
| 2766 | - }// end the_course_enrolment_actions |
|
| 2766 | + }// end the_course_enrolment_actions |
|
| 2767 | 2767 | |
| 2768 | - /** |
|
| 2769 | - * Output the course video inside the loop. |
|
| 2770 | - * |
|
| 2771 | - * @since 1.9.0 |
|
| 2772 | - */ |
|
| 2773 | - public static function the_course_video(){ |
|
| 2768 | + /** |
|
| 2769 | + * Output the course video inside the loop. |
|
| 2770 | + * |
|
| 2771 | + * @since 1.9.0 |
|
| 2772 | + */ |
|
| 2773 | + public static function the_course_video(){ |
|
| 2774 | 2774 | |
| 2775 | - global $post; |
|
| 2776 | - // Get the meta info |
|
| 2777 | - $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2775 | + global $post; |
|
| 2776 | + // Get the meta info |
|
| 2777 | + $course_video_embed = get_post_meta( $post->ID, '_course_video_embed', true ); |
|
| 2778 | 2778 | |
| 2779 | - if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2779 | + if ( 'http' == substr( $course_video_embed, 0, 4) ) { |
|
| 2780 | 2780 | |
| 2781 | - $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2781 | + $course_video_embed = wp_oembed_get( esc_url( $course_video_embed ) ); |
|
| 2782 | 2782 | |
| 2783 | - } // End If Statement |
|
| 2783 | + } // End If Statement |
|
| 2784 | 2784 | |
| 2785 | - if ( '' != $course_video_embed ) { ?> |
|
| 2785 | + if ( '' != $course_video_embed ) { ?> |
|
| 2786 | 2786 | |
| 2787 | 2787 | <div class="course-video"> |
| 2788 | 2788 | <?php echo html_entity_decode($course_video_embed); ?> |
| 2789 | 2789 | </div> |
| 2790 | 2790 | |
| 2791 | 2791 | <?php } // End If Statement |
| 2792 | - } |
|
| 2792 | + } |
|
| 2793 | 2793 | |
| 2794 | - /** |
|
| 2795 | - * Output the title for the single lesson page |
|
| 2796 | - * |
|
| 2797 | - * @global $post |
|
| 2798 | - * @since 1.9.0 |
|
| 2799 | - */ |
|
| 2800 | - public static function the_title(){ |
|
| 2794 | + /** |
|
| 2795 | + * Output the title for the single lesson page |
|
| 2796 | + * |
|
| 2797 | + * @global $post |
|
| 2798 | + * @since 1.9.0 |
|
| 2799 | + */ |
|
| 2800 | + public static function the_title(){ |
|
| 2801 | 2801 | |
| 2802 | - global $post; |
|
| 2802 | + global $post; |
|
| 2803 | 2803 | |
| 2804 | - ?> |
|
| 2804 | + ?> |
|
| 2805 | 2805 | <header> |
| 2806 | 2806 | |
| 2807 | 2807 | <h1> |
| 2808 | 2808 | |
| 2809 | 2809 | <?php |
| 2810 | - /** |
|
| 2811 | - * Filter documented in class-sensei-messages.php the_title |
|
| 2812 | - */ |
|
| 2813 | - echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2814 | - ?> |
|
| 2810 | + /** |
|
| 2811 | + * Filter documented in class-sensei-messages.php the_title |
|
| 2812 | + */ |
|
| 2813 | + echo apply_filters( 'sensei_single_title', get_the_title( $post ), $post->post_type ); |
|
| 2814 | + ?> |
|
| 2815 | 2815 | |
| 2816 | 2816 | </h1> |
| 2817 | 2817 | |
@@ -2819,111 +2819,111 @@ discard block |
||
| 2819 | 2819 | |
| 2820 | 2820 | <?php |
| 2821 | 2821 | |
| 2822 | - }//the_title |
|
| 2823 | - |
|
| 2824 | - /** |
|
| 2825 | - * Show the title on the course category pages |
|
| 2826 | - * |
|
| 2827 | - * @since 1.9.0 |
|
| 2828 | - */ |
|
| 2829 | - public static function course_category_title(){ |
|
| 2830 | - |
|
| 2831 | - if( ! is_tax( 'course-category' ) ){ |
|
| 2832 | - return; |
|
| 2833 | - } |
|
| 2834 | - |
|
| 2835 | - $category_slug = get_query_var('course-category'); |
|
| 2836 | - $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2837 | - |
|
| 2838 | - if( ! empty($term) ){ |
|
| 2839 | - |
|
| 2840 | - $title = $term->name; |
|
| 2841 | - |
|
| 2842 | - }else{ |
|
| 2843 | - |
|
| 2844 | - $title = 'Course Category'; |
|
| 2845 | - |
|
| 2846 | - } |
|
| 2847 | - |
|
| 2848 | - $html = '<h2 class="sensei-category-title">'; |
|
| 2849 | - $html .= __('Category') . ' ' . $title; |
|
| 2850 | - $html .= '</h2>'; |
|
| 2851 | - |
|
| 2852 | - echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2853 | - |
|
| 2854 | - }// course_category_title |
|
| 2855 | - |
|
| 2856 | - /** |
|
| 2857 | - * Alter the course query to respect the order set for courses and apply |
|
| 2858 | - * this on the course-category pages. |
|
| 2859 | - * |
|
| 2860 | - * @since 1.9.0 |
|
| 2861 | - * |
|
| 2862 | - * @param WP_Query $query |
|
| 2863 | - * @return WP_Query |
|
| 2864 | - */ |
|
| 2865 | - public static function alter_course_category_order( $query ){ |
|
| 2866 | - |
|
| 2867 | - if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2868 | - return $query; |
|
| 2869 | - } |
|
| 2870 | - |
|
| 2871 | - $order = get_option( 'sensei_course_order', '' ); |
|
| 2872 | - if( !empty( $order ) ){ |
|
| 2873 | - $query->set('orderby', 'menu_order' ); |
|
| 2874 | - $query->set('order', 'ASC' ); |
|
| 2875 | - } |
|
| 2876 | - |
|
| 2877 | - return $query; |
|
| 2878 | - |
|
| 2879 | - } |
|
| 2880 | - |
|
| 2881 | - /** |
|
| 2882 | - * The very basic course query arguments |
|
| 2883 | - * so we don't have to repeat this througout |
|
| 2884 | - * the code base. |
|
| 2885 | - * |
|
| 2886 | - * Usage: |
|
| 2887 | - * $args = Sensei_Course::get_default_query_args(); |
|
| 2888 | - * $args['custom_arg'] ='custom value'; |
|
| 2889 | - * $courses = get_posts( $args ) |
|
| 2890 | - * |
|
| 2891 | - * @since 1.9.0 |
|
| 2892 | - * |
|
| 2893 | - * @return array |
|
| 2894 | - */ |
|
| 2895 | - public static function get_default_query_args(){ |
|
| 2896 | - return array( |
|
| 2897 | - 'post_type' => 'course', |
|
| 2898 | - 'posts_per_page' => 1000, |
|
| 2899 | - 'orderby' => 'date', |
|
| 2900 | - 'order' => 'DESC', |
|
| 2901 | - 'suppress_filters' => 0 |
|
| 2902 | - ); |
|
| 2903 | - } |
|
| 2904 | - |
|
| 2905 | - /** |
|
| 2906 | - * Check if the prerequisite course is completed |
|
| 2907 | - * Courses with no pre-requisite should always return true |
|
| 2908 | - * |
|
| 2909 | - * @since 1.9.0 |
|
| 2910 | - * @param $course_id |
|
| 2911 | - * @return bool |
|
| 2912 | - */ |
|
| 2913 | - public static function is_prerequisite_complete( $course_id ){ |
|
| 2914 | - |
|
| 2915 | - $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2916 | - |
|
| 2917 | - // if it has a pre requisite course check it |
|
| 2918 | - if( ! empty( $course_prerequisite_id ) ){ |
|
| 2919 | - |
|
| 2920 | - return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2921 | - |
|
| 2922 | - } |
|
| 2923 | - |
|
| 2924 | - return true; |
|
| 2925 | - |
|
| 2926 | - }// end is_prerequisite_complete |
|
| 2822 | + }//the_title |
|
| 2823 | + |
|
| 2824 | + /** |
|
| 2825 | + * Show the title on the course category pages |
|
| 2826 | + * |
|
| 2827 | + * @since 1.9.0 |
|
| 2828 | + */ |
|
| 2829 | + public static function course_category_title(){ |
|
| 2830 | + |
|
| 2831 | + if( ! is_tax( 'course-category' ) ){ |
|
| 2832 | + return; |
|
| 2833 | + } |
|
| 2834 | + |
|
| 2835 | + $category_slug = get_query_var('course-category'); |
|
| 2836 | + $term = get_term_by('slug',$category_slug,'course-category'); |
|
| 2837 | + |
|
| 2838 | + if( ! empty($term) ){ |
|
| 2839 | + |
|
| 2840 | + $title = $term->name; |
|
| 2841 | + |
|
| 2842 | + }else{ |
|
| 2843 | + |
|
| 2844 | + $title = 'Course Category'; |
|
| 2845 | + |
|
| 2846 | + } |
|
| 2847 | + |
|
| 2848 | + $html = '<h2 class="sensei-category-title">'; |
|
| 2849 | + $html .= __('Category') . ' ' . $title; |
|
| 2850 | + $html .= '</h2>'; |
|
| 2851 | + |
|
| 2852 | + echo apply_filters( 'course_category_title', $html , $term->term_id ); |
|
| 2853 | + |
|
| 2854 | + }// course_category_title |
|
| 2855 | + |
|
| 2856 | + /** |
|
| 2857 | + * Alter the course query to respect the order set for courses and apply |
|
| 2858 | + * this on the course-category pages. |
|
| 2859 | + * |
|
| 2860 | + * @since 1.9.0 |
|
| 2861 | + * |
|
| 2862 | + * @param WP_Query $query |
|
| 2863 | + * @return WP_Query |
|
| 2864 | + */ |
|
| 2865 | + public static function alter_course_category_order( $query ){ |
|
| 2866 | + |
|
| 2867 | + if( ! is_tax( 'course-category' ) || ! $query->is_main_query() ){ |
|
| 2868 | + return $query; |
|
| 2869 | + } |
|
| 2870 | + |
|
| 2871 | + $order = get_option( 'sensei_course_order', '' ); |
|
| 2872 | + if( !empty( $order ) ){ |
|
| 2873 | + $query->set('orderby', 'menu_order' ); |
|
| 2874 | + $query->set('order', 'ASC' ); |
|
| 2875 | + } |
|
| 2876 | + |
|
| 2877 | + return $query; |
|
| 2878 | + |
|
| 2879 | + } |
|
| 2880 | + |
|
| 2881 | + /** |
|
| 2882 | + * The very basic course query arguments |
|
| 2883 | + * so we don't have to repeat this througout |
|
| 2884 | + * the code base. |
|
| 2885 | + * |
|
| 2886 | + * Usage: |
|
| 2887 | + * $args = Sensei_Course::get_default_query_args(); |
|
| 2888 | + * $args['custom_arg'] ='custom value'; |
|
| 2889 | + * $courses = get_posts( $args ) |
|
| 2890 | + * |
|
| 2891 | + * @since 1.9.0 |
|
| 2892 | + * |
|
| 2893 | + * @return array |
|
| 2894 | + */ |
|
| 2895 | + public static function get_default_query_args(){ |
|
| 2896 | + return array( |
|
| 2897 | + 'post_type' => 'course', |
|
| 2898 | + 'posts_per_page' => 1000, |
|
| 2899 | + 'orderby' => 'date', |
|
| 2900 | + 'order' => 'DESC', |
|
| 2901 | + 'suppress_filters' => 0 |
|
| 2902 | + ); |
|
| 2903 | + } |
|
| 2904 | + |
|
| 2905 | + /** |
|
| 2906 | + * Check if the prerequisite course is completed |
|
| 2907 | + * Courses with no pre-requisite should always return true |
|
| 2908 | + * |
|
| 2909 | + * @since 1.9.0 |
|
| 2910 | + * @param $course_id |
|
| 2911 | + * @return bool |
|
| 2912 | + */ |
|
| 2913 | + public static function is_prerequisite_complete( $course_id ){ |
|
| 2914 | + |
|
| 2915 | + $course_prerequisite_id = get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 2916 | + |
|
| 2917 | + // if it has a pre requisite course check it |
|
| 2918 | + if( ! empty( $course_prerequisite_id ) ){ |
|
| 2919 | + |
|
| 2920 | + return Sensei_Utils::user_completed_course( $course_prerequisite_id, get_current_user_id() ); |
|
| 2921 | + |
|
| 2922 | + } |
|
| 2923 | + |
|
| 2924 | + return true; |
|
| 2925 | + |
|
| 2926 | + }// end is_prerequisite_complete |
|
| 2927 | 2927 | |
| 2928 | 2928 | |
| 2929 | 2929 | }// End Class |