Completed
Push — master ( be9484...2a1678 )
by Dwain
04:58
created
includes/admin/class-sensei-learner-management.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -79,16 +79,16 @@  discard block
 block discarded – undo
79 79
 
80 80
 		// Load Learners JS
81 81
 		wp_enqueue_script( 'sensei-learners-general',
82
-            Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js',
83
-                            array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true );
82
+			Sensei()->plugin_url . 'assets/js/learners-general' . $suffix . '.js',
83
+							array('jquery','select2','sensei-chosen-ajax' ), Sensei()->version, true );
84 84
 
85 85
 		$data = array(
86 86
 			'remove_generic_confirm' => __( 'Are you sure you want to remove this user?', 'woothemes-sensei' ),
87 87
 			'remove_from_lesson_confirm' => __( 'Are you sure you want to remove the user from this lesson?', 'woothemes-sensei' ),
88 88
 			'remove_from_course_confirm' => __( 'Are you sure you want to remove the user from this course?', 'woothemes-sensei' ),
89 89
 			'remove_user_from_post_nonce' => wp_create_nonce( 'remove_user_from_post_nonce' ),
90
-            'search_users_nonce' => wp_create_nonce( 'search-users' ),
91
-            'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' )
90
+			'search_users_nonce' => wp_create_nonce( 'search-users' ),
91
+			'selectplaceholder'=> __( 'Select Learner', 'woothemes-sensei' )
92 92
 		);
93 93
 
94 94
 		wp_localize_script( 'sensei-learners-general', 'woo_learners_general_data', $data );
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 
281 281
 				case 'course':
282 282
 
283
-                    $removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id );
283
+					$removed = Sensei_Utils::sensei_remove_user_from_course( $post_id, $user_id );
284 284
 
285 285
 				break;
286 286
 
@@ -327,19 +327,19 @@  discard block
 block discarded – undo
327 327
 
328 328
 		if ( $users ) {
329 329
 			foreach ( $users as $user ) {
330
-                $full_name = Sensei_Student::get_full_name( $user->ID );
330
+				$full_name = Sensei_Student::get_full_name( $user->ID );
331 331
 
332
-                if( trim($user->display_name ) == trim( $full_name ) ){
332
+				if( trim($user->display_name ) == trim( $full_name ) ){
333 333
 
334
-                    $name = $full_name;
334
+					$name = $full_name;
335 335
 
336
-                }else{
336
+				}else{
337 337
 
338
-                    $name = $full_name . ' ['. $user->display_name .']';
338
+					$name = $full_name . ' ['. $user->display_name .']';
339 339
 
340
-                }
340
+				}
341 341
 
342
-                $found_users[ $user->ID ] = $name  . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')';
342
+				$found_users[ $user->ID ] = $name  . ' (#' . $user->ID . ' – ' . sanitize_email( $user->user_email ) . ')';
343 343
 			}
344 344
 		}
345 345
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 			break;
384 384
 
385 385
 			case 'lesson':
386
-                $lesson_id = absint( $_POST['add_lesson_id'] );
386
+				$lesson_id = absint( $_POST['add_lesson_id'] );
387 387
 				$complete = false;
388 388
 				if( isset( $_POST['add_complete_lesson'] ) && 'yes' == $_POST['add_complete_lesson'] ) {
389 389
 					$complete = true;
@@ -443,23 +443,23 @@  discard block
 block discarded – undo
443 443
 		}
444 444
 	}
445 445
 
446
-    /**
447
-     * Return the full name and surname or the display name of the user.
448
-     *
449
-     * The user must have both name and surname otherwise display name will be returned.
450
-     *
451
-     * @deprecated since 1.9.0 use Se
452
-     * @since 1.8.0
453
-     *
454
-     * @param int $user_id | bool false for an invalid $user_id
455
-     *
456
-     * @return string $full_name
457
-     */
458
-    public function get_learner_full_name( $user_id ){
459
-
460
-        return Sensei_Student::get_full_name( $user_id );
461
-
462
-    } // end get_learner_full_name
446
+	/**
447
+	 * Return the full name and surname or the display name of the user.
448
+	 *
449
+	 * The user must have both name and surname otherwise display name will be returned.
450
+	 *
451
+	 * @deprecated since 1.9.0 use Se
452
+	 * @since 1.8.0
453
+	 *
454
+	 * @param int $user_id | bool false for an invalid $user_id
455
+	 *
456
+	 * @return string $full_name
457
+	 */
458
+	public function get_learner_full_name( $user_id ){
459
+
460
+		return Sensei_Student::get_full_name( $user_id );
461
+
462
+	} // end get_learner_full_name
463 463
 
464 464
 } // End Class
465 465
 
Please login to merge, or discard this patch.
includes/class-sensei-learners-main.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
 
