@@ -15,88 +15,88 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Sensei_Shortcode_User_Messages implements Sensei_Shortcode_Interface { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var array $messages{ |
|
| 20 | - * @type WP_Post |
|
| 21 | - * } |
|
| 22 | - * messages for the current user |
|
| 23 | - */ |
|
| 24 | - protected $messages_query; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Setup the shortcode object |
|
| 28 | - * |
|
| 29 | - * @since 1.9.0 |
|
| 30 | - * @param array $attributes |
|
| 31 | - * @param string $content |
|
| 32 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 33 | - */ |
|
| 34 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 35 | - |
|
| 36 | - if( is_user_logged_in() ){ |
|
| 37 | - |
|
| 38 | - $this->setup_messages_query(); |
|
| 39 | - |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * create the messages query . |
|
| 46 | - * |
|
| 47 | - * @return mixed |
|
| 48 | - */ |
|
| 49 | - public function setup_messages_query(){ |
|
| 50 | - |
|
| 51 | - $user = wp_get_current_user(); |
|
| 52 | - |
|
| 53 | - $args = array( |
|
| 54 | - 'post_type' => 'sensei_message', |
|
| 55 | - 'posts_per_page' => 500, |
|
| 56 | - 'orderby' => 'date', |
|
| 57 | - 'order' => 'DESC', |
|
| 58 | - 'post_status' => 'publish', |
|
| 59 | - 'meta_query' => array( |
|
| 60 | - array( |
|
| 61 | - 'key' => '_sender', |
|
| 62 | - 'value' => $user->user_login, |
|
| 63 | - 'compare' => '=', |
|
| 64 | - ), |
|
| 65 | - ), |
|
| 66 | - ); |
|
| 67 | - |
|
| 68 | - $this->messages_query = new WP_Query( $args ); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Rendering the shortcode this class is responsible for. |
|
| 73 | - * |
|
| 74 | - * @return string $content |
|
| 75 | - */ |
|
| 76 | - public function render(){ |
|
| 77 | - |
|
| 78 | - $messages_disabled_in_settings = ! ( ! isset( Sensei()->settings->settings['messages_disable'] ) |
|
| 79 | - || ! Sensei()->settings->settings['messages_disable'] ) ; |
|
| 80 | - |
|
| 81 | - if( empty( $this->messages_query ) || $messages_disabled_in_settings ){ |
|
| 82 | - |
|
| 83 | - return ''; |
|
| 84 | - |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - //set the wp_query to the current messages query |
|
| 88 | - global $wp_query; |
|
| 89 | - $wp_query = $this->messages_query; |
|
| 90 | - |
|
| 91 | - ob_start(); |
|
| 92 | - Sensei_Templates::get_part('loop', 'message'); |
|
| 93 | - $messages_html = ob_get_clean(); |
|
| 94 | - |
|
| 95 | - // set back the global query |
|
| 96 | - wp_reset_query(); |
|
| 97 | - |
|
| 98 | - return $messages_html; |
|
| 99 | - |
|
| 100 | - }// end render |
|
| 18 | + /** |
|
| 19 | + * @var array $messages{ |
|
| 20 | + * @type WP_Post |
|
| 21 | + * } |
|
| 22 | + * messages for the current user |
|
| 23 | + */ |
|
| 24 | + protected $messages_query; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Setup the shortcode object |
|
| 28 | + * |
|
| 29 | + * @since 1.9.0 |
|
| 30 | + * @param array $attributes |
|
| 31 | + * @param string $content |
|
| 32 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 33 | + */ |
|
| 34 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 35 | + |
|
| 36 | + if( is_user_logged_in() ){ |
|
| 37 | + |
|
| 38 | + $this->setup_messages_query(); |
|
| 39 | + |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * create the messages query . |
|
| 46 | + * |
|
| 47 | + * @return mixed |
|
| 48 | + */ |
|
| 49 | + public function setup_messages_query(){ |
|
| 50 | + |
|
| 51 | + $user = wp_get_current_user(); |
|
| 52 | + |
|
| 53 | + $args = array( |
|
| 54 | + 'post_type' => 'sensei_message', |
|
| 55 | + 'posts_per_page' => 500, |
|
| 56 | + 'orderby' => 'date', |
|
| 57 | + 'order' => 'DESC', |
|
| 58 | + 'post_status' => 'publish', |
|
| 59 | + 'meta_query' => array( |
|
| 60 | + array( |
|
| 61 | + 'key' => '_sender', |
|
| 62 | + 'value' => $user->user_login, |
|
| 63 | + 'compare' => '=', |
|
| 64 | + ), |
|
| 65 | + ), |
|
| 66 | + ); |
|
| 67 | + |
|
| 68 | + $this->messages_query = new WP_Query( $args ); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Rendering the shortcode this class is responsible for. |
|
| 73 | + * |
|
| 74 | + * @return string $content |
|
| 75 | + */ |
|
| 76 | + public function render(){ |
|
| 77 | + |
|
| 78 | + $messages_disabled_in_settings = ! ( ! isset( Sensei()->settings->settings['messages_disable'] ) |
|
| 79 | + || ! Sensei()->settings->settings['messages_disable'] ) ; |
|
| 80 | + |
|
| 81 | + if( empty( $this->messages_query ) || $messages_disabled_in_settings ){ |
|
| 82 | + |
|
| 83 | + return ''; |
|
| 84 | + |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + //set the wp_query to the current messages query |
|
| 88 | + global $wp_query; |
|
| 89 | + $wp_query = $this->messages_query; |
|
| 90 | + |
|
| 91 | + ob_start(); |
|
| 92 | + Sensei_Templates::get_part('loop', 'message'); |
|
| 93 | + $messages_html = ob_get_clean(); |
|
| 94 | + |
|
| 95 | + // set back the global query |
|
| 96 | + wp_reset_query(); |
|
| 97 | + |
|
| 98 | + return $messages_html; |
|
| 99 | + |
|
| 100 | + }// end render |
|
| 101 | 101 | |
| 102 | 102 | }// end class |
| 103 | 103 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | /** |
| 4 | 4 | * |
| 5 | 5 | * Renders the [sensei_user_messages] shortcode. The current users messages. |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | * @param string $content |
| 32 | 32 | * @param string $shortcode the shortcode that was called for this instance |
| 33 | 33 | */ |
| 34 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 34 | + public function __construct($attributes, $content, $shortcode) { |
|
| 35 | 35 | |
| 36 | - if( is_user_logged_in() ){ |
|
| 36 | + if (is_user_logged_in()) { |
|
| 37 | 37 | |
| 38 | 38 | $this->setup_messages_query(); |
| 39 | 39 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return mixed |
| 48 | 48 | */ |
| 49 | - public function setup_messages_query(){ |
|
| 49 | + public function setup_messages_query() { |
|
| 50 | 50 | |
| 51 | 51 | $user = wp_get_current_user(); |
| 52 | 52 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | ), |
| 66 | 66 | ); |
| 67 | 67 | |
| 68 | - $this->messages_query = new WP_Query( $args ); |
|
| 68 | + $this->messages_query = new WP_Query($args); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -73,12 +73,12 @@ discard block |
||
| 73 | 73 | * |
| 74 | 74 | * @return string $content |
| 75 | 75 | */ |
| 76 | - public function render(){ |
|
| 76 | + public function render() { |
|
| 77 | 77 | |
| 78 | - $messages_disabled_in_settings = ! ( ! isset( Sensei()->settings->settings['messages_disable'] ) |
|
| 79 | - || ! Sensei()->settings->settings['messages_disable'] ) ; |
|
| 78 | + $messages_disabled_in_settings = ! ( ! isset(Sensei()->settings->settings['messages_disable']) |
|
| 79 | + || ! Sensei()->settings->settings['messages_disable']); |
|
| 80 | 80 | |
| 81 | - if( empty( $this->messages_query ) || $messages_disabled_in_settings ){ |
|
| 81 | + if (empty($this->messages_query) || $messages_disabled_in_settings) { |
|
| 82 | 82 | |
| 83 | 83 | return ''; |
| 84 | 84 | |
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Analysis User Profile List Table Class |
@@ -13,115 +13,115 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Sensei_Shortcode_Featured_Courses implements Sensei_Shortcode_Interface { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var WP_Query to help setup the query needed by the render method. |
|
| 18 | - */ |
|
| 19 | - protected $query; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var string number of items to show on the current page |
|
| 23 | - * Default: -1. |
|
| 24 | - */ |
|
| 25 | - protected $number; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var string ordery by course field |
|
| 29 | - * Default: date |
|
| 30 | - */ |
|
| 31 | - protected $orderby; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var string ASC or DESC |
|
| 35 | - * Default: 'DESC' |
|
| 36 | - */ |
|
| 37 | - protected $order; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var string teacher id to limit the courses to |
|
| 41 | - */ |
|
| 42 | - protected $teacher; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Setup the shortcode object |
|
| 46 | - * |
|
| 47 | - * @since 1.9.0 |
|
| 48 | - * @param array $attributes |
|
| 49 | - * @param string $content |
|
| 50 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 51 | - */ |
|
| 52 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 53 | - |
|
| 54 | - // set up all argument need for constructing the course query |
|
| 55 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 56 | - $this->teacher = isset( $attributes['teacher'] ) ? $attributes['teacher'] : ''; |
|
| 57 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'date'; |
|
| 58 | - |
|
| 59 | - // set the default for menu_order to be ASC |
|
| 60 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 61 | - |
|
| 62 | - $this->order = 'ASC'; |
|
| 63 | - |
|
| 64 | - }else{ |
|
| 65 | - |
|
| 66 | - // for everything else use the value passed or the default DESC |
|
| 67 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 68 | - |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // setup the course query that will be used when rendering |
|
| 72 | - $this->setup_course_query(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Sets up the object course query |
|
| 77 | - * that will be used int he render method. |
|
| 78 | - * |
|
| 79 | - * @since 1.9.0 |
|
| 80 | - */ |
|
| 81 | - protected function setup_course_query(){ |
|
| 82 | - |
|
| 83 | - //for non numeric teacher arguments value query by author_name and not author |
|
| 84 | - $teacher_query_by = is_numeric( $this->teacher )? 'author':'author_name'; |
|
| 85 | - |
|
| 86 | - $query_args = array( |
|
| 87 | - 'post_type' => 'course', |
|
| 88 | - 'post_status' => 'publish', |
|
| 89 | - 'orderby' => $this->orderby, |
|
| 90 | - 'order' => $this->order, |
|
| 91 | - 'posts_per_page' => $this->number, |
|
| 92 | - $teacher_query_by => $this->teacher, |
|
| 93 | - 'meta_value' => 'featured', |
|
| 94 | - 'meta_key' => '_course_featured', |
|
| 95 | - 'meta_compare' => '=', |
|
| 96 | - 'suppress_filters' => 0, |
|
| 97 | - ); |
|
| 98 | - |
|
| 99 | - $this->query = new WP_Query( $query_args ); |
|
| 100 | - |
|
| 101 | - }// end setup _course_query |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Rendering the shortcode this class is responsible for. |
|
| 105 | - */ |
|
| 106 | - public function render(){ |
|
| 107 | - |
|
| 108 | - global $wp_query; |
|
| 109 | - |
|
| 110 | - // keep a reference to old query |
|
| 111 | - $current_global_query = $wp_query; |
|
| 112 | - |
|
| 113 | - // assign the query setup in $this-> setup_course_query |
|
| 114 | - $wp_query = $this->query; |
|
| 115 | - |
|
| 116 | - ob_start(); |
|
| 117 | - Sensei_Templates::get_template('loop-course.php'); |
|
| 118 | - $shortcode_output = ob_get_clean(); |
|
| 119 | - |
|
| 120 | - //restore old query |
|
| 121 | - $wp_query = $current_global_query; |
|
| 122 | - |
|
| 123 | - return $shortcode_output; |
|
| 124 | - |
|
| 125 | - }// end render |
|
| 16 | + /** |
|
| 17 | + * @var WP_Query to help setup the query needed by the render method. |
|
| 18 | + */ |
|
| 19 | + protected $query; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var string number of items to show on the current page |
|
| 23 | + * Default: -1. |
|
| 24 | + */ |
|
| 25 | + protected $number; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var string ordery by course field |
|
| 29 | + * Default: date |
|
| 30 | + */ |
|
| 31 | + protected $orderby; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var string ASC or DESC |
|
| 35 | + * Default: 'DESC' |
|
| 36 | + */ |
|
| 37 | + protected $order; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var string teacher id to limit the courses to |
|
| 41 | + */ |
|
| 42 | + protected $teacher; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Setup the shortcode object |
|
| 46 | + * |
|
| 47 | + * @since 1.9.0 |
|
| 48 | + * @param array $attributes |
|
| 49 | + * @param string $content |
|
| 50 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 51 | + */ |
|
| 52 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 53 | + |
|
| 54 | + // set up all argument need for constructing the course query |
|
| 55 | + $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 56 | + $this->teacher = isset( $attributes['teacher'] ) ? $attributes['teacher'] : ''; |
|
| 57 | + $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'date'; |
|
| 58 | + |
|
| 59 | + // set the default for menu_order to be ASC |
|
| 60 | + if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 61 | + |
|
| 62 | + $this->order = 'ASC'; |
|
| 63 | + |
|
| 64 | + }else{ |
|
| 65 | + |
|
| 66 | + // for everything else use the value passed or the default DESC |
|
| 67 | + $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 68 | + |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // setup the course query that will be used when rendering |
|
| 72 | + $this->setup_course_query(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Sets up the object course query |
|
| 77 | + * that will be used int he render method. |
|
| 78 | + * |
|
| 79 | + * @since 1.9.0 |
|
| 80 | + */ |
|
| 81 | + protected function setup_course_query(){ |
|
| 82 | + |
|
| 83 | + //for non numeric teacher arguments value query by author_name and not author |
|
| 84 | + $teacher_query_by = is_numeric( $this->teacher )? 'author':'author_name'; |
|
| 85 | + |
|
| 86 | + $query_args = array( |
|
| 87 | + 'post_type' => 'course', |
|
| 88 | + 'post_status' => 'publish', |
|
| 89 | + 'orderby' => $this->orderby, |
|
| 90 | + 'order' => $this->order, |
|
| 91 | + 'posts_per_page' => $this->number, |
|
| 92 | + $teacher_query_by => $this->teacher, |
|
| 93 | + 'meta_value' => 'featured', |
|
| 94 | + 'meta_key' => '_course_featured', |
|
| 95 | + 'meta_compare' => '=', |
|
| 96 | + 'suppress_filters' => 0, |
|
| 97 | + ); |
|
| 98 | + |
|
| 99 | + $this->query = new WP_Query( $query_args ); |
|
| 100 | + |
|
| 101 | + }// end setup _course_query |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Rendering the shortcode this class is responsible for. |
|
| 105 | + */ |
|
| 106 | + public function render(){ |
|
| 107 | + |
|
| 108 | + global $wp_query; |
|
| 109 | + |
|
| 110 | + // keep a reference to old query |
|
| 111 | + $current_global_query = $wp_query; |
|
| 112 | + |
|
| 113 | + // assign the query setup in $this-> setup_course_query |
|
| 114 | + $wp_query = $this->query; |
|
| 115 | + |
|
| 116 | + ob_start(); |
|
| 117 | + Sensei_Templates::get_template('loop-course.php'); |
|
| 118 | + $shortcode_output = ob_get_clean(); |
|
| 119 | + |
|
| 120 | + //restore old query |
|
| 121 | + $wp_query = $current_global_query; |
|
| 122 | + |
|
| 123 | + return $shortcode_output; |
|
| 124 | + |
|
| 125 | + }// end render |
|
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | /** |
| 4 | 4 | * Sensei Feature Course rendering class |
| 5 | 5 | * |
@@ -49,22 +49,22 @@ discard block |
||
| 49 | 49 | * @param string $content |
| 50 | 50 | * @param string $shortcode the shortcode that was called for this instance |
| 51 | 51 | */ |
| 52 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 52 | + public function __construct($attributes, $content, $shortcode) { |
|
| 53 | 53 | |
| 54 | 54 | // set up all argument need for constructing the course query |
| 55 | - $this->number = isset( $attributes['number'] ) ? $attributes['number'] : '10'; |
|
| 56 | - $this->teacher = isset( $attributes['teacher'] ) ? $attributes['teacher'] : ''; |
|
| 57 | - $this->orderby = isset( $attributes['orderby'] ) ? $attributes['orderby'] : 'date'; |
|
| 55 | + $this->number = isset($attributes['number']) ? $attributes['number'] : '10'; |
|
| 56 | + $this->teacher = isset($attributes['teacher']) ? $attributes['teacher'] : ''; |
|
| 57 | + $this->orderby = isset($attributes['orderby']) ? $attributes['orderby'] : 'date'; |
|
| 58 | 58 | |
| 59 | 59 | // set the default for menu_order to be ASC |
| 60 | - if( 'menu_order' == $this->orderby && !isset( $attributes['order'] ) ){ |
|
| 60 | + if ('menu_order' == $this->orderby && ! isset($attributes['order'])) { |
|
| 61 | 61 | |
| 62 | - $this->order = 'ASC'; |
|
| 62 | + $this->order = 'ASC'; |
|
| 63 | 63 | |
| 64 | - }else{ |
|
| 64 | + } else { |
|
| 65 | 65 | |
| 66 | 66 | // for everything else use the value passed or the default DESC |
| 67 | - $this->order = isset( $attributes['order'] ) ? $attributes['order'] : 'DESC'; |
|
| 67 | + $this->order = isset($attributes['order']) ? $attributes['order'] : 'DESC'; |
|
| 68 | 68 | |
| 69 | 69 | } |
| 70 | 70 | |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @since 1.9.0 |
| 80 | 80 | */ |
| 81 | - protected function setup_course_query(){ |
|
| 81 | + protected function setup_course_query() { |
|
| 82 | 82 | |
| 83 | 83 | //for non numeric teacher arguments value query by author_name and not author |
| 84 | - $teacher_query_by = is_numeric( $this->teacher )? 'author':'author_name'; |
|
| 84 | + $teacher_query_by = is_numeric($this->teacher) ? 'author' : 'author_name'; |
|
| 85 | 85 | |
| 86 | 86 | $query_args = array( |
| 87 | 87 | 'post_type' => 'course', |
@@ -96,14 +96,14 @@ discard block |
||
| 96 | 96 | 'suppress_filters' => 0, |
| 97 | 97 | ); |
| 98 | 98 | |
| 99 | - $this->query = new WP_Query( $query_args ); |
|
| 99 | + $this->query = new WP_Query($query_args); |
|
| 100 | 100 | |
| 101 | 101 | }// end setup _course_query |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | 104 | * Rendering the shortcode this class is responsible for. |
| 105 | 105 | */ |
| 106 | - public function render(){ |
|
| 106 | + public function render() { |
|
| 107 | 107 | |
| 108 | 108 | global $wp_query; |
| 109 | 109 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | ob_start(); |
| 117 | 117 | Sensei_Templates::get_template('loop-course.php'); |
| 118 | - $shortcode_output = ob_get_clean(); |
|
| 118 | + $shortcode_output = ob_get_clean(); |
|
| 119 | 119 | |
| 120 | 120 | //restore old query |
| 121 | 121 | $wp_query = $current_global_query; |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Post Types Class |
@@ -146,7 +149,7 @@ discard block |
||
| 146 | 149 | |
| 147 | 150 | return get_page_uri( $settings_course_page->ID ); |
| 148 | 151 | |
| 149 | - }else{ |
|
| 152 | + } else{ |
|
| 150 | 153 | |
| 151 | 154 | return 'courses'; |
| 152 | 155 | |
@@ -12,19 +12,19 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | interface Sensei_Shortcode_Interface { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * All constructors must implement and accept $attributes and $content as arguments |
|
| 17 | - * |
|
| 18 | - * @param array $attributes |
|
| 19 | - * @param string $content |
|
| 20 | - * @param string $shortcode |
|
| 21 | - * @return mixed |
|
| 22 | - */ |
|
| 23 | - public function __construct($attributes, $content, $shortcode); |
|
| 15 | + /** |
|
| 16 | + * All constructors must implement and accept $attributes and $content as arguments |
|
| 17 | + * |
|
| 18 | + * @param array $attributes |
|
| 19 | + * @param string $content |
|
| 20 | + * @param string $shortcode |
|
| 21 | + * @return mixed |
|
| 22 | + */ |
|
| 23 | + public function __construct($attributes, $content, $shortcode); |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return string generated output |
|
| 27 | - */ |
|
| 28 | - public function render(); |
|
| 25 | + /** |
|
| 26 | + * @return string generated output |
|
| 27 | + */ |
|
| 28 | + public function render(); |
|
| 29 | 29 | |
| 30 | 30 | }// end interface |
| 31 | 31 | \ No newline at end of file |
@@ -14,97 +14,97 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Shortcode_Course_Page implements Sensei_Shortcode_Interface { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var array $course_page_query{ |
|
| 19 | - * @type WP_Post |
|
| 20 | - * } |
|
| 21 | - * The courses query |
|
| 22 | - */ |
|
| 23 | - protected $course_page_query; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Setup the shortcode object |
|
| 27 | - * |
|
| 28 | - * @since 1.9.0 |
|
| 29 | - * @param array $attributes |
|
| 30 | - * @param string $content |
|
| 31 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 32 | - */ |
|
| 33 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 34 | - |
|
| 35 | - $this->id = isset( $attributes['id'] ) ? $attributes['id'] : ''; |
|
| 36 | - $this->setup_course_query(); |
|
| 37 | - |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * create the courses query . |
|
| 42 | - * |
|
| 43 | - * @return mixed |
|
| 44 | - */ |
|
| 45 | - public function setup_course_query(){ |
|
| 46 | - |
|
| 47 | - if( empty( $this->id ) ){ |
|
| 48 | - return; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $args = array( |
|
| 52 | - 'post_type' => 'course', |
|
| 53 | - 'posts_per_page' => 1, |
|
| 54 | - 'post_status' => 'publish', |
|
| 55 | - 'post__in' => array( $this->id ), |
|
| 56 | - ); |
|
| 57 | - |
|
| 58 | - $this->course_page_query = new WP_Query( $args ); |
|
| 59 | - |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Rendering the shortcode this class is responsible for. |
|
| 64 | - * |
|
| 65 | - * @return string $content |
|
| 66 | - */ |
|
| 67 | - public function render(){ |
|
| 68 | - |
|
| 69 | - if( empty( $this->id ) ){ |
|
| 70 | - |
|
| 71 | - return sprintf( __( 'Please supply a course ID for the shortcode: %s', 'woothemes-sensei' ),'[sensei_course_page id=""]') ; |
|
| 72 | - |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - //set the wp_query to the current courses query |
|
| 76 | - global $wp_query, $post; |
|
| 77 | - |
|
| 78 | - // backups |
|
| 79 | - $global_post_ref = $post; |
|
| 80 | - $global_wp_query_ref = $wp_query; |
|
| 81 | - |
|
| 82 | - $post = get_post( $this->id ); |
|
| 83 | - $wp_query->post = get_post( $this->id ); // set this in case some the course hooks resets the query |
|
| 84 | - $wp_query = $this->course_page_query; |
|
| 85 | - |
|
| 86 | - ob_start(); |
|
| 87 | - self::the_single_course_content(); |
|
| 88 | - $shortcode_output = ob_get_clean(); |
|
| 89 | - |
|
| 90 | - // set back the global query and post |
|
| 91 | - // restore global backups |
|
| 92 | - $wp_query = $global_wp_query_ref; |
|
| 93 | - $post = $global_post_ref; |
|
| 94 | - $wp_query->post = $global_post_ref; |
|
| 95 | - wp_reset_query(); |
|
| 96 | - |
|
| 97 | - return $shortcode_output; |
|
| 98 | - |
|
| 99 | - }// end render |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Print out the single course content markup |
|
| 103 | - * |
|
| 104 | - * @since 1.9.0 |
|
| 105 | - */ |
|
| 106 | - public static function the_single_course_content(){ |
|
| 107 | - ?> |
|
| 17 | + /** |
|
| 18 | + * @var array $course_page_query{ |
|
| 19 | + * @type WP_Post |
|
| 20 | + * } |
|
| 21 | + * The courses query |
|
| 22 | + */ |
|
| 23 | + protected $course_page_query; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Setup the shortcode object |
|
| 27 | + * |
|
| 28 | + * @since 1.9.0 |
|
| 29 | + * @param array $attributes |
|
| 30 | + * @param string $content |
|
| 31 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 32 | + */ |
|
| 33 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 34 | + |
|
| 35 | + $this->id = isset( $attributes['id'] ) ? $attributes['id'] : ''; |
|
| 36 | + $this->setup_course_query(); |
|
| 37 | + |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * create the courses query . |
|
| 42 | + * |
|
| 43 | + * @return mixed |
|
| 44 | + */ |
|
| 45 | + public function setup_course_query(){ |
|
| 46 | + |
|
| 47 | + if( empty( $this->id ) ){ |
|
| 48 | + return; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $args = array( |
|
| 52 | + 'post_type' => 'course', |
|
| 53 | + 'posts_per_page' => 1, |
|
| 54 | + 'post_status' => 'publish', |
|
| 55 | + 'post__in' => array( $this->id ), |
|
| 56 | + ); |
|
| 57 | + |
|
| 58 | + $this->course_page_query = new WP_Query( $args ); |
|
| 59 | + |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Rendering the shortcode this class is responsible for. |
|
| 64 | + * |
|
| 65 | + * @return string $content |
|
| 66 | + */ |
|
| 67 | + public function render(){ |
|
| 68 | + |
|
| 69 | + if( empty( $this->id ) ){ |
|
| 70 | + |
|
| 71 | + return sprintf( __( 'Please supply a course ID for the shortcode: %s', 'woothemes-sensei' ),'[sensei_course_page id=""]') ; |
|
| 72 | + |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + //set the wp_query to the current courses query |
|
| 76 | + global $wp_query, $post; |
|
| 77 | + |
|
| 78 | + // backups |
|
| 79 | + $global_post_ref = $post; |
|
| 80 | + $global_wp_query_ref = $wp_query; |
|
| 81 | + |
|
| 82 | + $post = get_post( $this->id ); |
|
| 83 | + $wp_query->post = get_post( $this->id ); // set this in case some the course hooks resets the query |
|
| 84 | + $wp_query = $this->course_page_query; |
|
| 85 | + |
|
| 86 | + ob_start(); |
|
| 87 | + self::the_single_course_content(); |
|
| 88 | + $shortcode_output = ob_get_clean(); |
|
| 89 | + |
|
| 90 | + // set back the global query and post |
|
| 91 | + // restore global backups |
|
| 92 | + $wp_query = $global_wp_query_ref; |
|
| 93 | + $post = $global_post_ref; |
|
| 94 | + $wp_query->post = $global_post_ref; |
|
| 95 | + wp_reset_query(); |
|
| 96 | + |
|
| 97 | + return $shortcode_output; |
|
| 98 | + |
|
| 99 | + }// end render |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Print out the single course content markup |
|
| 103 | + * |
|
| 104 | + * @since 1.9.0 |
|
| 105 | + */ |
|
| 106 | + public static function the_single_course_content(){ |
|
| 107 | + ?> |
|
| 108 | 108 | |
| 109 | 109 | <article <?php post_class( array( 'course', 'post' ) ); ?> > |
| 110 | 110 | |
@@ -122,6 +122,6 @@ discard block |
||
| 122 | 122 | </article> |
| 123 | 123 | |
| 124 | 124 | <?php |
| 125 | - }// end the_single_course_content |
|
| 125 | + }// end the_single_course_content |
|
| 126 | 126 | |
| 127 | 127 | }// end class |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | /** |
| 4 | 4 | * |
| 5 | 5 | * Renders the [sensei_course_page] shortcode. Display a single course based on the ID parameter given |
@@ -30,9 +30,9 @@ discard block |
||
| 30 | 30 | * @param string $content |
| 31 | 31 | * @param string $shortcode the shortcode that was called for this instance |
| 32 | 32 | */ |
| 33 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 33 | + public function __construct($attributes, $content, $shortcode) { |
|
| 34 | 34 | |
| 35 | - $this->id = isset( $attributes['id'] ) ? $attributes['id'] : ''; |
|
| 35 | + $this->id = isset($attributes['id']) ? $attributes['id'] : ''; |
|
| 36 | 36 | $this->setup_course_query(); |
| 37 | 37 | |
| 38 | 38 | } |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return mixed |
| 44 | 44 | */ |
| 45 | - public function setup_course_query(){ |
|
| 45 | + public function setup_course_query() { |
|
| 46 | 46 | |
| 47 | - if( empty( $this->id ) ){ |
|
| 47 | + if (empty($this->id)) { |
|
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | 'post_type' => 'course', |
| 53 | 53 | 'posts_per_page' => 1, |
| 54 | 54 | 'post_status' => 'publish', |
| 55 | - 'post__in' => array( $this->id ), |
|
| 55 | + 'post__in' => array($this->id), |
|
| 56 | 56 | ); |
| 57 | 57 | |
| 58 | - $this->course_page_query = new WP_Query( $args ); |
|
| 58 | + $this->course_page_query = new WP_Query($args); |
|
| 59 | 59 | |
| 60 | 60 | } |
| 61 | 61 | |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @return string $content |
| 66 | 66 | */ |
| 67 | - public function render(){ |
|
| 67 | + public function render() { |
|
| 68 | 68 | |
| 69 | - if( empty( $this->id ) ){ |
|
| 69 | + if (empty($this->id)) { |
|
| 70 | 70 | |
| 71 | - return sprintf( __( 'Please supply a course ID for the shortcode: %s', 'woothemes-sensei' ),'[sensei_course_page id=""]') ; |
|
| 71 | + return sprintf(__('Please supply a course ID for the shortcode: %s', 'woothemes-sensei'), '[sensei_course_page id=""]'); |
|
| 72 | 72 | |
| 73 | 73 | } |
| 74 | 74 | |
@@ -79,8 +79,8 @@ discard block |
||
| 79 | 79 | $global_post_ref = $post; |
| 80 | 80 | $global_wp_query_ref = $wp_query; |
| 81 | 81 | |
| 82 | - $post = get_post( $this->id ); |
|
| 83 | - $wp_query->post = get_post( $this->id ); // set this in case some the course hooks resets the query |
|
| 82 | + $post = get_post($this->id); |
|
| 83 | + $wp_query->post = get_post($this->id); // set this in case some the course hooks resets the query |
|
| 84 | 84 | $wp_query = $this->course_page_query; |
| 85 | 85 | |
| 86 | 86 | ob_start(); |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @since 1.9.0 |
| 105 | 105 | */ |
| 106 | - public static function the_single_course_content(){ |
|
| 106 | + public static function the_single_course_content() { |
|
| 107 | 107 | ?> |
| 108 | 108 | |
| 109 | - <article <?php post_class( array( 'course', 'post' ) ); ?> > |
|
| 109 | + <article <?php post_class(array('course', 'post')); ?> > |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - <?php do_action( 'sensei_single_course_content_inside_before' ); ?> |
|
| 112 | + <?php do_action('sensei_single_course_content_inside_before'); ?> |
|
| 113 | 113 | |
| 114 | 114 | <section class="entry fix"> |
| 115 | 115 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | </section> |
| 119 | 119 | |
| 120 | - <?php do_action( 'sensei_single_course_content_inside_after' ); ?> |
|
| 120 | + <?php do_action('sensei_single_course_content_inside_after'); ?> |
|
| 121 | 121 | |
| 122 | 122 | </article> |
| 123 | 123 | |
@@ -1,5 +1,8 @@ |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Analysis User Profile List Table Class |
@@ -17,270 +17,270 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class Sensei_Shortcode_Teachers implements Sensei_Shortcode_Interface { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var WP_User_Query keeps a reference to the user query created |
|
| 22 | - */ |
|
| 23 | - protected $user_query; |
|
| 20 | + /** |
|
| 21 | + * @var WP_User_Query keeps a reference to the user query created |
|
| 22 | + */ |
|
| 23 | + protected $user_query; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var which user id's to include |
|
| 27 | - */ |
|
| 28 | - protected $include; |
|
| 25 | + /** |
|
| 26 | + * @var which user id's to include |
|
| 27 | + */ |
|
| 28 | + protected $include; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var which user id's to exclude |
|
| 32 | - */ |
|
| 33 | - protected $exclude; |
|
| 30 | + /** |
|
| 31 | + * @var which user id's to exclude |
|
| 32 | + */ |
|
| 33 | + protected $exclude; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Setup the shortcode object |
|
| 37 | - * |
|
| 38 | - * @since 1.9.0 |
|
| 39 | - * @param array $attributes |
|
| 40 | - * @param string $content |
|
| 41 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 42 | - */ |
|
| 43 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 35 | + /** |
|
| 36 | + * Setup the shortcode object |
|
| 37 | + * |
|
| 38 | + * @since 1.9.0 |
|
| 39 | + * @param array $attributes |
|
| 40 | + * @param string $content |
|
| 41 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 42 | + */ |
|
| 43 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 44 | 44 | |
| 45 | - $include = isset( $attributes['include'] ) ? explode( ',', $attributes['include'] ) : ''; |
|
| 46 | - $exclude = isset( $attributes['exclude'] ) ? explode( ',', $attributes['exclude'] ) : ''; |
|
| 45 | + $include = isset( $attributes['include'] ) ? explode( ',', $attributes['include'] ) : ''; |
|
| 46 | + $exclude = isset( $attributes['exclude'] ) ? explode( ',', $attributes['exclude'] ) : ''; |
|
| 47 | 47 | |
| 48 | - // convert teacher usernames given to the id |
|
| 49 | - $this->include = $this->convert_usernames_to_ids( $include ); |
|
| 50 | - $this->exclude = $this->convert_usernames_to_ids( $exclude ); |
|
| 48 | + // convert teacher usernames given to the id |
|
| 49 | + $this->include = $this->convert_usernames_to_ids( $include ); |
|
| 50 | + $this->exclude = $this->convert_usernames_to_ids( $exclude ); |
|
| 51 | 51 | |
| 52 | - $this->setup_teacher_query(); |
|
| 52 | + $this->setup_teacher_query(); |
|
| 53 | 53 | |
| 54 | - } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * |
|
| 58 | - * Setup the user query that will be used in the render method |
|
| 59 | - * |
|
| 60 | - * @since 1.9.0 |
|
| 61 | - */ |
|
| 62 | - protected function setup_teacher_query(){ |
|
| 56 | + /** |
|
| 57 | + * |
|
| 58 | + * Setup the user query that will be used in the render method |
|
| 59 | + * |
|
| 60 | + * @since 1.9.0 |
|
| 61 | + */ |
|
| 62 | + protected function setup_teacher_query(){ |
|
| 63 | 63 | |
| 64 | - $user_query_args = array( |
|
| 65 | - 'role' => 'teacher', |
|
| 66 | - ); |
|
| 64 | + $user_query_args = array( |
|
| 65 | + 'role' => 'teacher', |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - $this->user_query = new WP_User_Query( $user_query_args ); |
|
| 68 | + $this->user_query = new WP_User_Query( $user_query_args ); |
|
| 69 | 69 | |
| 70 | - }// end setup _course_query |
|
| 70 | + }// end setup _course_query |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Rendering the shortcode this class is responsible for. |
|
| 74 | - * |
|
| 75 | - * @return string $content |
|
| 76 | - */ |
|
| 77 | - public function render(){ |
|
| 72 | + /** |
|
| 73 | + * Rendering the shortcode this class is responsible for. |
|
| 74 | + * |
|
| 75 | + * @return string $content |
|
| 76 | + */ |
|
| 77 | + public function render(){ |
|
| 78 | 78 | |
| 79 | - $all_users = $this->user_query->get_results(); |
|
| 80 | - // if the user has specified more users add them as well. |
|
| 81 | - if( ! empty( $this->include ) ){ |
|
| 79 | + $all_users = $this->user_query->get_results(); |
|
| 80 | + // if the user has specified more users add them as well. |
|
| 81 | + if( ! empty( $this->include ) ){ |
|
| 82 | 82 | |
| 83 | - $included_users_query = new WP_User_Query( array( 'include' => $this->include ) ); |
|
| 84 | - $included_users = $included_users_query->get_results(); |
|
| 85 | - if( ! empty( $included_users ) ){ |
|
| 83 | + $included_users_query = new WP_User_Query( array( 'include' => $this->include ) ); |
|
| 84 | + $included_users = $included_users_query->get_results(); |
|
| 85 | + if( ! empty( $included_users ) ){ |
|
| 86 | 86 | |
| 87 | - $merged_users = array_merge( $all_users, $included_users ); |
|
| 88 | - $all_users = $this->users_unique( $merged_users ); |
|
| 89 | - $all_users = $this->users_sort( $all_users ); |
|
| 87 | + $merged_users = array_merge( $all_users, $included_users ); |
|
| 88 | + $all_users = $this->users_unique( $merged_users ); |
|
| 89 | + $all_users = $this->users_sort( $all_users ); |
|
| 90 | 90 | |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - } |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - // exclude the users not wanted |
|
| 96 | - if( ! empty( $this->exclude ) ){ |
|
| 95 | + // exclude the users not wanted |
|
| 96 | + if( ! empty( $this->exclude ) ){ |
|
| 97 | 97 | |
| 98 | - $all_users = $this->exclude_users( $all_users, $this->exclude ); |
|
| 98 | + $all_users = $this->exclude_users( $all_users, $this->exclude ); |
|
| 99 | 99 | |
| 100 | - } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - if( ! count( $all_users )> 0 ){ |
|
| 103 | - return ''; |
|
| 104 | - } |
|
| 102 | + if( ! count( $all_users )> 0 ){ |
|
| 103 | + return ''; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | - $users_output = ''; |
|
| 107 | + $users_output = ''; |
|
| 108 | 108 | |
| 109 | - foreach ( $all_users as $user ) { |
|
| 109 | + foreach ( $all_users as $user ) { |
|
| 110 | 110 | |
| 111 | - $user_display_name = $this->get_user_public_name( $user ); |
|
| 111 | + $user_display_name = $this->get_user_public_name( $user ); |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Sensei teachers shortcode list item filter |
|
| 115 | - * |
|
| 116 | - * @since 1.9.0 |
|
| 117 | - * |
|
| 118 | - * @param string $teacher_li the html for the teacher li |
|
| 119 | - * @param WP_User $user |
|
| 120 | - */ |
|
| 121 | - $users_output .= apply_filters( 'sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'. get_author_posts_url( $user->ID ) . '">'. $user_display_name . '<a/></li>', $user ); |
|
| 113 | + /** |
|
| 114 | + * Sensei teachers shortcode list item filter |
|
| 115 | + * |
|
| 116 | + * @since 1.9.0 |
|
| 117 | + * |
|
| 118 | + * @param string $teacher_li the html for the teacher li |
|
| 119 | + * @param WP_User $user |
|
| 120 | + */ |
|
| 121 | + $users_output .= apply_filters( 'sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'. get_author_posts_url( $user->ID ) . '">'. $user_display_name . '<a/></li>', $user ); |
|
| 122 | 122 | |
| 123 | - } |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - return '<ul class="sensei-teachers">' . $users_output . '</ul>'; |
|
| 125 | + return '<ul class="sensei-teachers">' . $users_output . '</ul>'; |
|
| 126 | 126 | |
| 127 | - }// end render |
|
| 127 | + }// end render |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * remove duplicate user objects from and array of users |
|
| 131 | - * |
|
| 132 | - * @since 1.9.0 |
|
| 133 | - * |
|
| 134 | - * @param array $users{ |
|
| 135 | - * @type WP_User |
|
| 136 | - * } |
|
| 137 | - * |
|
| 138 | - * @return array $unique_users { |
|
| 139 | - * @type WP_User |
|
| 140 | - * } |
|
| 141 | - */ |
|
| 142 | - public function users_unique( $users ){ |
|
| 129 | + /** |
|
| 130 | + * remove duplicate user objects from and array of users |
|
| 131 | + * |
|
| 132 | + * @since 1.9.0 |
|
| 133 | + * |
|
| 134 | + * @param array $users{ |
|
| 135 | + * @type WP_User |
|
| 136 | + * } |
|
| 137 | + * |
|
| 138 | + * @return array $unique_users { |
|
| 139 | + * @type WP_User |
|
| 140 | + * } |
|
| 141 | + */ |
|
| 142 | + public function users_unique( $users ){ |
|
| 143 | 143 | |
| 144 | - $array_unique_users_ids = array(); |
|
| 145 | - foreach( $users as $index => $user ){ |
|
| 144 | + $array_unique_users_ids = array(); |
|
| 145 | + foreach( $users as $index => $user ){ |
|
| 146 | 146 | |
| 147 | - if( in_array( $user->ID, $array_unique_users_ids) ){ |
|
| 147 | + if( in_array( $user->ID, $array_unique_users_ids) ){ |
|
| 148 | 148 | |
| 149 | - // exclude this user as it is already in the list |
|
| 150 | - unset( $users[ $index ] ); |
|
| 149 | + // exclude this user as it is already in the list |
|
| 150 | + unset( $users[ $index ] ); |
|
| 151 | 151 | |
| 152 | - }else{ |
|
| 152 | + }else{ |
|
| 153 | 153 | |
| 154 | - // add teh user to the list of users |
|
| 155 | - $array_unique_users_ids[] = $user->ID; |
|
| 154 | + // add teh user to the list of users |
|
| 155 | + $array_unique_users_ids[] = $user->ID; |
|
| 156 | 156 | |
| 157 | - } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - return $users; |
|
| 161 | + return $users; |
|
| 162 | 162 | |
| 163 | - }// end users_unique |
|
| 163 | + }// end users_unique |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Exclude users based ont he ids given. |
|
| 167 | - * |
|
| 168 | - * @since 1.9.0 |
|
| 169 | - * |
|
| 170 | - * @param array $users |
|
| 171 | - * @param array $exclude_ids |
|
| 172 | - * @return array |
|
| 173 | - */ |
|
| 174 | - public function exclude_users( $users, $exclude_ids ){ |
|
| 165 | + /** |
|
| 166 | + * Exclude users based ont he ids given. |
|
| 167 | + * |
|
| 168 | + * @since 1.9.0 |
|
| 169 | + * |
|
| 170 | + * @param array $users |
|
| 171 | + * @param array $exclude_ids |
|
| 172 | + * @return array |
|
| 173 | + */ |
|
| 174 | + public function exclude_users( $users, $exclude_ids ){ |
|
| 175 | 175 | |
| 176 | - foreach( $users as $index => $user ){ |
|
| 176 | + foreach( $users as $index => $user ){ |
|
| 177 | 177 | |
| 178 | - if( in_array( $user->ID, $exclude_ids ) ){ |
|
| 178 | + if( in_array( $user->ID, $exclude_ids ) ){ |
|
| 179 | 179 | |
| 180 | - // remove the user from the list |
|
| 181 | - unset( $users[ $index ] ); |
|
| 180 | + // remove the user from the list |
|
| 181 | + unset( $users[ $index ] ); |
|
| 182 | 182 | |
| 183 | - } |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - } |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - return $users; |
|
| 187 | + return $users; |
|
| 188 | 188 | |
| 189 | - }// end exclude_users |
|
| 189 | + }// end exclude_users |
|
| 190 | 190 | |
| 191 | - /** |
|
| 192 | - * Convert mixed array of user id and user names to only be an array of user_ids |
|
| 193 | - * |
|
| 194 | - * @param array $users |
|
| 195 | - * @return array $users_ids |
|
| 196 | - */ |
|
| 197 | - public function convert_usernames_to_ids( $users ){ |
|
| 191 | + /** |
|
| 192 | + * Convert mixed array of user id and user names to only be an array of user_ids |
|
| 193 | + * |
|
| 194 | + * @param array $users |
|
| 195 | + * @return array $users_ids |
|
| 196 | + */ |
|
| 197 | + public function convert_usernames_to_ids( $users ){ |
|
| 198 | 198 | |
| 199 | - // backup |
|
| 200 | - $users_ids = array(); |
|
| 199 | + // backup |
|
| 200 | + $users_ids = array(); |
|
| 201 | 201 | |
| 202 | - if ( is_array($users) ) { |
|
| 202 | + if ( is_array($users) ) { |
|
| 203 | 203 | |
| 204 | - foreach ($users as $user_id_or_username) { |
|
| 204 | + foreach ($users as $user_id_or_username) { |
|
| 205 | 205 | |
| 206 | - if (!is_numeric($user_id_or_username)) { |
|
| 206 | + if (!is_numeric($user_id_or_username)) { |
|
| 207 | 207 | |
| 208 | - $user_name = $user_id_or_username; |
|
| 209 | - $user = get_user_by('login', $user_name); |
|
| 208 | + $user_name = $user_id_or_username; |
|
| 209 | + $user = get_user_by('login', $user_name); |
|
| 210 | 210 | |
| 211 | - if (is_a($user, 'WP_User')) { |
|
| 212 | - $users_ids[] = $user->ID; |
|
| 213 | - } |
|
| 211 | + if (is_a($user, 'WP_User')) { |
|
| 212 | + $users_ids[] = $user->ID; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - } else { |
|
| 215 | + } else { |
|
| 216 | 216 | |
| 217 | - $user_id = $user_id_or_username; |
|
| 218 | - $users_ids[] = $user_id; |
|
| 217 | + $user_id = $user_id_or_username; |
|
| 218 | + $users_ids[] = $user_id; |
|
| 219 | 219 | |
| 220 | - } |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - } |
|
| 223 | - } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - return $users_ids; |
|
| 226 | - } |
|
| 225 | + return $users_ids; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * Returns the first name and last name or the display name of a user. |
|
| 230 | - * |
|
| 231 | - * @since 1.9.0 |
|
| 232 | - * |
|
| 233 | - * @param $user |
|
| 234 | - * @return string $user_public_name |
|
| 235 | - */ |
|
| 236 | - public function get_user_public_name( $user ){ |
|
| 228 | + /** |
|
| 229 | + * Returns the first name and last name or the display name of a user. |
|
| 230 | + * |
|
| 231 | + * @since 1.9.0 |
|
| 232 | + * |
|
| 233 | + * @param $user |
|
| 234 | + * @return string $user_public_name |
|
| 235 | + */ |
|
| 236 | + public function get_user_public_name( $user ){ |
|
| 237 | 237 | |
| 238 | - if (!empty($user->first_name) && !empty($user->last_name)) { |
|
| 238 | + if (!empty($user->first_name) && !empty($user->last_name)) { |
|
| 239 | 239 | |
| 240 | - $user_public_name = $user->first_name . ' ' . $user->last_name; |
|
| 240 | + $user_public_name = $user->first_name . ' ' . $user->last_name; |
|
| 241 | 241 | |
| 242 | - } |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - else { |
|
| 244 | + else { |
|
| 245 | 245 | |
| 246 | - $user_public_name = $user->display_name; |
|
| 246 | + $user_public_name = $user->display_name; |
|
| 247 | 247 | |
| 248 | - } |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return $user_public_name; |
|
| 251 | - } |
|
| 250 | + return $user_public_name; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * |
|
| 255 | - * Sort user objects by user display |
|
| 256 | - * |
|
| 257 | - * @since 1.9.0 |
|
| 258 | - * |
|
| 259 | - * @param $users |
|
| 260 | - * @return array $sorted_users |
|
| 261 | - */ |
|
| 262 | - public function users_sort( $users ){ |
|
| 253 | + /** |
|
| 254 | + * |
|
| 255 | + * Sort user objects by user display |
|
| 256 | + * |
|
| 257 | + * @since 1.9.0 |
|
| 258 | + * |
|
| 259 | + * @param $users |
|
| 260 | + * @return array $sorted_users |
|
| 261 | + */ |
|
| 262 | + public function users_sort( $users ){ |
|
| 263 | 263 | |
| 264 | - $sorted_users = $users; |
|
| 264 | + $sorted_users = $users; |
|
| 265 | 265 | |
| 266 | - uasort( $sorted_users, array( $this, 'custom_user_sort' ) ); |
|
| 266 | + uasort( $sorted_users, array( $this, 'custom_user_sort' ) ); |
|
| 267 | 267 | |
| 268 | - return $sorted_users; |
|
| 269 | - } |
|
| 268 | + return $sorted_users; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Used in the uasort function to sort users by title |
|
| 273 | - * |
|
| 274 | - * @since 1.9.0 |
|
| 275 | - * |
|
| 276 | - * @param $user_1 |
|
| 277 | - * @param $user_2 |
|
| 278 | - * @return int |
|
| 279 | - */ |
|
| 280 | - public function custom_user_sort($user_1, $user_2){ |
|
| 271 | + /** |
|
| 272 | + * Used in the uasort function to sort users by title |
|
| 273 | + * |
|
| 274 | + * @since 1.9.0 |
|
| 275 | + * |
|
| 276 | + * @param $user_1 |
|
| 277 | + * @param $user_2 |
|
| 278 | + * @return int |
|
| 279 | + */ |
|
| 280 | + public function custom_user_sort($user_1, $user_2){ |
|
| 281 | 281 | |
| 282 | - return strcasecmp( $this->get_user_public_name( $user_1 ), $this->get_user_public_name( $user_2 ) ); |
|
| 282 | + return strcasecmp( $this->get_user_public_name( $user_1 ), $this->get_user_public_name( $user_2 ) ); |
|
| 283 | 283 | |
| 284 | - }// end custom_user_sort |
|
| 284 | + }// end custom_user_sort |
|
| 285 | 285 | |
| 286 | 286 | }// end class |
| 287 | 287 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | /** |
| 4 | 4 | * |
| 5 | 5 | * Renders the [sensei_teachers] shortcode. Will show a list of teachers |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | * @param string $content |
| 41 | 41 | * @param string $shortcode the shortcode that was called for this instance |
| 42 | 42 | */ |
| 43 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 43 | + public function __construct($attributes, $content, $shortcode) { |
|
| 44 | 44 | |
| 45 | - $include = isset( $attributes['include'] ) ? explode( ',', $attributes['include'] ) : ''; |
|
| 46 | - $exclude = isset( $attributes['exclude'] ) ? explode( ',', $attributes['exclude'] ) : ''; |
|
| 45 | + $include = isset($attributes['include']) ? explode(',', $attributes['include']) : ''; |
|
| 46 | + $exclude = isset($attributes['exclude']) ? explode(',', $attributes['exclude']) : ''; |
|
| 47 | 47 | |
| 48 | 48 | // convert teacher usernames given to the id |
| 49 | - $this->include = $this->convert_usernames_to_ids( $include ); |
|
| 50 | - $this->exclude = $this->convert_usernames_to_ids( $exclude ); |
|
| 49 | + $this->include = $this->convert_usernames_to_ids($include); |
|
| 50 | + $this->exclude = $this->convert_usernames_to_ids($exclude); |
|
| 51 | 51 | |
| 52 | 52 | $this->setup_teacher_query(); |
| 53 | 53 | |
@@ -59,13 +59,13 @@ discard block |
||
| 59 | 59 | * |
| 60 | 60 | * @since 1.9.0 |
| 61 | 61 | */ |
| 62 | - protected function setup_teacher_query(){ |
|
| 62 | + protected function setup_teacher_query() { |
|
| 63 | 63 | |
| 64 | 64 | $user_query_args = array( |
| 65 | 65 | 'role' => 'teacher', |
| 66 | 66 | ); |
| 67 | 67 | |
| 68 | - $this->user_query = new WP_User_Query( $user_query_args ); |
|
| 68 | + $this->user_query = new WP_User_Query($user_query_args); |
|
| 69 | 69 | |
| 70 | 70 | }// end setup _course_query |
| 71 | 71 | |
@@ -74,41 +74,41 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return string $content |
| 76 | 76 | */ |
| 77 | - public function render(){ |
|
| 77 | + public function render() { |
|
| 78 | 78 | |
| 79 | 79 | $all_users = $this->user_query->get_results(); |
| 80 | 80 | // if the user has specified more users add them as well. |
| 81 | - if( ! empty( $this->include ) ){ |
|
| 81 | + if ( ! empty($this->include)) { |
|
| 82 | 82 | |
| 83 | - $included_users_query = new WP_User_Query( array( 'include' => $this->include ) ); |
|
| 83 | + $included_users_query = new WP_User_Query(array('include' => $this->include)); |
|
| 84 | 84 | $included_users = $included_users_query->get_results(); |
| 85 | - if( ! empty( $included_users ) ){ |
|
| 85 | + if ( ! empty($included_users)) { |
|
| 86 | 86 | |
| 87 | - $merged_users = array_merge( $all_users, $included_users ); |
|
| 88 | - $all_users = $this->users_unique( $merged_users ); |
|
| 89 | - $all_users = $this->users_sort( $all_users ); |
|
| 87 | + $merged_users = array_merge($all_users, $included_users); |
|
| 88 | + $all_users = $this->users_unique($merged_users); |
|
| 89 | + $all_users = $this->users_sort($all_users); |
|
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | // exclude the users not wanted |
| 96 | - if( ! empty( $this->exclude ) ){ |
|
| 96 | + if ( ! empty($this->exclude)) { |
|
| 97 | 97 | |
| 98 | - $all_users = $this->exclude_users( $all_users, $this->exclude ); |
|
| 98 | + $all_users = $this->exclude_users($all_users, $this->exclude); |
|
| 99 | 99 | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if( ! count( $all_users )> 0 ){ |
|
| 102 | + if ( ! count($all_users) > 0) { |
|
| 103 | 103 | return ''; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | $users_output = ''; |
| 108 | 108 | |
| 109 | - foreach ( $all_users as $user ) { |
|
| 109 | + foreach ($all_users as $user) { |
|
| 110 | 110 | |
| 111 | - $user_display_name = $this->get_user_public_name( $user ); |
|
| 111 | + $user_display_name = $this->get_user_public_name($user); |
|
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Sensei teachers shortcode list item filter |
@@ -118,11 +118,11 @@ discard block |
||
| 118 | 118 | * @param string $teacher_li the html for the teacher li |
| 119 | 119 | * @param WP_User $user |
| 120 | 120 | */ |
| 121 | - $users_output .= apply_filters( 'sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'. get_author_posts_url( $user->ID ) . '">'. $user_display_name . '<a/></li>', $user ); |
|
| 121 | + $users_output .= apply_filters('sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="'.get_author_posts_url($user->ID).'">'.$user_display_name.'<a/></li>', $user); |
|
| 122 | 122 | |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return '<ul class="sensei-teachers">' . $users_output . '</ul>'; |
|
| 125 | + return '<ul class="sensei-teachers">'.$users_output.'</ul>'; |
|
| 126 | 126 | |
| 127 | 127 | }// end render |
| 128 | 128 | |
@@ -139,17 +139,17 @@ discard block |
||
| 139 | 139 | * @type WP_User |
| 140 | 140 | * } |
| 141 | 141 | */ |
| 142 | - public function users_unique( $users ){ |
|
| 142 | + public function users_unique($users) { |
|
| 143 | 143 | |
| 144 | 144 | $array_unique_users_ids = array(); |
| 145 | - foreach( $users as $index => $user ){ |
|
| 145 | + foreach ($users as $index => $user) { |
|
| 146 | 146 | |
| 147 | - if( in_array( $user->ID, $array_unique_users_ids) ){ |
|
| 147 | + if (in_array($user->ID, $array_unique_users_ids)) { |
|
| 148 | 148 | |
| 149 | 149 | // exclude this user as it is already in the list |
| 150 | - unset( $users[ $index ] ); |
|
| 150 | + unset($users[$index]); |
|
| 151 | 151 | |
| 152 | - }else{ |
|
| 152 | + } else { |
|
| 153 | 153 | |
| 154 | 154 | // add teh user to the list of users |
| 155 | 155 | $array_unique_users_ids[] = $user->ID; |
@@ -171,14 +171,14 @@ discard block |
||
| 171 | 171 | * @param array $exclude_ids |
| 172 | 172 | * @return array |
| 173 | 173 | */ |
| 174 | - public function exclude_users( $users, $exclude_ids ){ |
|
| 174 | + public function exclude_users($users, $exclude_ids) { |
|
| 175 | 175 | |
| 176 | - foreach( $users as $index => $user ){ |
|
| 176 | + foreach ($users as $index => $user) { |
|
| 177 | 177 | |
| 178 | - if( in_array( $user->ID, $exclude_ids ) ){ |
|
| 178 | + if (in_array($user->ID, $exclude_ids)) { |
|
| 179 | 179 | |
| 180 | 180 | // remove the user from the list |
| 181 | - unset( $users[ $index ] ); |
|
| 181 | + unset($users[$index]); |
|
| 182 | 182 | |
| 183 | 183 | } |
| 184 | 184 | |
@@ -194,16 +194,16 @@ discard block |
||
| 194 | 194 | * @param array $users |
| 195 | 195 | * @return array $users_ids |
| 196 | 196 | */ |
| 197 | - public function convert_usernames_to_ids( $users ){ |
|
| 197 | + public function convert_usernames_to_ids($users) { |
|
| 198 | 198 | |
| 199 | 199 | // backup |
| 200 | 200 | $users_ids = array(); |
| 201 | 201 | |
| 202 | - if ( is_array($users) ) { |
|
| 202 | + if (is_array($users)) { |
|
| 203 | 203 | |
| 204 | 204 | foreach ($users as $user_id_or_username) { |
| 205 | 205 | |
| 206 | - if (!is_numeric($user_id_or_username)) { |
|
| 206 | + if ( ! is_numeric($user_id_or_username)) { |
|
| 207 | 207 | |
| 208 | 208 | $user_name = $user_id_or_username; |
| 209 | 209 | $user = get_user_by('login', $user_name); |
@@ -233,11 +233,11 @@ discard block |
||
| 233 | 233 | * @param $user |
| 234 | 234 | * @return string $user_public_name |
| 235 | 235 | */ |
| 236 | - public function get_user_public_name( $user ){ |
|
| 236 | + public function get_user_public_name($user) { |
|
| 237 | 237 | |
| 238 | - if (!empty($user->first_name) && !empty($user->last_name)) { |
|
| 238 | + if ( ! empty($user->first_name) && ! empty($user->last_name)) { |
|
| 239 | 239 | |
| 240 | - $user_public_name = $user->first_name . ' ' . $user->last_name; |
|
| 240 | + $user_public_name = $user->first_name.' '.$user->last_name; |
|
| 241 | 241 | |
| 242 | 242 | } |
| 243 | 243 | |
@@ -259,11 +259,11 @@ discard block |
||
| 259 | 259 | * @param $users |
| 260 | 260 | * @return array $sorted_users |
| 261 | 261 | */ |
| 262 | - public function users_sort( $users ){ |
|
| 262 | + public function users_sort($users) { |
|
| 263 | 263 | |
| 264 | 264 | $sorted_users = $users; |
| 265 | 265 | |
| 266 | - uasort( $sorted_users, array( $this, 'custom_user_sort' ) ); |
|
| 266 | + uasort($sorted_users, array($this, 'custom_user_sort')); |
|
| 267 | 267 | |
| 268 | 268 | return $sorted_users; |
| 269 | 269 | } |
@@ -277,9 +277,9 @@ discard block |
||
| 277 | 277 | * @param $user_2 |
| 278 | 278 | * @return int |
| 279 | 279 | */ |
| 280 | - public function custom_user_sort($user_1, $user_2){ |
|
| 280 | + public function custom_user_sort($user_1, $user_2) { |
|
| 281 | 281 | |
| 282 | - return strcasecmp( $this->get_user_public_name( $user_1 ), $this->get_user_public_name( $user_2 ) ); |
|
| 282 | + return strcasecmp($this->get_user_public_name($user_1), $this->get_user_public_name($user_2)); |
|
| 283 | 283 | |
| 284 | 284 | }// end custom_user_sort |
| 285 | 285 | |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | /** |
| 4 | 7 | * |
| 5 | 8 | * Renders the [sensei_teachers] shortcode. Will show a list of teachers |
@@ -149,7 +152,7 @@ discard block |
||
| 149 | 152 | // exclude this user as it is already in the list |
| 150 | 153 | unset( $users[ $index ] ); |
| 151 | 154 | |
| 152 | - }else{ |
|
| 155 | + } else{ |
|
| 153 | 156 | |
| 154 | 157 | // add teh user to the list of users |
| 155 | 158 | $array_unique_users_ids[] = $user->ID; |
@@ -239,9 +242,7 @@ discard block |
||
| 239 | 242 | |
| 240 | 243 | $user_public_name = $user->first_name . ' ' . $user->last_name; |
| 241 | 244 | |
| 242 | - } |
|
| 243 | - |
|
| 244 | - else { |
|
| 245 | + } else { |
|
| 245 | 246 | |
| 246 | 247 | $user_public_name = $user->display_name; |
| 247 | 248 | |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei_Main |
@@ -156,7 +159,9 @@ discard block |
||
| 156 | 159 | $this->init(); |
| 157 | 160 | |
| 158 | 161 | // Installation |
| 159 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 162 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 163 | + $this->install(); |
|
| 164 | + } |
|
| 160 | 165 | |
| 161 | 166 | // Run this on activation. |
| 162 | 167 | register_activation_hook( $this->file, array( $this, 'activation' ) ); |
@@ -442,7 +447,9 @@ discard block |
||
| 442 | 447 | **/ |
| 443 | 448 | public function virtual_order_payment_complete( $order_status, $order_id ) { |
| 444 | 449 | $order = new WC_Order( $order_id ); |
| 445 | - if ( ! isset ( $order ) ) return; |
|
| 450 | + if ( ! isset ( $order ) ) { |
|
| 451 | + return; |
|
| 452 | + } |
|
| 446 | 453 | if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
| 447 | 454 | $virtual_order = true; |
| 448 | 455 | |
@@ -606,7 +613,7 @@ discard block |
||
| 606 | 613 | |
| 607 | 614 | $sensei_plugin_path = $this->plugin_path; |
| 608 | 615 | |
| 609 | - }else{ |
|
| 616 | + } else{ |
|
| 610 | 617 | |
| 611 | 618 | $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
| 612 | 619 | |
@@ -641,7 +648,9 @@ discard block |
||
| 641 | 648 | public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
| 642 | 649 | global $current_user; |
| 643 | 650 | |
| 644 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return; |
|
| 651 | + if ( ! isset( $current_user ) || !$current_user->ID > 0 ) { |
|
| 652 | + return; |
|
| 653 | + } |
|
| 645 | 654 | |
| 646 | 655 | $data_update = false; |
| 647 | 656 | |
@@ -725,8 +734,7 @@ discard block |
||
| 725 | 734 | |
| 726 | 735 | $prerequisite_complete = WooThemes_Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
| 727 | 736 | |
| 728 | - } |
|
| 729 | - else { |
|
| 737 | + } else { |
|
| 730 | 738 | $prerequisite_complete = true; |
| 731 | 739 | } // End If Statement |
| 732 | 740 | // Handles restrictions |
@@ -853,7 +861,9 @@ discard block |
||
| 853 | 861 | */ |
| 854 | 862 | public function access_settings () { |
| 855 | 863 | |
| 856 | - if( sensei_all_access() ) return true; |
|
| 864 | + if( sensei_all_access() ) { |
|
| 865 | + return true; |
|
| 866 | + } |
|
| 857 | 867 | |
| 858 | 868 | if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
| 859 | 869 | if ( is_user_logged_in() ) { |
@@ -1182,8 +1192,9 @@ discard block |
||
| 1182 | 1192 | } |
| 1183 | 1193 | $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
| 1184 | 1194 | |
| 1185 | - if ( $post_id > 0 ) |
|
| 1186 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1195 | + if ( $post_id > 0 ) { |
|
| 1196 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1197 | + } |
|
| 1187 | 1198 | |
| 1188 | 1199 | $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
| 1189 | 1200 | |
@@ -1191,16 +1202,19 @@ discard block |
||
| 1191 | 1202 | $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
| 1192 | 1203 | foreach ( (array) $count as $row ) { |
| 1193 | 1204 | // Don't count post-trashed toward totals |
| 1194 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1195 | - $total += $row['num_comments']; |
|
| 1196 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1197 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1205 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) { |
|
| 1206 | + $total += $row['num_comments']; |
|
| 1207 | + } |
|
| 1208 | + if ( isset( $approved[$row['comment_approved']] ) ) { |
|
| 1209 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1210 | + } |
|
| 1198 | 1211 | } |
| 1199 | 1212 | |
| 1200 | 1213 | $stats['total_comments'] = $total; |
| 1201 | 1214 | foreach ( $approved as $key ) { |
| 1202 | - if ( empty($stats[$key]) ) |
|
| 1203 | - $stats[$key] = 0; |
|
| 1215 | + if ( empty($stats[$key]) ) { |
|
| 1216 | + $stats[$key] = 0; |
|
| 1217 | + } |
|
| 1204 | 1218 | } |
| 1205 | 1219 | |
| 1206 | 1220 | $stats = (object) $stats; |
@@ -1241,8 +1255,9 @@ discard block |
||
| 1241 | 1255 | public function get_image_size( $image_size ) { |
| 1242 | 1256 | |
| 1243 | 1257 | // Only return sizes we define in settings |
| 1244 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1245 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1258 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) { |
|
| 1259 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1260 | + } |
|
| 1246 | 1261 | |
| 1247 | 1262 | if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
| 1248 | 1263 | $this->settings->settings[ $image_size . '_width' ] = false; |
@@ -1305,7 +1320,7 @@ discard block |
||
| 1305 | 1320 | require_once( 'class-sensei-modules.php'); |
| 1306 | 1321 | Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
| 1307 | 1322 | |
| 1308 | - }else{ |
|
| 1323 | + } else{ |
|
| 1309 | 1324 | // fallback for people still using the modules extension. |
| 1310 | 1325 | global $sensei_modules; |
| 1311 | 1326 | Sensei()->modules = $sensei_modules; |
@@ -1352,7 +1367,7 @@ discard block |
||
| 1352 | 1367 | |
| 1353 | 1368 | update_option('sensei_flush_rewrite_rules', '2'); |
| 1354 | 1369 | |
| 1355 | - }elseif( '2' == $option ) { |
|
| 1370 | + } elseif( '2' == $option ) { |
|
| 1356 | 1371 | |
| 1357 | 1372 | flush_rewrite_rules(); |
| 1358 | 1373 | update_option('sensei_flush_rewrite_rules', '0'); |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | /** |
| 399 | 399 | * Disable guest checkout if a course product is in the cart |
| 400 | 400 | * @param boolean $guest_checkout Current guest checkout setting |
| 401 | - * @return boolean Modified guest checkout setting |
|
| 401 | + * @return string|boolean Modified guest checkout setting |
|
| 402 | 402 | */ |
| 403 | 403 | public function disable_guest_checkout( $guest_checkout ) { |
| 404 | 404 | global $woocommerce; |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | * |
| 585 | 585 | * @access public |
| 586 | 586 | * @param mixed $template |
| 587 | - * @return void |
|
| 587 | + * @return string |
|
| 588 | 588 | * @deprecated |
| 589 | 589 | */ |
| 590 | 590 | public function template_loader ( $template = '' ) { |
@@ -849,7 +849,7 @@ discard block |
||
| 849 | 849 | * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
| 850 | 850 | * @since 1.0.0 |
| 851 | 851 | * @access public |
| 852 | - * @return void |
|
| 852 | + * @return boolean |
|
| 853 | 853 | */ |
| 854 | 854 | public function access_settings () { |
| 855 | 855 | |
@@ -1235,7 +1235,7 @@ discard block |
||
| 1235 | 1235 | * |
| 1236 | 1236 | * @since 1.4.5 |
| 1237 | 1237 | * @access public |
| 1238 | - * @param mixed $image_size |
|
| 1238 | + * @param string $image_size |
|
| 1239 | 1239 | * @return string |
| 1240 | 1240 | */ |
| 1241 | 1241 | public function get_image_size( $image_size ) { |
@@ -14,1316 +14,1316 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Main { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var file |
|
| 19 | - * Reference to the main plugin file |
|
| 20 | - */ |
|
| 21 | - private $file; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var $_instance reference 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 WooThemes_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 WooThemes_Sensei_Course |
|
| 65 | - */ |
|
| 66 | - public $course; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @var WooThemes_Sensei_Lesson |
|
| 70 | - */ |
|
| 71 | - public $lesson; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var WooThemes_Sensei_Quiz |
|
| 75 | - */ |
|
| 76 | - public $quiz; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @var WooThemes_Sensei_Question |
|
| 80 | - */ |
|
| 81 | - public $question; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @var WooThemes_Sensei_Admin |
|
| 85 | - */ |
|
| 86 | - public $admin; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @var WooThemes_Sensei_Frontend |
|
| 90 | - */ |
|
| 91 | - public $frontend; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @var String |
|
| 95 | - */ |
|
| 96 | - public $notice; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @var WooThemes_Sensei_Grading |
|
| 100 | - */ |
|
| 101 | - public $grading; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @var WooThemes_Sensei_Emails |
|
| 105 | - */ |
|
| 106 | - public $emails; |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @var WooThemes_Sensei_Learner_Profiles |
|
| 110 | - */ |
|
| 111 | - public $learner_profiles; |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @var Sensei_Teacher |
|
| 115 | - */ |
|
| 116 | - public $teacher; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @var WooThemes_Sensei_Learners |
|
| 120 | - */ |
|
| 121 | - public $learners; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @var array |
|
| 125 | - * Global instance for access to the permissions message shown |
|
| 126 | - * when users do not have the right privileges to access resources. |
|
| 127 | - */ |
|
| 128 | - public $permissions_message; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 132 | - */ |
|
| 133 | - public $modules; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @var Sensei_Analysis |
|
| 137 | - */ |
|
| 138 | - public $analysis; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Constructor method. |
|
| 142 | - * @param string $file The base file of the plugin. |
|
| 143 | - * @since 1.0.0 |
|
| 144 | - */ |
|
| 145 | - public function __construct ( $file ) { |
|
| 146 | - |
|
| 147 | - // Setup object data |
|
| 148 | - $this->file = $file; |
|
| 149 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 150 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 151 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 152 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 153 | - |
|
| 154 | - // Initialize the core Sensei functionality |
|
| 155 | - $this->init(); |
|
| 17 | + /** |
|
| 18 | + * @var file |
|
| 19 | + * Reference to the main plugin file |
|
| 20 | + */ |
|
| 21 | + private $file; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var $_instance reference 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 WooThemes_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 WooThemes_Sensei_Course |
|
| 65 | + */ |
|
| 66 | + public $course; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @var WooThemes_Sensei_Lesson |
|
| 70 | + */ |
|
| 71 | + public $lesson; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var WooThemes_Sensei_Quiz |
|
| 75 | + */ |
|
| 76 | + public $quiz; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @var WooThemes_Sensei_Question |
|
| 80 | + */ |
|
| 81 | + public $question; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @var WooThemes_Sensei_Admin |
|
| 85 | + */ |
|
| 86 | + public $admin; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @var WooThemes_Sensei_Frontend |
|
| 90 | + */ |
|
| 91 | + public $frontend; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @var String |
|
| 95 | + */ |
|
| 96 | + public $notice; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @var WooThemes_Sensei_Grading |
|
| 100 | + */ |
|
| 101 | + public $grading; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @var WooThemes_Sensei_Emails |
|
| 105 | + */ |
|
| 106 | + public $emails; |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @var WooThemes_Sensei_Learner_Profiles |
|
| 110 | + */ |
|
| 111 | + public $learner_profiles; |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @var Sensei_Teacher |
|
| 115 | + */ |
|
| 116 | + public $teacher; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @var WooThemes_Sensei_Learners |
|
| 120 | + */ |
|
| 121 | + public $learners; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @var array |
|
| 125 | + * Global instance for access to the permissions message shown |
|
| 126 | + * when users do not have the right privileges to access resources. |
|
| 127 | + */ |
|
| 128 | + public $permissions_message; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 132 | + */ |
|
| 133 | + public $modules; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @var Sensei_Analysis |
|
| 137 | + */ |
|
| 138 | + public $analysis; |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Constructor method. |
|
| 142 | + * @param string $file The base file of the plugin. |
|
| 143 | + * @since 1.0.0 |
|
| 144 | + */ |
|
| 145 | + public function __construct ( $file ) { |
|
| 146 | + |
|
| 147 | + // Setup object data |
|
| 148 | + $this->file = $file; |
|
| 149 | + $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 150 | + $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 151 | + $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 152 | + $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 153 | + |
|
| 154 | + // Initialize the core Sensei functionality |
|
| 155 | + $this->init(); |
|
| 156 | 156 | |
| 157 | - // Installation |
|
| 158 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 157 | + // Installation |
|
| 158 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 159 | 159 | |
| 160 | - // Run this on activation. |
|
| 161 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 160 | + // Run this on activation. |
|
| 161 | + register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 162 | 162 | |
| 163 | - // Setup post types. |
|
| 164 | - $this->post_types = new Sensei_PostTypes(); |
|
| 165 | - $this->post_types->token = 'woothemes-sensei-posttypes'; |
|
| 166 | - |
|
| 167 | - // Lad the updates class |
|
| 168 | - $this->updates = new WooThemes_Sensei_Updates( $this ); |
|
| 169 | - |
|
| 170 | - // Setup settings screen. |
|
| 171 | - $this->settings = new Sensei_Settings(); |
|
| 172 | - $this->settings->token = 'woothemes-sensei-settings'; |
|
| 173 | - |
|
| 174 | - // Setup Admin Settings data |
|
| 175 | - if ( is_admin() ) { |
|
| 176 | - |
|
| 177 | - $this->settings->has_tabs = true; |
|
| 178 | - $this->settings->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
| 179 | - $this->settings->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
| 180 | - $this->settings->page_slug = 'woothemes-sensei-settings'; |
|
| 163 | + // Setup post types. |
|
| 164 | + $this->post_types = new Sensei_PostTypes(); |
|
| 165 | + $this->post_types->token = 'woothemes-sensei-posttypes'; |
|
| 166 | + |
|
| 167 | + // Lad the updates class |
|
| 168 | + $this->updates = new WooThemes_Sensei_Updates( $this ); |
|
| 169 | + |
|
| 170 | + // Setup settings screen. |
|
| 171 | + $this->settings = new Sensei_Settings(); |
|
| 172 | + $this->settings->token = 'woothemes-sensei-settings'; |
|
| 173 | + |
|
| 174 | + // Setup Admin Settings data |
|
| 175 | + if ( is_admin() ) { |
|
| 176 | + |
|
| 177 | + $this->settings->has_tabs = true; |
|
| 178 | + $this->settings->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
| 179 | + $this->settings->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
| 180 | + $this->settings->page_slug = 'woothemes-sensei-settings'; |
|
| 181 | 181 | |
| 182 | - } // End If Statement |
|
| 182 | + } // End If Statement |
|
| 183 | 183 | |
| 184 | - $this->settings->setup_settings(); |
|
| 185 | - $this->settings->get_settings(); |
|
| 184 | + $this->settings->setup_settings(); |
|
| 185 | + $this->settings->get_settings(); |
|
| 186 | 186 | |
| 187 | - // Load Course Results Class |
|
| 188 | - $this->course_results = new Sensei_Course_Results(); |
|
| 189 | - $this->course_results->token = $this->token; |
|
| 187 | + // Load Course Results Class |
|
| 188 | + $this->course_results = new Sensei_Course_Results(); |
|
| 189 | + $this->course_results->token = $this->token; |
|
| 190 | 190 | |
| 191 | - // Load the teacher role |
|
| 192 | - $this->teacher = new Sensei_Teacher(); |
|
| 191 | + // Load the teacher role |
|
| 192 | + $this->teacher = new Sensei_Teacher(); |
|
| 193 | 193 | |
| 194 | - // Add the Course class |
|
| 195 | - $this->course = $this->post_types->course; |
|
| 194 | + // Add the Course class |
|
| 195 | + $this->course = $this->post_types->course; |
|
| 196 | 196 | |
| 197 | - // Add the lesson class |
|
| 198 | - $this->lesson = $this->post_types->lesson; |
|
| 197 | + // Add the lesson class |
|
| 198 | + $this->lesson = $this->post_types->lesson; |
|
| 199 | 199 | |
| 200 | - // Add the question class |
|
| 201 | - $this->question = $this->post_types->question; |
|
| 200 | + // Add the question class |
|
| 201 | + $this->question = $this->post_types->question; |
|
| 202 | 202 | |
| 203 | - //Add the quiz class |
|
| 204 | - $this->quiz = $this->post_types->quiz; |
|
| 203 | + //Add the quiz class |
|
| 204 | + $this->quiz = $this->post_types->quiz; |
|
| 205 | 205 | |
| 206 | - // load the modules class |
|
| 207 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 206 | + // load the modules class |
|
| 207 | + add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 208 | 208 | |
| 209 | - // Load Learner Management Functionality |
|
| 210 | - $this->learners = new Sensei_Learners( $file ); |
|
| 211 | - $this->learners->token = $this->token; |
|
| 209 | + // Load Learner Management Functionality |
|
| 210 | + $this->learners = new Sensei_Learners( $file ); |
|
| 211 | + $this->learners->token = $this->token; |
|
| 212 | 212 | |
| 213 | - // Differentiate between administration and frontend logic. |
|
| 214 | - if ( is_admin() ) { |
|
| 213 | + // Differentiate between administration and frontend logic. |
|
| 214 | + if ( is_admin() ) { |
|
| 215 | 215 | |
| 216 | - // Load Admin Welcome class |
|
| 217 | - new Sensei_Welcome(); |
|
| 216 | + // Load Admin Welcome class |
|
| 217 | + new Sensei_Welcome(); |
|
| 218 | 218 | |
| 219 | - // Load Admin Class |
|
| 220 | - $this->admin = new Sensei_Admin( $file ); |
|
| 221 | - $this->admin->token = $this->token; |
|
| 219 | + // Load Admin Class |
|
| 220 | + $this->admin = new Sensei_Admin( $file ); |
|
| 221 | + $this->admin->token = $this->token; |
|
| 222 | 222 | |
| 223 | - // Load Analysis Reports |
|
| 224 | - $this->analysis = new Sensei_Analysis( $file ); |
|
| 225 | - $this->analysis->token = $this->token; |
|
| 223 | + // Load Analysis Reports |
|
| 224 | + $this->analysis = new Sensei_Analysis( $file ); |
|
| 225 | + $this->analysis->token = $this->token; |
|
| 226 | 226 | |
| 227 | 227 | |
| 228 | - } else { |
|
| 228 | + } else { |
|
| 229 | 229 | |
| 230 | - // Load Frontend Class |
|
| 231 | - $this->frontend = new Sensei_Frontend(); |
|
| 232 | - $this->frontend->token = $this->token; |
|
| 233 | - $this->frontend->init(); |
|
| 230 | + // Load Frontend Class |
|
| 231 | + $this->frontend = new Sensei_Frontend(); |
|
| 232 | + $this->frontend->token = $this->token; |
|
| 233 | + $this->frontend->init(); |
|
| 234 | 234 | |
| 235 | - // Load notice Class |
|
| 236 | - $this->notices = new Sensei_Notices(); |
|
| 235 | + // Load notice Class |
|
| 236 | + $this->notices = new Sensei_Notices(); |
|
| 237 | 237 | |
| 238 | - } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - // Load Grading Functionality |
|
| 241 | - $this->grading = new Sensei_Grading( $file ); |
|
| 242 | - $this->grading->token = $this->token; |
|
| 240 | + // Load Grading Functionality |
|
| 241 | + $this->grading = new Sensei_Grading( $file ); |
|
| 242 | + $this->grading->token = $this->token; |
|
| 243 | 243 | |
| 244 | - // Load Email Class |
|
| 245 | - $this->emails = new Sensei_Emails( $file ); |
|
| 246 | - $this->emails->token = $this->token; |
|
| 244 | + // Load Email Class |
|
| 245 | + $this->emails = new Sensei_Emails( $file ); |
|
| 246 | + $this->emails->token = $this->token; |
|
| 247 | 247 | |
| 248 | - // Load Learner Profiles Class |
|
| 249 | - $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 250 | - $this->learner_profiles->token = $this->token; |
|
| 248 | + // Load Learner Profiles Class |
|
| 249 | + $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 250 | + $this->learner_profiles->token = $this->token; |
|
| 251 | 251 | |
| 252 | - // Image Sizes |
|
| 253 | - $this->init_image_sizes(); |
|
| 252 | + // Image Sizes |
|
| 253 | + $this->init_image_sizes(); |
|
| 254 | 254 | |
| 255 | - // Force WooCommerce Required Settings |
|
| 256 | - $this->set_woocommerce_functionality(); |
|
| 257 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 258 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 255 | + // Force WooCommerce Required Settings |
|
| 256 | + $this->set_woocommerce_functionality(); |
|
| 257 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 258 | + add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 259 | 259 | |
| 260 | - // WooCommerce Payment Actions |
|
| 261 | - add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 262 | - add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 263 | - add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 264 | - add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 265 | - add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 266 | - add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 267 | - add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 260 | + // WooCommerce Payment Actions |
|
| 261 | + add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 262 | + add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 263 | + add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 264 | + add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 265 | + add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 266 | + add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 267 | + add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 268 | 268 | |
| 269 | - // WooCommerce Subscriptions Actions |
|
| 270 | - add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 271 | - add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 272 | - add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 273 | - add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 274 | - add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 269 | + // WooCommerce Subscriptions Actions |
|
| 270 | + add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 271 | + add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 272 | + add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 273 | + add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 274 | + add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 275 | 275 | |
| 276 | - // Add Email link to course orders |
|
| 277 | - add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 276 | + // Add Email link to course orders |
|
| 277 | + add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 278 | 278 | |
| 279 | - // Filter comment counts |
|
| 280 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 279 | + // Filter comment counts |
|
| 280 | + add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 281 | 281 | |
| 282 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 282 | + add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 283 | 283 | |
| 284 | - // Check for and activate JetPack LaTeX support |
|
| 285 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 284 | + // Check for and activate JetPack LaTeX support |
|
| 285 | + add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 286 | 286 | |
| 287 | - // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 288 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 287 | + // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 288 | + add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 289 | 289 | |
| 290 | - } // End __construct() |
|
| 290 | + } // End __construct() |
|
| 291 | 291 | |
| 292 | - /** |
|
| 293 | - * Load the foundations of Sensei. |
|
| 294 | - * @since 1.9.0 |
|
| 295 | - */ |
|
| 296 | - protected function init(){ |
|
| 292 | + /** |
|
| 293 | + * Load the foundations of Sensei. |
|
| 294 | + * @since 1.9.0 |
|
| 295 | + */ |
|
| 296 | + protected function init(){ |
|
| 297 | 297 | |
| 298 | - // Localisation |
|
| 299 | - $this->load_plugin_textdomain(); |
|
| 300 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 298 | + // Localisation |
|
| 299 | + $this->load_plugin_textdomain(); |
|
| 300 | + add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 301 | 301 | |
| 302 | - // load the shortcode loader into memory, so as to listen to all for |
|
| 303 | - // all shortcodes on the front end |
|
| 304 | - new Sensei_Shortcode_Loader(); |
|
| 302 | + // load the shortcode loader into memory, so as to listen to all for |
|
| 303 | + // all shortcodes on the front end |
|
| 304 | + new Sensei_Shortcode_Loader(); |
|
| 305 | 305 | |
| 306 | - } |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - /** |
|
| 309 | - * This function is linked into the activation |
|
| 310 | - * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 311 | - * |
|
| 312 | - * @since 1.9.0 |
|
| 313 | - * |
|
| 314 | - * @param $plugin |
|
| 315 | - */ |
|
| 316 | - public static function activation_flush_rules( $plugin ){ |
|
| 317 | - |
|
| 318 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 319 | - |
|
| 320 | - flush_rewrite_rules(true); |
|
| 321 | - |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Global Sensei Instance |
|
| 328 | - * |
|
| 329 | - * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 330 | - * |
|
| 331 | - * @since 1.8.0 |
|
| 332 | - * @static |
|
| 333 | - * @see WC() |
|
| 334 | - * @return WooThemes_Sensei Instance. |
|
| 335 | - */ |
|
| 336 | - public static function instance() { |
|
| 337 | - |
|
| 338 | - if ( is_null( self::$_instance ) ) { |
|
| 339 | - |
|
| 340 | - //Sensei requires a reference to the main Sensei plugin file |
|
| 341 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 342 | - |
|
| 343 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 344 | - |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return self::$_instance; |
|
| 348 | - |
|
| 349 | - } // end instance() |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Cloning is forbidden. |
|
| 353 | - * @since 1.8.0 |
|
| 354 | - */ |
|
| 355 | - public function __clone() { |
|
| 356 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Unserializing instances of this class is forbidden. |
|
| 361 | - * @since 1.8.0 |
|
| 362 | - */ |
|
| 363 | - public function __wakeup() { |
|
| 364 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Run Sensei updates. |
|
| 369 | - * @access public |
|
| 370 | - * @since 1.1.0 |
|
| 371 | - * @return void |
|
| 372 | - */ |
|
| 373 | - public function run_updates() { |
|
| 374 | - // Run updates if administrator |
|
| 375 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 376 | - |
|
| 377 | - $this->updates->update(); |
|
| 378 | - |
|
| 379 | - } // End If Statement |
|
| 380 | - } // End run_updates() |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Setup required WooCommerce settings. |
|
| 384 | - * @access public |
|
| 385 | - * @since 1.1.0 |
|
| 386 | - * @return void |
|
| 387 | - */ |
|
| 388 | - public function set_woocommerce_functionality() { |
|
| 389 | - // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
|
| 390 | - add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 391 | - |
|
| 392 | - // Mark orders with virtual products as complete rather then stay processing |
|
| 393 | - add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 394 | - |
|
| 395 | - } // End set_woocommerce_functionality() |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Disable guest checkout if a course product is in the cart |
|
| 399 | - * @param boolean $guest_checkout Current guest checkout setting |
|
| 400 | - * @return boolean Modified guest checkout setting |
|
| 401 | - */ |
|
| 402 | - public function disable_guest_checkout( $guest_checkout ) { |
|
| 403 | - global $woocommerce; |
|
| 404 | - |
|
| 405 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 406 | - |
|
| 407 | - if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 408 | - foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 409 | - if( isset( $product['product_id'] ) ) { |
|
| 410 | - $args = array( |
|
| 411 | - 'posts_per_page' => -1, |
|
| 412 | - 'post_type' => 'course', |
|
| 413 | - 'meta_query' => array( |
|
| 414 | - array( |
|
| 415 | - 'key' => '_course_woocommerce_product', |
|
| 416 | - 'value' => $product['product_id'] |
|
| 417 | - ) |
|
| 418 | - ) |
|
| 419 | - ); |
|
| 420 | - $posts = get_posts( $args ); |
|
| 421 | - if( $posts && count( $posts ) > 0 ) { |
|
| 422 | - foreach( $posts as $course ) { |
|
| 423 | - $guest_checkout = ''; |
|
| 424 | - break; |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - return $guest_checkout; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Change order status with virtual products to completed |
|
| 437 | - * @since 1.1.0 |
|
| 438 | - * @param string $order_status |
|
| 439 | - * @param int $order_id |
|
| 440 | - * @return string |
|
| 441 | - **/ |
|
| 442 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 443 | - $order = new WC_Order( $order_id ); |
|
| 444 | - if ( ! isset ( $order ) ) return; |
|
| 445 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 446 | - $virtual_order = true; |
|
| 447 | - |
|
| 448 | - if ( count( $order->get_items() ) > 0 ) { |
|
| 449 | - foreach( $order->get_items() as $item ) { |
|
| 450 | - if ( $item['product_id'] > 0 ) { |
|
| 451 | - $_product = $order->get_product_from_item( $item ); |
|
| 452 | - if ( ! $_product->is_virtual() ) { |
|
| 453 | - $virtual_order = false; |
|
| 454 | - break; |
|
| 455 | - } // End If Statement |
|
| 456 | - } // End If Statement |
|
| 457 | - } // End For Loop |
|
| 458 | - } // End If Statement |
|
| 459 | - |
|
| 460 | - // virtual order, mark as completed |
|
| 461 | - if ( $virtual_order ) { |
|
| 462 | - return 'completed'; |
|
| 463 | - } // End If Statement |
|
| 464 | - } // End If Statement |
|
| 465 | - return $order_status; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Register the widgets. |
|
| 470 | - * @access public |
|
| 471 | - * @since 1.0.0 |
|
| 472 | - * @return void |
|
| 473 | - */ |
|
| 474 | - public function register_widgets () { |
|
| 475 | - // Widget List (key => value is filename => widget class). |
|
| 476 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 477 | - 'lesson-component' => 'Lesson_Component', |
|
| 478 | - 'course-categories' => 'Course_Categories', |
|
| 479 | - 'category-courses' => 'Category_Courses' ) |
|
| 480 | - ); |
|
| 481 | - foreach ( $widget_list as $key => $value ) { |
|
| 482 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ) ) { |
|
| 483 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ); |
|
| 484 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 485 | - } |
|
| 486 | - } // End For Loop |
|
| 487 | - |
|
| 488 | - do_action( 'sensei_register_widgets' ); |
|
| 489 | - } // End register_widgets() |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * Load the plugin's localisation file. |
|
| 493 | - * @access public |
|
| 494 | - * @since 1.0.0 |
|
| 495 | - * @return void |
|
| 496 | - */ |
|
| 497 | - public function load_localisation () { |
|
| 498 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 499 | - } // End load_localisation() |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 503 | - * @access public |
|
| 504 | - * @since 1.0.0 |
|
| 505 | - * @return void |
|
| 506 | - */ |
|
| 507 | - public function load_plugin_textdomain () { |
|
| 508 | - $domain = 'woothemes-sensei'; |
|
| 509 | - // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 510 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 511 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 512 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 513 | - } // End load_plugin_textdomain() |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Run on activation. |
|
| 517 | - * @access public |
|
| 518 | - * @since 1.0.0 |
|
| 519 | - * @return void |
|
| 520 | - */ |
|
| 521 | - public function activation () { |
|
| 522 | - $this->register_plugin_version(); |
|
| 523 | - } // End activation() |
|
| 524 | - |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Register activation hooks. |
|
| 528 | - * @access public |
|
| 529 | - * @since 1.0.0 |
|
| 530 | - * @return void |
|
| 531 | - */ |
|
| 532 | - public function install () { |
|
| 533 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 534 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 535 | - } // End install() |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Run on activation of the plugin. |
|
| 540 | - * @access public |
|
| 541 | - * @since 1.0.0 |
|
| 542 | - * @return void |
|
| 543 | - */ |
|
| 544 | - public function activate_sensei () { |
|
| 545 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
| 546 | - update_option( 'sensei_installed', 1 ); |
|
| 547 | - } // End activate_sensei() |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Register the plugin's version. |
|
| 551 | - * @access public |
|
| 552 | - * @since 1.0.0 |
|
| 553 | - * @return void |
|
| 554 | - */ |
|
| 555 | - private function register_plugin_version () { |
|
| 556 | - if ( $this->version != '' ) { |
|
| 557 | - |
|
| 558 | - // Check previous version to see if forced updates must run |
|
| 559 | - // $old_version = get_option( 'woothemes-sensei-version', false ); |
|
| 560 | - // if( $old_version && version_compare( $old_version, '1.7.0', '<' ) ) { |
|
| 561 | - // update_option( 'woothemes-sensei-force-updates', $this->version ); |
|
| 562 | - // } else { |
|
| 563 | - // delete_option( 'woothemes-sensei-force-updates' ); |
|
| 564 | - // } |
|
| 565 | - |
|
| 566 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
| 567 | - } |
|
| 568 | - } // End register_plugin_version() |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 572 | - * @access public |
|
| 573 | - * @since 1.0.1 |
|
| 574 | - * @return void |
|
| 575 | - */ |
|
| 576 | - public function ensure_post_thumbnails_support () { |
|
| 577 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 578 | - } // End ensure_post_thumbnails_support() |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * template_loader function. |
|
| 583 | - * |
|
| 584 | - * @access public |
|
| 585 | - * @param mixed $template |
|
| 586 | - * @return void |
|
| 587 | - * @deprecated |
|
| 588 | - */ |
|
| 589 | - public function template_loader ( $template = '' ) { |
|
| 590 | - |
|
| 591 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 592 | - return Sensei_Templates::template_loader( $template ); |
|
| 593 | - |
|
| 594 | - } // End template_loader() |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Determine the relative path to the plugin's directory. |
|
| 598 | - * @access public |
|
| 599 | - * @since 1.0.0 |
|
| 600 | - * @return string $sensei_plugin_path |
|
| 601 | - */ |
|
| 602 | - public function plugin_path () { |
|
| 603 | - |
|
| 604 | - if ( $this->plugin_path ) { |
|
| 605 | - |
|
| 606 | - $sensei_plugin_path = $this->plugin_path; |
|
| 607 | - |
|
| 608 | - }else{ |
|
| 609 | - |
|
| 610 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 611 | - |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - return $sensei_plugin_path; |
|
| 615 | - |
|
| 616 | - } // End plugin_path() |
|
| 617 | - |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Retrieve the ID of a specified page setting. |
|
| 621 | - * @access public |
|
| 622 | - * @since 1.0.0 |
|
| 623 | - * @param string $page |
|
| 624 | - * @return int |
|
| 625 | - */ |
|
| 626 | - public function get_page_id ( $page ) { |
|
| 627 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 628 | - return ( $page ) ? $page : -1; |
|
| 629 | - } // End get_page_id() |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 634 | - * @access public |
|
| 635 | - * @since 1.0.0 |
|
| 636 | - * @param int $course_id (default: 0) |
|
| 637 | - * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 638 | - * @return void |
|
| 639 | - */ |
|
| 640 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 641 | - global $current_user; |
|
| 642 | - |
|
| 643 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return; |
|
| 644 | - |
|
| 645 | - $data_update = false; |
|
| 646 | - |
|
| 647 | - // Get the product ID |
|
| 648 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 649 | - |
|
| 650 | - // Check if in the admin |
|
| 651 | - if ( is_admin() ) { |
|
| 652 | - $user_login = $order_user['user_login']; |
|
| 653 | - $user_email = $order_user['user_email']; |
|
| 654 | - $user_url = $order_user['user_url']; |
|
| 655 | - $user_id = $order_user['ID']; |
|
| 656 | - } else { |
|
| 657 | - $user_login = $current_user->user_login; |
|
| 658 | - $user_email = $current_user->user_email; |
|
| 659 | - $user_url = $current_user->user_url; |
|
| 660 | - $user_id = $current_user->ID; |
|
| 661 | - } // End If Statement |
|
| 662 | - |
|
| 663 | - // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 664 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 665 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 666 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 667 | - if ( ! $prereq_course_complete ) { |
|
| 668 | - // Remove all course user meta |
|
| 669 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 674 | - |
|
| 675 | - if( ! $is_user_taking_course ) { |
|
| 676 | - |
|
| 677 | - if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 678 | - |
|
| 679 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 680 | - |
|
| 681 | - $is_user_taking_course = false; |
|
| 682 | - if ( true == $activity_logged ) { |
|
| 683 | - $is_user_taking_course = true; |
|
| 684 | - } // End If Statement |
|
| 685 | - } // End If Statement |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - return $is_user_taking_course; |
|
| 689 | - } // End woocommerce_course_update() |
|
| 690 | - |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * check_user_permissions function. |
|
| 694 | - * |
|
| 695 | - * @access public |
|
| 696 | - * @param string $page (default: '') |
|
| 697 | - * @param array $data (default: array()) |
|
| 698 | - * @return bool |
|
| 699 | - */ |
|
| 700 | - public function check_user_permissions ( $page = '', $data = array() ) { |
|
| 701 | - // REFACTOR |
|
| 702 | - global $current_user, $post; |
|
| 703 | - |
|
| 704 | - // if use is not logged in |
|
| 705 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){ |
|
| 706 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 707 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 708 | - return; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - // Get User Meta |
|
| 713 | - get_currentuserinfo(); |
|
| 714 | - |
|
| 715 | - $user_allowed = false; |
|
| 716 | - |
|
| 717 | - switch ( $page ) { |
|
| 718 | - case 'course-single': |
|
| 719 | - // check for prerequisite course or lesson, |
|
| 720 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 721 | - $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 722 | - // Count completed lessons |
|
| 723 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 724 | - |
|
| 725 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 726 | - |
|
| 727 | - } |
|
| 728 | - else { |
|
| 729 | - $prerequisite_complete = true; |
|
| 730 | - } // End If Statement |
|
| 731 | - // Handles restrictions |
|
| 732 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 733 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 734 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 735 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 736 | - } else { |
|
| 737 | - $user_allowed = true; |
|
| 738 | - } // End If Statement |
|
| 739 | - break; |
|
| 740 | - case 'lesson-single': |
|
| 741 | - // Check for WC purchase |
|
| 742 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 743 | - |
|
| 744 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 745 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 746 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 747 | - $user_allowed = true; |
|
| 748 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 749 | - |
|
| 750 | - $user_allowed = true; |
|
| 751 | - } else { |
|
| 752 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 753 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 754 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 755 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 756 | - if ( $is_preview ) { |
|
| 757 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 758 | - } else { |
|
| 759 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 760 | - } |
|
| 761 | - } else { |
|
| 762 | - if ( $is_preview ) { |
|
| 763 | - $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 ); |
|
| 764 | - } else { |
|
| 765 | - /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 766 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 767 | - } |
|
| 768 | - } // End If Statement |
|
| 769 | - } // End If Statement |
|
| 770 | - break; |
|
| 771 | - case 'quiz-single': |
|
| 772 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 773 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 774 | - |
|
| 775 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 776 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 777 | - |
|
| 778 | - // Check for prerequisite lesson for this quiz |
|
| 779 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 780 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 781 | - |
|
| 782 | - // Handle restrictions |
|
| 783 | - if( sensei_all_access() ) { |
|
| 784 | - $user_allowed = true; |
|
| 785 | - } else { |
|
| 786 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 787 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 788 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 789 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 790 | - } else { |
|
| 791 | - $user_allowed = true; |
|
| 792 | - } // End If Statement |
|
| 793 | - } // End If Statement |
|
| 794 | - } elseif( $this->access_settings() ) { |
|
| 795 | - // Check if the user has started the course |
|
| 796 | - |
|
| 797 | - 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'] ) ) ) { |
|
| 798 | - |
|
| 799 | - $user_allowed = false; |
|
| 800 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 801 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 802 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 803 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 804 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 805 | - } else { |
|
| 806 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 807 | - } // End If Statement |
|
| 808 | - } else { |
|
| 809 | - $user_allowed = true; |
|
| 810 | - } // End If Statement |
|
| 811 | - } else { |
|
| 812 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 813 | - $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>'; |
|
| 814 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 815 | - } // End If Statement |
|
| 816 | - break; |
|
| 817 | - default: |
|
| 818 | - $user_allowed = true; |
|
| 819 | - break; |
|
| 820 | - |
|
| 821 | - } // End Switch Statement |
|
| 822 | - |
|
| 823 | - /** |
|
| 824 | - * filter the permissions message shown on sensei post types. |
|
| 825 | - * |
|
| 826 | - * @since 1.8.7 |
|
| 827 | - * |
|
| 828 | - * @param array $permissions_message{ |
|
| 829 | - * |
|
| 830 | - * @type string $title |
|
| 831 | - * @type string $message |
|
| 832 | - * |
|
| 833 | - * } |
|
| 834 | - * @param string $post_id |
|
| 835 | - */ |
|
| 836 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 840 | - $user_allowed = true; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 844 | - } // End get_placeholder_image() |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 849 | - * @since 1.0.0 |
|
| 850 | - * @access public |
|
| 851 | - * @return void |
|
| 852 | - */ |
|
| 853 | - public function access_settings () { |
|
| 854 | - |
|
| 855 | - if( sensei_all_access() ) return true; |
|
| 856 | - |
|
| 857 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 858 | - if ( is_user_logged_in() ) { |
|
| 859 | - return true; |
|
| 860 | - } else { |
|
| 861 | - return false; |
|
| 862 | - } // End If Statement |
|
| 863 | - } else { |
|
| 864 | - return true; |
|
| 865 | - } // End If Statement |
|
| 866 | - } // End access_settings() |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * sensei_woocommerce_complete_order description |
|
| 870 | - * @since 1.0.3 |
|
| 871 | - * @access public |
|
| 872 | - * @param int $order_id WC order ID |
|
| 873 | - * @return void |
|
| 874 | - */ |
|
| 875 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 876 | - $order_user = array(); |
|
| 877 | - // Check for WooCommerce |
|
| 878 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 879 | - // Get order object |
|
| 880 | - $order = new WC_Order( $order_id ); |
|
| 881 | - $user = get_user_by( 'id', $order->user_id ); |
|
| 882 | - $order_user['ID'] = $user->ID; |
|
| 883 | - $order_user['user_login'] = $user->user_login; |
|
| 884 | - $order_user['user_email'] = $user->user_email; |
|
| 885 | - $order_user['user_url'] = $user->user_url; |
|
| 886 | - // Run through each product ordered |
|
| 887 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 888 | - foreach( $order->get_items() as $item ) { |
|
| 889 | - $product_type = ''; |
|
| 890 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 891 | - $item_id = $item['variation_id']; |
|
| 892 | - $product_type = 'variation'; |
|
| 893 | - } else { |
|
| 894 | - $item_id = $item['product_id']; |
|
| 895 | - } // End If Statement |
|
| 896 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 897 | - // Get courses that use the WC product |
|
| 898 | - $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 899 | - // Loop and update those courses |
|
| 900 | - foreach ( $courses as $course_item ) { |
|
| 901 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 902 | - } // End For Loop |
|
| 903 | - } // End For Loop |
|
| 904 | - } // End If Statement |
|
| 905 | - // Add meta to indicate that payment has been completed successfully |
|
| 906 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 907 | - } // End If Statement |
|
| 908 | - } // End sensei_woocommerce_complete_order() |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * Runs when an order is cancelled. |
|
| 912 | - * @since 1.2.0 |
|
| 913 | - * @access public |
|
| 914 | - * @param integer $order_id order ID |
|
| 915 | - * @return void |
|
| 916 | - */ |
|
| 917 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 918 | - |
|
| 919 | - // Get order object |
|
| 920 | - $order = new WC_Order( $order_id ); |
|
| 921 | - |
|
| 922 | - // Run through each product ordered |
|
| 923 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 924 | - |
|
| 925 | - // Get order user |
|
| 926 | - $user_id = $order->__get( 'user_id' ); |
|
| 927 | - |
|
| 928 | - foreach( $order->get_items() as $item ) { |
|
| 929 | - |
|
| 930 | - $product_type = ''; |
|
| 931 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 932 | - $item_id = $item['variation_id']; |
|
| 933 | - $product_type = 'variation'; |
|
| 934 | - } else { |
|
| 935 | - $item_id = $item['product_id']; |
|
| 936 | - } // End If Statement |
|
| 937 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 938 | - |
|
| 939 | - // Get courses that use the WC product |
|
| 940 | - $courses = array(); |
|
| 941 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 942 | - |
|
| 943 | - // Loop and update those courses |
|
| 944 | - foreach ($courses as $course_item){ |
|
| 945 | - // Check and Remove course from courses user meta |
|
| 946 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 947 | - } // End For Loop |
|
| 948 | - } // End For Loop |
|
| 949 | - } // End If Statement |
|
| 950 | - } // End sensei_woocommerce_cancel_order() |
|
| 951 | - |
|
| 952 | - /** |
|
| 953 | - * Runs when an subscription is cancelled or expires. |
|
| 954 | - * @since 1.3.3 |
|
| 955 | - * @access public |
|
| 956 | - * @param integer $user_id User ID |
|
| 957 | - * @param integer $subscription_key Subscription Unique Key |
|
| 958 | - * @return void |
|
| 959 | - */ |
|
| 960 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 961 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 962 | - self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * Runs when an subscription is re-activated after suspension. |
|
| 967 | - * @since 1.3.3 |
|
| 968 | - * @access public |
|
| 969 | - * @param integer $user_id User ID |
|
| 970 | - * @param integer $subscription_key Subscription Unique Key |
|
| 971 | - * @return void |
|
| 972 | - */ |
|
| 973 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 974 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 975 | - $order = new WC_Order( $subscription['order_id'] ); |
|
| 976 | - $user = get_user_by( 'id', $order->user_id ); |
|
| 977 | - $order_user = array(); |
|
| 978 | - $order_user['ID'] = $user->ID; |
|
| 979 | - $order_user['user_login'] = $user->user_login; |
|
| 980 | - $order_user['user_email'] = $user->user_email; |
|
| 981 | - $order_user['user_url'] = $user->user_url; |
|
| 982 | - $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 983 | - foreach ( $courses as $course_item ){ |
|
| 984 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 985 | - } // End For Loop |
|
| 986 | - } // End sensei_woocommerce_reactivate_subscription |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Returns the WooCommerce Product Object |
|
| 990 | - * |
|
| 991 | - * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 992 | - * |
|
| 993 | - * @since 1.1.1 |
|
| 994 | - * @access public |
|
| 995 | - * @param integer $wc_product_id Product ID or Variation ID |
|
| 996 | - * @param string $product_type '' or 'variation' |
|
| 997 | - * @return WC_Product $wc_product_object |
|
| 998 | - */ |
|
| 999 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1000 | - |
|
| 1001 | - $wc_product_object = false; |
|
| 1002 | - if ( 0 < intval( $wc_product_id ) ) { |
|
| 1003 | - |
|
| 1004 | - // Get the product |
|
| 1005 | - if ( function_exists( 'wc_get_product' ) ) { |
|
| 1006 | - |
|
| 1007 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1008 | - |
|
| 1009 | - } elseif ( function_exists( 'get_product' ) ) { |
|
| 1010 | - |
|
| 1011 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1012 | - |
|
| 1013 | - } else { |
|
| 1014 | - |
|
| 1015 | - // Pre WC 2.0 |
|
| 1016 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1017 | - |
|
| 1018 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1019 | - |
|
| 1020 | - } else { |
|
| 1021 | - |
|
| 1022 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1023 | - |
|
| 1024 | - } // End If Statement |
|
| 1025 | - |
|
| 1026 | - } // End If Statement |
|
| 1027 | - |
|
| 1028 | - } // End If Statement |
|
| 1029 | - |
|
| 1030 | - return $wc_product_object; |
|
| 1031 | - |
|
| 1032 | - } // End sensei_get_woocommerce_product_object() |
|
| 1033 | - |
|
| 1034 | - /** |
|
| 1035 | - * load_class loads in class files |
|
| 1036 | - * @since 1.2.0 |
|
| 1037 | - * @access public |
|
| 1038 | - * @return void |
|
| 1039 | - */ |
|
| 1040 | - public function load_class ( $class_name = '' ) { |
|
| 1041 | - if ( '' != $class_name && '' != $this->token ) { |
|
| 1042 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1043 | - } // End If Statement |
|
| 1044 | - } // End load_class() |
|
| 1045 | - |
|
| 1046 | - /** |
|
| 1047 | - * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1048 | - * @since 1.2.0 |
|
| 1049 | - * @access public |
|
| 1050 | - * @param integer $order_id order ID |
|
| 1051 | - * @return void |
|
| 1052 | - */ |
|
| 1053 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1054 | - if ( 0 < intval( $order_id ) ) { |
|
| 1055 | - $order = new WC_Order( $order_id ); |
|
| 1056 | - $user = get_user_by('id', $order->user_id); |
|
| 1057 | - $order_user['ID'] = $user->ID; |
|
| 1058 | - $order_user['user_login'] = $user->user_login; |
|
| 1059 | - $order_user['user_email'] = $user->user_email; |
|
| 1060 | - $order_user['user_url'] = $user->user_url; |
|
| 1061 | - // Run through each product ordered |
|
| 1062 | - if (sizeof($order->get_items())>0) { |
|
| 1063 | - foreach($order->get_items() as $item) { |
|
| 1064 | - $product_type = ''; |
|
| 1065 | - if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1066 | - $item_id = $item['variation_id']; |
|
| 1067 | - $product_type = 'subscription_variation'; |
|
| 1068 | - } else { |
|
| 1069 | - $item_id = $item['product_id']; |
|
| 1070 | - } // End If Statement |
|
| 1071 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1072 | - // Get courses that use the WC product |
|
| 1073 | - $courses = array(); |
|
| 1074 | - if ( $product_type == 'subscription_variation' ) { |
|
| 1075 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1076 | - } // End If Statement |
|
| 1077 | - // Loop and update those courses |
|
| 1078 | - foreach ($courses as $course_item){ |
|
| 1079 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1080 | - } // End For Loop |
|
| 1081 | - } // End For Loop |
|
| 1082 | - } // End If Statement |
|
| 1083 | - } // End If Statement |
|
| 1084 | - } // End sensei_activate_subscription() |
|
| 1085 | - |
|
| 1086 | - /** |
|
| 1087 | - * sensei_woocommerce_email_course_details adds detail to email |
|
| 1088 | - * @since 1.4.5 |
|
| 1089 | - * @access public |
|
| 1090 | - * @param WC_Order $order |
|
| 1091 | - * @return void |
|
| 1092 | - */ |
|
| 1093 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1094 | - global $woocommerce; |
|
| 1095 | - |
|
| 1096 | - // exit early if not wc-completed or wc-processing |
|
| 1097 | - if( 'wc-completed' != $order->post_status |
|
| 1098 | - && 'wc-processing' != $order->post_status ) { |
|
| 1099 | - return; |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - $order_items = $order->get_items(); |
|
| 1103 | - $order_id = $order->id; |
|
| 1104 | - |
|
| 1105 | - //If object have items go through them all to find course |
|
| 1106 | - if ( 0 < sizeof( $order_items ) ) { |
|
| 1107 | - |
|
| 1108 | - echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1109 | - |
|
| 1110 | - foreach ( $order_items as $item ) { |
|
| 1111 | - |
|
| 1112 | - $product_type = ''; |
|
| 1113 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1114 | - // If item has variation_id then its from variation |
|
| 1115 | - $item_id = $item['variation_id']; |
|
| 1116 | - $product_type = 'variation'; |
|
| 1117 | - } else { |
|
| 1118 | - // If not its real product set its id to item_id |
|
| 1119 | - $item_id = $item['product_id']; |
|
| 1120 | - } // End If Statement |
|
| 1121 | - |
|
| 1122 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1123 | - |
|
| 1124 | - if( $user_id ) { |
|
| 1125 | - |
|
| 1126 | - // Get all courses for product |
|
| 1127 | - $args = array( |
|
| 1128 | - 'posts_per_page' => -1, |
|
| 1129 | - 'post_type' => 'course', |
|
| 1130 | - 'meta_query' => array( |
|
| 1131 | - array( |
|
| 1132 | - 'key' => '_course_woocommerce_product', |
|
| 1133 | - 'value' => $item_id |
|
| 1134 | - ) |
|
| 1135 | - ), |
|
| 1136 | - 'orderby' => 'menu_order date', |
|
| 1137 | - 'order' => 'ASC', |
|
| 1138 | - ); |
|
| 1139 | - $courses = get_posts( $args ); |
|
| 1140 | - |
|
| 1141 | - if( $courses && count( $courses ) > 0 ) { |
|
| 1142 | - |
|
| 1143 | - foreach( $courses as $course ) { |
|
| 1144 | - |
|
| 1145 | - $title = $course->post_title; |
|
| 1146 | - $permalink = get_permalink( $course->ID ); |
|
| 1147 | - |
|
| 1148 | - echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - } |
|
| 1152 | - } |
|
| 1153 | - } |
|
| 1154 | - } |
|
| 1155 | - |
|
| 1156 | - /** |
|
| 1157 | - * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 1158 | - * @since 1.4.0 |
|
| 1159 | - * @access public |
|
| 1160 | - * @param array $comments |
|
| 1161 | - * @param integer $post_id |
|
| 1162 | - * @return array |
|
| 1163 | - */ |
|
| 1164 | - public function sensei_count_comments( $comments, $post_id ) { |
|
| 1165 | - global $wpdb; |
|
| 1166 | - |
|
| 1167 | - $post_id = (int) $post_id; |
|
| 1168 | - |
|
| 1169 | - $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 1170 | - |
|
| 1171 | - if ( false !== $count ) { |
|
| 1172 | - return $count; |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - $statuses = array( '' ); // Default to the WP normal comments |
|
| 1176 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1177 | - foreach ( (array) $stati AS $status ) { |
|
| 1178 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1179 | - $statuses[] = $status['comment_type']; |
|
| 1180 | - } |
|
| 1181 | - } |
|
| 1182 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1183 | - |
|
| 1184 | - if ( $post_id > 0 ) |
|
| 1185 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1186 | - |
|
| 1187 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1188 | - |
|
| 1189 | - $total = 0; |
|
| 1190 | - $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 1191 | - foreach ( (array) $count as $row ) { |
|
| 1192 | - // Don't count post-trashed toward totals |
|
| 1193 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1194 | - $total += $row['num_comments']; |
|
| 1195 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1196 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1197 | - } |
|
| 1198 | - |
|
| 1199 | - $stats['total_comments'] = $total; |
|
| 1200 | - foreach ( $approved as $key ) { |
|
| 1201 | - if ( empty($stats[$key]) ) |
|
| 1202 | - $stats[$key] = 0; |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - $stats = (object) $stats; |
|
| 1206 | - wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 1207 | - |
|
| 1208 | - return $stats; |
|
| 1209 | - } |
|
| 1210 | - |
|
| 1211 | - /** |
|
| 1212 | - * Init images. |
|
| 1213 | - * |
|
| 1214 | - * @since 1.4.5 |
|
| 1215 | - * @access public |
|
| 1216 | - * @return void |
|
| 1217 | - */ |
|
| 1218 | - public function init_image_sizes() { |
|
| 1219 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1220 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1221 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1222 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1223 | - |
|
| 1224 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1225 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1226 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1227 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - /** |
|
| 1231 | - * Get an image size. |
|
| 1232 | - * |
|
| 1233 | - * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 1234 | - * |
|
| 1235 | - * @since 1.4.5 |
|
| 1236 | - * @access public |
|
| 1237 | - * @param mixed $image_size |
|
| 1238 | - * @return string |
|
| 1239 | - */ |
|
| 1240 | - public function get_image_size( $image_size ) { |
|
| 1241 | - |
|
| 1242 | - // Only return sizes we define in settings |
|
| 1243 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1244 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1245 | - |
|
| 1246 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1247 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1248 | - } |
|
| 1249 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1250 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1251 | - } |
|
| 1252 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1253 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - $size = array_filter( array( |
|
| 1257 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1258 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1259 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1260 | - ) ); |
|
| 1261 | - |
|
| 1262 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1263 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1264 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1265 | - |
|
| 1266 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - public function body_class( $classes ) { |
|
| 1270 | - if( is_sensei() ) { |
|
| 1271 | - $classes[] = 'sensei'; |
|
| 1272 | - } |
|
| 1273 | - return $classes; |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 1278 | - * |
|
| 1279 | - * @return null |
|
| 1280 | - * @since 1.7.0 |
|
| 1281 | - */ |
|
| 1282 | - public function jetpack_latex_support() { |
|
| 1283 | - if ( function_exists( 'latex_markup') ) { |
|
| 1284 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1285 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1286 | - } |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - /** |
|
| 1290 | - * Load the module functionality. |
|
| 1291 | - * |
|
| 1292 | - * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 1293 | - * the retired modules extension. |
|
| 1294 | - * |
|
| 1295 | - * @since 1.8.0 |
|
| 1296 | - */ |
|
| 1297 | - public function load_modules_class(){ |
|
| 1298 | - global $sensei_modules; |
|
| 1299 | - |
|
| 1300 | - if( !class_exists( 'Sensei_Modules' ) |
|
| 1301 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1302 | - |
|
| 1303 | - //Load the modules class |
|
| 1304 | - require_once( 'class-sensei-modules.php'); |
|
| 1305 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1306 | - |
|
| 1307 | - }else{ |
|
| 1308 | - // fallback for people still using the modules extension. |
|
| 1309 | - global $sensei_modules; |
|
| 1310 | - Sensei()->modules = $sensei_modules; |
|
| 1311 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - /** |
|
| 1316 | - * Tell the user to that the modules extension is no longer needed. |
|
| 1317 | - * |
|
| 1318 | - * @since 1.8.0 |
|
| 1319 | - */ |
|
| 1320 | - public function disable_sensei_modules_extension(){ ?> |
|
| 308 | + /** |
|
| 309 | + * This function is linked into the activation |
|
| 310 | + * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 311 | + * |
|
| 312 | + * @since 1.9.0 |
|
| 313 | + * |
|
| 314 | + * @param $plugin |
|
| 315 | + */ |
|
| 316 | + public static function activation_flush_rules( $plugin ){ |
|
| 317 | + |
|
| 318 | + if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 319 | + |
|
| 320 | + flush_rewrite_rules(true); |
|
| 321 | + |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Global Sensei Instance |
|
| 328 | + * |
|
| 329 | + * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 330 | + * |
|
| 331 | + * @since 1.8.0 |
|
| 332 | + * @static |
|
| 333 | + * @see WC() |
|
| 334 | + * @return WooThemes_Sensei Instance. |
|
| 335 | + */ |
|
| 336 | + public static function instance() { |
|
| 337 | + |
|
| 338 | + if ( is_null( self::$_instance ) ) { |
|
| 339 | + |
|
| 340 | + //Sensei requires a reference to the main Sensei plugin file |
|
| 341 | + $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 342 | + |
|
| 343 | + self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 344 | + |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return self::$_instance; |
|
| 348 | + |
|
| 349 | + } // end instance() |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Cloning is forbidden. |
|
| 353 | + * @since 1.8.0 |
|
| 354 | + */ |
|
| 355 | + public function __clone() { |
|
| 356 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Unserializing instances of this class is forbidden. |
|
| 361 | + * @since 1.8.0 |
|
| 362 | + */ |
|
| 363 | + public function __wakeup() { |
|
| 364 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Run Sensei updates. |
|
| 369 | + * @access public |
|
| 370 | + * @since 1.1.0 |
|
| 371 | + * @return void |
|
| 372 | + */ |
|
| 373 | + public function run_updates() { |
|
| 374 | + // Run updates if administrator |
|
| 375 | + if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 376 | + |
|
| 377 | + $this->updates->update(); |
|
| 378 | + |
|
| 379 | + } // End If Statement |
|
| 380 | + } // End run_updates() |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Setup required WooCommerce settings. |
|
| 384 | + * @access public |
|
| 385 | + * @since 1.1.0 |
|
| 386 | + * @return void |
|
| 387 | + */ |
|
| 388 | + public function set_woocommerce_functionality() { |
|
| 389 | + // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
|
| 390 | + add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 391 | + |
|
| 392 | + // Mark orders with virtual products as complete rather then stay processing |
|
| 393 | + add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 394 | + |
|
| 395 | + } // End set_woocommerce_functionality() |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Disable guest checkout if a course product is in the cart |
|
| 399 | + * @param boolean $guest_checkout Current guest checkout setting |
|
| 400 | + * @return boolean Modified guest checkout setting |
|
| 401 | + */ |
|
| 402 | + public function disable_guest_checkout( $guest_checkout ) { |
|
| 403 | + global $woocommerce; |
|
| 404 | + |
|
| 405 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 406 | + |
|
| 407 | + if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 408 | + foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 409 | + if( isset( $product['product_id'] ) ) { |
|
| 410 | + $args = array( |
|
| 411 | + 'posts_per_page' => -1, |
|
| 412 | + 'post_type' => 'course', |
|
| 413 | + 'meta_query' => array( |
|
| 414 | + array( |
|
| 415 | + 'key' => '_course_woocommerce_product', |
|
| 416 | + 'value' => $product['product_id'] |
|
| 417 | + ) |
|
| 418 | + ) |
|
| 419 | + ); |
|
| 420 | + $posts = get_posts( $args ); |
|
| 421 | + if( $posts && count( $posts ) > 0 ) { |
|
| 422 | + foreach( $posts as $course ) { |
|
| 423 | + $guest_checkout = ''; |
|
| 424 | + break; |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + return $guest_checkout; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Change order status with virtual products to completed |
|
| 437 | + * @since 1.1.0 |
|
| 438 | + * @param string $order_status |
|
| 439 | + * @param int $order_id |
|
| 440 | + * @return string |
|
| 441 | + **/ |
|
| 442 | + public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 443 | + $order = new WC_Order( $order_id ); |
|
| 444 | + if ( ! isset ( $order ) ) return; |
|
| 445 | + if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 446 | + $virtual_order = true; |
|
| 447 | + |
|
| 448 | + if ( count( $order->get_items() ) > 0 ) { |
|
| 449 | + foreach( $order->get_items() as $item ) { |
|
| 450 | + if ( $item['product_id'] > 0 ) { |
|
| 451 | + $_product = $order->get_product_from_item( $item ); |
|
| 452 | + if ( ! $_product->is_virtual() ) { |
|
| 453 | + $virtual_order = false; |
|
| 454 | + break; |
|
| 455 | + } // End If Statement |
|
| 456 | + } // End If Statement |
|
| 457 | + } // End For Loop |
|
| 458 | + } // End If Statement |
|
| 459 | + |
|
| 460 | + // virtual order, mark as completed |
|
| 461 | + if ( $virtual_order ) { |
|
| 462 | + return 'completed'; |
|
| 463 | + } // End If Statement |
|
| 464 | + } // End If Statement |
|
| 465 | + return $order_status; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Register the widgets. |
|
| 470 | + * @access public |
|
| 471 | + * @since 1.0.0 |
|
| 472 | + * @return void |
|
| 473 | + */ |
|
| 474 | + public function register_widgets () { |
|
| 475 | + // Widget List (key => value is filename => widget class). |
|
| 476 | + $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 477 | + 'lesson-component' => 'Lesson_Component', |
|
| 478 | + 'course-categories' => 'Course_Categories', |
|
| 479 | + 'category-courses' => 'Category_Courses' ) |
|
| 480 | + ); |
|
| 481 | + foreach ( $widget_list as $key => $value ) { |
|
| 482 | + if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ) ) { |
|
| 483 | + require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ); |
|
| 484 | + register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 485 | + } |
|
| 486 | + } // End For Loop |
|
| 487 | + |
|
| 488 | + do_action( 'sensei_register_widgets' ); |
|
| 489 | + } // End register_widgets() |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Load the plugin's localisation file. |
|
| 493 | + * @access public |
|
| 494 | + * @since 1.0.0 |
|
| 495 | + * @return void |
|
| 496 | + */ |
|
| 497 | + public function load_localisation () { |
|
| 498 | + load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 499 | + } // End load_localisation() |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 503 | + * @access public |
|
| 504 | + * @since 1.0.0 |
|
| 505 | + * @return void |
|
| 506 | + */ |
|
| 507 | + public function load_plugin_textdomain () { |
|
| 508 | + $domain = 'woothemes-sensei'; |
|
| 509 | + // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 510 | + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 511 | + load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 512 | + load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 513 | + } // End load_plugin_textdomain() |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Run on activation. |
|
| 517 | + * @access public |
|
| 518 | + * @since 1.0.0 |
|
| 519 | + * @return void |
|
| 520 | + */ |
|
| 521 | + public function activation () { |
|
| 522 | + $this->register_plugin_version(); |
|
| 523 | + } // End activation() |
|
| 524 | + |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Register activation hooks. |
|
| 528 | + * @access public |
|
| 529 | + * @since 1.0.0 |
|
| 530 | + * @return void |
|
| 531 | + */ |
|
| 532 | + public function install () { |
|
| 533 | + register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 534 | + register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 535 | + } // End install() |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Run on activation of the plugin. |
|
| 540 | + * @access public |
|
| 541 | + * @since 1.0.0 |
|
| 542 | + * @return void |
|
| 543 | + */ |
|
| 544 | + public function activate_sensei () { |
|
| 545 | + update_option( 'skip_install_sensei_pages', 0 ); |
|
| 546 | + update_option( 'sensei_installed', 1 ); |
|
| 547 | + } // End activate_sensei() |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Register the plugin's version. |
|
| 551 | + * @access public |
|
| 552 | + * @since 1.0.0 |
|
| 553 | + * @return void |
|
| 554 | + */ |
|
| 555 | + private function register_plugin_version () { |
|
| 556 | + if ( $this->version != '' ) { |
|
| 557 | + |
|
| 558 | + // Check previous version to see if forced updates must run |
|
| 559 | + // $old_version = get_option( 'woothemes-sensei-version', false ); |
|
| 560 | + // if( $old_version && version_compare( $old_version, '1.7.0', '<' ) ) { |
|
| 561 | + // update_option( 'woothemes-sensei-force-updates', $this->version ); |
|
| 562 | + // } else { |
|
| 563 | + // delete_option( 'woothemes-sensei-force-updates' ); |
|
| 564 | + // } |
|
| 565 | + |
|
| 566 | + update_option( 'woothemes-sensei-version', $this->version ); |
|
| 567 | + } |
|
| 568 | + } // End register_plugin_version() |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 572 | + * @access public |
|
| 573 | + * @since 1.0.1 |
|
| 574 | + * @return void |
|
| 575 | + */ |
|
| 576 | + public function ensure_post_thumbnails_support () { |
|
| 577 | + if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 578 | + } // End ensure_post_thumbnails_support() |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * template_loader function. |
|
| 583 | + * |
|
| 584 | + * @access public |
|
| 585 | + * @param mixed $template |
|
| 586 | + * @return void |
|
| 587 | + * @deprecated |
|
| 588 | + */ |
|
| 589 | + public function template_loader ( $template = '' ) { |
|
| 590 | + |
|
| 591 | + _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 592 | + return Sensei_Templates::template_loader( $template ); |
|
| 593 | + |
|
| 594 | + } // End template_loader() |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Determine the relative path to the plugin's directory. |
|
| 598 | + * @access public |
|
| 599 | + * @since 1.0.0 |
|
| 600 | + * @return string $sensei_plugin_path |
|
| 601 | + */ |
|
| 602 | + public function plugin_path () { |
|
| 603 | + |
|
| 604 | + if ( $this->plugin_path ) { |
|
| 605 | + |
|
| 606 | + $sensei_plugin_path = $this->plugin_path; |
|
| 607 | + |
|
| 608 | + }else{ |
|
| 609 | + |
|
| 610 | + $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 611 | + |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + return $sensei_plugin_path; |
|
| 615 | + |
|
| 616 | + } // End plugin_path() |
|
| 617 | + |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Retrieve the ID of a specified page setting. |
|
| 621 | + * @access public |
|
| 622 | + * @since 1.0.0 |
|
| 623 | + * @param string $page |
|
| 624 | + * @return int |
|
| 625 | + */ |
|
| 626 | + public function get_page_id ( $page ) { |
|
| 627 | + $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 628 | + return ( $page ) ? $page : -1; |
|
| 629 | + } // End get_page_id() |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 634 | + * @access public |
|
| 635 | + * @since 1.0.0 |
|
| 636 | + * @param int $course_id (default: 0) |
|
| 637 | + * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 638 | + * @return void |
|
| 639 | + */ |
|
| 640 | + public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 641 | + global $current_user; |
|
| 642 | + |
|
| 643 | + if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return; |
|
| 644 | + |
|
| 645 | + $data_update = false; |
|
| 646 | + |
|
| 647 | + // Get the product ID |
|
| 648 | + $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 649 | + |
|
| 650 | + // Check if in the admin |
|
| 651 | + if ( is_admin() ) { |
|
| 652 | + $user_login = $order_user['user_login']; |
|
| 653 | + $user_email = $order_user['user_email']; |
|
| 654 | + $user_url = $order_user['user_url']; |
|
| 655 | + $user_id = $order_user['ID']; |
|
| 656 | + } else { |
|
| 657 | + $user_login = $current_user->user_login; |
|
| 658 | + $user_email = $current_user->user_email; |
|
| 659 | + $user_url = $current_user->user_url; |
|
| 660 | + $user_id = $current_user->ID; |
|
| 661 | + } // End If Statement |
|
| 662 | + |
|
| 663 | + // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 664 | + $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 665 | + if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 666 | + $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 667 | + if ( ! $prereq_course_complete ) { |
|
| 668 | + // Remove all course user meta |
|
| 669 | + return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 674 | + |
|
| 675 | + if( ! $is_user_taking_course ) { |
|
| 676 | + |
|
| 677 | + if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 678 | + |
|
| 679 | + $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 680 | + |
|
| 681 | + $is_user_taking_course = false; |
|
| 682 | + if ( true == $activity_logged ) { |
|
| 683 | + $is_user_taking_course = true; |
|
| 684 | + } // End If Statement |
|
| 685 | + } // End If Statement |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + return $is_user_taking_course; |
|
| 689 | + } // End woocommerce_course_update() |
|
| 690 | + |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * check_user_permissions function. |
|
| 694 | + * |
|
| 695 | + * @access public |
|
| 696 | + * @param string $page (default: '') |
|
| 697 | + * @param array $data (default: array()) |
|
| 698 | + * @return bool |
|
| 699 | + */ |
|
| 700 | + public function check_user_permissions ( $page = '', $data = array() ) { |
|
| 701 | + // REFACTOR |
|
| 702 | + global $current_user, $post; |
|
| 703 | + |
|
| 704 | + // if use is not logged in |
|
| 705 | + if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){ |
|
| 706 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 707 | + $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 708 | + return; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + // Get User Meta |
|
| 713 | + get_currentuserinfo(); |
|
| 714 | + |
|
| 715 | + $user_allowed = false; |
|
| 716 | + |
|
| 717 | + switch ( $page ) { |
|
| 718 | + case 'course-single': |
|
| 719 | + // check for prerequisite course or lesson, |
|
| 720 | + $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 721 | + $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 722 | + // Count completed lessons |
|
| 723 | + if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 724 | + |
|
| 725 | + $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 726 | + |
|
| 727 | + } |
|
| 728 | + else { |
|
| 729 | + $prerequisite_complete = true; |
|
| 730 | + } // End If Statement |
|
| 731 | + // Handles restrictions |
|
| 732 | + if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 733 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 734 | + $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 735 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 736 | + } else { |
|
| 737 | + $user_allowed = true; |
|
| 738 | + } // End If Statement |
|
| 739 | + break; |
|
| 740 | + case 'lesson-single': |
|
| 741 | + // Check for WC purchase |
|
| 742 | + $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 743 | + |
|
| 744 | + $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 745 | + $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 746 | + if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 747 | + $user_allowed = true; |
|
| 748 | + } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 749 | + |
|
| 750 | + $user_allowed = true; |
|
| 751 | + } else { |
|
| 752 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 753 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 754 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 755 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 756 | + if ( $is_preview ) { |
|
| 757 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 758 | + } else { |
|
| 759 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 760 | + } |
|
| 761 | + } else { |
|
| 762 | + if ( $is_preview ) { |
|
| 763 | + $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 ); |
|
| 764 | + } else { |
|
| 765 | + /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 766 | + $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 767 | + } |
|
| 768 | + } // End If Statement |
|
| 769 | + } // End If Statement |
|
| 770 | + break; |
|
| 771 | + case 'quiz-single': |
|
| 772 | + $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 773 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 774 | + |
|
| 775 | + $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 776 | + if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 777 | + |
|
| 778 | + // Check for prerequisite lesson for this quiz |
|
| 779 | + $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 780 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 781 | + |
|
| 782 | + // Handle restrictions |
|
| 783 | + if( sensei_all_access() ) { |
|
| 784 | + $user_allowed = true; |
|
| 785 | + } else { |
|
| 786 | + if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 787 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 788 | + $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 789 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 790 | + } else { |
|
| 791 | + $user_allowed = true; |
|
| 792 | + } // End If Statement |
|
| 793 | + } // End If Statement |
|
| 794 | + } elseif( $this->access_settings() ) { |
|
| 795 | + // Check if the user has started the course |
|
| 796 | + |
|
| 797 | + 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'] ) ) ) { |
|
| 798 | + |
|
| 799 | + $user_allowed = false; |
|
| 800 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 801 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 802 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 803 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 804 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 805 | + } else { |
|
| 806 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 807 | + } // End If Statement |
|
| 808 | + } else { |
|
| 809 | + $user_allowed = true; |
|
| 810 | + } // End If Statement |
|
| 811 | + } else { |
|
| 812 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 813 | + $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>'; |
|
| 814 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 815 | + } // End If Statement |
|
| 816 | + break; |
|
| 817 | + default: |
|
| 818 | + $user_allowed = true; |
|
| 819 | + break; |
|
| 820 | + |
|
| 821 | + } // End Switch Statement |
|
| 822 | + |
|
| 823 | + /** |
|
| 824 | + * filter the permissions message shown on sensei post types. |
|
| 825 | + * |
|
| 826 | + * @since 1.8.7 |
|
| 827 | + * |
|
| 828 | + * @param array $permissions_message{ |
|
| 829 | + * |
|
| 830 | + * @type string $title |
|
| 831 | + * @type string $message |
|
| 832 | + * |
|
| 833 | + * } |
|
| 834 | + * @param string $post_id |
|
| 835 | + */ |
|
| 836 | + $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 840 | + $user_allowed = true; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 844 | + } // End get_placeholder_image() |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 849 | + * @since 1.0.0 |
|
| 850 | + * @access public |
|
| 851 | + * @return void |
|
| 852 | + */ |
|
| 853 | + public function access_settings () { |
|
| 854 | + |
|
| 855 | + if( sensei_all_access() ) return true; |
|
| 856 | + |
|
| 857 | + if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 858 | + if ( is_user_logged_in() ) { |
|
| 859 | + return true; |
|
| 860 | + } else { |
|
| 861 | + return false; |
|
| 862 | + } // End If Statement |
|
| 863 | + } else { |
|
| 864 | + return true; |
|
| 865 | + } // End If Statement |
|
| 866 | + } // End access_settings() |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * sensei_woocommerce_complete_order description |
|
| 870 | + * @since 1.0.3 |
|
| 871 | + * @access public |
|
| 872 | + * @param int $order_id WC order ID |
|
| 873 | + * @return void |
|
| 874 | + */ |
|
| 875 | + public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 876 | + $order_user = array(); |
|
| 877 | + // Check for WooCommerce |
|
| 878 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 879 | + // Get order object |
|
| 880 | + $order = new WC_Order( $order_id ); |
|
| 881 | + $user = get_user_by( 'id', $order->user_id ); |
|
| 882 | + $order_user['ID'] = $user->ID; |
|
| 883 | + $order_user['user_login'] = $user->user_login; |
|
| 884 | + $order_user['user_email'] = $user->user_email; |
|
| 885 | + $order_user['user_url'] = $user->user_url; |
|
| 886 | + // Run through each product ordered |
|
| 887 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 888 | + foreach( $order->get_items() as $item ) { |
|
| 889 | + $product_type = ''; |
|
| 890 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 891 | + $item_id = $item['variation_id']; |
|
| 892 | + $product_type = 'variation'; |
|
| 893 | + } else { |
|
| 894 | + $item_id = $item['product_id']; |
|
| 895 | + } // End If Statement |
|
| 896 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 897 | + // Get courses that use the WC product |
|
| 898 | + $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 899 | + // Loop and update those courses |
|
| 900 | + foreach ( $courses as $course_item ) { |
|
| 901 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 902 | + } // End For Loop |
|
| 903 | + } // End For Loop |
|
| 904 | + } // End If Statement |
|
| 905 | + // Add meta to indicate that payment has been completed successfully |
|
| 906 | + update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 907 | + } // End If Statement |
|
| 908 | + } // End sensei_woocommerce_complete_order() |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * Runs when an order is cancelled. |
|
| 912 | + * @since 1.2.0 |
|
| 913 | + * @access public |
|
| 914 | + * @param integer $order_id order ID |
|
| 915 | + * @return void |
|
| 916 | + */ |
|
| 917 | + public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 918 | + |
|
| 919 | + // Get order object |
|
| 920 | + $order = new WC_Order( $order_id ); |
|
| 921 | + |
|
| 922 | + // Run through each product ordered |
|
| 923 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 924 | + |
|
| 925 | + // Get order user |
|
| 926 | + $user_id = $order->__get( 'user_id' ); |
|
| 927 | + |
|
| 928 | + foreach( $order->get_items() as $item ) { |
|
| 929 | + |
|
| 930 | + $product_type = ''; |
|
| 931 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 932 | + $item_id = $item['variation_id']; |
|
| 933 | + $product_type = 'variation'; |
|
| 934 | + } else { |
|
| 935 | + $item_id = $item['product_id']; |
|
| 936 | + } // End If Statement |
|
| 937 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 938 | + |
|
| 939 | + // Get courses that use the WC product |
|
| 940 | + $courses = array(); |
|
| 941 | + $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 942 | + |
|
| 943 | + // Loop and update those courses |
|
| 944 | + foreach ($courses as $course_item){ |
|
| 945 | + // Check and Remove course from courses user meta |
|
| 946 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 947 | + } // End For Loop |
|
| 948 | + } // End For Loop |
|
| 949 | + } // End If Statement |
|
| 950 | + } // End sensei_woocommerce_cancel_order() |
|
| 951 | + |
|
| 952 | + /** |
|
| 953 | + * Runs when an subscription is cancelled or expires. |
|
| 954 | + * @since 1.3.3 |
|
| 955 | + * @access public |
|
| 956 | + * @param integer $user_id User ID |
|
| 957 | + * @param integer $subscription_key Subscription Unique Key |
|
| 958 | + * @return void |
|
| 959 | + */ |
|
| 960 | + public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 961 | + $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 962 | + self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * Runs when an subscription is re-activated after suspension. |
|
| 967 | + * @since 1.3.3 |
|
| 968 | + * @access public |
|
| 969 | + * @param integer $user_id User ID |
|
| 970 | + * @param integer $subscription_key Subscription Unique Key |
|
| 971 | + * @return void |
|
| 972 | + */ |
|
| 973 | + public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 974 | + $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 975 | + $order = new WC_Order( $subscription['order_id'] ); |
|
| 976 | + $user = get_user_by( 'id', $order->user_id ); |
|
| 977 | + $order_user = array(); |
|
| 978 | + $order_user['ID'] = $user->ID; |
|
| 979 | + $order_user['user_login'] = $user->user_login; |
|
| 980 | + $order_user['user_email'] = $user->user_email; |
|
| 981 | + $order_user['user_url'] = $user->user_url; |
|
| 982 | + $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 983 | + foreach ( $courses as $course_item ){ |
|
| 984 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 985 | + } // End For Loop |
|
| 986 | + } // End sensei_woocommerce_reactivate_subscription |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Returns the WooCommerce Product Object |
|
| 990 | + * |
|
| 991 | + * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 992 | + * |
|
| 993 | + * @since 1.1.1 |
|
| 994 | + * @access public |
|
| 995 | + * @param integer $wc_product_id Product ID or Variation ID |
|
| 996 | + * @param string $product_type '' or 'variation' |
|
| 997 | + * @return WC_Product $wc_product_object |
|
| 998 | + */ |
|
| 999 | + public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1000 | + |
|
| 1001 | + $wc_product_object = false; |
|
| 1002 | + if ( 0 < intval( $wc_product_id ) ) { |
|
| 1003 | + |
|
| 1004 | + // Get the product |
|
| 1005 | + if ( function_exists( 'wc_get_product' ) ) { |
|
| 1006 | + |
|
| 1007 | + $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1008 | + |
|
| 1009 | + } elseif ( function_exists( 'get_product' ) ) { |
|
| 1010 | + |
|
| 1011 | + $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1012 | + |
|
| 1013 | + } else { |
|
| 1014 | + |
|
| 1015 | + // Pre WC 2.0 |
|
| 1016 | + if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1017 | + |
|
| 1018 | + $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1019 | + |
|
| 1020 | + } else { |
|
| 1021 | + |
|
| 1022 | + $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1023 | + |
|
| 1024 | + } // End If Statement |
|
| 1025 | + |
|
| 1026 | + } // End If Statement |
|
| 1027 | + |
|
| 1028 | + } // End If Statement |
|
| 1029 | + |
|
| 1030 | + return $wc_product_object; |
|
| 1031 | + |
|
| 1032 | + } // End sensei_get_woocommerce_product_object() |
|
| 1033 | + |
|
| 1034 | + /** |
|
| 1035 | + * load_class loads in class files |
|
| 1036 | + * @since 1.2.0 |
|
| 1037 | + * @access public |
|
| 1038 | + * @return void |
|
| 1039 | + */ |
|
| 1040 | + public function load_class ( $class_name = '' ) { |
|
| 1041 | + if ( '' != $class_name && '' != $this->token ) { |
|
| 1042 | + require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1043 | + } // End If Statement |
|
| 1044 | + } // End load_class() |
|
| 1045 | + |
|
| 1046 | + /** |
|
| 1047 | + * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1048 | + * @since 1.2.0 |
|
| 1049 | + * @access public |
|
| 1050 | + * @param integer $order_id order ID |
|
| 1051 | + * @return void |
|
| 1052 | + */ |
|
| 1053 | + public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1054 | + if ( 0 < intval( $order_id ) ) { |
|
| 1055 | + $order = new WC_Order( $order_id ); |
|
| 1056 | + $user = get_user_by('id', $order->user_id); |
|
| 1057 | + $order_user['ID'] = $user->ID; |
|
| 1058 | + $order_user['user_login'] = $user->user_login; |
|
| 1059 | + $order_user['user_email'] = $user->user_email; |
|
| 1060 | + $order_user['user_url'] = $user->user_url; |
|
| 1061 | + // Run through each product ordered |
|
| 1062 | + if (sizeof($order->get_items())>0) { |
|
| 1063 | + foreach($order->get_items() as $item) { |
|
| 1064 | + $product_type = ''; |
|
| 1065 | + if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1066 | + $item_id = $item['variation_id']; |
|
| 1067 | + $product_type = 'subscription_variation'; |
|
| 1068 | + } else { |
|
| 1069 | + $item_id = $item['product_id']; |
|
| 1070 | + } // End If Statement |
|
| 1071 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1072 | + // Get courses that use the WC product |
|
| 1073 | + $courses = array(); |
|
| 1074 | + if ( $product_type == 'subscription_variation' ) { |
|
| 1075 | + $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1076 | + } // End If Statement |
|
| 1077 | + // Loop and update those courses |
|
| 1078 | + foreach ($courses as $course_item){ |
|
| 1079 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1080 | + } // End For Loop |
|
| 1081 | + } // End For Loop |
|
| 1082 | + } // End If Statement |
|
| 1083 | + } // End If Statement |
|
| 1084 | + } // End sensei_activate_subscription() |
|
| 1085 | + |
|
| 1086 | + /** |
|
| 1087 | + * sensei_woocommerce_email_course_details adds detail to email |
|
| 1088 | + * @since 1.4.5 |
|
| 1089 | + * @access public |
|
| 1090 | + * @param WC_Order $order |
|
| 1091 | + * @return void |
|
| 1092 | + */ |
|
| 1093 | + public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1094 | + global $woocommerce; |
|
| 1095 | + |
|
| 1096 | + // exit early if not wc-completed or wc-processing |
|
| 1097 | + if( 'wc-completed' != $order->post_status |
|
| 1098 | + && 'wc-processing' != $order->post_status ) { |
|
| 1099 | + return; |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + $order_items = $order->get_items(); |
|
| 1103 | + $order_id = $order->id; |
|
| 1104 | + |
|
| 1105 | + //If object have items go through them all to find course |
|
| 1106 | + if ( 0 < sizeof( $order_items ) ) { |
|
| 1107 | + |
|
| 1108 | + echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1109 | + |
|
| 1110 | + foreach ( $order_items as $item ) { |
|
| 1111 | + |
|
| 1112 | + $product_type = ''; |
|
| 1113 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1114 | + // If item has variation_id then its from variation |
|
| 1115 | + $item_id = $item['variation_id']; |
|
| 1116 | + $product_type = 'variation'; |
|
| 1117 | + } else { |
|
| 1118 | + // If not its real product set its id to item_id |
|
| 1119 | + $item_id = $item['product_id']; |
|
| 1120 | + } // End If Statement |
|
| 1121 | + |
|
| 1122 | + $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1123 | + |
|
| 1124 | + if( $user_id ) { |
|
| 1125 | + |
|
| 1126 | + // Get all courses for product |
|
| 1127 | + $args = array( |
|
| 1128 | + 'posts_per_page' => -1, |
|
| 1129 | + 'post_type' => 'course', |
|
| 1130 | + 'meta_query' => array( |
|
| 1131 | + array( |
|
| 1132 | + 'key' => '_course_woocommerce_product', |
|
| 1133 | + 'value' => $item_id |
|
| 1134 | + ) |
|
| 1135 | + ), |
|
| 1136 | + 'orderby' => 'menu_order date', |
|
| 1137 | + 'order' => 'ASC', |
|
| 1138 | + ); |
|
| 1139 | + $courses = get_posts( $args ); |
|
| 1140 | + |
|
| 1141 | + if( $courses && count( $courses ) > 0 ) { |
|
| 1142 | + |
|
| 1143 | + foreach( $courses as $course ) { |
|
| 1144 | + |
|
| 1145 | + $title = $course->post_title; |
|
| 1146 | + $permalink = get_permalink( $course->ID ); |
|
| 1147 | + |
|
| 1148 | + echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1152 | + } |
|
| 1153 | + } |
|
| 1154 | + } |
|
| 1155 | + |
|
| 1156 | + /** |
|
| 1157 | + * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 1158 | + * @since 1.4.0 |
|
| 1159 | + * @access public |
|
| 1160 | + * @param array $comments |
|
| 1161 | + * @param integer $post_id |
|
| 1162 | + * @return array |
|
| 1163 | + */ |
|
| 1164 | + public function sensei_count_comments( $comments, $post_id ) { |
|
| 1165 | + global $wpdb; |
|
| 1166 | + |
|
| 1167 | + $post_id = (int) $post_id; |
|
| 1168 | + |
|
| 1169 | + $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 1170 | + |
|
| 1171 | + if ( false !== $count ) { |
|
| 1172 | + return $count; |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + $statuses = array( '' ); // Default to the WP normal comments |
|
| 1176 | + $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1177 | + foreach ( (array) $stati AS $status ) { |
|
| 1178 | + if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1179 | + $statuses[] = $status['comment_type']; |
|
| 1180 | + } |
|
| 1181 | + } |
|
| 1182 | + $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1183 | + |
|
| 1184 | + if ( $post_id > 0 ) |
|
| 1185 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1186 | + |
|
| 1187 | + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1188 | + |
|
| 1189 | + $total = 0; |
|
| 1190 | + $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 1191 | + foreach ( (array) $count as $row ) { |
|
| 1192 | + // Don't count post-trashed toward totals |
|
| 1193 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1194 | + $total += $row['num_comments']; |
|
| 1195 | + if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1196 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1197 | + } |
|
| 1198 | + |
|
| 1199 | + $stats['total_comments'] = $total; |
|
| 1200 | + foreach ( $approved as $key ) { |
|
| 1201 | + if ( empty($stats[$key]) ) |
|
| 1202 | + $stats[$key] = 0; |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + $stats = (object) $stats; |
|
| 1206 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 1207 | + |
|
| 1208 | + return $stats; |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + /** |
|
| 1212 | + * Init images. |
|
| 1213 | + * |
|
| 1214 | + * @since 1.4.5 |
|
| 1215 | + * @access public |
|
| 1216 | + * @return void |
|
| 1217 | + */ |
|
| 1218 | + public function init_image_sizes() { |
|
| 1219 | + $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1220 | + $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1221 | + $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1222 | + $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1223 | + |
|
| 1224 | + add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1225 | + add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1226 | + add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1227 | + add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + /** |
|
| 1231 | + * Get an image size. |
|
| 1232 | + * |
|
| 1233 | + * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 1234 | + * |
|
| 1235 | + * @since 1.4.5 |
|
| 1236 | + * @access public |
|
| 1237 | + * @param mixed $image_size |
|
| 1238 | + * @return string |
|
| 1239 | + */ |
|
| 1240 | + public function get_image_size( $image_size ) { |
|
| 1241 | + |
|
| 1242 | + // Only return sizes we define in settings |
|
| 1243 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1244 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1245 | + |
|
| 1246 | + if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1247 | + $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1248 | + } |
|
| 1249 | + if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1250 | + $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1251 | + } |
|
| 1252 | + if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1253 | + $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + $size = array_filter( array( |
|
| 1257 | + 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1258 | + 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1259 | + 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1260 | + ) ); |
|
| 1261 | + |
|
| 1262 | + $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1263 | + $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1264 | + $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1265 | + |
|
| 1266 | + return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + public function body_class( $classes ) { |
|
| 1270 | + if( is_sensei() ) { |
|
| 1271 | + $classes[] = 'sensei'; |
|
| 1272 | + } |
|
| 1273 | + return $classes; |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 1278 | + * |
|
| 1279 | + * @return null |
|
| 1280 | + * @since 1.7.0 |
|
| 1281 | + */ |
|
| 1282 | + public function jetpack_latex_support() { |
|
| 1283 | + if ( function_exists( 'latex_markup') ) { |
|
| 1284 | + add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1285 | + add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1286 | + } |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + /** |
|
| 1290 | + * Load the module functionality. |
|
| 1291 | + * |
|
| 1292 | + * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 1293 | + * the retired modules extension. |
|
| 1294 | + * |
|
| 1295 | + * @since 1.8.0 |
|
| 1296 | + */ |
|
| 1297 | + public function load_modules_class(){ |
|
| 1298 | + global $sensei_modules; |
|
| 1299 | + |
|
| 1300 | + if( !class_exists( 'Sensei_Modules' ) |
|
| 1301 | + && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1302 | + |
|
| 1303 | + //Load the modules class |
|
| 1304 | + require_once( 'class-sensei-modules.php'); |
|
| 1305 | + Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1306 | + |
|
| 1307 | + }else{ |
|
| 1308 | + // fallback for people still using the modules extension. |
|
| 1309 | + global $sensei_modules; |
|
| 1310 | + Sensei()->modules = $sensei_modules; |
|
| 1311 | + add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + /** |
|
| 1316 | + * Tell the user to that the modules extension is no longer needed. |
|
| 1317 | + * |
|
| 1318 | + * @since 1.8.0 |
|
| 1319 | + */ |
|
| 1320 | + public function disable_sensei_modules_extension(){ ?> |
|
| 1321 | 1321 | <div class="notice updated fade"> |
| 1322 | 1322 | <p> |
| 1323 | 1323 | <?php |
| 1324 | - $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 1325 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1326 | - ?> |
|
| 1324 | + $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 1325 | + $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1326 | + ?> |
|
| 1327 | 1327 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
| 1328 | 1328 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
| 1329 | 1329 | </p> |
@@ -1331,46 +1331,46 @@ discard block |
||
| 1331 | 1331 | |
| 1332 | 1332 | <?php }// end function |
| 1333 | 1333 | |
| 1334 | - /** |
|
| 1335 | - * Sensei wide rewrite flush call. |
|
| 1336 | - * |
|
| 1337 | - * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 1338 | - * |
|
| 1339 | - * After the option is one the Rules will be flushed. |
|
| 1340 | - * |
|
| 1341 | - * @since 1.9.0 |
|
| 1342 | - */ |
|
| 1343 | - public function flush_rewrite_rules(){ |
|
| 1334 | + /** |
|
| 1335 | + * Sensei wide rewrite flush call. |
|
| 1336 | + * |
|
| 1337 | + * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 1338 | + * |
|
| 1339 | + * After the option is one the Rules will be flushed. |
|
| 1340 | + * |
|
| 1341 | + * @since 1.9.0 |
|
| 1342 | + */ |
|
| 1343 | + public function flush_rewrite_rules(){ |
|
| 1344 | 1344 | |
| 1345 | - // ensures that the rewrite rules are flushed on the second |
|
| 1346 | - // attempt. This ensure that the settings for any other process |
|
| 1347 | - // have been completed and saved to the database before we refresh the |
|
| 1348 | - // rewrite rules. |
|
| 1349 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1350 | - if( '1' == $option ) { |
|
| 1345 | + // ensures that the rewrite rules are flushed on the second |
|
| 1346 | + // attempt. This ensure that the settings for any other process |
|
| 1347 | + // have been completed and saved to the database before we refresh the |
|
| 1348 | + // rewrite rules. |
|
| 1349 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1350 | + if( '1' == $option ) { |
|
| 1351 | 1351 | |
| 1352 | - update_option('sensei_flush_rewrite_rules', '2'); |
|
| 1352 | + update_option('sensei_flush_rewrite_rules', '2'); |
|
| 1353 | 1353 | |
| 1354 | - }elseif( '2' == $option ) { |
|
| 1354 | + }elseif( '2' == $option ) { |
|
| 1355 | 1355 | |
| 1356 | - flush_rewrite_rules(); |
|
| 1357 | - update_option('sensei_flush_rewrite_rules', '0'); |
|
| 1356 | + flush_rewrite_rules(); |
|
| 1357 | + update_option('sensei_flush_rewrite_rules', '0'); |
|
| 1358 | 1358 | |
| 1359 | - } |
|
| 1359 | + } |
|
| 1360 | 1360 | |
| 1361 | - } // end flush_rewrite_rules |
|
| 1361 | + } // end flush_rewrite_rules |
|
| 1362 | 1362 | |
| 1363 | - /** |
|
| 1364 | - * Calling this function will tell Sensei to flush rewrite |
|
| 1365 | - * rules on the next load. |
|
| 1366 | - * |
|
| 1367 | - * @since 1.9.0 |
|
| 1368 | - */ |
|
| 1369 | - public function initiate_rewrite_rules_flush(){ |
|
| 1363 | + /** |
|
| 1364 | + * Calling this function will tell Sensei to flush rewrite |
|
| 1365 | + * rules on the next load. |
|
| 1366 | + * |
|
| 1367 | + * @since 1.9.0 |
|
| 1368 | + */ |
|
| 1369 | + public function initiate_rewrite_rules_flush(){ |
|
| 1370 | 1370 | |
| 1371 | - update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1371 | + update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1372 | 1372 | |
| 1373 | - } |
|
| 1373 | + } |
|
| 1374 | 1374 | |
| 1375 | 1375 | } // End Class |
| 1376 | 1376 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei_Main |
@@ -142,41 +142,41 @@ discard block |
||
| 142 | 142 | * @param string $file The base file of the plugin. |
| 143 | 143 | * @since 1.0.0 |
| 144 | 144 | */ |
| 145 | - public function __construct ( $file ) { |
|
| 145 | + public function __construct($file) { |
|
| 146 | 146 | |
| 147 | 147 | // Setup object data |
| 148 | 148 | $this->file = $file; |
| 149 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 150 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 151 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 152 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 149 | + $this->plugin_url = trailingslashit(plugins_url('', $plugin = $file)); |
|
| 150 | + $this->plugin_path = trailingslashit(dirname($file)); |
|
| 151 | + $this->template_url = apply_filters('sensei_template_url', 'sensei/'); |
|
| 152 | + $this->permissions_message = array('title' => __('Permission Denied', 'woothemes-sensei'), 'message' => __('Unfortunately you do not have permissions to access this page.', 'woothemes-sensei')); |
|
| 153 | 153 | |
| 154 | 154 | // Initialize the core Sensei functionality |
| 155 | 155 | $this->init(); |
| 156 | 156 | |
| 157 | 157 | // Installation |
| 158 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 158 | + if (is_admin() && ! defined('DOING_AJAX')) $this->install(); |
|
| 159 | 159 | |
| 160 | 160 | // Run this on activation. |
| 161 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 161 | + register_activation_hook($this->file, array($this, 'activation')); |
|
| 162 | 162 | |
| 163 | 163 | // Setup post types. |
| 164 | 164 | $this->post_types = new Sensei_PostTypes(); |
| 165 | 165 | $this->post_types->token = 'woothemes-sensei-posttypes'; |
| 166 | 166 | |
| 167 | 167 | // Lad the updates class |
| 168 | - $this->updates = new WooThemes_Sensei_Updates( $this ); |
|
| 168 | + $this->updates = new WooThemes_Sensei_Updates($this); |
|
| 169 | 169 | |
| 170 | 170 | // Setup settings screen. |
| 171 | 171 | $this->settings = new Sensei_Settings(); |
| 172 | 172 | $this->settings->token = 'woothemes-sensei-settings'; |
| 173 | 173 | |
| 174 | 174 | // Setup Admin Settings data |
| 175 | - if ( is_admin() ) { |
|
| 175 | + if (is_admin()) { |
|
| 176 | 176 | |
| 177 | 177 | $this->settings->has_tabs = true; |
| 178 | - $this->settings->name = __( 'Sensei Settings', 'woothemes-sensei' ); |
|
| 179 | - $this->settings->menu_label = __( 'Settings', 'woothemes-sensei' ); |
|
| 178 | + $this->settings->name = __('Sensei Settings', 'woothemes-sensei'); |
|
| 179 | + $this->settings->menu_label = __('Settings', 'woothemes-sensei'); |
|
| 180 | 180 | $this->settings->page_slug = 'woothemes-sensei-settings'; |
| 181 | 181 | |
| 182 | 182 | } // End If Statement |
@@ -204,24 +204,24 @@ discard block |
||
| 204 | 204 | $this->quiz = $this->post_types->quiz; |
| 205 | 205 | |
| 206 | 206 | // load the modules class |
| 207 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 207 | + add_action('plugins_loaded', array($this, 'load_modules_class')); |
|
| 208 | 208 | |
| 209 | 209 | // Load Learner Management Functionality |
| 210 | - $this->learners = new Sensei_Learners( $file ); |
|
| 210 | + $this->learners = new Sensei_Learners($file); |
|
| 211 | 211 | $this->learners->token = $this->token; |
| 212 | 212 | |
| 213 | 213 | // Differentiate between administration and frontend logic. |
| 214 | - if ( is_admin() ) { |
|
| 214 | + if (is_admin()) { |
|
| 215 | 215 | |
| 216 | 216 | // Load Admin Welcome class |
| 217 | 217 | new Sensei_Welcome(); |
| 218 | 218 | |
| 219 | 219 | // Load Admin Class |
| 220 | - $this->admin = new Sensei_Admin( $file ); |
|
| 220 | + $this->admin = new Sensei_Admin($file); |
|
| 221 | 221 | $this->admin->token = $this->token; |
| 222 | 222 | |
| 223 | 223 | // Load Analysis Reports |
| 224 | - $this->analysis = new Sensei_Analysis( $file ); |
|
| 224 | + $this->analysis = new Sensei_Analysis($file); |
|
| 225 | 225 | $this->analysis->token = $this->token; |
| 226 | 226 | |
| 227 | 227 | |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // Load Grading Functionality |
| 241 | - $this->grading = new Sensei_Grading( $file ); |
|
| 241 | + $this->grading = new Sensei_Grading($file); |
|
| 242 | 242 | $this->grading->token = $this->token; |
| 243 | 243 | |
| 244 | 244 | // Load Email Class |
| 245 | - $this->emails = new Sensei_Emails( $file ); |
|
| 245 | + $this->emails = new Sensei_Emails($file); |
|
| 246 | 246 | $this->emails->token = $this->token; |
| 247 | 247 | |
| 248 | 248 | // Load Learner Profiles Class |
@@ -254,38 +254,38 @@ discard block |
||
| 254 | 254 | |
| 255 | 255 | // Force WooCommerce Required Settings |
| 256 | 256 | $this->set_woocommerce_functionality(); |
| 257 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 258 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 257 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
| 258 | + add_action('after_setup_theme', array($this, 'ensure_post_thumbnails_support')); |
|
| 259 | 259 | |
| 260 | 260 | // WooCommerce Payment Actions |
| 261 | - add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 262 | - add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 263 | - add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 264 | - add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 265 | - add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 266 | - add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 267 | - add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 261 | + add_action('woocommerce_payment_complete', array($this, 'sensei_woocommerce_complete_order')); |
|
| 262 | + add_action('woocommerce_thankyou', array($this, 'sensei_woocommerce_complete_order')); |
|
| 263 | + add_action('woocommerce_order_status_completed', array($this, 'sensei_woocommerce_complete_order')); |
|
| 264 | + add_action('woocommerce_order_status_processing', array($this, 'sensei_woocommerce_complete_order')); |
|
| 265 | + add_action('woocommerce_order_status_cancelled', array($this, 'sensei_woocommerce_cancel_order')); |
|
| 266 | + add_action('woocommerce_order_status_refunded', array($this, 'sensei_woocommerce_cancel_order')); |
|
| 267 | + add_action('subscriptions_activated_for_order', array($this, 'sensei_activate_subscription')); |
|
| 268 | 268 | |
| 269 | 269 | // WooCommerce Subscriptions Actions |
| 270 | - add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 271 | - add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 272 | - add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 273 | - add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 274 | - add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 270 | + add_action('reactivated_subscription', array($this, 'sensei_woocommerce_reactivate_subscription'), 10, 2); |
|
| 271 | + add_action('subscription_expired', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 272 | + add_action('subscription_end_of_prepaid_term', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 273 | + add_action('cancelled_subscription', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 274 | + add_action('subscription_put_on-hold', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 275 | 275 | |
| 276 | 276 | // Add Email link to course orders |
| 277 | - add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 277 | + add_action('woocommerce_email_after_order_table', array($this, 'sensei_woocommerce_email_course_details'), 10, 1); |
|
| 278 | 278 | |
| 279 | 279 | // Filter comment counts |
| 280 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 280 | + add_filter('wp_count_comments', array($this, 'sensei_count_comments'), 10, 2); |
|
| 281 | 281 | |
| 282 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 282 | + add_action('body_class', array($this, 'body_class')); |
|
| 283 | 283 | |
| 284 | 284 | // Check for and activate JetPack LaTeX support |
| 285 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 285 | + add_action('plugins_loaded', array($this, 'jetpack_latex_support'), 200); // Runs after Jetpack has loaded it's modules |
|
| 286 | 286 | |
| 287 | 287 | // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
| 288 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 288 | + add_action('init', array($this, 'flush_rewrite_rules'), 101); |
|
| 289 | 289 | |
| 290 | 290 | } // End __construct() |
| 291 | 291 | |
@@ -293,11 +293,11 @@ discard block |
||
| 293 | 293 | * Load the foundations of Sensei. |
| 294 | 294 | * @since 1.9.0 |
| 295 | 295 | */ |
| 296 | - protected function init(){ |
|
| 296 | + protected function init() { |
|
| 297 | 297 | |
| 298 | 298 | // Localisation |
| 299 | 299 | $this->load_plugin_textdomain(); |
| 300 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 300 | + add_action('init', array($this, 'load_localisation'), 0); |
|
| 301 | 301 | |
| 302 | 302 | // load the shortcode loader into memory, so as to listen to all for |
| 303 | 303 | // all shortcodes on the front end |
@@ -313,9 +313,9 @@ discard block |
||
| 313 | 313 | * |
| 314 | 314 | * @param $plugin |
| 315 | 315 | */ |
| 316 | - public static function activation_flush_rules( $plugin ){ |
|
| 316 | + public static function activation_flush_rules($plugin) { |
|
| 317 | 317 | |
| 318 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 318 | + if (strpos($plugin, '/woothemes-sensei.php') > 0) { |
|
| 319 | 319 | |
| 320 | 320 | flush_rewrite_rules(true); |
| 321 | 321 | |
@@ -335,12 +335,12 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | public static function instance() { |
| 337 | 337 | |
| 338 | - if ( is_null( self::$_instance ) ) { |
|
| 338 | + if (is_null(self::$_instance)) { |
|
| 339 | 339 | |
| 340 | 340 | //Sensei requires a reference to the main Sensei plugin file |
| 341 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 341 | + $sensei_main_plugin_file = dirname(dirname(__FILE__)).'/woothemes-sensei.php'; |
|
| 342 | 342 | |
| 343 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 343 | + self::$_instance = new self($sensei_main_plugin_file); |
|
| 344 | 344 | |
| 345 | 345 | } |
| 346 | 346 | |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | * @since 1.8.0 |
| 354 | 354 | */ |
| 355 | 355 | public function __clone() { |
| 356 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 356 | + _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'woothemes-sensei'), '2.1'); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | * @since 1.8.0 |
| 362 | 362 | */ |
| 363 | 363 | public function __wakeup() { |
| 364 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 364 | + _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'woothemes-sensei'), '2.1'); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | public function run_updates() { |
| 374 | 374 | // Run updates if administrator |
| 375 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 375 | + if (current_user_can('manage_options') || current_user_can('manage_sensei')) { |
|
| 376 | 376 | |
| 377 | 377 | $this->updates->update(); |
| 378 | 378 | |
@@ -387,10 +387,10 @@ discard block |
||
| 387 | 387 | */ |
| 388 | 388 | public function set_woocommerce_functionality() { |
| 389 | 389 | // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
| 390 | - add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 390 | + add_filter('pre_option_woocommerce_enable_guest_checkout', array($this, 'disable_guest_checkout')); |
|
| 391 | 391 | |
| 392 | 392 | // Mark orders with virtual products as complete rather then stay processing |
| 393 | - add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 393 | + add_filter('woocommerce_payment_complete_order_status', array($this, 'virtual_order_payment_complete'), 10, 2); |
|
| 394 | 394 | |
| 395 | 395 | } // End set_woocommerce_functionality() |
| 396 | 396 | |
@@ -399,14 +399,14 @@ discard block |
||
| 399 | 399 | * @param boolean $guest_checkout Current guest checkout setting |
| 400 | 400 | * @return boolean Modified guest checkout setting |
| 401 | 401 | */ |
| 402 | - public function disable_guest_checkout( $guest_checkout ) { |
|
| 402 | + public function disable_guest_checkout($guest_checkout) { |
|
| 403 | 403 | global $woocommerce; |
| 404 | 404 | |
| 405 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 405 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 406 | 406 | |
| 407 | - if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 408 | - foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 409 | - if( isset( $product['product_id'] ) ) { |
|
| 407 | + if (isset($woocommerce->cart->cart_contents) && count($woocommerce->cart->cart_contents) > 0) { |
|
| 408 | + foreach ($woocommerce->cart->cart_contents as $cart_key => $product) { |
|
| 409 | + if (isset($product['product_id'])) { |
|
| 410 | 410 | $args = array( |
| 411 | 411 | 'posts_per_page' => -1, |
| 412 | 412 | 'post_type' => 'course', |
@@ -417,9 +417,9 @@ discard block |
||
| 417 | 417 | ) |
| 418 | 418 | ) |
| 419 | 419 | ); |
| 420 | - $posts = get_posts( $args ); |
|
| 421 | - if( $posts && count( $posts ) > 0 ) { |
|
| 422 | - foreach( $posts as $course ) { |
|
| 420 | + $posts = get_posts($args); |
|
| 421 | + if ($posts && count($posts) > 0) { |
|
| 422 | + foreach ($posts as $course) { |
|
| 423 | 423 | $guest_checkout = ''; |
| 424 | 424 | break; |
| 425 | 425 | } |
@@ -439,17 +439,17 @@ discard block |
||
| 439 | 439 | * @param int $order_id |
| 440 | 440 | * @return string |
| 441 | 441 | **/ |
| 442 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 443 | - $order = new WC_Order( $order_id ); |
|
| 444 | - if ( ! isset ( $order ) ) return; |
|
| 445 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 442 | + public function virtual_order_payment_complete($order_status, $order_id) { |
|
| 443 | + $order = new WC_Order($order_id); |
|
| 444 | + if ( ! isset ($order)) return; |
|
| 445 | + if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) { |
|
| 446 | 446 | $virtual_order = true; |
| 447 | 447 | |
| 448 | - if ( count( $order->get_items() ) > 0 ) { |
|
| 449 | - foreach( $order->get_items() as $item ) { |
|
| 450 | - if ( $item['product_id'] > 0 ) { |
|
| 451 | - $_product = $order->get_product_from_item( $item ); |
|
| 452 | - if ( ! $_product->is_virtual() ) { |
|
| 448 | + if (count($order->get_items()) > 0) { |
|
| 449 | + foreach ($order->get_items() as $item) { |
|
| 450 | + if ($item['product_id'] > 0) { |
|
| 451 | + $_product = $order->get_product_from_item($item); |
|
| 452 | + if ( ! $_product->is_virtual()) { |
|
| 453 | 453 | $virtual_order = false; |
| 454 | 454 | break; |
| 455 | 455 | } // End If Statement |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | } // End If Statement |
| 459 | 459 | |
| 460 | 460 | // virtual order, mark as completed |
| 461 | - if ( $virtual_order ) { |
|
| 461 | + if ($virtual_order) { |
|
| 462 | 462 | return 'completed'; |
| 463 | 463 | } // End If Statement |
| 464 | 464 | } // End If Statement |
@@ -471,21 +471,21 @@ discard block |
||
| 471 | 471 | * @since 1.0.0 |
| 472 | 472 | * @return void |
| 473 | 473 | */ |
| 474 | - public function register_widgets () { |
|
| 474 | + public function register_widgets() { |
|
| 475 | 475 | // Widget List (key => value is filename => widget class). |
| 476 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 476 | + $widget_list = apply_filters('sensei_registered_widgets_list', array('course-component' => 'Course_Component', |
|
| 477 | 477 | 'lesson-component' => 'Lesson_Component', |
| 478 | 478 | 'course-categories' => 'Course_Categories', |
| 479 | - 'category-courses' => 'Category_Courses' ) |
|
| 479 | + 'category-courses' => 'Category_Courses') |
|
| 480 | 480 | ); |
| 481 | - foreach ( $widget_list as $key => $value ) { |
|
| 482 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ) ) { |
|
| 483 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . esc_attr( $key ) . '.php' ); |
|
| 484 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 481 | + foreach ($widget_list as $key => $value) { |
|
| 482 | + if (file_exists($this->plugin_path.'widgets/widget-woothemes-sensei-'.esc_attr($key).'.php')) { |
|
| 483 | + require_once($this->plugin_path.'widgets/widget-woothemes-sensei-'.esc_attr($key).'.php'); |
|
| 484 | + register_widget('WooThemes_Sensei_'.$value.'_Widget'); |
|
| 485 | 485 | } |
| 486 | 486 | } // End For Loop |
| 487 | 487 | |
| 488 | - do_action( 'sensei_register_widgets' ); |
|
| 488 | + do_action('sensei_register_widgets'); |
|
| 489 | 489 | } // End register_widgets() |
| 490 | 490 | |
| 491 | 491 | /** |
@@ -494,8 +494,8 @@ discard block |
||
| 494 | 494 | * @since 1.0.0 |
| 495 | 495 | * @return void |
| 496 | 496 | */ |
| 497 | - public function load_localisation () { |
|
| 498 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 497 | + public function load_localisation() { |
|
| 498 | + load_plugin_textdomain('woothemes-sensei', false, dirname(plugin_basename($this->file)).'/lang/'); |
|
| 499 | 499 | } // End load_localisation() |
| 500 | 500 | |
| 501 | 501 | /** |
@@ -504,12 +504,12 @@ discard block |
||
| 504 | 504 | * @since 1.0.0 |
| 505 | 505 | * @return void |
| 506 | 506 | */ |
| 507 | - public function load_plugin_textdomain () { |
|
| 507 | + public function load_plugin_textdomain() { |
|
| 508 | 508 | $domain = 'woothemes-sensei'; |
| 509 | 509 | // The "plugin_locale" filter is also used in load_plugin_textdomain() |
| 510 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 511 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 512 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 510 | + $locale = apply_filters('plugin_locale', get_locale(), $domain); |
|
| 511 | + load_textdomain($domain, WP_LANG_DIR.'/'.$domain.'/'.$domain.'-'.$locale.'.mo'); |
|
| 512 | + load_plugin_textdomain($domain, FALSE, dirname(plugin_basename($this->file)).'/lang/'); |
|
| 513 | 513 | } // End load_plugin_textdomain() |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | * @since 1.0.0 |
| 519 | 519 | * @return void |
| 520 | 520 | */ |
| 521 | - public function activation () { |
|
| 521 | + public function activation() { |
|
| 522 | 522 | $this->register_plugin_version(); |
| 523 | 523 | } // End activation() |
| 524 | 524 | |
@@ -529,9 +529,9 @@ discard block |
||
| 529 | 529 | * @since 1.0.0 |
| 530 | 530 | * @return void |
| 531 | 531 | */ |
| 532 | - public function install () { |
|
| 533 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 534 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 532 | + public function install() { |
|
| 533 | + register_activation_hook($this->file, array($this, 'activate_sensei')); |
|
| 534 | + register_activation_hook($this->file, 'flush_rewrite_rules'); |
|
| 535 | 535 | } // End install() |
| 536 | 536 | |
| 537 | 537 | |
@@ -541,9 +541,9 @@ discard block |
||
| 541 | 541 | * @since 1.0.0 |
| 542 | 542 | * @return void |
| 543 | 543 | */ |
| 544 | - public function activate_sensei () { |
|
| 545 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
| 546 | - update_option( 'sensei_installed', 1 ); |
|
| 544 | + public function activate_sensei() { |
|
| 545 | + update_option('skip_install_sensei_pages', 0); |
|
| 546 | + update_option('sensei_installed', 1); |
|
| 547 | 547 | } // End activate_sensei() |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -552,8 +552,8 @@ discard block |
||
| 552 | 552 | * @since 1.0.0 |
| 553 | 553 | * @return void |
| 554 | 554 | */ |
| 555 | - private function register_plugin_version () { |
|
| 556 | - if ( $this->version != '' ) { |
|
| 555 | + private function register_plugin_version() { |
|
| 556 | + if ($this->version != '') { |
|
| 557 | 557 | |
| 558 | 558 | // Check previous version to see if forced updates must run |
| 559 | 559 | // $old_version = get_option( 'woothemes-sensei-version', false ); |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | // delete_option( 'woothemes-sensei-force-updates' ); |
| 564 | 564 | // } |
| 565 | 565 | |
| 566 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
| 566 | + update_option('woothemes-sensei-version', $this->version); |
|
| 567 | 567 | } |
| 568 | 568 | } // End register_plugin_version() |
| 569 | 569 | |
@@ -573,8 +573,8 @@ discard block |
||
| 573 | 573 | * @since 1.0.1 |
| 574 | 574 | * @return void |
| 575 | 575 | */ |
| 576 | - public function ensure_post_thumbnails_support () { |
|
| 577 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 576 | + public function ensure_post_thumbnails_support() { |
|
| 577 | + if ( ! current_theme_supports('post-thumbnails')) { add_theme_support('post-thumbnails'); } |
|
| 578 | 578 | } // End ensure_post_thumbnails_support() |
| 579 | 579 | |
| 580 | 580 | |
@@ -586,10 +586,10 @@ discard block |
||
| 586 | 586 | * @return void |
| 587 | 587 | * @deprecated |
| 588 | 588 | */ |
| 589 | - public function template_loader ( $template = '' ) { |
|
| 589 | + public function template_loader($template = '') { |
|
| 590 | 590 | |
| 591 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 592 | - return Sensei_Templates::template_loader( $template ); |
|
| 591 | + _deprecated_function('Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead'); |
|
| 592 | + return Sensei_Templates::template_loader($template); |
|
| 593 | 593 | |
| 594 | 594 | } // End template_loader() |
| 595 | 595 | |
@@ -599,15 +599,15 @@ discard block |
||
| 599 | 599 | * @since 1.0.0 |
| 600 | 600 | * @return string $sensei_plugin_path |
| 601 | 601 | */ |
| 602 | - public function plugin_path () { |
|
| 602 | + public function plugin_path() { |
|
| 603 | 603 | |
| 604 | - if ( $this->plugin_path ) { |
|
| 604 | + if ($this->plugin_path) { |
|
| 605 | 605 | |
| 606 | - $sensei_plugin_path = $this->plugin_path; |
|
| 606 | + $sensei_plugin_path = $this->plugin_path; |
|
| 607 | 607 | |
| 608 | - }else{ |
|
| 608 | + } else { |
|
| 609 | 609 | |
| 610 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 610 | + $sensei_plugin_path = plugin_dir_path(__FILE__); |
|
| 611 | 611 | |
| 612 | 612 | } |
| 613 | 613 | |
@@ -623,9 +623,9 @@ discard block |
||
| 623 | 623 | * @param string $page |
| 624 | 624 | * @return int |
| 625 | 625 | */ |
| 626 | - public function get_page_id ( $page ) { |
|
| 627 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 628 | - return ( $page ) ? $page : -1; |
|
| 626 | + public function get_page_id($page) { |
|
| 627 | + $page = apply_filters('sensei_get_'.esc_attr($page).'_page_id', get_option('sensei_'.esc_attr($page).'_page_id')); |
|
| 628 | + return ($page) ? $page : -1; |
|
| 629 | 629 | } // End get_page_id() |
| 630 | 630 | |
| 631 | 631 | |
@@ -637,18 +637,18 @@ discard block |
||
| 637 | 637 | * @param array/Object $order_user (default: array()) Specific user's data. |
| 638 | 638 | * @return void |
| 639 | 639 | */ |
| 640 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 640 | + public function woocommerce_course_update($course_id = 0, $order_user = array()) { |
|
| 641 | 641 | global $current_user; |
| 642 | 642 | |
| 643 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return; |
|
| 643 | + if ( ! isset($current_user) || ! $current_user->ID > 0) return; |
|
| 644 | 644 | |
| 645 | 645 | $data_update = false; |
| 646 | 646 | |
| 647 | 647 | // Get the product ID |
| 648 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 648 | + $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true); |
|
| 649 | 649 | |
| 650 | 650 | // Check if in the admin |
| 651 | - if ( is_admin() ) { |
|
| 651 | + if (is_admin()) { |
|
| 652 | 652 | $user_login = $order_user['user_login']; |
| 653 | 653 | $user_email = $order_user['user_email']; |
| 654 | 654 | $user_url = $order_user['user_url']; |
@@ -661,25 +661,25 @@ discard block |
||
| 661 | 661 | } // End If Statement |
| 662 | 662 | |
| 663 | 663 | // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
| 664 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 665 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 666 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 667 | - if ( ! $prereq_course_complete ) { |
|
| 664 | + $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true); |
|
| 665 | + if (0 < absint($course_prerequisite_id)) { |
|
| 666 | + $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id)); |
|
| 667 | + if ( ! $prereq_course_complete) { |
|
| 668 | 668 | // Remove all course user meta |
| 669 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 669 | + return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id); |
|
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 673 | + $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id)); |
|
| 674 | 674 | |
| 675 | - if( ! $is_user_taking_course ) { |
|
| 675 | + if ( ! $is_user_taking_course) { |
|
| 676 | 676 | |
| 677 | - if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 677 | + if (Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product($user_email, $user_id, $wc_post_id) && (0 < $wc_post_id)) { |
|
| 678 | 678 | |
| 679 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 679 | + $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id)); |
|
| 680 | 680 | |
| 681 | 681 | $is_user_taking_course = false; |
| 682 | - if ( true == $activity_logged ) { |
|
| 682 | + if (true == $activity_logged) { |
|
| 683 | 683 | $is_user_taking_course = true; |
| 684 | 684 | } // End If Statement |
| 685 | 685 | } // End If Statement |
@@ -697,14 +697,14 @@ discard block |
||
| 697 | 697 | * @param array $data (default: array()) |
| 698 | 698 | * @return bool |
| 699 | 699 | */ |
| 700 | - public function check_user_permissions ( $page = '', $data = array() ) { |
|
| 700 | + public function check_user_permissions($page = '', $data = array()) { |
|
| 701 | 701 | // REFACTOR |
| 702 | 702 | global $current_user, $post; |
| 703 | 703 | |
| 704 | 704 | // if use is not logged in |
| 705 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){ |
|
| 706 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 707 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 705 | + if (empty($current_user->caps) && Sensei()->settings->get('access_permission')) { |
|
| 706 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei'); |
|
| 707 | + $this->permissions_message['message'] = sprintf(__('You must be logged in to view this %s'), get_post_type()); |
|
| 708 | 708 | return; |
| 709 | 709 | } |
| 710 | 710 | |
@@ -714,104 +714,104 @@ discard block |
||
| 714 | 714 | |
| 715 | 715 | $user_allowed = false; |
| 716 | 716 | |
| 717 | - switch ( $page ) { |
|
| 717 | + switch ($page) { |
|
| 718 | 718 | case 'course-single': |
| 719 | 719 | // check for prerequisite course or lesson, |
| 720 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 721 | - $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 720 | + $course_prerequisite_id = (int) get_post_meta($post->ID, '_course_prerequisite', true); |
|
| 721 | + $update_course = $this->woocommerce_course_update($post->ID); |
|
| 722 | 722 | // Count completed lessons |
| 723 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 723 | + if (0 < absint($course_prerequisite_id)) { |
|
| 724 | 724 | |
| 725 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 725 | + $prerequisite_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, $current_user->ID); |
|
| 726 | 726 | |
| 727 | 727 | } |
| 728 | 728 | else { |
| 729 | 729 | $prerequisite_complete = true; |
| 730 | 730 | } // End If Statement |
| 731 | 731 | // Handles restrictions |
| 732 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 733 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 734 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 735 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 732 | + if ( ! $prerequisite_complete && 0 < absint($course_prerequisite_id)) { |
|
| 733 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 734 | + $course_link = '<a href="'.esc_url(get_permalink($course_prerequisite_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 735 | + $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this course.', 'woothemes-sensei'), $course_link); |
|
| 736 | 736 | } else { |
| 737 | 737 | $user_allowed = true; |
| 738 | 738 | } // End If Statement |
| 739 | 739 | break; |
| 740 | 740 | case 'lesson-single': |
| 741 | 741 | // Check for WC purchase |
| 742 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 742 | + $lesson_course_id = get_post_meta($post->ID, '_lesson_course', true); |
|
| 743 | 743 | |
| 744 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 745 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 746 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 744 | + $update_course = $this->woocommerce_course_update($lesson_course_id); |
|
| 745 | + $is_preview = Sensei_Utils::is_preview_lesson($post->ID); |
|
| 746 | + if ($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) { |
|
| 747 | 747 | $user_allowed = true; |
| 748 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 748 | + } elseif ($this->access_settings() && false == $is_preview) { |
|
| 749 | 749 | |
| 750 | 750 | $user_allowed = true; |
| 751 | 751 | } else { |
| 752 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 753 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 754 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 755 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 756 | - if ( $is_preview ) { |
|
| 757 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 752 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 753 | + $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 754 | + $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true); |
|
| 755 | + if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) { |
|
| 756 | + if ($is_preview) { |
|
| 757 | + $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei'), $course_link); |
|
| 758 | 758 | } else { |
| 759 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 759 | + $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei'), $course_link); |
|
| 760 | 760 | } |
| 761 | 761 | } else { |
| 762 | - if ( $is_preview ) { |
|
| 763 | - $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 ); |
|
| 762 | + if ($is_preview) { |
|
| 763 | + $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); |
|
| 764 | 764 | } else { |
| 765 | 765 | /** This filter is documented in class-woothemes-sensei-frontend.php */ |
| 766 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 766 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link); |
|
| 767 | 767 | } |
| 768 | 768 | } // End If Statement |
| 769 | 769 | } // End If Statement |
| 770 | 770 | break; |
| 771 | 771 | case 'quiz-single': |
| 772 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 773 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 772 | + $lesson_id = get_post_meta($post->ID, '_quiz_lesson', true); |
|
| 773 | + $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 774 | 774 | |
| 775 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 776 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 775 | + $update_course = $this->woocommerce_course_update($lesson_course_id); |
|
| 776 | + if (($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) || sensei_all_access()) { |
|
| 777 | 777 | |
| 778 | 778 | // Check for prerequisite lesson for this quiz |
| 779 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 780 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 779 | + $lesson_prerequisite_id = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
| 780 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson($lesson_prerequisite_id, $current_user->ID); |
|
| 781 | 781 | |
| 782 | 782 | // Handle restrictions |
| 783 | - if( sensei_all_access() ) { |
|
| 783 | + if (sensei_all_access()) { |
|
| 784 | 784 | $user_allowed = true; |
| 785 | 785 | } else { |
| 786 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 787 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 788 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 789 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 786 | + if (0 < absint($lesson_prerequisite_id) && ( ! $user_lesson_prerequisite_complete)) { |
|
| 787 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 788 | + $lesson_link = '<a href="'.esc_url(get_permalink($lesson_prerequisite_id)).'">'.__('lesson', 'woothemes-sensei').'</a>'; |
|
| 789 | + $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei'), $lesson_link); |
|
| 790 | 790 | } else { |
| 791 | 791 | $user_allowed = true; |
| 792 | 792 | } // End If Statement |
| 793 | 793 | } // End If Statement |
| 794 | - } elseif( $this->access_settings() ) { |
|
| 794 | + } elseif ($this->access_settings()) { |
|
| 795 | 795 | // Check if the user has started the course |
| 796 | 796 | |
| 797 | - 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'] ) ) ) { |
|
| 797 | + 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']))) { |
|
| 798 | 798 | |
| 799 | 799 | $user_allowed = false; |
| 800 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 801 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 802 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 803 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 804 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 800 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 801 | + $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 802 | + $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true); |
|
| 803 | + if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) { |
|
| 804 | + $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link); |
|
| 805 | 805 | } else { |
| 806 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 806 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link); |
|
| 807 | 807 | } // End If Statement |
| 808 | 808 | } else { |
| 809 | 809 | $user_allowed = true; |
| 810 | 810 | } // End If Statement |
| 811 | 811 | } else { |
| 812 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 813 | - $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>'; |
|
| 814 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 812 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 813 | + $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>'; |
|
| 814 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei'), $course_link); |
|
| 815 | 815 | } // End If Statement |
| 816 | 816 | break; |
| 817 | 817 | default: |
@@ -833,14 +833,14 @@ discard block |
||
| 833 | 833 | * } |
| 834 | 834 | * @param string $post_id |
| 835 | 835 | */ |
| 836 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 836 | + $this->permissions_message = apply_filters('sensei_permissions_message', $this->permissions_message, $post->ID); |
|
| 837 | 837 | |
| 838 | 838 | |
| 839 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 839 | + if (sensei_all_access() || Sensei_Utils::is_preview_lesson($post->ID)) { |
|
| 840 | 840 | $user_allowed = true; |
| 841 | 841 | } |
| 842 | 842 | |
| 843 | - return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 843 | + return apply_filters('sensei_access_permissions', $user_allowed); |
|
| 844 | 844 | } // End get_placeholder_image() |
| 845 | 845 | |
| 846 | 846 | |
@@ -850,12 +850,12 @@ discard block |
||
| 850 | 850 | * @access public |
| 851 | 851 | * @return void |
| 852 | 852 | */ |
| 853 | - public function access_settings () { |
|
| 853 | + public function access_settings() { |
|
| 854 | 854 | |
| 855 | - if( sensei_all_access() ) return true; |
|
| 855 | + if (sensei_all_access()) return true; |
|
| 856 | 856 | |
| 857 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 858 | - if ( is_user_logged_in() ) { |
|
| 857 | + if (isset($this->settings->settings['access_permission']) && (true == $this->settings->settings['access_permission'])) { |
|
| 858 | + if (is_user_logged_in()) { |
|
| 859 | 859 | return true; |
| 860 | 860 | } else { |
| 861 | 861 | return false; |
@@ -872,38 +872,38 @@ discard block |
||
| 872 | 872 | * @param int $order_id WC order ID |
| 873 | 873 | * @return void |
| 874 | 874 | */ |
| 875 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 875 | + public function sensei_woocommerce_complete_order($order_id = 0) { |
|
| 876 | 876 | $order_user = array(); |
| 877 | 877 | // Check for WooCommerce |
| 878 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 878 | + if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) { |
|
| 879 | 879 | // Get order object |
| 880 | - $order = new WC_Order( $order_id ); |
|
| 881 | - $user = get_user_by( 'id', $order->user_id ); |
|
| 880 | + $order = new WC_Order($order_id); |
|
| 881 | + $user = get_user_by('id', $order->user_id); |
|
| 882 | 882 | $order_user['ID'] = $user->ID; |
| 883 | 883 | $order_user['user_login'] = $user->user_login; |
| 884 | 884 | $order_user['user_email'] = $user->user_email; |
| 885 | 885 | $order_user['user_url'] = $user->user_url; |
| 886 | 886 | // Run through each product ordered |
| 887 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 888 | - foreach( $order->get_items() as $item ) { |
|
| 887 | + if (0 < sizeof($order->get_items())) { |
|
| 888 | + foreach ($order->get_items() as $item) { |
|
| 889 | 889 | $product_type = ''; |
| 890 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 890 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 891 | 891 | $item_id = $item['variation_id']; |
| 892 | 892 | $product_type = 'variation'; |
| 893 | 893 | } else { |
| 894 | 894 | $item_id = $item['product_id']; |
| 895 | 895 | } // End If Statement |
| 896 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 896 | + $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); |
|
| 897 | 897 | // Get courses that use the WC product |
| 898 | - $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 898 | + $courses = $this->post_types->course->get_product_courses($_product->id); |
|
| 899 | 899 | // Loop and update those courses |
| 900 | - foreach ( $courses as $course_item ) { |
|
| 901 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 900 | + foreach ($courses as $course_item) { |
|
| 901 | + $update_course = $this->woocommerce_course_update($course_item->ID, $order_user); |
|
| 902 | 902 | } // End For Loop |
| 903 | 903 | } // End For Loop |
| 904 | 904 | } // End If Statement |
| 905 | 905 | // Add meta to indicate that payment has been completed successfully |
| 906 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 906 | + update_post_meta($order_id, 'sensei_payment_complete', '1'); |
|
| 907 | 907 | } // End If Statement |
| 908 | 908 | } // End sensei_woocommerce_complete_order() |
| 909 | 909 | |
@@ -914,36 +914,36 @@ discard block |
||
| 914 | 914 | * @param integer $order_id order ID |
| 915 | 915 | * @return void |
| 916 | 916 | */ |
| 917 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 917 | + public function sensei_woocommerce_cancel_order($order_id) { |
|
| 918 | 918 | |
| 919 | 919 | // Get order object |
| 920 | - $order = new WC_Order( $order_id ); |
|
| 920 | + $order = new WC_Order($order_id); |
|
| 921 | 921 | |
| 922 | 922 | // Run through each product ordered |
| 923 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 923 | + if (0 < sizeof($order->get_items())) { |
|
| 924 | 924 | |
| 925 | 925 | // Get order user |
| 926 | - $user_id = $order->__get( 'user_id' ); |
|
| 926 | + $user_id = $order->__get('user_id'); |
|
| 927 | 927 | |
| 928 | - foreach( $order->get_items() as $item ) { |
|
| 928 | + foreach ($order->get_items() as $item) { |
|
| 929 | 929 | |
| 930 | 930 | $product_type = ''; |
| 931 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 931 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 932 | 932 | $item_id = $item['variation_id']; |
| 933 | 933 | $product_type = 'variation'; |
| 934 | 934 | } else { |
| 935 | 935 | $item_id = $item['product_id']; |
| 936 | 936 | } // End If Statement |
| 937 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 937 | + $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); |
|
| 938 | 938 | |
| 939 | 939 | // Get courses that use the WC product |
| 940 | 940 | $courses = array(); |
| 941 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 941 | + $courses = $this->post_types->course->get_product_courses($item_id); |
|
| 942 | 942 | |
| 943 | 943 | // Loop and update those courses |
| 944 | - foreach ($courses as $course_item){ |
|
| 944 | + foreach ($courses as $course_item) { |
|
| 945 | 945 | // Check and Remove course from courses user meta |
| 946 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 946 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id); |
|
| 947 | 947 | } // End For Loop |
| 948 | 948 | } // End For Loop |
| 949 | 949 | } // End If Statement |
@@ -957,9 +957,9 @@ discard block |
||
| 957 | 957 | * @param integer $subscription_key Subscription Unique Key |
| 958 | 958 | * @return void |
| 959 | 959 | */ |
| 960 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 961 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 962 | - self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 960 | + public function sensei_woocommerce_subscription_ended($user_id, $subscription_key) { |
|
| 961 | + $subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key); |
|
| 962 | + self::sensei_woocommerce_cancel_order($subscription['order_id']); |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -970,18 +970,18 @@ discard block |
||
| 970 | 970 | * @param integer $subscription_key Subscription Unique Key |
| 971 | 971 | * @return void |
| 972 | 972 | */ |
| 973 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 974 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 975 | - $order = new WC_Order( $subscription['order_id'] ); |
|
| 976 | - $user = get_user_by( 'id', $order->user_id ); |
|
| 973 | + public function sensei_woocommerce_reactivate_subscription($user_id, $subscription_key) { |
|
| 974 | + $subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key); |
|
| 975 | + $order = new WC_Order($subscription['order_id']); |
|
| 976 | + $user = get_user_by('id', $order->user_id); |
|
| 977 | 977 | $order_user = array(); |
| 978 | 978 | $order_user['ID'] = $user->ID; |
| 979 | 979 | $order_user['user_login'] = $user->user_login; |
| 980 | 980 | $order_user['user_email'] = $user->user_email; |
| 981 | 981 | $order_user['user_url'] = $user->user_url; |
| 982 | - $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 983 | - foreach ( $courses as $course_item ){ |
|
| 984 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 982 | + $courses = $this->post_types->course->get_product_courses($subscription['product_id']); |
|
| 983 | + foreach ($courses as $course_item) { |
|
| 984 | + $update_course = $this->woocommerce_course_update($course_item->ID, $order_user); |
|
| 985 | 985 | } // End For Loop |
| 986 | 986 | } // End sensei_woocommerce_reactivate_subscription |
| 987 | 987 | |
@@ -996,30 +996,30 @@ discard block |
||
| 996 | 996 | * @param string $product_type '' or 'variation' |
| 997 | 997 | * @return WC_Product $wc_product_object |
| 998 | 998 | */ |
| 999 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 999 | + public function sensei_get_woocommerce_product_object($wc_product_id = 0, $product_type = '') { |
|
| 1000 | 1000 | |
| 1001 | 1001 | $wc_product_object = false; |
| 1002 | - if ( 0 < intval( $wc_product_id ) ) { |
|
| 1002 | + if (0 < intval($wc_product_id)) { |
|
| 1003 | 1003 | |
| 1004 | 1004 | // Get the product |
| 1005 | - if ( function_exists( 'wc_get_product' ) ) { |
|
| 1005 | + if (function_exists('wc_get_product')) { |
|
| 1006 | 1006 | |
| 1007 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1007 | + $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3 |
|
| 1008 | 1008 | |
| 1009 | - } elseif ( function_exists( 'get_product' ) ) { |
|
| 1009 | + } elseif (function_exists('get_product')) { |
|
| 1010 | 1010 | |
| 1011 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1011 | + $wc_product_object = get_product($wc_product_id); // Post WC 2.0 |
|
| 1012 | 1012 | |
| 1013 | 1013 | } else { |
| 1014 | 1014 | |
| 1015 | 1015 | // Pre WC 2.0 |
| 1016 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1016 | + if ('variation' == $product_type || 'subscription_variation' == $product_type) { |
|
| 1017 | 1017 | |
| 1018 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1018 | + $wc_product_object = new WC_Product_Variation($wc_product_id); |
|
| 1019 | 1019 | |
| 1020 | 1020 | } else { |
| 1021 | 1021 | |
| 1022 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1022 | + $wc_product_object = new WC_Product($wc_product_id); |
|
| 1023 | 1023 | |
| 1024 | 1024 | } // End If Statement |
| 1025 | 1025 | |
@@ -1037,9 +1037,9 @@ discard block |
||
| 1037 | 1037 | * @access public |
| 1038 | 1038 | * @return void |
| 1039 | 1039 | */ |
| 1040 | - public function load_class ( $class_name = '' ) { |
|
| 1041 | - if ( '' != $class_name && '' != $this->token ) { |
|
| 1042 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1040 | + public function load_class($class_name = '') { |
|
| 1041 | + if ('' != $class_name && '' != $this->token) { |
|
| 1042 | + require_once('class-'.esc_attr($this->token).'-'.esc_attr($class_name).'.php'); |
|
| 1043 | 1043 | } // End If Statement |
| 1044 | 1044 | } // End load_class() |
| 1045 | 1045 | |
@@ -1050,17 +1050,17 @@ discard block |
||
| 1050 | 1050 | * @param integer $order_id order ID |
| 1051 | 1051 | * @return void |
| 1052 | 1052 | */ |
| 1053 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1054 | - if ( 0 < intval( $order_id ) ) { |
|
| 1055 | - $order = new WC_Order( $order_id ); |
|
| 1053 | + public function sensei_activate_subscription($order_id = 0) { |
|
| 1054 | + if (0 < intval($order_id)) { |
|
| 1055 | + $order = new WC_Order($order_id); |
|
| 1056 | 1056 | $user = get_user_by('id', $order->user_id); |
| 1057 | 1057 | $order_user['ID'] = $user->ID; |
| 1058 | 1058 | $order_user['user_login'] = $user->user_login; |
| 1059 | 1059 | $order_user['user_email'] = $user->user_email; |
| 1060 | 1060 | $order_user['user_url'] = $user->user_url; |
| 1061 | 1061 | // Run through each product ordered |
| 1062 | - if (sizeof($order->get_items())>0) { |
|
| 1063 | - foreach($order->get_items() as $item) { |
|
| 1062 | + if (sizeof($order->get_items()) > 0) { |
|
| 1063 | + foreach ($order->get_items() as $item) { |
|
| 1064 | 1064 | $product_type = ''; |
| 1065 | 1065 | if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
| 1066 | 1066 | $item_id = $item['variation_id']; |
@@ -1068,15 +1068,15 @@ discard block |
||
| 1068 | 1068 | } else { |
| 1069 | 1069 | $item_id = $item['product_id']; |
| 1070 | 1070 | } // End If Statement |
| 1071 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1071 | + $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); |
|
| 1072 | 1072 | // Get courses that use the WC product |
| 1073 | 1073 | $courses = array(); |
| 1074 | - if ( $product_type == 'subscription_variation' ) { |
|
| 1075 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1074 | + if ($product_type == 'subscription_variation') { |
|
| 1075 | + $courses = $this->post_types->course->get_product_courses($item_id); |
|
| 1076 | 1076 | } // End If Statement |
| 1077 | 1077 | // Loop and update those courses |
| 1078 | - foreach ($courses as $course_item){ |
|
| 1079 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1078 | + foreach ($courses as $course_item) { |
|
| 1079 | + $update_course = $this->woocommerce_course_update($course_item->ID, $order_user); |
|
| 1080 | 1080 | } // End For Loop |
| 1081 | 1081 | } // End For Loop |
| 1082 | 1082 | } // End If Statement |
@@ -1090,12 +1090,12 @@ discard block |
||
| 1090 | 1090 | * @param WC_Order $order |
| 1091 | 1091 | * @return void |
| 1092 | 1092 | */ |
| 1093 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1093 | + public function sensei_woocommerce_email_course_details($order) { |
|
| 1094 | 1094 | global $woocommerce; |
| 1095 | 1095 | |
| 1096 | 1096 | // exit early if not wc-completed or wc-processing |
| 1097 | - if( 'wc-completed' != $order->post_status |
|
| 1098 | - && 'wc-processing' != $order->post_status ) { |
|
| 1097 | + if ('wc-completed' != $order->post_status |
|
| 1098 | + && 'wc-processing' != $order->post_status) { |
|
| 1099 | 1099 | return; |
| 1100 | 1100 | } |
| 1101 | 1101 | |
@@ -1103,14 +1103,14 @@ discard block |
||
| 1103 | 1103 | $order_id = $order->id; |
| 1104 | 1104 | |
| 1105 | 1105 | //If object have items go through them all to find course |
| 1106 | - if ( 0 < sizeof( $order_items ) ) { |
|
| 1106 | + if (0 < sizeof($order_items)) { |
|
| 1107 | 1107 | |
| 1108 | - echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1108 | + echo '<h2>'.__('Course details', 'woothemes-sensei').'</h2>'; |
|
| 1109 | 1109 | |
| 1110 | - foreach ( $order_items as $item ) { |
|
| 1110 | + foreach ($order_items as $item) { |
|
| 1111 | 1111 | |
| 1112 | 1112 | $product_type = ''; |
| 1113 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1113 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 1114 | 1114 | // If item has variation_id then its from variation |
| 1115 | 1115 | $item_id = $item['variation_id']; |
| 1116 | 1116 | $product_type = 'variation'; |
@@ -1119,9 +1119,9 @@ discard block |
||
| 1119 | 1119 | $item_id = $item['product_id']; |
| 1120 | 1120 | } // End If Statement |
| 1121 | 1121 | |
| 1122 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1122 | + $user_id = get_post_meta($order_id, '_customer_user', true); |
|
| 1123 | 1123 | |
| 1124 | - if( $user_id ) { |
|
| 1124 | + if ($user_id) { |
|
| 1125 | 1125 | |
| 1126 | 1126 | // Get all courses for product |
| 1127 | 1127 | $args = array( |
@@ -1136,16 +1136,16 @@ discard block |
||
| 1136 | 1136 | 'orderby' => 'menu_order date', |
| 1137 | 1137 | 'order' => 'ASC', |
| 1138 | 1138 | ); |
| 1139 | - $courses = get_posts( $args ); |
|
| 1139 | + $courses = get_posts($args); |
|
| 1140 | 1140 | |
| 1141 | - if( $courses && count( $courses ) > 0 ) { |
|
| 1141 | + if ($courses && count($courses) > 0) { |
|
| 1142 | 1142 | |
| 1143 | - foreach( $courses as $course ) { |
|
| 1143 | + foreach ($courses as $course) { |
|
| 1144 | 1144 | |
| 1145 | 1145 | $title = $course->post_title; |
| 1146 | - $permalink = get_permalink( $course->ID ); |
|
| 1146 | + $permalink = get_permalink($course->ID); |
|
| 1147 | 1147 | |
| 1148 | - echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1148 | + echo '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>'; |
|
| 1149 | 1149 | } |
| 1150 | 1150 | } |
| 1151 | 1151 | } |
@@ -1161,44 +1161,44 @@ discard block |
||
| 1161 | 1161 | * @param integer $post_id |
| 1162 | 1162 | * @return array |
| 1163 | 1163 | */ |
| 1164 | - public function sensei_count_comments( $comments, $post_id ) { |
|
| 1164 | + public function sensei_count_comments($comments, $post_id) { |
|
| 1165 | 1165 | global $wpdb; |
| 1166 | 1166 | |
| 1167 | 1167 | $post_id = (int) $post_id; |
| 1168 | 1168 | |
| 1169 | 1169 | $count = wp_cache_get("comments-{$post_id}", 'counts'); |
| 1170 | 1170 | |
| 1171 | - if ( false !== $count ) { |
|
| 1171 | + if (false !== $count) { |
|
| 1172 | 1172 | return $count; |
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | - $statuses = array( '' ); // Default to the WP normal comments |
|
| 1176 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1177 | - foreach ( (array) $stati AS $status ) { |
|
| 1178 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1175 | + $statuses = array(''); // Default to the WP normal comments |
|
| 1176 | + $stati = $wpdb->get_results("SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A); |
|
| 1177 | + foreach ((array) $stati AS $status) { |
|
| 1178 | + if ('sensei_' != substr($status['comment_type'], 0, 7)) { |
|
| 1179 | 1179 | $statuses[] = $status['comment_type']; |
| 1180 | 1180 | } |
| 1181 | 1181 | } |
| 1182 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1182 | + $where = "WHERE comment_type IN ('".join("', '", array_unique($statuses))."')"; |
|
| 1183 | 1183 | |
| 1184 | - if ( $post_id > 0 ) |
|
| 1185 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1184 | + if ($post_id > 0) |
|
| 1185 | + $where .= $wpdb->prepare(" AND comment_post_ID = %d", $post_id); |
|
| 1186 | 1186 | |
| 1187 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1187 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A); |
|
| 1188 | 1188 | |
| 1189 | 1189 | $total = 0; |
| 1190 | 1190 | $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
| 1191 | - foreach ( (array) $count as $row ) { |
|
| 1191 | + foreach ((array) $count as $row) { |
|
| 1192 | 1192 | // Don't count post-trashed toward totals |
| 1193 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1193 | + if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) |
|
| 1194 | 1194 | $total += $row['num_comments']; |
| 1195 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1195 | + if (isset($approved[$row['comment_approved']])) |
|
| 1196 | 1196 | $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | $stats['total_comments'] = $total; |
| 1200 | - foreach ( $approved as $key ) { |
|
| 1201 | - if ( empty($stats[$key]) ) |
|
| 1200 | + foreach ($approved as $key) { |
|
| 1201 | + if (empty($stats[$key])) |
|
| 1202 | 1202 | $stats[$key] = 0; |
| 1203 | 1203 | } |
| 1204 | 1204 | |
@@ -1216,15 +1216,15 @@ discard block |
||
| 1216 | 1216 | * @return void |
| 1217 | 1217 | */ |
| 1218 | 1218 | public function init_image_sizes() { |
| 1219 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1220 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1221 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1222 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1223 | - |
|
| 1224 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1225 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1226 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1227 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1219 | + $course_archive_thumbnail = $this->get_image_size('course_archive_image'); |
|
| 1220 | + $course_single_thumbnail = $this->get_image_size('course_single_image'); |
|
| 1221 | + $lesson_archive_thumbnail = $this->get_image_size('lesson_archive_image'); |
|
| 1222 | + $lesson_single_thumbnail = $this->get_image_size('lesson_single_image'); |
|
| 1223 | + |
|
| 1224 | + add_image_size('course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop']); |
|
| 1225 | + add_image_size('course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop']); |
|
| 1226 | + add_image_size('lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop']); |
|
| 1227 | + add_image_size('lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop']); |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | /** |
@@ -1237,37 +1237,37 @@ discard block |
||
| 1237 | 1237 | * @param mixed $image_size |
| 1238 | 1238 | * @return string |
| 1239 | 1239 | */ |
| 1240 | - public function get_image_size( $image_size ) { |
|
| 1240 | + public function get_image_size($image_size) { |
|
| 1241 | 1241 | |
| 1242 | 1242 | // Only return sizes we define in settings |
| 1243 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1244 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1243 | + if ( ! in_array($image_size, array('course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image'))) |
|
| 1244 | + return apply_filters('sensei_get_image_size_'.$image_size, ''); |
|
| 1245 | 1245 | |
| 1246 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1247 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1246 | + if ( ! isset($this->settings->settings[$image_size.'_width'])) { |
|
| 1247 | + $this->settings->settings[$image_size.'_width'] = false; |
|
| 1248 | 1248 | } |
| 1249 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1250 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1249 | + if ( ! isset($this->settings->settings[$image_size.'_height'])) { |
|
| 1250 | + $this->settings->settings[$image_size.'_height'] = false; |
|
| 1251 | 1251 | } |
| 1252 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1253 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1252 | + if ( ! isset($this->settings->settings[$image_size.'_hard_crop'])) { |
|
| 1253 | + $this->settings->settings[$image_size.'_hard_crop'] = false; |
|
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | - $size = array_filter( array( |
|
| 1257 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1258 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1259 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1260 | - ) ); |
|
| 1256 | + $size = array_filter(array( |
|
| 1257 | + 'width' => $this->settings->settings[$image_size.'_width'], |
|
| 1258 | + 'height' => $this->settings->settings[$image_size.'_height'], |
|
| 1259 | + 'crop' => $this->settings->settings[$image_size.'_hard_crop'] |
|
| 1260 | + )); |
|
| 1261 | 1261 | |
| 1262 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1263 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1264 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1262 | + $size['width'] = isset($size['width']) ? $size['width'] : '100'; |
|
| 1263 | + $size['height'] = isset($size['height']) ? $size['height'] : '100'; |
|
| 1264 | + $size['crop'] = isset($size['crop']) ? $size['crop'] : 0; |
|
| 1265 | 1265 | |
| 1266 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1266 | + return apply_filters('sensei_get_image_size_'.$image_size, $size); |
|
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | - public function body_class( $classes ) { |
|
| 1270 | - if( is_sensei() ) { |
|
| 1269 | + public function body_class($classes) { |
|
| 1270 | + if (is_sensei()) { |
|
| 1271 | 1271 | $classes[] = 'sensei'; |
| 1272 | 1272 | } |
| 1273 | 1273 | return $classes; |
@@ -1280,9 +1280,9 @@ discard block |
||
| 1280 | 1280 | * @since 1.7.0 |
| 1281 | 1281 | */ |
| 1282 | 1282 | public function jetpack_latex_support() { |
| 1283 | - if ( function_exists( 'latex_markup') ) { |
|
| 1284 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1285 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1283 | + if (function_exists('latex_markup')) { |
|
| 1284 | + add_filter('sensei_question_title', 'latex_markup'); |
|
| 1285 | + add_filter('sensei_answer_text', 'latex_markup'); |
|
| 1286 | 1286 | } |
| 1287 | 1287 | } |
| 1288 | 1288 | |
@@ -1294,21 +1294,21 @@ discard block |
||
| 1294 | 1294 | * |
| 1295 | 1295 | * @since 1.8.0 |
| 1296 | 1296 | */ |
| 1297 | - public function load_modules_class(){ |
|
| 1297 | + public function load_modules_class() { |
|
| 1298 | 1298 | global $sensei_modules; |
| 1299 | 1299 | |
| 1300 | - if( !class_exists( 'Sensei_Modules' ) |
|
| 1301 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1300 | + if ( ! class_exists('Sensei_Modules') |
|
| 1301 | + && 'Sensei_Modules' != get_class($sensei_modules)) { |
|
| 1302 | 1302 | |
| 1303 | 1303 | //Load the modules class |
| 1304 | - require_once( 'class-sensei-modules.php'); |
|
| 1305 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1304 | + require_once('class-sensei-modules.php'); |
|
| 1305 | + Sensei()->modules = new Sensei_Core_Modules($this->file); |
|
| 1306 | 1306 | |
| 1307 | - }else{ |
|
| 1307 | + } else { |
|
| 1308 | 1308 | // fallback for people still using the modules extension. |
| 1309 | 1309 | global $sensei_modules; |
| 1310 | 1310 | Sensei()->modules = $sensei_modules; |
| 1311 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1311 | + add_action('admin_notices', array($this, 'disable_sensei_modules_extension'), 30); |
|
| 1312 | 1312 | } |
| 1313 | 1313 | } |
| 1314 | 1314 | |
@@ -1317,12 +1317,12 @@ discard block |
||
| 1317 | 1317 | * |
| 1318 | 1318 | * @since 1.8.0 |
| 1319 | 1319 | */ |
| 1320 | - public function disable_sensei_modules_extension(){ ?> |
|
| 1320 | + public function disable_sensei_modules_extension() { ?> |
|
| 1321 | 1321 | <div class="notice updated fade"> |
| 1322 | 1322 | <p> |
| 1323 | 1323 | <?php |
| 1324 | 1324 | $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
| 1325 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1325 | + $plugin_link_element = '<a href="'.$plugin_manage_url.'" >plugins page</a> '; |
|
| 1326 | 1326 | ?> |
| 1327 | 1327 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
| 1328 | 1328 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
@@ -1340,18 +1340,18 @@ discard block |
||
| 1340 | 1340 | * |
| 1341 | 1341 | * @since 1.9.0 |
| 1342 | 1342 | */ |
| 1343 | - public function flush_rewrite_rules(){ |
|
| 1343 | + public function flush_rewrite_rules() { |
|
| 1344 | 1344 | |
| 1345 | 1345 | // ensures that the rewrite rules are flushed on the second |
| 1346 | 1346 | // attempt. This ensure that the settings for any other process |
| 1347 | 1347 | // have been completed and saved to the database before we refresh the |
| 1348 | 1348 | // rewrite rules. |
| 1349 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1350 | - if( '1' == $option ) { |
|
| 1349 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1350 | + if ('1' == $option) { |
|
| 1351 | 1351 | |
| 1352 | 1352 | update_option('sensei_flush_rewrite_rules', '2'); |
| 1353 | 1353 | |
| 1354 | - }elseif( '2' == $option ) { |
|
| 1354 | + }elseif ('2' == $option) { |
|
| 1355 | 1355 | |
| 1356 | 1356 | flush_rewrite_rules(); |
| 1357 | 1357 | update_option('sensei_flush_rewrite_rules', '0'); |
@@ -1366,7 +1366,7 @@ discard block |
||
| 1366 | 1366 | * |
| 1367 | 1367 | * @since 1.9.0 |
| 1368 | 1368 | */ |
| 1369 | - public function initiate_rewrite_rules_flush(){ |
|
| 1369 | + public function initiate_rewrite_rules_flush() { |
|
| 1370 | 1370 | |
| 1371 | 1371 | update_option('sensei_flush_rewrite_rules', '1'); |
| 1372 | 1372 | |
@@ -1379,4 +1379,4 @@ discard block |
||
| 1379 | 1379 | * for backward compatibility |
| 1380 | 1380 | * @since 1.9.0 |
| 1381 | 1381 | */ |
| 1382 | -class Woothemes_Sensei extends Sensei_Main{ } |
|
| 1382 | +class Woothemes_Sensei extends Sensei_Main { } |
|
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | 'order' => $order, |
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | - // Handle search |
|
| 166 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 167 | - $args['search'] = esc_html( $_GET['s'] ); |
|
| 168 | - } |
|
| 165 | + // Handle search |
|
| 166 | + if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 167 | + $args['search'] = esc_html( $_GET['s'] ); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | 170 | switch ( $this->type ) { |
| 171 | 171 | case 'courses': |
@@ -222,10 +222,10 @@ discard block |
||
| 222 | 222 | ); |
| 223 | 223 | |
| 224 | 224 | |
| 225 | - // Handle search |
|
| 226 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 227 | - $args['search'] = esc_html( $_GET['s'] ); |
|
| 228 | - } |
|
| 225 | + // Handle search |
|
| 226 | + if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 227 | + $args['search'] = esc_html( $_GET['s'] ); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | // Start the csv with the column headings |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * Generates the overall array for a single item in the display |
| 264 | 264 | * @since 1.7.0 |
| 265 | 265 | * @param object $item The current item |
| 266 | - * @return array $column_data; |
|
| 266 | + * @return array $column_data; |
|
| 267 | 267 | */ |
| 268 | 268 | protected function get_row_data( $item ) { |
| 269 | 269 | |
@@ -422,8 +422,8 @@ discard block |
||
| 422 | 422 | |
| 423 | 423 | // Output the users data |
| 424 | 424 | if ( $this->csv_output ) { |
| 425 | - $user_name = Sensei()->learners->get_learner_full_name( $item->ID ); |
|
| 426 | - } |
|
| 425 | + $user_name = Sensei()->learners->get_learner_full_name( $item->ID ); |
|
| 426 | + } |
|
| 427 | 427 | else { |
| 428 | 428 | $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) ); |
| 429 | 429 | $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>'; |
@@ -517,17 +517,17 @@ discard block |
||
| 517 | 517 | // This stops the full meta data of each user being loaded |
| 518 | 518 | $args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' ); |
| 519 | 519 | |
| 520 | - /** |
|
| 521 | - * Filter the WP_User_Query arguments |
|
| 522 | - * @since 1.6.0 |
|
| 523 | - * @param $args |
|
| 524 | - */ |
|
| 525 | - $args = apply_filters( 'sensei_analysis_overview_filter_users', $args ); |
|
| 520 | + /** |
|
| 521 | + * Filter the WP_User_Query arguments |
|
| 522 | + * @since 1.6.0 |
|
| 523 | + * @param $args |
|
| 524 | + */ |
|
| 525 | + $args = apply_filters( 'sensei_analysis_overview_filter_users', $args ); |
|
| 526 | 526 | $wp_user_search = new WP_User_Query( $args ); |
| 527 | - $learners = $wp_user_search->get_results(); |
|
| 527 | + $learners = $wp_user_search->get_results(); |
|
| 528 | 528 | $this->total_items = $wp_user_search->get_total(); |
| 529 | 529 | |
| 530 | - return $learners; |
|
| 530 | + return $learners; |
|
| 531 | 531 | |
| 532 | 532 | } // End get_learners() |
| 533 | 533 | |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Analysis Overview List Table Class |
@@ -306,8 +309,7 @@ discard block |
||
| 306 | 309 | // Output course data |
| 307 | 310 | if ( $this->csv_output ) { |
| 308 | 311 | $course_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
| 309 | - } |
|
| 310 | - else { |
|
| 312 | + } else { |
|
| 311 | 313 | $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID ), admin_url( 'admin.php' ) ); |
| 312 | 314 | |
| 313 | 315 | $course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
@@ -363,16 +365,14 @@ discard block |
||
| 363 | 365 | // Output lesson data |
| 364 | 366 | if ( $this->csv_output ) { |
| 365 | 367 | $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
| 366 | - } |
|
| 367 | - else { |
|
| 368 | + } else { |
|
| 368 | 369 | $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) ); |
| 369 | 370 | $lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
| 370 | 371 | |
| 371 | 372 | if ( $course_id ) { |
| 372 | 373 | $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
| 373 | 374 | $course_title = '<a href="' . esc_url( $url ) . '">' . $course_title . '</a>'; |
| 374 | - } |
|
| 375 | - else { |
|
| 375 | + } else { |
|
| 376 | 376 | $course_title = __('n/a', 'woothemes-sensei'); |
| 377 | 377 | } |
| 378 | 378 | if ( is_numeric( $lesson_average_grade ) ) { |
@@ -423,8 +423,7 @@ discard block |
||
| 423 | 423 | // Output the users data |
| 424 | 424 | if ( $this->csv_output ) { |
| 425 | 425 | $user_name = Sensei()->learners->get_learner_full_name( $item->ID ); |
| 426 | - } |
|
| 427 | - else { |
|
| 426 | + } else { |
|
| 428 | 427 | $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) ); |
| 429 | 428 | $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>'; |
| 430 | 429 | $user_average_grade .= '%'; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Analysis Overview List Table Class |
@@ -21,17 +21,17 @@ discard block |
||
| 21 | 21 | * @since 1.2.0 |
| 22 | 22 | * @return void |
| 23 | 23 | */ |
| 24 | - public function __construct ( $type = 'users' ) { |
|
| 25 | - $this->type = in_array( $type, array( 'courses', 'lessons', 'users' ) ) ? $type : 'users'; |
|
| 24 | + public function __construct($type = 'users') { |
|
| 25 | + $this->type = in_array($type, array('courses', 'lessons', 'users')) ? $type : 'users'; |
|
| 26 | 26 | |
| 27 | 27 | // Load Parent token into constructor |
| 28 | - parent::__construct( 'analysis_overview' ); |
|
| 28 | + parent::__construct('analysis_overview'); |
|
| 29 | 29 | |
| 30 | 30 | // Actions |
| 31 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
| 32 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
| 31 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
| 32 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
| 33 | 33 | |
| 34 | - add_filter( 'sensei_list_table_search_button_text', array( $this, 'search_button' ) ); |
|
| 34 | + add_filter('sensei_list_table_search_button_text', array($this, 'search_button')); |
|
| 35 | 35 | } // End __construct() |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -41,41 +41,41 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function get_columns() { |
| 43 | 43 | |
| 44 | - switch( $this->type ) { |
|
| 44 | + switch ($this->type) { |
|
| 45 | 45 | case 'courses': |
| 46 | 46 | $columns = array( |
| 47 | - 'title' => __( 'Course', 'woothemes-sensei' ), |
|
| 48 | - 'students' => __( 'Learners', 'woothemes-sensei' ), |
|
| 49 | - 'lessons' => __( 'Lessons', 'woothemes-sensei' ), |
|
| 50 | - 'completions' => __( 'Completed', 'woothemes-sensei' ), |
|
| 51 | - 'average_percent' => __( 'Average Percentage', 'woothemes-sensei' ), |
|
| 47 | + 'title' => __('Course', 'woothemes-sensei'), |
|
| 48 | + 'students' => __('Learners', 'woothemes-sensei'), |
|
| 49 | + 'lessons' => __('Lessons', 'woothemes-sensei'), |
|
| 50 | + 'completions' => __('Completed', 'woothemes-sensei'), |
|
| 51 | + 'average_percent' => __('Average Percentage', 'woothemes-sensei'), |
|
| 52 | 52 | ); |
| 53 | 53 | break; |
| 54 | 54 | |
| 55 | 55 | case 'lessons': |
| 56 | 56 | $columns = array( |
| 57 | - 'title' => __( 'Lesson', 'woothemes-sensei' ), |
|
| 58 | - 'course' => __( 'Course', 'woothemes-sensei' ), |
|
| 59 | - 'students' => __( 'Learners', 'woothemes-sensei' ), |
|
| 60 | - 'completions' => __( 'Completed', 'woothemes-sensei' ), |
|
| 61 | - 'average_grade' => __( 'Average Grade', 'woothemes-sensei' ), |
|
| 57 | + 'title' => __('Lesson', 'woothemes-sensei'), |
|
| 58 | + 'course' => __('Course', 'woothemes-sensei'), |
|
| 59 | + 'students' => __('Learners', 'woothemes-sensei'), |
|
| 60 | + 'completions' => __('Completed', 'woothemes-sensei'), |
|
| 61 | + 'average_grade' => __('Average Grade', 'woothemes-sensei'), |
|
| 62 | 62 | ); |
| 63 | 63 | break; |
| 64 | 64 | |
| 65 | 65 | case 'users': |
| 66 | 66 | default: |
| 67 | 67 | $columns = array( |
| 68 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
| 69 | - 'registered' => __( 'Date Registered', 'woothemes-sensei' ), |
|
| 70 | - 'active_courses' => __( 'Active Courses', 'woothemes-sensei' ), |
|
| 71 | - 'completed_courses' => __( 'Completed Courses', 'woothemes-sensei' ), |
|
| 72 | - 'average_grade' => __( 'Average Grade', 'woothemes-sensei' ), |
|
| 68 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
| 69 | + 'registered' => __('Date Registered', 'woothemes-sensei'), |
|
| 70 | + 'active_courses' => __('Active Courses', 'woothemes-sensei'), |
|
| 71 | + 'completed_courses' => __('Completed Courses', 'woothemes-sensei'), |
|
| 72 | + 'average_grade' => __('Average Grade', 'woothemes-sensei'), |
|
| 73 | 73 | ); |
| 74 | 74 | break; |
| 75 | 75 | } |
| 76 | 76 | // Backwards compatible filter name, moving forward should have single filter name |
| 77 | - $columns = apply_filters( 'sensei_analysis_overview_' . $this->type . '_columns', $columns, $this ); |
|
| 78 | - $columns = apply_filters( 'sensei_analysis_overview_columns', $columns, $this ); |
|
| 77 | + $columns = apply_filters('sensei_analysis_overview_'.$this->type.'_columns', $columns, $this); |
|
| 78 | + $columns = apply_filters('sensei_analysis_overview_columns', $columns, $this); |
|
| 79 | 79 | return $columns; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -86,41 +86,41 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function get_sortable_columns() { |
| 88 | 88 | |
| 89 | - switch( $this->type ) { |
|
| 89 | + switch ($this->type) { |
|
| 90 | 90 | case 'courses': |
| 91 | 91 | $columns = array( |
| 92 | - 'title' => array( 'title', false ), |
|
| 93 | - 'students' => array( 'students', false ), |
|
| 94 | - 'lessons' => array( 'lessons', false ), |
|
| 95 | - 'completions' => array( 'completions', false ), |
|
| 96 | - 'average_percent' => array( 'average_percent', false ), |
|
| 92 | + 'title' => array('title', false), |
|
| 93 | + 'students' => array('students', false), |
|
| 94 | + 'lessons' => array('lessons', false), |
|
| 95 | + 'completions' => array('completions', false), |
|
| 96 | + 'average_percent' => array('average_percent', false), |
|
| 97 | 97 | ); |
| 98 | 98 | break; |
| 99 | 99 | |
| 100 | 100 | case 'lessons': |
| 101 | 101 | $columns = array( |
| 102 | - 'title' => array( 'title', false ), |
|
| 103 | - 'course' => array( 'course', false ), |
|
| 104 | - 'students' => array( 'students', false ), |
|
| 105 | - 'completions' => array( 'completions', false ), |
|
| 106 | - 'average_grade' => array( 'average_grade', false ), |
|
| 102 | + 'title' => array('title', false), |
|
| 103 | + 'course' => array('course', false), |
|
| 104 | + 'students' => array('students', false), |
|
| 105 | + 'completions' => array('completions', false), |
|
| 106 | + 'average_grade' => array('average_grade', false), |
|
| 107 | 107 | ); |
| 108 | 108 | break; |
| 109 | 109 | |
| 110 | 110 | case 'users': |
| 111 | 111 | default: |
| 112 | 112 | $columns = array( |
| 113 | - 'title' => array( 'user_login', false ), |
|
| 114 | - 'registered' => array( 'registered', false ), |
|
| 115 | - 'active_courses' => array( 'active_courses', false ), |
|
| 116 | - 'completed_courses' => array( 'completed_courses', false ), |
|
| 117 | - 'average_grade' => array( 'average_grade', false ) |
|
| 113 | + 'title' => array('user_login', false), |
|
| 114 | + 'registered' => array('registered', false), |
|
| 115 | + 'active_courses' => array('active_courses', false), |
|
| 116 | + 'completed_courses' => array('completed_courses', false), |
|
| 117 | + 'average_grade' => array('average_grade', false) |
|
| 118 | 118 | ); |
| 119 | 119 | break; |
| 120 | 120 | } |
| 121 | 121 | // Backwards compatible filter name, moving forward should have single filter name |
| 122 | - $columns = apply_filters( 'sensei_analysis_overview_' . $this->type . '_columns_sortable', $columns, $this ); |
|
| 123 | - $columns = apply_filters( 'sensei_analysis_overview_columns_sortable', $columns, $this ); |
|
| 122 | + $columns = apply_filters('sensei_analysis_overview_'.$this->type.'_columns_sortable', $columns, $this); |
|
| 123 | + $columns = apply_filters('sensei_analysis_overview_columns_sortable', $columns, $this); |
|
| 124 | 124 | return $columns; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -134,25 +134,25 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | // Handle orderby |
| 136 | 136 | $orderby = ''; |
| 137 | - if ( !empty( $_GET['orderby'] ) ) { |
|
| 138 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
| 139 | - $orderby = esc_html( $_GET['orderby'] ); |
|
| 137 | + if ( ! empty($_GET['orderby'])) { |
|
| 138 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
| 139 | + $orderby = esc_html($_GET['orderby']); |
|
| 140 | 140 | } // End If Statement |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // Handle order |
| 144 | 144 | $order = 'ASC'; |
| 145 | - if ( !empty( $_GET['order'] ) ) { |
|
| 146 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
| 145 | + if ( ! empty($_GET['order'])) { |
|
| 146 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
| 150 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
| 149 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
| 150 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
| 151 | 151 | |
| 152 | 152 | $paged = $this->get_pagenum(); |
| 153 | 153 | $offset = 0; |
| 154 | - if ( !empty($paged) ) { |
|
| 155 | - $offset = $per_page * ( $paged - 1 ); |
|
| 154 | + if ( ! empty($paged)) { |
|
| 155 | + $offset = $per_page * ($paged - 1); |
|
| 156 | 156 | } // End If Statement |
| 157 | 157 | |
| 158 | 158 | $args = array( |
@@ -163,32 +163,32 @@ discard block |
||
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | 165 | // Handle search |
| 166 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 167 | - $args['search'] = esc_html( $_GET['s'] ); |
|
| 166 | + if (isset($_GET['s']) && ! empty($_GET['s'])) { |
|
| 167 | + $args['search'] = esc_html($_GET['s']); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - switch ( $this->type ) { |
|
| 170 | + switch ($this->type) { |
|
| 171 | 171 | case 'courses': |
| 172 | - $this->items = $this->get_courses( $args ); |
|
| 172 | + $this->items = $this->get_courses($args); |
|
| 173 | 173 | break; |
| 174 | 174 | |
| 175 | 175 | case 'lessons': |
| 176 | - $this->items = $this->get_lessons( $args ); |
|
| 176 | + $this->items = $this->get_lessons($args); |
|
| 177 | 177 | break; |
| 178 | 178 | |
| 179 | 179 | case 'users': |
| 180 | 180 | default : |
| 181 | - $this->items = $this->get_learners( $args ); |
|
| 181 | + $this->items = $this->get_learners($args); |
|
| 182 | 182 | break; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $total_items = $this->total_items; |
| 186 | - $total_pages = ceil( $total_items / $per_page ); |
|
| 187 | - $this->set_pagination_args( array( |
|
| 186 | + $total_pages = ceil($total_items / $per_page); |
|
| 187 | + $this->set_pagination_args(array( |
|
| 188 | 188 | 'total_items' => $total_items, |
| 189 | 189 | 'total_pages' => $total_pages, |
| 190 | 190 | 'per_page' => $per_page |
| 191 | - ) ); |
|
| 191 | + )); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @since 1.7.0 |
| 197 | 197 | * @return data |
| 198 | 198 | */ |
| 199 | - public function generate_report( $report ) { |
|
| 199 | + public function generate_report($report) { |
|
| 200 | 200 | |
| 201 | 201 | $data = array(); |
| 202 | 202 | |
@@ -204,16 +204,16 @@ discard block |
||
| 204 | 204 | |
| 205 | 205 | // Handle orderby |
| 206 | 206 | $orderby = ''; |
| 207 | - if ( !empty( $_GET['orderby'] ) ) { |
|
| 208 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
| 209 | - $orderby = esc_html( $_GET['orderby'] ); |
|
| 207 | + if ( ! empty($_GET['orderby'])) { |
|
| 208 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
| 209 | + $orderby = esc_html($_GET['orderby']); |
|
| 210 | 210 | } // End If Statement |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | // Handle order |
| 214 | 214 | $order = 'ASC'; |
| 215 | - if ( !empty( $_GET['order'] ) ) { |
|
| 216 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
| 215 | + if ( ! empty($_GET['order'])) { |
|
| 216 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | $args = array( |
@@ -223,37 +223,37 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | |
| 225 | 225 | // Handle search |
| 226 | - if ( isset( $_GET['s'] ) && !empty( $_GET['s'] ) ) { |
|
| 227 | - $args['search'] = esc_html( $_GET['s'] ); |
|
| 226 | + if (isset($_GET['s']) && ! empty($_GET['s'])) { |
|
| 227 | + $args['search'] = esc_html($_GET['s']); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | // Start the csv with the column headings |
| 232 | 232 | $column_headers = array(); |
| 233 | 233 | $columns = $this->get_columns(); |
| 234 | - foreach( $columns AS $key => $title ) { |
|
| 234 | + foreach ($columns AS $key => $title) { |
|
| 235 | 235 | $column_headers[] = $title; |
| 236 | 236 | } |
| 237 | 237 | $data[] = $column_headers; |
| 238 | 238 | |
| 239 | - switch ( $this->type ) { |
|
| 239 | + switch ($this->type) { |
|
| 240 | 240 | case 'courses': |
| 241 | - $this->items = $this->get_courses( $args ); |
|
| 241 | + $this->items = $this->get_courses($args); |
|
| 242 | 242 | break; |
| 243 | 243 | |
| 244 | 244 | case 'lessons': |
| 245 | - $this->items = $this->get_lessons( $args ); |
|
| 245 | + $this->items = $this->get_lessons($args); |
|
| 246 | 246 | break; |
| 247 | 247 | |
| 248 | 248 | case 'users': |
| 249 | 249 | default : |
| 250 | - $this->items = $this->get_learners( $args ); |
|
| 250 | + $this->items = $this->get_learners($args); |
|
| 251 | 251 | break; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // Process each row |
| 255 | - foreach( $this->items AS $item) { |
|
| 256 | - $data[] = $this->get_row_data( $item ); |
|
| 255 | + foreach ($this->items AS $item) { |
|
| 256 | + $data[] = $this->get_row_data($item); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | return $data; |
@@ -265,9 +265,9 @@ discard block |
||
| 265 | 265 | * @param object $item The current item |
| 266 | 266 | * @return array $column_data; |
| 267 | 267 | */ |
| 268 | - protected function get_row_data( $item ) { |
|
| 268 | + protected function get_row_data($item) { |
|
| 269 | 269 | |
| 270 | - switch( $this->type ) { |
|
| 270 | + switch ($this->type) { |
|
| 271 | 271 | case 'courses' : |
| 272 | 272 | // Get Learners (i.e. those who have started) |
| 273 | 273 | $course_args = array( |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | 'type' => 'sensei_course_status', |
| 276 | 276 | 'status' => 'any', |
| 277 | 277 | ); |
| 278 | - $course_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_learners', $course_args, $item ) ); |
|
| 278 | + $course_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_learners', $course_args, $item)); |
|
| 279 | 279 | |
| 280 | 280 | // Get Course Completions |
| 281 | 281 | $course_args = array( |
@@ -283,10 +283,10 @@ discard block |
||
| 283 | 283 | 'type' => 'sensei_course_status', |
| 284 | 284 | 'status' => 'complete', |
| 285 | 285 | ); |
| 286 | - $course_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_completions', $course_args, $item ) ); |
|
| 286 | + $course_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_completions', $course_args, $item)); |
|
| 287 | 287 | |
| 288 | 288 | // Course Lessons |
| 289 | - $course_lessons = Sensei()->lesson->lesson_count( array('publish', 'private'), $item->ID ); |
|
| 289 | + $course_lessons = Sensei()->lesson->lesson_count(array('publish', 'private'), $item->ID); |
|
| 290 | 290 | |
| 291 | 291 | // Get Percent Complete |
| 292 | 292 | $grade_args = array( |
@@ -295,30 +295,30 @@ discard block |
||
| 295 | 295 | 'status' => 'any', |
| 296 | 296 | 'meta_key' => 'percent', |
| 297 | 297 | ); |
| 298 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 299 | - $course_percentage = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_course_percentage', $grade_args, $item ), true ); |
|
| 300 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 298 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 299 | + $course_percentage = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_course_percentage', $grade_args, $item), true); |
|
| 300 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 301 | 301 | |
| 302 | - $percent_count = !empty( $course_percentage->total ) ? $course_percentage->total : 1; |
|
| 303 | - $percent_total = !empty( $course_percentage->meta_sum ) ? doubleval( $course_percentage->meta_sum ) : 0; |
|
| 304 | - $course_average_percent = abs( round( doubleval( $percent_total / $percent_count ), 2 ) ); |
|
| 302 | + $percent_count = ! empty($course_percentage->total) ? $course_percentage->total : 1; |
|
| 303 | + $percent_total = ! empty($course_percentage->meta_sum) ? doubleval($course_percentage->meta_sum) : 0; |
|
| 304 | + $course_average_percent = abs(round(doubleval($percent_total / $percent_count), 2)); |
|
| 305 | 305 | |
| 306 | 306 | // Output course data |
| 307 | - if ( $this->csv_output ) { |
|
| 308 | - $course_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
| 307 | + if ($this->csv_output) { |
|
| 308 | + $course_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
| 309 | 309 | } |
| 310 | 310 | else { |
| 311 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
| 311 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $item->ID), admin_url('admin.php')); |
|
| 312 | 312 | |
| 313 | - $course_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
| 313 | + $course_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
| 314 | 314 | $course_average_percent .= '%'; |
| 315 | 315 | } // End If Statement |
| 316 | - $column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $course_title, |
|
| 316 | + $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $course_title, |
|
| 317 | 317 | 'students' => $course_students, |
| 318 | 318 | 'lessons' => $course_lessons, |
| 319 | 319 | 'completions' => $course_completions, |
| 320 | 320 | 'average_percent' => $course_average_percent, |
| 321 | - ), $item, $this ); |
|
| 321 | + ), $item, $this); |
|
| 322 | 322 | break; |
| 323 | 323 | |
| 324 | 324 | case 'lessons' : |
@@ -328,63 +328,63 @@ discard block |
||
| 328 | 328 | 'type' => 'sensei_lesson_status', |
| 329 | 329 | 'status' => 'any', |
| 330 | 330 | ); |
| 331 | - $lesson_students = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_learners', $lesson_args, $item ) ); |
|
| 331 | + $lesson_students = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_learners', $lesson_args, $item)); |
|
| 332 | 332 | |
| 333 | 333 | // Get Course Completions |
| 334 | 334 | $lesson_args = array( |
| 335 | 335 | 'post_id' => $item->ID, |
| 336 | 336 | 'type' => 'sensei_lesson_status', |
| 337 | - 'status' => array( 'complete', 'graded', 'passed', 'failed' ), |
|
| 337 | + 'status' => array('complete', 'graded', 'passed', 'failed'), |
|
| 338 | 338 | 'count' => true, |
| 339 | 339 | ); |
| 340 | - $lesson_completions = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_completions', $lesson_args, $item ) ); |
|
| 340 | + $lesson_completions = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_completions', $lesson_args, $item)); |
|
| 341 | 341 | |
| 342 | 342 | // Course |
| 343 | - $course_id = get_post_meta( $item->ID, '_lesson_course', true ); |
|
| 344 | - $course_title = $course_id ? get_the_title( $course_id ) : ''; |
|
| 343 | + $course_id = get_post_meta($item->ID, '_lesson_course', true); |
|
| 344 | + $course_title = $course_id ? get_the_title($course_id) : ''; |
|
| 345 | 345 | |
| 346 | 346 | $lesson_average_grade = __('n/a', 'woothemes-sensei'); |
| 347 | - if ( false != get_post_meta($item->ID, '_quiz_has_questions', true) ) { |
|
| 347 | + if (false != get_post_meta($item->ID, '_quiz_has_questions', true)) { |
|
| 348 | 348 | // Get Percent Complete |
| 349 | 349 | $grade_args = array( |
| 350 | 350 | 'post_id' => $item->ID, |
| 351 | 351 | 'type' => 'sensei_lesson_status', |
| 352 | - 'status' => array( 'graded', 'passed', 'failed' ), |
|
| 352 | + 'status' => array('graded', 'passed', 'failed'), |
|
| 353 | 353 | 'meta_key' => 'grade', |
| 354 | 354 | ); |
| 355 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 356 | - $lesson_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_lesson_grades', $grade_args, $item ), true ); |
|
| 357 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 355 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 356 | + $lesson_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_lesson_grades', $grade_args, $item), true); |
|
| 357 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 358 | 358 | |
| 359 | - $grade_count = !empty( $lesson_grades->total ) ? $lesson_grades->total : 1; |
|
| 360 | - $grade_total = !empty( $lesson_grades->meta_sum ) ? doubleval( $lesson_grades->meta_sum ) : 0; |
|
| 361 | - $lesson_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
| 359 | + $grade_count = ! empty($lesson_grades->total) ? $lesson_grades->total : 1; |
|
| 360 | + $grade_total = ! empty($lesson_grades->meta_sum) ? doubleval($lesson_grades->meta_sum) : 0; |
|
| 361 | + $lesson_average_grade = abs(round(doubleval($grade_total / $grade_count), 2)); |
|
| 362 | 362 | } |
| 363 | 363 | // Output lesson data |
| 364 | - if ( $this->csv_output ) { |
|
| 365 | - $lesson_title = apply_filters( 'the_title', $item->post_title, $item->ID ); |
|
| 364 | + if ($this->csv_output) { |
|
| 365 | + $lesson_title = apply_filters('the_title', $item->post_title, $item->ID); |
|
| 366 | 366 | } |
| 367 | 367 | else { |
| 368 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
| 369 | - $lesson_title = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . apply_filters( 'the_title', $item->post_title, $item->ID ) . '</a></strong>'; |
|
| 368 | + $url = add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->ID), admin_url('admin.php')); |
|
| 369 | + $lesson_title = '<strong><a class="row-title" href="'.esc_url($url).'">'.apply_filters('the_title', $item->post_title, $item->ID).'</a></strong>'; |
|
| 370 | 370 | |
| 371 | - if ( $course_id ) { |
|
| 372 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ); |
|
| 373 | - $course_title = '<a href="' . esc_url( $url ) . '">' . $course_title . '</a>'; |
|
| 371 | + if ($course_id) { |
|
| 372 | + $url = add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php')); |
|
| 373 | + $course_title = '<a href="'.esc_url($url).'">'.$course_title.'</a>'; |
|
| 374 | 374 | } |
| 375 | 375 | else { |
| 376 | 376 | $course_title = __('n/a', 'woothemes-sensei'); |
| 377 | 377 | } |
| 378 | - if ( is_numeric( $lesson_average_grade ) ) { |
|
| 378 | + if (is_numeric($lesson_average_grade)) { |
|
| 379 | 379 | $lesson_average_grade .= '%'; |
| 380 | 380 | } |
| 381 | 381 | } // End If Statement |
| 382 | - $column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $lesson_title, |
|
| 382 | + $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $lesson_title, |
|
| 383 | 383 | 'course' => $course_title, |
| 384 | 384 | 'students' => $lesson_students, |
| 385 | 385 | 'completions' => $lesson_completions, |
| 386 | 386 | 'average_grade' => $lesson_average_grade, |
| 387 | - ), $item, $this ); |
|
| 387 | + ), $item, $this); |
|
| 388 | 388 | break; |
| 389 | 389 | |
| 390 | 390 | case 'users' : |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | 'type' => 'sensei_course_status', |
| 396 | 396 | 'status' => 'any', |
| 397 | 397 | ); |
| 398 | - $user_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_started', $course_args, $item ) ); |
|
| 398 | + $user_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_started', $course_args, $item)); |
|
| 399 | 399 | |
| 400 | 400 | // Get Completed Courses |
| 401 | 401 | $course_args = array( |
@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | 'type' => 'sensei_course_status', |
| 404 | 404 | 'status' => 'complete', |
| 405 | 405 | ); |
| 406 | - $user_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_courses_ended', $course_args, $item ) ); |
|
| 406 | + $user_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_courses_ended', $course_args, $item)); |
|
| 407 | 407 | |
| 408 | 408 | // Get Quiz Grades |
| 409 | 409 | $grade_args = array( |
@@ -412,29 +412,29 @@ discard block |
||
| 412 | 412 | 'status' => 'any', |
| 413 | 413 | 'meta_key' => 'grade', |
| 414 | 414 | ); |
| 415 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 416 | - $user_quiz_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_user_lesson_grades', $grade_args, $item ), true ); |
|
| 417 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 415 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 416 | + $user_quiz_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_user_lesson_grades', $grade_args, $item), true); |
|
| 417 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 418 | 418 | |
| 419 | - $grade_count = !empty( $user_quiz_grades->total ) ? $user_quiz_grades->total : 1; |
|
| 420 | - $grade_total = !empty( $user_quiz_grades->meta_sum ) ? doubleval( $user_quiz_grades->meta_sum ) : 0; |
|
| 421 | - $user_average_grade = abs( round( doubleval( $grade_total / $grade_count ), 2 ) ); |
|
| 419 | + $grade_count = ! empty($user_quiz_grades->total) ? $user_quiz_grades->total : 1; |
|
| 420 | + $grade_total = ! empty($user_quiz_grades->meta_sum) ? doubleval($user_quiz_grades->meta_sum) : 0; |
|
| 421 | + $user_average_grade = abs(round(doubleval($grade_total / $grade_count), 2)); |
|
| 422 | 422 | |
| 423 | 423 | // Output the users data |
| 424 | - if ( $this->csv_output ) { |
|
| 425 | - $user_name = Sensei()->learners->get_learner_full_name( $item->ID ); |
|
| 424 | + if ($this->csv_output) { |
|
| 425 | + $user_name = Sensei()->learners->get_learner_full_name($item->ID); |
|
| 426 | 426 | } |
| 427 | 427 | else { |
| 428 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->ID ), admin_url( 'admin.php' ) ); |
|
| 429 | - $user_name = '<strong><a class="row-title" href="' . esc_url( $url ) . '">' . $item->display_name . '</a></strong>'; |
|
| 428 | + $url = add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->ID), admin_url('admin.php')); |
|
| 429 | + $user_name = '<strong><a class="row-title" href="'.esc_url($url).'">'.$item->display_name.'</a></strong>'; |
|
| 430 | 430 | $user_average_grade .= '%'; |
| 431 | 431 | } // End If Statement |
| 432 | - $column_data = apply_filters( 'sensei_analysis_overview_column_data', array( 'title' => $user_name, |
|
| 432 | + $column_data = apply_filters('sensei_analysis_overview_column_data', array('title' => $user_name, |
|
| 433 | 433 | 'registered' => $item->user_registered, |
| 434 | - 'active_courses' => ( $user_courses_started - $user_courses_ended ), |
|
| 434 | + 'active_courses' => ($user_courses_started - $user_courses_ended), |
|
| 435 | 435 | 'completed_courses' => $user_courses_ended, |
| 436 | 436 | 'average_grade' => $user_average_grade, |
| 437 | - ), $item, $this ); |
|
| 437 | + ), $item, $this); |
|
| 438 | 438 | break; |
| 439 | 439 | } // end switch |
| 440 | 440 | return $column_data; |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | * @since 1.7.0 |
| 446 | 446 | * @return array courses |
| 447 | 447 | */ |
| 448 | - private function get_courses( $args ) { |
|
| 448 | + private function get_courses($args) { |
|
| 449 | 449 | $course_args = array( |
| 450 | 450 | 'post_type' => 'course', |
| 451 | 451 | 'post_status' => array('publish', 'private'), |
@@ -456,16 +456,16 @@ discard block |
||
| 456 | 456 | 'suppress_filters' => 0, |
| 457 | 457 | ); |
| 458 | 458 | |
| 459 | - if ( $this->csv_output ) { |
|
| 459 | + if ($this->csv_output) { |
|
| 460 | 460 | $course_args['posts_per_page'] = '-1'; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - if( isset( $args['search'] ) ) { |
|
| 463 | + if (isset($args['search'])) { |
|
| 464 | 464 | $course_args['s'] = $args['search']; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | // Using WP_Query as get_posts() doesn't support 'found_posts' |
| 468 | - $courses_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_courses', $course_args ) ); |
|
| 468 | + $courses_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_courses', $course_args)); |
|
| 469 | 469 | $this->total_items = $courses_query->found_posts; |
| 470 | 470 | return $courses_query->posts; |
| 471 | 471 | |
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | * @since 1.7.0 |
| 477 | 477 | * @return array lessons |
| 478 | 478 | */ |
| 479 | - private function get_lessons( $args ) { |
|
| 479 | + private function get_lessons($args) { |
|
| 480 | 480 | $lessons_args = array( |
| 481 | 481 | 'post_type' => 'lesson', |
| 482 | 482 | 'post_status' => array('publish', 'private'), |
@@ -487,16 +487,16 @@ discard block |
||
| 487 | 487 | 'suppress_filters' => 0, |
| 488 | 488 | ); |
| 489 | 489 | |
| 490 | - if ( $this->csv_output ) { |
|
| 490 | + if ($this->csv_output) { |
|
| 491 | 491 | $lessons_args['posts_per_page'] = '-1'; |
| 492 | 492 | } |
| 493 | 493 | |
| 494 | - if( isset( $args['search'] ) ) { |
|
| 494 | + if (isset($args['search'])) { |
|
| 495 | 495 | $lessons_args['s'] = $args['search']; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | // Using WP_Query as get_posts() doesn't support 'found_posts' |
| 499 | - $lessons_query = new WP_Query( apply_filters( 'sensei_analysis_overview_filter_lessons', $lessons_args ) ); |
|
| 499 | + $lessons_query = new WP_Query(apply_filters('sensei_analysis_overview_filter_lessons', $lessons_args)); |
|
| 500 | 500 | $this->total_items = $lessons_query->found_posts; |
| 501 | 501 | return $lessons_query->posts; |
| 502 | 502 | } // End get_lessons() |
@@ -506,24 +506,24 @@ discard block |
||
| 506 | 506 | * @since 1.7.0 |
| 507 | 507 | * @return array learners |
| 508 | 508 | */ |
| 509 | - private function get_learners( $args ) { |
|
| 509 | + private function get_learners($args) { |
|
| 510 | 510 | |
| 511 | - if ( !empty($args['search']) ) { |
|
| 511 | + if ( ! empty($args['search'])) { |
|
| 512 | 512 | $args = array( |
| 513 | - 'search' => '*' . trim( $args['search'], '*' ) . '*', |
|
| 513 | + 'search' => '*'.trim($args['search'], '*').'*', |
|
| 514 | 514 | ); |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | // This stops the full meta data of each user being loaded |
| 518 | - $args['fields'] = array( 'ID', 'user_login', 'user_email', 'user_registered', 'display_name' ); |
|
| 518 | + $args['fields'] = array('ID', 'user_login', 'user_email', 'user_registered', 'display_name'); |
|
| 519 | 519 | |
| 520 | 520 | /** |
| 521 | 521 | * Filter the WP_User_Query arguments |
| 522 | 522 | * @since 1.6.0 |
| 523 | 523 | * @param $args |
| 524 | 524 | */ |
| 525 | - $args = apply_filters( 'sensei_analysis_overview_filter_users', $args ); |
|
| 526 | - $wp_user_search = new WP_User_Query( $args ); |
|
| 525 | + $args = apply_filters('sensei_analysis_overview_filter_users', $args); |
|
| 526 | + $wp_user_search = new WP_User_Query($args); |
|
| 527 | 527 | $learners = $wp_user_search->get_results(); |
| 528 | 528 | $this->total_items = $wp_user_search->get_total(); |
| 529 | 529 | |
@@ -536,13 +536,13 @@ discard block |
||
| 536 | 536 | * @since 1.2.0 |
| 537 | 537 | * @return array $stats_to_render of stats boxes and values |
| 538 | 538 | */ |
| 539 | - public function stats_boxes () { |
|
| 539 | + public function stats_boxes() { |
|
| 540 | 540 | |
| 541 | 541 | // Get the data required |
| 542 | 542 | $user_count = count_users(); |
| 543 | - $user_count = apply_filters( 'sensei_analysis_total_users', $user_count['total_users'], $user_count ); |
|
| 544 | - $total_courses = Sensei()->course->course_count( array('publish', 'private') ); |
|
| 545 | - $total_lessons = Sensei()->lesson->lesson_count( array('publish', 'private') ); |
|
| 543 | + $user_count = apply_filters('sensei_analysis_total_users', $user_count['total_users'], $user_count); |
|
| 544 | + $total_courses = Sensei()->course->course_count(array('publish', 'private')); |
|
| 545 | + $total_lessons = Sensei()->lesson->lesson_count(array('publish', 'private')); |
|
| 546 | 546 | |
| 547 | 547 | $grade_args = array( |
| 548 | 548 | 'type' => 'sensei_lesson_status', |
@@ -550,36 +550,36 @@ discard block |
||
| 550 | 550 | 'meta_key' => 'grade', |
| 551 | 551 | ); |
| 552 | 552 | |
| 553 | - add_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 554 | - $total_quiz_grades = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_quiz_grades', $grade_args ), true ); |
|
| 555 | - remove_filter( 'comments_clauses', array( 'WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter' ) ); |
|
| 553 | + add_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 554 | + $total_quiz_grades = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_quiz_grades', $grade_args), true); |
|
| 555 | + remove_filter('comments_clauses', array('WooThemes_Sensei_Utils', 'comment_total_sum_meta_value_filter')); |
|
| 556 | 556 | |
| 557 | - $total_grade_count = !empty( $total_quiz_grades->total ) ? $total_quiz_grades->total : 1; |
|
| 558 | - $total_grade_total = !empty( $total_quiz_grades->meta_sum ) ? doubleval( $total_quiz_grades->meta_sum ) : 0; |
|
| 559 | - $total_average_grade = abs( round( doubleval( $total_grade_total / $total_grade_count ), 2 ) ); |
|
| 557 | + $total_grade_count = ! empty($total_quiz_grades->total) ? $total_quiz_grades->total : 1; |
|
| 558 | + $total_grade_total = ! empty($total_quiz_grades->meta_sum) ? doubleval($total_quiz_grades->meta_sum) : 0; |
|
| 559 | + $total_average_grade = abs(round(doubleval($total_grade_total / $total_grade_count), 2)); |
|
| 560 | 560 | |
| 561 | 561 | $course_args = array( |
| 562 | 562 | 'type' => 'sensei_course_status', |
| 563 | 563 | 'status' => 'any', |
| 564 | 564 | ); |
| 565 | - $total_courses_started = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_started', $course_args ) ); |
|
| 565 | + $total_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_started', $course_args)); |
|
| 566 | 566 | $course_args = array( |
| 567 | 567 | 'type' => 'sensei_course_status', |
| 568 | 568 | 'status' => 'complete', |
| 569 | 569 | ); |
| 570 | - $total_courses_ended = Sensei_Utils::sensei_check_for_activity( apply_filters( 'sensei_analysis_total_courses_ended', $course_args ) ); |
|
| 571 | - $average_courses_per_learner = abs( round( doubleval( $total_courses_started / $user_count ), 2 ) ); |
|
| 570 | + $total_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_ended', $course_args)); |
|
| 571 | + $average_courses_per_learner = abs(round(doubleval($total_courses_started / $user_count), 2)); |
|
| 572 | 572 | |
| 573 | 573 | // Setup the boxes to render |
| 574 | 574 | $stats_to_render = array( |
| 575 | - __( 'Total Courses', 'woothemes-sensei' ) => $total_courses, |
|
| 576 | - __( 'Total Lessons', 'woothemes-sensei' ) => $total_lessons, |
|
| 577 | - __( 'Total Learners', 'woothemes-sensei' ) => $user_count, |
|
| 578 | - __( 'Average Courses per Learner', 'woothemes-sensei' ) => $average_courses_per_learner, |
|
| 579 | - __( 'Average Grade', 'woothemes-sensei' ) => $total_average_grade . '%', |
|
| 580 | - __( 'Total Completed Courses', 'woothemes-sensei' ) => $total_courses_ended, |
|
| 575 | + __('Total Courses', 'woothemes-sensei') => $total_courses, |
|
| 576 | + __('Total Lessons', 'woothemes-sensei') => $total_lessons, |
|
| 577 | + __('Total Learners', 'woothemes-sensei') => $user_count, |
|
| 578 | + __('Average Courses per Learner', 'woothemes-sensei') => $average_courses_per_learner, |
|
| 579 | + __('Average Grade', 'woothemes-sensei') => $total_average_grade.'%', |
|
| 580 | + __('Total Completed Courses', 'woothemes-sensei') => $total_courses_ended, |
|
| 581 | 581 | ); |
| 582 | - return apply_filters( 'sensei_analysis_stats_boxes', $stats_to_render ); |
|
| 582 | + return apply_filters('sensei_analysis_stats_boxes', $stats_to_render); |
|
| 583 | 583 | } // End stats_boxes() |
| 584 | 584 | |
| 585 | 585 | /** |
@@ -589,12 +589,12 @@ discard block |
||
| 589 | 589 | * @return void |
| 590 | 590 | */ |
| 591 | 591 | public function no_items() { |
| 592 | - if( ! $this->view || 'users' == $this->view ) { |
|
| 592 | + if ( ! $this->view || 'users' == $this->view) { |
|
| 593 | 593 | $type = 'learners'; |
| 594 | 594 | } else { |
| 595 | 595 | $type = $this->view; |
| 596 | 596 | } |
| 597 | - echo sprintf( __( '%1$sNo %2$s found%3$s', 'woothemes-sensei' ), '<em>', $type, '</em>' ); |
|
| 597 | + echo sprintf(__('%1$sNo %2$s found%3$s', 'woothemes-sensei'), '<em>', $type, '</em>'); |
|
| 598 | 598 | } // End no_items() |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | 'page' => $this->page_slug, |
| 610 | 610 | ); |
| 611 | 611 | $learners_class = $courses_class = $lessons_class = ''; |
| 612 | - switch( $this->type ) { |
|
| 612 | + switch ($this->type) { |
|
| 613 | 613 | case 'courses': |
| 614 | 614 | $courses_class = 'current'; |
| 615 | 615 | break; |
@@ -627,18 +627,18 @@ discard block |
||
| 627 | 627 | $lesson_args['view'] = 'lessons'; |
| 628 | 628 | $courses_args['view'] = 'courses'; |
| 629 | 629 | |
| 630 | - $menu['learners'] = '<a class="' . $learners_class . '" href="' . esc_url( add_query_arg( $learner_args, admin_url( 'admin.php' ) ) ). '">' . __( 'Learners', 'woothemes-sensei' ) . '</a>'; |
|
| 631 | - $menu['courses'] = '<a class="' . $courses_class . '" href="' . esc_url ( add_query_arg( $courses_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Courses', 'woothemes-sensei' ) . '</a>'; |
|
| 632 | - $menu['lessons'] = '<a class="' . $lessons_class . '" href="' . esc_url( add_query_arg( $lesson_args, admin_url( 'admin.php' ) ) ) . '">' . __( 'Lessons', 'woothemes-sensei' ) . '</a>'; |
|
| 630 | + $menu['learners'] = '<a class="'.$learners_class.'" href="'.esc_url(add_query_arg($learner_args, admin_url('admin.php'))).'">'.__('Learners', 'woothemes-sensei').'</a>'; |
|
| 631 | + $menu['courses'] = '<a class="'.$courses_class.'" href="'.esc_url(add_query_arg($courses_args, admin_url('admin.php'))).'">'.__('Courses', 'woothemes-sensei').'</a>'; |
|
| 632 | + $menu['lessons'] = '<a class="'.$lessons_class.'" href="'.esc_url(add_query_arg($lesson_args, admin_url('admin.php'))).'">'.__('Lessons', 'woothemes-sensei').'</a>'; |
|
| 633 | 633 | |
| 634 | - $menu = apply_filters( 'sensei_analysis_overview_sub_menu', $menu ); |
|
| 635 | - if ( !empty($menu) ) { |
|
| 636 | - echo '<ul class="subsubsub">' . "\n"; |
|
| 637 | - foreach ( $menu as $class => $item ) { |
|
| 638 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
| 634 | + $menu = apply_filters('sensei_analysis_overview_sub_menu', $menu); |
|
| 635 | + if ( ! empty($menu)) { |
|
| 636 | + echo '<ul class="subsubsub">'."\n"; |
|
| 637 | + foreach ($menu as $class => $item) { |
|
| 638 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
| 639 | 639 | } |
| 640 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
| 641 | - echo '</ul>' . "\n"; |
|
| 640 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
| 641 | + echo '</ul>'."\n"; |
|
| 642 | 642 | } |
| 643 | 643 | } // End data_table_header() |
| 644 | 644 | |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | * @return void |
| 649 | 649 | */ |
| 650 | 650 | public function data_table_footer() { |
| 651 | - switch ( $this->type ) { |
|
| 651 | + switch ($this->type) { |
|
| 652 | 652 | case 'courses': |
| 653 | 653 | $report = 'courses-overview'; |
| 654 | 654 | break; |
@@ -662,8 +662,8 @@ discard block |
||
| 662 | 662 | $report = 'user-overview'; |
| 663 | 663 | break; |
| 664 | 664 | } // End Switch Statement |
| 665 | - $url = add_query_arg( array( 'page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report ), admin_url( 'admin.php' ) ); |
|
| 666 | - echo '<a class="button button-primary" href="' . esc_url( wp_nonce_url( $url, 'sensei_csv_download-' . $report, '_sdl_nonce' ) ) . '">' . __( 'Export all rows (CSV)', 'woothemes-sensei' ) . '</a>'; |
|
| 665 | + $url = add_query_arg(array('page' => $this->page_slug, 'view' => $this->type, 'sensei_report_download' => $report), admin_url('admin.php')); |
|
| 666 | + echo '<a class="button button-primary" href="'.esc_url(wp_nonce_url($url, 'sensei_csv_download-'.$report, '_sdl_nonce')).'">'.__('Export all rows (CSV)', 'woothemes-sensei').'</a>'; |
|
| 667 | 667 | } // End data_table_footer() |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -671,19 +671,19 @@ discard block |
||
| 671 | 671 | * @since 1.7.0 |
| 672 | 672 | * @return void |
| 673 | 673 | */ |
| 674 | - public function search_button( $text = '' ) { |
|
| 675 | - switch( $this->type ) { |
|
| 674 | + public function search_button($text = '') { |
|
| 675 | + switch ($this->type) { |
|
| 676 | 676 | case 'courses': |
| 677 | - $text = __( 'Search Courses', 'woothemes-sensei' ); |
|
| 677 | + $text = __('Search Courses', 'woothemes-sensei'); |
|
| 678 | 678 | break; |
| 679 | 679 | |
| 680 | 680 | case 'lessons': |
| 681 | - $text = __( 'Search Lessons', 'woothemes-sensei' ); |
|
| 681 | + $text = __('Search Lessons', 'woothemes-sensei'); |
|
| 682 | 682 | break; |
| 683 | 683 | |
| 684 | 684 | case 'users': |
| 685 | 685 | default: |
| 686 | - $text = __( 'Search Learners', 'woothemes-sensei' ); |
|
| 686 | + $text = __('Search Learners', 'woothemes-sensei'); |
|
| 687 | 687 | break; |
| 688 | 688 | } // End Switch Statement |
| 689 | 689 | |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Display output to the admin view |
| 44 | - * |
|
| 45 | - * This view is shown when grading a quiz for a single user in admin under grading |
|
| 46 | - * |
|
| 44 | + * |
|
| 45 | + * This view is shown when grading a quiz for a single user in admin under grading |
|
| 46 | + * |
|
| 47 | 47 | * @since 1.3.0 |
| 48 | 48 | * @return html |
| 49 | 49 | */ |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | $user_quiz_grade_total = 0; |
| 58 | 58 | $quiz_grade_total = 0; |
| 59 | 59 | $quiz_grade = 0; |
| 60 | - $lesson_id = $this->lesson_id; |
|
| 61 | - $user_id = $this->user_id; |
|
| 60 | + $lesson_id = $this->lesson_id; |
|
| 61 | + $user_id = $this->user_id; |
|
| 62 | 62 | |
| 63 | 63 | ?><form name="<?php esc_attr_e( 'quiz_' . $this->quiz_id ); ?>" action="" method="post"> |
| 64 | 64 | <?php wp_nonce_field( 'sensei_manual_grading', '_wp_sensei_manual_grading_nonce' ); ?> |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | <p class="user-answer"><?php |
| 207 | 207 | foreach ( $user_answer_content as $_user_answer ) { |
| 208 | 208 | |
| 209 | - if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){ |
|
| 209 | + if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){ |
|
| 210 | 210 | |
| 211 | - $_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) ); |
|
| 211 | + $_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) ); |
|
| 212 | 212 | |
| 213 | - } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | 215 | echo apply_filters( 'sensei_answer_text', $_user_answer ) . "<br>"; |
| 216 | 216 | } |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Grading User Quiz Class |
@@ -172,8 +175,7 @@ discard block |
||
| 172 | 175 | ++$correct_answers; |
| 173 | 176 | ++$graded_count; |
| 174 | 177 | $user_question_grade = 0; |
| 175 | - } |
|
| 176 | - elseif( intval( $user_question_grade ) > 0 ) { |
|
| 178 | + } elseif( intval( $user_question_grade ) > 0 ) { |
|
| 177 | 179 | $graded_class = 'user_right'; |
| 178 | 180 | ++$correct_answers; |
| 179 | 181 | $user_quiz_grade_total += $user_question_grade; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Grading User Quiz Class |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | * @since 1.3.0 |
| 23 | 23 | * @return void |
| 24 | 24 | */ |
| 25 | - public function __construct ( $user_id = 0, $quiz_id = 0 ) { |
|
| 26 | - $this->user_id = intval( $user_id ); |
|
| 27 | - $this->quiz_id = intval( $quiz_id ); |
|
| 28 | - $this->lesson_id = get_post_meta( $this->quiz_id, '_quiz_lesson', true ); |
|
| 25 | + public function __construct($user_id = 0, $quiz_id = 0) { |
|
| 26 | + $this->user_id = intval($user_id); |
|
| 27 | + $this->quiz_id = intval($quiz_id); |
|
| 28 | + $this->lesson_id = get_post_meta($this->quiz_id, '_quiz_lesson', true); |
|
| 29 | 29 | } // End __construct() |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @return array |
| 36 | 36 | */ |
| 37 | 37 | public function build_data_array() { |
| 38 | - $data_array = Sensei_Utils::sensei_get_quiz_questions( $this->quiz_id ); |
|
| 38 | + $data_array = Sensei_Utils::sensei_get_quiz_questions($this->quiz_id); |
|
| 39 | 39 | return $data_array; |
| 40 | 40 | } // End build_data_array() |
| 41 | 41 | |
@@ -60,94 +60,94 @@ discard block |
||
| 60 | 60 | $lesson_id = $this->lesson_id; |
| 61 | 61 | $user_id = $this->user_id; |
| 62 | 62 | |
| 63 | - ?><form name="<?php esc_attr_e( 'quiz_' . $this->quiz_id ); ?>" action="" method="post"> |
|
| 64 | - <?php wp_nonce_field( 'sensei_manual_grading', '_wp_sensei_manual_grading_nonce' ); ?> |
|
| 65 | - <input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e( $this->quiz_id ); ?>" /> |
|
| 66 | - <input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e( $this->user_id ); ?>" /> |
|
| 63 | + ?><form name="<?php esc_attr_e('quiz_'.$this->quiz_id); ?>" action="" method="post"> |
|
| 64 | + <?php wp_nonce_field('sensei_manual_grading', '_wp_sensei_manual_grading_nonce'); ?> |
|
| 65 | + <input type="hidden" name="sensei_manual_grade" value="<?php esc_attr_e($this->quiz_id); ?>" /> |
|
| 66 | + <input type="hidden" name="sensei_grade_next_learner" value="<?php esc_attr_e($this->user_id); ?>" /> |
|
| 67 | 67 | <div class="total_grade_display"> |
| 68 | - <span><?php esc_attr_e( __( 'Grade:', 'woothemes-sensei' ) ); ?></span> |
|
| 68 | + <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?></span> |
|
| 69 | 69 | <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?></span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?></span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?></span>%) |
| 70 | 70 | </div> |
| 71 | 71 | <div class="buttons"> |
| 72 | - <input type="submit" value="<?php esc_attr_e( __( 'Save', 'woothemes-sensei' ) ); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
| 73 | - <input type="button" value="<?php esc_attr_e( __( 'Auto grade', 'woothemes-sensei' ) ); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
| 74 | - <input type="reset" value="<?php esc_attr_e( __( 'Reset', 'woothemes-sensei' ) ); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
| 72 | + <input type="submit" value="<?php esc_attr_e(__('Save', 'woothemes-sensei')); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
| 73 | + <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
| 74 | + <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
| 75 | 75 | </div> |
| 76 | 76 | <div class="clear"></div><br/><?php |
| 77 | 77 | |
| 78 | - $lesson_status_id = Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID' ) ); |
|
| 79 | - $user_quiz_grade = get_comment_meta( $lesson_status_id, 'grade', true ); |
|
| 78 | + $lesson_status_id = Sensei_Utils::sensei_get_activity_value(array('post_id' => $this->lesson_id, 'user_id' => $this->user_id, 'type' => 'sensei_lesson_status', 'field' => 'comment_ID')); |
|
| 79 | + $user_quiz_grade = get_comment_meta($lesson_status_id, 'grade', true); |
|
| 80 | 80 | $correct_answers = 0; |
| 81 | 81 | |
| 82 | - foreach( $questions as $question ) { |
|
| 82 | + foreach ($questions as $question) { |
|
| 83 | 83 | $question_id = $question->ID; |
| 84 | 84 | ++$count; |
| 85 | 85 | |
| 86 | 86 | $type = false; |
| 87 | 87 | $type_name = ''; |
| 88 | 88 | |
| 89 | - $type = Sensei()->question->get_question_type( $question_id ); |
|
| 89 | + $type = Sensei()->question->get_question_type($question_id); |
|
| 90 | 90 | |
| 91 | - $question_answer_notes = Sensei()->quiz->get_user_question_feedback( $lesson_id, $question_id, $user_id ); |
|
| 91 | + $question_answer_notes = Sensei()->quiz->get_user_question_feedback($lesson_id, $question_id, $user_id); |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - $question_grade_total = Sensei()->question->get_question_grade( $question_id ); |
|
| 94 | + $question_grade_total = Sensei()->question->get_question_grade($question_id); |
|
| 95 | 95 | $quiz_grade_total += $question_grade_total; |
| 96 | 96 | |
| 97 | - $right_answer = get_post_meta( $question_id, '_question_right_answer', true ); |
|
| 98 | - $user_answer_content = Sensei()->quiz->get_user_question_answer( $lesson_id, $question_id, $user_id ); |
|
| 99 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 97 | + $right_answer = get_post_meta($question_id, '_question_right_answer', true); |
|
| 98 | + $user_answer_content = Sensei()->quiz->get_user_question_answer($lesson_id, $question_id, $user_id); |
|
| 99 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
| 100 | 100 | $grade_type = 'manual-grade'; |
| 101 | 101 | |
| 102 | - switch( $type ) { |
|
| 102 | + switch ($type) { |
|
| 103 | 103 | case 'boolean': |
| 104 | - $type_name = __( 'True/False', 'woothemes-sensei' ); |
|
| 105 | - $right_answer = ucfirst( $right_answer ); |
|
| 106 | - $user_answer_content = ucfirst( $user_answer_content ); |
|
| 104 | + $type_name = __('True/False', 'woothemes-sensei'); |
|
| 105 | + $right_answer = ucfirst($right_answer); |
|
| 106 | + $user_answer_content = ucfirst($user_answer_content); |
|
| 107 | 107 | $grade_type = 'auto-grade'; |
| 108 | 108 | break; |
| 109 | 109 | case 'multiple-choice': |
| 110 | - $type_name = __( 'Multiple Choice', 'woothemes-sensei' ); |
|
| 110 | + $type_name = __('Multiple Choice', 'woothemes-sensei'); |
|
| 111 | 111 | $grade_type = 'auto-grade'; |
| 112 | 112 | break; |
| 113 | 113 | case 'gap-fill': |
| 114 | - $type_name = __( 'Gap Fill', 'woothemes-sensei' ); |
|
| 114 | + $type_name = __('Gap Fill', 'woothemes-sensei'); |
|
| 115 | 115 | |
| 116 | - $right_answer_array = explode( '||', $right_answer ); |
|
| 117 | - if ( isset( $right_answer_array[0] ) ) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 118 | - if ( isset( $right_answer_array[1] ) ) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 119 | - if ( isset( $right_answer_array[2] ) ) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 116 | + $right_answer_array = explode('||', $right_answer); |
|
| 117 | + if (isset($right_answer_array[0])) { $gapfill_pre = $right_answer_array[0]; } else { $gapfill_pre = ''; } |
|
| 118 | + if (isset($right_answer_array[1])) { $gapfill_gap = $right_answer_array[1]; } else { $gapfill_gap = ''; } |
|
| 119 | + if (isset($right_answer_array[2])) { $gapfill_post = $right_answer_array[2]; } else { $gapfill_post = ''; } |
|
| 120 | 120 | |
| 121 | - if( ! $user_answer_content ) { |
|
| 121 | + if ( ! $user_answer_content) { |
|
| 122 | 122 | $user_answer_content = '______'; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $right_answer = $gapfill_pre . ' <span class="highlight">' . $gapfill_gap . '</span> ' . $gapfill_post; |
|
| 126 | - $user_answer_content = $gapfill_pre . ' <span class="highlight">' . $user_answer_content . '</span> ' . $gapfill_post; |
|
| 125 | + $right_answer = $gapfill_pre.' <span class="highlight">'.$gapfill_gap.'</span> '.$gapfill_post; |
|
| 126 | + $user_answer_content = $gapfill_pre.' <span class="highlight">'.$user_answer_content.'</span> '.$gapfill_post; |
|
| 127 | 127 | $grade_type = 'auto-grade'; |
| 128 | 128 | |
| 129 | 129 | break; |
| 130 | 130 | case 'multi-line': |
| 131 | - $type_name = __( 'Multi Line', 'woothemes-sensei' ); |
|
| 131 | + $type_name = __('Multi Line', 'woothemes-sensei'); |
|
| 132 | 132 | $grade_type = 'manual-grade'; |
| 133 | 133 | break; |
| 134 | 134 | case 'single-line': |
| 135 | - $type_name = __( 'Single Line', 'woothemes-sensei' ); |
|
| 135 | + $type_name = __('Single Line', 'woothemes-sensei'); |
|
| 136 | 136 | $grade_type = 'manual-grade'; |
| 137 | 137 | break; |
| 138 | 138 | case 'file-upload': |
| 139 | - $type_name = __( 'File Upload', 'woothemes-sensei' ); |
|
| 139 | + $type_name = __('File Upload', 'woothemes-sensei'); |
|
| 140 | 140 | $grade_type = 'manual-grade'; |
| 141 | 141 | |
| 142 | 142 | // Get uploaded file |
| 143 | - if( $user_answer_content ) { |
|
| 143 | + if ($user_answer_content) { |
|
| 144 | 144 | $attachment_id = $user_answer_content; |
| 145 | 145 | $answer_media_url = $answer_media_filename = ''; |
| 146 | - if( 0 < intval( $attachment_id ) ) { |
|
| 147 | - $answer_media_url = wp_get_attachment_url( $attachment_id ); |
|
| 148 | - $answer_media_filename = basename( $answer_media_url ); |
|
| 149 | - if( $answer_media_url && $answer_media_filename ) { |
|
| 150 | - $user_answer_content = sprintf( __( 'Submitted file: %1$s', 'woothemes-sensei' ), '<a href="' . esc_url( $answer_media_url ) . '" target="_blank">' . esc_html( $answer_media_filename ) . '</a>' ); |
|
| 146 | + if (0 < intval($attachment_id)) { |
|
| 147 | + $answer_media_url = wp_get_attachment_url($attachment_id); |
|
| 148 | + $answer_media_filename = basename($answer_media_url); |
|
| 149 | + if ($answer_media_url && $answer_media_filename) { |
|
| 150 | + $user_answer_content = sprintf(__('Submitted file: %1$s', 'woothemes-sensei'), '<a href="'.esc_url($answer_media_url).'" target="_blank">'.esc_html($answer_media_filename).'</a>'); |
|
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | } else { |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | $user_answer_content = (array) $user_answer_content; |
| 162 | 162 | $right_answer = (array) $right_answer; |
| 163 | - $question_title = sprintf( __( 'Question %d: ', 'woothemes-sensei' ), $count ) . $type_name; |
|
| 163 | + $question_title = sprintf(__('Question %d: ', 'woothemes-sensei'), $count).$type_name; |
|
| 164 | 164 | |
| 165 | 165 | $graded_class = ''; |
| 166 | - $user_question_grade = Sensei()->quiz->get_user_question_grade( $lesson_id, $question_id, $user_id ); |
|
| 166 | + $user_question_grade = Sensei()->quiz->get_user_question_grade($lesson_id, $question_id, $user_id); |
|
| 167 | 167 | $graded_class = 'ungraded'; |
| 168 | - if ( 0 == $question_grade_total && 0 == intval( $user_question_grade ) ) { |
|
| 168 | + if (0 == $question_grade_total && 0 == intval($user_question_grade)) { |
|
| 169 | 169 | // Question skips grading |
| 170 | 170 | $grade_type = 'zero-graded'; |
| 171 | 171 | $graded_class = ''; |
@@ -173,86 +173,86 @@ discard block |
||
| 173 | 173 | ++$graded_count; |
| 174 | 174 | $user_question_grade = 0; |
| 175 | 175 | } |
| 176 | - elseif( intval( $user_question_grade ) > 0 ) { |
|
| 176 | + elseif (intval($user_question_grade) > 0) { |
|
| 177 | 177 | $graded_class = 'user_right'; |
| 178 | 178 | ++$correct_answers; |
| 179 | 179 | $user_quiz_grade_total += $user_question_grade; |
| 180 | 180 | ++$graded_count; |
| 181 | 181 | } else { |
| 182 | - if( ! is_string( $user_question_grade ) && intval( $user_question_grade ) == 0 ) { |
|
| 182 | + if ( ! is_string($user_question_grade) && intval($user_question_grade) == 0) { |
|
| 183 | 183 | $graded_class = 'user_wrong'; |
| 184 | 184 | ++$graded_count; |
| 185 | 185 | } |
| 186 | 186 | $user_question_grade = 0; |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - ?><div class="postbox question_box <?php esc_attr_e( $type ); ?> <?php esc_attr_e( $grade_type ); ?> <?php esc_attr_e( $graded_class ); ?>" id="<?php esc_attr_e( 'question_' . $question_id . '_box' ); ?>"> |
|
| 189 | + ?><div class="postbox question_box <?php esc_attr_e($type); ?> <?php esc_attr_e($grade_type); ?> <?php esc_attr_e($graded_class); ?>" id="<?php esc_attr_e('question_'.$question_id.'_box'); ?>"> |
|
| 190 | 190 | <div class="handlediv" title="Click to toggle"><br></div> |
| 191 | 191 | <h3 class="hndle"><span><?php echo $question_title; ?></span></h3> |
| 192 | 192 | <div class="inside"> |
| 193 | 193 | <div class="sensei-grading-actions"> |
| 194 | 194 | <div class="actions"> |
| 195 | - <input type="hidden" class="question_id" value="<?php esc_attr_e( $question_id ); ?>" /> |
|
| 196 | - <input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo esc_attr( $question_grade_total ); ?>" /> |
|
| 197 | - <span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e( 'question_' . $question_id . '_right_option' ); ?>" name="<?php esc_attr_e( 'question_' . $question_id ); ?>" value="right" <?php checked( $graded_class, 'user_right', true ); ?> /></span> |
|
| 198 | - <span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e( 'question_' . $question_id . '_wrong_option' ); ?>" name="<?php esc_attr_e( 'question_' . $question_id ); ?>" value="wrong" <?php checked( $graded_class, 'user_wrong', true ); ?> /></span> |
|
| 199 | - <input type="number" class="question-grade" name="<?php esc_attr_e( 'question_' . $question_id . '_grade' ); ?>" id="<?php esc_attr_e( 'question_' . $question_id . '_grade' ); ?>" value="<?php echo esc_attr( $user_question_grade ); ?>" min="0" max="<?php echo esc_attr( $question_grade_total ); ?>" /> |
|
| 195 | + <input type="hidden" class="question_id" value="<?php esc_attr_e($question_id); ?>" /> |
|
| 196 | + <input type="hidden" class="question_total_grade" name="question_total_grade" value="<?php echo esc_attr($question_grade_total); ?>" /> |
|
| 197 | + <span class="grading-mark icon_right"><input type="radio" class="<?php esc_attr_e('question_'.$question_id.'_right_option'); ?>" name="<?php esc_attr_e('question_'.$question_id); ?>" value="right" <?php checked($graded_class, 'user_right', true); ?> /></span> |
|
| 198 | + <span class="grading-mark icon_wrong"><input type="radio" class="<?php esc_attr_e('question_'.$question_id.'_wrong_option'); ?>" name="<?php esc_attr_e('question_'.$question_id); ?>" value="wrong" <?php checked($graded_class, 'user_wrong', true); ?> /></span> |
|
| 199 | + <input type="number" class="question-grade" name="<?php esc_attr_e('question_'.$question_id.'_grade'); ?>" id="<?php esc_attr_e('question_'.$question_id.'_grade'); ?>" value="<?php echo esc_attr($user_question_grade); ?>" min="0" max="<?php echo esc_attr($question_grade_total); ?>" /> |
|
| 200 | 200 | <span class="question-grade-total"><?php echo $question_grade_total; ?></span> |
| 201 | 201 | </div> |
| 202 | 202 | </div> |
| 203 | 203 | <div class="sensei-grading-answer"> |
| 204 | - <h4><?php echo apply_filters( 'sensei_question_title', $question->post_title ); ?></h4> |
|
| 205 | - <?php echo apply_filters( 'the_content', $question->post_content );?> |
|
| 204 | + <h4><?php echo apply_filters('sensei_question_title', $question->post_title); ?></h4> |
|
| 205 | + <?php echo apply_filters('the_content', $question->post_content); ?> |
|
| 206 | 206 | <p class="user-answer"><?php |
| 207 | - foreach ( $user_answer_content as $_user_answer ) { |
|
| 207 | + foreach ($user_answer_content as $_user_answer) { |
|
| 208 | 208 | |
| 209 | - if( 'multi-line' == Sensei()->question->get_question_type( $question->ID ) ){ |
|
| 209 | + if ('multi-line' == Sensei()->question->get_question_type($question->ID)) { |
|
| 210 | 210 | |
| 211 | - $_user_answer = htmlspecialchars_decode( nl2br( esc_html($_user_answer) ) ); |
|
| 211 | + $_user_answer = htmlspecialchars_decode(nl2br(esc_html($_user_answer))); |
|
| 212 | 212 | |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - echo apply_filters( 'sensei_answer_text', $_user_answer ) . "<br>"; |
|
| 215 | + echo apply_filters('sensei_answer_text', $_user_answer)."<br>"; |
|
| 216 | 216 | } |
| 217 | 217 | ?></p> |
| 218 | 218 | <div class="right-answer"> |
| 219 | - <h5><?php _e( 'Correct answer', 'woothemes-sensei' ) ?></h5> |
|
| 219 | + <h5><?php _e('Correct answer', 'woothemes-sensei') ?></h5> |
|
| 220 | 220 | <span class="correct-answer"><?php |
| 221 | - foreach ( $right_answer as $_right_answer ) { |
|
| 221 | + foreach ($right_answer as $_right_answer) { |
|
| 222 | 222 | |
| 223 | - echo apply_filters( 'sensei_answer_text', $_right_answer ) . "<br>"; |
|
| 223 | + echo apply_filters('sensei_answer_text', $_right_answer)."<br>"; |
|
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | ?></span> |
| 227 | 227 | </div> |
| 228 | 228 | <div class="answer-notes"> |
| 229 | - <h5><?php _e( 'Grading Notes', 'woothemes-sensei' ) ?></h5> |
|
| 230 | - <textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e( $question_id ); ?>]" placeholder="<?php _e( 'Add notes here...', 'woothemes-sensei' ) ?>"><?php echo $question_answer_notes; ?></textarea> |
|
| 229 | + <h5><?php _e('Grading Notes', 'woothemes-sensei') ?></h5> |
|
| 230 | + <textarea class="correct-answer" name="questions_feedback[<?php esc_attr_e($question_id); ?>]" placeholder="<?php _e('Add notes here...', 'woothemes-sensei') ?>"><?php echo $question_answer_notes; ?></textarea> |
|
| 231 | 231 | </div> |
| 232 | 232 | </div> |
| 233 | 233 | </div> |
| 234 | 234 | </div><?php |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - $quiz_grade = intval( $user_quiz_grade ); |
|
| 237 | + $quiz_grade = intval($user_quiz_grade); |
|
| 238 | 238 | $all_graded = 'no'; |
| 239 | - if( intval( $count ) == intval( $graded_count ) ) { |
|
| 239 | + if (intval($count) == intval($graded_count)) { |
|
| 240 | 240 | $all_graded = 'yes'; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - ?> <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e( $user_quiz_grade_total ); ?>" /> |
|
| 244 | - <input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e( $count ); ?>" /> |
|
| 245 | - <input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e( $quiz_grade_total ); ?>" /> |
|
| 246 | - <input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e( $graded_count ); ?>" /> |
|
| 247 | - <input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e( $all_graded ); ?>" /> |
|
| 243 | + ?> <input type="hidden" name="total_grade" id="total_grade" value="<?php esc_attr_e($user_quiz_grade_total); ?>" /> |
|
| 244 | + <input type="hidden" name="total_questions" id="total_questions" value="<?php esc_attr_e($count); ?>" /> |
|
| 245 | + <input type="hidden" name="quiz_grade_total" id="quiz_grade_total" value="<?php esc_attr_e($quiz_grade_total); ?>" /> |
|
| 246 | + <input type="hidden" name="total_graded_questions" id="total_graded_questions" value="<?php esc_attr_e($graded_count); ?>" /> |
|
| 247 | + <input type="hidden" name="all_questions_graded" id="all_questions_graded" value="<?php esc_attr_e($all_graded); ?>" /> |
|
| 248 | 248 | <div class="total_grade_display"> |
| 249 | - <span><?php esc_attr_e( __( 'Grade:', 'woothemes-sensei' ) ); ?></span> |
|
| 249 | + <span><?php esc_attr_e(__('Grade:', 'woothemes-sensei')); ?></span> |
|
| 250 | 250 | <span class="total_grade_total"><?php echo $user_quiz_grade_total; ?></span> / <span class="quiz_grade_total"><?php echo $quiz_grade_total; ?></span> (<span class="total_grade_percent"><?php echo $quiz_grade; ?></span>%) |
| 251 | 251 | </div> |
| 252 | 252 | <div class="buttons"> |
| 253 | - <input type="submit" value="<?php esc_attr_e( 'Save' ); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
| 254 | - <input type="button" value="<?php esc_attr_e( __( 'Auto grade', 'woothemes-sensei' ) ); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
| 255 | - <input type="reset" value="<?php esc_attr_e( __( 'Reset', 'woothemes-sensei' ) ); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
| 253 | + <input type="submit" value="<?php esc_attr_e('Save'); ?>" class="grade-button button-primary" title="Saves grades as currently marked on this page" /> |
|
| 254 | + <input type="button" value="<?php esc_attr_e(__('Auto grade', 'woothemes-sensei')); ?>" class="autograde-button button-secondary" title="Where possible, automatically grades questions that have not yet been graded" /> |
|
| 255 | + <input type="reset" value="<?php esc_attr_e(__('Reset', 'woothemes-sensei')); ?>" class="reset-button button-secondary" title="Resets all questions to ungraded and total grade to 0" /> |
|
| 256 | 256 | </div> |
| 257 | 257 | <div class="clear"></div> |
| 258 | 258 | <script type="text/javascript"> |
@@ -271,4 +271,4 @@ discard block |
||
| 271 | 271 | * for backward compatibility |
| 272 | 272 | * @since 1.9.0 |
| 273 | 273 | */ |
| 274 | -class WooThemes_Sensei_Grading_User_Quiz extends Sensei_Grading_User_Quiz{} |
|
| 274 | +class WooThemes_Sensei_Grading_User_Quiz extends Sensei_Grading_User_Quiz {} |
|
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | $grade = __( 'N/A', 'woothemes-sensei' ); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $title = Sensei()->learners->get_learner_full_name( $item->user_id ); |
|
| 256 | + $title = Sensei()->learners->get_learner_full_name( $item->user_id ); |
|
| 257 | 257 | |
| 258 | 258 | // QuizID to be deprecated |
| 259 | 259 | $quiz_id = get_post_meta( $item->comment_post_ID, '_lesson_quiz', true ); |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function no_items() { |
| 305 | 305 | |
| 306 | - _e( 'No submissions found.', 'woothemes-sensei' ); |
|
| 306 | + _e( 'No submissions found.', 'woothemes-sensei' ); |
|
| 307 | 307 | |
| 308 | 308 | } // End no_items() |
| 309 | 309 | |
@@ -1,5 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | + exit; |
|
| 4 | +} |
|
| 5 | +// Exit if accessed directly |
|
| 3 | 6 | |
| 4 | 7 | /** |
| 5 | 8 | * Sensei Grading Overview List Table Class |
@@ -155,8 +158,7 @@ discard block |
||
| 155 | 158 | |
| 156 | 159 | if( $this->lesson_id ) { |
| 157 | 160 | $activity_args['post_id'] = $this->lesson_id; |
| 158 | - } |
|
| 159 | - elseif( $this->course_id ) { |
|
| 161 | + } elseif( $this->course_id ) { |
|
| 160 | 162 | // Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple |
| 161 | 163 | // post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 ) |
| 162 | 164 | if ( version_compare($wp_version, '4.1', '>=') ) { |
@@ -231,24 +233,19 @@ discard block |
||
| 231 | 233 | if( 'complete' == $item->comment_approved ) { |
| 232 | 234 | $status_html = '<span class="graded">' . __( 'Completed', 'woothemes-sensei' ) . '</span>'; |
| 233 | 235 | $grade = __( 'No Grade', 'woothemes-sensei' ); |
| 234 | - } |
|
| 235 | - elseif( 'graded' == $item->comment_approved ) { |
|
| 236 | + } elseif( 'graded' == $item->comment_approved ) { |
|
| 236 | 237 | $status_html = '<span class="graded">' . __( 'Graded', 'woothemes-sensei' ) . '</span>'; |
| 237 | 238 | $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
| 238 | - } |
|
| 239 | - elseif( 'passed' == $item->comment_approved ) { |
|
| 239 | + } elseif( 'passed' == $item->comment_approved ) { |
|
| 240 | 240 | $status_html = '<span class="passed">' . __( 'Passed', 'woothemes-sensei' ) . '</span>'; |
| 241 | 241 | $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
| 242 | - } |
|
| 243 | - elseif( 'failed' == $item->comment_approved ) { |
|
| 242 | + } elseif( 'failed' == $item->comment_approved ) { |
|
| 244 | 243 | $status_html = '<span class="failed">' . __( 'Failed', 'woothemes-sensei' ) . '</span>'; |
| 245 | 244 | $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
| 246 | - } |
|
| 247 | - elseif( 'ungraded' == $item->comment_approved ) { |
|
| 245 | + } elseif( 'ungraded' == $item->comment_approved ) { |
|
| 248 | 246 | $status_html = '<span class="ungraded">' . __( 'Ungraded', 'woothemes-sensei' ) . '</span>'; |
| 249 | 247 | $grade = __( 'N/A', 'woothemes-sensei' ); |
| 250 | - } |
|
| 251 | - else { |
|
| 248 | + } else { |
|
| 252 | 249 | $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
| 253 | 250 | $grade = __( 'N/A', 'woothemes-sensei' ); |
| 254 | 251 | } |
@@ -276,8 +273,7 @@ discard block |
||
| 276 | 273 | $course_title = ''; |
| 277 | 274 | if ( !empty($course_id) && version_compare($wp_version, '4.1', '>=') ) { |
| 278 | 275 | $course_title = '<a href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ) ) . '">' . get_the_title( $course_id ) . '</a>'; |
| 279 | - } |
|
| 280 | - else if ( !empty($course_id) ) { |
|
| 276 | + } else if ( !empty($course_id) ) { |
|
| 281 | 277 | $course_title = get_the_title( $course_id ); |
| 282 | 278 | } |
| 283 | 279 | $lesson_title = '<a href="' . add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ) . '">' . get_the_title( $item->comment_post_ID ) . '</a>'; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Grading Overview List Table Class |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @since 1.3.0 |
| 26 | 26 | * @return void |
| 27 | 27 | */ |
| 28 | - public function __construct ( $args = null ) { |
|
| 28 | + public function __construct($args = null) { |
|
| 29 | 29 | |
| 30 | 30 | $defaults = array( |
| 31 | 31 | 'course_id' => 0, |
@@ -33,24 +33,24 @@ discard block |
||
| 33 | 33 | 'user_id' => false, |
| 34 | 34 | 'view' => 'ungraded', |
| 35 | 35 | ); |
| 36 | - $args = wp_parse_args( $args, $defaults ); |
|
| 36 | + $args = wp_parse_args($args, $defaults); |
|
| 37 | 37 | |
| 38 | - $this->course_id = intval( $args['course_id'] ); |
|
| 39 | - $this->lesson_id = intval( $args['lesson_id'] ); |
|
| 40 | - if ( !empty($args['user_id']) ) { |
|
| 41 | - $this->user_id = intval( $args['user_id'] ); |
|
| 38 | + $this->course_id = intval($args['course_id']); |
|
| 39 | + $this->lesson_id = intval($args['lesson_id']); |
|
| 40 | + if ( ! empty($args['user_id'])) { |
|
| 41 | + $this->user_id = intval($args['user_id']); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - if( !empty( $args['view'] ) && in_array( $args['view'], array( 'in-progress', 'graded', 'ungraded', 'all' ) ) ) { |
|
| 44 | + if ( ! empty($args['view']) && in_array($args['view'], array('in-progress', 'graded', 'ungraded', 'all'))) { |
|
| 45 | 45 | $this->view = $args['view']; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | // Load Parent token into constructor |
| 49 | - parent::__construct( 'grading_main' ); |
|
| 49 | + parent::__construct('grading_main'); |
|
| 50 | 50 | |
| 51 | 51 | // Actions |
| 52 | - add_action( 'sensei_before_list_table', array( $this, 'data_table_header' ) ); |
|
| 53 | - add_action( 'sensei_after_list_table', array( $this, 'data_table_footer' ) ); |
|
| 52 | + add_action('sensei_before_list_table', array($this, 'data_table_header')); |
|
| 53 | + add_action('sensei_after_list_table', array($this, 'data_table_footer')); |
|
| 54 | 54 | } // End __construct() |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -60,16 +60,16 @@ discard block |
||
| 60 | 60 | */ |
| 61 | 61 | function get_columns() { |
| 62 | 62 | $columns = array( |
| 63 | - 'title' => __( 'Learner', 'woothemes-sensei' ), |
|
| 64 | - 'course' => __( 'Course', 'woothemes-sensei' ), |
|
| 65 | - 'lesson' => __( 'Lesson', 'woothemes-sensei' ), |
|
| 66 | - 'updated' => __( 'Updated', 'woothemes-sensei' ), |
|
| 67 | - 'user_status' => __( 'Status', 'woothemes-sensei' ), |
|
| 68 | - 'user_grade' => __( 'Grade', 'woothemes-sensei' ), |
|
| 63 | + 'title' => __('Learner', 'woothemes-sensei'), |
|
| 64 | + 'course' => __('Course', 'woothemes-sensei'), |
|
| 65 | + 'lesson' => __('Lesson', 'woothemes-sensei'), |
|
| 66 | + 'updated' => __('Updated', 'woothemes-sensei'), |
|
| 67 | + 'user_status' => __('Status', 'woothemes-sensei'), |
|
| 68 | + 'user_grade' => __('Grade', 'woothemes-sensei'), |
|
| 69 | 69 | 'action' => '', |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | - $columns = apply_filters( 'sensei_grading_default_columns', $columns, $this ); |
|
| 72 | + $columns = apply_filters('sensei_grading_default_columns', $columns, $this); |
|
| 73 | 73 | return $columns; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -80,14 +80,14 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function get_sortable_columns() { |
| 82 | 82 | $columns = array( |
| 83 | - 'title' => array( 'title', false ), |
|
| 84 | - 'course' => array( 'course', false ), |
|
| 85 | - 'lesson' => array( 'lesson', false ), |
|
| 86 | - 'updated' => array( 'updated', false ), |
|
| 87 | - 'user_status' => array( 'user_status', false ), |
|
| 88 | - 'user_grade' => array( 'user_grade', false ), |
|
| 83 | + 'title' => array('title', false), |
|
| 84 | + 'course' => array('course', false), |
|
| 85 | + 'lesson' => array('lesson', false), |
|
| 86 | + 'updated' => array('updated', false), |
|
| 87 | + 'user_status' => array('user_status', false), |
|
| 88 | + 'user_grade' => array('user_grade', false), |
|
| 89 | 89 | ); |
| 90 | - $columns = apply_filters( 'sensei_grading_default_columns_sortable', $columns, $this ); |
|
| 90 | + $columns = apply_filters('sensei_grading_default_columns_sortable', $columns, $this); |
|
| 91 | 91 | return $columns; |
| 92 | 92 | } |
| 93 | 93 | |
@@ -101,47 +101,47 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | // Handle orderby |
| 103 | 103 | $orderby = ''; |
| 104 | - if ( !empty( $_GET['orderby'] ) ) { |
|
| 105 | - if ( array_key_exists( esc_html( $_GET['orderby'] ), $this->get_sortable_columns() ) ) { |
|
| 106 | - $orderby = esc_html( $_GET['orderby'] ); |
|
| 104 | + if ( ! empty($_GET['orderby'])) { |
|
| 105 | + if (array_key_exists(esc_html($_GET['orderby']), $this->get_sortable_columns())) { |
|
| 106 | + $orderby = esc_html($_GET['orderby']); |
|
| 107 | 107 | } // End If Statement |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Handle order |
| 111 | 111 | $order = 'DESC'; |
| 112 | - if ( !empty( $_GET['order'] ) ) { |
|
| 113 | - $order = ( 'ASC' == strtoupper($_GET['order']) ) ? 'ASC' : 'DESC'; |
|
| 112 | + if ( ! empty($_GET['order'])) { |
|
| 113 | + $order = ('ASC' == strtoupper($_GET['order'])) ? 'ASC' : 'DESC'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | // Handle search |
| 117 | 117 | $search = false; |
| 118 | - if ( !empty( $_GET['s'] ) ) { |
|
| 119 | - $search = esc_html( $_GET['s'] ); |
|
| 118 | + if ( ! empty($_GET['s'])) { |
|
| 119 | + $search = esc_html($_GET['s']); |
|
| 120 | 120 | } // End If Statement |
| 121 | 121 | $this->search = $search; |
| 122 | 122 | |
| 123 | 123 | // Searching users on statuses requires sub-selecting the statuses by user_ids |
| 124 | - if ( $this->search ) { |
|
| 124 | + if ($this->search) { |
|
| 125 | 125 | $user_args = array( |
| 126 | - 'search' => '*' . $this->search . '*', |
|
| 126 | + 'search' => '*'.$this->search.'*', |
|
| 127 | 127 | 'fields' => 'ID', |
| 128 | 128 | ); |
| 129 | 129 | // Filter for extending |
| 130 | - $user_args = apply_filters( 'sensei_grading_search_users', $user_args ); |
|
| 131 | - if ( !empty( $user_args ) ) { |
|
| 132 | - $learners_search = new WP_User_Query( $user_args ); |
|
| 130 | + $user_args = apply_filters('sensei_grading_search_users', $user_args); |
|
| 131 | + if ( ! empty($user_args)) { |
|
| 132 | + $learners_search = new WP_User_Query($user_args); |
|
| 133 | 133 | // Store for reuse on counts |
| 134 | 134 | $this->user_ids = $learners_search->get_results(); |
| 135 | 135 | } |
| 136 | 136 | } // End If Statement |
| 137 | 137 | |
| 138 | - $per_page = $this->get_items_per_page( 'sensei_comments_per_page' ); |
|
| 139 | - $per_page = apply_filters( 'sensei_comments_per_page', $per_page, 'sensei_comments' ); |
|
| 138 | + $per_page = $this->get_items_per_page('sensei_comments_per_page'); |
|
| 139 | + $per_page = apply_filters('sensei_comments_per_page', $per_page, 'sensei_comments'); |
|
| 140 | 140 | |
| 141 | 141 | $paged = $this->get_pagenum(); |
| 142 | 142 | $offset = 0; |
| 143 | - if ( !empty($paged) ) { |
|
| 144 | - $offset = $per_page * ( $paged - 1 ); |
|
| 143 | + if ( ! empty($paged)) { |
|
| 144 | + $offset = $per_page * ($paged - 1); |
|
| 145 | 145 | } // End If Statement |
| 146 | 146 | |
| 147 | 147 | $activity_args = array( |
@@ -153,27 +153,27 @@ discard block |
||
| 153 | 153 | 'status' => 'any', |
| 154 | 154 | ); |
| 155 | 155 | |
| 156 | - if( $this->lesson_id ) { |
|
| 156 | + if ($this->lesson_id) { |
|
| 157 | 157 | $activity_args['post_id'] = $this->lesson_id; |
| 158 | 158 | } |
| 159 | - elseif( $this->course_id ) { |
|
| 159 | + elseif ($this->course_id) { |
|
| 160 | 160 | // Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple |
| 161 | 161 | // post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 ) |
| 162 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 163 | - $activity_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' ); |
|
| 162 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 163 | + $activity_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids'); |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | // Sub select to group of learners |
| 167 | - if ( $this->user_ids ) { |
|
| 167 | + if ($this->user_ids) { |
|
| 168 | 168 | $activity_args['user_id'] = (array) $this->user_ids; |
| 169 | 169 | } |
| 170 | 170 | // Restrict to a single Learner |
| 171 | - if( $this->user_id ) { |
|
| 171 | + if ($this->user_id) { |
|
| 172 | 172 | $activity_args['user_id'] = $this->user_id; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
| 176 | - switch( $this->view ) { |
|
| 176 | + switch ($this->view) { |
|
| 177 | 177 | case 'in-progress' : |
| 178 | 178 | $activity_args['status'] = 'in-progress'; |
| 179 | 179 | break; |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | break; |
| 184 | 184 | |
| 185 | 185 | case 'graded' : |
| 186 | - $activity_args['status'] = array( 'graded', 'passed', 'failed' ); |
|
| 186 | + $activity_args['status'] = array('graded', 'passed', 'failed'); |
|
| 187 | 187 | break; |
| 188 | 188 | |
| 189 | 189 | case 'all' : |
@@ -192,31 +192,31 @@ discard block |
||
| 192 | 192 | break; |
| 193 | 193 | } // End switch |
| 194 | 194 | |
| 195 | - $activity_args = apply_filters( 'sensei_grading_filter_statuses', $activity_args ); |
|
| 195 | + $activity_args = apply_filters('sensei_grading_filter_statuses', $activity_args); |
|
| 196 | 196 | |
| 197 | 197 | // WP_Comment_Query doesn't support SQL_CALC_FOUND_ROWS, so instead do this twice |
| 198 | - $total_statuses = Sensei_Utils::sensei_check_for_activity( array_merge( $activity_args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
|
| 198 | + $total_statuses = Sensei_Utils::sensei_check_for_activity(array_merge($activity_args, array('count' => true, 'offset' => 0, 'number' => 0))); |
|
| 199 | 199 | |
| 200 | 200 | // Ensure we change our range to fit (in case a search threw off the pagination) - Should this be added to all views? |
| 201 | - if ( $total_statuses < $activity_args['offset'] ) { |
|
| 202 | - $new_paged = floor( $total_statuses / $activity_args['number'] ); |
|
| 201 | + if ($total_statuses < $activity_args['offset']) { |
|
| 202 | + $new_paged = floor($total_statuses / $activity_args['number']); |
|
| 203 | 203 | $activity_args['offset'] = $new_paged * $activity_args['number']; |
| 204 | 204 | } |
| 205 | - $statuses = Sensei_Utils::sensei_check_for_activity( $activity_args, true ); |
|
| 205 | + $statuses = Sensei_Utils::sensei_check_for_activity($activity_args, true); |
|
| 206 | 206 | // Need to always return an array, even with only 1 item |
| 207 | - if ( !is_array($statuses) ) { |
|
| 208 | - $statuses = array( $statuses ); |
|
| 207 | + if ( ! is_array($statuses)) { |
|
| 208 | + $statuses = array($statuses); |
|
| 209 | 209 | } |
| 210 | 210 | $this->total_items = $total_statuses; |
| 211 | 211 | $this->items = $statuses; |
| 212 | 212 | |
| 213 | 213 | $total_items = $this->total_items; |
| 214 | - $total_pages = ceil( $total_items / $per_page ); |
|
| 215 | - $this->set_pagination_args( array( |
|
| 214 | + $total_pages = ceil($total_items / $per_page); |
|
| 215 | + $this->set_pagination_args(array( |
|
| 216 | 216 | 'total_items' => $total_items, |
| 217 | 217 | 'total_pages' => $total_pages, |
| 218 | 218 | 'per_page' => $per_page |
| 219 | - ) ); |
|
| 219 | + )); |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -224,73 +224,73 @@ discard block |
||
| 224 | 224 | * @since 1.7.0 |
| 225 | 225 | * @param object $item The current item |
| 226 | 226 | */ |
| 227 | - protected function get_row_data( $item ) { |
|
| 227 | + protected function get_row_data($item) { |
|
| 228 | 228 | global $wp_version; |
| 229 | 229 | |
| 230 | 230 | $grade = ''; |
| 231 | - if( 'complete' == $item->comment_approved ) { |
|
| 232 | - $status_html = '<span class="graded">' . __( 'Completed', 'woothemes-sensei' ) . '</span>'; |
|
| 233 | - $grade = __( 'No Grade', 'woothemes-sensei' ); |
|
| 231 | + if ('complete' == $item->comment_approved) { |
|
| 232 | + $status_html = '<span class="graded">'.__('Completed', 'woothemes-sensei').'</span>'; |
|
| 233 | + $grade = __('No Grade', 'woothemes-sensei'); |
|
| 234 | 234 | } |
| 235 | - elseif( 'graded' == $item->comment_approved ) { |
|
| 236 | - $status_html = '<span class="graded">' . __( 'Graded', 'woothemes-sensei' ) . '</span>'; |
|
| 237 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
|
| 235 | + elseif ('graded' == $item->comment_approved) { |
|
| 236 | + $status_html = '<span class="graded">'.__('Graded', 'woothemes-sensei').'</span>'; |
|
| 237 | + $grade = get_comment_meta($item->comment_ID, 'grade', true).'%'; |
|
| 238 | 238 | } |
| 239 | - elseif( 'passed' == $item->comment_approved ) { |
|
| 240 | - $status_html = '<span class="passed">' . __( 'Passed', 'woothemes-sensei' ) . '</span>'; |
|
| 241 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
|
| 239 | + elseif ('passed' == $item->comment_approved) { |
|
| 240 | + $status_html = '<span class="passed">'.__('Passed', 'woothemes-sensei').'</span>'; |
|
| 241 | + $grade = get_comment_meta($item->comment_ID, 'grade', true).'%'; |
|
| 242 | 242 | } |
| 243 | - elseif( 'failed' == $item->comment_approved ) { |
|
| 244 | - $status_html = '<span class="failed">' . __( 'Failed', 'woothemes-sensei' ) . '</span>'; |
|
| 245 | - $grade = get_comment_meta( $item->comment_ID, 'grade', true) . '%'; |
|
| 243 | + elseif ('failed' == $item->comment_approved) { |
|
| 244 | + $status_html = '<span class="failed">'.__('Failed', 'woothemes-sensei').'</span>'; |
|
| 245 | + $grade = get_comment_meta($item->comment_ID, 'grade', true).'%'; |
|
| 246 | 246 | } |
| 247 | - elseif( 'ungraded' == $item->comment_approved ) { |
|
| 248 | - $status_html = '<span class="ungraded">' . __( 'Ungraded', 'woothemes-sensei' ) . '</span>'; |
|
| 249 | - $grade = __( 'N/A', 'woothemes-sensei' ); |
|
| 247 | + elseif ('ungraded' == $item->comment_approved) { |
|
| 248 | + $status_html = '<span class="ungraded">'.__('Ungraded', 'woothemes-sensei').'</span>'; |
|
| 249 | + $grade = __('N/A', 'woothemes-sensei'); |
|
| 250 | 250 | } |
| 251 | 251 | else { |
| 252 | - $status_html = '<span class="in-progress">' . __( 'In Progress', 'woothemes-sensei' ) . '</span>'; |
|
| 253 | - $grade = __( 'N/A', 'woothemes-sensei' ); |
|
| 252 | + $status_html = '<span class="in-progress">'.__('In Progress', 'woothemes-sensei').'</span>'; |
|
| 253 | + $grade = __('N/A', 'woothemes-sensei'); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $title = Sensei()->learners->get_learner_full_name( $item->user_id ); |
|
| 256 | + $title = Sensei()->learners->get_learner_full_name($item->user_id); |
|
| 257 | 257 | |
| 258 | 258 | // QuizID to be deprecated |
| 259 | - $quiz_id = get_post_meta( $item->comment_post_ID, '_lesson_quiz', true ); |
|
| 260 | - $quiz_link = esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id ), admin_url( 'admin.php' ) ) ); |
|
| 259 | + $quiz_id = get_post_meta($item->comment_post_ID, '_lesson_quiz', true); |
|
| 260 | + $quiz_link = esc_url(add_query_arg(array('page' => $this->page_slug, 'user' => $item->user_id, 'quiz_id' => $quiz_id), admin_url('admin.php'))); |
|
| 261 | 261 | |
| 262 | 262 | $grade_link = ''; |
| 263 | - switch( $item->comment_approved ) { |
|
| 263 | + switch ($item->comment_approved) { |
|
| 264 | 264 | case 'ungraded': |
| 265 | - $grade_link = '<a class="button-primary button" href="' . $quiz_link . '">' . __('Grade quiz', 'woothemes-sensei' ) . '</a>'; |
|
| 265 | + $grade_link = '<a class="button-primary button" href="'.$quiz_link.'">'.__('Grade quiz', 'woothemes-sensei').'</a>'; |
|
| 266 | 266 | break; |
| 267 | 267 | |
| 268 | 268 | case 'graded': |
| 269 | 269 | case 'passed': |
| 270 | 270 | case 'failed': |
| 271 | - $grade_link = '<a class="button-secondary button" href="' . $quiz_link . '">' . __('Review grade', 'woothemes-sensei' ) . '</a>'; |
|
| 271 | + $grade_link = '<a class="button-secondary button" href="'.$quiz_link.'">'.__('Review grade', 'woothemes-sensei').'</a>'; |
|
| 272 | 272 | break; |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - $course_id = get_post_meta( $item->comment_post_ID, '_lesson_course', true ); |
|
| 275 | + $course_id = get_post_meta($item->comment_post_ID, '_lesson_course', true); |
|
| 276 | 276 | $course_title = ''; |
| 277 | - if ( !empty($course_id) && version_compare($wp_version, '4.1', '>=') ) { |
|
| 278 | - $course_title = '<a href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'course_id' => $course_id ), admin_url( 'admin.php' ) ) ) . '">' . get_the_title( $course_id ) . '</a>'; |
|
| 277 | + if ( ! empty($course_id) && version_compare($wp_version, '4.1', '>=')) { |
|
| 278 | + $course_title = '<a href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'course_id' => $course_id), admin_url('admin.php'))).'">'.get_the_title($course_id).'</a>'; |
|
| 279 | 279 | } |
| 280 | - else if ( !empty($course_id) ) { |
|
| 281 | - $course_title = get_the_title( $course_id ); |
|
| 280 | + else if ( ! empty($course_id)) { |
|
| 281 | + $course_title = get_the_title($course_id); |
|
| 282 | 282 | } |
| 283 | - $lesson_title = '<a href="' . add_query_arg( array( 'page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID ), admin_url( 'admin.php' ) ) . '">' . get_the_title( $item->comment_post_ID ) . '</a>'; |
|
| 283 | + $lesson_title = '<a href="'.add_query_arg(array('page' => $this->page_slug, 'lesson_id' => $item->comment_post_ID), admin_url('admin.php')).'">'.get_the_title($item->comment_post_ID).'</a>'; |
|
| 284 | 284 | |
| 285 | - $column_data = apply_filters( 'sensei_grading_main_column_data', array( |
|
| 286 | - 'title' => '<strong><a class="row-title" href="' . esc_url( add_query_arg( array( 'page' => $this->page_slug, 'user_id' => $item->user_id ), admin_url( 'admin.php' ) ) ) . '"">' . $title . '</a></strong>', |
|
| 285 | + $column_data = apply_filters('sensei_grading_main_column_data', array( |
|
| 286 | + 'title' => '<strong><a class="row-title" href="'.esc_url(add_query_arg(array('page' => $this->page_slug, 'user_id' => $item->user_id), admin_url('admin.php'))).'"">'.$title.'</a></strong>', |
|
| 287 | 287 | 'course' => $course_title, |
| 288 | 288 | 'lesson' => $lesson_title, |
| 289 | 289 | 'updated' => $item->comment_date, |
| 290 | 290 | 'user_status' => $status_html, |
| 291 | 291 | 'user_grade' => $grade, |
| 292 | 292 | 'action' => $grade_link, |
| 293 | - ), $item, $course_id ); |
|
| 293 | + ), $item, $course_id); |
|
| 294 | 294 | |
| 295 | 295 | return $column_data; |
| 296 | 296 | } |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | */ |
| 304 | 304 | public function no_items() { |
| 305 | 305 | |
| 306 | - _e( 'No submissions found.', 'woothemes-sensei' ); |
|
| 306 | + _e('No submissions found.', 'woothemes-sensei'); |
|
| 307 | 307 | |
| 308 | 308 | } // End no_items() |
| 309 | 309 | |
@@ -316,35 +316,35 @@ discard block |
||
| 316 | 316 | global $wp_version; |
| 317 | 317 | |
| 318 | 318 | echo '<div class="grading-selects">'; |
| 319 | - do_action( 'sensei_grading_before_dropdown_filters' ); |
|
| 319 | + do_action('sensei_grading_before_dropdown_filters'); |
|
| 320 | 320 | |
| 321 | - echo '<div class="select-box">' . "\n"; |
|
| 321 | + echo '<div class="select-box">'."\n"; |
|
| 322 | 322 | |
| 323 | - echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">' . "\n"; |
|
| 323 | + echo '<select id="grading-course-options" name="grading_course" class="chosen_select widefat">'."\n"; |
|
| 324 | 324 | |
| 325 | - echo Sensei()->grading->courses_drop_down_html( $this->course_id ); |
|
| 325 | + echo Sensei()->grading->courses_drop_down_html($this->course_id); |
|
| 326 | 326 | |
| 327 | - echo '</select>' . "\n"; |
|
| 327 | + echo '</select>'."\n"; |
|
| 328 | 328 | |
| 329 | - echo '</div>' . "\n"; |
|
| 329 | + echo '</div>'."\n"; |
|
| 330 | 330 | |
| 331 | - echo '<div class="select-box">' . "\n"; |
|
| 331 | + echo '<div class="select-box">'."\n"; |
|
| 332 | 332 | |
| 333 | - echo '<select id="grading-lesson-options" data-placeholder="← ' . __( 'Select a course', 'woothemes-sensei' ) . '" name="grading_lesson" class="chosen_select widefat">' . "\n"; |
|
| 333 | + echo '<select id="grading-lesson-options" data-placeholder="← '.__('Select a course', 'woothemes-sensei').'" name="grading_lesson" class="chosen_select widefat">'."\n"; |
|
| 334 | 334 | |
| 335 | - echo Sensei()->grading->lessons_drop_down_html( $this->course_id, $this->lesson_id ); |
|
| 335 | + echo Sensei()->grading->lessons_drop_down_html($this->course_id, $this->lesson_id); |
|
| 336 | 336 | |
| 337 | - echo '</select>' . "\n"; |
|
| 337 | + echo '</select>'."\n"; |
|
| 338 | 338 | |
| 339 | - echo '</div>' . "\n"; |
|
| 339 | + echo '</div>'."\n"; |
|
| 340 | 340 | |
| 341 | - if( $this->course_id && $this->lesson_id ) { |
|
| 341 | + if ($this->course_id && $this->lesson_id) { |
|
| 342 | 342 | |
| 343 | - echo '<div class="select-box reset-filter">' . "\n"; |
|
| 343 | + echo '<div class="select-box reset-filter">'."\n"; |
|
| 344 | 344 | |
| 345 | - echo '<a class="button-secondary" href="' . esc_url( remove_query_arg( array( 'lesson_id', 'course_id' ) ) ) . '">' . __( 'Reset filter', 'woothemes-sensei' ) . '</a>' . "\n"; |
|
| 345 | + echo '<a class="button-secondary" href="'.esc_url(remove_query_arg(array('lesson_id', 'course_id'))).'">'.__('Reset filter', 'woothemes-sensei').'</a>'."\n"; |
|
| 346 | 346 | |
| 347 | - echo '</div>' . "\n"; |
|
| 347 | + echo '</div>'."\n"; |
|
| 348 | 348 | |
| 349 | 349 | } |
| 350 | 350 | |
@@ -359,26 +359,26 @@ discard block |
||
| 359 | 359 | $query_args = array( |
| 360 | 360 | 'page' => $this->page_slug, |
| 361 | 361 | ); |
| 362 | - if( $this->course_id ) { |
|
| 362 | + if ($this->course_id) { |
|
| 363 | 363 | // Currently not possible to restrict to a single Course, as that requires WP_Comment to support multiple |
| 364 | 364 | // post_ids (i.e. every lesson within the Course), WP 4.1 ( https://core.trac.wordpress.org/changeset/29808 ) |
| 365 | 365 | $query_args['course_id'] = $this->course_id; |
| 366 | - if ( version_compare($wp_version, '4.1', '>=') ) { |
|
| 367 | - $count_args['post__in'] = Sensei()->course->course_lessons( $this->course_id, 'any', 'ids' ); |
|
| 366 | + if (version_compare($wp_version, '4.1', '>=')) { |
|
| 367 | + $count_args['post__in'] = Sensei()->course->course_lessons($this->course_id, 'any', 'ids'); |
|
| 368 | 368 | } |
| 369 | 369 | } |
| 370 | - if( $this->lesson_id ) { |
|
| 370 | + if ($this->lesson_id) { |
|
| 371 | 371 | $query_args['lesson_id'] = $this->lesson_id; |
| 372 | 372 | // Restrict to a single lesson |
| 373 | 373 | $count_args['post_id'] = $this->lesson_id; |
| 374 | 374 | } |
| 375 | - if( $this->search ) { |
|
| 375 | + if ($this->search) { |
|
| 376 | 376 | $query_args['s'] = $this->search; |
| 377 | 377 | } |
| 378 | - if ( !empty($this->user_ids) ) { |
|
| 378 | + if ( ! empty($this->user_ids)) { |
|
| 379 | 379 | $count_args['user_id'] = $this->user_ids; |
| 380 | 380 | } |
| 381 | - if( !empty($this->user_id) ) { |
|
| 381 | + if ( ! empty($this->user_id)) { |
|
| 382 | 382 | $query_args['user_id'] = $this->user_id; |
| 383 | 383 | $count_args['user_id'] = $this->user_id; |
| 384 | 384 | } |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | $all_lessons_count = $ungraded_lessons_count = $graded_lessons_count = $inprogress_lessons_count = 0; |
| 387 | 387 | $all_class = $ungraded_class = $graded_class = $inprogress_class = ''; |
| 388 | 388 | |
| 389 | - switch( $this->view ) : |
|
| 389 | + switch ($this->view) : |
|
| 390 | 390 | case 'all': |
| 391 | 391 | $all_class = 'current'; |
| 392 | 392 | break; |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | break; |
| 403 | 403 | endswitch; |
| 404 | 404 | |
| 405 | - $counts = Sensei()->grading->count_statuses( apply_filters( 'sensei_grading_count_statues', $count_args ) ); |
|
| 405 | + $counts = Sensei()->grading->count_statuses(apply_filters('sensei_grading_count_statues', $count_args)); |
|
| 406 | 406 | |
| 407 | 407 | $inprogress_lessons_count = $counts['in-progress']; |
| 408 | 408 | $ungraded_lessons_count = $counts['ungraded']; |
@@ -418,19 +418,19 @@ discard block |
||
| 418 | 418 | $inprogress_args['view'] = 'in-progress'; |
| 419 | 419 | |
| 420 | 420 | $format = '<a class="%s" href="%s">%s <span class="count">(%s)</span></a>'; |
| 421 | - $menu['all'] = sprintf( $format, $all_class, esc_url( add_query_arg( $all_args, admin_url( 'admin.php' ) ) ), __( 'All', 'woothemes-sensei' ), number_format( (int) $all_lessons_count ) ); |
|
| 422 | - $menu['ungraded'] = sprintf( $format, $ungraded_class, esc_url( add_query_arg( $ungraded_args, admin_url( 'admin.php' ) ) ), __( 'Ungraded', 'woothemes-sensei' ), number_format( (int) $ungraded_lessons_count ) ); |
|
| 423 | - $menu['graded'] = sprintf( $format, $graded_class, esc_url( add_query_arg( $graded_args, admin_url( 'admin.php' ) ) ), __( 'Graded', 'woothemes-sensei' ), number_format( (int) $graded_lessons_count ) ); |
|
| 424 | - $menu['in-progress'] = sprintf( $format, $inprogress_class, esc_url( add_query_arg( $inprogress_args, admin_url( 'admin.php' ) ) ), __( 'In Progress', 'woothemes-sensei' ), number_format( (int) $inprogress_lessons_count ) ); |
|
| 425 | - |
|
| 426 | - $menu = apply_filters( 'sensei_grading_sub_menu', $menu ); |
|
| 427 | - if ( !empty($menu) ) { |
|
| 428 | - echo '<ul class="subsubsub">' . "\n"; |
|
| 429 | - foreach ( $menu as $class => $item ) { |
|
| 430 | - $menu[ $class ] = "\t<li class='$class'>$item"; |
|
| 421 | + $menu['all'] = sprintf($format, $all_class, esc_url(add_query_arg($all_args, admin_url('admin.php'))), __('All', 'woothemes-sensei'), number_format((int) $all_lessons_count)); |
|
| 422 | + $menu['ungraded'] = sprintf($format, $ungraded_class, esc_url(add_query_arg($ungraded_args, admin_url('admin.php'))), __('Ungraded', 'woothemes-sensei'), number_format((int) $ungraded_lessons_count)); |
|
| 423 | + $menu['graded'] = sprintf($format, $graded_class, esc_url(add_query_arg($graded_args, admin_url('admin.php'))), __('Graded', 'woothemes-sensei'), number_format((int) $graded_lessons_count)); |
|
| 424 | + $menu['in-progress'] = sprintf($format, $inprogress_class, esc_url(add_query_arg($inprogress_args, admin_url('admin.php'))), __('In Progress', 'woothemes-sensei'), number_format((int) $inprogress_lessons_count)); |
|
| 425 | + |
|
| 426 | + $menu = apply_filters('sensei_grading_sub_menu', $menu); |
|
| 427 | + if ( ! empty($menu)) { |
|
| 428 | + echo '<ul class="subsubsub">'."\n"; |
|
| 429 | + foreach ($menu as $class => $item) { |
|
| 430 | + $menu[$class] = "\t<li class='$class'>$item"; |
|
| 431 | 431 | } |
| 432 | - echo implode( " |</li>\n", $menu ) . "</li>\n"; |
|
| 433 | - echo '</ul>' . "\n"; |
|
| 432 | + echo implode(" |</li>\n", $menu)."</li>\n"; |
|
| 433 | + echo '</ul>'."\n"; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | } // End data_table_header() |
@@ -451,4 +451,4 @@ discard block |
||
| 451 | 451 | * for backward compatibility |
| 452 | 452 | * @since 1.9.0 |
| 453 | 453 | */ |
| 454 | -class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main{} |
|
| 454 | +class WooThemes_Sensei_Grading_Main extends Sensei_Grading_Main {} |
|