207 207
 	/**
208 208
 	 * Generates content for a single row of the table in the user management
209
-     * screen.
210
-     *
209
+	 * screen.
210
+	 *
211 211
 	 * @since  1.7.0
212
-     *
212
+	 *
213 213
 	 * @param object $item The current item
214
-     *
215
-     * @return void
214
+	 *
215
+	 * @return void
216 216
 	 */
217 217
 	protected function get_row_data( $item ) {
218 218
 		global $wp_version;
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
 		switch ( $this->view ) {
221 221
 			case 'learners' :
222 222
 
223
-                // in this case the item passed in is actually the users activity on course of lesson
224
-                $user_activity = $item;
223
+				// in this case the item passed in is actually the users activity on course of lesson
224
+				$user_activity = $item;
225 225
 				$post_id = false;
226 226
 
227 227
 				if( $this->lesson_id ) {
@@ -240,30 +240,30 @@  discard block
 block discarded – undo
240 240
 
241 241
 				if( 'complete' == $user_activity->comment_approved || 'graded' == $user_activity->comment_approved || 'passed' == $user_activity->comment_approved ) {
242 242
 
243
-                    $status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>';
243
+					$status_html = '<span class="graded">' .__( 'Completed', 'woothemes-sensei' ) . '</span>';
244 244
 
245 245
 				} else {
246 246
 
247
-                    $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
247
+					$status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>';
248 248
 
249 249
 				}
250 250
 
251
-                $title = Sensei_Student::get_full_name( $user_activity->user_id );
251
+				$title = Sensei_Student::get_full_name( $user_activity->user_id );
252 252
 				$a_title = sprintf( __( 'Edit &#8220;%s&#8221;' ), $title );
253 253
 
254
-                /**
255
-                 * sensei_learners_main_column_data filter
256
-                 *
257
-                 * This filter runs on the learner management screen for a specific course.
258
-                 * It provides the learner row column details.
259
-                 *
260
-                 * @param array $columns{
261
-                 *   type string $title
262
-                 *   type string $date_started
263
-                 *   type string $course_status (completed, started etc)
264
-                 *   type html $action_buttons
265
-                 * }
266
-                 */
254
+				/**
255
+				 * sensei_learners_main_column_data filter
256
+				 *
257
+				 * This filter runs on the learner management screen for a specific course.
258
+				 * It provides the learner row column details.
259
+				 *
260
+				 * @param array $columns{
261
+				 *   type string $title
262
+				 *   type string $date_started
263
+				 *   type string $course_status (completed, started etc)
264
+				 *   type html $action_buttons
265
+				 * }
266
+				 */
267 267
 				$column_data = apply_filters( 'sensei_learners_main_column_data', array(
268 268
 						'title' => '<strong><a class="row-title" href="' . admin_url( 'user-edit.php?user_id=' . $user_activity->user_id ) . '" title="' . esc_attr( $a_title ) . '">' . $title . '</a></strong>',
269 269
 						'date_started' => get_comment_meta( $user_activity->comment_ID, 'start', true),
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 
294 294
 			case 'courses' :
295 295
 			default:
296
-                $course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) );
296
+				$course_learners = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_learners_course_learners', array( 'post_id' => $item->ID, 'type' => 'sensei_course_status', 'status' => 'any' ) ) );
297 297
 				$title = get_the_title( $item );
298 298
 				$a_title = sprintf( __( 'Edit &#8220;%s&#8221;' ), $title );
299 299
 
Please login to merge, or discard this patch.
includes/class-sensei-notices.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -16,28 +16,28 @@  discard block
 block discarded – undo
16 16
 class Sensei_Notices{
17 17
 
18 18
 	/**
19
-	*  @var $notices
20
-	*/
19
+	 *  @var $notices
20
+	 */
21 21
 	protected $notices;
22 22
 
23 23
 	/**
24
-	*  constructor 
25
- 	*/
24
+	 *  constructor 
25
+	 */
26 26
 	public function __construct(){
27 27
 		//initialize the notices variable
28 28
 		$this->notices = array();
29 29
 	}
30 30
 
31 31
 	/**
32
-	*  Add a notice to the array of notices for display at a later stage.
33
-	* 
34
-	*
35
-	* 
36
-	* @param string $message 
37
-	* @param string $type defaults to alert options( alert, tick , download , info   )
38
-	*
39
-	* @return void
40
-	*/
32
+	 *  Add a notice to the array of notices for display at a later stage.
33
+	 * 
34
+	 *
35
+	 * 
36
+	 * @param string $message 
37
+	 * @param string $type defaults to alert options( alert, tick , download , info   )
38
+	 *
39
+	 * @return void
40
+	 */
41 41
 
42 42
 	public function add_notice( $content ,  $type = 'alert'   ){
43 43
 		// append the new notice
@@ -45,13 +45,13 @@  discard block
 block discarded – undo
45 45
 	} // end add_notice()
46 46
 
47 47
 	/**
48
-	*  Output all notices added 
49
-	* 
50
-	* @param string $message 
51
-	* @param string $type
52
-	*
53
-	* @return void
54
-	*/
48
+	 *  Output all notices added 
49
+	 * 
50
+	 * @param string $message 
51
+	 * @param string $type
52
+	 *
53
+	 * @return void
54
+	 */
55 55
 
56 56
 	public function print_notices(){
57 57
 		if(  count( $this->notices ) > 0  ){
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 	} // end print_notice()
69 69
 
70 70
 	/**
71
-	*  Clear all notices  
72
-	* 
73
-	* @return void
74
-	*/
71
+	 *  Clear all notices  
72
+	 * 
73
+	 * @return void
74
+	 */
75 75
 
76 76
 	public function clear_notices(){
77 77
 		// assign an empty array to clear all existing notices
Please login to merge, or discard this patch.
includes/sensei-functions.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -45,16 +45,16 @@  discard block
 block discarded – undo
45 45
  */
46 46
 function sensei_all_access() {
47 47
 
48
-    $access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' );
49
-
50
-    /**
51
-     * Filter sensei_all_access function result
52
-     * which determinse if the current user
53
-     * can access all of Sensei without restrictions
54
-     *
55
-     * @since 1.4.0
56
-     * @param bool $access
57
-     */
48
+	$access = current_user_can( 'manage_sensei' ) || current_user_can( 'manage_sensei_grades' );
49
+
50
+	/**
51
+	 * Filter sensei_all_access function result
52
+	 * which determinse if the current user
53
+	 * can access all of Sensei without restrictions
54
+	 *
55
+	 * @since 1.4.0
56
+	 * @param bool $access
57
+	 */
58 58
 	return apply_filters( 'sensei_all_access', $access );
59 59
 
60 60
 } // End sensei_all_access()
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 	 */
73 73
 	function sensei_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
74 74
 
75
-	    $hex = str_replace( '#', '', $color );
75
+		$hex = str_replace( '#', '', $color );
76 76
 
77 77
 		$c_r = hexdec( substr( $hex, 0, 2 ) );
78 78
 		$c_g = hexdec( substr( $hex, 2, 2 ) );
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
 		$color = '#';
120 120
 
121 121
 		foreach ($base as $k => $v) :
122
-	        $amount = $v / 100;
123
-	        $amount = round($amount * $factor);
124
-	        $new_decimal = $v - $amount;
125
-
126
-	        $new_hex_component = dechex($new_decimal);
127
-	        if(strlen($new_hex_component) < 2) :
128
-	        	$new_hex_component = "0".$new_hex_component;
129
-	        endif;
130
-	        $color .= $new_hex_component;
122
+			$amount = $v / 100;
123
+			$amount = round($amount * $factor);
124
+			$new_decimal = $v - $amount;
125
+
126
+			$new_hex_component = dechex($new_decimal);
127
+			if(strlen($new_hex_component) < 2) :
128
+				$new_hex_component = "0".$new_hex_component;
129
+			endif;
130
+			$color .= $new_hex_component;
131 131
 		endforeach;
132 132
 
133 133
 		return $color;
@@ -148,17 +148,17 @@  discard block
 block discarded – undo
148 148
 		$base = sensei_rgb_from_hex( $color );
149 149
 		$color = '#';
150 150
 
151
-	    foreach ($base as $k => $v) :
152
-	        $amount = 255 - $v;
153
-	        $amount = $amount / 100;
154
-	        $amount = round($amount * $factor);
155
-	        $new_decimal = $v + $amount;
156
-
157
-	        $new_hex_component = dechex($new_decimal);
158
-	        if(strlen($new_hex_component) < 2) :
159
-	        	$new_hex_component = "0".$new_hex_component;
160
-	        endif;
161
-	        $color .= $new_hex_component;
151
+		foreach ($base as $k => $v) :
152
+			$amount = 255 - $v;
153
+			$amount = $amount / 100;
154
+			$amount = round($amount * $factor);
155
+			$new_decimal = $v + $amount;
156
+
157
+			$new_hex_component = dechex($new_decimal);
158
+			if(strlen($new_hex_component) < 2) :
159
+				$new_hex_component = "0".$new_hex_component;
160
+			endif;
161
+			$color .= $new_hex_component;
162 162
 	   	endforeach;
163 163
 
164 164
 	   	return $color;
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
  * @deprecated since 1.9.0 use  Sensei_WC::is_woocommerce_active()
173 173
  */
174 174
 if ( ! function_exists( 'is_woocommerce_active' ) ) {
175
-    function is_woocommerce_active() {
176
-        // calling is present instead of is active here
177
-        // as this function can override other is_woocommerce_active
178
-        // function in other woo plugins and Sensei_WC::is_woocommerce_active
179
-        // also check the sensei settings for enable WooCommerce support, which
180
-        // other plugins should not check against.
181
-        return Sensei_WC::is_woocommerce_present();
182
-    }
175
+	function is_woocommerce_active() {
176
+		// calling is present instead of is active here
177
+		// as this function can override other is_woocommerce_active
178
+		// function in other woo plugins and Sensei_WC::is_woocommerce_active
179
+		// also check the sensei settings for enable WooCommerce support, which
180
+		// other plugins should not check against.
181
+		return Sensei_WC::is_woocommerce_present();
182
+	}
183 183
 }
184 184
 
185 185
 /**
@@ -195,20 +195,20 @@  discard block
 block discarded – undo
195 195
  */
196 196
 function sensei_do_deprecated_action( $hook_tag, $version, $alternative="" , $args = array()  ){
197 197
 
198
-    if( has_action( $hook_tag ) ){
198
+	if( has_action( $hook_tag ) ){
199 199
 
200
-        $error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version );
200
+		$error_message = sprintf( __( "SENSEI: The hook '%s', has been deprecated since '%s'." , 'woothemes-sensei'), $hook_tag ,$version );
201 201
 
202
-        if( !empty( $alternative ) ){
202
+		if( !empty( $alternative ) ){
203 203
 
204
-            $error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ;
204
+			$error_message .= sprintf( __("Please use '%s' instead.", 'woothemes-sensei'), $alternative ) ;
205 205
 
206
-        }
206
+		}
207 207
 
208
-        trigger_error( $error_message );
209
-        do_action( $hook_tag , $args );
208
+		trigger_error( $error_message );
209
+		do_action( $hook_tag , $args );
210 210
 
211
-    }
211
+	}
212 212
 
213 213
 }// end sensei_do_deprecated_action
214 214
 
@@ -238,18 +238,18 @@  discard block
 block discarded – undo
238 238
  */
239 239
 function sensei_user_login_url(){
240 240
 
241
-    $my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) );
242
-    $page = get_post( $my_courses_page_id );
241
+	$my_courses_page_id = intval( Sensei()->settings->get( 'my_course_page' ) );
242
+	$page = get_post( $my_courses_page_id );
243 243
 
244
-    if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID )  ){
244
+	if ( $my_courses_page_id && isset( $page->ID ) && 'page' == get_post_type( $page->ID )  ){
245 245
 
246
-        return get_permalink( $page->ID );
246
+		return get_permalink( $page->ID );
247 247
 
248
-    } else {
248
+	} else {
249 249
 
250
-        return wp_login_url();
250
+		return wp_login_url();
251 251
 
252
-    }
252
+	}
253 253
 
254 254
 }// end sensei_user_login_link
255 255
 
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
  */
263 263
 function sensei_is_login_required(){
264 264
 
265
-    $login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] );
265
+	$login_required = isset( Sensei()->settings->settings['access_permission'] ) && ( true == Sensei()->settings->settings['access_permission'] );
266 266
 
267
-    return $login_required;
267
+	return $login_required;
268 268
 
269 269
 }
270 270
\ No newline at end of file
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-loader.php 1 patch
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -15,172 +15,172 @@
 block discarded – undo
15 15
  */
16 16
 class Sensei_Shortcode_Loader{
17 17
 
18
-    /**
19
-     * @var array {
20
-     *  type string $shortcode
21
-     *  type Sensei_Shortcode
22
-     * } all the shortcodes and which class to instantiate when they are called from
23
-     * WordPress's do_shortcode() function.
24
-     *
25
-     */
26
-    protected $shortcode_classes;
27
-
28
-    /**
29
-     * Run all the functions that needs to be hooked into WordPress
30
-     *
31
-     * @since 1.9.0
32
-     */
33
-    public function __construct(){
34
-
35
-        // create a list of shortcodes and the class that handles them
36
-        $this->setup_shortcode_class_map();
37
-
38
-        // setup all the shortcodes and load the listener into WP
39
-        $this->initialize_shortcodes();
40
-
41
-        // add sensei body class for shortcodes
42
-        add_filter( 'body_class', array( $this, 'possibly_add_body_class' ));
43
-
44
-        // array( $this, 'add_body_class')
45
-
46
-    }
47
-
48
-    /**
49
-     * Array of shortcode classes that should be instantiated when WordPress loads
50
-     * a Sensei specific shortcode.
51
-     * This list contains:
52
-     * $shortcode => $class_name
53
-     *
54
-     * $shortcode is the actual shortcode the user will add to the editor
55
-     * $class_name is the name of the class that will be instantiated to handle
56
-     * the rendering of the shortcode.
57
-     *
58
-     * NOTE: When adding a new shortcode here be sure to load your shortcodes class
59
-     * in class-sensei-autoloader class_file_map function
60
-     */
61
-    public function setup_shortcode_class_map(){
62
-
63
-        $this->shortcode_classes = array(
64
-            'sensei_featured_courses'    => 'Sensei_Shortcode_Featured_Courses',
65
-            'sensei_user_courses'        => 'Sensei_Shortcode_User_Courses',
66
-            'sensei_courses'             => 'Sensei_Shortcode_Courses',
67
-            'sensei_teachers'            => 'Sensei_Shortcode_Teachers',
68
-            'sensei_user_messages'       => 'Sensei_Shortcode_User_Messages',
69
-            'sensei_course_page'         => 'Sensei_Shortcode_Course_Page',
70
-            'sensei_lesson_page'         => 'Sensei_Shortcode_Lesson_Page',
71
-            'sensei_course_categories'   => 'Sensei_Shortcode_Course_Categories',
72
-            'sensei_unpurchased_courses' => 'Sensei_Shortcode_Unpurchased_Courses',
73
-        );
74
-
75
-        // legacy shortcode handling:
76
-        Sensei_Legacy_Shortcodes::init();
77
-
78
-    }
79
-
80
-    /**
81
-     * Add all shortcodes here
82
-     *
83
-     * This function adds shortcodes to WP that links to other functionality.
84
-     * @since 1.9.0
85
-     */
86
-    public function initialize_shortcodes(){
87
-
88
-        // shortcodes should only respond to front end calls
89
-        if( is_admin() || defined( 'DOING_AJAX' ) ){
90
-            return;
91
-        }
92
-
93
-        /**
94
-         * Tell WP to run this classes load_shortcode function for all the
95
-         * shortcodes registered here in.
96
-         *
97
-         * With this method we only load shortcode classes when we need them.
98
-         */
99
-        foreach( $this->shortcode_classes as $shortcode => $class ){
100
-
101
-            // all Sensei shortcodes are rendered by this loader class
102
-            // it acts as an interface between wp and the shortcodes registered
103
-            // above
104
-            add_shortcode( $shortcode, array( $this,'render_shortcode' ) );
105
-
106
-        }
107
-
108
-    }
109
-
110
-    /**
111
-     * Respond to WordPress do_shortcode calls
112
-     * for shortcodes registered in the initialize_shortcodes function.
113
-     *
114
-     * @since 1.9.0
115
-     *
116
-     * @param $attributes
117
-     * @param $content
118
-     * @param $code the shortcode that is being requested
119
-     *
120
-     * @return string
121
-     */
122
-    public function render_shortcode( $attributes='', $content='', $code ){
123
-
124
-        // only respond if the shortcode that we've added shortcode
125
-        // classes for.
126
-        if( ! isset( $this->shortcode_classes[ $code ] ) ){
127
-            return '';
128
-        }
129
-
130
-        // create an instances of the current requested shortcode
131
-        $shortcode_handling_class = $this->shortcode_classes[ $code ];
132
-        $shortcode = new $shortcode_handling_class( $attributes, $content, $code );
133
-
134
-        // we expect the sensei class instantiated to implement the Sensei_Shortcode interface
135
-        if( ! in_array( 'Sensei_Shortcode_Interface', class_implements( $shortcode) ) ){
136
-
137
-            $message = "The rendering class for your shortcode: $code, must implement the Sensei_Shortcode interface";
138
-            _doing_it_wrong('Sensei_Shortcode_Loader::render_shortcode',$message, '1.9.0' );
139
-
140
-        }
141
-
142
-        return $shortcode->render();
143
-
144
-    }
145
-
146
-    /**
147
-     * Add the Sensei body class if
148
-     * the current page has a Sensei shortcode.
149
-     *
150
-     * Note: legacy shortcodes not supported here.
151
-     *
152
-     * @since 1.9.0
153
-     *
154
-     * @param array $classes
155
-     * @return array
156
-     */
157
-    public function possibly_add_body_class ( $classes ) {
158
-
159
-        global $post;
160
-
161
-        $has_sensei_shortcode = false;
162
-
163
-        if ( is_a( $post, 'WP_Post' ) ) {
164
-
165
-            // check all registered Sensei shortcodes (not legacy shortcodes)
166
-            foreach ( $this->shortcode_classes as $shortcode => $class ){
167
-
168
-                if ( has_shortcode( $post->post_content, $shortcode ) ) {
18
+	/**
19
+	 * @var array {
20
+	 *  type string $shortcode
21
+	 *  type Sensei_Shortcode
22
+	 * } all the shortcodes and which class to instantiate when they are called from
23
+	 * WordPress's do_shortcode() function.
24
+	 *
25
+	 */
26
+	protected $shortcode_classes;
27
+
28
+	/**
29
+	 * Run all the functions that needs to be hooked into WordPress
30
+	 *
31
+	 * @since 1.9.0
32
+	 */
33
+	public function __construct(){
34
+
35
+		// create a list of shortcodes and the class that handles them
36
+		$this->setup_shortcode_class_map();
37
+
38
+		// setup all the shortcodes and load the listener into WP
39
+		$this->initialize_shortcodes();
40
+
41
+		// add sensei body class for shortcodes
42
+		add_filter( 'body_class', array( $this, 'possibly_add_body_class' ));
43
+
44
+		// array( $this, 'add_body_class')
45
+
46
+	}
47
+
48
+	/**
49
+	 * Array of shortcode classes that should be instantiated when WordPress loads
50
+	 * a Sensei specific shortcode.
51
+	 * This list contains:
52
+	 * $shortcode => $class_name
53
+	 *
54
+	 * $shortcode is the actual shortcode the user will add to the editor
55
+	 * $class_name is the name of the class that will be instantiated to handle
56
+	 * the rendering of the shortcode.
57
+	 *
58
+	 * NOTE: When adding a new shortcode here be sure to load your shortcodes class
59
+	 * in class-sensei-autoloader class_file_map function
60
+	 */
61
+	public function setup_shortcode_class_map(){
62
+
63
+		$this->shortcode_classes = array(
64
+			'sensei_featured_courses'    => 'Sensei_Shortcode_Featured_Courses',
65
+			'sensei_user_courses'        => 'Sensei_Shortcode_User_Courses',
66
+			'sensei_courses'             => 'Sensei_Shortcode_Courses',
67
+			'sensei_teachers'            => 'Sensei_Shortcode_Teachers',
68
+			'sensei_user_messages'       => 'Sensei_Shortcode_User_Messages',
69
+			'sensei_course_page'         => 'Sensei_Shortcode_Course_Page',
70
+			'sensei_lesson_page'         => 'Sensei_Shortcode_Lesson_Page',
71
+			'sensei_course_categories'   => 'Sensei_Shortcode_Course_Categories',
72
+			'sensei_unpurchased_courses' => 'Sensei_Shortcode_Unpurchased_Courses',
73
+		);
74
+
75
+		// legacy shortcode handling:
76
+		Sensei_Legacy_Shortcodes::init();
77
+
78
+	}
79
+
80
+	/**
81
+	 * Add all shortcodes here
82
+	 *
83
+	 * This function adds shortcodes to WP that links to other functionality.
84
+	 * @since 1.9.0
85
+	 */
86
+	public function initialize_shortcodes(){
87
+
88
+		// shortcodes should only respond to front end calls
89
+		if( is_admin() || defined( 'DOING_AJAX' ) ){
90
+			return;
91
+		}
92
+
93
+		/**
94
+		 * Tell WP to run this classes load_shortcode function for all the
95
+		 * shortcodes registered here in.
96
+		 *
97
+		 * With this method we only load shortcode classes when we need them.
98
+		 */
99
+		foreach( $this->shortcode_classes as $shortcode => $class ){
100
+
101
+			// all Sensei shortcodes are rendered by this loader class
102
+			// it acts as an interface between wp and the shortcodes registered
103
+			// above
104
+			add_shortcode( $shortcode, array( $this,'render_shortcode' ) );
105
+
106
+		}
107
+
108
+	}
109
+
110
+	/**
111
+	 * Respond to WordPress do_shortcode calls
112
+	 * for shortcodes registered in the initialize_shortcodes function.
113
+	 *
114
+	 * @since 1.9.0
115
+	 *
116
+	 * @param $attributes
117
+	 * @param $content
118
+	 * @param $code the shortcode that is being requested
119
+	 *
120
+	 * @return string
121
+	 */
122
+	public function render_shortcode( $attributes='', $content='', $code ){
123
+
124
+		// only respond if the shortcode that we've added shortcode
125
+		// classes for.
126
+		if( ! isset( $this->shortcode_classes[ $code ] ) ){
127
+			return '';
128
+		}
129
+
130
+		// create an instances of the current requested shortcode
131
+		$shortcode_handling_class = $this->shortcode_classes[ $code ];
132
+		$shortcode = new $shortcode_handling_class( $attributes, $content, $code );
133
+
134
+		// we expect the sensei class instantiated to implement the Sensei_Shortcode interface
135
+		if( ! in_array( 'Sensei_Shortcode_Interface', class_implements( $shortcode) ) ){
136
+
137
+			$message = "The rendering class for your shortcode: $code, must implement the Sensei_Shortcode interface";
138
+			_doing_it_wrong('Sensei_Shortcode_Loader::render_shortcode',$message, '1.9.0' );
139
+
140
+		}
141
+
142
+		return $shortcode->render();
143
+
144
+	}
145
+
146
+	/**
147
+	 * Add the Sensei body class if
148
+	 * the current page has a Sensei shortcode.
149
+	 *
150
+	 * Note: legacy shortcodes not supported here.
151
+	 *
152
+	 * @since 1.9.0
153
+	 *
154
+	 * @param array $classes
155
+	 * @return array
156
+	 */
157
+	public function possibly_add_body_class ( $classes ) {
158
+
159
+		global $post;
160
+
161
+		$has_sensei_shortcode = false;
162
+
163
+		if ( is_a( $post, 'WP_Post' ) ) {
164
+
165
+			// check all registered Sensei shortcodes (not legacy shortcodes)
166
+			foreach ( $this->shortcode_classes as $shortcode => $class ){
167
+
168
+				if ( has_shortcode( $post->post_content, $shortcode ) ) {
169 169
 
170
-                    $has_sensei_shortcode = true;
171
-                }
170
+					$has_sensei_shortcode = true;
171
+				}
172 172
 
173
-            }
174
-        }
173
+			}
174
+		}
175 175
 
176
-        if( $has_sensei_shortcode ) {
177
-            $classes[] = 'sensei' ;
178
-        }
176
+		if( $has_sensei_shortcode ) {
177
+			$classes[] = 'sensei' ;
178
+		}
179 179
 
180 180
 
181
-        return $classes;
182
-
183
-    }
181
+		return $classes;
182
+
183
+	}
184 184
 
185 185
 } // end class Sensei_Shortcodes
186 186
 new Sensei_Shortcode_Loader();
Please login to merge, or discard this patch.
includes/shortcodes/class-sensei-shortcode-unpurchased-courses.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -14,148 +14,148 @@
 block discarded – undo
14 14
  */
15 15
 class Sensei_Shortcode_Unpurchased_Courses implements Sensei_Shortcode_Interface {
16 16
 
17
-    /**
18
-     * @var WP_Query to help setup the query needed by the render method.
19
-     */
20
-    protected $query;
21
-
22
-    /**
23
-     * @var string number of items to show on the current page
24
-     * Default: all.
25
-     */
26
-    protected $number;
27
-
28
-    /**
29
-     * @var string ordery by course field
30
-     * Default: date
31
-     */
32
-    protected $orderby;
33
-
34
-    /**
35
-     * @var string ASC or DESC
36
-     * Default: 'DESC'
37
-     */
38
-    protected  $order;
39
-
40
-    /**
41
-     * Setup the shortcode object
42
-     *
43
-     * @since 1.9.0
44
-     * @param array $attributes
45
-     * @param string $content
46
-     * @param string $shortcode the shortcode that was called for this instance
47
-     */
48
-    public function __construct( $attributes, $content, $shortcode ){
49
-
50
-        // set up all argument need for constructing the course query
51
-        $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
52
-        $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
53
-
54
-        // set the default for menu_order to be ASC
55
-        if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
56
-
57
-            $this->order =  'ASC';
17
+	/**
18
+	 * @var WP_Query to help setup the query needed by the render method.
19
+	 */
20
+	protected $query;
21
+
22
+	/**
23
+	 * @var string number of items to show on the current page
24
+	 * Default: all.
25
+	 */
26
+	protected $number;
27
+
28
+	/**
29
+	 * @var string ordery by course field
30
+	 * Default: date
31
+	 */
32
+	protected $orderby;
33
+
34
+	/**
35
+	 * @var string ASC or DESC
36
+	 * Default: 'DESC'
37
+	 */
38
+	protected  $order;
39
+
40
+	/**
41
+	 * Setup the shortcode object
42
+	 *
43
+	 * @since 1.9.0
44
+	 * @param array $attributes
45
+	 * @param string $content
46
+	 * @param string $shortcode the shortcode that was called for this instance
47
+	 */
48
+	public function __construct( $attributes, $content, $shortcode ){
49
+
50
+		// set up all argument need for constructing the course query
51
+		$this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10';
52
+		$this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'title';
53
+
54
+		// set the default for menu_order to be ASC
55
+		if( 'menu_order' == $this->orderby && !isset( $attributes['order']  ) ){
56
+
57
+			$this->order =  'ASC';
58 58
 
59
-        }else{
59
+		}else{
60 60
 
61
-            // for everything else use the value passed or the default DESC
62
-            $this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
61
+			// for everything else use the value passed or the default DESC
62
+			$this->order = isset( $attributes['order']  ) ? $attributes['order'] : 'DESC';
63 63
 
64
-        }
64
+		}
65 65
 
66
-        // setup the course query that will be used when rendering
67
-        $this->setup_course_query();
68
-    }
66
+		// setup the course query that will be used when rendering
67
+		$this->setup_course_query();
68
+	}
69 69
 
70
-    /**
71
-     * Sets up the object course query
72
-     * that will be used int he render method.
73
-     *
74
-     * @since 1.9.0
75
-     */
76
-    protected function setup_course_query(){
70
+	/**
71
+	 * Sets up the object course query
72
+	 * that will be used int he render method.
73
+	 *
74
+	 * @since 1.9.0
75
+	 */
76
+	protected function setup_course_query(){
77 77
 
78 78
 
79
-        // course query parameters to be used for all courses
80
-        $query_args = array(
81
-            'post_type'        => 'course',
82
-            'post_status'      => 'publish',
83
-            // the number specified by the user will be used later in this function
84
-            'posts_per_page' => 1000,
85
-            'orderby'          => $this->orderby,
86
-            'order'            => $this->order
87
-        );
79
+		// course query parameters to be used for all courses
80
+		$query_args = array(
81
+			'post_type'        => 'course',
82
+			'post_status'      => 'publish',
83
+			// the number specified by the user will be used later in this function
84
+			'posts_per_page' => 1000,
85
+			'orderby'          => $this->orderby,
86
+			'order'            => $this->order
87
+		);
88 88
 
89
-        // get all the courses that has a product attached
90
-        $all_courses_query = new WP_Query( $query_args );
89
+		// get all the courses that has a product attached
90
+		$all_courses_query = new WP_Query( $query_args );
91 91
 
92
-        $paid_courses_not_taken = array();
93
-        // look through all course and find the purchasable ones that user has not purchased
94
-        foreach( $all_courses_query->posts as $course ){
92
+		$paid_courses_not_taken = array();
93
+		// look through all course and find the purchasable ones that user has not purchased
94
+		foreach( $all_courses_query->posts as $course ){
95 95
 
96
-            // only keep the courses with a product including only  courses that the user not taking
97
-            $course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true );
98
-            if( is_numeric( $course_product_id )
99
-                &&
100
-                ! Sensei_Utils::user_started_course( $course->ID , get_current_user_id()  )
101
-            ){
96
+			// only keep the courses with a product including only  courses that the user not taking
97
+			$course_product_id = get_post_meta( $course->ID, '_course_woocommerce_product',true );
98
+			if( is_numeric( $course_product_id )
99
+				&&
100
+				! Sensei_Utils::user_started_course( $course->ID , get_current_user_id()  )
101
+			){
102 102
 
103
-                    $paid_courses_not_taken[] = $course->ID;
103
+					$paid_courses_not_taken[] = $course->ID;
104 104
 
105
-                }
105
+				}
106 106
 
107
-        } // end foreach
107
+		} // end foreach
108 108
 
109
-        // setup the course query again and only use the course the user has not purchased.
110
-        // this query will be loaded into the global WP_Query in the render function.
111
-        $query_args[ 'post__in' ] = $paid_courses_not_taken;
112
-        $query_args[ 'posts_per_page' ] = $this->number;
109
+		// setup the course query again and only use the course the user has not purchased.
110
+		// this query will be loaded into the global WP_Query in the render function.
111
+		$query_args[ 'post__in' ] = $paid_courses_not_taken;
112
+		$query_args[ 'posts_per_page' ] = $this->number;
113 113
 
114
-        $this->query = new WP_Query( $query_args );
114
+		$this->query = new WP_Query( $query_args );
115 115
 
116
-    }// end setup _course_query
116
+	}// end setup _course_query
117 117
 
118
-    /**
119
-     * Rendering the shortcode this class is responsible for.
120
-     *
121
-     * @return string $content
122
-     */
123
-    public function render(){
118
+	/**
119
+	 * Rendering the shortcode this class is responsible for.
120
+	 *
121
+	 * @return string $content
122
+	 */
123
+	public function render(){
124 124
 
125
-        global $wp_query;
125
+		global $wp_query;
126 126
 
127
-        if ( ! is_user_logged_in() ) {
127
+		if ( ! is_user_logged_in() ) {
128 128
 
129
-            $anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >';
130
-            $anchor_after = '</a>';
131
-            $notice = sprintf(
132
-                __('You must be logged in to view the non-purchased courses. Click here to %slogin%s.'),
133
-                $anchor_before,
134
-                $anchor_after
135
-            );
129
+			$anchor_before = '<a href="' . esc_url( sensei_user_login_url() ) . '" >';
130
+			$anchor_after = '</a>';
131
+			$notice = sprintf(
132
+				__('You must be logged in to view the non-purchased courses. Click here to %slogin%s.'),
133
+				$anchor_before,
134
+				$anchor_after
135
+			);
136 136
 
137
-            Sensei()->notices->add_notice( $notice, 'info' );
138
-            Sensei()->notices->print_notices();
137
+			Sensei()->notices->add_notice( $notice, 'info' );
138
+			Sensei()->notices->print_notices();
139 139
 
140
-            return '';
140
+			return '';
141 141
 
142
-        }
142
+		}
143 143
 
144
-        // keep a reference to old query
145
-        $current_global_query = $wp_query;
146
-        // assign the query setup in $this-> setup_course_query
147
-        $wp_query = $this->query;
144
+		// keep a reference to old query
145
+		$current_global_query = $wp_query;
146
+		// assign the query setup in $this-> setup_course_query
147
+		$wp_query = $this->query;
148 148
 
149
-        ob_start();
150
-        Sensei()->notices->print_notices();
151
-        Sensei_Templates::get_template('loop-course.php');
152
-        $shortcode_output =  ob_get_clean();
149
+		ob_start();
150
+		Sensei()->notices->print_notices();
151
+		Sensei_Templates::get_template('loop-course.php');
152
+		$shortcode_output =  ob_get_clean();
153 153
 
154
-        //restore old query
155
-        $wp_query = $current_global_query;
154
+		//restore old query
155
+		$wp_query = $current_global_query;
156 156
 
157
-        return $shortcode_output;
157
+		return $shortcode_output;
158 158
 
159
-    }// end render
159
+	}// end render
160 160
 
161 161
 }
162 162
\ No newline at end of file
Please login to merge, or discard this patch.