@@ -403,7 +403,7 @@ discard block |
||
| 403 | 403 | /** |
| 404 | 404 | * Disable guest checkout if a course product is in the cart |
| 405 | 405 | * @param boolean $guest_checkout Current guest checkout setting |
| 406 | - * @return boolean Modified guest checkout setting |
|
| 406 | + * @return string|boolean Modified guest checkout setting |
|
| 407 | 407 | */ |
| 408 | 408 | public function disable_guest_checkout( $guest_checkout ) { |
| 409 | 409 | global $woocommerce; |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | * @since 1.0.0 |
| 643 | 643 | * @param int $course_id (default: 0) |
| 644 | 644 | * @param array/Object $order_user (default: array()) Specific user's data. |
| 645 | - * @return bool|int |
|
| 645 | + * @return boolean|string |
|
| 646 | 646 | */ |
| 647 | 647 | public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
| 648 | 648 | global $current_user; |
@@ -1241,7 +1241,7 @@ discard block |
||
| 1241 | 1241 | * |
| 1242 | 1242 | * @since 1.4.5 |
| 1243 | 1243 | * @access public |
| 1244 | - * @param mixed $image_size |
|
| 1244 | + * @param string $image_size |
|
| 1245 | 1245 | * @return string |
| 1246 | 1246 | */ |
| 1247 | 1247 | public function get_image_size( $image_size ) { |
@@ -14,1323 +14,1323 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Main { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var string |
|
| 19 | - * Reference to the main plugin file |
|
| 20 | - */ |
|
| 21 | - private $file; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
| 25 | - * @since 1.8.0 |
|
| 26 | - */ |
|
| 27 | - protected static $_instance = null; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Main reference to the plugins current version |
|
| 31 | - */ |
|
| 32 | - public $version; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Public token, referencing for the text domain. |
|
| 36 | - */ |
|
| 37 | - public $token = 'woothemes-sensei'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Plugin url and path for use when access resources. |
|
| 41 | - */ |
|
| 42 | - public $plugin_url; |
|
| 43 | - public $plugin_path; |
|
| 44 | - public $template_url; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var Sensei_PostTypes |
|
| 48 | - * All Sensei sub classes. Currently used to access functionality contained within |
|
| 49 | - * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
| 50 | - */ |
|
| 51 | - public $post_types; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var WooThemes_Sensei_Settings |
|
| 55 | - */ |
|
| 56 | - public $settings; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var WooThemes_Sensei_Course_Results |
|
| 60 | - */ |
|
| 61 | - public $course_results; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var Sensei_Updates |
|
| 65 | - */ |
|
| 66 | - public $updates; |
|
| 67 | - /** |
|
| 68 | - * @var WooThemes_Sensei_Course |
|
| 69 | - */ |
|
| 70 | - public $course; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var WooThemes_Sensei_Lesson |
|
| 74 | - */ |
|
| 75 | - public $lesson; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var WooThemes_Sensei_Quiz |
|
| 79 | - */ |
|
| 80 | - public $quiz; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @var WooThemes_Sensei_Question |
|
| 84 | - */ |
|
| 85 | - public $question; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @var WooThemes_Sensei_Admin |
|
| 89 | - */ |
|
| 90 | - public $admin; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @var WooThemes_Sensei_Frontend |
|
| 94 | - */ |
|
| 95 | - public $frontend; |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @var Sensei_Notices |
|
| 99 | - */ |
|
| 100 | - public $notices; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @var WooThemes_Sensei_Grading |
|
| 104 | - */ |
|
| 105 | - public $grading; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @var WooThemes_Sensei_Emails |
|
| 109 | - */ |
|
| 110 | - public $emails; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @var WooThemes_Sensei_Learner_Profiles |
|
| 114 | - */ |
|
| 115 | - public $learner_profiles; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @var Sensei_Teacher |
|
| 119 | - */ |
|
| 120 | - public $teacher; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @var WooThemes_Sensei_Learners |
|
| 124 | - */ |
|
| 125 | - public $learners; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @var array |
|
| 129 | - * Global instance for access to the permissions message shown |
|
| 130 | - * when users do not have the right privileges to access resources. |
|
| 131 | - */ |
|
| 132 | - public $permissions_message; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 136 | - */ |
|
| 137 | - public $modules; |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @var Sensei_Analysis |
|
| 141 | - */ |
|
| 142 | - public $analysis; |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Constructor method. |
|
| 146 | - * @param string $file The base file of the plugin. |
|
| 147 | - * @since 1.0.0 |
|
| 148 | - */ |
|
| 149 | - public function __construct ( $file ) { |
|
| 150 | - |
|
| 151 | - // Setup object data |
|
| 152 | - $this->file = $file; |
|
| 153 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 154 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 155 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 156 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 157 | - |
|
| 158 | - // Initialize the core Sensei functionality |
|
| 159 | - $this->init(); |
|
| 160 | - |
|
| 161 | - // Installation |
|
| 162 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 163 | - |
|
| 164 | - // Run this on activation. |
|
| 165 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 166 | - |
|
| 167 | - // load the classes need throughout sensei |
|
| 168 | - $this->initialize_global_objects(); |
|
| 169 | - |
|
| 170 | - // Image Sizes |
|
| 171 | - $this->init_image_sizes(); |
|
| 172 | - |
|
| 173 | - // Force WooCommerce Required Settings |
|
| 174 | - $this->set_woocommerce_functionality(); |
|
| 175 | - |
|
| 176 | - // load all hooks |
|
| 177 | - $this->load_hooks(); |
|
| 178 | - |
|
| 179 | - } // End __construct() |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Load the foundations of Sensei. |
|
| 183 | - * @since 1.9.0 |
|
| 184 | - */ |
|
| 185 | - protected function init(){ |
|
| 186 | - |
|
| 187 | - // Localisation |
|
| 188 | - $this->load_plugin_textdomain(); |
|
| 189 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 190 | - |
|
| 191 | - // load the shortcode loader into memory, so as to listen to all for |
|
| 192 | - // all shortcodes on the front end |
|
| 193 | - new Sensei_Shortcode_Loader(); |
|
| 194 | - |
|
| 195 | - } |
|
| 17 | + /** |
|
| 18 | + * @var string |
|
| 19 | + * Reference to the main plugin file |
|
| 20 | + */ |
|
| 21 | + private $file; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @var Sensei_Main $_instance to the the main and only instance of the Sensei class. |
|
| 25 | + * @since 1.8.0 |
|
| 26 | + */ |
|
| 27 | + protected static $_instance = null; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Main reference to the plugins current version |
|
| 31 | + */ |
|
| 32 | + public $version; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Public token, referencing for the text domain. |
|
| 36 | + */ |
|
| 37 | + public $token = 'woothemes-sensei'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Plugin url and path for use when access resources. |
|
| 41 | + */ |
|
| 42 | + public $plugin_url; |
|
| 43 | + public $plugin_path; |
|
| 44 | + public $template_url; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var Sensei_PostTypes |
|
| 48 | + * All Sensei sub classes. Currently used to access functionality contained within |
|
| 49 | + * within Sensei sub classes e.g. Sensei()->course->all_courses() |
|
| 50 | + */ |
|
| 51 | + public $post_types; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var WooThemes_Sensei_Settings |
|
| 55 | + */ |
|
| 56 | + public $settings; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var WooThemes_Sensei_Course_Results |
|
| 60 | + */ |
|
| 61 | + public $course_results; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var Sensei_Updates |
|
| 65 | + */ |
|
| 66 | + public $updates; |
|
| 67 | + /** |
|
| 68 | + * @var WooThemes_Sensei_Course |
|
| 69 | + */ |
|
| 70 | + public $course; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var WooThemes_Sensei_Lesson |
|
| 74 | + */ |
|
| 75 | + public $lesson; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @var WooThemes_Sensei_Quiz |
|
| 79 | + */ |
|
| 80 | + public $quiz; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @var WooThemes_Sensei_Question |
|
| 84 | + */ |
|
| 85 | + public $question; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @var WooThemes_Sensei_Admin |
|
| 89 | + */ |
|
| 90 | + public $admin; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @var WooThemes_Sensei_Frontend |
|
| 94 | + */ |
|
| 95 | + public $frontend; |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @var Sensei_Notices |
|
| 99 | + */ |
|
| 100 | + public $notices; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @var WooThemes_Sensei_Grading |
|
| 104 | + */ |
|
| 105 | + public $grading; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @var WooThemes_Sensei_Emails |
|
| 109 | + */ |
|
| 110 | + public $emails; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @var WooThemes_Sensei_Learner_Profiles |
|
| 114 | + */ |
|
| 115 | + public $learner_profiles; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @var Sensei_Teacher |
|
| 119 | + */ |
|
| 120 | + public $teacher; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @var WooThemes_Sensei_Learners |
|
| 124 | + */ |
|
| 125 | + public $learners; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @var array |
|
| 129 | + * Global instance for access to the permissions message shown |
|
| 130 | + * when users do not have the right privileges to access resources. |
|
| 131 | + */ |
|
| 132 | + public $permissions_message; |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @var Sensei_Core_Modules Sensei Modules functionality |
|
| 136 | + */ |
|
| 137 | + public $modules; |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @var Sensei_Analysis |
|
| 141 | + */ |
|
| 142 | + public $analysis; |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Constructor method. |
|
| 146 | + * @param string $file The base file of the plugin. |
|
| 147 | + * @since 1.0.0 |
|
| 148 | + */ |
|
| 149 | + public function __construct ( $file ) { |
|
| 150 | + |
|
| 151 | + // Setup object data |
|
| 152 | + $this->file = $file; |
|
| 153 | + $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 154 | + $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 155 | + $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 156 | + $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 157 | + |
|
| 158 | + // Initialize the core Sensei functionality |
|
| 159 | + $this->init(); |
|
| 160 | + |
|
| 161 | + // Installation |
|
| 162 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 163 | + |
|
| 164 | + // Run this on activation. |
|
| 165 | + register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 166 | + |
|
| 167 | + // load the classes need throughout sensei |
|
| 168 | + $this->initialize_global_objects(); |
|
| 169 | + |
|
| 170 | + // Image Sizes |
|
| 171 | + $this->init_image_sizes(); |
|
| 172 | + |
|
| 173 | + // Force WooCommerce Required Settings |
|
| 174 | + $this->set_woocommerce_functionality(); |
|
| 175 | + |
|
| 176 | + // load all hooks |
|
| 177 | + $this->load_hooks(); |
|
| 178 | + |
|
| 179 | + } // End __construct() |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Load the foundations of Sensei. |
|
| 183 | + * @since 1.9.0 |
|
| 184 | + */ |
|
| 185 | + protected function init(){ |
|
| 186 | + |
|
| 187 | + // Localisation |
|
| 188 | + $this->load_plugin_textdomain(); |
|
| 189 | + add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 190 | + |
|
| 191 | + // load the shortcode loader into memory, so as to listen to all for |
|
| 192 | + // all shortcodes on the front end |
|
| 193 | + new Sensei_Shortcode_Loader(); |
|
| 194 | + |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Global Sensei Instance |
|
| 199 | - * |
|
| 200 | - * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 201 | - * |
|
| 202 | - * @since 1.8.0 |
|
| 203 | - * @static |
|
| 204 | - * @see WC() |
|
| 205 | - * @return WooThemes_Sensei Instance. |
|
| 206 | - */ |
|
| 207 | - public static function instance() { |
|
| 197 | + /** |
|
| 198 | + * Global Sensei Instance |
|
| 199 | + * |
|
| 200 | + * Ensure that only one instance of the main Sensei class can be loaded. |
|
| 201 | + * |
|
| 202 | + * @since 1.8.0 |
|
| 203 | + * @static |
|
| 204 | + * @see WC() |
|
| 205 | + * @return WooThemes_Sensei Instance. |
|
| 206 | + */ |
|
| 207 | + public static function instance() { |
|
| 208 | 208 | |
| 209 | - if ( is_null( self::$_instance ) ) { |
|
| 209 | + if ( is_null( self::$_instance ) ) { |
|
| 210 | 210 | |
| 211 | - //Sensei requires a reference to the main Sensei plugin file |
|
| 212 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 211 | + //Sensei requires a reference to the main Sensei plugin file |
|
| 212 | + $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 213 | 213 | |
| 214 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 214 | + self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 215 | 215 | |
| 216 | - } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - return self::$_instance; |
|
| 218 | + return self::$_instance; |
|
| 219 | 219 | |
| 220 | - } // end instance() |
|
| 220 | + } // end instance() |
|
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * This function is linked into the activation |
|
| 224 | - * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 225 | - * |
|
| 226 | - * @since 1.9.0 |
|
| 227 | - * |
|
| 228 | - * @param $plugin |
|
| 229 | - */ |
|
| 230 | - public static function activation_flush_rules( $plugin ){ |
|
| 222 | + /** |
|
| 223 | + * This function is linked into the activation |
|
| 224 | + * hook to reset flush the urls to ensure Sensei post types show up. |
|
| 225 | + * |
|
| 226 | + * @since 1.9.0 |
|
| 227 | + * |
|
| 228 | + * @param $plugin |
|
| 229 | + */ |
|
| 230 | + public static function activation_flush_rules( $plugin ){ |
|
| 231 | 231 | |
| 232 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 232 | + if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 233 | 233 | |
| 234 | - flush_rewrite_rules(true); |
|
| 234 | + flush_rewrite_rules(true); |
|
| 235 | 235 | |
| 236 | - } |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - } |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * Cloning is forbidden. |
|
| 242 | - * @since 1.8.0 |
|
| 243 | - */ |
|
| 244 | - public function __clone() { |
|
| 245 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 246 | - } |
|
| 240 | + /** |
|
| 241 | + * Cloning is forbidden. |
|
| 242 | + * @since 1.8.0 |
|
| 243 | + */ |
|
| 244 | + public function __clone() { |
|
| 245 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Unserializing instances of this class is forbidden. |
|
| 250 | - * @since 1.8.0 |
|
| 251 | - */ |
|
| 252 | - public function __wakeup() { |
|
| 253 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 254 | - } |
|
| 248 | + /** |
|
| 249 | + * Unserializing instances of this class is forbidden. |
|
| 250 | + * @since 1.8.0 |
|
| 251 | + */ |
|
| 252 | + public function __wakeup() { |
|
| 253 | + _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - /** |
|
| 257 | - * Load the properties for the main Sensei object |
|
| 258 | - * |
|
| 259 | - * @since 1.9.0 |
|
| 260 | - */ |
|
| 261 | - public function initialize_global_objects(){ |
|
| 256 | + /** |
|
| 257 | + * Load the properties for the main Sensei object |
|
| 258 | + * |
|
| 259 | + * @since 1.9.0 |
|
| 260 | + */ |
|
| 261 | + public function initialize_global_objects(){ |
|
| 262 | 262 | |
| 263 | - // Setup post types. |
|
| 264 | - $this->post_types = new Sensei_PostTypes(); |
|
| 263 | + // Setup post types. |
|
| 264 | + $this->post_types = new Sensei_PostTypes(); |
|
| 265 | 265 | |
| 266 | - // Lad the updates class |
|
| 267 | - $this->updates = new Sensei_Updates( $this ); |
|
| 266 | + // Lad the updates class |
|
| 267 | + $this->updates = new Sensei_Updates( $this ); |
|
| 268 | 268 | |
| 269 | - // Setup settings |
|
| 270 | - $this->settings = new Sensei_Settings(); |
|
| 269 | + // Setup settings |
|
| 270 | + $this->settings = new Sensei_Settings(); |
|
| 271 | 271 | |
| 272 | - // Load Course Results Class |
|
| 273 | - $this->course_results = new Sensei_Course_Results(); |
|
| 272 | + // Load Course Results Class |
|
| 273 | + $this->course_results = new Sensei_Course_Results(); |
|
| 274 | 274 | |
| 275 | - // Load the teacher role |
|
| 276 | - $this->teacher = new Sensei_Teacher(); |
|
| 275 | + // Load the teacher role |
|
| 276 | + $this->teacher = new Sensei_Teacher(); |
|
| 277 | 277 | |
| 278 | - // Add the Course class |
|
| 279 | - $this->course = $this->post_types->course; |
|
| 278 | + // Add the Course class |
|
| 279 | + $this->course = $this->post_types->course; |
|
| 280 | 280 | |
| 281 | - // Add the lesson class |
|
| 282 | - $this->lesson = $this->post_types->lesson; |
|
| 281 | + // Add the lesson class |
|
| 282 | + $this->lesson = $this->post_types->lesson; |
|
| 283 | 283 | |
| 284 | - // Add the question class |
|
| 285 | - $this->question = $this->post_types->question; |
|
| 284 | + // Add the question class |
|
| 285 | + $this->question = $this->post_types->question; |
|
| 286 | 286 | |
| 287 | - //Add the quiz class |
|
| 288 | - $this->quiz = $this->post_types->quiz; |
|
| 287 | + //Add the quiz class |
|
| 288 | + $this->quiz = $this->post_types->quiz; |
|
| 289 | 289 | |
| 290 | - // load the modules class after all plugsin are loaded |
|
| 291 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 290 | + // load the modules class after all plugsin are loaded |
|
| 291 | + add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 292 | 292 | |
| 293 | - // Load Learner Management Functionality |
|
| 294 | - $this->learners = new Sensei_Learner_Management( $this->file ); |
|
| 293 | + // Load Learner Management Functionality |
|
| 294 | + $this->learners = new Sensei_Learner_Management( $this->file ); |
|
| 295 | 295 | |
| 296 | - // Differentiate between administration and frontend logic. |
|
| 297 | - if ( is_admin() ) { |
|
| 296 | + // Differentiate between administration and frontend logic. |
|
| 297 | + if ( is_admin() ) { |
|
| 298 | 298 | |
| 299 | - // Load Admin Welcome class |
|
| 300 | - new Sensei_Welcome(); |
|
| 299 | + // Load Admin Welcome class |
|
| 300 | + new Sensei_Welcome(); |
|
| 301 | 301 | |
| 302 | - // Load Admin Class |
|
| 303 | - $this->admin = new Sensei_Admin( $this->file ); |
|
| 302 | + // Load Admin Class |
|
| 303 | + $this->admin = new Sensei_Admin( $this->file ); |
|
| 304 | 304 | |
| 305 | - // Load Analysis Reports |
|
| 306 | - $this->analysis = new Sensei_Analysis( $this->file ); |
|
| 305 | + // Load Analysis Reports |
|
| 306 | + $this->analysis = new Sensei_Analysis( $this->file ); |
|
| 307 | 307 | |
| 308 | - } else { |
|
| 308 | + } else { |
|
| 309 | 309 | |
| 310 | - // Load Frontend Class |
|
| 311 | - $this->frontend = new Sensei_Frontend(); |
|
| 310 | + // Load Frontend Class |
|
| 311 | + $this->frontend = new Sensei_Frontend(); |
|
| 312 | 312 | |
| 313 | - // Load notice Class |
|
| 314 | - $this->notices = new Sensei_Notices(); |
|
| 313 | + // Load notice Class |
|
| 314 | + $this->notices = new Sensei_Notices(); |
|
| 315 | 315 | |
| 316 | - } |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | - // Load Grading Functionality |
|
| 319 | - $this->grading = new Sensei_Grading( $this->file ); |
|
| 318 | + // Load Grading Functionality |
|
| 319 | + $this->grading = new Sensei_Grading( $this->file ); |
|
| 320 | 320 | |
| 321 | - // Load Email Class |
|
| 322 | - $this->emails = new Sensei_Emails( $this->file ); |
|
| 321 | + // Load Email Class |
|
| 322 | + $this->emails = new Sensei_Emails( $this->file ); |
|
| 323 | 323 | |
| 324 | - // Load Learner Profiles Class |
|
| 325 | - $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 324 | + // Load Learner Profiles Class |
|
| 325 | + $this->learner_profiles = new Sensei_Learner_Profiles(); |
|
| 326 | 326 | |
| 327 | - } |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * Initialize all Sensei hooks |
|
| 331 | - * |
|
| 332 | - * @since 1.9.0 |
|
| 333 | - */ |
|
| 334 | - public function load_hooks(){ |
|
| 335 | - |
|
| 336 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 337 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 338 | - |
|
| 339 | - // WooCommerce Payment Actions |
|
| 340 | - add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 341 | - add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 342 | - add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 343 | - add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 344 | - add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 345 | - add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 346 | - add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 347 | - |
|
| 348 | - // WooCommerce Subscriptions Actions |
|
| 349 | - add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 350 | - add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 351 | - add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 352 | - add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 353 | - add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 354 | - |
|
| 355 | - // Add Email link to course orders |
|
| 356 | - add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 357 | - |
|
| 358 | - // Filter comment counts |
|
| 359 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 360 | - |
|
| 361 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 362 | - |
|
| 363 | - // Check for and activate JetPack LaTeX support |
|
| 364 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 365 | - |
|
| 366 | - // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 367 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 368 | - |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * Run Sensei updates. |
|
| 373 | - * @access public |
|
| 374 | - * @since 1.1.0 |
|
| 375 | - * @return void |
|
| 376 | - */ |
|
| 377 | - public function run_updates() { |
|
| 378 | - // Run updates if administrator |
|
| 379 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 380 | - |
|
| 381 | - $this->updates->update(); |
|
| 382 | - |
|
| 383 | - } // End If Statement |
|
| 384 | - } // End run_updates() |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Setup required WooCommerce settings. |
|
| 390 | - * @access public |
|
| 391 | - * @since 1.1.0 |
|
| 392 | - * @return void |
|
| 393 | - */ |
|
| 394 | - public function set_woocommerce_functionality() { |
|
| 395 | - // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
|
| 396 | - add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 397 | - |
|
| 398 | - // Mark orders with virtual products as complete rather then stay processing |
|
| 399 | - add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 400 | - |
|
| 401 | - } // End set_woocommerce_functionality() |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Disable guest checkout if a course product is in the cart |
|
| 405 | - * @param boolean $guest_checkout Current guest checkout setting |
|
| 406 | - * @return boolean Modified guest checkout setting |
|
| 407 | - */ |
|
| 408 | - public function disable_guest_checkout( $guest_checkout ) { |
|
| 409 | - global $woocommerce; |
|
| 410 | - |
|
| 411 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 412 | - |
|
| 413 | - if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 414 | - foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 415 | - if( isset( $product['product_id'] ) ) { |
|
| 416 | - $args = array( |
|
| 417 | - 'posts_per_page' => -1, |
|
| 418 | - 'post_type' => 'course', |
|
| 419 | - 'meta_query' => array( |
|
| 420 | - array( |
|
| 421 | - 'key' => '_course_woocommerce_product', |
|
| 422 | - 'value' => $product['product_id'] |
|
| 423 | - ) |
|
| 424 | - ) |
|
| 425 | - ); |
|
| 426 | - $posts = get_posts( $args ); |
|
| 427 | - if( $posts && count( $posts ) > 0 ) { |
|
| 428 | - foreach( $posts as $course ) { |
|
| 429 | - $guest_checkout = ''; |
|
| 430 | - break; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $guest_checkout; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Change order status with virtual products to completed |
|
| 443 | - * @since 1.1.0 |
|
| 444 | - * @param string $order_status |
|
| 445 | - * @param int $order_id |
|
| 446 | - * @return string |
|
| 447 | - **/ |
|
| 448 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 449 | - $order = new WC_Order( $order_id ); |
|
| 450 | - if ( ! isset ( $order ) ) return ''; |
|
| 451 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 452 | - $virtual_order = true; |
|
| 453 | - |
|
| 454 | - if ( count( $order->get_items() ) > 0 ) { |
|
| 455 | - foreach( $order->get_items() as $item ) { |
|
| 456 | - if ( $item['product_id'] > 0 ) { |
|
| 457 | - $_product = $order->get_product_from_item( $item ); |
|
| 458 | - if ( ! $_product->is_virtual() ) { |
|
| 459 | - $virtual_order = false; |
|
| 460 | - break; |
|
| 461 | - } // End If Statement |
|
| 462 | - } // End If Statement |
|
| 463 | - } // End For Loop |
|
| 464 | - } // End If Statement |
|
| 465 | - |
|
| 466 | - // virtual order, mark as completed |
|
| 467 | - if ( $virtual_order ) { |
|
| 468 | - return 'completed'; |
|
| 469 | - } // End If Statement |
|
| 470 | - } // End If Statement |
|
| 471 | - return $order_status; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Register the widgets. |
|
| 476 | - * @access public |
|
| 477 | - * @since 1.0.0 |
|
| 478 | - * @return void |
|
| 479 | - */ |
|
| 480 | - public function register_widgets () { |
|
| 481 | - // Widget List (key => value is filename => widget class). |
|
| 482 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 483 | - 'lesson-component' => 'Lesson_Component', |
|
| 484 | - 'course-categories' => 'Course_Categories', |
|
| 485 | - 'category-courses' => 'Category_Courses' ) |
|
| 486 | - ); |
|
| 487 | - foreach ( $widget_list as $key => $value ) { |
|
| 488 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
| 489 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
| 490 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 491 | - } |
|
| 492 | - } // End For Loop |
|
| 493 | - |
|
| 494 | - do_action( 'sensei_register_widgets' ); |
|
| 495 | - |
|
| 496 | - } // End register_widgets() |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * Load the plugin's localisation file. |
|
| 500 | - * @access public |
|
| 501 | - * @since 1.0.0 |
|
| 502 | - * @return void |
|
| 503 | - */ |
|
| 504 | - public function load_localisation () { |
|
| 505 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 506 | - } // End load_localisation() |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 510 | - * @access public |
|
| 511 | - * @since 1.0.0 |
|
| 512 | - * @return void |
|
| 513 | - */ |
|
| 514 | - public function load_plugin_textdomain () { |
|
| 515 | - $domain = 'woothemes-sensei'; |
|
| 516 | - // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 517 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 518 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 519 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 520 | - } // End load_plugin_textdomain() |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Run on activation. |
|
| 524 | - * @access public |
|
| 525 | - * @since 1.0.0 |
|
| 526 | - * @return void |
|
| 527 | - */ |
|
| 528 | - public function activation () { |
|
| 529 | - $this->register_plugin_version(); |
|
| 530 | - } // End activation() |
|
| 531 | - |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Register activation hooks. |
|
| 535 | - * @access public |
|
| 536 | - * @since 1.0.0 |
|
| 537 | - * @return void |
|
| 538 | - */ |
|
| 539 | - public function install () { |
|
| 540 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 541 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 542 | - } // End install() |
|
| 543 | - |
|
| 544 | - |
|
| 545 | - /** |
|
| 546 | - * Run on activation of the plugin. |
|
| 547 | - * @access public |
|
| 548 | - * @since 1.0.0 |
|
| 549 | - * @return void |
|
| 550 | - */ |
|
| 551 | - public function activate_sensei () { |
|
| 552 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
| 553 | - update_option( 'sensei_installed', 1 ); |
|
| 554 | - } // End activate_sensei() |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Register the plugin's version. |
|
| 558 | - * @access public |
|
| 559 | - * @since 1.0.0 |
|
| 560 | - * @return void |
|
| 561 | - */ |
|
| 562 | - private function register_plugin_version () { |
|
| 563 | - if ( $this->version != '' ) { |
|
| 564 | - |
|
| 565 | - // Check previous version to see if forced updates must run |
|
| 566 | - // $old_version = get_option( 'woothemes-sensei-version', false ); |
|
| 567 | - // if( $old_version && version_compare( $old_version, '1.7.0', '<' ) ) { |
|
| 568 | - // update_option( 'woothemes-sensei-force-updates', $this->version ); |
|
| 569 | - // } else { |
|
| 570 | - // delete_option( 'woothemes-sensei-force-updates' ); |
|
| 571 | - // } |
|
| 572 | - |
|
| 573 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
| 574 | - } |
|
| 575 | - } // End register_plugin_version() |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 579 | - * @access public |
|
| 580 | - * @since 1.0.1 |
|
| 581 | - * @return void |
|
| 582 | - */ |
|
| 583 | - public function ensure_post_thumbnails_support () { |
|
| 584 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 585 | - } // End ensure_post_thumbnails_support() |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * template_loader function. |
|
| 590 | - * |
|
| 591 | - * @access public |
|
| 592 | - * @param mixed $template |
|
| 593 | - * @return void |
|
| 594 | - * @deprecated |
|
| 595 | - */ |
|
| 596 | - public function template_loader ( $template = '' ) { |
|
| 597 | - |
|
| 598 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 599 | - Sensei_Templates::template_loader( $template ); |
|
| 600 | - |
|
| 601 | - } // End template_loader() |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * Determine the relative path to the plugin's directory. |
|
| 605 | - * @access public |
|
| 606 | - * @since 1.0.0 |
|
| 607 | - * @return string $sensei_plugin_path |
|
| 608 | - */ |
|
| 609 | - public function plugin_path () { |
|
| 610 | - |
|
| 611 | - if ( $this->plugin_path ) { |
|
| 612 | - |
|
| 613 | - $sensei_plugin_path = $this->plugin_path; |
|
| 614 | - |
|
| 615 | - }else{ |
|
| 616 | - |
|
| 617 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 618 | - |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - return $sensei_plugin_path; |
|
| 622 | - |
|
| 623 | - } // End plugin_path() |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Retrieve the ID of a specified page setting. |
|
| 628 | - * @access public |
|
| 629 | - * @since 1.0.0 |
|
| 630 | - * @param string $page |
|
| 631 | - * @return int |
|
| 632 | - */ |
|
| 633 | - public function get_page_id ( $page ) { |
|
| 634 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 635 | - return ( $page ) ? $page : -1; |
|
| 636 | - } // End get_page_id() |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 641 | - * @access public |
|
| 642 | - * @since 1.0.0 |
|
| 643 | - * @param int $course_id (default: 0) |
|
| 644 | - * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 645 | - * @return bool|int |
|
| 646 | - */ |
|
| 647 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 648 | - global $current_user; |
|
| 649 | - |
|
| 650 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
| 651 | - |
|
| 652 | - $data_update = false; |
|
| 653 | - |
|
| 654 | - // Get the product ID |
|
| 655 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 656 | - |
|
| 657 | - // Check if in the admin |
|
| 658 | - if ( is_admin() ) { |
|
| 659 | - $user_login = $order_user['user_login']; |
|
| 660 | - $user_email = $order_user['user_email']; |
|
| 661 | - $user_url = $order_user['user_url']; |
|
| 662 | - $user_id = $order_user['ID']; |
|
| 663 | - } else { |
|
| 664 | - $user_login = $current_user->user_login; |
|
| 665 | - $user_email = $current_user->user_email; |
|
| 666 | - $user_url = $current_user->user_url; |
|
| 667 | - $user_id = $current_user->ID; |
|
| 668 | - } // End If Statement |
|
| 669 | - |
|
| 670 | - // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 671 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 672 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 673 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 674 | - if ( ! $prereq_course_complete ) { |
|
| 675 | - // Remove all course user meta |
|
| 676 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 681 | - |
|
| 682 | - if( ! $is_user_taking_course ) { |
|
| 683 | - |
|
| 684 | - if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 685 | - |
|
| 686 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 687 | - |
|
| 688 | - $is_user_taking_course = false; |
|
| 689 | - if ( true == $activity_logged ) { |
|
| 690 | - $is_user_taking_course = true; |
|
| 691 | - } // End If Statement |
|
| 692 | - } // End If Statement |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - return $is_user_taking_course; |
|
| 696 | - } // End woocommerce_course_update() |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * check_user_permissions function. |
|
| 701 | - * |
|
| 702 | - * @access public |
|
| 703 | - * @param string $page (default: '') |
|
| 704 | - * |
|
| 705 | - * @return bool |
|
| 706 | - */ |
|
| 707 | - public function check_user_permissions ( $page = '' ) { |
|
| 708 | - // REFACTOR |
|
| 709 | - global $current_user, $post; |
|
| 710 | - |
|
| 711 | - // if use is not logged in |
|
| 712 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){ |
|
| 713 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 714 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 715 | - return false; |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - // Get User Meta |
|
| 720 | - get_currentuserinfo(); |
|
| 721 | - |
|
| 722 | - $user_allowed = false; |
|
| 723 | - |
|
| 724 | - switch ( $page ) { |
|
| 725 | - case 'course-single': |
|
| 726 | - // check for prerequisite course or lesson, |
|
| 727 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 728 | - $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 729 | - // Count completed lessons |
|
| 730 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 731 | - |
|
| 732 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 733 | - |
|
| 734 | - } |
|
| 735 | - else { |
|
| 736 | - $prerequisite_complete = true; |
|
| 737 | - } // End If Statement |
|
| 738 | - // Handles restrictions |
|
| 739 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 740 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 741 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 742 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 743 | - } else { |
|
| 744 | - $user_allowed = true; |
|
| 745 | - } // End If Statement |
|
| 746 | - break; |
|
| 747 | - case 'lesson-single': |
|
| 748 | - // Check for WC purchase |
|
| 749 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 750 | - |
|
| 751 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 752 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 753 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 754 | - $user_allowed = true; |
|
| 755 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 756 | - |
|
| 757 | - $user_allowed = true; |
|
| 758 | - } else { |
|
| 759 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 760 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 761 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 762 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 763 | - if ( $is_preview ) { |
|
| 764 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 765 | - } else { |
|
| 766 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 767 | - } |
|
| 768 | - } else { |
|
| 769 | - if ( $is_preview ) { |
|
| 770 | - $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 ); |
|
| 771 | - } else { |
|
| 772 | - /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 773 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 774 | - } |
|
| 775 | - } // End If Statement |
|
| 776 | - } // End If Statement |
|
| 777 | - break; |
|
| 778 | - case 'quiz-single': |
|
| 779 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 780 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 781 | - |
|
| 782 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 783 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 784 | - |
|
| 785 | - // Check for prerequisite lesson for this quiz |
|
| 786 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 787 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 788 | - |
|
| 789 | - // Handle restrictions |
|
| 790 | - if( sensei_all_access() ) { |
|
| 791 | - $user_allowed = true; |
|
| 792 | - } else { |
|
| 793 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 794 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 795 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 796 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 797 | - } else { |
|
| 798 | - $user_allowed = true; |
|
| 799 | - } // End If Statement |
|
| 800 | - } // End If Statement |
|
| 801 | - } elseif( $this->access_settings() ) { |
|
| 802 | - // Check if the user has started the course |
|
| 803 | - |
|
| 804 | - 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'] ) ) ) { |
|
| 805 | - |
|
| 806 | - $user_allowed = false; |
|
| 807 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 808 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 809 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 810 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 811 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 812 | - } else { |
|
| 813 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 814 | - } // End If Statement |
|
| 815 | - } else { |
|
| 816 | - $user_allowed = true; |
|
| 817 | - } // End If Statement |
|
| 818 | - } else { |
|
| 819 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 820 | - $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>'; |
|
| 821 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 822 | - } // End If Statement |
|
| 823 | - break; |
|
| 824 | - default: |
|
| 825 | - $user_allowed = true; |
|
| 826 | - break; |
|
| 827 | - |
|
| 828 | - } // End Switch Statement |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * filter the permissions message shown on sensei post types. |
|
| 832 | - * |
|
| 833 | - * @since 1.8.7 |
|
| 834 | - * |
|
| 835 | - * @param array $permissions_message{ |
|
| 836 | - * |
|
| 837 | - * @type string $title |
|
| 838 | - * @type string $message |
|
| 839 | - * |
|
| 840 | - * } |
|
| 841 | - * @param string $post_id |
|
| 842 | - */ |
|
| 843 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 847 | - $user_allowed = true; |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 851 | - } // End get_placeholder_image() |
|
| 852 | - |
|
| 853 | - |
|
| 854 | - /** |
|
| 855 | - * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 856 | - * @since 1.0.0 |
|
| 857 | - * @access public |
|
| 858 | - * @return bool |
|
| 859 | - */ |
|
| 860 | - public function access_settings () { |
|
| 861 | - |
|
| 862 | - if( sensei_all_access() ) return true; |
|
| 863 | - |
|
| 864 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 865 | - if ( is_user_logged_in() ) { |
|
| 866 | - return true; |
|
| 867 | - } else { |
|
| 868 | - return false; |
|
| 869 | - } // End If Statement |
|
| 870 | - } else { |
|
| 871 | - return true; |
|
| 872 | - } // End If Statement |
|
| 873 | - } // End access_settings() |
|
| 874 | - |
|
| 875 | - /** |
|
| 876 | - * sensei_woocommerce_complete_order description |
|
| 877 | - * @since 1.0.3 |
|
| 878 | - * @access public |
|
| 879 | - * @param int $order_id WC order ID |
|
| 880 | - * @return void |
|
| 881 | - */ |
|
| 882 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 883 | - $order_user = array(); |
|
| 884 | - // Check for WooCommerce |
|
| 885 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 886 | - // Get order object |
|
| 887 | - $order = new WC_Order( $order_id ); |
|
| 888 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 889 | - $order_user['ID'] = $user->ID; |
|
| 890 | - $order_user['user_login'] = $user->user_login; |
|
| 891 | - $order_user['user_email'] = $user->user_email; |
|
| 892 | - $order_user['user_url'] = $user->user_url; |
|
| 893 | - // Run through each product ordered |
|
| 894 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 895 | - foreach( $order->get_items() as $item ) { |
|
| 896 | - $product_type = ''; |
|
| 897 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 898 | - $item_id = $item['variation_id']; |
|
| 899 | - $product_type = 'variation'; |
|
| 900 | - } else { |
|
| 901 | - $item_id = $item['product_id']; |
|
| 902 | - } // End If Statement |
|
| 903 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 904 | - // Get courses that use the WC product |
|
| 905 | - $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 906 | - // Loop and update those courses |
|
| 907 | - foreach ( $courses as $course_item ) { |
|
| 908 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 909 | - } // End For Loop |
|
| 910 | - } // End For Loop |
|
| 911 | - } // End If Statement |
|
| 912 | - // Add meta to indicate that payment has been completed successfully |
|
| 913 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 914 | - } // End If Statement |
|
| 915 | - } // End sensei_woocommerce_complete_order() |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Runs when an order is cancelled. |
|
| 919 | - * @since 1.2.0 |
|
| 920 | - * @access public |
|
| 921 | - * @param integer $order_id order ID |
|
| 922 | - * @return void |
|
| 923 | - */ |
|
| 924 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 925 | - |
|
| 926 | - // Get order object |
|
| 927 | - $order = new WC_Order( $order_id ); |
|
| 928 | - |
|
| 929 | - // Run through each product ordered |
|
| 930 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 931 | - |
|
| 932 | - // Get order user |
|
| 933 | - $user_id = $order->__get( 'user_id' ); |
|
| 934 | - |
|
| 935 | - foreach( $order->get_items() as $item ) { |
|
| 936 | - |
|
| 937 | - $product_type = ''; |
|
| 938 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 939 | - $item_id = $item['variation_id']; |
|
| 940 | - $product_type = 'variation'; |
|
| 941 | - } else { |
|
| 942 | - $item_id = $item['product_id']; |
|
| 943 | - } // End If Statement |
|
| 944 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 945 | - |
|
| 946 | - // Get courses that use the WC product |
|
| 947 | - $courses = array(); |
|
| 948 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 949 | - |
|
| 950 | - // Loop and update those courses |
|
| 951 | - foreach ($courses as $course_item){ |
|
| 952 | - // Check and Remove course from courses user meta |
|
| 953 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 954 | - } // End For Loop |
|
| 955 | - } // End For Loop |
|
| 956 | - } // End If Statement |
|
| 957 | - } // End sensei_woocommerce_cancel_order() |
|
| 958 | - |
|
| 959 | - /** |
|
| 960 | - * Runs when an subscription is cancelled or expires. |
|
| 961 | - * @since 1.3.3 |
|
| 962 | - * @access public |
|
| 963 | - * @param integer $user_id User ID |
|
| 964 | - * @param integer $subscription_key Subscription Unique Key |
|
| 965 | - * @return void |
|
| 966 | - */ |
|
| 967 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 968 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 969 | - self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - /** |
|
| 973 | - * Runs when an subscription is re-activated after suspension. |
|
| 974 | - * @since 1.3.3 |
|
| 975 | - * @access public |
|
| 976 | - * @param integer $user_id User ID |
|
| 977 | - * @param integer $subscription_key Subscription Unique Key |
|
| 978 | - * @return void |
|
| 979 | - */ |
|
| 980 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 981 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 982 | - $order = new WC_Order( $subscription['order_id'] ); |
|
| 983 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 984 | - $order_user = array(); |
|
| 985 | - $order_user['ID'] = $user->ID; |
|
| 986 | - $order_user['user_login'] = $user->user_login; |
|
| 987 | - $order_user['user_email'] = $user->user_email; |
|
| 988 | - $order_user['user_url'] = $user->user_url; |
|
| 989 | - $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 990 | - foreach ( $courses as $course_item ){ |
|
| 991 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 992 | - } // End For Loop |
|
| 993 | - } // End sensei_woocommerce_reactivate_subscription |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * Returns the WooCommerce Product Object |
|
| 997 | - * |
|
| 998 | - * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 999 | - * |
|
| 1000 | - * @since 1.1.1 |
|
| 1001 | - * @access public |
|
| 1002 | - * @param integer $wc_product_id Product ID or Variation ID |
|
| 1003 | - * @param string $product_type '' or 'variation' |
|
| 1004 | - * @return WC_Product $wc_product_object |
|
| 1005 | - */ |
|
| 1006 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1007 | - |
|
| 1008 | - $wc_product_object = false; |
|
| 1009 | - if ( 0 < intval( $wc_product_id ) ) { |
|
| 1010 | - |
|
| 1011 | - // Get the product |
|
| 1012 | - if ( function_exists( 'wc_get_product' ) ) { |
|
| 1013 | - |
|
| 1014 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1015 | - |
|
| 1016 | - } elseif ( function_exists( 'get_product' ) ) { |
|
| 1017 | - |
|
| 1018 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1019 | - |
|
| 1020 | - } else { |
|
| 1021 | - |
|
| 1022 | - // Pre WC 2.0 |
|
| 1023 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1024 | - |
|
| 1025 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1026 | - |
|
| 1027 | - } else { |
|
| 1028 | - |
|
| 1029 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1030 | - |
|
| 1031 | - } // End If Statement |
|
| 1032 | - |
|
| 1033 | - } // End If Statement |
|
| 1034 | - |
|
| 1035 | - } // End If Statement |
|
| 1036 | - |
|
| 1037 | - return $wc_product_object; |
|
| 1038 | - |
|
| 1039 | - } // End sensei_get_woocommerce_product_object() |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * load_class loads in class files |
|
| 1043 | - * @since 1.2.0 |
|
| 1044 | - * @access public |
|
| 1045 | - * @return void |
|
| 1046 | - */ |
|
| 1047 | - public function load_class ( $class_name = '' ) { |
|
| 1048 | - if ( '' != $class_name && '' != $this->token ) { |
|
| 1049 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1050 | - } // End If Statement |
|
| 1051 | - } // End load_class() |
|
| 1052 | - |
|
| 1053 | - /** |
|
| 1054 | - * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1055 | - * @since 1.2.0 |
|
| 1056 | - * @access public |
|
| 1057 | - * @param integer $order_id order ID |
|
| 1058 | - * @return void |
|
| 1059 | - */ |
|
| 1060 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1061 | - if ( 0 < intval( $order_id ) ) { |
|
| 1062 | - $order = new WC_Order( $order_id ); |
|
| 1063 | - $user = get_user_by('id', $order->user_id); |
|
| 1064 | - $order_user['ID'] = $user->ID; |
|
| 1065 | - $order_user['user_login'] = $user->user_login; |
|
| 1066 | - $order_user['user_email'] = $user->user_email; |
|
| 1067 | - $order_user['user_url'] = $user->user_url; |
|
| 1068 | - // Run through each product ordered |
|
| 1069 | - if (sizeof($order->get_items())>0) { |
|
| 1070 | - foreach($order->get_items() as $item) { |
|
| 1071 | - $product_type = ''; |
|
| 1072 | - if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1073 | - $item_id = $item['variation_id']; |
|
| 1074 | - $product_type = 'subscription_variation'; |
|
| 1075 | - } else { |
|
| 1076 | - $item_id = $item['product_id']; |
|
| 1077 | - } // End If Statement |
|
| 1078 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1079 | - // Get courses that use the WC product |
|
| 1080 | - $courses = array(); |
|
| 1081 | - if ( $product_type == 'subscription_variation' ) { |
|
| 1082 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1083 | - } // End If Statement |
|
| 1084 | - // Loop and update those courses |
|
| 1085 | - foreach ($courses as $course_item){ |
|
| 1086 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1087 | - } // End For Loop |
|
| 1088 | - } // End For Loop |
|
| 1089 | - } // End If Statement |
|
| 1090 | - } // End If Statement |
|
| 1091 | - } // End sensei_activate_subscription() |
|
| 1092 | - |
|
| 1093 | - /** |
|
| 1094 | - * sensei_woocommerce_email_course_details adds detail to email |
|
| 1095 | - * @since 1.4.5 |
|
| 1096 | - * @access public |
|
| 1097 | - * @param WC_Order $order |
|
| 1098 | - * @return void |
|
| 1099 | - */ |
|
| 1100 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1101 | - global $woocommerce; |
|
| 1102 | - |
|
| 1103 | - // exit early if not wc-completed or wc-processing |
|
| 1104 | - if( 'wc-completed' != $order->post_status |
|
| 1105 | - && 'wc-processing' != $order->post_status ) { |
|
| 1106 | - return; |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - $order_items = $order->get_items(); |
|
| 1110 | - $order_id = $order->id; |
|
| 1111 | - |
|
| 1112 | - //If object have items go through them all to find course |
|
| 1113 | - if ( 0 < sizeof( $order_items ) ) { |
|
| 1114 | - |
|
| 1115 | - echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1116 | - |
|
| 1117 | - foreach ( $order_items as $item ) { |
|
| 1118 | - |
|
| 1119 | - $product_type = ''; |
|
| 1120 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1121 | - // If item has variation_id then its from variation |
|
| 1122 | - $item_id = $item['variation_id']; |
|
| 1123 | - $product_type = 'variation'; |
|
| 1124 | - } else { |
|
| 1125 | - // If not its real product set its id to item_id |
|
| 1126 | - $item_id = $item['product_id']; |
|
| 1127 | - } // End If Statement |
|
| 1128 | - |
|
| 1129 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1130 | - |
|
| 1131 | - if( $user_id ) { |
|
| 1132 | - |
|
| 1133 | - // Get all courses for product |
|
| 1134 | - $args = array( |
|
| 1135 | - 'posts_per_page' => -1, |
|
| 1136 | - 'post_type' => 'course', |
|
| 1137 | - 'meta_query' => array( |
|
| 1138 | - array( |
|
| 1139 | - 'key' => '_course_woocommerce_product', |
|
| 1140 | - 'value' => $item_id |
|
| 1141 | - ) |
|
| 1142 | - ), |
|
| 1143 | - 'orderby' => 'menu_order date', |
|
| 1144 | - 'order' => 'ASC', |
|
| 1145 | - ); |
|
| 1146 | - $courses = get_posts( $args ); |
|
| 1147 | - |
|
| 1148 | - if( $courses && count( $courses ) > 0 ) { |
|
| 1149 | - |
|
| 1150 | - foreach( $courses as $course ) { |
|
| 1151 | - |
|
| 1152 | - $title = $course->post_title; |
|
| 1153 | - $permalink = get_permalink( $course->ID ); |
|
| 1154 | - |
|
| 1155 | - echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1156 | - } |
|
| 1157 | - } |
|
| 1158 | - } |
|
| 1159 | - } |
|
| 1160 | - } |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - /** |
|
| 1164 | - * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 1165 | - * @since 1.4.0 |
|
| 1166 | - * @access public |
|
| 1167 | - * @param array $comments |
|
| 1168 | - * @param integer $post_id |
|
| 1169 | - * @return array |
|
| 1170 | - */ |
|
| 1171 | - public function sensei_count_comments( $comments, $post_id ) { |
|
| 1172 | - global $wpdb; |
|
| 1173 | - |
|
| 1174 | - $post_id = (int) $post_id; |
|
| 1175 | - |
|
| 1176 | - $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 1177 | - |
|
| 1178 | - if ( false !== $count ) { |
|
| 1179 | - return $count; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - $statuses = array( '' ); // Default to the WP normal comments |
|
| 1183 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1184 | - foreach ( (array) $stati AS $status ) { |
|
| 1185 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1186 | - $statuses[] = $status['comment_type']; |
|
| 1187 | - } |
|
| 1188 | - } |
|
| 1189 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1190 | - |
|
| 1191 | - if ( $post_id > 0 ) |
|
| 1192 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1193 | - |
|
| 1194 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1195 | - |
|
| 1196 | - $total = 0; |
|
| 1197 | - $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 1198 | - foreach ( (array) $count as $row ) { |
|
| 1199 | - // Don't count post-trashed toward totals |
|
| 1200 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1201 | - $total += $row['num_comments']; |
|
| 1202 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1203 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - $stats['total_comments'] = $total; |
|
| 1207 | - foreach ( $approved as $key ) { |
|
| 1208 | - if ( empty($stats[$key]) ) |
|
| 1209 | - $stats[$key] = 0; |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - $stats = (object) $stats; |
|
| 1213 | - wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 1214 | - |
|
| 1215 | - return $stats; |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - /** |
|
| 1219 | - * Init images. |
|
| 1220 | - * |
|
| 1221 | - * @since 1.4.5 |
|
| 1222 | - * @access public |
|
| 1223 | - * @return void |
|
| 1224 | - */ |
|
| 1225 | - public function init_image_sizes() { |
|
| 1226 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1227 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1228 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1229 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1230 | - |
|
| 1231 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1232 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1233 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1234 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - /** |
|
| 1238 | - * Get an image size. |
|
| 1239 | - * |
|
| 1240 | - * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 1241 | - * |
|
| 1242 | - * @since 1.4.5 |
|
| 1243 | - * @access public |
|
| 1244 | - * @param mixed $image_size |
|
| 1245 | - * @return string |
|
| 1246 | - */ |
|
| 1247 | - public function get_image_size( $image_size ) { |
|
| 1248 | - |
|
| 1249 | - // Only return sizes we define in settings |
|
| 1250 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1251 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1252 | - |
|
| 1253 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1254 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1255 | - } |
|
| 1256 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1257 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1258 | - } |
|
| 1259 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1260 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - $size = array_filter( array( |
|
| 1264 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1265 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1266 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1267 | - ) ); |
|
| 1268 | - |
|
| 1269 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1270 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1271 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1272 | - |
|
| 1273 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1274 | - } |
|
| 1275 | - |
|
| 1276 | - public function body_class( $classes ) { |
|
| 1277 | - if( is_sensei() ) { |
|
| 1278 | - $classes[] = 'sensei'; |
|
| 1279 | - } |
|
| 1280 | - return $classes; |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - /** |
|
| 1284 | - * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 1285 | - * |
|
| 1286 | - * @return null |
|
| 1287 | - * @since 1.7.0 |
|
| 1288 | - */ |
|
| 1289 | - public function jetpack_latex_support() { |
|
| 1290 | - if ( function_exists( 'latex_markup') ) { |
|
| 1291 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1292 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1293 | - } |
|
| 1294 | - } |
|
| 1295 | - |
|
| 1296 | - /** |
|
| 1297 | - * Load the module functionality. |
|
| 1298 | - * |
|
| 1299 | - * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 1300 | - * the retired modules extension. |
|
| 1301 | - * |
|
| 1302 | - * @since 1.8.0 |
|
| 1303 | - */ |
|
| 1304 | - public function load_modules_class(){ |
|
| 1305 | - global $sensei_modules; |
|
| 1306 | - |
|
| 1307 | - if( !class_exists( 'Sensei_Modules' ) |
|
| 1308 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1309 | - |
|
| 1310 | - //Load the modules class |
|
| 1311 | - require_once( 'class-sensei-modules.php'); |
|
| 1312 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1313 | - |
|
| 1314 | - }else{ |
|
| 1315 | - // fallback for people still using the modules extension. |
|
| 1316 | - global $sensei_modules; |
|
| 1317 | - Sensei()->modules = $sensei_modules; |
|
| 1318 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1319 | - } |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - /** |
|
| 1323 | - * Tell the user to that the modules extension is no longer needed. |
|
| 1324 | - * |
|
| 1325 | - * @since 1.8.0 |
|
| 1326 | - */ |
|
| 1327 | - public function disable_sensei_modules_extension(){ ?> |
|
| 329 | + /** |
|
| 330 | + * Initialize all Sensei hooks |
|
| 331 | + * |
|
| 332 | + * @since 1.9.0 |
|
| 333 | + */ |
|
| 334 | + public function load_hooks(){ |
|
| 335 | + |
|
| 336 | + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 337 | + add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 338 | + |
|
| 339 | + // WooCommerce Payment Actions |
|
| 340 | + add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 341 | + add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 342 | + add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 343 | + add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 344 | + add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 345 | + add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 346 | + add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 347 | + |
|
| 348 | + // WooCommerce Subscriptions Actions |
|
| 349 | + add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 350 | + add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 351 | + add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 352 | + add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 353 | + add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 354 | + |
|
| 355 | + // Add Email link to course orders |
|
| 356 | + add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 357 | + |
|
| 358 | + // Filter comment counts |
|
| 359 | + add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 360 | + |
|
| 361 | + add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 362 | + |
|
| 363 | + // Check for and activate JetPack LaTeX support |
|
| 364 | + add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 365 | + |
|
| 366 | + // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
|
| 367 | + add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 368 | + |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * Run Sensei updates. |
|
| 373 | + * @access public |
|
| 374 | + * @since 1.1.0 |
|
| 375 | + * @return void |
|
| 376 | + */ |
|
| 377 | + public function run_updates() { |
|
| 378 | + // Run updates if administrator |
|
| 379 | + if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 380 | + |
|
| 381 | + $this->updates->update(); |
|
| 382 | + |
|
| 383 | + } // End If Statement |
|
| 384 | + } // End run_updates() |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Setup required WooCommerce settings. |
|
| 390 | + * @access public |
|
| 391 | + * @since 1.1.0 |
|
| 392 | + * @return void |
|
| 393 | + */ |
|
| 394 | + public function set_woocommerce_functionality() { |
|
| 395 | + // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
|
| 396 | + add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 397 | + |
|
| 398 | + // Mark orders with virtual products as complete rather then stay processing |
|
| 399 | + add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 400 | + |
|
| 401 | + } // End set_woocommerce_functionality() |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Disable guest checkout if a course product is in the cart |
|
| 405 | + * @param boolean $guest_checkout Current guest checkout setting |
|
| 406 | + * @return boolean Modified guest checkout setting |
|
| 407 | + */ |
|
| 408 | + public function disable_guest_checkout( $guest_checkout ) { |
|
| 409 | + global $woocommerce; |
|
| 410 | + |
|
| 411 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 412 | + |
|
| 413 | + if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 414 | + foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 415 | + if( isset( $product['product_id'] ) ) { |
|
| 416 | + $args = array( |
|
| 417 | + 'posts_per_page' => -1, |
|
| 418 | + 'post_type' => 'course', |
|
| 419 | + 'meta_query' => array( |
|
| 420 | + array( |
|
| 421 | + 'key' => '_course_woocommerce_product', |
|
| 422 | + 'value' => $product['product_id'] |
|
| 423 | + ) |
|
| 424 | + ) |
|
| 425 | + ); |
|
| 426 | + $posts = get_posts( $args ); |
|
| 427 | + if( $posts && count( $posts ) > 0 ) { |
|
| 428 | + foreach( $posts as $course ) { |
|
| 429 | + $guest_checkout = ''; |
|
| 430 | + break; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $guest_checkout; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Change order status with virtual products to completed |
|
| 443 | + * @since 1.1.0 |
|
| 444 | + * @param string $order_status |
|
| 445 | + * @param int $order_id |
|
| 446 | + * @return string |
|
| 447 | + **/ |
|
| 448 | + public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 449 | + $order = new WC_Order( $order_id ); |
|
| 450 | + if ( ! isset ( $order ) ) return ''; |
|
| 451 | + if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 452 | + $virtual_order = true; |
|
| 453 | + |
|
| 454 | + if ( count( $order->get_items() ) > 0 ) { |
|
| 455 | + foreach( $order->get_items() as $item ) { |
|
| 456 | + if ( $item['product_id'] > 0 ) { |
|
| 457 | + $_product = $order->get_product_from_item( $item ); |
|
| 458 | + if ( ! $_product->is_virtual() ) { |
|
| 459 | + $virtual_order = false; |
|
| 460 | + break; |
|
| 461 | + } // End If Statement |
|
| 462 | + } // End If Statement |
|
| 463 | + } // End For Loop |
|
| 464 | + } // End If Statement |
|
| 465 | + |
|
| 466 | + // virtual order, mark as completed |
|
| 467 | + if ( $virtual_order ) { |
|
| 468 | + return 'completed'; |
|
| 469 | + } // End If Statement |
|
| 470 | + } // End If Statement |
|
| 471 | + return $order_status; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Register the widgets. |
|
| 476 | + * @access public |
|
| 477 | + * @since 1.0.0 |
|
| 478 | + * @return void |
|
| 479 | + */ |
|
| 480 | + public function register_widgets () { |
|
| 481 | + // Widget List (key => value is filename => widget class). |
|
| 482 | + $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 483 | + 'lesson-component' => 'Lesson_Component', |
|
| 484 | + 'course-categories' => 'Course_Categories', |
|
| 485 | + 'category-courses' => 'Category_Courses' ) |
|
| 486 | + ); |
|
| 487 | + foreach ( $widget_list as $key => $value ) { |
|
| 488 | + if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
| 489 | + require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
| 490 | + register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 491 | + } |
|
| 492 | + } // End For Loop |
|
| 493 | + |
|
| 494 | + do_action( 'sensei_register_widgets' ); |
|
| 495 | + |
|
| 496 | + } // End register_widgets() |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * Load the plugin's localisation file. |
|
| 500 | + * @access public |
|
| 501 | + * @since 1.0.0 |
|
| 502 | + * @return void |
|
| 503 | + */ |
|
| 504 | + public function load_localisation () { |
|
| 505 | + load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 506 | + } // End load_localisation() |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * Load the plugin textdomain from the main WordPress "languages" folder. |
|
| 510 | + * @access public |
|
| 511 | + * @since 1.0.0 |
|
| 512 | + * @return void |
|
| 513 | + */ |
|
| 514 | + public function load_plugin_textdomain () { |
|
| 515 | + $domain = 'woothemes-sensei'; |
|
| 516 | + // The "plugin_locale" filter is also used in load_plugin_textdomain() |
|
| 517 | + $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 518 | + load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 519 | + load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 520 | + } // End load_plugin_textdomain() |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Run on activation. |
|
| 524 | + * @access public |
|
| 525 | + * @since 1.0.0 |
|
| 526 | + * @return void |
|
| 527 | + */ |
|
| 528 | + public function activation () { |
|
| 529 | + $this->register_plugin_version(); |
|
| 530 | + } // End activation() |
|
| 531 | + |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Register activation hooks. |
|
| 535 | + * @access public |
|
| 536 | + * @since 1.0.0 |
|
| 537 | + * @return void |
|
| 538 | + */ |
|
| 539 | + public function install () { |
|
| 540 | + register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 541 | + register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 542 | + } // End install() |
|
| 543 | + |
|
| 544 | + |
|
| 545 | + /** |
|
| 546 | + * Run on activation of the plugin. |
|
| 547 | + * @access public |
|
| 548 | + * @since 1.0.0 |
|
| 549 | + * @return void |
|
| 550 | + */ |
|
| 551 | + public function activate_sensei () { |
|
| 552 | + update_option( 'skip_install_sensei_pages', 0 ); |
|
| 553 | + update_option( 'sensei_installed', 1 ); |
|
| 554 | + } // End activate_sensei() |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Register the plugin's version. |
|
| 558 | + * @access public |
|
| 559 | + * @since 1.0.0 |
|
| 560 | + * @return void |
|
| 561 | + */ |
|
| 562 | + private function register_plugin_version () { |
|
| 563 | + if ( $this->version != '' ) { |
|
| 564 | + |
|
| 565 | + // Check previous version to see if forced updates must run |
|
| 566 | + // $old_version = get_option( 'woothemes-sensei-version', false ); |
|
| 567 | + // if( $old_version && version_compare( $old_version, '1.7.0', '<' ) ) { |
|
| 568 | + // update_option( 'woothemes-sensei-force-updates', $this->version ); |
|
| 569 | + // } else { |
|
| 570 | + // delete_option( 'woothemes-sensei-force-updates' ); |
|
| 571 | + // } |
|
| 572 | + |
|
| 573 | + update_option( 'woothemes-sensei-version', $this->version ); |
|
| 574 | + } |
|
| 575 | + } // End register_plugin_version() |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Ensure that "post-thumbnails" support is available for those themes that don't register it. |
|
| 579 | + * @access public |
|
| 580 | + * @since 1.0.1 |
|
| 581 | + * @return void |
|
| 582 | + */ |
|
| 583 | + public function ensure_post_thumbnails_support () { |
|
| 584 | + if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 585 | + } // End ensure_post_thumbnails_support() |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * template_loader function. |
|
| 590 | + * |
|
| 591 | + * @access public |
|
| 592 | + * @param mixed $template |
|
| 593 | + * @return void |
|
| 594 | + * @deprecated |
|
| 595 | + */ |
|
| 596 | + public function template_loader ( $template = '' ) { |
|
| 597 | + |
|
| 598 | + _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 599 | + Sensei_Templates::template_loader( $template ); |
|
| 600 | + |
|
| 601 | + } // End template_loader() |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * Determine the relative path to the plugin's directory. |
|
| 605 | + * @access public |
|
| 606 | + * @since 1.0.0 |
|
| 607 | + * @return string $sensei_plugin_path |
|
| 608 | + */ |
|
| 609 | + public function plugin_path () { |
|
| 610 | + |
|
| 611 | + if ( $this->plugin_path ) { |
|
| 612 | + |
|
| 613 | + $sensei_plugin_path = $this->plugin_path; |
|
| 614 | + |
|
| 615 | + }else{ |
|
| 616 | + |
|
| 617 | + $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 618 | + |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + return $sensei_plugin_path; |
|
| 622 | + |
|
| 623 | + } // End plugin_path() |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Retrieve the ID of a specified page setting. |
|
| 628 | + * @access public |
|
| 629 | + * @since 1.0.0 |
|
| 630 | + * @param string $page |
|
| 631 | + * @return int |
|
| 632 | + */ |
|
| 633 | + public function get_page_id ( $page ) { |
|
| 634 | + $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 635 | + return ( $page ) ? $page : -1; |
|
| 636 | + } // End get_page_id() |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * If WooCommerce is activated and the customer has purchased the course, update Sensei to indicate that they are taking the course. |
|
| 641 | + * @access public |
|
| 642 | + * @since 1.0.0 |
|
| 643 | + * @param int $course_id (default: 0) |
|
| 644 | + * @param array/Object $order_user (default: array()) Specific user's data. |
|
| 645 | + * @return bool|int |
|
| 646 | + */ |
|
| 647 | + public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 648 | + global $current_user; |
|
| 649 | + |
|
| 650 | + if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
| 651 | + |
|
| 652 | + $data_update = false; |
|
| 653 | + |
|
| 654 | + // Get the product ID |
|
| 655 | + $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 656 | + |
|
| 657 | + // Check if in the admin |
|
| 658 | + if ( is_admin() ) { |
|
| 659 | + $user_login = $order_user['user_login']; |
|
| 660 | + $user_email = $order_user['user_email']; |
|
| 661 | + $user_url = $order_user['user_url']; |
|
| 662 | + $user_id = $order_user['ID']; |
|
| 663 | + } else { |
|
| 664 | + $user_login = $current_user->user_login; |
|
| 665 | + $user_email = $current_user->user_email; |
|
| 666 | + $user_url = $current_user->user_url; |
|
| 667 | + $user_id = $current_user->ID; |
|
| 668 | + } // End If Statement |
|
| 669 | + |
|
| 670 | + // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
|
| 671 | + $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 672 | + if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 673 | + $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 674 | + if ( ! $prereq_course_complete ) { |
|
| 675 | + // Remove all course user meta |
|
| 676 | + return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 681 | + |
|
| 682 | + if( ! $is_user_taking_course ) { |
|
| 683 | + |
|
| 684 | + if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 685 | + |
|
| 686 | + $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 687 | + |
|
| 688 | + $is_user_taking_course = false; |
|
| 689 | + if ( true == $activity_logged ) { |
|
| 690 | + $is_user_taking_course = true; |
|
| 691 | + } // End If Statement |
|
| 692 | + } // End If Statement |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + return $is_user_taking_course; |
|
| 696 | + } // End woocommerce_course_update() |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * check_user_permissions function. |
|
| 701 | + * |
|
| 702 | + * @access public |
|
| 703 | + * @param string $page (default: '') |
|
| 704 | + * |
|
| 705 | + * @return bool |
|
| 706 | + */ |
|
| 707 | + public function check_user_permissions ( $page = '' ) { |
|
| 708 | + // REFACTOR |
|
| 709 | + global $current_user, $post; |
|
| 710 | + |
|
| 711 | + // if use is not logged in |
|
| 712 | + if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){ |
|
| 713 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 714 | + $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 715 | + return false; |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + // Get User Meta |
|
| 720 | + get_currentuserinfo(); |
|
| 721 | + |
|
| 722 | + $user_allowed = false; |
|
| 723 | + |
|
| 724 | + switch ( $page ) { |
|
| 725 | + case 'course-single': |
|
| 726 | + // check for prerequisite course or lesson, |
|
| 727 | + $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 728 | + $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 729 | + // Count completed lessons |
|
| 730 | + if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 731 | + |
|
| 732 | + $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 733 | + |
|
| 734 | + } |
|
| 735 | + else { |
|
| 736 | + $prerequisite_complete = true; |
|
| 737 | + } // End If Statement |
|
| 738 | + // Handles restrictions |
|
| 739 | + if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 740 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 741 | + $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 742 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 743 | + } else { |
|
| 744 | + $user_allowed = true; |
|
| 745 | + } // End If Statement |
|
| 746 | + break; |
|
| 747 | + case 'lesson-single': |
|
| 748 | + // Check for WC purchase |
|
| 749 | + $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 750 | + |
|
| 751 | + $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 752 | + $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 753 | + if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 754 | + $user_allowed = true; |
|
| 755 | + } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 756 | + |
|
| 757 | + $user_allowed = true; |
|
| 758 | + } else { |
|
| 759 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 760 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 761 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 762 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 763 | + if ( $is_preview ) { |
|
| 764 | + $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 765 | + } else { |
|
| 766 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 767 | + } |
|
| 768 | + } else { |
|
| 769 | + if ( $is_preview ) { |
|
| 770 | + $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 ); |
|
| 771 | + } else { |
|
| 772 | + /** This filter is documented in class-woothemes-sensei-frontend.php */ |
|
| 773 | + $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 774 | + } |
|
| 775 | + } // End If Statement |
|
| 776 | + } // End If Statement |
|
| 777 | + break; |
|
| 778 | + case 'quiz-single': |
|
| 779 | + $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 780 | + $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 781 | + |
|
| 782 | + $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 783 | + if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 784 | + |
|
| 785 | + // Check for prerequisite lesson for this quiz |
|
| 786 | + $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 787 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 788 | + |
|
| 789 | + // Handle restrictions |
|
| 790 | + if( sensei_all_access() ) { |
|
| 791 | + $user_allowed = true; |
|
| 792 | + } else { |
|
| 793 | + if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 794 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 795 | + $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 796 | + $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 797 | + } else { |
|
| 798 | + $user_allowed = true; |
|
| 799 | + } // End If Statement |
|
| 800 | + } // End If Statement |
|
| 801 | + } elseif( $this->access_settings() ) { |
|
| 802 | + // Check if the user has started the course |
|
| 803 | + |
|
| 804 | + 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'] ) ) ) { |
|
| 805 | + |
|
| 806 | + $user_allowed = false; |
|
| 807 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 808 | + $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 809 | + $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 810 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 811 | + $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 812 | + } else { |
|
| 813 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 814 | + } // End If Statement |
|
| 815 | + } else { |
|
| 816 | + $user_allowed = true; |
|
| 817 | + } // End If Statement |
|
| 818 | + } else { |
|
| 819 | + $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 820 | + $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>'; |
|
| 821 | + $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 822 | + } // End If Statement |
|
| 823 | + break; |
|
| 824 | + default: |
|
| 825 | + $user_allowed = true; |
|
| 826 | + break; |
|
| 827 | + |
|
| 828 | + } // End Switch Statement |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * filter the permissions message shown on sensei post types. |
|
| 832 | + * |
|
| 833 | + * @since 1.8.7 |
|
| 834 | + * |
|
| 835 | + * @param array $permissions_message{ |
|
| 836 | + * |
|
| 837 | + * @type string $title |
|
| 838 | + * @type string $message |
|
| 839 | + * |
|
| 840 | + * } |
|
| 841 | + * @param string $post_id |
|
| 842 | + */ |
|
| 843 | + $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 847 | + $user_allowed = true; |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 851 | + } // End get_placeholder_image() |
|
| 852 | + |
|
| 853 | + |
|
| 854 | + /** |
|
| 855 | + * Check if visitors have access permission. If the "access_permission" setting is active, do a log in check. |
|
| 856 | + * @since 1.0.0 |
|
| 857 | + * @access public |
|
| 858 | + * @return bool |
|
| 859 | + */ |
|
| 860 | + public function access_settings () { |
|
| 861 | + |
|
| 862 | + if( sensei_all_access() ) return true; |
|
| 863 | + |
|
| 864 | + if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 865 | + if ( is_user_logged_in() ) { |
|
| 866 | + return true; |
|
| 867 | + } else { |
|
| 868 | + return false; |
|
| 869 | + } // End If Statement |
|
| 870 | + } else { |
|
| 871 | + return true; |
|
| 872 | + } // End If Statement |
|
| 873 | + } // End access_settings() |
|
| 874 | + |
|
| 875 | + /** |
|
| 876 | + * sensei_woocommerce_complete_order description |
|
| 877 | + * @since 1.0.3 |
|
| 878 | + * @access public |
|
| 879 | + * @param int $order_id WC order ID |
|
| 880 | + * @return void |
|
| 881 | + */ |
|
| 882 | + public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 883 | + $order_user = array(); |
|
| 884 | + // Check for WooCommerce |
|
| 885 | + if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 886 | + // Get order object |
|
| 887 | + $order = new WC_Order( $order_id ); |
|
| 888 | + $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 889 | + $order_user['ID'] = $user->ID; |
|
| 890 | + $order_user['user_login'] = $user->user_login; |
|
| 891 | + $order_user['user_email'] = $user->user_email; |
|
| 892 | + $order_user['user_url'] = $user->user_url; |
|
| 893 | + // Run through each product ordered |
|
| 894 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 895 | + foreach( $order->get_items() as $item ) { |
|
| 896 | + $product_type = ''; |
|
| 897 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 898 | + $item_id = $item['variation_id']; |
|
| 899 | + $product_type = 'variation'; |
|
| 900 | + } else { |
|
| 901 | + $item_id = $item['product_id']; |
|
| 902 | + } // End If Statement |
|
| 903 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 904 | + // Get courses that use the WC product |
|
| 905 | + $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 906 | + // Loop and update those courses |
|
| 907 | + foreach ( $courses as $course_item ) { |
|
| 908 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 909 | + } // End For Loop |
|
| 910 | + } // End For Loop |
|
| 911 | + } // End If Statement |
|
| 912 | + // Add meta to indicate that payment has been completed successfully |
|
| 913 | + update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 914 | + } // End If Statement |
|
| 915 | + } // End sensei_woocommerce_complete_order() |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Runs when an order is cancelled. |
|
| 919 | + * @since 1.2.0 |
|
| 920 | + * @access public |
|
| 921 | + * @param integer $order_id order ID |
|
| 922 | + * @return void |
|
| 923 | + */ |
|
| 924 | + public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 925 | + |
|
| 926 | + // Get order object |
|
| 927 | + $order = new WC_Order( $order_id ); |
|
| 928 | + |
|
| 929 | + // Run through each product ordered |
|
| 930 | + if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 931 | + |
|
| 932 | + // Get order user |
|
| 933 | + $user_id = $order->__get( 'user_id' ); |
|
| 934 | + |
|
| 935 | + foreach( $order->get_items() as $item ) { |
|
| 936 | + |
|
| 937 | + $product_type = ''; |
|
| 938 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 939 | + $item_id = $item['variation_id']; |
|
| 940 | + $product_type = 'variation'; |
|
| 941 | + } else { |
|
| 942 | + $item_id = $item['product_id']; |
|
| 943 | + } // End If Statement |
|
| 944 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 945 | + |
|
| 946 | + // Get courses that use the WC product |
|
| 947 | + $courses = array(); |
|
| 948 | + $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 949 | + |
|
| 950 | + // Loop and update those courses |
|
| 951 | + foreach ($courses as $course_item){ |
|
| 952 | + // Check and Remove course from courses user meta |
|
| 953 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 954 | + } // End For Loop |
|
| 955 | + } // End For Loop |
|
| 956 | + } // End If Statement |
|
| 957 | + } // End sensei_woocommerce_cancel_order() |
|
| 958 | + |
|
| 959 | + /** |
|
| 960 | + * Runs when an subscription is cancelled or expires. |
|
| 961 | + * @since 1.3.3 |
|
| 962 | + * @access public |
|
| 963 | + * @param integer $user_id User ID |
|
| 964 | + * @param integer $subscription_key Subscription Unique Key |
|
| 965 | + * @return void |
|
| 966 | + */ |
|
| 967 | + public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 968 | + $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 969 | + self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + /** |
|
| 973 | + * Runs when an subscription is re-activated after suspension. |
|
| 974 | + * @since 1.3.3 |
|
| 975 | + * @access public |
|
| 976 | + * @param integer $user_id User ID |
|
| 977 | + * @param integer $subscription_key Subscription Unique Key |
|
| 978 | + * @return void |
|
| 979 | + */ |
|
| 980 | + public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 981 | + $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 982 | + $order = new WC_Order( $subscription['order_id'] ); |
|
| 983 | + $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 984 | + $order_user = array(); |
|
| 985 | + $order_user['ID'] = $user->ID; |
|
| 986 | + $order_user['user_login'] = $user->user_login; |
|
| 987 | + $order_user['user_email'] = $user->user_email; |
|
| 988 | + $order_user['user_url'] = $user->user_url; |
|
| 989 | + $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 990 | + foreach ( $courses as $course_item ){ |
|
| 991 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 992 | + } // End For Loop |
|
| 993 | + } // End sensei_woocommerce_reactivate_subscription |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * Returns the WooCommerce Product Object |
|
| 997 | + * |
|
| 998 | + * The code caters for pre and post WooCommerce 2.2 installations. |
|
| 999 | + * |
|
| 1000 | + * @since 1.1.1 |
|
| 1001 | + * @access public |
|
| 1002 | + * @param integer $wc_product_id Product ID or Variation ID |
|
| 1003 | + * @param string $product_type '' or 'variation' |
|
| 1004 | + * @return WC_Product $wc_product_object |
|
| 1005 | + */ |
|
| 1006 | + public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1007 | + |
|
| 1008 | + $wc_product_object = false; |
|
| 1009 | + if ( 0 < intval( $wc_product_id ) ) { |
|
| 1010 | + |
|
| 1011 | + // Get the product |
|
| 1012 | + if ( function_exists( 'wc_get_product' ) ) { |
|
| 1013 | + |
|
| 1014 | + $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1015 | + |
|
| 1016 | + } elseif ( function_exists( 'get_product' ) ) { |
|
| 1017 | + |
|
| 1018 | + $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1019 | + |
|
| 1020 | + } else { |
|
| 1021 | + |
|
| 1022 | + // Pre WC 2.0 |
|
| 1023 | + if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1024 | + |
|
| 1025 | + $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1026 | + |
|
| 1027 | + } else { |
|
| 1028 | + |
|
| 1029 | + $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1030 | + |
|
| 1031 | + } // End If Statement |
|
| 1032 | + |
|
| 1033 | + } // End If Statement |
|
| 1034 | + |
|
| 1035 | + } // End If Statement |
|
| 1036 | + |
|
| 1037 | + return $wc_product_object; |
|
| 1038 | + |
|
| 1039 | + } // End sensei_get_woocommerce_product_object() |
|
| 1040 | + |
|
| 1041 | + /** |
|
| 1042 | + * load_class loads in class files |
|
| 1043 | + * @since 1.2.0 |
|
| 1044 | + * @access public |
|
| 1045 | + * @return void |
|
| 1046 | + */ |
|
| 1047 | + public function load_class ( $class_name = '' ) { |
|
| 1048 | + if ( '' != $class_name && '' != $this->token ) { |
|
| 1049 | + require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1050 | + } // End If Statement |
|
| 1051 | + } // End load_class() |
|
| 1052 | + |
|
| 1053 | + /** |
|
| 1054 | + * sensei_activate_subscription runs when a subscription product is purchased |
|
| 1055 | + * @since 1.2.0 |
|
| 1056 | + * @access public |
|
| 1057 | + * @param integer $order_id order ID |
|
| 1058 | + * @return void |
|
| 1059 | + */ |
|
| 1060 | + public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1061 | + if ( 0 < intval( $order_id ) ) { |
|
| 1062 | + $order = new WC_Order( $order_id ); |
|
| 1063 | + $user = get_user_by('id', $order->user_id); |
|
| 1064 | + $order_user['ID'] = $user->ID; |
|
| 1065 | + $order_user['user_login'] = $user->user_login; |
|
| 1066 | + $order_user['user_email'] = $user->user_email; |
|
| 1067 | + $order_user['user_url'] = $user->user_url; |
|
| 1068 | + // Run through each product ordered |
|
| 1069 | + if (sizeof($order->get_items())>0) { |
|
| 1070 | + foreach($order->get_items() as $item) { |
|
| 1071 | + $product_type = ''; |
|
| 1072 | + if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
|
| 1073 | + $item_id = $item['variation_id']; |
|
| 1074 | + $product_type = 'subscription_variation'; |
|
| 1075 | + } else { |
|
| 1076 | + $item_id = $item['product_id']; |
|
| 1077 | + } // End If Statement |
|
| 1078 | + $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1079 | + // Get courses that use the WC product |
|
| 1080 | + $courses = array(); |
|
| 1081 | + if ( $product_type == 'subscription_variation' ) { |
|
| 1082 | + $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1083 | + } // End If Statement |
|
| 1084 | + // Loop and update those courses |
|
| 1085 | + foreach ($courses as $course_item){ |
|
| 1086 | + $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1087 | + } // End For Loop |
|
| 1088 | + } // End For Loop |
|
| 1089 | + } // End If Statement |
|
| 1090 | + } // End If Statement |
|
| 1091 | + } // End sensei_activate_subscription() |
|
| 1092 | + |
|
| 1093 | + /** |
|
| 1094 | + * sensei_woocommerce_email_course_details adds detail to email |
|
| 1095 | + * @since 1.4.5 |
|
| 1096 | + * @access public |
|
| 1097 | + * @param WC_Order $order |
|
| 1098 | + * @return void |
|
| 1099 | + */ |
|
| 1100 | + public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1101 | + global $woocommerce; |
|
| 1102 | + |
|
| 1103 | + // exit early if not wc-completed or wc-processing |
|
| 1104 | + if( 'wc-completed' != $order->post_status |
|
| 1105 | + && 'wc-processing' != $order->post_status ) { |
|
| 1106 | + return; |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + $order_items = $order->get_items(); |
|
| 1110 | + $order_id = $order->id; |
|
| 1111 | + |
|
| 1112 | + //If object have items go through them all to find course |
|
| 1113 | + if ( 0 < sizeof( $order_items ) ) { |
|
| 1114 | + |
|
| 1115 | + echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1116 | + |
|
| 1117 | + foreach ( $order_items as $item ) { |
|
| 1118 | + |
|
| 1119 | + $product_type = ''; |
|
| 1120 | + if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1121 | + // If item has variation_id then its from variation |
|
| 1122 | + $item_id = $item['variation_id']; |
|
| 1123 | + $product_type = 'variation'; |
|
| 1124 | + } else { |
|
| 1125 | + // If not its real product set its id to item_id |
|
| 1126 | + $item_id = $item['product_id']; |
|
| 1127 | + } // End If Statement |
|
| 1128 | + |
|
| 1129 | + $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1130 | + |
|
| 1131 | + if( $user_id ) { |
|
| 1132 | + |
|
| 1133 | + // Get all courses for product |
|
| 1134 | + $args = array( |
|
| 1135 | + 'posts_per_page' => -1, |
|
| 1136 | + 'post_type' => 'course', |
|
| 1137 | + 'meta_query' => array( |
|
| 1138 | + array( |
|
| 1139 | + 'key' => '_course_woocommerce_product', |
|
| 1140 | + 'value' => $item_id |
|
| 1141 | + ) |
|
| 1142 | + ), |
|
| 1143 | + 'orderby' => 'menu_order date', |
|
| 1144 | + 'order' => 'ASC', |
|
| 1145 | + ); |
|
| 1146 | + $courses = get_posts( $args ); |
|
| 1147 | + |
|
| 1148 | + if( $courses && count( $courses ) > 0 ) { |
|
| 1149 | + |
|
| 1150 | + foreach( $courses as $course ) { |
|
| 1151 | + |
|
| 1152 | + $title = $course->post_title; |
|
| 1153 | + $permalink = get_permalink( $course->ID ); |
|
| 1154 | + |
|
| 1155 | + echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1156 | + } |
|
| 1157 | + } |
|
| 1158 | + } |
|
| 1159 | + } |
|
| 1160 | + } |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + /** |
|
| 1164 | + * Filtering wp_count_comments to ensure that Sensei comments are ignored |
|
| 1165 | + * @since 1.4.0 |
|
| 1166 | + * @access public |
|
| 1167 | + * @param array $comments |
|
| 1168 | + * @param integer $post_id |
|
| 1169 | + * @return array |
|
| 1170 | + */ |
|
| 1171 | + public function sensei_count_comments( $comments, $post_id ) { |
|
| 1172 | + global $wpdb; |
|
| 1173 | + |
|
| 1174 | + $post_id = (int) $post_id; |
|
| 1175 | + |
|
| 1176 | + $count = wp_cache_get("comments-{$post_id}", 'counts'); |
|
| 1177 | + |
|
| 1178 | + if ( false !== $count ) { |
|
| 1179 | + return $count; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + $statuses = array( '' ); // Default to the WP normal comments |
|
| 1183 | + $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1184 | + foreach ( (array) $stati AS $status ) { |
|
| 1185 | + if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1186 | + $statuses[] = $status['comment_type']; |
|
| 1187 | + } |
|
| 1188 | + } |
|
| 1189 | + $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1190 | + |
|
| 1191 | + if ( $post_id > 0 ) |
|
| 1192 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1193 | + |
|
| 1194 | + $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1195 | + |
|
| 1196 | + $total = 0; |
|
| 1197 | + $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
|
| 1198 | + foreach ( (array) $count as $row ) { |
|
| 1199 | + // Don't count post-trashed toward totals |
|
| 1200 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1201 | + $total += $row['num_comments']; |
|
| 1202 | + if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1203 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + $stats['total_comments'] = $total; |
|
| 1207 | + foreach ( $approved as $key ) { |
|
| 1208 | + if ( empty($stats[$key]) ) |
|
| 1209 | + $stats[$key] = 0; |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + $stats = (object) $stats; |
|
| 1213 | + wp_cache_set("comments-{$post_id}", $stats, 'counts'); |
|
| 1214 | + |
|
| 1215 | + return $stats; |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + /** |
|
| 1219 | + * Init images. |
|
| 1220 | + * |
|
| 1221 | + * @since 1.4.5 |
|
| 1222 | + * @access public |
|
| 1223 | + * @return void |
|
| 1224 | + */ |
|
| 1225 | + public function init_image_sizes() { |
|
| 1226 | + $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1227 | + $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1228 | + $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1229 | + $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1230 | + |
|
| 1231 | + add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1232 | + add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1233 | + add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1234 | + add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + /** |
|
| 1238 | + * Get an image size. |
|
| 1239 | + * |
|
| 1240 | + * Variable is filtered by sensei_get_image_size_{image_size} |
|
| 1241 | + * |
|
| 1242 | + * @since 1.4.5 |
|
| 1243 | + * @access public |
|
| 1244 | + * @param mixed $image_size |
|
| 1245 | + * @return string |
|
| 1246 | + */ |
|
| 1247 | + public function get_image_size( $image_size ) { |
|
| 1248 | + |
|
| 1249 | + // Only return sizes we define in settings |
|
| 1250 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1251 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1252 | + |
|
| 1253 | + if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1254 | + $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1255 | + } |
|
| 1256 | + if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1257 | + $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1258 | + } |
|
| 1259 | + if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1260 | + $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + $size = array_filter( array( |
|
| 1264 | + 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1265 | + 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1266 | + 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1267 | + ) ); |
|
| 1268 | + |
|
| 1269 | + $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1270 | + $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1271 | + $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1272 | + |
|
| 1273 | + return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1274 | + } |
|
| 1275 | + |
|
| 1276 | + public function body_class( $classes ) { |
|
| 1277 | + if( is_sensei() ) { |
|
| 1278 | + $classes[] = 'sensei'; |
|
| 1279 | + } |
|
| 1280 | + return $classes; |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + /** |
|
| 1284 | + * Checks that the Jetpack Beautiful Maths module has been activated to support LaTeX within question titles and answers |
|
| 1285 | + * |
|
| 1286 | + * @return null |
|
| 1287 | + * @since 1.7.0 |
|
| 1288 | + */ |
|
| 1289 | + public function jetpack_latex_support() { |
|
| 1290 | + if ( function_exists( 'latex_markup') ) { |
|
| 1291 | + add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1292 | + add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1293 | + } |
|
| 1294 | + } |
|
| 1295 | + |
|
| 1296 | + /** |
|
| 1297 | + * Load the module functionality. |
|
| 1298 | + * |
|
| 1299 | + * This function is hooked into plugins_loaded to avoid conflicts with |
|
| 1300 | + * the retired modules extension. |
|
| 1301 | + * |
|
| 1302 | + * @since 1.8.0 |
|
| 1303 | + */ |
|
| 1304 | + public function load_modules_class(){ |
|
| 1305 | + global $sensei_modules; |
|
| 1306 | + |
|
| 1307 | + if( !class_exists( 'Sensei_Modules' ) |
|
| 1308 | + && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1309 | + |
|
| 1310 | + //Load the modules class |
|
| 1311 | + require_once( 'class-sensei-modules.php'); |
|
| 1312 | + Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1313 | + |
|
| 1314 | + }else{ |
|
| 1315 | + // fallback for people still using the modules extension. |
|
| 1316 | + global $sensei_modules; |
|
| 1317 | + Sensei()->modules = $sensei_modules; |
|
| 1318 | + add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1319 | + } |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + /** |
|
| 1323 | + * Tell the user to that the modules extension is no longer needed. |
|
| 1324 | + * |
|
| 1325 | + * @since 1.8.0 |
|
| 1326 | + */ |
|
| 1327 | + public function disable_sensei_modules_extension(){ ?> |
|
| 1328 | 1328 | <div class="notice updated fade"> |
| 1329 | 1329 | <p> |
| 1330 | 1330 | <?php |
| 1331 | - $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 1332 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1333 | - ?> |
|
| 1331 | + $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
|
| 1332 | + $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1333 | + ?> |
|
| 1334 | 1334 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
| 1335 | 1335 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
| 1336 | 1336 | </p> |
@@ -1338,46 +1338,46 @@ discard block |
||
| 1338 | 1338 | |
| 1339 | 1339 | <?php }// end function |
| 1340 | 1340 | |
| 1341 | - /** |
|
| 1342 | - * Sensei wide rewrite flush call. |
|
| 1343 | - * |
|
| 1344 | - * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 1345 | - * |
|
| 1346 | - * After the option is one the Rules will be flushed. |
|
| 1347 | - * |
|
| 1348 | - * @since 1.9.0 |
|
| 1349 | - */ |
|
| 1350 | - public function flush_rewrite_rules(){ |
|
| 1341 | + /** |
|
| 1342 | + * Sensei wide rewrite flush call. |
|
| 1343 | + * |
|
| 1344 | + * To use this simply update the option 'sensei_flush_rewrite_rules' to 1 |
|
| 1345 | + * |
|
| 1346 | + * After the option is one the Rules will be flushed. |
|
| 1347 | + * |
|
| 1348 | + * @since 1.9.0 |
|
| 1349 | + */ |
|
| 1350 | + public function flush_rewrite_rules(){ |
|
| 1351 | 1351 | |
| 1352 | - // ensures that the rewrite rules are flushed on the second |
|
| 1353 | - // attempt. This ensure that the settings for any other process |
|
| 1354 | - // have been completed and saved to the database before we refresh the |
|
| 1355 | - // rewrite rules. |
|
| 1356 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1357 | - if( '1' == $option ) { |
|
| 1352 | + // ensures that the rewrite rules are flushed on the second |
|
| 1353 | + // attempt. This ensure that the settings for any other process |
|
| 1354 | + // have been completed and saved to the database before we refresh the |
|
| 1355 | + // rewrite rules. |
|
| 1356 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1357 | + if( '1' == $option ) { |
|
| 1358 | 1358 | |
| 1359 | - update_option('sensei_flush_rewrite_rules', '2'); |
|
| 1359 | + update_option('sensei_flush_rewrite_rules', '2'); |
|
| 1360 | 1360 | |
| 1361 | - }elseif( '2' == $option ) { |
|
| 1361 | + }elseif( '2' == $option ) { |
|
| 1362 | 1362 | |
| 1363 | - flush_rewrite_rules(); |
|
| 1364 | - update_option('sensei_flush_rewrite_rules', '0'); |
|
| 1363 | + flush_rewrite_rules(); |
|
| 1364 | + update_option('sensei_flush_rewrite_rules', '0'); |
|
| 1365 | 1365 | |
| 1366 | - } |
|
| 1366 | + } |
|
| 1367 | 1367 | |
| 1368 | - } // end flush_rewrite_rules |
|
| 1368 | + } // end flush_rewrite_rules |
|
| 1369 | 1369 | |
| 1370 | - /** |
|
| 1371 | - * Calling this function will tell Sensei to flush rewrite |
|
| 1372 | - * rules on the next load. |
|
| 1373 | - * |
|
| 1374 | - * @since 1.9.0 |
|
| 1375 | - */ |
|
| 1376 | - public function initiate_rewrite_rules_flush(){ |
|
| 1370 | + /** |
|
| 1371 | + * Calling this function will tell Sensei to flush rewrite |
|
| 1372 | + * rules on the next load. |
|
| 1373 | + * |
|
| 1374 | + * @since 1.9.0 |
|
| 1375 | + */ |
|
| 1376 | + public function initiate_rewrite_rules_flush(){ |
|
| 1377 | 1377 | |
| 1378 | - update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1378 | + update_option('sensei_flush_rewrite_rules', '1'); |
|
| 1379 | 1379 | |
| 1380 | - } |
|
| 1380 | + } |
|
| 1381 | 1381 | |
| 1382 | 1382 | } // End Class |
| 1383 | 1383 | |
@@ -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 |
@@ -146,23 +146,23 @@ discard block |
||
| 146 | 146 | * @param string $file The base file of the plugin. |
| 147 | 147 | * @since 1.0.0 |
| 148 | 148 | */ |
| 149 | - public function __construct ( $file ) { |
|
| 149 | + public function __construct($file) { |
|
| 150 | 150 | |
| 151 | 151 | // Setup object data |
| 152 | 152 | $this->file = $file; |
| 153 | - $this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) ); |
|
| 154 | - $this->plugin_path = trailingslashit( dirname( $file ) ); |
|
| 155 | - $this->template_url = apply_filters( 'sensei_template_url', 'sensei/' ); |
|
| 156 | - $this->permissions_message = array( 'title' => __( 'Permission Denied', 'woothemes-sensei' ), 'message' => __( 'Unfortunately you do not have permissions to access this page.', 'woothemes-sensei' ) ); |
|
| 153 | + $this->plugin_url = trailingslashit(plugins_url('', $plugin = $file)); |
|
| 154 | + $this->plugin_path = trailingslashit(dirname($file)); |
|
| 155 | + $this->template_url = apply_filters('sensei_template_url', 'sensei/'); |
|
| 156 | + $this->permissions_message = array('title' => __('Permission Denied', 'woothemes-sensei'), 'message' => __('Unfortunately you do not have permissions to access this page.', 'woothemes-sensei')); |
|
| 157 | 157 | |
| 158 | 158 | // Initialize the core Sensei functionality |
| 159 | 159 | $this->init(); |
| 160 | 160 | |
| 161 | 161 | // Installation |
| 162 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 162 | + if (is_admin() && ! defined('DOING_AJAX')) $this->install(); |
|
| 163 | 163 | |
| 164 | 164 | // Run this on activation. |
| 165 | - register_activation_hook( $this->file, array( $this, 'activation' ) ); |
|
| 165 | + register_activation_hook($this->file, array($this, 'activation')); |
|
| 166 | 166 | |
| 167 | 167 | // load the classes need throughout sensei |
| 168 | 168 | $this->initialize_global_objects(); |
@@ -182,11 +182,11 @@ discard block |
||
| 182 | 182 | * Load the foundations of Sensei. |
| 183 | 183 | * @since 1.9.0 |
| 184 | 184 | */ |
| 185 | - protected function init(){ |
|
| 185 | + protected function init() { |
|
| 186 | 186 | |
| 187 | 187 | // Localisation |
| 188 | 188 | $this->load_plugin_textdomain(); |
| 189 | - add_action( 'init', array( $this, 'load_localisation' ), 0 ); |
|
| 189 | + add_action('init', array($this, 'load_localisation'), 0); |
|
| 190 | 190 | |
| 191 | 191 | // load the shortcode loader into memory, so as to listen to all for |
| 192 | 192 | // all shortcodes on the front end |
@@ -206,12 +206,12 @@ discard block |
||
| 206 | 206 | */ |
| 207 | 207 | public static function instance() { |
| 208 | 208 | |
| 209 | - if ( is_null( self::$_instance ) ) { |
|
| 209 | + if (is_null(self::$_instance)) { |
|
| 210 | 210 | |
| 211 | 211 | //Sensei requires a reference to the main Sensei plugin file |
| 212 | - $sensei_main_plugin_file = dirname ( dirname( __FILE__ ) ) . '/woothemes-sensei.php'; |
|
| 212 | + $sensei_main_plugin_file = dirname(dirname(__FILE__)).'/woothemes-sensei.php'; |
|
| 213 | 213 | |
| 214 | - self::$_instance = new self( $sensei_main_plugin_file ); |
|
| 214 | + self::$_instance = new self($sensei_main_plugin_file); |
|
| 215 | 215 | |
| 216 | 216 | } |
| 217 | 217 | |
@@ -227,9 +227,9 @@ discard block |
||
| 227 | 227 | * |
| 228 | 228 | * @param $plugin |
| 229 | 229 | */ |
| 230 | - public static function activation_flush_rules( $plugin ){ |
|
| 230 | + public static function activation_flush_rules($plugin) { |
|
| 231 | 231 | |
| 232 | - if( strpos( $plugin, '/woothemes-sensei.php' ) > 0 ){ |
|
| 232 | + if (strpos($plugin, '/woothemes-sensei.php') > 0) { |
|
| 233 | 233 | |
| 234 | 234 | flush_rewrite_rules(true); |
| 235 | 235 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @since 1.8.0 |
| 243 | 243 | */ |
| 244 | 244 | public function __clone() { |
| 245 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 245 | + _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'woothemes-sensei'), '2.1'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @since 1.8.0 |
| 251 | 251 | */ |
| 252 | 252 | public function __wakeup() { |
| 253 | - _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'woothemes-sensei' ), '2.1' ); |
|
| 253 | + _doing_it_wrong(__FUNCTION__, __('Cheatin’ huh?', 'woothemes-sensei'), '2.1'); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -258,13 +258,13 @@ discard block |
||
| 258 | 258 | * |
| 259 | 259 | * @since 1.9.0 |
| 260 | 260 | */ |
| 261 | - public function initialize_global_objects(){ |
|
| 261 | + public function initialize_global_objects() { |
|
| 262 | 262 | |
| 263 | 263 | // Setup post types. |
| 264 | 264 | $this->post_types = new Sensei_PostTypes(); |
| 265 | 265 | |
| 266 | 266 | // Lad the updates class |
| 267 | - $this->updates = new Sensei_Updates( $this ); |
|
| 267 | + $this->updates = new Sensei_Updates($this); |
|
| 268 | 268 | |
| 269 | 269 | // Setup settings |
| 270 | 270 | $this->settings = new Sensei_Settings(); |
@@ -288,22 +288,22 @@ discard block |
||
| 288 | 288 | $this->quiz = $this->post_types->quiz; |
| 289 | 289 | |
| 290 | 290 | // load the modules class after all plugsin are loaded |
| 291 | - add_action( 'plugins_loaded', array( $this, 'load_modules_class' ) ); |
|
| 291 | + add_action('plugins_loaded', array($this, 'load_modules_class')); |
|
| 292 | 292 | |
| 293 | 293 | // Load Learner Management Functionality |
| 294 | - $this->learners = new Sensei_Learner_Management( $this->file ); |
|
| 294 | + $this->learners = new Sensei_Learner_Management($this->file); |
|
| 295 | 295 | |
| 296 | 296 | // Differentiate between administration and frontend logic. |
| 297 | - if ( is_admin() ) { |
|
| 297 | + if (is_admin()) { |
|
| 298 | 298 | |
| 299 | 299 | // Load Admin Welcome class |
| 300 | 300 | new Sensei_Welcome(); |
| 301 | 301 | |
| 302 | 302 | // Load Admin Class |
| 303 | - $this->admin = new Sensei_Admin( $this->file ); |
|
| 303 | + $this->admin = new Sensei_Admin($this->file); |
|
| 304 | 304 | |
| 305 | 305 | // Load Analysis Reports |
| 306 | - $this->analysis = new Sensei_Analysis( $this->file ); |
|
| 306 | + $this->analysis = new Sensei_Analysis($this->file); |
|
| 307 | 307 | |
| 308 | 308 | } else { |
| 309 | 309 | |
@@ -316,10 +316,10 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Load Grading Functionality |
| 319 | - $this->grading = new Sensei_Grading( $this->file ); |
|
| 319 | + $this->grading = new Sensei_Grading($this->file); |
|
| 320 | 320 | |
| 321 | 321 | // Load Email Class |
| 322 | - $this->emails = new Sensei_Emails( $this->file ); |
|
| 322 | + $this->emails = new Sensei_Emails($this->file); |
|
| 323 | 323 | |
| 324 | 324 | // Load Learner Profiles Class |
| 325 | 325 | $this->learner_profiles = new Sensei_Learner_Profiles(); |
@@ -331,40 +331,40 @@ discard block |
||
| 331 | 331 | * |
| 332 | 332 | * @since 1.9.0 |
| 333 | 333 | */ |
| 334 | - public function load_hooks(){ |
|
| 334 | + public function load_hooks() { |
|
| 335 | 335 | |
| 336 | - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); |
|
| 337 | - add_action( 'after_setup_theme', array( $this, 'ensure_post_thumbnails_support' ) ); |
|
| 336 | + add_action('widgets_init', array($this, 'register_widgets')); |
|
| 337 | + add_action('after_setup_theme', array($this, 'ensure_post_thumbnails_support')); |
|
| 338 | 338 | |
| 339 | 339 | // WooCommerce Payment Actions |
| 340 | - add_action( 'woocommerce_payment_complete' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 341 | - add_action( 'woocommerce_thankyou' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 342 | - add_action( 'woocommerce_order_status_completed' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 343 | - add_action( 'woocommerce_order_status_processing' , array( $this, 'sensei_woocommerce_complete_order' ) ); |
|
| 344 | - add_action( 'woocommerce_order_status_cancelled' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 345 | - add_action( 'woocommerce_order_status_refunded' , array( $this, 'sensei_woocommerce_cancel_order' ) ); |
|
| 346 | - add_action( 'subscriptions_activated_for_order', array( $this, 'sensei_activate_subscription' ) ); |
|
| 340 | + add_action('woocommerce_payment_complete', array($this, 'sensei_woocommerce_complete_order')); |
|
| 341 | + add_action('woocommerce_thankyou', array($this, 'sensei_woocommerce_complete_order')); |
|
| 342 | + add_action('woocommerce_order_status_completed', array($this, 'sensei_woocommerce_complete_order')); |
|
| 343 | + add_action('woocommerce_order_status_processing', array($this, 'sensei_woocommerce_complete_order')); |
|
| 344 | + add_action('woocommerce_order_status_cancelled', array($this, 'sensei_woocommerce_cancel_order')); |
|
| 345 | + add_action('woocommerce_order_status_refunded', array($this, 'sensei_woocommerce_cancel_order')); |
|
| 346 | + add_action('subscriptions_activated_for_order', array($this, 'sensei_activate_subscription')); |
|
| 347 | 347 | |
| 348 | 348 | // WooCommerce Subscriptions Actions |
| 349 | - add_action( 'reactivated_subscription', array( $this, 'sensei_woocommerce_reactivate_subscription' ), 10, 2 ); |
|
| 350 | - add_action( 'subscription_expired' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 351 | - add_action( 'subscription_end_of_prepaid_term' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 352 | - add_action( 'cancelled_subscription' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 353 | - add_action( 'subscription_put_on-hold' , array( $this, 'sensei_woocommerce_subscription_ended' ), 10, 2 ); |
|
| 349 | + add_action('reactivated_subscription', array($this, 'sensei_woocommerce_reactivate_subscription'), 10, 2); |
|
| 350 | + add_action('subscription_expired', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 351 | + add_action('subscription_end_of_prepaid_term', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 352 | + add_action('cancelled_subscription', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 353 | + add_action('subscription_put_on-hold', array($this, 'sensei_woocommerce_subscription_ended'), 10, 2); |
|
| 354 | 354 | |
| 355 | 355 | // Add Email link to course orders |
| 356 | - add_action( 'woocommerce_email_after_order_table', array( $this, 'sensei_woocommerce_email_course_details' ), 10, 1 ); |
|
| 356 | + add_action('woocommerce_email_after_order_table', array($this, 'sensei_woocommerce_email_course_details'), 10, 1); |
|
| 357 | 357 | |
| 358 | 358 | // Filter comment counts |
| 359 | - add_filter( 'wp_count_comments', array( $this, 'sensei_count_comments' ), 10, 2 ); |
|
| 359 | + add_filter('wp_count_comments', array($this, 'sensei_count_comments'), 10, 2); |
|
| 360 | 360 | |
| 361 | - add_action( 'body_class', array( $this, 'body_class' ) ); |
|
| 361 | + add_action('body_class', array($this, 'body_class')); |
|
| 362 | 362 | |
| 363 | 363 | // Check for and activate JetPack LaTeX support |
| 364 | - add_action( 'plugins_loaded', array( $this, 'jetpack_latex_support'), 200 ); // Runs after Jetpack has loaded it's modules |
|
| 364 | + add_action('plugins_loaded', array($this, 'jetpack_latex_support'), 200); // Runs after Jetpack has loaded it's modules |
|
| 365 | 365 | |
| 366 | 366 | // check flush the rewrite rules if the option sensei_flush_rewrite_rules option is 1 |
| 367 | - add_action( 'init', array( $this, 'flush_rewrite_rules'), 101 ); |
|
| 367 | + add_action('init', array($this, 'flush_rewrite_rules'), 101); |
|
| 368 | 368 | |
| 369 | 369 | } |
| 370 | 370 | |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | */ |
| 377 | 377 | public function run_updates() { |
| 378 | 378 | // Run updates if administrator |
| 379 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_sensei' ) ) { |
|
| 379 | + if (current_user_can('manage_options') || current_user_can('manage_sensei')) { |
|
| 380 | 380 | |
| 381 | 381 | $this->updates->update(); |
| 382 | 382 | |
@@ -393,10 +393,10 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | public function set_woocommerce_functionality() { |
| 395 | 395 | // Disable guest checkout if a course is in the cart as we need a valid user to store data for |
| 396 | - add_filter( 'pre_option_woocommerce_enable_guest_checkout', array( $this, 'disable_guest_checkout' ) ); |
|
| 396 | + add_filter('pre_option_woocommerce_enable_guest_checkout', array($this, 'disable_guest_checkout')); |
|
| 397 | 397 | |
| 398 | 398 | // Mark orders with virtual products as complete rather then stay processing |
| 399 | - add_filter( 'woocommerce_payment_complete_order_status', array( $this, 'virtual_order_payment_complete' ), 10, 2 ); |
|
| 399 | + add_filter('woocommerce_payment_complete_order_status', array($this, 'virtual_order_payment_complete'), 10, 2); |
|
| 400 | 400 | |
| 401 | 401 | } // End set_woocommerce_functionality() |
| 402 | 402 | |
@@ -405,14 +405,14 @@ discard block |
||
| 405 | 405 | * @param boolean $guest_checkout Current guest checkout setting |
| 406 | 406 | * @return boolean Modified guest checkout setting |
| 407 | 407 | */ |
| 408 | - public function disable_guest_checkout( $guest_checkout ) { |
|
| 408 | + public function disable_guest_checkout($guest_checkout) { |
|
| 409 | 409 | global $woocommerce; |
| 410 | 410 | |
| 411 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 411 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 412 | 412 | |
| 413 | - if( isset( $woocommerce->cart->cart_contents ) && count( $woocommerce->cart->cart_contents ) > 0 ) { |
|
| 414 | - foreach( $woocommerce->cart->cart_contents as $cart_key => $product ) { |
|
| 415 | - if( isset( $product['product_id'] ) ) { |
|
| 413 | + if (isset($woocommerce->cart->cart_contents) && count($woocommerce->cart->cart_contents) > 0) { |
|
| 414 | + foreach ($woocommerce->cart->cart_contents as $cart_key => $product) { |
|
| 415 | + if (isset($product['product_id'])) { |
|
| 416 | 416 | $args = array( |
| 417 | 417 | 'posts_per_page' => -1, |
| 418 | 418 | 'post_type' => 'course', |
@@ -423,9 +423,9 @@ discard block |
||
| 423 | 423 | ) |
| 424 | 424 | ) |
| 425 | 425 | ); |
| 426 | - $posts = get_posts( $args ); |
|
| 427 | - if( $posts && count( $posts ) > 0 ) { |
|
| 428 | - foreach( $posts as $course ) { |
|
| 426 | + $posts = get_posts($args); |
|
| 427 | + if ($posts && count($posts) > 0) { |
|
| 428 | + foreach ($posts as $course) { |
|
| 429 | 429 | $guest_checkout = ''; |
| 430 | 430 | break; |
| 431 | 431 | } |
@@ -445,17 +445,17 @@ discard block |
||
| 445 | 445 | * @param int $order_id |
| 446 | 446 | * @return string |
| 447 | 447 | **/ |
| 448 | - public function virtual_order_payment_complete( $order_status, $order_id ) { |
|
| 449 | - $order = new WC_Order( $order_id ); |
|
| 450 | - if ( ! isset ( $order ) ) return ''; |
|
| 451 | - if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
|
| 448 | + public function virtual_order_payment_complete($order_status, $order_id) { |
|
| 449 | + $order = new WC_Order($order_id); |
|
| 450 | + if ( ! isset ($order)) return ''; |
|
| 451 | + if ($order_status == 'wc-processing' && ($order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed')) { |
|
| 452 | 452 | $virtual_order = true; |
| 453 | 453 | |
| 454 | - if ( count( $order->get_items() ) > 0 ) { |
|
| 455 | - foreach( $order->get_items() as $item ) { |
|
| 456 | - if ( $item['product_id'] > 0 ) { |
|
| 457 | - $_product = $order->get_product_from_item( $item ); |
|
| 458 | - if ( ! $_product->is_virtual() ) { |
|
| 454 | + if (count($order->get_items()) > 0) { |
|
| 455 | + foreach ($order->get_items() as $item) { |
|
| 456 | + if ($item['product_id'] > 0) { |
|
| 457 | + $_product = $order->get_product_from_item($item); |
|
| 458 | + if ( ! $_product->is_virtual()) { |
|
| 459 | 459 | $virtual_order = false; |
| 460 | 460 | break; |
| 461 | 461 | } // End If Statement |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | } // End If Statement |
| 465 | 465 | |
| 466 | 466 | // virtual order, mark as completed |
| 467 | - if ( $virtual_order ) { |
|
| 467 | + if ($virtual_order) { |
|
| 468 | 468 | return 'completed'; |
| 469 | 469 | } // End If Statement |
| 470 | 470 | } // End If Statement |
@@ -477,21 +477,21 @@ discard block |
||
| 477 | 477 | * @since 1.0.0 |
| 478 | 478 | * @return void |
| 479 | 479 | */ |
| 480 | - public function register_widgets () { |
|
| 480 | + public function register_widgets() { |
|
| 481 | 481 | // Widget List (key => value is filename => widget class). |
| 482 | - $widget_list = apply_filters( 'sensei_registered_widgets_list', array( 'course-component' => 'Course_Component', |
|
| 482 | + $widget_list = apply_filters('sensei_registered_widgets_list', array('course-component' => 'Course_Component', |
|
| 483 | 483 | 'lesson-component' => 'Lesson_Component', |
| 484 | 484 | 'course-categories' => 'Course_Categories', |
| 485 | - 'category-courses' => 'Category_Courses' ) |
|
| 485 | + 'category-courses' => 'Category_Courses') |
|
| 486 | 486 | ); |
| 487 | - foreach ( $widget_list as $key => $value ) { |
|
| 488 | - if ( file_exists( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ) ) { |
|
| 489 | - require_once( $this->plugin_path . 'widgets/widget-woothemes-sensei-' . $key . '.php' ); |
|
| 490 | - register_widget( 'WooThemes_Sensei_' . $value . '_Widget' ); |
|
| 487 | + foreach ($widget_list as $key => $value) { |
|
| 488 | + if (file_exists($this->plugin_path.'widgets/widget-woothemes-sensei-'.$key.'.php')) { |
|
| 489 | + require_once($this->plugin_path.'widgets/widget-woothemes-sensei-'.$key.'.php'); |
|
| 490 | + register_widget('WooThemes_Sensei_'.$value.'_Widget'); |
|
| 491 | 491 | } |
| 492 | 492 | } // End For Loop |
| 493 | 493 | |
| 494 | - do_action( 'sensei_register_widgets' ); |
|
| 494 | + do_action('sensei_register_widgets'); |
|
| 495 | 495 | |
| 496 | 496 | } // End register_widgets() |
| 497 | 497 | |
@@ -501,8 +501,8 @@ discard block |
||
| 501 | 501 | * @since 1.0.0 |
| 502 | 502 | * @return void |
| 503 | 503 | */ |
| 504 | - public function load_localisation () { |
|
| 505 | - load_plugin_textdomain( 'woothemes-sensei', false, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 504 | + public function load_localisation() { |
|
| 505 | + load_plugin_textdomain('woothemes-sensei', false, dirname(plugin_basename($this->file)).'/lang/'); |
|
| 506 | 506 | } // End load_localisation() |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -511,12 +511,12 @@ discard block |
||
| 511 | 511 | * @since 1.0.0 |
| 512 | 512 | * @return void |
| 513 | 513 | */ |
| 514 | - public function load_plugin_textdomain () { |
|
| 514 | + public function load_plugin_textdomain() { |
|
| 515 | 515 | $domain = 'woothemes-sensei'; |
| 516 | 516 | // The "plugin_locale" filter is also used in load_plugin_textdomain() |
| 517 | - $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); |
|
| 518 | - load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); |
|
| 519 | - load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( $this->file ) ) . '/lang/' ); |
|
| 517 | + $locale = apply_filters('plugin_locale', get_locale(), $domain); |
|
| 518 | + load_textdomain($domain, WP_LANG_DIR.'/'.$domain.'/'.$domain.'-'.$locale.'.mo'); |
|
| 519 | + load_plugin_textdomain($domain, FALSE, dirname(plugin_basename($this->file)).'/lang/'); |
|
| 520 | 520 | } // End load_plugin_textdomain() |
| 521 | 521 | |
| 522 | 522 | /** |
@@ -525,7 +525,7 @@ discard block |
||
| 525 | 525 | * @since 1.0.0 |
| 526 | 526 | * @return void |
| 527 | 527 | */ |
| 528 | - public function activation () { |
|
| 528 | + public function activation() { |
|
| 529 | 529 | $this->register_plugin_version(); |
| 530 | 530 | } // End activation() |
| 531 | 531 | |
@@ -536,9 +536,9 @@ discard block |
||
| 536 | 536 | * @since 1.0.0 |
| 537 | 537 | * @return void |
| 538 | 538 | */ |
| 539 | - public function install () { |
|
| 540 | - register_activation_hook( $this->file, array( $this, 'activate_sensei' ) ); |
|
| 541 | - register_activation_hook( $this->file, 'flush_rewrite_rules' ); |
|
| 539 | + public function install() { |
|
| 540 | + register_activation_hook($this->file, array($this, 'activate_sensei')); |
|
| 541 | + register_activation_hook($this->file, 'flush_rewrite_rules'); |
|
| 542 | 542 | } // End install() |
| 543 | 543 | |
| 544 | 544 | |
@@ -548,9 +548,9 @@ discard block |
||
| 548 | 548 | * @since 1.0.0 |
| 549 | 549 | * @return void |
| 550 | 550 | */ |
| 551 | - public function activate_sensei () { |
|
| 552 | - update_option( 'skip_install_sensei_pages', 0 ); |
|
| 553 | - update_option( 'sensei_installed', 1 ); |
|
| 551 | + public function activate_sensei() { |
|
| 552 | + update_option('skip_install_sensei_pages', 0); |
|
| 553 | + update_option('sensei_installed', 1); |
|
| 554 | 554 | } // End activate_sensei() |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -559,8 +559,8 @@ discard block |
||
| 559 | 559 | * @since 1.0.0 |
| 560 | 560 | * @return void |
| 561 | 561 | */ |
| 562 | - private function register_plugin_version () { |
|
| 563 | - if ( $this->version != '' ) { |
|
| 562 | + private function register_plugin_version() { |
|
| 563 | + if ($this->version != '') { |
|
| 564 | 564 | |
| 565 | 565 | // Check previous version to see if forced updates must run |
| 566 | 566 | // $old_version = get_option( 'woothemes-sensei-version', false ); |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | // delete_option( 'woothemes-sensei-force-updates' ); |
| 571 | 571 | // } |
| 572 | 572 | |
| 573 | - update_option( 'woothemes-sensei-version', $this->version ); |
|
| 573 | + update_option('woothemes-sensei-version', $this->version); |
|
| 574 | 574 | } |
| 575 | 575 | } // End register_plugin_version() |
| 576 | 576 | |
@@ -580,8 +580,8 @@ discard block |
||
| 580 | 580 | * @since 1.0.1 |
| 581 | 581 | * @return void |
| 582 | 582 | */ |
| 583 | - public function ensure_post_thumbnails_support () { |
|
| 584 | - if ( ! current_theme_supports( 'post-thumbnails' ) ) { add_theme_support( 'post-thumbnails' ); } |
|
| 583 | + public function ensure_post_thumbnails_support() { |
|
| 584 | + if ( ! current_theme_supports('post-thumbnails')) { add_theme_support('post-thumbnails'); } |
|
| 585 | 585 | } // End ensure_post_thumbnails_support() |
| 586 | 586 | |
| 587 | 587 | |
@@ -593,10 +593,10 @@ discard block |
||
| 593 | 593 | * @return void |
| 594 | 594 | * @deprecated |
| 595 | 595 | */ |
| 596 | - public function template_loader ( $template = '' ) { |
|
| 596 | + public function template_loader($template = '') { |
|
| 597 | 597 | |
| 598 | - _deprecated_function( 'Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead' ); |
|
| 599 | - Sensei_Templates::template_loader( $template ); |
|
| 598 | + _deprecated_function('Sensei()->template_loader', '1.9.0', 'Use Sensei_Templates::template_loader( $template ) instead'); |
|
| 599 | + Sensei_Templates::template_loader($template); |
|
| 600 | 600 | |
| 601 | 601 | } // End template_loader() |
| 602 | 602 | |
@@ -606,15 +606,15 @@ discard block |
||
| 606 | 606 | * @since 1.0.0 |
| 607 | 607 | * @return string $sensei_plugin_path |
| 608 | 608 | */ |
| 609 | - public function plugin_path () { |
|
| 609 | + public function plugin_path() { |
|
| 610 | 610 | |
| 611 | - if ( $this->plugin_path ) { |
|
| 611 | + if ($this->plugin_path) { |
|
| 612 | 612 | |
| 613 | - $sensei_plugin_path = $this->plugin_path; |
|
| 613 | + $sensei_plugin_path = $this->plugin_path; |
|
| 614 | 614 | |
| 615 | - }else{ |
|
| 615 | + } else { |
|
| 616 | 616 | |
| 617 | - $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
|
| 617 | + $sensei_plugin_path = plugin_dir_path(__FILE__); |
|
| 618 | 618 | |
| 619 | 619 | } |
| 620 | 620 | |
@@ -630,9 +630,9 @@ discard block |
||
| 630 | 630 | * @param string $page |
| 631 | 631 | * @return int |
| 632 | 632 | */ |
| 633 | - public function get_page_id ( $page ) { |
|
| 634 | - $page = apply_filters( 'sensei_get_' . esc_attr( $page ) . '_page_id', get_option( 'sensei_' . esc_attr( $page ) . '_page_id' ) ); |
|
| 635 | - return ( $page ) ? $page : -1; |
|
| 633 | + public function get_page_id($page) { |
|
| 634 | + $page = apply_filters('sensei_get_'.esc_attr($page).'_page_id', get_option('sensei_'.esc_attr($page).'_page_id')); |
|
| 635 | + return ($page) ? $page : -1; |
|
| 636 | 636 | } // End get_page_id() |
| 637 | 637 | |
| 638 | 638 | |
@@ -644,18 +644,18 @@ discard block |
||
| 644 | 644 | * @param array/Object $order_user (default: array()) Specific user's data. |
| 645 | 645 | * @return bool|int |
| 646 | 646 | */ |
| 647 | - public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
|
| 647 | + public function woocommerce_course_update($course_id = 0, $order_user = array()) { |
|
| 648 | 648 | global $current_user; |
| 649 | 649 | |
| 650 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
| 650 | + if ( ! isset($current_user) || ! $current_user->ID > 0) return false; |
|
| 651 | 651 | |
| 652 | 652 | $data_update = false; |
| 653 | 653 | |
| 654 | 654 | // Get the product ID |
| 655 | - $wc_post_id = get_post_meta( intval( $course_id ), '_course_woocommerce_product', true ); |
|
| 655 | + $wc_post_id = get_post_meta(intval($course_id), '_course_woocommerce_product', true); |
|
| 656 | 656 | |
| 657 | 657 | // Check if in the admin |
| 658 | - if ( is_admin() ) { |
|
| 658 | + if (is_admin()) { |
|
| 659 | 659 | $user_login = $order_user['user_login']; |
| 660 | 660 | $user_email = $order_user['user_email']; |
| 661 | 661 | $user_url = $order_user['user_url']; |
@@ -668,25 +668,25 @@ discard block |
||
| 668 | 668 | } // End If Statement |
| 669 | 669 | |
| 670 | 670 | // This doesn't appear to be purely WooCommerce related. Should it be in a separate function? |
| 671 | - $course_prerequisite_id = (int) get_post_meta( $course_id, '_course_prerequisite', true ); |
|
| 672 | - if( 0 < absint( $course_prerequisite_id ) ) { |
|
| 673 | - $prereq_course_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, intval( $user_id ) ); |
|
| 674 | - if ( ! $prereq_course_complete ) { |
|
| 671 | + $course_prerequisite_id = (int) get_post_meta($course_id, '_course_prerequisite', true); |
|
| 672 | + if (0 < absint($course_prerequisite_id)) { |
|
| 673 | + $prereq_course_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, intval($user_id)); |
|
| 674 | + if ( ! $prereq_course_complete) { |
|
| 675 | 675 | // Remove all course user meta |
| 676 | - return Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 676 | + return Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id); |
|
| 677 | 677 | } |
| 678 | 678 | } |
| 679 | 679 | |
| 680 | - $is_user_taking_course = Sensei_Utils::user_started_course( intval( $course_id ), intval( $user_id ) ); |
|
| 680 | + $is_user_taking_course = Sensei_Utils::user_started_course(intval($course_id), intval($user_id)); |
|
| 681 | 681 | |
| 682 | - if( ! $is_user_taking_course ) { |
|
| 682 | + if ( ! $is_user_taking_course) { |
|
| 683 | 683 | |
| 684 | - if ( Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product( $user_email, $user_id, $wc_post_id ) && ( 0 < $wc_post_id ) ) { |
|
| 684 | + if (Sensei_WC::is_woocommerce_active() && Sensei_Utils::sensei_customer_bought_product($user_email, $user_id, $wc_post_id) && (0 < $wc_post_id)) { |
|
| 685 | 685 | |
| 686 | - $activity_logged = Sensei_Utils::user_start_course( intval( $user_id), intval( $course_id ) ); |
|
| 686 | + $activity_logged = Sensei_Utils::user_start_course(intval($user_id), intval($course_id)); |
|
| 687 | 687 | |
| 688 | 688 | $is_user_taking_course = false; |
| 689 | - if ( true == $activity_logged ) { |
|
| 689 | + if (true == $activity_logged) { |
|
| 690 | 690 | $is_user_taking_course = true; |
| 691 | 691 | } // End If Statement |
| 692 | 692 | } // End If Statement |
@@ -704,14 +704,14 @@ discard block |
||
| 704 | 704 | * |
| 705 | 705 | * @return bool |
| 706 | 706 | */ |
| 707 | - public function check_user_permissions ( $page = '' ) { |
|
| 707 | + public function check_user_permissions($page = '') { |
|
| 708 | 708 | // REFACTOR |
| 709 | 709 | global $current_user, $post; |
| 710 | 710 | |
| 711 | 711 | // if use is not logged in |
| 712 | - if ( empty( $current_user->caps ) && Sensei()->settings->get('access_permission') ){ |
|
| 713 | - $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei' ); |
|
| 714 | - $this->permissions_message['message'] = sprintf( __('You must be logged in to view this %s'), get_post_type() ); |
|
| 712 | + if (empty($current_user->caps) && Sensei()->settings->get('access_permission')) { |
|
| 713 | + $this->permissions_message['title'] = __('Restricted Access', 'woothemes-sensei'); |
|
| 714 | + $this->permissions_message['message'] = sprintf(__('You must be logged in to view this %s'), get_post_type()); |
|
| 715 | 715 | return false; |
| 716 | 716 | } |
| 717 | 717 | |
@@ -721,104 +721,104 @@ discard block |
||
| 721 | 721 | |
| 722 | 722 | $user_allowed = false; |
| 723 | 723 | |
| 724 | - switch ( $page ) { |
|
| 724 | + switch ($page) { |
|
| 725 | 725 | case 'course-single': |
| 726 | 726 | // check for prerequisite course or lesson, |
| 727 | - $course_prerequisite_id = (int) get_post_meta( $post->ID, '_course_prerequisite', true); |
|
| 728 | - $update_course = $this->woocommerce_course_update( $post->ID ); |
|
| 727 | + $course_prerequisite_id = (int) get_post_meta($post->ID, '_course_prerequisite', true); |
|
| 728 | + $update_course = $this->woocommerce_course_update($post->ID); |
|
| 729 | 729 | // Count completed lessons |
| 730 | - if ( 0 < absint( $course_prerequisite_id ) ) { |
|
| 730 | + if (0 < absint($course_prerequisite_id)) { |
|
| 731 | 731 | |
| 732 | - $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
|
| 732 | + $prerequisite_complete = Sensei_Utils::user_completed_course($course_prerequisite_id, $current_user->ID); |
|
| 733 | 733 | |
| 734 | 734 | } |
| 735 | 735 | else { |
| 736 | 736 | $prerequisite_complete = true; |
| 737 | 737 | } // End If Statement |
| 738 | 738 | // Handles restrictions |
| 739 | - if ( !$prerequisite_complete && 0 < absint( $course_prerequisite_id ) ) { |
|
| 740 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 741 | - $course_link = '<a href="' . esc_url( get_permalink( $course_prerequisite_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 742 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this course.', 'woothemes-sensei' ), $course_link ); |
|
| 739 | + if ( ! $prerequisite_complete && 0 < absint($course_prerequisite_id)) { |
|
| 740 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 741 | + $course_link = '<a href="'.esc_url(get_permalink($course_prerequisite_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 742 | + $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this course.', 'woothemes-sensei'), $course_link); |
|
| 743 | 743 | } else { |
| 744 | 744 | $user_allowed = true; |
| 745 | 745 | } // End If Statement |
| 746 | 746 | break; |
| 747 | 747 | case 'lesson-single': |
| 748 | 748 | // Check for WC purchase |
| 749 | - $lesson_course_id = get_post_meta( $post->ID, '_lesson_course',true ); |
|
| 749 | + $lesson_course_id = get_post_meta($post->ID, '_lesson_course', true); |
|
| 750 | 750 | |
| 751 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 752 | - $is_preview = Sensei_Utils::is_preview_lesson( $post->ID ); |
|
| 753 | - if ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) { |
|
| 751 | + $update_course = $this->woocommerce_course_update($lesson_course_id); |
|
| 752 | + $is_preview = Sensei_Utils::is_preview_lesson($post->ID); |
|
| 753 | + if ($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) { |
|
| 754 | 754 | $user_allowed = true; |
| 755 | - } elseif( $this->access_settings() && false == $is_preview ) { |
|
| 755 | + } elseif ($this->access_settings() && false == $is_preview) { |
|
| 756 | 756 | |
| 757 | 757 | $user_allowed = true; |
| 758 | 758 | } else { |
| 759 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 760 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 761 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 762 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 763 | - if ( $is_preview ) { |
|
| 764 | - $this->permissions_message['message'] = sprintf( __('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei' ), $course_link ); |
|
| 759 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 760 | + $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 761 | + $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true); |
|
| 762 | + if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) { |
|
| 763 | + if ($is_preview) { |
|
| 764 | + $this->permissions_message['message'] = sprintf(__('This is a preview lesson. Please purchase the %1$s to access all lessons.', 'woothemes-sensei'), $course_link); |
|
| 765 | 765 | } else { |
| 766 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 766 | + $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Lesson.', 'woothemes-sensei'), $course_link); |
|
| 767 | 767 | } |
| 768 | 768 | } else { |
| 769 | - if ( $is_preview ) { |
|
| 770 | - $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 ); |
|
| 769 | + if ($is_preview) { |
|
| 770 | + $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); |
|
| 771 | 771 | } else { |
| 772 | 772 | /** This filter is documented in class-woothemes-sensei-frontend.php */ |
| 773 | - $this->permissions_message['message'] = sprintf( __( 'Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei' ), $course_link ); |
|
| 773 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting the lesson.', 'woothemes-sensei'), $course_link); |
|
| 774 | 774 | } |
| 775 | 775 | } // End If Statement |
| 776 | 776 | } // End If Statement |
| 777 | 777 | break; |
| 778 | 778 | case 'quiz-single': |
| 779 | - $lesson_id = get_post_meta( $post->ID, '_quiz_lesson',true ); |
|
| 780 | - $lesson_course_id = get_post_meta( $lesson_id, '_lesson_course',true ); |
|
| 779 | + $lesson_id = get_post_meta($post->ID, '_quiz_lesson', true); |
|
| 780 | + $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true); |
|
| 781 | 781 | |
| 782 | - $update_course = $this->woocommerce_course_update( $lesson_course_id ); |
|
| 783 | - if ( ( $this->access_settings() && Sensei_Utils::user_started_course( $lesson_course_id, $current_user->ID ) ) || sensei_all_access() ) { |
|
| 782 | + $update_course = $this->woocommerce_course_update($lesson_course_id); |
|
| 783 | + if (($this->access_settings() && Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID)) || sensei_all_access()) { |
|
| 784 | 784 | |
| 785 | 785 | // Check for prerequisite lesson for this quiz |
| 786 | - $lesson_prerequisite_id = (int) get_post_meta( $lesson_id, '_lesson_prerequisite', true); |
|
| 787 | - $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson( $lesson_prerequisite_id, $current_user->ID); |
|
| 786 | + $lesson_prerequisite_id = (int) get_post_meta($lesson_id, '_lesson_prerequisite', true); |
|
| 787 | + $user_lesson_prerequisite_complete = Sensei_Utils::user_completed_lesson($lesson_prerequisite_id, $current_user->ID); |
|
| 788 | 788 | |
| 789 | 789 | // Handle restrictions |
| 790 | - if( sensei_all_access() ) { |
|
| 790 | + if (sensei_all_access()) { |
|
| 791 | 791 | $user_allowed = true; |
| 792 | 792 | } else { |
| 793 | - if ( 0 < absint( $lesson_prerequisite_id ) && ( !$user_lesson_prerequisite_complete ) ) { |
|
| 794 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 795 | - $lesson_link = '<a href="' . esc_url( get_permalink( $lesson_prerequisite_id ) ) . '">' . __( 'lesson', 'woothemes-sensei' ) . '</a>'; |
|
| 796 | - $this->permissions_message['message'] = sprintf( __('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei' ), $lesson_link ); |
|
| 793 | + if (0 < absint($lesson_prerequisite_id) && ( ! $user_lesson_prerequisite_complete)) { |
|
| 794 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 795 | + $lesson_link = '<a href="'.esc_url(get_permalink($lesson_prerequisite_id)).'">'.__('lesson', 'woothemes-sensei').'</a>'; |
|
| 796 | + $this->permissions_message['message'] = sprintf(__('Please complete the previous %1$s before taking this Quiz.', 'woothemes-sensei'), $lesson_link); |
|
| 797 | 797 | } else { |
| 798 | 798 | $user_allowed = true; |
| 799 | 799 | } // End If Statement |
| 800 | 800 | } // End If Statement |
| 801 | - } elseif( $this->access_settings() ) { |
|
| 801 | + } elseif ($this->access_settings()) { |
|
| 802 | 802 | // Check if the user has started the course |
| 803 | 803 | |
| 804 | - 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'] ) ) ) { |
|
| 804 | + 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']))) { |
|
| 805 | 805 | |
| 806 | 806 | $user_allowed = false; |
| 807 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 808 | - $course_link = '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '">' . __( 'course', 'woothemes-sensei' ) . '</a>'; |
|
| 809 | - $wc_post_id = get_post_meta( $lesson_course_id, '_course_woocommerce_product',true ); |
|
| 810 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $wc_post_id ) ) { |
|
| 811 | - $this->permissions_message['message'] = sprintf( __('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 807 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 808 | + $course_link = '<a href="'.esc_url(get_permalink($lesson_course_id)).'">'.__('course', 'woothemes-sensei').'</a>'; |
|
| 809 | + $wc_post_id = get_post_meta($lesson_course_id, '_course_woocommerce_product', true); |
|
| 810 | + if (Sensei_WC::is_woocommerce_active() && (0 < $wc_post_id)) { |
|
| 811 | + $this->permissions_message['message'] = sprintf(__('Please purchase the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link); |
|
| 812 | 812 | } else { |
| 813 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 813 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before starting this Quiz.', 'woothemes-sensei'), $course_link); |
|
| 814 | 814 | } // End If Statement |
| 815 | 815 | } else { |
| 816 | 816 | $user_allowed = true; |
| 817 | 817 | } // End If Statement |
| 818 | 818 | } else { |
| 819 | - $this->permissions_message['title'] = get_the_title( $post->ID ) . ': ' . __('Restricted Access', 'woothemes-sensei' ); |
|
| 820 | - $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>'; |
|
| 821 | - $this->permissions_message['message'] = sprintf( __('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei' ), $course_link ); |
|
| 819 | + $this->permissions_message['title'] = get_the_title($post->ID).': '.__('Restricted Access', 'woothemes-sensei'); |
|
| 820 | + $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>'; |
|
| 821 | + $this->permissions_message['message'] = sprintf(__('Please sign up for the %1$s before taking this Quiz.', 'woothemes-sensei'), $course_link); |
|
| 822 | 822 | } // End If Statement |
| 823 | 823 | break; |
| 824 | 824 | default: |
@@ -840,14 +840,14 @@ discard block |
||
| 840 | 840 | * } |
| 841 | 841 | * @param string $post_id |
| 842 | 842 | */ |
| 843 | - $this->permissions_message = apply_filters( 'sensei_permissions_message', $this->permissions_message, $post->ID ); |
|
| 843 | + $this->permissions_message = apply_filters('sensei_permissions_message', $this->permissions_message, $post->ID); |
|
| 844 | 844 | |
| 845 | 845 | |
| 846 | - if( sensei_all_access() || Sensei_Utils::is_preview_lesson( $post->ID ) ) { |
|
| 846 | + if (sensei_all_access() || Sensei_Utils::is_preview_lesson($post->ID)) { |
|
| 847 | 847 | $user_allowed = true; |
| 848 | 848 | } |
| 849 | 849 | |
| 850 | - return apply_filters( 'sensei_access_permissions', $user_allowed ); |
|
| 850 | + return apply_filters('sensei_access_permissions', $user_allowed); |
|
| 851 | 851 | } // End get_placeholder_image() |
| 852 | 852 | |
| 853 | 853 | |
@@ -857,12 +857,12 @@ discard block |
||
| 857 | 857 | * @access public |
| 858 | 858 | * @return bool |
| 859 | 859 | */ |
| 860 | - public function access_settings () { |
|
| 860 | + public function access_settings() { |
|
| 861 | 861 | |
| 862 | - if( sensei_all_access() ) return true; |
|
| 862 | + if (sensei_all_access()) return true; |
|
| 863 | 863 | |
| 864 | - if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
|
| 865 | - if ( is_user_logged_in() ) { |
|
| 864 | + if (isset($this->settings->settings['access_permission']) && (true == $this->settings->settings['access_permission'])) { |
|
| 865 | + if (is_user_logged_in()) { |
|
| 866 | 866 | return true; |
| 867 | 867 | } else { |
| 868 | 868 | return false; |
@@ -879,38 +879,38 @@ discard block |
||
| 879 | 879 | * @param int $order_id WC order ID |
| 880 | 880 | * @return void |
| 881 | 881 | */ |
| 882 | - public function sensei_woocommerce_complete_order ( $order_id = 0 ) { |
|
| 882 | + public function sensei_woocommerce_complete_order($order_id = 0) { |
|
| 883 | 883 | $order_user = array(); |
| 884 | 884 | // Check for WooCommerce |
| 885 | - if ( Sensei_WC::is_woocommerce_active() && ( 0 < $order_id ) ) { |
|
| 885 | + if (Sensei_WC::is_woocommerce_active() && (0 < $order_id)) { |
|
| 886 | 886 | // Get order object |
| 887 | - $order = new WC_Order( $order_id ); |
|
| 888 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 887 | + $order = new WC_Order($order_id); |
|
| 888 | + $user = get_user_by('id', $order->get_user_id()); |
|
| 889 | 889 | $order_user['ID'] = $user->ID; |
| 890 | 890 | $order_user['user_login'] = $user->user_login; |
| 891 | 891 | $order_user['user_email'] = $user->user_email; |
| 892 | 892 | $order_user['user_url'] = $user->user_url; |
| 893 | 893 | // Run through each product ordered |
| 894 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 895 | - foreach( $order->get_items() as $item ) { |
|
| 894 | + if (0 < sizeof($order->get_items())) { |
|
| 895 | + foreach ($order->get_items() as $item) { |
|
| 896 | 896 | $product_type = ''; |
| 897 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 897 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 898 | 898 | $item_id = $item['variation_id']; |
| 899 | 899 | $product_type = 'variation'; |
| 900 | 900 | } else { |
| 901 | 901 | $item_id = $item['product_id']; |
| 902 | 902 | } // End If Statement |
| 903 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 903 | + $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); |
|
| 904 | 904 | // Get courses that use the WC product |
| 905 | - $courses = $this->post_types->course->get_product_courses( $_product->id ); |
|
| 905 | + $courses = $this->post_types->course->get_product_courses($_product->id); |
|
| 906 | 906 | // Loop and update those courses |
| 907 | - foreach ( $courses as $course_item ) { |
|
| 908 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 907 | + foreach ($courses as $course_item) { |
|
| 908 | + $update_course = $this->woocommerce_course_update($course_item->ID, $order_user); |
|
| 909 | 909 | } // End For Loop |
| 910 | 910 | } // End For Loop |
| 911 | 911 | } // End If Statement |
| 912 | 912 | // Add meta to indicate that payment has been completed successfully |
| 913 | - update_post_meta( $order_id, 'sensei_payment_complete', '1' ); |
|
| 913 | + update_post_meta($order_id, 'sensei_payment_complete', '1'); |
|
| 914 | 914 | } // End If Statement |
| 915 | 915 | } // End sensei_woocommerce_complete_order() |
| 916 | 916 | |
@@ -921,36 +921,36 @@ discard block |
||
| 921 | 921 | * @param integer $order_id order ID |
| 922 | 922 | * @return void |
| 923 | 923 | */ |
| 924 | - public function sensei_woocommerce_cancel_order ( $order_id ) { |
|
| 924 | + public function sensei_woocommerce_cancel_order($order_id) { |
|
| 925 | 925 | |
| 926 | 926 | // Get order object |
| 927 | - $order = new WC_Order( $order_id ); |
|
| 927 | + $order = new WC_Order($order_id); |
|
| 928 | 928 | |
| 929 | 929 | // Run through each product ordered |
| 930 | - if ( 0 < sizeof( $order->get_items() ) ) { |
|
| 930 | + if (0 < sizeof($order->get_items())) { |
|
| 931 | 931 | |
| 932 | 932 | // Get order user |
| 933 | - $user_id = $order->__get( 'user_id' ); |
|
| 933 | + $user_id = $order->__get('user_id'); |
|
| 934 | 934 | |
| 935 | - foreach( $order->get_items() as $item ) { |
|
| 935 | + foreach ($order->get_items() as $item) { |
|
| 936 | 936 | |
| 937 | 937 | $product_type = ''; |
| 938 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 938 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 939 | 939 | $item_id = $item['variation_id']; |
| 940 | 940 | $product_type = 'variation'; |
| 941 | 941 | } else { |
| 942 | 942 | $item_id = $item['product_id']; |
| 943 | 943 | } // End If Statement |
| 944 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 944 | + $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); |
|
| 945 | 945 | |
| 946 | 946 | // Get courses that use the WC product |
| 947 | 947 | $courses = array(); |
| 948 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 948 | + $courses = $this->post_types->course->get_product_courses($item_id); |
|
| 949 | 949 | |
| 950 | 950 | // Loop and update those courses |
| 951 | - foreach ($courses as $course_item){ |
|
| 951 | + foreach ($courses as $course_item) { |
|
| 952 | 952 | // Check and Remove course from courses user meta |
| 953 | - $dataset_changes = Sensei_Utils::sensei_remove_user_from_course( $course_item->ID, $user_id ); |
|
| 953 | + $dataset_changes = Sensei_Utils::sensei_remove_user_from_course($course_item->ID, $user_id); |
|
| 954 | 954 | } // End For Loop |
| 955 | 955 | } // End For Loop |
| 956 | 956 | } // End If Statement |
@@ -964,9 +964,9 @@ discard block |
||
| 964 | 964 | * @param integer $subscription_key Subscription Unique Key |
| 965 | 965 | * @return void |
| 966 | 966 | */ |
| 967 | - public function sensei_woocommerce_subscription_ended( $user_id, $subscription_key ) { |
|
| 968 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 969 | - self::sensei_woocommerce_cancel_order( $subscription['order_id'] ); |
|
| 967 | + public function sensei_woocommerce_subscription_ended($user_id, $subscription_key) { |
|
| 968 | + $subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key); |
|
| 969 | + self::sensei_woocommerce_cancel_order($subscription['order_id']); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
@@ -977,18 +977,18 @@ discard block |
||
| 977 | 977 | * @param integer $subscription_key Subscription Unique Key |
| 978 | 978 | * @return void |
| 979 | 979 | */ |
| 980 | - public function sensei_woocommerce_reactivate_subscription( $user_id, $subscription_key ) { |
|
| 981 | - $subscription = WC_Subscriptions_Manager::get_users_subscription( $user_id, $subscription_key ); |
|
| 982 | - $order = new WC_Order( $subscription['order_id'] ); |
|
| 983 | - $user = get_user_by( 'id', $order->get_user_id() ); |
|
| 980 | + public function sensei_woocommerce_reactivate_subscription($user_id, $subscription_key) { |
|
| 981 | + $subscription = WC_Subscriptions_Manager::get_users_subscription($user_id, $subscription_key); |
|
| 982 | + $order = new WC_Order($subscription['order_id']); |
|
| 983 | + $user = get_user_by('id', $order->get_user_id()); |
|
| 984 | 984 | $order_user = array(); |
| 985 | 985 | $order_user['ID'] = $user->ID; |
| 986 | 986 | $order_user['user_login'] = $user->user_login; |
| 987 | 987 | $order_user['user_email'] = $user->user_email; |
| 988 | 988 | $order_user['user_url'] = $user->user_url; |
| 989 | - $courses = $this->post_types->course->get_product_courses( $subscription['product_id'] ); |
|
| 990 | - foreach ( $courses as $course_item ){ |
|
| 991 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 989 | + $courses = $this->post_types->course->get_product_courses($subscription['product_id']); |
|
| 990 | + foreach ($courses as $course_item) { |
|
| 991 | + $update_course = $this->woocommerce_course_update($course_item->ID, $order_user); |
|
| 992 | 992 | } // End For Loop |
| 993 | 993 | } // End sensei_woocommerce_reactivate_subscription |
| 994 | 994 | |
@@ -1003,30 +1003,30 @@ discard block |
||
| 1003 | 1003 | * @param string $product_type '' or 'variation' |
| 1004 | 1004 | * @return WC_Product $wc_product_object |
| 1005 | 1005 | */ |
| 1006 | - public function sensei_get_woocommerce_product_object ( $wc_product_id = 0, $product_type = '' ) { |
|
| 1006 | + public function sensei_get_woocommerce_product_object($wc_product_id = 0, $product_type = '') { |
|
| 1007 | 1007 | |
| 1008 | 1008 | $wc_product_object = false; |
| 1009 | - if ( 0 < intval( $wc_product_id ) ) { |
|
| 1009 | + if (0 < intval($wc_product_id)) { |
|
| 1010 | 1010 | |
| 1011 | 1011 | // Get the product |
| 1012 | - if ( function_exists( 'wc_get_product' ) ) { |
|
| 1012 | + if (function_exists('wc_get_product')) { |
|
| 1013 | 1013 | |
| 1014 | - $wc_product_object = wc_get_product( $wc_product_id ); // Post WC 2.3 |
|
| 1014 | + $wc_product_object = wc_get_product($wc_product_id); // Post WC 2.3 |
|
| 1015 | 1015 | |
| 1016 | - } elseif ( function_exists( 'get_product' ) ) { |
|
| 1016 | + } elseif (function_exists('get_product')) { |
|
| 1017 | 1017 | |
| 1018 | - $wc_product_object = get_product( $wc_product_id ); // Post WC 2.0 |
|
| 1018 | + $wc_product_object = get_product($wc_product_id); // Post WC 2.0 |
|
| 1019 | 1019 | |
| 1020 | 1020 | } else { |
| 1021 | 1021 | |
| 1022 | 1022 | // Pre WC 2.0 |
| 1023 | - if ( 'variation' == $product_type || 'subscription_variation' == $product_type ) { |
|
| 1023 | + if ('variation' == $product_type || 'subscription_variation' == $product_type) { |
|
| 1024 | 1024 | |
| 1025 | - $wc_product_object = new WC_Product_Variation( $wc_product_id ); |
|
| 1025 | + $wc_product_object = new WC_Product_Variation($wc_product_id); |
|
| 1026 | 1026 | |
| 1027 | 1027 | } else { |
| 1028 | 1028 | |
| 1029 | - $wc_product_object = new WC_Product( $wc_product_id ); |
|
| 1029 | + $wc_product_object = new WC_Product($wc_product_id); |
|
| 1030 | 1030 | |
| 1031 | 1031 | } // End If Statement |
| 1032 | 1032 | |
@@ -1044,9 +1044,9 @@ discard block |
||
| 1044 | 1044 | * @access public |
| 1045 | 1045 | * @return void |
| 1046 | 1046 | */ |
| 1047 | - public function load_class ( $class_name = '' ) { |
|
| 1048 | - if ( '' != $class_name && '' != $this->token ) { |
|
| 1049 | - require_once( 'class-' . esc_attr( $this->token ) . '-' . esc_attr( $class_name ) . '.php' ); |
|
| 1047 | + public function load_class($class_name = '') { |
|
| 1048 | + if ('' != $class_name && '' != $this->token) { |
|
| 1049 | + require_once('class-'.esc_attr($this->token).'-'.esc_attr($class_name).'.php'); |
|
| 1050 | 1050 | } // End If Statement |
| 1051 | 1051 | } // End load_class() |
| 1052 | 1052 | |
@@ -1057,17 +1057,17 @@ discard block |
||
| 1057 | 1057 | * @param integer $order_id order ID |
| 1058 | 1058 | * @return void |
| 1059 | 1059 | */ |
| 1060 | - public function sensei_activate_subscription( $order_id = 0 ) { |
|
| 1061 | - if ( 0 < intval( $order_id ) ) { |
|
| 1062 | - $order = new WC_Order( $order_id ); |
|
| 1060 | + public function sensei_activate_subscription($order_id = 0) { |
|
| 1061 | + if (0 < intval($order_id)) { |
|
| 1062 | + $order = new WC_Order($order_id); |
|
| 1063 | 1063 | $user = get_user_by('id', $order->user_id); |
| 1064 | 1064 | $order_user['ID'] = $user->ID; |
| 1065 | 1065 | $order_user['user_login'] = $user->user_login; |
| 1066 | 1066 | $order_user['user_email'] = $user->user_email; |
| 1067 | 1067 | $order_user['user_url'] = $user->user_url; |
| 1068 | 1068 | // Run through each product ordered |
| 1069 | - if (sizeof($order->get_items())>0) { |
|
| 1070 | - foreach($order->get_items() as $item) { |
|
| 1069 | + if (sizeof($order->get_items()) > 0) { |
|
| 1070 | + foreach ($order->get_items() as $item) { |
|
| 1071 | 1071 | $product_type = ''; |
| 1072 | 1072 | if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
| 1073 | 1073 | $item_id = $item['variation_id']; |
@@ -1075,15 +1075,15 @@ discard block |
||
| 1075 | 1075 | } else { |
| 1076 | 1076 | $item_id = $item['product_id']; |
| 1077 | 1077 | } // End If Statement |
| 1078 | - $_product = $this->sensei_get_woocommerce_product_object( $item_id, $product_type ); |
|
| 1078 | + $_product = $this->sensei_get_woocommerce_product_object($item_id, $product_type); |
|
| 1079 | 1079 | // Get courses that use the WC product |
| 1080 | 1080 | $courses = array(); |
| 1081 | - if ( $product_type == 'subscription_variation' ) { |
|
| 1082 | - $courses = $this->post_types->course->get_product_courses( $item_id ); |
|
| 1081 | + if ($product_type == 'subscription_variation') { |
|
| 1082 | + $courses = $this->post_types->course->get_product_courses($item_id); |
|
| 1083 | 1083 | } // End If Statement |
| 1084 | 1084 | // Loop and update those courses |
| 1085 | - foreach ($courses as $course_item){ |
|
| 1086 | - $update_course = $this->woocommerce_course_update( $course_item->ID, $order_user ); |
|
| 1085 | + foreach ($courses as $course_item) { |
|
| 1086 | + $update_course = $this->woocommerce_course_update($course_item->ID, $order_user); |
|
| 1087 | 1087 | } // End For Loop |
| 1088 | 1088 | } // End For Loop |
| 1089 | 1089 | } // End If Statement |
@@ -1097,12 +1097,12 @@ discard block |
||
| 1097 | 1097 | * @param WC_Order $order |
| 1098 | 1098 | * @return void |
| 1099 | 1099 | */ |
| 1100 | - public function sensei_woocommerce_email_course_details( $order ) { |
|
| 1100 | + public function sensei_woocommerce_email_course_details($order) { |
|
| 1101 | 1101 | global $woocommerce; |
| 1102 | 1102 | |
| 1103 | 1103 | // exit early if not wc-completed or wc-processing |
| 1104 | - if( 'wc-completed' != $order->post_status |
|
| 1105 | - && 'wc-processing' != $order->post_status ) { |
|
| 1104 | + if ('wc-completed' != $order->post_status |
|
| 1105 | + && 'wc-processing' != $order->post_status) { |
|
| 1106 | 1106 | return; |
| 1107 | 1107 | } |
| 1108 | 1108 | |
@@ -1110,14 +1110,14 @@ discard block |
||
| 1110 | 1110 | $order_id = $order->id; |
| 1111 | 1111 | |
| 1112 | 1112 | //If object have items go through them all to find course |
| 1113 | - if ( 0 < sizeof( $order_items ) ) { |
|
| 1113 | + if (0 < sizeof($order_items)) { |
|
| 1114 | 1114 | |
| 1115 | - echo '<h2>' . __( 'Course details', 'woothemes-sensei' ) . '</h2>'; |
|
| 1115 | + echo '<h2>'.__('Course details', 'woothemes-sensei').'</h2>'; |
|
| 1116 | 1116 | |
| 1117 | - foreach ( $order_items as $item ) { |
|
| 1117 | + foreach ($order_items as $item) { |
|
| 1118 | 1118 | |
| 1119 | 1119 | $product_type = ''; |
| 1120 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1120 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 1121 | 1121 | // If item has variation_id then its from variation |
| 1122 | 1122 | $item_id = $item['variation_id']; |
| 1123 | 1123 | $product_type = 'variation'; |
@@ -1126,9 +1126,9 @@ discard block |
||
| 1126 | 1126 | $item_id = $item['product_id']; |
| 1127 | 1127 | } // End If Statement |
| 1128 | 1128 | |
| 1129 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1129 | + $user_id = get_post_meta($order_id, '_customer_user', true); |
|
| 1130 | 1130 | |
| 1131 | - if( $user_id ) { |
|
| 1131 | + if ($user_id) { |
|
| 1132 | 1132 | |
| 1133 | 1133 | // Get all courses for product |
| 1134 | 1134 | $args = array( |
@@ -1143,16 +1143,16 @@ discard block |
||
| 1143 | 1143 | 'orderby' => 'menu_order date', |
| 1144 | 1144 | 'order' => 'ASC', |
| 1145 | 1145 | ); |
| 1146 | - $courses = get_posts( $args ); |
|
| 1146 | + $courses = get_posts($args); |
|
| 1147 | 1147 | |
| 1148 | - if( $courses && count( $courses ) > 0 ) { |
|
| 1148 | + if ($courses && count($courses) > 0) { |
|
| 1149 | 1149 | |
| 1150 | - foreach( $courses as $course ) { |
|
| 1150 | + foreach ($courses as $course) { |
|
| 1151 | 1151 | |
| 1152 | 1152 | $title = $course->post_title; |
| 1153 | - $permalink = get_permalink( $course->ID ); |
|
| 1153 | + $permalink = get_permalink($course->ID); |
|
| 1154 | 1154 | |
| 1155 | - echo '<p><strong>' . sprintf( __( 'View course: %1$s', 'woothemes-sensei' ), '</strong><a href="' . esc_url( $permalink ) . '">' . $title . '</a>' ) . '</p>'; |
|
| 1155 | + echo '<p><strong>'.sprintf(__('View course: %1$s', 'woothemes-sensei'), '</strong><a href="'.esc_url($permalink).'">'.$title.'</a>').'</p>'; |
|
| 1156 | 1156 | } |
| 1157 | 1157 | } |
| 1158 | 1158 | } |
@@ -1168,44 +1168,44 @@ discard block |
||
| 1168 | 1168 | * @param integer $post_id |
| 1169 | 1169 | * @return array |
| 1170 | 1170 | */ |
| 1171 | - public function sensei_count_comments( $comments, $post_id ) { |
|
| 1171 | + public function sensei_count_comments($comments, $post_id) { |
|
| 1172 | 1172 | global $wpdb; |
| 1173 | 1173 | |
| 1174 | 1174 | $post_id = (int) $post_id; |
| 1175 | 1175 | |
| 1176 | 1176 | $count = wp_cache_get("comments-{$post_id}", 'counts'); |
| 1177 | 1177 | |
| 1178 | - if ( false !== $count ) { |
|
| 1178 | + if (false !== $count) { |
|
| 1179 | 1179 | return $count; |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | - $statuses = array( '' ); // Default to the WP normal comments |
|
| 1183 | - $stati = $wpdb->get_results( "SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A ); |
|
| 1184 | - foreach ( (array) $stati AS $status ) { |
|
| 1185 | - if ( 'sensei_' != substr($status['comment_type'], 0, 7 ) ) { |
|
| 1182 | + $statuses = array(''); // Default to the WP normal comments |
|
| 1183 | + $stati = $wpdb->get_results("SELECT comment_type FROM {$wpdb->comments} GROUP BY comment_type", ARRAY_A); |
|
| 1184 | + foreach ((array) $stati AS $status) { |
|
| 1185 | + if ('sensei_' != substr($status['comment_type'], 0, 7)) { |
|
| 1186 | 1186 | $statuses[] = $status['comment_type']; |
| 1187 | 1187 | } |
| 1188 | 1188 | } |
| 1189 | - $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
|
| 1189 | + $where = "WHERE comment_type IN ('".join("', '", array_unique($statuses))."')"; |
|
| 1190 | 1190 | |
| 1191 | - if ( $post_id > 0 ) |
|
| 1192 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1191 | + if ($post_id > 0) |
|
| 1192 | + $where .= $wpdb->prepare(" AND comment_post_ID = %d", $post_id); |
|
| 1193 | 1193 | |
| 1194 | - $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
|
| 1194 | + $count = $wpdb->get_results("SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A); |
|
| 1195 | 1195 | |
| 1196 | 1196 | $total = 0; |
| 1197 | 1197 | $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
| 1198 | - foreach ( (array) $count as $row ) { |
|
| 1198 | + foreach ((array) $count as $row) { |
|
| 1199 | 1199 | // Don't count post-trashed toward totals |
| 1200 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1200 | + if ('post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved']) |
|
| 1201 | 1201 | $total += $row['num_comments']; |
| 1202 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1202 | + if (isset($approved[$row['comment_approved']])) |
|
| 1203 | 1203 | $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | $stats['total_comments'] = $total; |
| 1207 | - foreach ( $approved as $key ) { |
|
| 1208 | - if ( empty($stats[$key]) ) |
|
| 1207 | + foreach ($approved as $key) { |
|
| 1208 | + if (empty($stats[$key])) |
|
| 1209 | 1209 | $stats[$key] = 0; |
| 1210 | 1210 | } |
| 1211 | 1211 | |
@@ -1223,15 +1223,15 @@ discard block |
||
| 1223 | 1223 | * @return void |
| 1224 | 1224 | */ |
| 1225 | 1225 | public function init_image_sizes() { |
| 1226 | - $course_archive_thumbnail = $this->get_image_size( 'course_archive_image' ); |
|
| 1227 | - $course_single_thumbnail = $this->get_image_size( 'course_single_image' ); |
|
| 1228 | - $lesson_archive_thumbnail = $this->get_image_size( 'lesson_archive_image' ); |
|
| 1229 | - $lesson_single_thumbnail = $this->get_image_size( 'lesson_single_image' ); |
|
| 1230 | - |
|
| 1231 | - add_image_size( 'course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop'] ); |
|
| 1232 | - add_image_size( 'course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop'] ); |
|
| 1233 | - add_image_size( 'lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop'] ); |
|
| 1234 | - add_image_size( 'lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop'] ); |
|
| 1226 | + $course_archive_thumbnail = $this->get_image_size('course_archive_image'); |
|
| 1227 | + $course_single_thumbnail = $this->get_image_size('course_single_image'); |
|
| 1228 | + $lesson_archive_thumbnail = $this->get_image_size('lesson_archive_image'); |
|
| 1229 | + $lesson_single_thumbnail = $this->get_image_size('lesson_single_image'); |
|
| 1230 | + |
|
| 1231 | + add_image_size('course_archive_thumbnail', $course_archive_thumbnail['width'], $course_archive_thumbnail['height'], $course_archive_thumbnail['crop']); |
|
| 1232 | + add_image_size('course_single_thumbnail', $course_single_thumbnail['width'], $course_single_thumbnail['height'], $course_single_thumbnail['crop']); |
|
| 1233 | + add_image_size('lesson_archive_thumbnail', $lesson_archive_thumbnail['width'], $lesson_archive_thumbnail['height'], $lesson_archive_thumbnail['crop']); |
|
| 1234 | + add_image_size('lesson_single_thumbnail', $lesson_single_thumbnail['width'], $lesson_single_thumbnail['height'], $lesson_single_thumbnail['crop']); |
|
| 1235 | 1235 | } |
| 1236 | 1236 | |
| 1237 | 1237 | /** |
@@ -1244,37 +1244,37 @@ discard block |
||
| 1244 | 1244 | * @param mixed $image_size |
| 1245 | 1245 | * @return string |
| 1246 | 1246 | */ |
| 1247 | - public function get_image_size( $image_size ) { |
|
| 1247 | + public function get_image_size($image_size) { |
|
| 1248 | 1248 | |
| 1249 | 1249 | // Only return sizes we define in settings |
| 1250 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1251 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1250 | + if ( ! in_array($image_size, array('course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image'))) |
|
| 1251 | + return apply_filters('sensei_get_image_size_'.$image_size, ''); |
|
| 1252 | 1252 | |
| 1253 | - if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
|
| 1254 | - $this->settings->settings[ $image_size . '_width' ] = false; |
|
| 1253 | + if ( ! isset($this->settings->settings[$image_size.'_width'])) { |
|
| 1254 | + $this->settings->settings[$image_size.'_width'] = false; |
|
| 1255 | 1255 | } |
| 1256 | - if( ! isset( $this->settings->settings[ $image_size . '_height' ] ) ) { |
|
| 1257 | - $this->settings->settings[ $image_size . '_height' ] = false; |
|
| 1256 | + if ( ! isset($this->settings->settings[$image_size.'_height'])) { |
|
| 1257 | + $this->settings->settings[$image_size.'_height'] = false; |
|
| 1258 | 1258 | } |
| 1259 | - if( ! isset( $this->settings->settings[ $image_size . '_hard_crop' ] ) ) { |
|
| 1260 | - $this->settings->settings[ $image_size . '_hard_crop' ] = false; |
|
| 1259 | + if ( ! isset($this->settings->settings[$image_size.'_hard_crop'])) { |
|
| 1260 | + $this->settings->settings[$image_size.'_hard_crop'] = false; |
|
| 1261 | 1261 | } |
| 1262 | 1262 | |
| 1263 | - $size = array_filter( array( |
|
| 1264 | - 'width' => $this->settings->settings[ $image_size . '_width' ], |
|
| 1265 | - 'height' => $this->settings->settings[ $image_size . '_height' ], |
|
| 1266 | - 'crop' => $this->settings->settings[ $image_size . '_hard_crop' ] |
|
| 1267 | - ) ); |
|
| 1263 | + $size = array_filter(array( |
|
| 1264 | + 'width' => $this->settings->settings[$image_size.'_width'], |
|
| 1265 | + 'height' => $this->settings->settings[$image_size.'_height'], |
|
| 1266 | + 'crop' => $this->settings->settings[$image_size.'_hard_crop'] |
|
| 1267 | + )); |
|
| 1268 | 1268 | |
| 1269 | - $size['width'] = isset( $size['width'] ) ? $size['width'] : '100'; |
|
| 1270 | - $size['height'] = isset( $size['height'] ) ? $size['height'] : '100'; |
|
| 1271 | - $size['crop'] = isset( $size['crop'] ) ? $size['crop'] : 0; |
|
| 1269 | + $size['width'] = isset($size['width']) ? $size['width'] : '100'; |
|
| 1270 | + $size['height'] = isset($size['height']) ? $size['height'] : '100'; |
|
| 1271 | + $size['crop'] = isset($size['crop']) ? $size['crop'] : 0; |
|
| 1272 | 1272 | |
| 1273 | - return apply_filters( 'sensei_get_image_size_' . $image_size, $size ); |
|
| 1273 | + return apply_filters('sensei_get_image_size_'.$image_size, $size); |
|
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | - public function body_class( $classes ) { |
|
| 1277 | - if( is_sensei() ) { |
|
| 1276 | + public function body_class($classes) { |
|
| 1277 | + if (is_sensei()) { |
|
| 1278 | 1278 | $classes[] = 'sensei'; |
| 1279 | 1279 | } |
| 1280 | 1280 | return $classes; |
@@ -1287,9 +1287,9 @@ discard block |
||
| 1287 | 1287 | * @since 1.7.0 |
| 1288 | 1288 | */ |
| 1289 | 1289 | public function jetpack_latex_support() { |
| 1290 | - if ( function_exists( 'latex_markup') ) { |
|
| 1291 | - add_filter( 'sensei_question_title', 'latex_markup' ); |
|
| 1292 | - add_filter( 'sensei_answer_text', 'latex_markup' ); |
|
| 1290 | + if (function_exists('latex_markup')) { |
|
| 1291 | + add_filter('sensei_question_title', 'latex_markup'); |
|
| 1292 | + add_filter('sensei_answer_text', 'latex_markup'); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | } |
| 1295 | 1295 | |
@@ -1301,21 +1301,21 @@ discard block |
||
| 1301 | 1301 | * |
| 1302 | 1302 | * @since 1.8.0 |
| 1303 | 1303 | */ |
| 1304 | - public function load_modules_class(){ |
|
| 1304 | + public function load_modules_class() { |
|
| 1305 | 1305 | global $sensei_modules; |
| 1306 | 1306 | |
| 1307 | - if( !class_exists( 'Sensei_Modules' ) |
|
| 1308 | - && 'Sensei_Modules' != get_class( $sensei_modules ) ) { |
|
| 1307 | + if ( ! class_exists('Sensei_Modules') |
|
| 1308 | + && 'Sensei_Modules' != get_class($sensei_modules)) { |
|
| 1309 | 1309 | |
| 1310 | 1310 | //Load the modules class |
| 1311 | - require_once( 'class-sensei-modules.php'); |
|
| 1312 | - Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
|
| 1311 | + require_once('class-sensei-modules.php'); |
|
| 1312 | + Sensei()->modules = new Sensei_Core_Modules($this->file); |
|
| 1313 | 1313 | |
| 1314 | - }else{ |
|
| 1314 | + } else { |
|
| 1315 | 1315 | // fallback for people still using the modules extension. |
| 1316 | 1316 | global $sensei_modules; |
| 1317 | 1317 | Sensei()->modules = $sensei_modules; |
| 1318 | - add_action( 'admin_notices', array( $this, 'disable_sensei_modules_extension'), 30 ); |
|
| 1318 | + add_action('admin_notices', array($this, 'disable_sensei_modules_extension'), 30); |
|
| 1319 | 1319 | } |
| 1320 | 1320 | } |
| 1321 | 1321 | |
@@ -1324,12 +1324,12 @@ discard block |
||
| 1324 | 1324 | * |
| 1325 | 1325 | * @since 1.8.0 |
| 1326 | 1326 | */ |
| 1327 | - public function disable_sensei_modules_extension(){ ?> |
|
| 1327 | + public function disable_sensei_modules_extension() { ?> |
|
| 1328 | 1328 | <div class="notice updated fade"> |
| 1329 | 1329 | <p> |
| 1330 | 1330 | <?php |
| 1331 | 1331 | $plugin_manage_url = admin_url().'plugins.php#sensei-modules'; |
| 1332 | - $plugin_link_element = '<a href="' . $plugin_manage_url . '" >plugins page</a> '; |
|
| 1332 | + $plugin_link_element = '<a href="'.$plugin_manage_url.'" >plugins page</a> '; |
|
| 1333 | 1333 | ?> |
| 1334 | 1334 | <strong> Modules are now included in Sensei,</strong> so you no longer need the Sensei Modules extension. |
| 1335 | 1335 | Please deactivate and delete it from your <?php echo $plugin_link_element; ?>. (This will not affect your existing modules). |
@@ -1347,18 +1347,18 @@ discard block |
||
| 1347 | 1347 | * |
| 1348 | 1348 | * @since 1.9.0 |
| 1349 | 1349 | */ |
| 1350 | - public function flush_rewrite_rules(){ |
|
| 1350 | + public function flush_rewrite_rules() { |
|
| 1351 | 1351 | |
| 1352 | 1352 | // ensures that the rewrite rules are flushed on the second |
| 1353 | 1353 | // attempt. This ensure that the settings for any other process |
| 1354 | 1354 | // have been completed and saved to the database before we refresh the |
| 1355 | 1355 | // rewrite rules. |
| 1356 | - $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1357 | - if( '1' == $option ) { |
|
| 1356 | + $option = get_option('sensei_flush_rewrite_rules'); |
|
| 1357 | + if ('1' == $option) { |
|
| 1358 | 1358 | |
| 1359 | 1359 | update_option('sensei_flush_rewrite_rules', '2'); |
| 1360 | 1360 | |
| 1361 | - }elseif( '2' == $option ) { |
|
| 1361 | + }elseif ('2' == $option) { |
|
| 1362 | 1362 | |
| 1363 | 1363 | flush_rewrite_rules(); |
| 1364 | 1364 | update_option('sensei_flush_rewrite_rules', '0'); |
@@ -1373,7 +1373,7 @@ discard block |
||
| 1373 | 1373 | * |
| 1374 | 1374 | * @since 1.9.0 |
| 1375 | 1375 | */ |
| 1376 | - public function initiate_rewrite_rules_flush(){ |
|
| 1376 | + public function initiate_rewrite_rules_flush() { |
|
| 1377 | 1377 | |
| 1378 | 1378 | update_option('sensei_flush_rewrite_rules', '1'); |
| 1379 | 1379 | |
@@ -1386,4 +1386,4 @@ discard block |
||
| 1386 | 1386 | * for backward compatibility |
| 1387 | 1387 | * @since 1.9.0 |
| 1388 | 1388 | */ |
| 1389 | -class Woothemes_Sensei extends Sensei_Main{ } |
|
| 1389 | +class Woothemes_Sensei extends Sensei_Main { } |
|
@@ -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 |
@@ -159,7 +162,9 @@ discard block |
||
| 159 | 162 | $this->init(); |
| 160 | 163 | |
| 161 | 164 | // Installation |
| 162 | - if ( is_admin() && ! defined( 'DOING_AJAX' ) ) $this->install(); |
|
| 165 | + if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { |
|
| 166 | + $this->install(); |
|
| 167 | + } |
|
| 163 | 168 | |
| 164 | 169 | // Run this on activation. |
| 165 | 170 | register_activation_hook( $this->file, array( $this, 'activation' ) ); |
@@ -447,7 +452,9 @@ discard block |
||
| 447 | 452 | **/ |
| 448 | 453 | public function virtual_order_payment_complete( $order_status, $order_id ) { |
| 449 | 454 | $order = new WC_Order( $order_id ); |
| 450 | - if ( ! isset ( $order ) ) return ''; |
|
| 455 | + if ( ! isset ( $order ) ) { |
|
| 456 | + return ''; |
|
| 457 | + } |
|
| 451 | 458 | if ( $order_status == 'wc-processing' && ( $order->post_status == 'wc-on-hold' || $order->post_status == 'wc-pending' || $order->post_status == 'wc-failed' ) ) { |
| 452 | 459 | $virtual_order = true; |
| 453 | 460 | |
@@ -612,7 +619,7 @@ discard block |
||
| 612 | 619 | |
| 613 | 620 | $sensei_plugin_path = $this->plugin_path; |
| 614 | 621 | |
| 615 | - }else{ |
|
| 622 | + } else{ |
|
| 616 | 623 | |
| 617 | 624 | $sensei_plugin_path = plugin_dir_path( __FILE__ ); |
| 618 | 625 | |
@@ -647,7 +654,9 @@ discard block |
||
| 647 | 654 | public function woocommerce_course_update ( $course_id = 0, $order_user = array() ) { |
| 648 | 655 | global $current_user; |
| 649 | 656 | |
| 650 | - if ( ! isset( $current_user ) || !$current_user->ID > 0 ) return false; |
|
| 657 | + if ( ! isset( $current_user ) || !$current_user->ID > 0 ) { |
|
| 658 | + return false; |
|
| 659 | + } |
|
| 651 | 660 | |
| 652 | 661 | $data_update = false; |
| 653 | 662 | |
@@ -731,8 +740,7 @@ discard block |
||
| 731 | 740 | |
| 732 | 741 | $prerequisite_complete = Sensei_Utils::user_completed_course( $course_prerequisite_id, $current_user->ID ); |
| 733 | 742 | |
| 734 | - } |
|
| 735 | - else { |
|
| 743 | + } else { |
|
| 736 | 744 | $prerequisite_complete = true; |
| 737 | 745 | } // End If Statement |
| 738 | 746 | // Handles restrictions |
@@ -859,7 +867,9 @@ discard block |
||
| 859 | 867 | */ |
| 860 | 868 | public function access_settings () { |
| 861 | 869 | |
| 862 | - if( sensei_all_access() ) return true; |
|
| 870 | + if( sensei_all_access() ) { |
|
| 871 | + return true; |
|
| 872 | + } |
|
| 863 | 873 | |
| 864 | 874 | if ( isset( $this->settings->settings['access_permission'] ) && ( true == $this->settings->settings['access_permission'] ) ) { |
| 865 | 875 | if ( is_user_logged_in() ) { |
@@ -1188,8 +1198,9 @@ discard block |
||
| 1188 | 1198 | } |
| 1189 | 1199 | $where = "WHERE comment_type IN ('" . join("', '", array_unique( $statuses ) ) . "')"; |
| 1190 | 1200 | |
| 1191 | - if ( $post_id > 0 ) |
|
| 1192 | - $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1201 | + if ( $post_id > 0 ) { |
|
| 1202 | + $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id ); |
|
| 1203 | + } |
|
| 1193 | 1204 | |
| 1194 | 1205 | $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A ); |
| 1195 | 1206 | |
@@ -1197,16 +1208,19 @@ discard block |
||
| 1197 | 1208 | $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'); |
| 1198 | 1209 | foreach ( (array) $count as $row ) { |
| 1199 | 1210 | // Don't count post-trashed toward totals |
| 1200 | - if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) |
|
| 1201 | - $total += $row['num_comments']; |
|
| 1202 | - if ( isset( $approved[$row['comment_approved']] ) ) |
|
| 1203 | - $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1211 | + if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) { |
|
| 1212 | + $total += $row['num_comments']; |
|
| 1213 | + } |
|
| 1214 | + if ( isset( $approved[$row['comment_approved']] ) ) { |
|
| 1215 | + $stats[$approved[$row['comment_approved']]] = $row['num_comments']; |
|
| 1216 | + } |
|
| 1204 | 1217 | } |
| 1205 | 1218 | |
| 1206 | 1219 | $stats['total_comments'] = $total; |
| 1207 | 1220 | foreach ( $approved as $key ) { |
| 1208 | - if ( empty($stats[$key]) ) |
|
| 1209 | - $stats[$key] = 0; |
|
| 1221 | + if ( empty($stats[$key]) ) { |
|
| 1222 | + $stats[$key] = 0; |
|
| 1223 | + } |
|
| 1210 | 1224 | } |
| 1211 | 1225 | |
| 1212 | 1226 | $stats = (object) $stats; |
@@ -1247,8 +1261,9 @@ discard block |
||
| 1247 | 1261 | public function get_image_size( $image_size ) { |
| 1248 | 1262 | |
| 1249 | 1263 | // Only return sizes we define in settings |
| 1250 | - if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) |
|
| 1251 | - return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1264 | + if ( ! in_array( $image_size, array( 'course_archive_image', 'course_single_image', 'lesson_archive_image', 'lesson_single_image' ) ) ) { |
|
| 1265 | + return apply_filters( 'sensei_get_image_size_' . $image_size, '' ); |
|
| 1266 | + } |
|
| 1252 | 1267 | |
| 1253 | 1268 | if( ! isset( $this->settings->settings[ $image_size . '_width' ] ) ) { |
| 1254 | 1269 | $this->settings->settings[ $image_size . '_width' ] = false; |
@@ -1311,7 +1326,7 @@ discard block |
||
| 1311 | 1326 | require_once( 'class-sensei-modules.php'); |
| 1312 | 1327 | Sensei()->modules = new Sensei_Core_Modules( $this->file ); |
| 1313 | 1328 | |
| 1314 | - }else{ |
|
| 1329 | + } else{ |
|
| 1315 | 1330 | // fallback for people still using the modules extension. |
| 1316 | 1331 | global $sensei_modules; |
| 1317 | 1332 | Sensei()->modules = $sensei_modules; |
@@ -1358,7 +1373,7 @@ discard block |
||
| 1358 | 1373 | |
| 1359 | 1374 | update_option('sensei_flush_rewrite_rules', '2'); |
| 1360 | 1375 | |
| 1361 | - }elseif( '2' == $option ) { |
|
| 1376 | + } elseif( '2' == $option ) { |
|
| 1362 | 1377 | |
| 1363 | 1378 | flush_rewrite_rules(); |
| 1364 | 1379 | update_option('sensei_flush_rewrite_rules', '0'); |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Course_Results { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - public $courses_url_base; |
|
| 17 | + /** |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + public $courses_url_base; |
|
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | 23 | * Constructor. |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | global $wp_query, $current_user; |
| 99 | 99 | |
| 100 | 100 | if( isset( $wp_query->query_vars['course_results'] ) ) { |
| 101 | - Sensei_Templates::get_template( 'course-results/course-info.php' ); |
|
| 101 | + Sensei_Templates::get_template( 'course-results/course-info.php' ); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | } |
@@ -117,20 +117,20 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | sensei_do_deprecated_action( 'sensei_course_results_lessons','1.9.','sensei_course_results_content_inside_after', $course ); |
| 119 | 119 | |
| 120 | - sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID ); |
|
| 120 | + sensei_do_deprecated_action( 'sensei_course_results_bottom','1.9.','sensei_course_results_content_inside_after', $course->ID ); |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Load template for displaying course lessons |
| 126 | - * |
|
| 126 | + * |
|
| 127 | 127 | * @since 1.4.0 |
| 128 | 128 | * @return void |
| 129 | 129 | */ |
| 130 | 130 | public function course_lessons() { |
| 131 | 131 | |
| 132 | 132 | global $course; |
| 133 | - _deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' ); |
|
| 133 | + _deprecated_function( 'Sensei_modules course_lessons ', '1.9.0' ); |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | |
@@ -147,62 +147,62 @@ discard block |
||
| 147 | 147 | return $classes; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Deprecate the sensei_course_results_content hook |
|
| 152 | - * |
|
| 153 | - * @deprecated since 1.9.0 |
|
| 154 | - */ |
|
| 155 | - public static function deprecate_sensei_course_results_content_hook(){ |
|
| 150 | + /** |
|
| 151 | + * Deprecate the sensei_course_results_content hook |
|
| 152 | + * |
|
| 153 | + * @deprecated since 1.9.0 |
|
| 154 | + */ |
|
| 155 | + public static function deprecate_sensei_course_results_content_hook(){ |
|
| 156 | 156 | |
| 157 | - sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before'); |
|
| 157 | + sensei_do_deprecated_action('sensei_course_results_content', '1.9.0','sensei_course_results_content_before'); |
|
| 158 | 158 | |
| 159 | - } |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Fire the sensei frontend message hook |
|
| 163 | - * |
|
| 164 | - * @since 1.9.0 |
|
| 165 | - */ |
|
| 166 | - public static function fire_sensei_message_hook(){ |
|
| 161 | + /** |
|
| 162 | + * Fire the sensei frontend message hook |
|
| 163 | + * |
|
| 164 | + * @since 1.9.0 |
|
| 165 | + */ |
|
| 166 | + public static function fire_sensei_message_hook(){ |
|
| 167 | 167 | |
| 168 | - do_action( 'sensei_frontend_messages' ); |
|
| 168 | + do_action( 'sensei_frontend_messages' ); |
|
| 169 | 169 | |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Deprecate the course_results info hook |
|
| 174 | - * |
|
| 175 | - * @since 1.9.0 |
|
| 176 | - */ |
|
| 177 | - public static function deprecate_course_result_info_hook(){ |
|
| 172 | + /** |
|
| 173 | + * Deprecate the course_results info hook |
|
| 174 | + * |
|
| 175 | + * @since 1.9.0 |
|
| 176 | + */ |
|
| 177 | + public static function deprecate_course_result_info_hook(){ |
|
| 178 | 178 | |
| 179 | - sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' ); |
|
| 179 | + sensei_do_deprecated_action( 'sensei_course_results_info', '1.9.0', 'sensei_course_results_content_inside_before' ); |
|
| 180 | 180 | |
| 181 | - } |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Deprecate the sensei_course_results_top hook |
|
| 185 | - * |
|
| 186 | - * @deprecate since 1.9.0 |
|
| 187 | - */ |
|
| 188 | - public static function deprecate_course_results_top_hook(){ |
|
| 183 | + /** |
|
| 184 | + * Deprecate the sensei_course_results_top hook |
|
| 185 | + * |
|
| 186 | + * @deprecate since 1.9.0 |
|
| 187 | + */ |
|
| 188 | + public static function deprecate_course_results_top_hook(){ |
|
| 189 | 189 | |
| 190 | - global $course; |
|
| 191 | - sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID ); |
|
| 190 | + global $course; |
|
| 191 | + sensei_do_deprecated_action( 'sensei_course_results_top', '1.9.0' ,'sensei_course_results_content_inside_before',$course->ID ); |
|
| 192 | 192 | |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Fire the course image hook |
|
| 197 | - * |
|
| 198 | - * @since 1.8.0 |
|
| 199 | - */ |
|
| 200 | - public static function fire_course_image_hook(){ |
|
| 195 | + /** |
|
| 196 | + * Fire the course image hook |
|
| 197 | + * |
|
| 198 | + * @since 1.8.0 |
|
| 199 | + */ |
|
| 200 | + public static function fire_course_image_hook(){ |
|
| 201 | 201 | |
| 202 | - global $course; |
|
| 203 | - do_action( 'sensei_course_image', $course->ID ); |
|
| 202 | + global $course; |
|
| 203 | + do_action( 'sensei_course_image', $course->ID ); |
|
| 204 | 204 | |
| 205 | - } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | 207 | } // End Class |
| 208 | 208 | |
@@ -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 Frontend Class |
@@ -21,78 +21,78 @@ discard block |
||
| 21 | 21 | * Constructor. |
| 22 | 22 | * @since 1.0.0 |
| 23 | 23 | */ |
| 24 | - public function __construct () { |
|
| 24 | + public function __construct() { |
|
| 25 | 25 | |
| 26 | 26 | // Template output actions |
| 27 | - add_action( 'sensei_before_main_content', array( $this, 'sensei_output_content_wrapper' ), 10 ); |
|
| 28 | - add_action( 'sensei_after_main_content', array( $this, 'sensei_output_content_wrapper_end' ), 10 ); |
|
| 29 | - add_action( 'sensei_lesson_archive_lesson_title', array( $this, 'sensei_lesson_archive_lesson_title' ), 10 ); |
|
| 27 | + add_action('sensei_before_main_content', array($this, 'sensei_output_content_wrapper'), 10); |
|
| 28 | + add_action('sensei_after_main_content', array($this, 'sensei_output_content_wrapper_end'), 10); |
|
| 29 | + add_action('sensei_lesson_archive_lesson_title', array($this, 'sensei_lesson_archive_lesson_title'), 10); |
|
| 30 | 30 | |
| 31 | 31 | // 1.2.1 |
| 32 | - add_action( 'sensei_complete_lesson', array( $this, 'sensei_complete_lesson' ) ); |
|
| 33 | - add_action( 'init', array( $this, 'sensei_complete_course' ), 5 ); |
|
| 34 | - add_action( 'sensei_frontend_messages', array( $this, 'sensei_frontend_messages' ) ); |
|
| 35 | - add_action( 'sensei_lesson_video', array( $this, 'sensei_lesson_video' ), 10, 1 ); |
|
| 36 | - add_action( 'sensei_complete_lesson_button', array( $this, 'sensei_complete_lesson_button' ) ); |
|
| 37 | - add_action( 'sensei_reset_lesson_button', array( $this, 'sensei_reset_lesson_button' ) ); |
|
| 32 | + add_action('sensei_complete_lesson', array($this, 'sensei_complete_lesson')); |
|
| 33 | + add_action('init', array($this, 'sensei_complete_course'), 5); |
|
| 34 | + add_action('sensei_frontend_messages', array($this, 'sensei_frontend_messages')); |
|
| 35 | + add_action('sensei_lesson_video', array($this, 'sensei_lesson_video'), 10, 1); |
|
| 36 | + add_action('sensei_complete_lesson_button', array($this, 'sensei_complete_lesson_button')); |
|
| 37 | + add_action('sensei_reset_lesson_button', array($this, 'sensei_reset_lesson_button')); |
|
| 38 | 38 | |
| 39 | - add_action( 'sensei_course_archive_meta', array( $this, 'sensei_course_archive_meta' ) ); |
|
| 39 | + add_action('sensei_course_archive_meta', array($this, 'sensei_course_archive_meta')); |
|
| 40 | 40 | |
| 41 | - add_action( 'sensei_lesson_tag_main_content', array( $this, 'sensei_lesson_archive_main_content' ), 10 ); |
|
| 42 | - add_action( 'sensei_no_permissions_main_content', array( $this, 'sensei_no_permissions_main_content' ), 10 ); |
|
| 41 | + add_action('sensei_lesson_tag_main_content', array($this, 'sensei_lesson_archive_main_content'), 10); |
|
| 42 | + add_action('sensei_no_permissions_main_content', array($this, 'sensei_no_permissions_main_content'), 10); |
|
| 43 | 43 | |
| 44 | - add_action( 'sensei_lesson_meta', array( $this, 'sensei_lesson_meta' ), 10 ); |
|
| 45 | - add_action( 'sensei_single_course_content_inside_before', array( $this, 'sensei_course_start' ), 10 ); |
|
| 44 | + add_action('sensei_lesson_meta', array($this, 'sensei_lesson_meta'), 10); |
|
| 45 | + add_action('sensei_single_course_content_inside_before', array($this, 'sensei_course_start'), 10); |
|
| 46 | 46 | |
| 47 | 47 | // add_filter( 'get_comments_number', array( $this, 'sensei_lesson_comment_count' ), 1 ); |
| 48 | - add_filter( 'the_title', array( $this, 'sensei_lesson_preview_title' ), 10, 2 ); |
|
| 48 | + add_filter('the_title', array($this, 'sensei_lesson_preview_title'), 10, 2); |
|
| 49 | 49 | |
| 50 | 50 | //1.6.2 |
| 51 | - add_filter( 'wp_login_failed', array( $this, 'sensei_login_fail_redirect' ), 10 ); |
|
| 52 | - add_filter( 'init', array( $this, 'sensei_handle_login_request' ), 10 ); |
|
| 51 | + add_filter('wp_login_failed', array($this, 'sensei_login_fail_redirect'), 10); |
|
| 52 | + add_filter('init', array($this, 'sensei_handle_login_request'), 10); |
|
| 53 | 53 | //1.6.3 |
| 54 | - add_action( 'init', array( $this, 'sensei_process_registration' ), 2 ); |
|
| 54 | + add_action('init', array($this, 'sensei_process_registration'), 2); |
|
| 55 | 55 | //1.7.0 |
| 56 | - add_action( 'sensei_pagination', array( $this, 'sensei_breadcrumb' ), 80, 1 ); |
|
| 56 | + add_action('sensei_pagination', array($this, 'sensei_breadcrumb'), 80, 1); |
|
| 57 | 57 | |
| 58 | 58 | // Fix pagination for course archive pages when filtering by course type |
| 59 | - add_filter( 'pre_get_posts', array( $this, 'sensei_course_archive_pagination' ) ); |
|
| 59 | + add_filter('pre_get_posts', array($this, 'sensei_course_archive_pagination')); |
|
| 60 | 60 | |
| 61 | 61 | // Scripts and Styles |
| 62 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
|
| 63 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
|
| 62 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles')); |
|
| 63 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); |
|
| 64 | 64 | |
| 65 | 65 | // Custom Menu Item filters |
| 66 | - add_filter( 'wp_setup_nav_menu_item', array( $this, 'sensei_setup_nav_menu_item' ) ); |
|
| 67 | - add_filter( 'wp_nav_menu_objects', array( $this, 'sensei_wp_nav_menu_objects' ) ); |
|
| 66 | + add_filter('wp_setup_nav_menu_item', array($this, 'sensei_setup_nav_menu_item')); |
|
| 67 | + add_filter('wp_nav_menu_objects', array($this, 'sensei_wp_nav_menu_objects')); |
|
| 68 | 68 | // Search Results filters |
| 69 | - add_filter( 'post_class', array( $this, 'sensei_search_results_classes' ), 10 ); |
|
| 69 | + add_filter('post_class', array($this, 'sensei_search_results_classes'), 10); |
|
| 70 | 70 | // Only show course & lesson excerpts in search results |
| 71 | - add_filter( 'the_content', array( $this, 'sensei_search_results_excerpt' ) ); |
|
| 71 | + add_filter('the_content', array($this, 'sensei_search_results_excerpt')); |
|
| 72 | 72 | |
| 73 | 73 | //Use WooCommerce filter to show admin bar to Teachers. |
| 74 | - add_action( 'init', array( $this, 'sensei_show_admin_bar') ); |
|
| 74 | + add_action('init', array($this, 'sensei_show_admin_bar')); |
|
| 75 | 75 | |
| 76 | 76 | // Remove course from active courses if an order is cancelled or refunded |
| 77 | - add_action( 'woocommerce_order_status_processing_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 78 | - add_action( 'woocommerce_order_status_completed_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 79 | - add_action( 'woocommerce_order_status_on-hold_to_cancelled', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 80 | - add_action( 'woocommerce_order_status_processing_to_refunded', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 81 | - add_action( 'woocommerce_order_status_completed_to_refunded', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 82 | - add_action( 'woocommerce_order_status_on-hold_to_refunded', array( $this, 'remove_active_course' ), 10, 1 ); |
|
| 77 | + add_action('woocommerce_order_status_processing_to_cancelled', array($this, 'remove_active_course'), 10, 1); |
|
| 78 | + add_action('woocommerce_order_status_completed_to_cancelled', array($this, 'remove_active_course'), 10, 1); |
|
| 79 | + add_action('woocommerce_order_status_on-hold_to_cancelled', array($this, 'remove_active_course'), 10, 1); |
|
| 80 | + add_action('woocommerce_order_status_processing_to_refunded', array($this, 'remove_active_course'), 10, 1); |
|
| 81 | + add_action('woocommerce_order_status_completed_to_refunded', array($this, 'remove_active_course'), 10, 1); |
|
| 82 | + add_action('woocommerce_order_status_on-hold_to_refunded', array($this, 'remove_active_course'), 10, 1); |
|
| 83 | 83 | |
| 84 | 84 | // Make sure correct courses are marked as active for users |
| 85 | - add_action( 'sensei_before_my_courses', array( $this, 'activate_purchased_courses' ), 10, 1 ); |
|
| 86 | - add_action( 'sensei_single_course_content_inside_before', array( $this, 'activate_purchased_single_course' ), 10 ); |
|
| 85 | + add_action('sensei_before_my_courses', array($this, 'activate_purchased_courses'), 10, 1); |
|
| 86 | + add_action('sensei_single_course_content_inside_before', array($this, 'activate_purchased_single_course'), 10); |
|
| 87 | 87 | |
| 88 | 88 | // Lesson tags |
| 89 | - add_action( 'sensei_lesson_meta_extra', array( $this, 'lesson_tags_display' ), 10, 1 ); |
|
| 90 | - add_action( 'pre_get_posts', array( $this, 'lesson_tag_archive_filter' ), 10, 1 ); |
|
| 91 | - add_filter( 'sensei_lessons_archive_text', array( $this, 'lesson_tag_archive_header' ) ); |
|
| 92 | - add_action( 'sensei_loop_lesson_inside_before', array( $this, 'lesson_tag_archive_description' ), 11 ); |
|
| 89 | + add_action('sensei_lesson_meta_extra', array($this, 'lesson_tags_display'), 10, 1); |
|
| 90 | + add_action('pre_get_posts', array($this, 'lesson_tag_archive_filter'), 10, 1); |
|
| 91 | + add_filter('sensei_lessons_archive_text', array($this, 'lesson_tag_archive_header')); |
|
| 92 | + add_action('sensei_loop_lesson_inside_before', array($this, 'lesson_tag_archive_description'), 11); |
|
| 93 | 93 | |
| 94 | 94 | // Hide Sensei activity comments from lesson and course pages |
| 95 | - add_filter( 'wp_list_comments_args', array( $this, 'hide_sensei_activity' ) ); |
|
| 95 | + add_filter('wp_list_comments_args', array($this, 'hide_sensei_activity')); |
|
| 96 | 96 | } // End __construct() |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * @since 1.7.3 |
| 103 | 103 | * @return array|mixed |
| 104 | 104 | */ |
| 105 | - public function __get( $key ) { |
|
| 105 | + public function __get($key) { |
|
| 106 | 106 | |
| 107 | - if ( 'lesson' == $key || 'course' == $key ) { |
|
| 108 | - if ( WP_DEBUG ) { |
|
| 109 | - trigger_error( sprintf( 'Sensei()->frontend->%1$s has been <strong>deprecated</strong> since version %2$s! Please use Sensei()->%1$s to access the instance.', $key, '1.7.3' ) ); |
|
| 107 | + if ('lesson' == $key || 'course' == $key) { |
|
| 108 | + if (WP_DEBUG) { |
|
| 109 | + trigger_error(sprintf('Sensei()->frontend->%1$s has been <strong>deprecated</strong> since version %2$s! Please use Sensei()->%1$s to access the instance.', $key, '1.7.3')); |
|
| 110 | 110 | } |
| 111 | 111 | return Sensei()->$key; |
| 112 | 112 | } |
@@ -119,32 +119,32 @@ discard block |
||
| 119 | 119 | * @since 1.0.0 |
| 120 | 120 | * @return void |
| 121 | 121 | */ |
| 122 | - public function enqueue_scripts () { |
|
| 122 | + public function enqueue_scripts() { |
|
| 123 | 123 | |
| 124 | 124 | $disable_js = false; |
| 125 | - if ( isset( Sensei()->settings->settings[ 'js_disable' ] ) ) { |
|
| 126 | - $disable_js = Sensei()->settings->settings[ 'js_disable' ]; |
|
| 125 | + if (isset(Sensei()->settings->settings['js_disable'])) { |
|
| 126 | + $disable_js = Sensei()->settings->settings['js_disable']; |
|
| 127 | 127 | } // End If Statement |
| 128 | - if ( ! $disable_js ) { |
|
| 128 | + if ( ! $disable_js) { |
|
| 129 | 129 | |
| 130 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 130 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 131 | 131 | |
| 132 | 132 | // My Courses tabs script |
| 133 | - wp_register_script( Sensei()->token . '-user-dashboard', esc_url( Sensei()->plugin_url . 'assets/js/user-dashboard' . $suffix . '.js' ), array( 'jquery-ui-tabs' ), Sensei()->version, true ); |
|
| 134 | - wp_enqueue_script( Sensei()->token . '-user-dashboard' ); |
|
| 133 | + wp_register_script(Sensei()->token.'-user-dashboard', esc_url(Sensei()->plugin_url.'assets/js/user-dashboard'.$suffix.'.js'), array('jquery-ui-tabs'), Sensei()->version, true); |
|
| 134 | + wp_enqueue_script(Sensei()->token.'-user-dashboard'); |
|
| 135 | 135 | |
| 136 | 136 | |
| 137 | 137 | // Course Archive javascript |
| 138 | - if( is_post_type_archive( 'course' ) ){ |
|
| 138 | + if (is_post_type_archive('course')) { |
|
| 139 | 139 | |
| 140 | - wp_register_script( 'sensei-course-archive-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/course-archive' . $suffix . '.js' ), array( 'jquery' ), '1', true ); |
|
| 141 | - wp_enqueue_script( 'sensei-course-archive-js' ); |
|
| 140 | + wp_register_script('sensei-course-archive-js', esc_url(Sensei()->plugin_url.'assets/js/frontend/course-archive'.$suffix.'.js'), array('jquery'), '1', true); |
|
| 141 | + wp_enqueue_script('sensei-course-archive-js'); |
|
| 142 | 142 | |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
| 146 | 146 | // Allow additional scripts to be loaded |
| 147 | - do_action( 'sensei_additional_scripts' ); |
|
| 147 | + do_action('sensei_additional_scripts'); |
|
| 148 | 148 | |
| 149 | 149 | } // End If Statement |
| 150 | 150 | |
@@ -155,24 +155,24 @@ discard block |
||
| 155 | 155 | * @since 1.0.0 |
| 156 | 156 | * @return void |
| 157 | 157 | */ |
| 158 | - public function enqueue_styles () { |
|
| 158 | + public function enqueue_styles() { |
|
| 159 | 159 | |
| 160 | 160 | |
| 161 | 161 | $disable_styles = false; |
| 162 | - if ( isset( Sensei()->settings->settings[ 'styles_disable' ] ) ) { |
|
| 163 | - $disable_styles = Sensei()->settings->settings[ 'styles_disable' ]; |
|
| 162 | + if (isset(Sensei()->settings->settings['styles_disable'])) { |
|
| 163 | + $disable_styles = Sensei()->settings->settings['styles_disable']; |
|
| 164 | 164 | } // End If Statement |
| 165 | 165 | |
| 166 | 166 | // Add filter for theme overrides |
| 167 | - $disable_styles = apply_filters( 'sensei_disable_styles', $disable_styles ); |
|
| 167 | + $disable_styles = apply_filters('sensei_disable_styles', $disable_styles); |
|
| 168 | 168 | |
| 169 | - if ( ! $disable_styles ) { |
|
| 169 | + if ( ! $disable_styles) { |
|
| 170 | 170 | |
| 171 | - wp_register_style( Sensei()->token . '-frontend', Sensei()->plugin_url . 'assets/css/frontend/sensei.css', '', Sensei()->version, 'screen' ); |
|
| 172 | - wp_enqueue_style( Sensei()->token . '-frontend' ); |
|
| 171 | + wp_register_style(Sensei()->token.'-frontend', Sensei()->plugin_url.'assets/css/frontend/sensei.css', '', Sensei()->version, 'screen'); |
|
| 172 | + wp_enqueue_style(Sensei()->token.'-frontend'); |
|
| 173 | 173 | |
| 174 | 174 | // Allow additional stylesheets to be loaded |
| 175 | - do_action( 'sensei_additional_styles' ); |
|
| 175 | + do_action('sensei_additional_styles'); |
|
| 176 | 176 | |
| 177 | 177 | } // End If Statement |
| 178 | 178 | |
@@ -188,10 +188,10 @@ discard block |
||
| 188 | 188 | * @param string $name (default: '') |
| 189 | 189 | * @return void |
| 190 | 190 | */ |
| 191 | - function sensei_get_template_part( $slug, $name = '' ) { |
|
| 191 | + function sensei_get_template_part($slug, $name = '') { |
|
| 192 | 192 | |
| 193 | - _deprecated_function( 'class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part' ); |
|
| 194 | - Sensei_Templates::get_part( $slug, $name ); |
|
| 193 | + _deprecated_function('class-woothemes-sensei-frontend.php', '1.9.0', 'Sensei_Templates::get_part'); |
|
| 194 | + Sensei_Templates::get_part($slug, $name); |
|
| 195 | 195 | |
| 196 | 196 | } // End sensei_get_template_part() |
| 197 | 197 | |
@@ -206,10 +206,10 @@ discard block |
||
| 206 | 206 | * @param string $default_path (default: '') |
| 207 | 207 | * @return void |
| 208 | 208 | */ |
| 209 | - function sensei_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 209 | + function sensei_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 210 | 210 | |
| 211 | - _deprecated_function( 'sensei_get_template', '1.9.0', 'Sensei_Templates::get_template' ); |
|
| 212 | - Sensei_Templates::get_template($template_name, $args, $template_path, $default_path ); |
|
| 211 | + _deprecated_function('sensei_get_template', '1.9.0', 'Sensei_Templates::get_template'); |
|
| 212 | + Sensei_Templates::get_template($template_name, $args, $template_path, $default_path); |
|
| 213 | 213 | |
| 214 | 214 | } // End sensei_get_template() |
| 215 | 215 | |
@@ -223,10 +223,10 @@ discard block |
||
| 223 | 223 | * @param string $default_path (default: '') |
| 224 | 224 | * @return void |
| 225 | 225 | */ |
| 226 | - function sensei_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 226 | + function sensei_locate_template($template_name, $template_path = '', $default_path = '') { |
|
| 227 | 227 | |
| 228 | - _deprecated_function( 'sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template' ); |
|
| 229 | - Sensei_Templates::locate_template( $template_name, $template_path, $default_path ); |
|
| 228 | + _deprecated_function('sensei_locate_template', '1.9.0', 'Sensei_Templates::locate_template'); |
|
| 229 | + Sensei_Templates::locate_template($template_name, $template_path, $default_path); |
|
| 230 | 230 | |
| 231 | 231 | } // End sensei_locate_template() |
| 232 | 232 | |
@@ -240,20 +240,20 @@ discard block |
||
| 240 | 240 | function sensei_output_content_wrapper() { |
| 241 | 241 | |
| 242 | 242 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 243 | - $backwards_compatible_wrapper_location = array( |
|
| 244 | - Sensei()->template_url . 'wrappers/wrapper-start.php', |
|
| 243 | + $backwards_compatible_wrapper_location = array( |
|
| 244 | + Sensei()->template_url.'wrappers/wrapper-start.php', |
|
| 245 | 245 | 'wrappers/wrapper-start.php' |
| 246 | 246 | ); |
| 247 | 247 | |
| 248 | - $template = locate_template( $backwards_compatible_wrapper_location ); |
|
| 249 | - if( !empty( $template ) ){ |
|
| 248 | + $template = locate_template($backwards_compatible_wrapper_location); |
|
| 249 | + if ( ! empty($template)) { |
|
| 250 | 250 | |
| 251 | - Sensei_Templates::get_template( 'wrappers/wrapper-start.php' ); |
|
| 251 | + Sensei_Templates::get_template('wrappers/wrapper-start.php'); |
|
| 252 | 252 | return; |
| 253 | 253 | |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - Sensei_Templates::get_template( 'globals/wrapper-start.php' ); |
|
| 256 | + Sensei_Templates::get_template('globals/wrapper-start.php'); |
|
| 257 | 257 | |
| 258 | 258 | } // End sensei_output_content_wrapper() |
| 259 | 259 | |
@@ -267,21 +267,21 @@ discard block |
||
| 267 | 267 | function sensei_output_content_wrapper_end() { |
| 268 | 268 | |
| 269 | 269 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 270 | - $backwards_compatible_wrapper_location = array( |
|
| 271 | - Sensei()->template_url . 'wrappers/wrapper-end.php', |
|
| 270 | + $backwards_compatible_wrapper_location = array( |
|
| 271 | + Sensei()->template_url.'wrappers/wrapper-end.php', |
|
| 272 | 272 | 'wrappers/wrapper-end.php' |
| 273 | 273 | ); |
| 274 | 274 | |
| 275 | - $backwards_compatible_template = locate_template( $backwards_compatible_wrapper_location ); |
|
| 276 | - if( !empty( $backwards_compatible_template ) ){ |
|
| 275 | + $backwards_compatible_template = locate_template($backwards_compatible_wrapper_location); |
|
| 276 | + if ( ! empty($backwards_compatible_template)) { |
|
| 277 | 277 | |
| 278 | - Sensei_Templates::get_template( 'wrappers/wrapper-end.php' ); |
|
| 278 | + Sensei_Templates::get_template('wrappers/wrapper-end.php'); |
|
| 279 | 279 | return; |
| 280 | 280 | |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | |
| 284 | - Sensei_Templates::get_template( 'globals/wrapper-end.php' ); |
|
| 284 | + Sensei_Templates::get_template('globals/wrapper-end.php'); |
|
| 285 | 285 | |
| 286 | 286 | } // End sensei_output_content_wrapper_end() |
| 287 | 287 | |
@@ -294,57 +294,57 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | public static function load_content_pagination() { |
| 296 | 296 | |
| 297 | - if( is_singular('course') ) { |
|
| 297 | + if (is_singular('course')) { |
|
| 298 | 298 | |
| 299 | 299 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 300 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-posts.php' ) ); |
|
| 301 | - if( !empty( $template ) ){ |
|
| 300 | + $template = locate_template(array(Sensei()->template_url.'wrappers/pagination-posts.php')); |
|
| 301 | + if ( ! empty($template)) { |
|
| 302 | 302 | |
| 303 | - Sensei_Templates::get_template( 'wrappers/pagination-posts.php' ); |
|
| 303 | + Sensei_Templates::get_template('wrappers/pagination-posts.php'); |
|
| 304 | 304 | return; |
| 305 | 305 | |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - Sensei_Templates::get_template( 'globals/pagination-posts.php' ); |
|
| 308 | + Sensei_Templates::get_template('globals/pagination-posts.php'); |
|
| 309 | 309 | |
| 310 | - } elseif( is_singular('lesson') ) { |
|
| 310 | + } elseif (is_singular('lesson')) { |
|
| 311 | 311 | |
| 312 | 312 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 313 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-lesson.php' ) ); |
|
| 314 | - if( !empty( $template ) ){ |
|
| 313 | + $template = locate_template(array(Sensei()->template_url.'wrappers/pagination-lesson.php')); |
|
| 314 | + if ( ! empty($template)) { |
|
| 315 | 315 | |
| 316 | - Sensei_Templates::get_template( 'wrappers/pagination-lesson.php' ); |
|
| 316 | + Sensei_Templates::get_template('wrappers/pagination-lesson.php'); |
|
| 317 | 317 | return; |
| 318 | 318 | |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - Sensei_Templates::get_template( 'globals/pagination-lesson.php' ); |
|
| 321 | + Sensei_Templates::get_template('globals/pagination-lesson.php'); |
|
| 322 | 322 | |
| 323 | - } elseif( is_singular('quiz') ) { |
|
| 323 | + } elseif (is_singular('quiz')) { |
|
| 324 | 324 | |
| 325 | 325 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 326 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination-quiz.php' ) ); |
|
| 327 | - if( !empty( $template ) ){ |
|
| 326 | + $template = locate_template(array(Sensei()->template_url.'wrappers/pagination-quiz.php')); |
|
| 327 | + if ( ! empty($template)) { |
|
| 328 | 328 | |
| 329 | - Sensei_Templates::get_template( 'wrappers/pagination-quiz.php' ); |
|
| 329 | + Sensei_Templates::get_template('wrappers/pagination-quiz.php'); |
|
| 330 | 330 | return; |
| 331 | 331 | |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - Sensei_Templates::get_template( 'globals/pagination-quiz.php' ); |
|
| 334 | + Sensei_Templates::get_template('globals/pagination-quiz.php'); |
|
| 335 | 335 | |
| 336 | 336 | } else { |
| 337 | 337 | |
| 338 | 338 | // backwards compatibility check for old location under the wrappers directory of the active theme |
| 339 | - $template = locate_template( array( Sensei()->template_url . 'wrappers/pagination.php' ) ); |
|
| 340 | - if( !empty( $template ) ){ |
|
| 339 | + $template = locate_template(array(Sensei()->template_url.'wrappers/pagination.php')); |
|
| 340 | + if ( ! empty($template)) { |
|
| 341 | 341 | |
| 342 | - Sensei_Templates::get_template( 'wrappers/pagination.php' ); |
|
| 342 | + Sensei_Templates::get_template('wrappers/pagination.php'); |
|
| 343 | 343 | return; |
| 344 | 344 | |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | - Sensei_Templates::get_template( 'globals/pagination.php' ); |
|
| 347 | + Sensei_Templates::get_template('globals/pagination.php'); |
|
| 348 | 348 | |
| 349 | 349 | } // End If Statement |
| 350 | 350 | |
@@ -370,21 +370,21 @@ discard block |
||
| 370 | 370 | * @param object $item |
| 371 | 371 | * @return object $item |
| 372 | 372 | */ |
| 373 | - public function sensei_setup_nav_menu_item( $item ) { |
|
| 373 | + public function sensei_setup_nav_menu_item($item) { |
|
| 374 | 374 | global $pagenow, $wp_rewrite; |
| 375 | 375 | |
| 376 | - if( 'nav-menus.php' != $pagenow && !defined('DOING_AJAX') && isset( $item->url ) && 'custom' == $item->type ) { |
|
| 376 | + if ('nav-menus.php' != $pagenow && ! defined('DOING_AJAX') && isset($item->url) && 'custom' == $item->type) { |
|
| 377 | 377 | |
| 378 | 378 | // Set up Sensei menu links |
| 379 | - $course_page_id = intval( Sensei()->settings->settings[ 'course_page' ] ); |
|
| 380 | - $my_account_page_id = intval( Sensei()->settings->settings[ 'my_course_page' ] ); |
|
| 379 | + $course_page_id = intval(Sensei()->settings->settings['course_page']); |
|
| 380 | + $my_account_page_id = intval(Sensei()->settings->settings['my_course_page']); |
|
| 381 | 381 | |
| 382 | 382 | $course_page_url = Sensei_Course::get_courses_page_url(); |
| 383 | - $lesson_archive_url = get_post_type_archive_link( 'lesson' ); |
|
| 384 | - $my_courses_url = get_permalink( $my_account_page_id ); |
|
| 385 | - $my_messages_url = get_post_type_archive_link( 'sensei_message' ); |
|
| 383 | + $lesson_archive_url = get_post_type_archive_link('lesson'); |
|
| 384 | + $my_courses_url = get_permalink($my_account_page_id); |
|
| 385 | + $my_messages_url = get_post_type_archive_link('sensei_message'); |
|
| 386 | 386 | |
| 387 | - switch ( $item->url ) { |
|
| 387 | + switch ($item->url) { |
|
| 388 | 388 | case '#senseicourses': |
| 389 | 389 | $item->url = $course_page_url; |
| 390 | 390 | break; |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | $item->url = $my_messages_url; |
| 402 | 402 | // if no archive link exist for sensei_message |
| 403 | 403 | // set it back to the place holder |
| 404 | - if( ! $item->url ){ |
|
| 404 | + if ( ! $item->url) { |
|
| 405 | 405 | |
| 406 | 406 | $item->url = '#senseimymessages'; |
| 407 | 407 | |
@@ -409,21 +409,21 @@ discard block |
||
| 409 | 409 | break; |
| 410 | 410 | |
| 411 | 411 | case '#senseilearnerprofile': |
| 412 | - $item->url = esc_url( Sensei()->learner_profiles->get_permalink() ); |
|
| 412 | + $item->url = esc_url(Sensei()->learner_profiles->get_permalink()); |
|
| 413 | 413 | break; |
| 414 | 414 | |
| 415 | 415 | case '#senseiloginlogout': |
| 416 | - $logout_url = wp_logout_url( home_url() ); |
|
| 416 | + $logout_url = wp_logout_url(home_url()); |
|
| 417 | 417 | // Login link links to the My Courses page, to avoid the WP dashboard. |
| 418 | 418 | $login_url = $my_courses_url; |
| 419 | 419 | |
| 420 | - $item->url = ( is_user_logged_in() ? $logout_url : $login_url ); |
|
| 420 | + $item->url = (is_user_logged_in() ? $logout_url : $login_url); |
|
| 421 | 421 | |
| 422 | 422 | // determine the menu title login or logout |
| 423 | - if ( is_user_logged_in() ) { |
|
| 424 | - $menu_title = __( 'Logout' ,'woothemes-sensei'); |
|
| 423 | + if (is_user_logged_in()) { |
|
| 424 | + $menu_title = __('Logout', 'woothemes-sensei'); |
|
| 425 | 425 | } else { |
| 426 | - $menu_title = __( 'Login' ,'woothemes-sensei'); |
|
| 426 | + $menu_title = __('Login', 'woothemes-sensei'); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | * |
| 434 | 434 | * @param $menu_title |
| 435 | 435 | */ |
| 436 | - $item->title = apply_filters( 'sensei_login_logout_menu_title', $menu_title ); |
|
| 436 | + $item->title = apply_filters('sensei_login_logout_menu_title', $menu_title); |
|
| 437 | 437 | |
| 438 | 438 | break; |
| 439 | 439 | |
@@ -441,12 +441,12 @@ discard block |
||
| 441 | 441 | break; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] ); |
|
| 445 | - $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current ); |
|
| 446 | - $item_url = untrailingslashit( $item->url ); |
|
| 447 | - $_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) ); |
|
| 444 | + $_root_relative_current = untrailingslashit($_SERVER['REQUEST_URI']); |
|
| 445 | + $current_url = set_url_scheme('http://'.$_SERVER['HTTP_HOST'].$_root_relative_current); |
|
| 446 | + $item_url = untrailingslashit($item->url); |
|
| 447 | + $_indexless_current = untrailingslashit(preg_replace('/'.preg_quote($wp_rewrite->index, '/').'$/', '', $current_url)); |
|
| 448 | 448 | // Highlight current menu item |
| 449 | - if ( $item_url && in_array( $item_url, array( $current_url, $_indexless_current, $_root_relative_current ) ) ) { |
|
| 449 | + if ($item_url && in_array($item_url, array($current_url, $_indexless_current, $_root_relative_current))) { |
|
| 450 | 450 | $item->classes[] = 'current-menu-item current_page_item'; |
| 451 | 451 | } |
| 452 | 452 | |
@@ -465,26 +465,26 @@ discard block |
||
| 465 | 465 | * @param object $sorted_menu_items |
| 466 | 466 | * @return object $sorted_menu_items |
| 467 | 467 | */ |
| 468 | - public function sensei_wp_nav_menu_objects( $sorted_menu_items ) { |
|
| 468 | + public function sensei_wp_nav_menu_objects($sorted_menu_items) { |
|
| 469 | 469 | |
| 470 | - foreach( $sorted_menu_items as $k=>$item ) { |
|
| 470 | + foreach ($sorted_menu_items as $k=>$item) { |
|
| 471 | 471 | |
| 472 | 472 | // Remove the My Messages link for logged out users or if Private Messages are disabled |
| 473 | - if( ! get_post_type_archive_link( 'sensei_message' ) |
|
| 474 | - && '#senseimymessages' == $item->url ) { |
|
| 473 | + if ( ! get_post_type_archive_link('sensei_message') |
|
| 474 | + && '#senseimymessages' == $item->url) { |
|
| 475 | 475 | |
| 476 | - if ( !is_user_logged_in() || ( isset( Sensei()->settings->settings['messages_disable'] ) && Sensei()->settings->settings['messages_disable'] ) ) { |
|
| 476 | + if ( ! is_user_logged_in() || (isset(Sensei()->settings->settings['messages_disable']) && Sensei()->settings->settings['messages_disable'])) { |
|
| 477 | 477 | |
| 478 | - unset( $sorted_menu_items[$k] ); |
|
| 478 | + unset($sorted_menu_items[$k]); |
|
| 479 | 479 | |
| 480 | 480 | } |
| 481 | 481 | } |
| 482 | 482 | // Remove the My Profile link for logged out users. |
| 483 | - if( Sensei()->learner_profiles->get_permalink() == $item->url ) { |
|
| 483 | + if (Sensei()->learner_profiles->get_permalink() == $item->url) { |
|
| 484 | 484 | |
| 485 | - if ( !is_user_logged_in() || ! ( isset( Sensei()->settings->settings[ 'learner_profile_enable' ] ) && Sensei()->settings->settings[ 'learner_profile_enable' ] ) ) { |
|
| 485 | + if ( ! is_user_logged_in() || ! (isset(Sensei()->settings->settings['learner_profile_enable']) && Sensei()->settings->settings['learner_profile_enable'])) { |
|
| 486 | 486 | |
| 487 | - unset( $sorted_menu_items[$k] ); |
|
| 487 | + unset($sorted_menu_items[$k]); |
|
| 488 | 488 | |
| 489 | 489 | } |
| 490 | 490 | } |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | function sensei_search_results_classes($classes) { |
| 497 | 497 | global $post; |
| 498 | 498 | // Handle Search Classes for Courses, Lessons, and WC Products |
| 499 | - if ( isset( $post->post_type ) && ( ( 'course' == $post->post_type ) || ( 'lesson' == $post->post_type ) || ( 'product' == $post->post_type ) ) ) { |
|
| 499 | + if (isset($post->post_type) && (('course' == $post->post_type) || ('lesson' == $post->post_type) || ('product' == $post->post_type))) { |
|
| 500 | 500 | $classes[] = 'post'; |
| 501 | 501 | } // End If Statement |
| 502 | 502 | return $classes; |
@@ -524,18 +524,18 @@ discard block |
||
| 524 | 524 | * @param bool|false $return |
| 525 | 525 | * @return string|void |
| 526 | 526 | */ |
| 527 | - function sensei_course_image( $course_id, $width = '100', $height = '100', $return = false ) { |
|
| 527 | + function sensei_course_image($course_id, $width = '100', $height = '100', $return = false) { |
|
| 528 | 528 | |
| 529 | - trigger_error( 'Sensei Deprecated function: sensei_course_image since 1.9.0 . Please use Sensei()->course->course_image instead.'); |
|
| 529 | + trigger_error('Sensei Deprecated function: sensei_course_image since 1.9.0 . Please use Sensei()->course->course_image instead.'); |
|
| 530 | 530 | |
| 531 | - if ( ! $return ) { |
|
| 531 | + if ( ! $return) { |
|
| 532 | 532 | |
| 533 | - echo Sensei()->course->course_image( $course_id, $width, $height ); |
|
| 533 | + echo Sensei()->course->course_image($course_id, $width, $height); |
|
| 534 | 534 | return ''; |
| 535 | 535 | |
| 536 | 536 | } // End If Statement |
| 537 | 537 | |
| 538 | - return Sensei()->course->course_image( $course_id, $width, $height ); |
|
| 538 | + return Sensei()->course->course_image($course_id, $width, $height); |
|
| 539 | 539 | |
| 540 | 540 | } // End sensei_course_image() |
| 541 | 541 | |
@@ -550,15 +550,15 @@ discard block |
||
| 550 | 550 | * @param bool|false $widget |
| 551 | 551 | * @return string |
| 552 | 552 | */ |
| 553 | - function sensei_lesson_image( $lesson_id, $width = '100', $height = '100', $return = false, $widget = false ) { |
|
| 553 | + function sensei_lesson_image($lesson_id, $width = '100', $height = '100', $return = false, $widget = false) { |
|
| 554 | 554 | |
| 555 | - if( ! $return ){ |
|
| 555 | + if ( ! $return) { |
|
| 556 | 556 | |
| 557 | - echo Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
| 557 | + echo Sensei()->lesson->lesson_image($lesson_id, $width, $height, $widget); |
|
| 558 | 558 | return ''; |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - return Sensei()->lesson->lesson_image( $lesson_id, $width, $height, $widget ); |
|
| 561 | + return Sensei()->lesson->lesson_image($lesson_id, $width, $height, $widget); |
|
| 562 | 562 | |
| 563 | 563 | } // End sensei_lesson_image() |
| 564 | 564 | |
@@ -566,20 +566,20 @@ discard block |
||
| 566 | 566 | * @since 1.0.0 |
| 567 | 567 | * @param WP_Query $query |
| 568 | 568 | */ |
| 569 | - function sensei_course_archive_pagination( $query ) { |
|
| 569 | + function sensei_course_archive_pagination($query) { |
|
| 570 | 570 | |
| 571 | - if( ! is_admin() && $query->is_main_query() && isset( $_GET['action'] ) && in_array( $_GET['action'], array( 'newcourses', 'featuredcourses', 'freecourses', 'paidcourses' ) ) ) { |
|
| 571 | + if ( ! is_admin() && $query->is_main_query() && isset($_GET['action']) && in_array($_GET['action'], array('newcourses', 'featuredcourses', 'freecourses', 'paidcourses'))) { |
|
| 572 | 572 | |
| 573 | 573 | $amount = 0; |
| 574 | - if ( isset( Sensei()->settings->settings[ 'course_archive_amount' ] ) && ( 0 < absint( Sensei()->settings->settings[ 'course_archive_amount' ] ) ) ) { |
|
| 575 | - $amount = absint( Sensei()->settings->settings[ 'course_archive_amount' ] ); |
|
| 574 | + if (isset(Sensei()->settings->settings['course_archive_amount']) && (0 < absint(Sensei()->settings->settings['course_archive_amount']))) { |
|
| 575 | + $amount = absint(Sensei()->settings->settings['course_archive_amount']); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - if( $amount ) { |
|
| 579 | - $query->set( 'posts_per_page', $amount ); |
|
| 578 | + if ($amount) { |
|
| 579 | + $query->set('posts_per_page', $amount); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - $query->set( 'orderby', 'menu_order date' ); |
|
| 582 | + $query->set('orderby', 'menu_order date'); |
|
| 583 | 583 | |
| 584 | 584 | } |
| 585 | 585 | } |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | function sensei_course_archive_header( ) { |
| 596 | 596 | |
| 597 | 597 | trigger_error('This function sensei_course_archive_header has been depricated. Please use: WooThemes_Sensei_Course::course_archive_header '); |
| 598 | - WooThemes_Sensei_Course::archive_header( '', '<header class="archive-header"><h1>', '</h1></header>' ); |
|
| 598 | + WooThemes_Sensei_Course::archive_header('', '<header class="archive-header"><h1>', '</h1></header>'); |
|
| 599 | 599 | |
| 600 | 600 | } // sensei_course_archive_header() |
| 601 | 601 | |
@@ -608,15 +608,15 @@ discard block |
||
| 608 | 608 | * @return void |
| 609 | 609 | */ |
| 610 | 610 | public function sensei_lesson_archive_header( ) { |
| 611 | - _deprecated_function( 'WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header' ); |
|
| 611 | + _deprecated_function('WooThemes_Sensei_Frontend::sensei_lesson_archive_header', '1.9.0', 'WooThemes_Sensei_Lesson::the_archive_header'); |
|
| 612 | 612 | Sensei()->lesson->the_archive_header(); |
| 613 | 613 | } // sensei_course_archive_header() |
| 614 | 614 | |
| 615 | 615 | /** |
| 616 | 616 | * @deprecated since 1.9.0 |
| 617 | 617 | */ |
| 618 | - public function sensei_message_archive_header( ){ |
|
| 619 | - _deprecated_function('Sensei_Frontend::sensei_message_archive_header','Please use: Sense'); |
|
| 618 | + public function sensei_message_archive_header( ) { |
|
| 619 | + _deprecated_function('Sensei_Frontend::sensei_message_archive_header', 'Please use: Sense'); |
|
| 620 | 620 | Sensei_Messages::the_archive_header(); |
| 621 | 621 | } // sensei_message_archive_header() |
| 622 | 622 | |
@@ -626,15 +626,15 @@ discard block |
||
| 626 | 626 | * @param WP_Post $post_item |
| 627 | 627 | * @return void |
| 628 | 628 | */ |
| 629 | - function sensei_course_archive_course_title( $post_item ) { |
|
| 630 | - if ( isset( $post_item->ID ) && ( 0 < $post_item->ID ) ) { |
|
| 631 | - $post_id = absint( $post_item->ID ); |
|
| 629 | + function sensei_course_archive_course_title($post_item) { |
|
| 630 | + if (isset($post_item->ID) && (0 < $post_item->ID)) { |
|
| 631 | + $post_id = absint($post_item->ID); |
|
| 632 | 632 | $post_title = $post_item->post_title; |
| 633 | 633 | } else { |
| 634 | 634 | $post_id = get_the_ID(); |
| 635 | 635 | $post_title = get_the_title(); |
| 636 | 636 | } // End If Statement |
| 637 | - ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php |
|
| 637 | + ?><header><h2><a href="<?php echo get_permalink($post_id); ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $post_title; ?></a></h2></header><?php |
|
| 638 | 638 | } // End sensei_course_archive_course_title() |
| 639 | 639 | |
| 640 | 640 | /** |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | public function sensei_lesson_archive_lesson_title() { |
| 646 | 646 | $post_id = get_the_ID(); |
| 647 | 647 | $post_title = get_the_title(); |
| 648 | - ?><header><h2><a href="<?php echo get_permalink( $post_id ); ?>" title="<?php echo esc_attr( $post_title ); ?>"><?php echo $post_title; ?></a></h2></header><?php |
|
| 648 | + ?><header><h2><a href="<?php echo get_permalink($post_id); ?>" title="<?php echo esc_attr($post_title); ?>"><?php echo $post_title; ?></a></h2></header><?php |
|
| 649 | 649 | } // End sensei_lesson_archive_lesson_title() |
| 650 | 650 | |
| 651 | 651 | /** |
@@ -654,40 +654,40 @@ discard block |
||
| 654 | 654 | * @param integer $id course, lesson or quiz id |
| 655 | 655 | * @return void |
| 656 | 656 | */ |
| 657 | - public function sensei_breadcrumb( $id = 0 ) { |
|
| 657 | + public function sensei_breadcrumb($id = 0) { |
|
| 658 | 658 | |
| 659 | 659 | // Only output on lesson, quiz and taxonomy (module) pages |
| 660 | - if( ! ( is_tax( 'module' ) || is_singular( 'lesson' ) || is_singular( 'quiz' ) ) ) return; |
|
| 660 | + if ( ! (is_tax('module') || is_singular('lesson') || is_singular('quiz'))) return; |
|
| 661 | 661 | |
| 662 | - if( empty( $id ) ){ |
|
| 662 | + if (empty($id)) { |
|
| 663 | 663 | |
| 664 | 664 | $id = get_the_ID(); |
| 665 | 665 | |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - $sensei_breadcrumb_prefix = __( 'Back to: ', 'woothemes-sensei' ); |
|
| 669 | - $separator = apply_filters( 'sensei_breadcrumb_separator', '>' ); |
|
| 668 | + $sensei_breadcrumb_prefix = __('Back to: ', 'woothemes-sensei'); |
|
| 669 | + $separator = apply_filters('sensei_breadcrumb_separator', '>'); |
|
| 670 | 670 | |
| 671 | - $html = '<section class="sensei-breadcrumb">' . $sensei_breadcrumb_prefix; |
|
| 671 | + $html = '<section class="sensei-breadcrumb">'.$sensei_breadcrumb_prefix; |
|
| 672 | 672 | // Lesson |
| 673 | - if ( is_singular( 'lesson' ) && 0 < intval( $id ) ) { |
|
| 674 | - $course_id = intval( get_post_meta( $id, '_lesson_course', true ) ); |
|
| 675 | - if( ! $course_id ) { |
|
| 673 | + if (is_singular('lesson') && 0 < intval($id)) { |
|
| 674 | + $course_id = intval(get_post_meta($id, '_lesson_course', true)); |
|
| 675 | + if ( ! $course_id) { |
|
| 676 | 676 | return; |
| 677 | 677 | } |
| 678 | - $html .= '<a href="' . esc_url( get_permalink( $course_id ) ) . '" title="' . __( 'Back to the course', 'woothemes-sensei' ) . '">' . get_the_title( $course_id ) . '</a>'; |
|
| 678 | + $html .= '<a href="'.esc_url(get_permalink($course_id)).'" title="'.__('Back to the course', 'woothemes-sensei').'">'.get_the_title($course_id).'</a>'; |
|
| 679 | 679 | } // End If Statement |
| 680 | 680 | // Quiz |
| 681 | - if ( is_singular( 'quiz' ) && 0 < intval( $id ) ) { |
|
| 682 | - $lesson_id = intval( get_post_meta( $id, '_quiz_lesson', true ) ); |
|
| 683 | - if( ! $lesson_id ) { |
|
| 681 | + if (is_singular('quiz') && 0 < intval($id)) { |
|
| 682 | + $lesson_id = intval(get_post_meta($id, '_quiz_lesson', true)); |
|
| 683 | + if ( ! $lesson_id) { |
|
| 684 | 684 | return; |
| 685 | 685 | } |
| 686 | - $html .= '<a href="' . esc_url( get_permalink( $lesson_id ) ) . '" title="' . __( 'Back to the lesson', 'woothemes-sensei' ) . '">' . get_the_title( $lesson_id ) . '</a>'; |
|
| 686 | + $html .= '<a href="'.esc_url(get_permalink($lesson_id)).'" title="'.__('Back to the lesson', 'woothemes-sensei').'">'.get_the_title($lesson_id).'</a>'; |
|
| 687 | 687 | } // End If Statement |
| 688 | 688 | |
| 689 | 689 | // Allow other plugins to filter html |
| 690 | - $html = apply_filters ( 'sensei_breadcrumb_output', $html, $separator ); |
|
| 690 | + $html = apply_filters('sensei_breadcrumb_output', $html, $separator); |
|
| 691 | 691 | $html .= '</section>'; |
| 692 | 692 | |
| 693 | 693 | echo $html; |
@@ -699,25 +699,25 @@ discard block |
||
| 699 | 699 | */ |
| 700 | 700 | public function sensei_lesson_course_signup_link( ) { |
| 701 | 701 | |
| 702 | - _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link' ); |
|
| 702 | + _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link'); |
|
| 703 | 703 | WooThemes_Sensei_Lesson::course_signup_link(); |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - public function lesson_tags_display( $lesson_id = 0 ) { |
|
| 707 | - if( $lesson_id ) { |
|
| 708 | - $tags = wp_get_post_terms( $lesson_id, 'lesson-tag' ); |
|
| 709 | - if( $tags && count( $tags ) > 0 ) { |
|
| 706 | + public function lesson_tags_display($lesson_id = 0) { |
|
| 707 | + if ($lesson_id) { |
|
| 708 | + $tags = wp_get_post_terms($lesson_id, 'lesson-tag'); |
|
| 709 | + if ($tags && count($tags) > 0) { |
|
| 710 | 710 | $tag_list = ''; |
| 711 | - foreach( $tags as $tag ) { |
|
| 712 | - $tag_link = get_term_link( $tag, 'lesson-tag' ); |
|
| 713 | - if( ! is_wp_error( $tag_link ) ) { |
|
| 714 | - if( $tag_list ) { $tag_list .= ', '; } |
|
| 715 | - $tag_list .= '<a href="' . $tag_link . '">' . $tag->name . '</a>'; |
|
| 711 | + foreach ($tags as $tag) { |
|
| 712 | + $tag_link = get_term_link($tag, 'lesson-tag'); |
|
| 713 | + if ( ! is_wp_error($tag_link)) { |
|
| 714 | + if ($tag_list) { $tag_list .= ', '; } |
|
| 715 | + $tag_list .= '<a href="'.$tag_link.'">'.$tag->name.'</a>'; |
|
| 716 | 716 | } |
| 717 | 717 | } |
| 718 | - if( $tag_list ) { |
|
| 718 | + if ($tag_list) { |
|
| 719 | 719 | ?><section class="lesson-tags"> |
| 720 | - <?php printf( __( 'Lesson tags: %1$s', 'woothemes-sensei' ), $tag_list ); ?> |
|
| 720 | + <?php printf(__('Lesson tags: %1$s', 'woothemes-sensei'), $tag_list); ?> |
|
| 721 | 721 | </section><?php |
| 722 | 722 | } |
| 723 | 723 | } |
@@ -727,51 +727,51 @@ discard block |
||
| 727 | 727 | /** |
| 728 | 728 | * @param WP_Query $query |
| 729 | 729 | */ |
| 730 | - public function lesson_tag_archive_filter( $query ) { |
|
| 731 | - if( is_tax( 'lesson-tag' ) && $query->is_main_query() ) { |
|
| 730 | + public function lesson_tag_archive_filter($query) { |
|
| 731 | + if (is_tax('lesson-tag') && $query->is_main_query()) { |
|
| 732 | 732 | // Limit to lessons only |
| 733 | - $query->set( 'post_type', 'lesson' ); |
|
| 733 | + $query->set('post_type', 'lesson'); |
|
| 734 | 734 | |
| 735 | 735 | // Set order of lessons |
| 736 | - $query->set( 'orderby', 'menu_order' ); |
|
| 737 | - $query->set( 'order', 'ASC' ); |
|
| 736 | + $query->set('orderby', 'menu_order'); |
|
| 737 | + $query->set('order', 'ASC'); |
|
| 738 | 738 | |
| 739 | 739 | } |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | - public function lesson_tag_archive_header( $title ) { |
|
| 743 | - if( is_tax( 'lesson-tag' ) ) { |
|
| 744 | - $title = sprintf( __( 'Lesson tag: %1$s', 'woothemes-sensei' ), apply_filters( 'sensei_lesson_tag_archive_title', get_queried_object()->name ) ); |
|
| 742 | + public function lesson_tag_archive_header($title) { |
|
| 743 | + if (is_tax('lesson-tag')) { |
|
| 744 | + $title = sprintf(__('Lesson tag: %1$s', 'woothemes-sensei'), apply_filters('sensei_lesson_tag_archive_title', get_queried_object()->name)); |
|
| 745 | 745 | } |
| 746 | 746 | return $title; |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | public function lesson_tag_archive_description() { |
| 750 | - if( is_tax( 'lesson-tag' ) ) { |
|
| 750 | + if (is_tax('lesson-tag')) { |
|
| 751 | 751 | $tag = get_queried_object(); |
| 752 | - echo '<p class="archive-description lesson-description">' . apply_filters( 'sensei_lesson_tag_archive_description', nl2br( $tag->description ), $tag->term_id ) . '</p>'; |
|
| 752 | + echo '<p class="archive-description lesson-description">'.apply_filters('sensei_lesson_tag_archive_description', nl2br($tag->description), $tag->term_id).'</p>'; |
|
| 753 | 753 | } |
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | public function sensei_complete_lesson() { |
| 757 | - global $post, $current_user; |
|
| 757 | + global $post, $current_user; |
|
| 758 | 758 | // Handle Quiz Completion |
| 759 | - if ( isset( $_POST['quiz_action'] ) && wp_verify_nonce( $_POST[ 'woothemes_sensei_complete_lesson_noonce' ], 'woothemes_sensei_complete_lesson_noonce' ) ) { |
|
| 759 | + if (isset($_POST['quiz_action']) && wp_verify_nonce($_POST['woothemes_sensei_complete_lesson_noonce'], 'woothemes_sensei_complete_lesson_noonce')) { |
|
| 760 | 760 | |
| 761 | - $sanitized_submit = esc_html( $_POST['quiz_action'] ); |
|
| 761 | + $sanitized_submit = esc_html($_POST['quiz_action']); |
|
| 762 | 762 | |
| 763 | 763 | switch ($sanitized_submit) { |
| 764 | 764 | case 'lesson-complete': |
| 765 | 765 | |
| 766 | - Sensei_Utils::sensei_start_lesson( $post->ID, $current_user->ID, $complete = true ); |
|
| 766 | + Sensei_Utils::sensei_start_lesson($post->ID, $current_user->ID, $complete = true); |
|
| 767 | 767 | |
| 768 | 768 | break; |
| 769 | 769 | |
| 770 | 770 | case 'lesson-reset': |
| 771 | 771 | |
| 772 | - Sensei_Utils::sensei_remove_user_from_lesson( $post->ID, $current_user->ID ); |
|
| 772 | + Sensei_Utils::sensei_remove_user_from_lesson($post->ID, $current_user->ID); |
|
| 773 | 773 | |
| 774 | - $this->messages = '<div class="sensei-message note">' . __( 'Lesson Reset Successfully.', 'woothemes-sensei' ) . '</div>'; |
|
| 774 | + $this->messages = '<div class="sensei-message note">'.__('Lesson Reset Successfully.', 'woothemes-sensei').'</div>'; |
|
| 775 | 775 | break; |
| 776 | 776 | |
| 777 | 777 | default: |
@@ -785,14 +785,14 @@ discard block |
||
| 785 | 785 | } // End sensei_complete_lesson() |
| 786 | 786 | |
| 787 | 787 | public function sensei_complete_course() { |
| 788 | - global $post, $current_user, $wp_query; |
|
| 789 | - if ( isset( $_POST['course_complete'] ) && wp_verify_nonce( $_POST[ 'woothemes_sensei_complete_course_noonce' ], 'woothemes_sensei_complete_course_noonce' ) ) { |
|
| 788 | + global $post, $current_user, $wp_query; |
|
| 789 | + if (isset($_POST['course_complete']) && wp_verify_nonce($_POST['woothemes_sensei_complete_course_noonce'], 'woothemes_sensei_complete_course_noonce')) { |
|
| 790 | 790 | |
| 791 | - $sanitized_submit = esc_html( $_POST['course_complete'] ); |
|
| 792 | - $sanitized_course_id = absint( esc_html( $_POST['course_complete_id'] ) ); |
|
| 791 | + $sanitized_submit = esc_html($_POST['course_complete']); |
|
| 792 | + $sanitized_course_id = absint(esc_html($_POST['course_complete_id'])); |
|
| 793 | 793 | // Handle submit data |
| 794 | 794 | switch ($sanitized_submit) { |
| 795 | - case __( 'Mark as Complete', 'woothemes-sensei' ): |
|
| 795 | + case __('Mark as Complete', 'woothemes-sensei'): |
|
| 796 | 796 | |
| 797 | 797 | // Add user to course |
| 798 | 798 | $course_metadata = array( |
@@ -800,15 +800,15 @@ discard block |
||
| 800 | 800 | 'percent' => 0, // No completed lessons yet |
| 801 | 801 | 'complete' => 0, |
| 802 | 802 | ); |
| 803 | - $activity_logged = Sensei_Utils::update_course_status( $current_user->ID, $sanitized_course_id, 'in-progress', $course_metadata ); |
|
| 803 | + $activity_logged = Sensei_Utils::update_course_status($current_user->ID, $sanitized_course_id, 'in-progress', $course_metadata); |
|
| 804 | 804 | |
| 805 | - if ( $activity_logged ) { |
|
| 805 | + if ($activity_logged) { |
|
| 806 | 806 | // Get all course lessons |
| 807 | - $course_lesson_ids = Sensei()->course->course_lessons( $sanitized_course_id, 'any', 'ids' ); |
|
| 807 | + $course_lesson_ids = Sensei()->course->course_lessons($sanitized_course_id, 'any', 'ids'); |
|
| 808 | 808 | // Mark all quiz user meta lessons as complete |
| 809 | - foreach ( $course_lesson_ids as $lesson_item_id ){ |
|
| 809 | + foreach ($course_lesson_ids as $lesson_item_id) { |
|
| 810 | 810 | // Mark lesson as complete |
| 811 | - $activity_logged = Sensei_Utils::sensei_start_lesson( $lesson_item_id, $current_user->ID, $complete = true ); |
|
| 811 | + $activity_logged = Sensei_Utils::sensei_start_lesson($lesson_item_id, $current_user->ID, $complete = true); |
|
| 812 | 812 | } // End For Loop |
| 813 | 813 | |
| 814 | 814 | // Update with final stats |
@@ -816,22 +816,22 @@ discard block |
||
| 816 | 816 | 'percent' => 100, |
| 817 | 817 | 'complete' => count($course_lesson_ids), |
| 818 | 818 | ); |
| 819 | - $activity_logged = Sensei_Utils::update_course_status( $current_user->ID, $sanitized_course_id, 'complete', $course_metadata ); |
|
| 819 | + $activity_logged = Sensei_Utils::update_course_status($current_user->ID, $sanitized_course_id, 'complete', $course_metadata); |
|
| 820 | 820 | |
| 821 | - do_action( 'sensei_user_course_end', $current_user->ID, $sanitized_course_id ); |
|
| 821 | + do_action('sensei_user_course_end', $current_user->ID, $sanitized_course_id); |
|
| 822 | 822 | |
| 823 | 823 | // Success message |
| 824 | - $this->messages = '<header class="archive-header"><div class="sensei-message tick">' . sprintf( __( '%1$s marked as complete.', 'woothemes-sensei' ), get_the_title( $sanitized_course_id ) ) . '</div></header>'; |
|
| 824 | + $this->messages = '<header class="archive-header"><div class="sensei-message tick">'.sprintf(__('%1$s marked as complete.', 'woothemes-sensei'), get_the_title($sanitized_course_id)).'</div></header>'; |
|
| 825 | 825 | } // End If Statement |
| 826 | 826 | |
| 827 | 827 | break; |
| 828 | 828 | |
| 829 | - case __( 'Delete Course', 'woothemes-sensei' ): |
|
| 829 | + case __('Delete Course', 'woothemes-sensei'): |
|
| 830 | 830 | |
| 831 | - Sensei_Utils::sensei_remove_user_from_course( $sanitized_course_id, $current_user->ID ); |
|
| 831 | + Sensei_Utils::sensei_remove_user_from_course($sanitized_course_id, $current_user->ID); |
|
| 832 | 832 | |
| 833 | 833 | // Success message |
| 834 | - $this->messages = '<header class="archive-header"><div class="sensei-message tick">' . sprintf( __( '%1$s deleted.', 'woothemes-sensei' ), get_the_title( $sanitized_course_id ) ) . '</div></header>'; |
|
| 834 | + $this->messages = '<header class="archive-header"><div class="sensei-message tick">'.sprintf(__('%1$s deleted.', 'woothemes-sensei'), get_the_title($sanitized_course_id)).'</div></header>'; |
|
| 835 | 835 | break; |
| 836 | 836 | |
| 837 | 837 | default: |
@@ -847,25 +847,25 @@ discard block |
||
| 847 | 847 | * @param int $lesson_id |
| 848 | 848 | * @return array |
| 849 | 849 | */ |
| 850 | - public function sensei_get_user_quiz_answers( $lesson_id = 0 ) { |
|
| 850 | + public function sensei_get_user_quiz_answers($lesson_id = 0) { |
|
| 851 | 851 | global $current_user; |
| 852 | 852 | |
| 853 | 853 | $user_answers = array(); |
| 854 | 854 | |
| 855 | - if ( 0 < intval( $lesson_id ) ) { |
|
| 856 | - $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions( $lesson_id ); |
|
| 857 | - foreach( $lesson_quiz_questions as $question ) { |
|
| 858 | - $answer = maybe_unserialize( base64_decode( Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $question->ID, 'user_id' => $current_user->ID, 'type' => 'sensei_user_answer', 'field' => 'comment_content' ) ) ) ); |
|
| 859 | - $user_answers[ $question->ID ] = $answer; |
|
| 855 | + if (0 < intval($lesson_id)) { |
|
| 856 | + $lesson_quiz_questions = Sensei()->lesson->lesson_quiz_questions($lesson_id); |
|
| 857 | + foreach ($lesson_quiz_questions as $question) { |
|
| 858 | + $answer = maybe_unserialize(base64_decode(Sensei_Utils::sensei_get_activity_value(array('post_id' => $question->ID, 'user_id' => $current_user->ID, 'type' => 'sensei_user_answer', 'field' => 'comment_content')))); |
|
| 859 | + $user_answers[$question->ID] = $answer; |
|
| 860 | 860 | } |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | return $user_answers; |
| 864 | 864 | } // End sensei_get_user_quiz_answers() |
| 865 | 865 | |
| 866 | - public function sensei_has_user_completed_lesson( $post_id = 0, $user_id = 0 ) { |
|
| 867 | - _deprecated_function( __FUNCTION__, '1.7', "WooThemes_Sensei_Utils::user_completed_lesson()" ); |
|
| 868 | - return Sensei_Utils::user_completed_lesson( $post_id, $user_id ); |
|
| 866 | + public function sensei_has_user_completed_lesson($post_id = 0, $user_id = 0) { |
|
| 867 | + _deprecated_function(__FUNCTION__, '1.7', "WooThemes_Sensei_Utils::user_completed_lesson()"); |
|
| 868 | + return Sensei_Utils::user_completed_lesson($post_id, $user_id); |
|
| 869 | 869 | } // End sensei_has_user_completed_lesson() |
| 870 | 870 | |
| 871 | 871 | /** |
@@ -875,14 +875,14 @@ discard block |
||
| 875 | 875 | Sensei()->notices->print_notices(); |
| 876 | 876 | } // End sensei_frontend_messages() |
| 877 | 877 | |
| 878 | - public function sensei_lesson_video( $post_id = 0 ) { |
|
| 879 | - if ( 0 < intval( $post_id ) ) { |
|
| 880 | - $lesson_video_embed = get_post_meta( $post_id, '_lesson_video_embed', true ); |
|
| 881 | - if ( 'http' == substr( $lesson_video_embed, 0, 4) ) { |
|
| 878 | + public function sensei_lesson_video($post_id = 0) { |
|
| 879 | + if (0 < intval($post_id)) { |
|
| 880 | + $lesson_video_embed = get_post_meta($post_id, '_lesson_video_embed', true); |
|
| 881 | + if ('http' == substr($lesson_video_embed, 0, 4)) { |
|
| 882 | 882 | // V2 - make width and height a setting for video embed |
| 883 | - $lesson_video_embed = wp_oembed_get( esc_url( $lesson_video_embed )/*, array( 'width' => 100 , 'height' => 100)*/ ); |
|
| 883 | + $lesson_video_embed = wp_oembed_get(esc_url($lesson_video_embed)/*, array( 'width' => 100 , 'height' => 100)*/); |
|
| 884 | 884 | } // End If Statement |
| 885 | - if ( '' != $lesson_video_embed ) { |
|
| 885 | + if ('' != $lesson_video_embed) { |
|
| 886 | 886 | ?><div class="video"><?php echo html_entity_decode($lesson_video_embed); ?></div><?php |
| 887 | 887 | } // End If Statement |
| 888 | 888 | } // End If Statement |
@@ -894,19 +894,19 @@ discard block |
||
| 894 | 894 | $quiz_id = 0; |
| 895 | 895 | |
| 896 | 896 | // Lesson quizzes |
| 897 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $post->ID ); |
|
| 897 | + $quiz_id = Sensei()->lesson->lesson_quizzes($post->ID); |
|
| 898 | 898 | $pass_required = true; |
| 899 | - if( $quiz_id ) { |
|
| 899 | + if ($quiz_id) { |
|
| 900 | 900 | // Get quiz pass setting |
| 901 | - $pass_required = get_post_meta( $quiz_id, '_pass_required', true ); |
|
| 901 | + $pass_required = get_post_meta($quiz_id, '_pass_required', true); |
|
| 902 | 902 | } |
| 903 | - if( ! $quiz_id || ( $quiz_id && ! $pass_required ) ) { |
|
| 903 | + if ( ! $quiz_id || ($quiz_id && ! $pass_required)) { |
|
| 904 | 904 | ?> |
| 905 | - <form class="lesson_button_form" method="POST" action="<?php echo esc_url( get_permalink() ); ?>"> |
|
| 905 | + <form class="lesson_button_form" method="POST" action="<?php echo esc_url(get_permalink()); ?>"> |
|
| 906 | 906 | <input type="hidden" |
| 907 | 907 | name="woothemes_sensei_complete_lesson_noonce" |
| 908 | 908 | id="woothemes_sensei_complete_lesson_noonce" |
| 909 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_lesson_noonce' ) ); ?>" |
|
| 909 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_lesson_noonce')); ?>" |
|
| 910 | 910 | /> |
| 911 | 911 | |
| 912 | 912 | <input type="hidden" name="quiz_action" value="lesson-complete" /> |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | <input type="submit" |
| 915 | 915 | name="quiz_complete" |
| 916 | 916 | class="quiz-submit complete" |
| 917 | - value="<?php _e( 'Complete Lesson', 'woothemes-sensei' ); ?>"/> |
|
| 917 | + value="<?php _e('Complete Lesson', 'woothemes-sensei'); ?>"/> |
|
| 918 | 918 | |
| 919 | 919 | </form> |
| 920 | 920 | <?php |
@@ -927,25 +927,25 @@ discard block |
||
| 927 | 927 | $quiz_id = 0; |
| 928 | 928 | |
| 929 | 929 | // Lesson quizzes |
| 930 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $post->ID ); |
|
| 930 | + $quiz_id = Sensei()->lesson->lesson_quizzes($post->ID); |
|
| 931 | 931 | $reset_allowed = true; |
| 932 | - if( $quiz_id ) { |
|
| 932 | + if ($quiz_id) { |
|
| 933 | 933 | // Get quiz pass setting |
| 934 | - $reset_allowed = get_post_meta( $quiz_id, '_enable_quiz_reset', true ); |
|
| 934 | + $reset_allowed = get_post_meta($quiz_id, '_enable_quiz_reset', true); |
|
| 935 | 935 | } |
| 936 | - if ( ! $quiz_id || !empty($reset_allowed) ) { |
|
| 936 | + if ( ! $quiz_id || ! empty($reset_allowed)) { |
|
| 937 | 937 | ?> |
| 938 | - <form method="POST" action="<?php echo esc_url( get_permalink() ); ?>"> |
|
| 938 | + <form method="POST" action="<?php echo esc_url(get_permalink()); ?>"> |
|
| 939 | 939 | |
| 940 | 940 | <input |
| 941 | 941 | type="hidden" |
| 942 | - name="<?php echo esc_attr( 'woothemes_sensei_complete_lesson_noonce' ); ?>" |
|
| 943 | - id="<?php echo esc_attr( 'woothemes_sensei_complete_lesson_noonce' ); ?>" |
|
| 944 | - value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_complete_lesson_noonce' ) ); ?>" /> |
|
| 942 | + name="<?php echo esc_attr('woothemes_sensei_complete_lesson_noonce'); ?>" |
|
| 943 | + id="<?php echo esc_attr('woothemes_sensei_complete_lesson_noonce'); ?>" |
|
| 944 | + value="<?php echo esc_attr(wp_create_nonce('woothemes_sensei_complete_lesson_noonce')); ?>" /> |
|
| 945 | 945 | |
| 946 | 946 | <input type="hidden" name="quiz_action" value="lesson-reset" /> |
| 947 | 947 | |
| 948 | - <input type="submit" name="quiz_complete" class="quiz-submit reset" value="<?php _e( 'Reset Lesson', 'woothemes-sensei' ); ?>"/> |
|
| 948 | + <input type="submit" name="quiz_complete" class="quiz-submit reset" value="<?php _e('Reset Lesson', 'woothemes-sensei'); ?>"/> |
|
| 949 | 949 | |
| 950 | 950 | </form> |
| 951 | 951 | <?php |
@@ -968,23 +968,23 @@ discard block |
||
| 968 | 968 | $post_title = get_the_title(); |
| 969 | 969 | $author_display_name = get_the_author(); |
| 970 | 970 | $author_id = get_the_author_meta('ID'); |
| 971 | - $category_output = get_the_term_list( $post_id, 'course-category', '', ', ', '' ); |
|
| 972 | - $free_lesson_count = intval( Sensei()->course->course_lesson_preview_count( $post_id ) ); |
|
| 971 | + $category_output = get_the_term_list($post_id, 'course-category', '', ', ', ''); |
|
| 972 | + $free_lesson_count = intval(Sensei()->course->course_lesson_preview_count($post_id)); |
|
| 973 | 973 | ?><section class="entry"> |
| 974 | 974 | <p class="sensei-course-meta"> |
| 975 | - <?php if ( isset( Sensei()->settings->settings[ 'course_author' ] ) && ( Sensei()->settings->settings[ 'course_author' ] ) ) { ?> |
|
| 976 | - <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><?php the_author_link(); ?></span> |
|
| 975 | + <?php if (isset(Sensei()->settings->settings['course_author']) && (Sensei()->settings->settings['course_author'])) { ?> |
|
| 976 | + <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><?php the_author_link(); ?></span> |
|
| 977 | 977 | <?php } // End If Statement ?> |
| 978 | - <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count( $post_id ) . ' ' . __( 'Lessons', 'woothemes-sensei' ); ?></span> |
|
| 979 | - <?php if ( '' != $category_output ) { ?> |
|
| 980 | - <span class="course-category"><?php echo sprintf( __( 'in %s', 'woothemes-sensei' ), $category_output ); ?></span> |
|
| 978 | + <span class="course-lesson-count"><?php echo Sensei()->course->course_lesson_count($post_id).' '.__('Lessons', 'woothemes-sensei'); ?></span> |
|
| 979 | + <?php if ('' != $category_output) { ?> |
|
| 980 | + <span class="course-category"><?php echo sprintf(__('in %s', 'woothemes-sensei'), $category_output); ?></span> |
|
| 981 | 981 | <?php } // End If Statement ?> |
| 982 | - <?php sensei_simple_course_price( $post_id ); ?> |
|
| 982 | + <?php sensei_simple_course_price($post_id); ?> |
|
| 983 | 983 | </p> |
| 984 | 984 | <p class="course-excerpt"><?php the_excerpt(); ?></p> |
| 985 | - <?php if ( 0 < $free_lesson_count ) { |
|
| 986 | - $free_lessons = sprintf( __( 'You can access %d of this course\'s lessons for free', 'woothemes-sensei' ), $free_lesson_count ); ?> |
|
| 987 | - <p class="sensei-free-lessons"><a href="<?php echo get_permalink( $post_id ); ?>"><?php _e( 'Preview this course', 'woothemes-sensei' ) ?></a> - <?php echo $free_lessons; ?></p> |
|
| 985 | + <?php if (0 < $free_lesson_count) { |
|
| 986 | + $free_lessons = sprintf(__('You can access %d of this course\'s lessons for free', 'woothemes-sensei'), $free_lesson_count); ?> |
|
| 987 | + <p class="sensei-free-lessons"><a href="<?php echo get_permalink($post_id); ?>"><?php _e('Preview this course', 'woothemes-sensei') ?></a> - <?php echo $free_lessons; ?></p> |
|
| 988 | 988 | <?php } ?> |
| 989 | 989 | </section><?php |
| 990 | 990 | } // End sensei_course_archive_meta() |
@@ -1007,33 +1007,33 @@ discard block |
||
| 1007 | 1007 | * @deprecated since 1.9.0 |
| 1008 | 1008 | */ |
| 1009 | 1009 | public function sensei_message_archive_main_content() { |
| 1010 | - _deprecated_function( 'Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed' ); |
|
| 1010 | + _deprecated_function('Sensei_Frontend::sensei_message_archive_main_content', 'This method is no longer needed'); |
|
| 1011 | 1011 | } // End sensei_lesson_archive_main_content() |
| 1012 | 1012 | |
| 1013 | 1013 | /** |
| 1014 | 1014 | * @deprecated since 1.9.0 |
| 1015 | 1015 | */ |
| 1016 | 1016 | public function sensei_no_permissions_main_content() { |
| 1017 | - _deprecated_function( 'Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed' ); |
|
| 1017 | + _deprecated_function('Sensei_Frontend::sensei_no_permissions_main_content', 'This method is no longer needed'); |
|
| 1018 | 1018 | } // End sensei_no_permissions_main_content() |
| 1019 | 1019 | |
| 1020 | 1020 | public function sensei_course_category_main_content() { |
| 1021 | 1021 | global $post; |
| 1022 | - if ( have_posts() ) { ?> |
|
| 1022 | + if (have_posts()) { ?> |
|
| 1023 | 1023 | |
| 1024 | 1024 | <section id="main-course" class="course-container"> |
| 1025 | 1025 | |
| 1026 | - <?php do_action( 'sensei_course_archive_header' ); ?> |
|
| 1026 | + <?php do_action('sensei_course_archive_header'); ?> |
|
| 1027 | 1027 | |
| 1028 | - <?php while ( have_posts() ) { the_post(); ?> |
|
| 1028 | + <?php while (have_posts()) { the_post(); ?> |
|
| 1029 | 1029 | |
| 1030 | - <article class="<?php echo join( ' ', get_post_class( array( 'course', 'post' ), get_the_ID() ) ); ?>"> |
|
| 1030 | + <article class="<?php echo join(' ', get_post_class(array('course', 'post'), get_the_ID())); ?>"> |
|
| 1031 | 1031 | |
| 1032 | - <?php do_action( 'sensei_course_image', get_the_ID() ); ?> |
|
| 1032 | + <?php do_action('sensei_course_image', get_the_ID()); ?> |
|
| 1033 | 1033 | |
| 1034 | - <?php do_action( 'sensei_course_archive_course_title', $post ); ?> |
|
| 1034 | + <?php do_action('sensei_course_archive_course_title', $post); ?> |
|
| 1035 | 1035 | |
| 1036 | - <?php do_action( 'sensei_course_archive_meta' ); ?> |
|
| 1036 | + <?php do_action('sensei_course_archive_meta'); ?> |
|
| 1037 | 1037 | |
| 1038 | 1038 | </article> |
| 1039 | 1039 | |
@@ -1045,7 +1045,7 @@ discard block |
||
| 1045 | 1045 | |
| 1046 | 1046 | <p> |
| 1047 | 1047 | |
| 1048 | - <?php _e( 'No courses found that match your selection.', 'woothemes-sensei' ); ?> |
|
| 1048 | + <?php _e('No courses found that match your selection.', 'woothemes-sensei'); ?> |
|
| 1049 | 1049 | |
| 1050 | 1050 | </p> |
| 1051 | 1051 | |
@@ -1062,12 +1062,12 @@ discard block |
||
| 1062 | 1062 | <div class="col-1"> |
| 1063 | 1063 | <?php |
| 1064 | 1064 | // output the actual form markup |
| 1065 | - Sensei_Templates::get_template( 'user/login-form.php'); |
|
| 1065 | + Sensei_Templates::get_template('user/login-form.php'); |
|
| 1066 | 1066 | ?> |
| 1067 | 1067 | </div> |
| 1068 | 1068 | |
| 1069 | 1069 | <?php |
| 1070 | - if ( get_option('users_can_register') ) { |
|
| 1070 | + if (get_option('users_can_register')) { |
|
| 1071 | 1071 | |
| 1072 | 1072 | // get current url |
| 1073 | 1073 | $action_url = get_permalink(); |
@@ -1075,38 +1075,38 @@ discard block |
||
| 1075 | 1075 | ?> |
| 1076 | 1076 | |
| 1077 | 1077 | <div class="col-2"> |
| 1078 | - <h2><?php _e( 'Register', 'woothemes-sensei' ); ?></h2> |
|
| 1078 | + <h2><?php _e('Register', 'woothemes-sensei'); ?></h2> |
|
| 1079 | 1079 | |
| 1080 | - <form method="post" class="register" action="<?php echo esc_url( $action_url ); ?>" > |
|
| 1080 | + <form method="post" class="register" action="<?php echo esc_url($action_url); ?>" > |
|
| 1081 | 1081 | |
| 1082 | - <?php do_action( 'sensei_register_form_start' ); ?> |
|
| 1082 | + <?php do_action('sensei_register_form_start'); ?> |
|
| 1083 | 1083 | |
| 1084 | 1084 | <p class="form-row form-row-wide"> |
| 1085 | - <label for="sensei_reg_username"><?php _e( 'Username', 'woothemes-sensei' ); ?> <span class="required">*</span></label> |
|
| 1086 | - <input type="text" class="input-text" name="sensei_reg_username" id="sensei_reg_username" value="<?php if ( ! empty( $_POST['sensei_reg_username'] ) ) esc_attr_e( $_POST['sensei_reg_username'] ); ?>" /> |
|
| 1085 | + <label for="sensei_reg_username"><?php _e('Username', 'woothemes-sensei'); ?> <span class="required">*</span></label> |
|
| 1086 | + <input type="text" class="input-text" name="sensei_reg_username" id="sensei_reg_username" value="<?php if ( ! empty($_POST['sensei_reg_username'])) esc_attr_e($_POST['sensei_reg_username']); ?>" /> |
|
| 1087 | 1087 | </p> |
| 1088 | 1088 | |
| 1089 | 1089 | <p class="form-row form-row-wide"> |
| 1090 | - <label for="sensei_reg_email"><?php _e( 'Email address', 'woothemes-sensei' ); ?> <span class="required">*</span></label> |
|
| 1091 | - <input type="email" class="input-text" name="sensei_reg_email" id="sensei_reg_email" value="<?php if ( ! empty( $_POST['sensei_reg_email'] ) ) esc_attr_e( $_POST['sensei_reg_email'] ); ?>" /> |
|
| 1090 | + <label for="sensei_reg_email"><?php _e('Email address', 'woothemes-sensei'); ?> <span class="required">*</span></label> |
|
| 1091 | + <input type="email" class="input-text" name="sensei_reg_email" id="sensei_reg_email" value="<?php if ( ! empty($_POST['sensei_reg_email'])) esc_attr_e($_POST['sensei_reg_email']); ?>" /> |
|
| 1092 | 1092 | </p> |
| 1093 | 1093 | |
| 1094 | 1094 | <p class="form-row form-row-wide"> |
| 1095 | - <label for="sensei_reg_password"><?php _e( 'Password', 'woothemes-sensei' ); ?> <span class="required">*</span></label> |
|
| 1096 | - <input type="password" class="input-text" name="sensei_reg_password" id="sensei_reg_password" value="<?php if ( ! empty( $_POST['sensei_reg_password'] ) ) esc_attr_e( $_POST['sensei_reg_password'] ); ?>" /> |
|
| 1095 | + <label for="sensei_reg_password"><?php _e('Password', 'woothemes-sensei'); ?> <span class="required">*</span></label> |
|
| 1096 | + <input type="password" class="input-text" name="sensei_reg_password" id="sensei_reg_password" value="<?php if ( ! empty($_POST['sensei_reg_password'])) esc_attr_e($_POST['sensei_reg_password']); ?>" /> |
|
| 1097 | 1097 | </p> |
| 1098 | 1098 | |
| 1099 | 1099 | <!-- Spam Trap --> |
| 1100 | - <div style="left:-999em; position:absolute;"><label for="trap"><?php _e( 'Anti-spam', 'woothemes-sensei' ); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div> |
|
| 1100 | + <div style="left:-999em; position:absolute;"><label for="trap"><?php _e('Anti-spam', 'woothemes-sensei'); ?></label><input type="text" name="email_2" id="trap" tabindex="-1" /></div> |
|
| 1101 | 1101 | |
| 1102 | - <?php do_action( 'sensei_register_form_fields' ); ?> |
|
| 1103 | - <?php do_action( 'register_form' ); ?> |
|
| 1102 | + <?php do_action('sensei_register_form_fields'); ?> |
|
| 1103 | + <?php do_action('register_form'); ?> |
|
| 1104 | 1104 | |
| 1105 | 1105 | <p class="form-row"> |
| 1106 | - <input type="submit" class="button" name="register" value="<?php _e( 'Register', 'woothemes-sensei' ); ?>" /> |
|
| 1106 | + <input type="submit" class="button" name="register" value="<?php _e('Register', 'woothemes-sensei'); ?>" /> |
|
| 1107 | 1107 | </p> |
| 1108 | 1108 | |
| 1109 | - <?php do_action( 'sensei_register_form_end' ); ?> |
|
| 1109 | + <?php do_action('sensei_register_form_end'); ?> |
|
| 1110 | 1110 | |
| 1111 | 1111 | </form> |
| 1112 | 1112 | </div> |
@@ -1119,17 +1119,17 @@ discard block |
||
| 1119 | 1119 | <?php |
| 1120 | 1120 | } // End sensei_login_form() |
| 1121 | 1121 | |
| 1122 | - public function sensei_lesson_meta( $post_id = 0 ) { |
|
| 1122 | + public function sensei_lesson_meta($post_id = 0) { |
|
| 1123 | 1123 | global $post; |
| 1124 | - if ( 0 < intval( $post_id ) ) { |
|
| 1125 | - $lesson_course_id = absint( get_post_meta( $post_id, '_lesson_course', true ) ); |
|
| 1124 | + if (0 < intval($post_id)) { |
|
| 1125 | + $lesson_course_id = absint(get_post_meta($post_id, '_lesson_course', true)); |
|
| 1126 | 1126 | ?><section class="entry"> |
| 1127 | 1127 | <p class="sensei-course-meta"> |
| 1128 | - <?php if ( isset( Sensei()->settings->settings[ 'lesson_author' ] ) && ( Sensei()->settings->settings[ 'lesson_author' ] ) ) { ?> |
|
| 1129 | - <span class="course-author"><?php _e( 'by ', 'woothemes-sensei' ); ?><?php the_author_link(); ?></span> |
|
| 1128 | + <?php if (isset(Sensei()->settings->settings['lesson_author']) && (Sensei()->settings->settings['lesson_author'])) { ?> |
|
| 1129 | + <span class="course-author"><?php _e('by ', 'woothemes-sensei'); ?><?php the_author_link(); ?></span> |
|
| 1130 | 1130 | <?php } ?> |
| 1131 | - <?php if ( 0 < intval( $lesson_course_id ) ) { ?> |
|
| 1132 | - <span class="lesson-course"><?php echo ' ' . sprintf( __( 'Part of: %s', 'woothemes-sensei' ), '<a href="' . esc_url( get_permalink( $lesson_course_id ) ) . '" title="' . __( 'View course', 'woothemes-sensei' ) . '"><em>' . get_the_title( $lesson_course_id ) . '</em></a>' ); ?></span> |
|
| 1131 | + <?php if (0 < intval($lesson_course_id)) { ?> |
|
| 1132 | + <span class="lesson-course"><?php echo ' '.sprintf(__('Part of: %s', 'woothemes-sensei'), '<a href="'.esc_url(get_permalink($lesson_course_id)).'" title="'.__('View course', 'woothemes-sensei').'"><em>'.get_the_title($lesson_course_id).'</em></a>'); ?></span> |
|
| 1133 | 1133 | <?php } ?> |
| 1134 | 1134 | </p> |
| 1135 | 1135 | <p class="lesson-excerpt"><?php the_excerpt( ); ?></p> |
@@ -1137,36 +1137,36 @@ discard block |
||
| 1137 | 1137 | } // End If Statement |
| 1138 | 1138 | } // sensei_lesson_meta() |
| 1139 | 1139 | |
| 1140 | - public function sensei_lesson_preview_title_text( $course_id ) { |
|
| 1140 | + public function sensei_lesson_preview_title_text($course_id) { |
|
| 1141 | 1141 | |
| 1142 | - $preview_text = __( ' (Preview)', 'woothemes-sensei' ); |
|
| 1142 | + $preview_text = __(' (Preview)', 'woothemes-sensei'); |
|
| 1143 | 1143 | |
| 1144 | 1144 | //if this is a paid course |
| 1145 | - if ( Sensei_WC::is_woocommerce_active() ) { |
|
| 1146 | - $wc_post_id = get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 1147 | - if ( 0 < $wc_post_id ) { |
|
| 1148 | - $preview_text = __( ' (Free Preview)', 'woothemes-sensei' ); |
|
| 1145 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 1146 | + $wc_post_id = get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 1147 | + if (0 < $wc_post_id) { |
|
| 1148 | + $preview_text = __(' (Free Preview)', 'woothemes-sensei'); |
|
| 1149 | 1149 | } // End If Statement |
| 1150 | 1150 | } |
| 1151 | 1151 | return $preview_text; |
| 1152 | 1152 | } |
| 1153 | 1153 | |
| 1154 | - public function sensei_lesson_preview_title( $title = '', $id = 0 ) { |
|
| 1154 | + public function sensei_lesson_preview_title($title = '', $id = 0) { |
|
| 1155 | 1155 | global $post, $current_user; |
| 1156 | 1156 | |
| 1157 | 1157 | // Limit to lessons and check if lesson ID matches filtered post ID |
| 1158 | 1158 | // @see https://github.com/woothemes/sensei/issues/574 |
| 1159 | - if( isset( $post->ID ) && $id == $post->ID && 'lesson' == get_post_type( $post ) ) { |
|
| 1159 | + if (isset($post->ID) && $id == $post->ID && 'lesson' == get_post_type($post)) { |
|
| 1160 | 1160 | |
| 1161 | 1161 | // Limit to main query only |
| 1162 | - if( is_main_query() ) { |
|
| 1162 | + if (is_main_query()) { |
|
| 1163 | 1163 | |
| 1164 | 1164 | // Get the course ID |
| 1165 | - $course_id = get_post_meta( $post->ID, '_lesson_course', true ); |
|
| 1165 | + $course_id = get_post_meta($post->ID, '_lesson_course', true); |
|
| 1166 | 1166 | |
| 1167 | 1167 | // Check if the user is taking the course |
| 1168 | - if( is_singular( 'lesson' ) && Sensei_Utils::is_preview_lesson( $post->ID ) && ! Sensei_Utils::user_started_course( $course_id, $current_user->ID ) && $post->ID == $id ) { |
|
| 1169 | - $title .= ' ' . $this->sensei_lesson_preview_title_text( $course_id ); |
|
| 1168 | + if (is_singular('lesson') && Sensei_Utils::is_preview_lesson($post->ID) && ! Sensei_Utils::user_started_course($course_id, $current_user->ID) && $post->ID == $id) { |
|
| 1169 | + $title .= ' '.$this->sensei_lesson_preview_title_text($course_id); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | } |
| 1172 | 1172 | } |
@@ -1177,23 +1177,23 @@ discard block |
||
| 1177 | 1177 | global $post, $current_user; |
| 1178 | 1178 | |
| 1179 | 1179 | // Check if the user is taking the course |
| 1180 | - $is_user_taking_course = Sensei_Utils::user_started_course( $post->ID, $current_user->ID ); |
|
| 1180 | + $is_user_taking_course = Sensei_Utils::user_started_course($post->ID, $current_user->ID); |
|
| 1181 | 1181 | // Handle user starting the course |
| 1182 | - if ( isset( $_POST['course_start'] ) |
|
| 1183 | - && wp_verify_nonce( $_POST[ 'woothemes_sensei_start_course_noonce' ], 'woothemes_sensei_start_course_noonce' ) |
|
| 1184 | - && !$is_user_taking_course ) { |
|
| 1182 | + if (isset($_POST['course_start']) |
|
| 1183 | + && wp_verify_nonce($_POST['woothemes_sensei_start_course_noonce'], 'woothemes_sensei_start_course_noonce') |
|
| 1184 | + && ! $is_user_taking_course) { |
|
| 1185 | 1185 | |
| 1186 | 1186 | // Start the course |
| 1187 | - $activity_logged = Sensei_Utils::user_start_course( $current_user->ID, $post->ID ); |
|
| 1187 | + $activity_logged = Sensei_Utils::user_start_course($current_user->ID, $post->ID); |
|
| 1188 | 1188 | $this->data = new stdClass(); |
| 1189 | 1189 | $this->data->is_user_taking_course = false; |
| 1190 | - if ( $activity_logged ) { |
|
| 1190 | + if ($activity_logged) { |
|
| 1191 | 1191 | $this->data->is_user_taking_course = true; |
| 1192 | 1192 | |
| 1193 | 1193 | // Refresh page to avoid re-posting |
| 1194 | 1194 | ?> |
| 1195 | 1195 | |
| 1196 | - <script type="text/javascript"> window.location = '<?php echo get_permalink( $post->ID ); ?>'; </script> |
|
| 1196 | + <script type="text/javascript"> window.location = '<?php echo get_permalink($post->ID); ?>'; </script> |
|
| 1197 | 1197 | |
| 1198 | 1198 | <?php |
| 1199 | 1199 | } // End If Statement |
@@ -1204,15 +1204,15 @@ discard block |
||
| 1204 | 1204 | * @deprecated since 1.9.0 |
| 1205 | 1205 | */ |
| 1206 | 1206 | public function sensei_course_meta() { |
| 1207 | - _deprecated_function( 'Sensei_Frontend::sensei_course_meta', '1.9.0' , 'Sensei_Course::the_course_meta()' ); |
|
| 1208 | - Sensei()->course->the_course_meta( get_post() ); |
|
| 1207 | + _deprecated_function('Sensei_Frontend::sensei_course_meta', '1.9.0', 'Sensei_Course::the_course_meta()'); |
|
| 1208 | + Sensei()->course->the_course_meta(get_post()); |
|
| 1209 | 1209 | } // End sensei_course_meta() |
| 1210 | 1210 | |
| 1211 | 1211 | /** |
| 1212 | 1212 | * @deprecated since 1.9.0 |
| 1213 | 1213 | */ |
| 1214 | 1214 | public function sensei_course_meta_video() { |
| 1215 | - _deprecated_function( 'Sensei_Frontend::sensei_course_meta_video', '1.9.0' , 'Sensei_Course::the_course_video()' ); |
|
| 1215 | + _deprecated_function('Sensei_Frontend::sensei_course_meta_video', '1.9.0', 'Sensei_Course::the_course_video()'); |
|
| 1216 | 1216 | Sensei_Course::the_course_video(); |
| 1217 | 1217 | } // End sensei_course_meta_video() |
| 1218 | 1218 | |
@@ -1227,12 +1227,12 @@ discard block |
||
| 1227 | 1227 | public function sensei_woocommerce_in_cart_message() { |
| 1228 | 1228 | global $post, $woocommerce; |
| 1229 | 1229 | |
| 1230 | - $wc_post_id = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) ); |
|
| 1231 | - $user_course_status_id = Sensei_Utils::user_started_course($post->ID , get_current_user_id() ); |
|
| 1232 | - if ( 0 < intval( $wc_post_id ) && ! $user_course_status_id ) { |
|
| 1230 | + $wc_post_id = absint(get_post_meta($post->ID, '_course_woocommerce_product', true)); |
|
| 1231 | + $user_course_status_id = Sensei_Utils::user_started_course($post->ID, get_current_user_id()); |
|
| 1232 | + if (0 < intval($wc_post_id) && ! $user_course_status_id) { |
|
| 1233 | 1233 | |
| 1234 | - if ( Sensei_WC::is_product_in_cart( $wc_post_id ) ) { |
|
| 1235 | - echo '<div class="sensei-message info">' . sprintf( __('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei') . '</div>', '<a class="cart-complete" href="' . $woocommerce->cart->get_checkout_url() . '" title="' . __('complete the purchase', 'woothemes-sensei') . '">' . __('complete the purchase', 'woothemes-sensei') . '</a>' ); |
|
| 1234 | + if (Sensei_WC::is_product_in_cart($wc_post_id)) { |
|
| 1235 | + echo '<div class="sensei-message info">'.sprintf(__('You have already added this Course to your cart. Please %1$s to access the course.', 'woothemes-sensei').'</div>', '<a class="cart-complete" href="'.$woocommerce->cart->get_checkout_url().'" title="'.__('complete the purchase', 'woothemes-sensei').'">'.__('complete the purchase', 'woothemes-sensei').'</a>'); |
|
| 1236 | 1236 | } // End If Statement |
| 1237 | 1237 | |
| 1238 | 1238 | } // End If Statement |
@@ -1240,7 +1240,7 @@ discard block |
||
| 1240 | 1240 | } // End sensei_woocommerce_in_cart_message() |
| 1241 | 1241 | |
| 1242 | 1242 | // Deprecated |
| 1243 | - public function sensei_lesson_comment_count( $count ) { |
|
| 1243 | + public function sensei_lesson_comment_count($count) { |
|
| 1244 | 1244 | return $count; |
| 1245 | 1245 | } // End sensei_lesson_comment_count() |
| 1246 | 1246 | |
@@ -1249,11 +1249,11 @@ discard block |
||
| 1249 | 1249 | * @param string $content Original content |
| 1250 | 1250 | * @return string Modified content |
| 1251 | 1251 | */ |
| 1252 | - public function sensei_search_results_excerpt( $content ) { |
|
| 1252 | + public function sensei_search_results_excerpt($content) { |
|
| 1253 | 1253 | global $post; |
| 1254 | 1254 | |
| 1255 | - if( is_search() && in_array( $post->post_type, array( 'course', 'lesson' ) ) ) { |
|
| 1256 | - $content = '<p class="course-excerpt">' . the_excerpt( ) . '</p>'; |
|
| 1255 | + if (is_search() && in_array($post->post_type, array('course', 'lesson'))) { |
|
| 1256 | + $content = '<p class="course-excerpt">'.the_excerpt( ).'</p>'; |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | return $content; |
@@ -1264,11 +1264,11 @@ discard block |
||
| 1264 | 1264 | * @param integer $order_id ID of order |
| 1265 | 1265 | * @return void |
| 1266 | 1266 | */ |
| 1267 | - public function remove_active_course( $order_id ) { |
|
| 1268 | - $order = new WC_Order( $order_id ); |
|
| 1267 | + public function remove_active_course($order_id) { |
|
| 1268 | + $order = new WC_Order($order_id); |
|
| 1269 | 1269 | |
| 1270 | - foreach ( $order->get_items() as $item ) { |
|
| 1271 | - if ( isset( $item['variation_id'] ) && ( 0 < $item['variation_id'] ) ) { |
|
| 1270 | + foreach ($order->get_items() as $item) { |
|
| 1271 | + if (isset($item['variation_id']) && (0 < $item['variation_id'])) { |
|
| 1272 | 1272 | // If item has variation_id then its a variation of the product |
| 1273 | 1273 | $item_id = $item['variation_id']; |
| 1274 | 1274 | } else { |
@@ -1276,11 +1276,11 @@ discard block |
||
| 1276 | 1276 | $item_id = $item['product_id']; |
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | - if ( $item_id > 0 ) { |
|
| 1279 | + if ($item_id > 0) { |
|
| 1280 | 1280 | |
| 1281 | - $user_id = get_post_meta( $order_id, '_customer_user', true ); |
|
| 1281 | + $user_id = get_post_meta($order_id, '_customer_user', true); |
|
| 1282 | 1282 | |
| 1283 | - if( $user_id ) { |
|
| 1283 | + if ($user_id) { |
|
| 1284 | 1284 | |
| 1285 | 1285 | // Get all courses for product |
| 1286 | 1286 | $args = array( |
@@ -1296,13 +1296,13 @@ discard block |
||
| 1296 | 1296 | 'order' => 'ASC', |
| 1297 | 1297 | 'fields' => 'ids', |
| 1298 | 1298 | ); |
| 1299 | - $course_ids = get_posts( $args ); |
|
| 1299 | + $course_ids = get_posts($args); |
|
| 1300 | 1300 | |
| 1301 | - if( $course_ids && count( $course_ids ) > 0 ) { |
|
| 1302 | - foreach( $course_ids as $course_id ) { |
|
| 1301 | + if ($course_ids && count($course_ids) > 0) { |
|
| 1302 | + foreach ($course_ids as $course_id) { |
|
| 1303 | 1303 | |
| 1304 | 1304 | // Remove all course user meta |
| 1305 | - Sensei_Utils::sensei_remove_user_from_course( $course_id, $user_id ); |
|
| 1305 | + Sensei_Utils::sensei_remove_user_from_course($course_id, $user_id); |
|
| 1306 | 1306 | |
| 1307 | 1307 | } // End For Loop |
| 1308 | 1308 | } // End If Statement |
@@ -1318,16 +1318,16 @@ discard block |
||
| 1318 | 1318 | * @param integer $user_id User ID |
| 1319 | 1319 | * @return void |
| 1320 | 1320 | */ |
| 1321 | - public function activate_purchased_courses( $user_id = 0 ) { |
|
| 1321 | + public function activate_purchased_courses($user_id = 0) { |
|
| 1322 | 1322 | |
| 1323 | - if( $user_id ) { |
|
| 1323 | + if ($user_id) { |
|
| 1324 | 1324 | |
| 1325 | - if( Sensei_WC::is_woocommerce_active() ) { |
|
| 1325 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 1326 | 1326 | |
| 1327 | 1327 | // Get all user's orders |
| 1328 | 1328 | $order_args = array( |
| 1329 | 1329 | 'post_type' => 'shop_order', |
| 1330 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 1330 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 1331 | 1331 | 'posts_per_page' => -1, |
| 1332 | 1332 | 'meta_query' => array( |
| 1333 | 1333 | array( |
@@ -1337,25 +1337,25 @@ discard block |
||
| 1337 | 1337 | ), |
| 1338 | 1338 | ); |
| 1339 | 1339 | |
| 1340 | - $orders = get_posts( $order_args ); |
|
| 1340 | + $orders = get_posts($order_args); |
|
| 1341 | 1341 | |
| 1342 | 1342 | $product_ids = array(); |
| 1343 | 1343 | $order_ids = array(); |
| 1344 | 1344 | |
| 1345 | - foreach( $orders as $post_id ) { |
|
| 1345 | + foreach ($orders as $post_id) { |
|
| 1346 | 1346 | |
| 1347 | 1347 | // Only process each order once |
| 1348 | - $processed = get_post_meta( $post_id, 'sensei_products_processed', true ); |
|
| 1348 | + $processed = get_post_meta($post_id, 'sensei_products_processed', true); |
|
| 1349 | 1349 | |
| 1350 | - if( $processed && $processed == 'processed' ) { |
|
| 1350 | + if ($processed && $processed == 'processed') { |
|
| 1351 | 1351 | continue; |
| 1352 | 1352 | } |
| 1353 | 1353 | |
| 1354 | 1354 | // Get course product IDs from order |
| 1355 | - $order = new WC_Order( $post_id ); |
|
| 1355 | + $order = new WC_Order($post_id); |
|
| 1356 | 1356 | |
| 1357 | 1357 | $items = $order->get_items(); |
| 1358 | - foreach( $items as $item ) { |
|
| 1358 | + foreach ($items as $item) { |
|
| 1359 | 1359 | if (isset($item['variation_id']) && $item['variation_id'] > 0) { |
| 1360 | 1360 | $item_id = $item['variation_id']; |
| 1361 | 1361 | $product_type = 'variation'; |
@@ -1369,7 +1369,7 @@ discard block |
||
| 1369 | 1369 | $order_ids[] = $post_id; |
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | - if( count( $product_ids ) > 0 ) { |
|
| 1372 | + if (count($product_ids) > 0) { |
|
| 1373 | 1373 | |
| 1374 | 1374 | // Get all courses from user's orders |
| 1375 | 1375 | $course_args = array( |
@@ -1386,31 +1386,31 @@ discard block |
||
| 1386 | 1386 | 'order' => 'ASC', |
| 1387 | 1387 | 'fields' => 'ids', |
| 1388 | 1388 | ); |
| 1389 | - $course_ids = get_posts( $course_args ); |
|
| 1389 | + $course_ids = get_posts($course_args); |
|
| 1390 | 1390 | |
| 1391 | - foreach( $course_ids as $course_id ) { |
|
| 1391 | + foreach ($course_ids as $course_id) { |
|
| 1392 | 1392 | |
| 1393 | - $user_course_status = Sensei_Utils::user_course_status( intval($course_id), $user_id ); |
|
| 1393 | + $user_course_status = Sensei_Utils::user_course_status(intval($course_id), $user_id); |
|
| 1394 | 1394 | |
| 1395 | 1395 | // Ignore course if already completed |
| 1396 | - if( Sensei_Utils::user_completed_course( $user_course_status ) ) { |
|
| 1396 | + if (Sensei_Utils::user_completed_course($user_course_status)) { |
|
| 1397 | 1397 | continue; |
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | 1400 | // Ignore course if already started |
| 1401 | - if( $user_course_status ) { |
|
| 1401 | + if ($user_course_status) { |
|
| 1402 | 1402 | continue; |
| 1403 | 1403 | } |
| 1404 | 1404 | |
| 1405 | 1405 | // Mark course as started by user |
| 1406 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
| 1406 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
| 1407 | 1407 | } |
| 1408 | 1408 | } |
| 1409 | 1409 | |
| 1410 | - if( count( $order_ids ) > 0 ) { |
|
| 1411 | - foreach( $order_ids as $order_id ) { |
|
| 1410 | + if (count($order_ids) > 0) { |
|
| 1411 | + foreach ($order_ids as $order_id) { |
|
| 1412 | 1412 | // Mark order as processed |
| 1413 | - update_post_meta( $order_id, 'sensei_products_processed', 'processed' ); |
|
| 1413 | + update_post_meta($order_id, 'sensei_products_processed', 'processed'); |
|
| 1414 | 1414 | } |
| 1415 | 1415 | } |
| 1416 | 1416 | } |
@@ -1424,28 +1424,28 @@ discard block |
||
| 1424 | 1424 | public function activate_purchased_single_course() { |
| 1425 | 1425 | global $post, $current_user; |
| 1426 | 1426 | |
| 1427 | - if( Sensei_WC::is_woocommerce_active() ) { |
|
| 1427 | + if (Sensei_WC::is_woocommerce_active()) { |
|
| 1428 | 1428 | |
| 1429 | - if( ! is_user_logged_in() ) return; |
|
| 1430 | - if( ! isset( $post->ID ) ) return; |
|
| 1429 | + if ( ! is_user_logged_in()) return; |
|
| 1430 | + if ( ! isset($post->ID)) return; |
|
| 1431 | 1431 | |
| 1432 | 1432 | $user_id = $current_user->ID; |
| 1433 | 1433 | $course_id = $post->ID; |
| 1434 | - $course_product_id = (int) get_post_meta( $course_id, '_course_woocommerce_product', true ); |
|
| 1435 | - if( ! $course_product_id ) { |
|
| 1434 | + $course_product_id = (int) get_post_meta($course_id, '_course_woocommerce_product', true); |
|
| 1435 | + if ( ! $course_product_id) { |
|
| 1436 | 1436 | return; |
| 1437 | 1437 | } |
| 1438 | 1438 | |
| 1439 | - $user_course_status = Sensei_Utils::user_course_status( intval($course_id), $user_id ); |
|
| 1439 | + $user_course_status = Sensei_Utils::user_course_status(intval($course_id), $user_id); |
|
| 1440 | 1440 | |
| 1441 | 1441 | // Ignore course if already completed |
| 1442 | - if( Sensei_Utils::user_completed_course( $user_course_status ) ) { |
|
| 1442 | + if (Sensei_Utils::user_completed_course($user_course_status)) { |
|
| 1443 | 1443 | |
| 1444 | 1444 | return; |
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | 1447 | // Ignore course if already started |
| 1448 | - if( $user_course_status ) { |
|
| 1448 | + if ($user_course_status) { |
|
| 1449 | 1449 | return; |
| 1450 | 1450 | } |
| 1451 | 1451 | |
@@ -1453,7 +1453,7 @@ discard block |
||
| 1453 | 1453 | $order_args = array( |
| 1454 | 1454 | 'post_type' => 'shop_order', |
| 1455 | 1455 | 'posts_per_page' => -1, |
| 1456 | - 'post_status' => array( 'wc-processing', 'wc-completed' ), |
|
| 1456 | + 'post_status' => array('wc-processing', 'wc-completed'), |
|
| 1457 | 1457 | 'meta_query' => array( |
| 1458 | 1458 | array( |
| 1459 | 1459 | 'key' => '_customer_user', |
@@ -1462,27 +1462,27 @@ discard block |
||
| 1462 | 1462 | ), |
| 1463 | 1463 | 'fields' => 'ids', |
| 1464 | 1464 | ); |
| 1465 | - $orders = get_posts( $order_args ); |
|
| 1465 | + $orders = get_posts($order_args); |
|
| 1466 | 1466 | |
| 1467 | - foreach( $orders as $order_post_id ) { |
|
| 1467 | + foreach ($orders as $order_post_id) { |
|
| 1468 | 1468 | |
| 1469 | 1469 | // Get course product IDs from order |
| 1470 | - $order = new WC_Order( $order_post_id ); |
|
| 1470 | + $order = new WC_Order($order_post_id); |
|
| 1471 | 1471 | |
| 1472 | 1472 | $items = $order->get_items(); |
| 1473 | - foreach( $items as $item ) { |
|
| 1474 | - $product = wc_get_product( $item['product_id'] ); |
|
| 1473 | + foreach ($items as $item) { |
|
| 1474 | + $product = wc_get_product($item['product_id']); |
|
| 1475 | 1475 | |
| 1476 | 1476 | // handle product bundles |
| 1477 | - if( $product->is_type('bundle') ){ |
|
| 1477 | + if ($product->is_type('bundle')) { |
|
| 1478 | 1478 | |
| 1479 | - $bundled_product = new WC_Product_Bundle( $product->id ); |
|
| 1479 | + $bundled_product = new WC_Product_Bundle($product->id); |
|
| 1480 | 1480 | $bundled_items = $bundled_product->get_bundled_items(); |
| 1481 | 1481 | |
| 1482 | - foreach( $bundled_items as $bundled_item ){ |
|
| 1482 | + foreach ($bundled_items as $bundled_item) { |
|
| 1483 | 1483 | |
| 1484 | - if( $bundled_item->product_id == $course_product_id ) { |
|
| 1485 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
| 1484 | + if ($bundled_item->product_id == $course_product_id) { |
|
| 1485 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
| 1486 | 1486 | return; |
| 1487 | 1487 | } |
| 1488 | 1488 | |
@@ -1491,8 +1491,8 @@ discard block |
||
| 1491 | 1491 | } else { |
| 1492 | 1492 | |
| 1493 | 1493 | // handle regular products |
| 1494 | - if( $item['product_id'] == $course_product_id ) { |
|
| 1495 | - Sensei_Utils::user_start_course( $user_id, $course_id ); |
|
| 1494 | + if ($item['product_id'] == $course_product_id) { |
|
| 1495 | + Sensei_Utils::user_start_course($user_id, $course_id); |
|
| 1496 | 1496 | return; |
| 1497 | 1497 | } |
| 1498 | 1498 | |
@@ -1508,9 +1508,9 @@ discard block |
||
| 1508 | 1508 | * @param array $args Default arguments |
| 1509 | 1509 | * @return array Modified arguments |
| 1510 | 1510 | */ |
| 1511 | - public function hide_sensei_activity( $args = array() ) { |
|
| 1511 | + public function hide_sensei_activity($args = array()) { |
|
| 1512 | 1512 | |
| 1513 | - if( is_singular( 'lesson' ) || is_singular( 'course' ) ) { |
|
| 1513 | + if (is_singular('lesson') || is_singular('course')) { |
|
| 1514 | 1514 | $args['type'] = 'comment'; |
| 1515 | 1515 | } |
| 1516 | 1516 | |
@@ -1527,9 +1527,9 @@ discard block |
||
| 1527 | 1527 | |
| 1528 | 1528 | //if not posted from the sensei login form let |
| 1529 | 1529 | // WordPress or any other party handle the failed request |
| 1530 | - if( ! isset( $_REQUEST['form'] ) || 'sensei-login' != $_REQUEST['form'] ){ |
|
| 1530 | + if ( ! isset($_REQUEST['form']) || 'sensei-login' != $_REQUEST['form']) { |
|
| 1531 | 1531 | |
| 1532 | - return ; |
|
| 1532 | + return; |
|
| 1533 | 1533 | |
| 1534 | 1534 | } |
| 1535 | 1535 | |
@@ -1537,9 +1537,9 @@ discard block |
||
| 1537 | 1537 | $referrer = add_query_arg('login', false, $_SERVER['HTTP_REFERER']); |
| 1538 | 1538 | |
| 1539 | 1539 | // if there's a valid referrer, and it's not the default log-in screen |
| 1540 | - if(!empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin')){ |
|
| 1540 | + if ( ! empty($referrer) && ! strstr($referrer, 'wp-login') && ! strstr($referrer, 'wp-admin')) { |
|
| 1541 | 1541 | // let's append some information (login=failed) to the URL for the theme to use |
| 1542 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
| 1542 | + wp_redirect(esc_url_raw(add_query_arg('login', 'failed', $referrer))); |
|
| 1543 | 1543 | exit; |
| 1544 | 1544 | } |
| 1545 | 1545 | }// End sensei_login_fail_redirect_to_front_end_login |
@@ -1553,10 +1553,10 @@ discard block |
||
| 1553 | 1553 | |
| 1554 | 1554 | |
| 1555 | 1555 | // Check that it is a sensei login request and if it has a valid nonce |
| 1556 | - if( isset( $_REQUEST['form'] ) && 'sensei-login' == $_REQUEST['form'] ) { |
|
| 1556 | + if (isset($_REQUEST['form']) && 'sensei-login' == $_REQUEST['form']) { |
|
| 1557 | 1557 | |
| 1558 | 1558 | // Validate the login request nonce |
| 1559 | - if( !wp_verify_nonce( $_REQUEST['_wpnonce'], 'sensei-login' ) ){ |
|
| 1559 | + if ( ! wp_verify_nonce($_REQUEST['_wpnonce'], 'sensei-login')) { |
|
| 1560 | 1560 | return; |
| 1561 | 1561 | } |
| 1562 | 1562 | |
@@ -1565,47 +1565,47 @@ discard block |
||
| 1565 | 1565 | $referrer = $_REQUEST['_wp_http_referer']; |
| 1566 | 1566 | //$redirect = $_REQUEST['_sensei_redirect']; |
| 1567 | 1567 | |
| 1568 | - if ( ( isset( $_REQUEST['log'] ) && !empty( $_REQUEST['log'] ) ) |
|
| 1569 | - && ( isset( $_REQUEST['pwd'] ) && !empty( $_REQUEST['pwd'] ) ) ){ |
|
| 1568 | + if ((isset($_REQUEST['log']) && ! empty($_REQUEST['log'])) |
|
| 1569 | + && (isset($_REQUEST['pwd']) && ! empty($_REQUEST['pwd']))) { |
|
| 1570 | 1570 | |
| 1571 | 1571 | // when the user has entered a password or username do the sensei login |
| 1572 | 1572 | $creds = array(); |
| 1573 | 1573 | |
| 1574 | 1574 | // check if the requests login is an email address |
| 1575 | - if( is_email( trim( $_REQUEST['log'] ) ) ){ |
|
| 1575 | + if (is_email(trim($_REQUEST['log']))) { |
|
| 1576 | 1576 | // query wordpress for the users details |
| 1577 | - $user = get_user_by( 'email', sanitize_email( $_REQUEST['log'] ) ); |
|
| 1577 | + $user = get_user_by('email', sanitize_email($_REQUEST['log'])); |
|
| 1578 | 1578 | |
| 1579 | 1579 | // validate the user object |
| 1580 | - if( !$user ){ |
|
| 1580 | + if ( ! $user) { |
|
| 1581 | 1581 | |
| 1582 | 1582 | // the email doesnt exist |
| 1583 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
| 1583 | + wp_redirect(esc_url_raw(add_query_arg('login', 'failed', $referrer))); |
|
| 1584 | 1584 | exit; |
| 1585 | 1585 | |
| 1586 | 1586 | } |
| 1587 | 1587 | |
| 1588 | 1588 | //assigne the username to the creds array for further processing |
| 1589 | - $creds['user_login'] = $user->user_login ; |
|
| 1589 | + $creds['user_login'] = $user->user_login; |
|
| 1590 | 1590 | |
| 1591 | - }else{ |
|
| 1591 | + } else { |
|
| 1592 | 1592 | |
| 1593 | 1593 | // process this as a default username login |
| 1594 | - $creds['user_login'] = sanitize_text_field( $_REQUEST['log'] ) ; |
|
| 1594 | + $creds['user_login'] = sanitize_text_field($_REQUEST['log']); |
|
| 1595 | 1595 | |
| 1596 | 1596 | } |
| 1597 | 1597 | |
| 1598 | 1598 | // get setup the rest of the creds array |
| 1599 | - $creds['user_password'] = sanitize_text_field( $_REQUEST['pwd'] ); |
|
| 1600 | - $creds['remember'] = isset( $_REQUEST['rememberme'] ) ? true : false ; |
|
| 1599 | + $creds['user_password'] = sanitize_text_field($_REQUEST['pwd']); |
|
| 1600 | + $creds['remember'] = isset($_REQUEST['rememberme']) ? true : false; |
|
| 1601 | 1601 | |
| 1602 | 1602 | //attempt logging in with the given details |
| 1603 | - $user = wp_signon( $creds, false ); |
|
| 1603 | + $user = wp_signon($creds, false); |
|
| 1604 | 1604 | |
| 1605 | - if ( is_wp_error($user) ){ // on login failure |
|
| 1606 | - wp_redirect( esc_url_raw( add_query_arg('login', 'failed', $referrer) ) ); |
|
| 1605 | + if (is_wp_error($user)) { // on login failure |
|
| 1606 | + wp_redirect(esc_url_raw(add_query_arg('login', 'failed', $referrer))); |
|
| 1607 | 1607 | exit; |
| 1608 | - }else{ // on login success |
|
| 1608 | + } else { // on login success |
|
| 1609 | 1609 | |
| 1610 | 1610 | /** |
| 1611 | 1611 | * change the redirect url programatically |
@@ -1615,21 +1615,21 @@ discard block |
||
| 1615 | 1615 | * @param string $referrer the page where the current url wheresensei login form was posted from |
| 1616 | 1616 | */ |
| 1617 | 1617 | |
| 1618 | - $success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg( 'login', $referrer ) ); |
|
| 1618 | + $success_redirect_url = apply_filters('sesei_login_success_redirect_url', remove_query_arg('login', $referrer)); |
|
| 1619 | 1619 | |
| 1620 | - wp_redirect( esc_url_raw( $success_redirect_url ) ); |
|
| 1620 | + wp_redirect(esc_url_raw($success_redirect_url)); |
|
| 1621 | 1621 | exit; |
| 1622 | 1622 | |
| 1623 | 1623 | } // end is_wp_error($user) |
| 1624 | 1624 | |
| 1625 | - }else{ // if username or password is empty |
|
| 1625 | + } else { // if username or password is empty |
|
| 1626 | 1626 | |
| 1627 | - wp_redirect( esc_url_raw( add_query_arg('login', 'emptyfields', $referrer) ) ); |
|
| 1627 | + wp_redirect(esc_url_raw(add_query_arg('login', 'emptyfields', $referrer))); |
|
| 1628 | 1628 | exit; |
| 1629 | 1629 | |
| 1630 | 1630 | } // end if username $_REQUEST['log'] and password $_REQUEST['pwd'] is empty |
| 1631 | 1631 | |
| 1632 | - }elseif( ( isset( $_GET['login'] ) ) ) { |
|
| 1632 | + }elseif ((isset($_GET['login']))) { |
|
| 1633 | 1633 | // else if this request is a redircect from a previously faile login request |
| 1634 | 1634 | $this->login_message_process(); |
| 1635 | 1635 | |
@@ -1648,87 +1648,87 @@ discard block |
||
| 1648 | 1648 | * @return void redirect |
| 1649 | 1649 | * |
| 1650 | 1650 | */ |
| 1651 | - public function sensei_process_registration(){ |
|
| 1651 | + public function sensei_process_registration() { |
|
| 1652 | 1652 | global $current_user; |
| 1653 | 1653 | // check the for the sensei specific registration requests |
| 1654 | - if( !isset( $_POST['sensei_reg_username'] ) && ! isset( $_POST['sensei_reg_email'] ) && !isset( $_POST['sensei_reg_password'] )){ |
|
| 1654 | + if ( ! isset($_POST['sensei_reg_username']) && ! isset($_POST['sensei_reg_email']) && ! isset($_POST['sensei_reg_password'])) { |
|
| 1655 | 1655 | // exit functionas this is not a sensei registration request |
| 1656 | - return ; |
|
| 1656 | + return; |
|
| 1657 | 1657 | } |
| 1658 | 1658 | // check for spam throw cheating huh |
| 1659 | - if( isset( $_POST['email_2'] ) && '' !== $_POST['email_2'] ){ |
|
| 1659 | + if (isset($_POST['email_2']) && '' !== $_POST['email_2']) { |
|
| 1660 | 1660 | $message = 'Error: The spam field should be empty'; |
| 1661 | - Sensei()->notices->add_notice( $message, 'alert'); |
|
| 1661 | + Sensei()->notices->add_notice($message, 'alert'); |
|
| 1662 | 1662 | return; |
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | // retreive form variables |
| 1666 | - $new_user_name = sanitize_user( $_POST['sensei_reg_username'] ); |
|
| 1667 | - $new_user_email = $_POST['sensei_reg_email']; |
|
| 1668 | - $new_user_password = $_POST['sensei_reg_password']; |
|
| 1666 | + $new_user_name = sanitize_user($_POST['sensei_reg_username']); |
|
| 1667 | + $new_user_email = $_POST['sensei_reg_email']; |
|
| 1668 | + $new_user_password = $_POST['sensei_reg_password']; |
|
| 1669 | 1669 | |
| 1670 | 1670 | // Check the username |
| 1671 | 1671 | $username_error_notice = ''; |
| 1672 | - if ( $new_user_name == '' ) { |
|
| 1673 | - $username_error_notice = __( '<strong>ERROR</strong>: Please enter a username.' ); |
|
| 1674 | - } elseif ( ! validate_username( $new_user_name ) ) { |
|
| 1675 | - $username_error_notice = __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ); |
|
| 1676 | - } elseif ( username_exists( $new_user_name ) ) { |
|
| 1677 | - $username_error_notice = __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ); |
|
| 1672 | + if ($new_user_name == '') { |
|
| 1673 | + $username_error_notice = __('<strong>ERROR</strong>: Please enter a username.'); |
|
| 1674 | + } elseif ( ! validate_username($new_user_name)) { |
|
| 1675 | + $username_error_notice = __('<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.'); |
|
| 1676 | + } elseif (username_exists($new_user_name)) { |
|
| 1677 | + $username_error_notice = __('<strong>ERROR</strong>: This username is already registered. Please choose another one.'); |
|
| 1678 | 1678 | } |
| 1679 | 1679 | |
| 1680 | 1680 | // exit on username error |
| 1681 | - if( '' !== $username_error_notice ){ |
|
| 1682 | - Sensei()->notices->add_notice( $username_error_notice , 'alert'); |
|
| 1681 | + if ('' !== $username_error_notice) { |
|
| 1682 | + Sensei()->notices->add_notice($username_error_notice, 'alert'); |
|
| 1683 | 1683 | return; |
| 1684 | 1684 | } |
| 1685 | 1685 | |
| 1686 | 1686 | // Check the e-mail address |
| 1687 | 1687 | $email_error_notice = ''; |
| 1688 | - if ( $new_user_email == '' ) { |
|
| 1689 | - $email_error_notice = __( '<strong>ERROR</strong>: Please type your e-mail address.' ); |
|
| 1690 | - } elseif ( ! is_email( $new_user_email ) ) { |
|
| 1691 | - $email_error_notice = __( '<strong>ERROR</strong>: The email address isn’t correct.' ); |
|
| 1692 | - } elseif ( email_exists( $new_user_email ) ) { |
|
| 1693 | - $email_error_notice = __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ); |
|
| 1688 | + if ($new_user_email == '') { |
|
| 1689 | + $email_error_notice = __('<strong>ERROR</strong>: Please type your e-mail address.'); |
|
| 1690 | + } elseif ( ! is_email($new_user_email)) { |
|
| 1691 | + $email_error_notice = __('<strong>ERROR</strong>: The email address isn’t correct.'); |
|
| 1692 | + } elseif (email_exists($new_user_email)) { |
|
| 1693 | + $email_error_notice = __('<strong>ERROR</strong>: This email is already registered, please choose another one.'); |
|
| 1694 | 1694 | } |
| 1695 | 1695 | |
| 1696 | 1696 | // exit on email address error |
| 1697 | - if( '' !== $email_error_notice ){ |
|
| 1698 | - Sensei()->notices->add_notice( $email_error_notice , 'alert'); |
|
| 1697 | + if ('' !== $email_error_notice) { |
|
| 1698 | + Sensei()->notices->add_notice($email_error_notice, 'alert'); |
|
| 1699 | 1699 | return; |
| 1700 | 1700 | } |
| 1701 | 1701 | |
| 1702 | 1702 | //check user password |
| 1703 | 1703 | |
| 1704 | 1704 | // exit on email address error |
| 1705 | - if( empty( $new_user_password ) ){ |
|
| 1706 | - Sensei()->notices->add_notice( __( '<strong>ERROR</strong>: The password field may not be empty, please enter a secure password.' ) , 'alert'); |
|
| 1705 | + if (empty($new_user_password)) { |
|
| 1706 | + Sensei()->notices->add_notice(__('<strong>ERROR</strong>: The password field may not be empty, please enter a secure password.'), 'alert'); |
|
| 1707 | 1707 | return; |
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | 1710 | // register user |
| 1711 | - $user_id = wp_create_user( $new_user_name, $new_user_password, $new_user_email ); |
|
| 1712 | - if ( ! $user_id || is_wp_error( $user_id ) ) { |
|
| 1713 | - Sensei()->notices->add_notice( sprintf( __( '<strong>ERROR</strong>: Couldn\'t register you… please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ), 'alert'); |
|
| 1711 | + $user_id = wp_create_user($new_user_name, $new_user_password, $new_user_email); |
|
| 1712 | + if ( ! $user_id || is_wp_error($user_id)) { |
|
| 1713 | + Sensei()->notices->add_notice(sprintf(__('<strong>ERROR</strong>: Couldn\'t register you… please contact the <a href="mailto:%s">webmaster</a> !'), get_option('admin_email')), 'alert'); |
|
| 1714 | 1714 | } |
| 1715 | 1715 | |
| 1716 | 1716 | // notify the user |
| 1717 | - wp_new_user_notification( $user_id, $new_user_password ); |
|
| 1717 | + wp_new_user_notification($user_id, $new_user_password); |
|
| 1718 | 1718 | |
| 1719 | 1719 | // set global current user aka log the user in |
| 1720 | - $current_user = get_user_by( 'id', $user_id ); |
|
| 1721 | - wp_set_auth_cookie( $user_id, true ); |
|
| 1720 | + $current_user = get_user_by('id', $user_id); |
|
| 1721 | + wp_set_auth_cookie($user_id, true); |
|
| 1722 | 1722 | |
| 1723 | 1723 | // Redirect |
| 1724 | 1724 | global $wp; |
| 1725 | - if ( wp_get_referer() ) { |
|
| 1726 | - $redirect = esc_url( wp_get_referer() ); |
|
| 1725 | + if (wp_get_referer()) { |
|
| 1726 | + $redirect = esc_url(wp_get_referer()); |
|
| 1727 | 1727 | } else { |
| 1728 | - $redirect = esc_url( home_url( $wp->request ) ); |
|
| 1728 | + $redirect = esc_url(home_url($wp->request)); |
|
| 1729 | 1729 | } |
| 1730 | 1730 | |
| 1731 | - wp_redirect( apply_filters( 'sensei_registration_redirect', $redirect ) ); |
|
| 1731 | + wp_redirect(apply_filters('sensei_registration_redirect', $redirect)); |
|
| 1732 | 1732 | exit; |
| 1733 | 1733 | |
| 1734 | 1734 | } // end sensei_process_registration)() |
@@ -1739,7 +1739,7 @@ discard block |
||
| 1739 | 1739 | * @return void redirect |
| 1740 | 1740 | * @since 1.7.0 |
| 1741 | 1741 | */ |
| 1742 | - public function login_message_process(){ |
|
| 1742 | + public function login_message_process() { |
|
| 1743 | 1743 | |
| 1744 | 1744 | |
| 1745 | 1745 | // setup the message variables |
@@ -1747,16 +1747,16 @@ discard block |
||
| 1747 | 1747 | |
| 1748 | 1748 | //only output message if the url contains login=failed and login=emptyfields |
| 1749 | 1749 | |
| 1750 | - if( $_GET['login'] == 'failed' ){ |
|
| 1750 | + if ($_GET['login'] == 'failed') { |
|
| 1751 | 1751 | |
| 1752 | - $message = __('Incorrect login details', 'woothemes-sensei' ); |
|
| 1752 | + $message = __('Incorrect login details', 'woothemes-sensei'); |
|
| 1753 | 1753 | |
| 1754 | - }elseif( $_GET['login'] == 'emptyfields' ){ |
|
| 1754 | + }elseif ($_GET['login'] == 'emptyfields') { |
|
| 1755 | 1755 | |
| 1756 | - $message= __('Please enter your username and password', 'woothemes-sensei' ); |
|
| 1756 | + $message = __('Please enter your username and password', 'woothemes-sensei'); |
|
| 1757 | 1757 | } |
| 1758 | 1758 | |
| 1759 | - Sensei()->notices->add_notice( $message, 'alert'); |
|
| 1759 | + Sensei()->notices->add_notice($message, 'alert'); |
|
| 1760 | 1760 | |
| 1761 | 1761 | }// end login_message_process |
| 1762 | 1762 | |
@@ -1768,11 +1768,11 @@ discard block |
||
| 1768 | 1768 | * @return void redirect |
| 1769 | 1769 | * |
| 1770 | 1770 | */ |
| 1771 | - public function sensei_show_admin_bar () { |
|
| 1771 | + public function sensei_show_admin_bar() { |
|
| 1772 | 1772 | |
| 1773 | 1773 | if (current_user_can('edit_courses')) { |
| 1774 | 1774 | |
| 1775 | - add_filter( 'woocommerce_disable_admin_bar', '__return_false', 10, 1); |
|
| 1775 | + add_filter('woocommerce_disable_admin_bar', '__return_false', 10, 1); |
|
| 1776 | 1776 | |
| 1777 | 1777 | } |
| 1778 | 1778 | |
@@ -1785,4 +1785,4 @@ discard block |
||
| 1785 | 1785 | * for backward compatibility |
| 1786 | 1786 | * @since 1.9.0 |
| 1787 | 1787 | */ |
| 1788 | -class WooThemes_Sensei_Frontend extends Sensei_Frontend{} |
|
| 1788 | +class WooThemes_Sensei_Frontend extends Sensei_Frontend {} |
|
@@ -15,91 +15,91 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class Sensei_Shortcode_User_Messages implements Sensei_Shortcode_Interface { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * @var WP_Query |
|
| 20 | - * messages for the current user |
|
| 21 | - */ |
|
| 22 | - protected $messages_query; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Setup the shortcode object |
|
| 26 | - * |
|
| 27 | - * @since 1.9.0 |
|
| 28 | - * @param array $attributes |
|
| 29 | - * @param string $content |
|
| 30 | - * @param string $shortcode the shortcode that was called for this instance |
|
| 31 | - */ |
|
| 32 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 33 | - |
|
| 34 | - $this->setup_messages_query(); |
|
| 35 | - |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * create the messages query . |
|
| 40 | - * |
|
| 41 | - * @return mixed |
|
| 42 | - */ |
|
| 43 | - public function setup_messages_query(){ |
|
| 44 | - |
|
| 45 | - $user = wp_get_current_user(); |
|
| 46 | - |
|
| 47 | - $args = array( |
|
| 48 | - 'post_type' => 'sensei_message', |
|
| 49 | - 'posts_per_page' => 500, |
|
| 50 | - 'orderby' => 'date', |
|
| 51 | - 'order' => 'DESC', |
|
| 52 | - 'post_status' => 'publish', |
|
| 53 | - 'meta_query' => array( |
|
| 54 | - array( |
|
| 55 | - 'key' => '_sender', |
|
| 56 | - 'value' => $user->user_login, |
|
| 57 | - 'compare' => '=', |
|
| 58 | - ), |
|
| 59 | - ), |
|
| 60 | - ); |
|
| 61 | - |
|
| 62 | - $this->messages_query = new WP_Query( $args ); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Rendering the shortcode this class is responsible for. |
|
| 67 | - * |
|
| 68 | - * @return string $content |
|
| 69 | - */ |
|
| 70 | - public function render(){ |
|
| 71 | - |
|
| 72 | - if( !is_user_logged_in() ){ |
|
| 73 | - |
|
| 74 | - Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert' ); |
|
| 75 | - |
|
| 76 | - } elseif( 0 == $this->messages_query->post_count ){ |
|
| 77 | - |
|
| 78 | - Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert' ); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $messages_disabled_in_settings = ! ( ! isset( Sensei()->settings->settings['messages_disable'] ) |
|
| 82 | - || ! Sensei()->settings->settings['messages_disable'] ) ; |
|
| 83 | - |
|
| 84 | - // don't show anything if messages are disable |
|
| 85 | - if( $messages_disabled_in_settings ){ |
|
| 86 | - return ''; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - //set the wp_query to the current messages query |
|
| 90 | - global $wp_query; |
|
| 91 | - $wp_query = $this->messages_query; |
|
| 92 | - |
|
| 93 | - ob_start(); |
|
| 94 | - Sensei()->notices->print_notices(); |
|
| 95 | - Sensei_Templates::get_part('loop', 'message'); |
|
| 96 | - $messages_html = ob_get_clean(); |
|
| 97 | - |
|
| 98 | - // set back the global query |
|
| 99 | - wp_reset_query(); |
|
| 100 | - |
|
| 101 | - return $messages_html; |
|
| 102 | - |
|
| 103 | - }// end render |
|
| 18 | + /** |
|
| 19 | + * @var WP_Query |
|
| 20 | + * messages for the current user |
|
| 21 | + */ |
|
| 22 | + protected $messages_query; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Setup the shortcode object |
|
| 26 | + * |
|
| 27 | + * @since 1.9.0 |
|
| 28 | + * @param array $attributes |
|
| 29 | + * @param string $content |
|
| 30 | + * @param string $shortcode the shortcode that was called for this instance |
|
| 31 | + */ |
|
| 32 | + public function __construct( $attributes, $content, $shortcode ){ |
|
| 33 | + |
|
| 34 | + $this->setup_messages_query(); |
|
| 35 | + |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * create the messages query . |
|
| 40 | + * |
|
| 41 | + * @return mixed |
|
| 42 | + */ |
|
| 43 | + public function setup_messages_query(){ |
|
| 44 | + |
|
| 45 | + $user = wp_get_current_user(); |
|
| 46 | + |
|
| 47 | + $args = array( |
|
| 48 | + 'post_type' => 'sensei_message', |
|
| 49 | + 'posts_per_page' => 500, |
|
| 50 | + 'orderby' => 'date', |
|
| 51 | + 'order' => 'DESC', |
|
| 52 | + 'post_status' => 'publish', |
|
| 53 | + 'meta_query' => array( |
|
| 54 | + array( |
|
| 55 | + 'key' => '_sender', |
|
| 56 | + 'value' => $user->user_login, |
|
| 57 | + 'compare' => '=', |
|
| 58 | + ), |
|
| 59 | + ), |
|
| 60 | + ); |
|
| 61 | + |
|
| 62 | + $this->messages_query = new WP_Query( $args ); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Rendering the shortcode this class is responsible for. |
|
| 67 | + * |
|
| 68 | + * @return string $content |
|
| 69 | + */ |
|
| 70 | + public function render(){ |
|
| 71 | + |
|
| 72 | + if( !is_user_logged_in() ){ |
|
| 73 | + |
|
| 74 | + Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert' ); |
|
| 75 | + |
|
| 76 | + } elseif( 0 == $this->messages_query->post_count ){ |
|
| 77 | + |
|
| 78 | + Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert' ); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $messages_disabled_in_settings = ! ( ! isset( Sensei()->settings->settings['messages_disable'] ) |
|
| 82 | + || ! Sensei()->settings->settings['messages_disable'] ) ; |
|
| 83 | + |
|
| 84 | + // don't show anything if messages are disable |
|
| 85 | + if( $messages_disabled_in_settings ){ |
|
| 86 | + return ''; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + //set the wp_query to the current messages query |
|
| 90 | + global $wp_query; |
|
| 91 | + $wp_query = $this->messages_query; |
|
| 92 | + |
|
| 93 | + ob_start(); |
|
| 94 | + Sensei()->notices->print_notices(); |
|
| 95 | + Sensei_Templates::get_part('loop', 'message'); |
|
| 96 | + $messages_html = ob_get_clean(); |
|
| 97 | + |
|
| 98 | + // set back the global query |
|
| 99 | + wp_reset_query(); |
|
| 100 | + |
|
| 101 | + return $messages_html; |
|
| 102 | + |
|
| 103 | + }// end render |
|
| 104 | 104 | |
| 105 | 105 | }// end class |
| 106 | 106 | \ 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. |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param string $content |
| 30 | 30 | * @param string $shortcode the shortcode that was called for this instance |
| 31 | 31 | */ |
| 32 | - public function __construct( $attributes, $content, $shortcode ){ |
|
| 32 | + public function __construct($attributes, $content, $shortcode) { |
|
| 33 | 33 | |
| 34 | 34 | $this->setup_messages_query(); |
| 35 | 35 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return mixed |
| 42 | 42 | */ |
| 43 | - public function setup_messages_query(){ |
|
| 43 | + public function setup_messages_query() { |
|
| 44 | 44 | |
| 45 | 45 | $user = wp_get_current_user(); |
| 46 | 46 | |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | ), |
| 60 | 60 | ); |
| 61 | 61 | |
| 62 | - $this->messages_query = new WP_Query( $args ); |
|
| 62 | + $this->messages_query = new WP_Query($args); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -67,22 +67,22 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @return string $content |
| 69 | 69 | */ |
| 70 | - public function render(){ |
|
| 70 | + public function render() { |
|
| 71 | 71 | |
| 72 | - if( !is_user_logged_in() ){ |
|
| 72 | + if ( ! is_user_logged_in()) { |
|
| 73 | 73 | |
| 74 | - Sensei()->notices->add_notice( __('Please login to view your messages.','woothemes-sensei') , 'alert' ); |
|
| 74 | + Sensei()->notices->add_notice(__('Please login to view your messages.', 'woothemes-sensei'), 'alert'); |
|
| 75 | 75 | |
| 76 | - } elseif( 0 == $this->messages_query->post_count ){ |
|
| 76 | + } elseif (0 == $this->messages_query->post_count) { |
|
| 77 | 77 | |
| 78 | - Sensei()->notices->add_notice( __( 'You do not have any messages.', 'woothemes-sensei') , 'alert' ); |
|
| 78 | + Sensei()->notices->add_notice(__('You do not have any messages.', 'woothemes-sensei'), 'alert'); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $messages_disabled_in_settings = ! ( ! isset( Sensei()->settings->settings['messages_disable'] ) |
|
| 82 | - || ! Sensei()->settings->settings['messages_disable'] ) ; |
|
| 81 | + $messages_disabled_in_settings = ! ( ! isset(Sensei()->settings->settings['messages_disable']) |
|
| 82 | + || ! Sensei()->settings->settings['messages_disable']); |
|
| 83 | 83 | |
| 84 | 84 | // don't show anything if messages are disable |
| 85 | - if( $messages_disabled_in_settings ){ |
|
| 85 | + if ($messages_disabled_in_settings) { |
|
| 86 | 86 | return ''; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -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_Student::get_full_name( $item->ID ); |
|
| 426 | - } |
|
| 425 | + $user_name = Sensei_Student::get_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,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_Student::get_full_name( $item->ID ); |
|
| 424 | + if ($this->csv_output) { |
|
| 425 | + $user_name = Sensei_Student::get_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 | |
@@ -14,251 +14,251 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class Sensei_Teacher { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * $teacher_role |
|
| 19 | - * |
|
| 20 | - * Keeps a reference to the teacher role object |
|
| 21 | - * |
|
| 22 | - * @access protected |
|
| 23 | - * @since 1.8.0 |
|
| 24 | - */ |
|
| 25 | - protected $teacher_role; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * $token |
|
| 29 | - * |
|
| 30 | - * Keeps a reference to the global sensei token |
|
| 31 | - * |
|
| 32 | - * @access protected |
|
| 33 | - * @since 1.8.0 |
|
| 34 | - */ |
|
| 35 | - public $token; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Sensei_Teacher::__constructor |
|
| 39 | - * |
|
| 40 | - * Constructor Function |
|
| 41 | - * |
|
| 42 | - * @since 1.8.0 |
|
| 43 | - * @access public |
|
| 44 | - */ |
|
| 45 | - public function __construct ( ) { |
|
| 46 | - |
|
| 47 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 52 | - |
|
| 53 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 54 | - |
|
| 55 | - //filter the quiz submissions |
|
| 56 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 57 | - |
|
| 58 | - //grading totals count only those belonging to the teacher |
|
| 59 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 60 | - |
|
| 61 | - // show the courses owned by a user on his author archive page |
|
| 62 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 63 | - |
|
| 64 | - // notify admin when a teacher creates a course |
|
| 65 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 66 | - |
|
| 67 | - // limit the analysis view to only the users taking courses belong to this teacher |
|
| 68 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 69 | - |
|
| 70 | - // give teacher access to question post type |
|
| 71 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 72 | - |
|
| 73 | - // Teacher column on the courses list on the admin edit screen |
|
| 74 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 76 | - |
|
| 77 | - //admin edit messages query limit teacher |
|
| 78 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 79 | - |
|
| 80 | - //add filter by teacher on courses list |
|
| 81 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 83 | - |
|
| 84 | - // Handle media library restrictions |
|
| 85 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 87 | - |
|
| 88 | - // update lesson owner to course teacher when saved |
|
| 89 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 90 | - |
|
| 91 | - // If a Teacher logs in, redirect to /wp-admin/ |
|
| 92 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - } // end __constructor() |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Sensei_Teacher::create_teacher_role |
|
| 103 | - * |
|
| 104 | - * This function checks if the role exist, if not it creates it. |
|
| 105 | - * for the teacher role |
|
| 106 | - * |
|
| 107 | - * @since 1.8.0 |
|
| 108 | - * @access public |
|
| 109 | - * @return void |
|
| 110 | - */ |
|
| 111 | - public function create_role ( ) { |
|
| 112 | - |
|
| 113 | - // check if the role exists |
|
| 114 | - $this->teacher_role = get_role( 'teacher' ); |
|
| 115 | - |
|
| 116 | - // if the the teacher is not a valid WordPress role create it |
|
| 117 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 118 | - // create the role |
|
| 119 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // add the capabilities before returning |
|
| 123 | - $this->add_capabilities(); |
|
| 124 | - |
|
| 125 | - }// end create_teacher_role |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Sensei_Teacher::add_capabilities |
|
| 129 | - * |
|
| 130 | - * @since 1.8.0 |
|
| 131 | - * @access protected |
|
| 132 | - */ |
|
| 133 | - protected function add_capabilities ( ) { |
|
| 134 | - |
|
| 135 | - // if this is not a valid WP_Role object exit without adding anything |
|
| 136 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Sensei teachers capabilities array filter |
|
| 142 | - * |
|
| 143 | - * These capabilities will be applied to the teacher role |
|
| 144 | - * @param array $capabilities |
|
| 145 | - * keys: (string) $cap_name => (bool) $grant |
|
| 146 | - */ |
|
| 147 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 148 | - // General access rules |
|
| 149 | - 'read' => true, |
|
| 150 | - 'manage_sensei_grades' => true, |
|
| 151 | - 'moderate_comments'=> true, |
|
| 152 | - 'upload_files' => true, |
|
| 153 | - 'edit_files' => true, |
|
| 154 | - |
|
| 155 | - //Lessons |
|
| 156 | - 'publish_lessons' => true, |
|
| 157 | - 'manage_lesson_categories' => true, |
|
| 158 | - 'edit_lessons' => true, |
|
| 159 | - 'edit_published_lessons' => true, |
|
| 160 | - 'edit_private_lessons' => true, |
|
| 161 | - 'read_private_lessons' => true, |
|
| 162 | - 'delete_published_lessons' => true, |
|
| 163 | - |
|
| 164 | - // Courses |
|
| 165 | - 'create_courses' => true, |
|
| 166 | - 'publish_courses' => false, |
|
| 167 | - 'manage_course_categories' => true, |
|
| 168 | - 'edit_courses' => true, |
|
| 169 | - 'edit_published_courses' => true, |
|
| 170 | - 'edit_private_courses' => true, |
|
| 171 | - 'read_private_courses' => true, |
|
| 172 | - 'delete_published_courses' => true, |
|
| 173 | - |
|
| 174 | - // Quiz |
|
| 175 | - 'publish_quizzes' => true, |
|
| 176 | - 'edit_quizzes' => true, |
|
| 177 | - 'edit_published_quizzes' => true, |
|
| 178 | - 'edit_private_quizzes' => true, |
|
| 179 | - 'read_private_quizzes' => true, |
|
| 180 | - |
|
| 181 | - // Questions |
|
| 182 | - 'publish_questions' => true, |
|
| 183 | - 'edit_questions' => true, |
|
| 184 | - 'edit_published_questions' => true, |
|
| 185 | - 'edit_private_questions' => true, |
|
| 186 | - 'read_private_questions' => true, |
|
| 187 | - |
|
| 188 | - //messages |
|
| 189 | - 'publish_sensei_messages' => true, |
|
| 190 | - 'edit_sensei_messages' => true, |
|
| 191 | - 'edit_published_sensei_messages' => true, |
|
| 192 | - 'edit_private_sensei_messages' => true, |
|
| 193 | - 'read_private_sensei_messages' => true, |
|
| 194 | - |
|
| 195 | - // Comments - |
|
| 196 | - // Necessary cap so Teachers can moderate comments |
|
| 197 | - // on their own lessons. We restrict access to other |
|
| 198 | - // post types in $this->restrict_posts_menu_page() |
|
| 199 | - |
|
| 200 | - 'edit_posts' => true, |
|
| 201 | - |
|
| 202 | - )); |
|
| 203 | - |
|
| 204 | - foreach ( $caps as $cap => $grant ) { |
|
| 205 | - |
|
| 206 | - // load the capability on to the teacher role |
|
| 207 | - $this->teacher_role->add_cap($cap, $grant); |
|
| 208 | - |
|
| 209 | - } // end for each |
|
| 210 | - |
|
| 211 | - }// end add_cap |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Sensei_Teacher::teacher_meta_box |
|
| 215 | - * |
|
| 216 | - * Add the teacher metabox to the course post type edit screen |
|
| 217 | - * |
|
| 218 | - * @since 1.8.0 |
|
| 219 | - * @access public |
|
| 220 | - * @parameter string $post_type |
|
| 221 | - * @parameter WP_Post $post |
|
| 222 | - * @return void |
|
| 223 | - */ |
|
| 224 | - public function add_teacher_meta_boxes ( $post ) { |
|
| 225 | - |
|
| 226 | - if( !current_user_can('manage_options') ){ |
|
| 227 | - return; |
|
| 228 | - } |
|
| 229 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
| 230 | - 'course', |
|
| 231 | - 'side', |
|
| 232 | - 'core' |
|
| 233 | - ); |
|
| 234 | - |
|
| 235 | - } // end teacher_meta_box() |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Sensei_Teacher::teacher_meta_box_content |
|
| 239 | - * |
|
| 240 | - * Render the teacher meta box markup |
|
| 241 | - * |
|
| 242 | - * @since 1.8.0 |
|
| 243 | - * @access public |
|
| 244 | - * @parameters |
|
| 245 | - */ |
|
| 246 | - public function teacher_meta_box_content ( $post ) { |
|
| 247 | - |
|
| 248 | - // get the current author |
|
| 249 | - $current_author = $post->post_author; |
|
| 250 | - |
|
| 251 | - //get the users authorised to author courses |
|
| 252 | - $users = $this->get_teachers_and_authors(); |
|
| 253 | - |
|
| 254 | - ?> |
|
| 17 | + /** |
|
| 18 | + * $teacher_role |
|
| 19 | + * |
|
| 20 | + * Keeps a reference to the teacher role object |
|
| 21 | + * |
|
| 22 | + * @access protected |
|
| 23 | + * @since 1.8.0 |
|
| 24 | + */ |
|
| 25 | + protected $teacher_role; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * $token |
|
| 29 | + * |
|
| 30 | + * Keeps a reference to the global sensei token |
|
| 31 | + * |
|
| 32 | + * @access protected |
|
| 33 | + * @since 1.8.0 |
|
| 34 | + */ |
|
| 35 | + public $token; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Sensei_Teacher::__constructor |
|
| 39 | + * |
|
| 40 | + * Constructor Function |
|
| 41 | + * |
|
| 42 | + * @since 1.8.0 |
|
| 43 | + * @access public |
|
| 44 | + */ |
|
| 45 | + public function __construct ( ) { |
|
| 46 | + |
|
| 47 | + add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | + add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | + add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | + add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | + add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 52 | + |
|
| 53 | + add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 54 | + |
|
| 55 | + //filter the quiz submissions |
|
| 56 | + add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 57 | + |
|
| 58 | + //grading totals count only those belonging to the teacher |
|
| 59 | + add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 60 | + |
|
| 61 | + // show the courses owned by a user on his author archive page |
|
| 62 | + add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 63 | + |
|
| 64 | + // notify admin when a teacher creates a course |
|
| 65 | + add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 66 | + |
|
| 67 | + // limit the analysis view to only the users taking courses belong to this teacher |
|
| 68 | + add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 69 | + |
|
| 70 | + // give teacher access to question post type |
|
| 71 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 72 | + |
|
| 73 | + // Teacher column on the courses list on the admin edit screen |
|
| 74 | + add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | + add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 76 | + |
|
| 77 | + //admin edit messages query limit teacher |
|
| 78 | + add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 79 | + |
|
| 80 | + //add filter by teacher on courses list |
|
| 81 | + add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | + add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 83 | + |
|
| 84 | + // Handle media library restrictions |
|
| 85 | + add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | + add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 87 | + |
|
| 88 | + // update lesson owner to course teacher when saved |
|
| 89 | + add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 90 | + |
|
| 91 | + // If a Teacher logs in, redirect to /wp-admin/ |
|
| 92 | + add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | + add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + } // end __constructor() |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Sensei_Teacher::create_teacher_role |
|
| 103 | + * |
|
| 104 | + * This function checks if the role exist, if not it creates it. |
|
| 105 | + * for the teacher role |
|
| 106 | + * |
|
| 107 | + * @since 1.8.0 |
|
| 108 | + * @access public |
|
| 109 | + * @return void |
|
| 110 | + */ |
|
| 111 | + public function create_role ( ) { |
|
| 112 | + |
|
| 113 | + // check if the role exists |
|
| 114 | + $this->teacher_role = get_role( 'teacher' ); |
|
| 115 | + |
|
| 116 | + // if the the teacher is not a valid WordPress role create it |
|
| 117 | + if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 118 | + // create the role |
|
| 119 | + $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // add the capabilities before returning |
|
| 123 | + $this->add_capabilities(); |
|
| 124 | + |
|
| 125 | + }// end create_teacher_role |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Sensei_Teacher::add_capabilities |
|
| 129 | + * |
|
| 130 | + * @since 1.8.0 |
|
| 131 | + * @access protected |
|
| 132 | + */ |
|
| 133 | + protected function add_capabilities ( ) { |
|
| 134 | + |
|
| 135 | + // if this is not a valid WP_Role object exit without adding anything |
|
| 136 | + if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Sensei teachers capabilities array filter |
|
| 142 | + * |
|
| 143 | + * These capabilities will be applied to the teacher role |
|
| 144 | + * @param array $capabilities |
|
| 145 | + * keys: (string) $cap_name => (bool) $grant |
|
| 146 | + */ |
|
| 147 | + $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 148 | + // General access rules |
|
| 149 | + 'read' => true, |
|
| 150 | + 'manage_sensei_grades' => true, |
|
| 151 | + 'moderate_comments'=> true, |
|
| 152 | + 'upload_files' => true, |
|
| 153 | + 'edit_files' => true, |
|
| 154 | + |
|
| 155 | + //Lessons |
|
| 156 | + 'publish_lessons' => true, |
|
| 157 | + 'manage_lesson_categories' => true, |
|
| 158 | + 'edit_lessons' => true, |
|
| 159 | + 'edit_published_lessons' => true, |
|
| 160 | + 'edit_private_lessons' => true, |
|
| 161 | + 'read_private_lessons' => true, |
|
| 162 | + 'delete_published_lessons' => true, |
|
| 163 | + |
|
| 164 | + // Courses |
|
| 165 | + 'create_courses' => true, |
|
| 166 | + 'publish_courses' => false, |
|
| 167 | + 'manage_course_categories' => true, |
|
| 168 | + 'edit_courses' => true, |
|
| 169 | + 'edit_published_courses' => true, |
|
| 170 | + 'edit_private_courses' => true, |
|
| 171 | + 'read_private_courses' => true, |
|
| 172 | + 'delete_published_courses' => true, |
|
| 173 | + |
|
| 174 | + // Quiz |
|
| 175 | + 'publish_quizzes' => true, |
|
| 176 | + 'edit_quizzes' => true, |
|
| 177 | + 'edit_published_quizzes' => true, |
|
| 178 | + 'edit_private_quizzes' => true, |
|
| 179 | + 'read_private_quizzes' => true, |
|
| 180 | + |
|
| 181 | + // Questions |
|
| 182 | + 'publish_questions' => true, |
|
| 183 | + 'edit_questions' => true, |
|
| 184 | + 'edit_published_questions' => true, |
|
| 185 | + 'edit_private_questions' => true, |
|
| 186 | + 'read_private_questions' => true, |
|
| 187 | + |
|
| 188 | + //messages |
|
| 189 | + 'publish_sensei_messages' => true, |
|
| 190 | + 'edit_sensei_messages' => true, |
|
| 191 | + 'edit_published_sensei_messages' => true, |
|
| 192 | + 'edit_private_sensei_messages' => true, |
|
| 193 | + 'read_private_sensei_messages' => true, |
|
| 194 | + |
|
| 195 | + // Comments - |
|
| 196 | + // Necessary cap so Teachers can moderate comments |
|
| 197 | + // on their own lessons. We restrict access to other |
|
| 198 | + // post types in $this->restrict_posts_menu_page() |
|
| 199 | + |
|
| 200 | + 'edit_posts' => true, |
|
| 201 | + |
|
| 202 | + )); |
|
| 203 | + |
|
| 204 | + foreach ( $caps as $cap => $grant ) { |
|
| 205 | + |
|
| 206 | + // load the capability on to the teacher role |
|
| 207 | + $this->teacher_role->add_cap($cap, $grant); |
|
| 208 | + |
|
| 209 | + } // end for each |
|
| 210 | + |
|
| 211 | + }// end add_cap |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Sensei_Teacher::teacher_meta_box |
|
| 215 | + * |
|
| 216 | + * Add the teacher metabox to the course post type edit screen |
|
| 217 | + * |
|
| 218 | + * @since 1.8.0 |
|
| 219 | + * @access public |
|
| 220 | + * @parameter string $post_type |
|
| 221 | + * @parameter WP_Post $post |
|
| 222 | + * @return void |
|
| 223 | + */ |
|
| 224 | + public function add_teacher_meta_boxes ( $post ) { |
|
| 225 | + |
|
| 226 | + if( !current_user_can('manage_options') ){ |
|
| 227 | + return; |
|
| 228 | + } |
|
| 229 | + add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
| 230 | + 'course', |
|
| 231 | + 'side', |
|
| 232 | + 'core' |
|
| 233 | + ); |
|
| 234 | + |
|
| 235 | + } // end teacher_meta_box() |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Sensei_Teacher::teacher_meta_box_content |
|
| 239 | + * |
|
| 240 | + * Render the teacher meta box markup |
|
| 241 | + * |
|
| 242 | + * @since 1.8.0 |
|
| 243 | + * @access public |
|
| 244 | + * @parameters |
|
| 245 | + */ |
|
| 246 | + public function teacher_meta_box_content ( $post ) { |
|
| 247 | + |
|
| 248 | + // get the current author |
|
| 249 | + $current_author = $post->post_author; |
|
| 250 | + |
|
| 251 | + //get the users authorised to author courses |
|
| 252 | + $users = $this->get_teachers_and_authors(); |
|
| 253 | + |
|
| 254 | + ?> |
|
| 255 | 255 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
| 256 | 256 | |
| 257 | 257 | <?php foreach ( $users as $user_id ) { ?> |
| 258 | 258 | |
| 259 | 259 | <?php |
| 260 | - $user = get_user_by('id', $user_id); |
|
| 261 | - ?> |
|
| 260 | + $user = get_user_by('id', $user_id); |
|
| 261 | + ?> |
|
| 262 | 262 | <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
| 263 | 263 | <?php echo $user->display_name; ?> |
| 264 | 264 | </option> |
@@ -269,1289 +269,1289 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | <?php |
| 271 | 271 | |
| 272 | - } // end render_teacher_meta_box() |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Sensei_Teacher::get_teachers_and_authors |
|
| 276 | - * |
|
| 277 | - * Get a list of users who can author courses, lessons and quizes. |
|
| 278 | - * |
|
| 279 | - * @since 1.8.0 |
|
| 280 | - * @access public |
|
| 281 | - * @parameters |
|
| 282 | - * @return array $users user id array |
|
| 283 | - */ |
|
| 284 | - public function get_teachers_and_authors ( ){ |
|
| 285 | - |
|
| 286 | - $author_query_args = array( |
|
| 287 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 288 | - 'fields' => 'any', |
|
| 289 | - 'who' => 'authors' |
|
| 290 | - ); |
|
| 291 | - |
|
| 292 | - $authors = get_users( $author_query_args ); |
|
| 293 | - |
|
| 294 | - $teacher_query_args = array( |
|
| 295 | - 'blog_id' => $GLOBALS['blog_id'], |
|
| 296 | - 'fields' => 'any', |
|
| 297 | - 'role' => 'teacher', |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - $teachers = get_users( $teacher_query_args ); |
|
| 301 | - |
|
| 302 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
| 303 | - |
|
| 304 | - }// end get_teachers_and_authors |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Sensei_Teacher::save_teacher_meta_box |
|
| 308 | - * |
|
| 309 | - * Save the new teacher / author to course and all lessons |
|
| 310 | - * |
|
| 311 | - * Hooked into admin_init |
|
| 312 | - * |
|
| 313 | - * @since 1.8.0 |
|
| 314 | - * @access public |
|
| 315 | - * @parameters |
|
| 316 | - * @return array $users user id array |
|
| 317 | - */ |
|
| 318 | - public function save_teacher_meta_box ( $course_id ){ |
|
| 272 | + } // end render_teacher_meta_box() |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Sensei_Teacher::get_teachers_and_authors |
|
| 276 | + * |
|
| 277 | + * Get a list of users who can author courses, lessons and quizes. |
|
| 278 | + * |
|
| 279 | + * @since 1.8.0 |
|
| 280 | + * @access public |
|
| 281 | + * @parameters |
|
| 282 | + * @return array $users user id array |
|
| 283 | + */ |
|
| 284 | + public function get_teachers_and_authors ( ){ |
|
| 285 | + |
|
| 286 | + $author_query_args = array( |
|
| 287 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 288 | + 'fields' => 'any', |
|
| 289 | + 'who' => 'authors' |
|
| 290 | + ); |
|
| 291 | + |
|
| 292 | + $authors = get_users( $author_query_args ); |
|
| 293 | + |
|
| 294 | + $teacher_query_args = array( |
|
| 295 | + 'blog_id' => $GLOBALS['blog_id'], |
|
| 296 | + 'fields' => 'any', |
|
| 297 | + 'role' => 'teacher', |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + $teachers = get_users( $teacher_query_args ); |
|
| 301 | + |
|
| 302 | + return array_unique( array_merge( $teachers, $authors ) ); |
|
| 303 | + |
|
| 304 | + }// end get_teachers_and_authors |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Sensei_Teacher::save_teacher_meta_box |
|
| 308 | + * |
|
| 309 | + * Save the new teacher / author to course and all lessons |
|
| 310 | + * |
|
| 311 | + * Hooked into admin_init |
|
| 312 | + * |
|
| 313 | + * @since 1.8.0 |
|
| 314 | + * @access public |
|
| 315 | + * @parameters |
|
| 316 | + * @return array $users user id array |
|
| 317 | + */ |
|
| 318 | + public function save_teacher_meta_box ( $course_id ){ |
|
| 319 | 319 | |
| 320 | - // check if this is a post from saving the teacher, if not exit early |
|
| 321 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 322 | - return; |
|
| 323 | - } |
|
| 320 | + // check if this is a post from saving the teacher, if not exit early |
|
| 321 | + if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 322 | + return; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - //don't fire this hook again |
|
| 326 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 325 | + //don't fire this hook again |
|
| 326 | + remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 327 | 327 | |
| 328 | - // get the current post object |
|
| 329 | - $post = get_post( $course_id ); |
|
| 328 | + // get the current post object |
|
| 329 | + $post = get_post( $course_id ); |
|
| 330 | 330 | |
| 331 | - // get the current teacher/author |
|
| 332 | - $current_author = absint( $post->post_author ); |
|
| 333 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 331 | + // get the current teacher/author |
|
| 332 | + $current_author = absint( $post->post_author ); |
|
| 333 | + $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 334 | 334 | |
| 335 | - // loop through all post lessons to update their authors as well |
|
| 336 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 335 | + // loop through all post lessons to update their authors as well |
|
| 336 | + $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 337 | 337 | |
| 338 | - // do not do any processing if the selected author is the same as the current author |
|
| 339 | - if( $current_author == $new_author ){ |
|
| 340 | - return; |
|
| 341 | - } |
|
| 338 | + // do not do any processing if the selected author is the same as the current author |
|
| 339 | + if( $current_author == $new_author ){ |
|
| 340 | + return; |
|
| 341 | + } |
|
| 342 | 342 | |
| 343 | - // save the course author |
|
| 344 | - $post_updates = array( |
|
| 345 | - 'ID' => $post->ID , |
|
| 346 | - 'post_author' => $new_author |
|
| 347 | - ); |
|
| 348 | - wp_update_post( $post_updates ); |
|
| 343 | + // save the course author |
|
| 344 | + $post_updates = array( |
|
| 345 | + 'ID' => $post->ID , |
|
| 346 | + 'post_author' => $new_author |
|
| 347 | + ); |
|
| 348 | + wp_update_post( $post_updates ); |
|
| 349 | 349 | |
| 350 | - // ensure the the modules are update so that then new teacher has access to them |
|
| 351 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 350 | + // ensure the the modules are update so that then new teacher has access to them |
|
| 351 | + Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 352 | 352 | |
| 353 | - // notify the new teacher |
|
| 354 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 353 | + // notify the new teacher |
|
| 354 | + $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 355 | 355 | |
| 356 | - } // end save_teacher_meta_box |
|
| 356 | + } // end save_teacher_meta_box |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 360 | - * the new author. Making sure the course terms are maintained. |
|
| 361 | - * |
|
| 362 | - * This function also checks if terms are shared, with other courses |
|
| 363 | - * |
|
| 364 | - * @param $course_id |
|
| 365 | - * @param $new_teacher_id |
|
| 366 | - * @return void |
|
| 367 | - */ |
|
| 368 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 358 | + /** |
|
| 359 | + * Update all the course terms set(selected) on the given course. Moving course term ownership to |
|
| 360 | + * the new author. Making sure the course terms are maintained. |
|
| 361 | + * |
|
| 362 | + * This function also checks if terms are shared, with other courses |
|
| 363 | + * |
|
| 364 | + * @param $course_id |
|
| 365 | + * @param $new_teacher_id |
|
| 366 | + * @return void |
|
| 367 | + */ |
|
| 368 | + public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 369 | 369 | |
| 370 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 371 | - return false; |
|
| 372 | - } |
|
| 370 | + if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 371 | + return false; |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 374 | + $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 375 | 375 | |
| 376 | - if( empty( $terms_selected_on_course ) ){ |
|
| 377 | - return; |
|
| 378 | - } |
|
| 376 | + if( empty( $terms_selected_on_course ) ){ |
|
| 377 | + return; |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - foreach( $terms_selected_on_course as $term ){ |
|
| 380 | + foreach( $terms_selected_on_course as $term ){ |
|
| 381 | 381 | |
| 382 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | - if( $new_teacher_id != $term_author->ID ){ |
|
| 382 | + $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | + if( $new_teacher_id != $term_author->ID ){ |
|
| 384 | 384 | |
| 385 | - $new_term = ''; |
|
| 385 | + $new_term = ''; |
|
| 386 | 386 | |
| 387 | - //if the new teacher is admin first check to see if the term with this name already exists |
|
| 388 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 387 | + //if the new teacher is admin first check to see if the term with this name already exists |
|
| 388 | + if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 389 | 389 | |
| 390 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | - if( !empty( $existing_admin_terms ) ){ |
|
| 394 | - // insert it even if it exists |
|
| 395 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 396 | - } |
|
| 397 | - } |
|
| 390 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | + $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | + $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | + if( !empty( $existing_admin_terms ) ){ |
|
| 394 | + // insert it even if it exists |
|
| 395 | + $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - if( empty ( $new_term ) ){ |
|
| 399 | + if( empty ( $new_term ) ){ |
|
| 400 | 400 | |
| 401 | - //setup the new slug |
|
| 402 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 403 | - |
|
| 404 | - // create new term and set it |
|
| 405 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 406 | - |
|
| 407 | - } |
|
| 401 | + //setup the new slug |
|
| 402 | + $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 403 | + |
|
| 404 | + // create new term and set it |
|
| 405 | + $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 406 | + |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | 410 | |
| 411 | - // if term exists |
|
| 412 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 411 | + // if term exists |
|
| 412 | + if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 413 | 413 | |
| 414 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 415 | - $term_id = $existing_term->term_id; |
|
| 414 | + $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 415 | + $term_id = $existing_term->term_id; |
|
| 416 | 416 | |
| 417 | - }else{ |
|
| 417 | + }else{ |
|
| 418 | 418 | |
| 419 | - // for a new term simply get the term from the returned value |
|
| 420 | - $term_id = $new_term['term_id']; |
|
| 419 | + // for a new term simply get the term from the returned value |
|
| 420 | + $term_id = $new_term['term_id']; |
|
| 421 | 421 | |
| 422 | - } // end if term exist |
|
| 422 | + } // end if term exist |
|
| 423 | 423 | |
| 424 | - // set the terms selected on the course |
|
| 425 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 424 | + // set the terms selected on the course |
|
| 425 | + wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 426 | 426 | |
| 427 | - // remove old term |
|
| 428 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 427 | + // remove old term |
|
| 428 | + wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 429 | 429 | |
| 430 | - // update the lessons within the current module term |
|
| 431 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | - foreach( $lessons as $lesson ){ |
|
| 430 | + // update the lessons within the current module term |
|
| 431 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | + foreach( $lessons as $lesson ){ |
|
| 433 | 433 | |
| 434 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 434 | + if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 435 | 435 | |
| 436 | - // add the new term, the false at the end says to replace all terms on this module |
|
| 437 | - // with the new term. |
|
| 438 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 440 | - } |
|
| 436 | + // add the new term, the false at the end says to replace all terms on this module |
|
| 437 | + // with the new term. |
|
| 438 | + wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | + update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - }// end for each |
|
| 442 | + }// end for each |
|
| 443 | 443 | |
| 444 | - } |
|
| 445 | - } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | 446 | |
| 447 | - }// end update_course_module_terms_author |
|
| 447 | + }// end update_course_module_terms_author |
|
| 448 | 448 | |
| 449 | - /** |
|
| 450 | - * Sensei_Teacher::update_course_lessons_author |
|
| 451 | - * |
|
| 452 | - * Update all course lessons and their quiz with a new author |
|
| 453 | - * |
|
| 454 | - * @since 1.8.0 |
|
| 455 | - * @access public |
|
| 456 | - * @parameters |
|
| 457 | - * @return array $users user id array |
|
| 458 | - */ |
|
| 459 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 449 | + /** |
|
| 450 | + * Sensei_Teacher::update_course_lessons_author |
|
| 451 | + * |
|
| 452 | + * Update all course lessons and their quiz with a new author |
|
| 453 | + * |
|
| 454 | + * @since 1.8.0 |
|
| 455 | + * @access public |
|
| 456 | + * @parameters |
|
| 457 | + * @return array $users user id array |
|
| 458 | + */ |
|
| 459 | + public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 460 | 460 | |
| 461 | 461 | |
| 462 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 463 | - return false; |
|
| 464 | - } |
|
| 462 | + if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 463 | + return false; |
|
| 464 | + } |
|
| 465 | 465 | |
| 466 | - //get a list of course lessons |
|
| 467 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 466 | + //get a list of course lessons |
|
| 467 | + $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 468 | 468 | |
| 469 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 470 | - return false; |
|
| 471 | - } |
|
| 469 | + if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 470 | + return false; |
|
| 471 | + } |
|
| 472 | 472 | |
| 473 | - // update each lesson and quiz author |
|
| 474 | - foreach( $lessons as $lesson ){ |
|
| 473 | + // update each lesson and quiz author |
|
| 474 | + foreach( $lessons as $lesson ){ |
|
| 475 | 475 | |
| 476 | - // don't update if the author is tha same as the new author |
|
| 477 | - if( $new_author == $lesson->post_author ){ |
|
| 478 | - continue; |
|
| 479 | - } |
|
| 476 | + // don't update if the author is tha same as the new author |
|
| 477 | + if( $new_author == $lesson->post_author ){ |
|
| 478 | + continue; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - // update lesson author |
|
| 482 | - wp_update_post( array( |
|
| 483 | - 'ID'=> $lesson->ID, |
|
| 484 | - 'post_author' => $new_author |
|
| 485 | - ) ); |
|
| 481 | + // update lesson author |
|
| 482 | + wp_update_post( array( |
|
| 483 | + 'ID'=> $lesson->ID, |
|
| 484 | + 'post_author' => $new_author |
|
| 485 | + ) ); |
|
| 486 | 486 | |
| 487 | - // update quiz author |
|
| 488 | - //get the lessons quiz |
|
| 489 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | - if( is_array( $lesson_quizzes ) ){ |
|
| 491 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 492 | - // update quiz with new author |
|
| 493 | - wp_update_post( array( |
|
| 494 | - 'ID' => $quiz_id, |
|
| 495 | - 'post_author' => $new_author |
|
| 496 | - ) ); |
|
| 497 | - } |
|
| 498 | - }else{ |
|
| 499 | - wp_update_post( array( |
|
| 500 | - 'ID' => $lesson_quizzes, |
|
| 501 | - 'post_author' => $new_author |
|
| 502 | - ) ); |
|
| 503 | - } |
|
| 487 | + // update quiz author |
|
| 488 | + //get the lessons quiz |
|
| 489 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | + if( is_array( $lesson_quizzes ) ){ |
|
| 491 | + foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 492 | + // update quiz with new author |
|
| 493 | + wp_update_post( array( |
|
| 494 | + 'ID' => $quiz_id, |
|
| 495 | + 'post_author' => $new_author |
|
| 496 | + ) ); |
|
| 497 | + } |
|
| 498 | + }else{ |
|
| 499 | + wp_update_post( array( |
|
| 500 | + 'ID' => $lesson_quizzes, |
|
| 501 | + 'post_author' => $new_author |
|
| 502 | + ) ); |
|
| 503 | + } |
|
| 504 | 504 | |
| 505 | - } // end for each lessons |
|
| 505 | + } // end for each lessons |
|
| 506 | 506 | |
| 507 | - return true; |
|
| 507 | + return true; |
|
| 508 | 508 | |
| 509 | - }// end update_course_lessons_author |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 515 | - * |
|
| 516 | - * Alter the query so that users can only see their courses on the analysis page |
|
| 517 | - * |
|
| 518 | - * @since 1.8.0 |
|
| 519 | - * @access public |
|
| 520 | - * @parameters $query |
|
| 521 | - * @return array $users user id array |
|
| 522 | - */ |
|
| 523 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
| 524 | - |
|
| 525 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 526 | - return $query; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 530 | - return $query; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $screen = get_current_screen(); |
|
| 534 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 535 | - |
|
| 536 | - // exit early for the following conditions |
|
| 537 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 538 | - |
|
| 539 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 541 | - return $query; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - global $current_user; |
|
| 545 | - // set the query author to the current user to only show those those posts |
|
| 546 | - $query->set( 'author', $current_user->ID ); |
|
| 547 | - return $query; |
|
| 548 | - |
|
| 549 | - }// end course_analysis_teacher_access_limit |
|
| 550 | - |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 554 | - * |
|
| 555 | - * Determine if we're in admin and the current logged in use is a teacher |
|
| 556 | - * |
|
| 557 | - * @since 1.8.0 |
|
| 558 | - * @access public |
|
| 559 | - * @parameters array $wp_query |
|
| 560 | - * @return bool $is_admin_teacher |
|
| 561 | - */ |
|
| 562 | - public function is_admin_teacher ( ){ |
|
| 563 | - |
|
| 564 | - if( ! is_user_logged_in()){ |
|
| 565 | - return false; |
|
| 566 | - } |
|
| 567 | - $is_admin_teacher = false; |
|
| 568 | - |
|
| 569 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 570 | - |
|
| 571 | - $is_admin_teacher = true; |
|
| 572 | - |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return $is_admin_teacher; |
|
| 576 | - |
|
| 577 | - } // end is_admin_teacher |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * Show correct post counts on list table for Sensei post types |
|
| 581 | - * |
|
| 582 | - * @since 1.8.0 |
|
| 583 | - * |
|
| 584 | - * @param object $counts Default status counts |
|
| 585 | - * @param string $type Current post type |
|
| 586 | - * @param string $perm User permission level |
|
| 587 | - * @return object Modified status counts |
|
| 588 | - */ |
|
| 589 | - public function list_table_counts( $counts, $type, $perm ) { |
|
| 590 | - global $current_user; |
|
| 591 | - |
|
| 592 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 593 | - return $counts; |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - if( ! $this->is_admin_teacher() ) { |
|
| 597 | - return $counts; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - $args = array( |
|
| 601 | - 'post_type' => $type, |
|
| 602 | - 'author' => $current_user->ID, |
|
| 603 | - 'posts_per_page' => -1 |
|
| 604 | - ); |
|
| 605 | - |
|
| 606 | - // Get all available statuses |
|
| 607 | - $stati = get_post_stati(); |
|
| 608 | - |
|
| 609 | - // Update count object |
|
| 610 | - foreach( $stati as $status ) { |
|
| 611 | - $args['post_status'] = $status; |
|
| 612 | - $posts = get_posts( $args ); |
|
| 613 | - $counts->$status = count( $posts ); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - return $counts; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Filter the post queries to show |
|
| 621 | - * only lesson /course and users that belong |
|
| 622 | - * to the current logged teacher. |
|
| 623 | - * |
|
| 624 | - * @since 1.8.0 |
|
| 625 | - * |
|
| 626 | - */ |
|
| 627 | - public function filter_queries ( $query ) { |
|
| 628 | - global $current_user; |
|
| 629 | - |
|
| 630 | - if( ! $this->is_admin_teacher() ) { |
|
| 631 | - return; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 635 | - return; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - $screen = get_current_screen(); |
|
| 639 | - if( empty( $screen ) ) { |
|
| 640 | - return $query; |
|
| 641 | - } |
|
| 642 | - switch( $screen->id ) { |
|
| 643 | - case 'sensei_page_sensei_grading': |
|
| 644 | - case 'sensei_page_sensei_analysis': |
|
| 645 | - case 'sensei_page_sensei_learners': |
|
| 646 | - case 'lesson': |
|
| 647 | - case 'course': |
|
| 648 | - case 'question': |
|
| 649 | - case 'lesson_page_module-order': |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * sensei_filter_queries_set_author |
|
| 653 | - * Filter the author Sensei set for queries |
|
| 654 | - * |
|
| 655 | - * @since 1.8.0 |
|
| 656 | - * |
|
| 657 | - * @param int $user_id |
|
| 658 | - * @param string $screen_id |
|
| 659 | - * |
|
| 660 | - */ |
|
| 661 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 662 | - break; |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 668 | - * . This excludes the admin user. |
|
| 669 | - * |
|
| 670 | - * @since 1.8.0 |
|
| 671 | - * @hooked into the_comments |
|
| 672 | - * @param array $comments |
|
| 673 | - * |
|
| 674 | - * @return array $comments |
|
| 675 | - */ |
|
| 676 | - public function filter_grading_activity_queries( $comments ){ |
|
| 677 | - |
|
| 678 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | - return $comments ; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - //check if we're on the grading screen |
|
| 683 | - $screen = get_current_screen(); |
|
| 684 | - |
|
| 685 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 686 | - return $comments; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - // get the course and determine if the current teacher is the owner |
|
| 690 | - // if not remove it from the list of comments to be returned |
|
| 691 | - foreach( $comments as $key => $comment){ |
|
| 692 | - $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | - $course = get_post( $course_id ); |
|
| 695 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 696 | - //remove this as the teacher should see this. |
|
| 697 | - unset( $comments[ $key ] ); |
|
| 698 | - } |
|
| 699 | - } |
|
| 700 | - return $comments ; |
|
| 701 | - |
|
| 702 | - }// end function filter grading |
|
| 703 | - |
|
| 704 | - /** |
|
| 705 | - * Limit the grading screen totals to only show lessons in the course |
|
| 706 | - * belonging to the currently logged in teacher. This only applies to |
|
| 707 | - * the teacher role. |
|
| 708 | - * |
|
| 709 | - * @since 1.8.0 |
|
| 710 | - * |
|
| 711 | - * @hooked into sensei_count_statuses_args |
|
| 712 | - * @param array $args |
|
| 713 | - * |
|
| 714 | - * @return array $args |
|
| 715 | - */ |
|
| 716 | - public function limit_grading_totals( $args ){ |
|
| 717 | - |
|
| 718 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | - return $args ; |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - //get the teachers courses |
|
| 723 | - // the query is already filtered to only the teacher |
|
| 724 | - $courses = Sensei()->course->get_all_courses(); |
|
| 725 | - |
|
| 726 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 727 | - return $args; |
|
| 728 | - } |
|
| 729 | - |
|
| 730 | - //setup the lessons quizzes to limit the grading totals to |
|
| 731 | - $quiz_scope = array(); |
|
| 732 | - foreach( $courses as $course ){ |
|
| 733 | - |
|
| 734 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 735 | - |
|
| 736 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 737 | - |
|
| 738 | - foreach( $course_lessons as $lesson ){ |
|
| 739 | - |
|
| 740 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | - if( !empty( $quiz_id ) ) { |
|
| 742 | - |
|
| 743 | - array_push( $quiz_scope, $quiz_id ); |
|
| 744 | - |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - $args['post__in'] = $quiz_scope; |
|
| 754 | - |
|
| 755 | - return $args; |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - /** |
|
| 759 | - * It ensures that the author archive shows course by the current user. |
|
| 760 | - * |
|
| 761 | - * This function is hooked into the pre_get_posts filter |
|
| 762 | - * |
|
| 763 | - * @param WP_Query $query |
|
| 764 | - * @return WP_Query $query |
|
| 765 | - */ |
|
| 766 | - public function add_courses_to_author_archive( $query ) { |
|
| 767 | - |
|
| 768 | - if ( is_admin() || ! $query->is_author() ){ |
|
| 769 | - return $query; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - // this should only apply to users with the teacher role |
|
| 773 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 775 | - |
|
| 776 | - return $query; |
|
| 777 | - |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // Change post types depending on what is set already |
|
| 781 | - $current_post_types = $query->get( 'post_type' ); |
|
| 782 | - if( empty( $current_post_types ) ){ |
|
| 783 | - |
|
| 784 | - // if empty it means post by default, so add post so that it also includes that for now |
|
| 785 | - $new_post_types = array( 'post', 'course' ); |
|
| 786 | - |
|
| 787 | - } elseif( is_array( $current_post_types ) ) { |
|
| 788 | - |
|
| 789 | - // merge the post types instead of overwriting it |
|
| 790 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 791 | - |
|
| 792 | - }else{ |
|
| 793 | - |
|
| 794 | - // in this instance it is probably just one post type in string format |
|
| 795 | - $new_post_types = array( $current_post_types , 'course'); |
|
| 796 | - |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - // change the query before returning it |
|
| 800 | - $query->set('post_type', $new_post_types ); |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * Change the query on the teacher author archive template |
|
| 804 | - * |
|
| 805 | - * @since 1.8.4 |
|
| 806 | - * @param WP_Query $query |
|
| 807 | - */ |
|
| 808 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 809 | - |
|
| 810 | - } |
|
| 811 | - |
|
| 812 | - /** |
|
| 813 | - * Notify teacher when someone assigns a course to their account. |
|
| 814 | - * |
|
| 815 | - * @since 1.8.0 |
|
| 816 | - * |
|
| 817 | - * @param $teacher_id |
|
| 818 | - * @param $course_id |
|
| 819 | - * @return bool |
|
| 820 | - */ |
|
| 821 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 822 | - |
|
| 823 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 824 | - return false; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - // if new user is the same as the current logged user, they don't need an email |
|
| 828 | - if( $teacher_id == get_current_user_id() ){ |
|
| 829 | - return true; |
|
| 830 | - } |
|
| 831 | - |
|
| 832 | - // load the email class |
|
| 833 | - include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
| 834 | - $email = new Teacher_New_Course_Assignment(); |
|
| 835 | - $email->trigger( $teacher_id, $course_id ); |
|
| 836 | - |
|
| 837 | - return true; |
|
| 838 | - } // end teacher_course_assigned_notification |
|
| 839 | - |
|
| 840 | - /** |
|
| 841 | - * Email the admin when a teacher creates a new course |
|
| 842 | - * |
|
| 843 | - * This function hooks into wp_insert_post |
|
| 844 | - * |
|
| 845 | - * @since 1.8.0 |
|
| 846 | - * @param int $course_id |
|
| 847 | - * @return bool |
|
| 848 | - */ |
|
| 849 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 850 | - |
|
| 851 | - $course_id = $post->ID; |
|
| 852 | - |
|
| 853 | - if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 855 | - |
|
| 856 | - return false; |
|
| 857 | - |
|
| 858 | - } |
|
| 859 | - |
|
| 860 | - /** |
|
| 861 | - * Filter the option to send admin notification emails when teachers creation |
|
| 862 | - * course. |
|
| 863 | - * |
|
| 864 | - * @since 1.8.0 |
|
| 865 | - * |
|
| 866 | - * @param bool $on default true |
|
| 867 | - */ |
|
| 868 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 869 | - return false; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - // setting up the data needed by the email template |
|
| 873 | - global $sensei_email_data; |
|
| 874 | - $template = 'admin-teacher-new-course-created'; |
|
| 875 | - $course = get_post( $course_id ); |
|
| 876 | - $teacher = new WP_User( $course->post_author ); |
|
| 877 | - $recipient = get_option('admin_email', true); |
|
| 878 | - |
|
| 879 | - // don't send if the course is created by admin |
|
| 880 | - if( $recipient == $teacher->user_email ){ |
|
| 881 | - return; |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - /** |
|
| 885 | - * Filter the email Header for the admin-teacher-new-course-created template |
|
| 886 | - * |
|
| 887 | - * @since 1.8.0 |
|
| 888 | - * @param string $template |
|
| 889 | - */ |
|
| 890 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 891 | - |
|
| 892 | - /** |
|
| 893 | - * Filter the email subject for the the |
|
| 894 | - * admin-teacher-new-course-created template |
|
| 895 | - * |
|
| 896 | - * @since 1.8.0 |
|
| 897 | - * @param string $subject default New course assigned to you |
|
| 898 | - * @param string $template |
|
| 899 | - */ |
|
| 900 | - $subject = apply_filters('sensei_email_subject', |
|
| 901 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | - $template ); |
|
| 903 | - |
|
| 904 | - //course edit link |
|
| 905 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 906 | - |
|
| 907 | - // Construct data array |
|
| 908 | - $email_data = array( |
|
| 909 | - 'template' => $template, |
|
| 910 | - 'heading' => $heading, |
|
| 911 | - 'teacher' => $teacher, |
|
| 912 | - 'course_id' => $course_id, |
|
| 913 | - 'course_name' => $course->post_title, |
|
| 914 | - 'course_edit_link' => $course_edit_link, |
|
| 915 | - ); |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 919 | - * |
|
| 920 | - * @since 1.8.0 |
|
| 921 | - * @param array $email_data |
|
| 922 | - * @param string $template |
|
| 923 | - */ |
|
| 924 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 925 | - |
|
| 926 | - // Send mail |
|
| 927 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 928 | - |
|
| 929 | - }// end notify admin of course creation |
|
| 930 | - |
|
| 931 | - /** |
|
| 932 | - * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 933 | - * |
|
| 934 | - * Hooked into sensei_analysis_get_learners |
|
| 935 | - * @param array $args WP_User_Query arguments |
|
| 936 | - * @return array $learners_query_results |
|
| 937 | - */ |
|
| 938 | - public function limit_analysis_learners( $args ){ |
|
| 939 | - |
|
| 940 | - // show default for none teachers |
|
| 941 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 942 | - return $args; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - // for teachers all courses only return those which belong to the teacher |
|
| 946 | - // as they don't have access to course belonging to other users |
|
| 947 | - $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 509 | + }// end update_course_lessons_author |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Sensei_Teacher::course_analysis_teacher_access_limit |
|
| 515 | + * |
|
| 516 | + * Alter the query so that users can only see their courses on the analysis page |
|
| 517 | + * |
|
| 518 | + * @since 1.8.0 |
|
| 519 | + * @access public |
|
| 520 | + * @parameters $query |
|
| 521 | + * @return array $users user id array |
|
| 522 | + */ |
|
| 523 | + public function course_analysis_teacher_access_limit ( $query ) { |
|
| 524 | + |
|
| 525 | + if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 526 | + return $query; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 530 | + return $query; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $screen = get_current_screen(); |
|
| 534 | + $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 535 | + |
|
| 536 | + // exit early for the following conditions |
|
| 537 | + $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 538 | + |
|
| 539 | + if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | + || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 541 | + return $query; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + global $current_user; |
|
| 545 | + // set the query author to the current user to only show those those posts |
|
| 546 | + $query->set( 'author', $current_user->ID ); |
|
| 547 | + return $query; |
|
| 548 | + |
|
| 549 | + }// end course_analysis_teacher_access_limit |
|
| 550 | + |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 554 | + * |
|
| 555 | + * Determine if we're in admin and the current logged in use is a teacher |
|
| 556 | + * |
|
| 557 | + * @since 1.8.0 |
|
| 558 | + * @access public |
|
| 559 | + * @parameters array $wp_query |
|
| 560 | + * @return bool $is_admin_teacher |
|
| 561 | + */ |
|
| 562 | + public function is_admin_teacher ( ){ |
|
| 563 | + |
|
| 564 | + if( ! is_user_logged_in()){ |
|
| 565 | + return false; |
|
| 566 | + } |
|
| 567 | + $is_admin_teacher = false; |
|
| 568 | + |
|
| 569 | + if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 570 | + |
|
| 571 | + $is_admin_teacher = true; |
|
| 572 | + |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return $is_admin_teacher; |
|
| 576 | + |
|
| 577 | + } // end is_admin_teacher |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * Show correct post counts on list table for Sensei post types |
|
| 581 | + * |
|
| 582 | + * @since 1.8.0 |
|
| 583 | + * |
|
| 584 | + * @param object $counts Default status counts |
|
| 585 | + * @param string $type Current post type |
|
| 586 | + * @param string $perm User permission level |
|
| 587 | + * @return object Modified status counts |
|
| 588 | + */ |
|
| 589 | + public function list_table_counts( $counts, $type, $perm ) { |
|
| 590 | + global $current_user; |
|
| 591 | + |
|
| 592 | + if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 593 | + return $counts; |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + if( ! $this->is_admin_teacher() ) { |
|
| 597 | + return $counts; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $args = array( |
|
| 601 | + 'post_type' => $type, |
|
| 602 | + 'author' => $current_user->ID, |
|
| 603 | + 'posts_per_page' => -1 |
|
| 604 | + ); |
|
| 605 | + |
|
| 606 | + // Get all available statuses |
|
| 607 | + $stati = get_post_stati(); |
|
| 608 | + |
|
| 609 | + // Update count object |
|
| 610 | + foreach( $stati as $status ) { |
|
| 611 | + $args['post_status'] = $status; |
|
| 612 | + $posts = get_posts( $args ); |
|
| 613 | + $counts->$status = count( $posts ); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + return $counts; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Filter the post queries to show |
|
| 621 | + * only lesson /course and users that belong |
|
| 622 | + * to the current logged teacher. |
|
| 623 | + * |
|
| 624 | + * @since 1.8.0 |
|
| 625 | + * |
|
| 626 | + */ |
|
| 627 | + public function filter_queries ( $query ) { |
|
| 628 | + global $current_user; |
|
| 629 | + |
|
| 630 | + if( ! $this->is_admin_teacher() ) { |
|
| 631 | + return; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 635 | + return; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + $screen = get_current_screen(); |
|
| 639 | + if( empty( $screen ) ) { |
|
| 640 | + return $query; |
|
| 641 | + } |
|
| 642 | + switch( $screen->id ) { |
|
| 643 | + case 'sensei_page_sensei_grading': |
|
| 644 | + case 'sensei_page_sensei_analysis': |
|
| 645 | + case 'sensei_page_sensei_learners': |
|
| 646 | + case 'lesson': |
|
| 647 | + case 'course': |
|
| 648 | + case 'question': |
|
| 649 | + case 'lesson_page_module-order': |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * sensei_filter_queries_set_author |
|
| 653 | + * Filter the author Sensei set for queries |
|
| 654 | + * |
|
| 655 | + * @since 1.8.0 |
|
| 656 | + * |
|
| 657 | + * @param int $user_id |
|
| 658 | + * @param string $screen_id |
|
| 659 | + * |
|
| 660 | + */ |
|
| 661 | + $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 662 | + break; |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Limit grading quizzes to only those within courses belonging to the current teacher |
|
| 668 | + * . This excludes the admin user. |
|
| 669 | + * |
|
| 670 | + * @since 1.8.0 |
|
| 671 | + * @hooked into the_comments |
|
| 672 | + * @param array $comments |
|
| 673 | + * |
|
| 674 | + * @return array $comments |
|
| 675 | + */ |
|
| 676 | + public function filter_grading_activity_queries( $comments ){ |
|
| 677 | + |
|
| 678 | + if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | + return $comments ; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + //check if we're on the grading screen |
|
| 683 | + $screen = get_current_screen(); |
|
| 684 | + |
|
| 685 | + if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 686 | + return $comments; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + // get the course and determine if the current teacher is the owner |
|
| 690 | + // if not remove it from the list of comments to be returned |
|
| 691 | + foreach( $comments as $key => $comment){ |
|
| 692 | + $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | + $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | + $course = get_post( $course_id ); |
|
| 695 | + if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 696 | + //remove this as the teacher should see this. |
|
| 697 | + unset( $comments[ $key ] ); |
|
| 698 | + } |
|
| 699 | + } |
|
| 700 | + return $comments ; |
|
| 701 | + |
|
| 702 | + }// end function filter grading |
|
| 703 | + |
|
| 704 | + /** |
|
| 705 | + * Limit the grading screen totals to only show lessons in the course |
|
| 706 | + * belonging to the currently logged in teacher. This only applies to |
|
| 707 | + * the teacher role. |
|
| 708 | + * |
|
| 709 | + * @since 1.8.0 |
|
| 710 | + * |
|
| 711 | + * @hooked into sensei_count_statuses_args |
|
| 712 | + * @param array $args |
|
| 713 | + * |
|
| 714 | + * @return array $args |
|
| 715 | + */ |
|
| 716 | + public function limit_grading_totals( $args ){ |
|
| 717 | + |
|
| 718 | + if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | + return $args ; |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + //get the teachers courses |
|
| 723 | + // the query is already filtered to only the teacher |
|
| 724 | + $courses = Sensei()->course->get_all_courses(); |
|
| 725 | + |
|
| 726 | + if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 727 | + return $args; |
|
| 728 | + } |
|
| 729 | + |
|
| 730 | + //setup the lessons quizzes to limit the grading totals to |
|
| 731 | + $quiz_scope = array(); |
|
| 732 | + foreach( $courses as $course ){ |
|
| 733 | + |
|
| 734 | + $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 735 | + |
|
| 736 | + if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 737 | + |
|
| 738 | + foreach( $course_lessons as $lesson ){ |
|
| 739 | + |
|
| 740 | + $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | + if( !empty( $quiz_id ) ) { |
|
| 742 | + |
|
| 743 | + array_push( $quiz_scope, $quiz_id ); |
|
| 744 | + |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + $args['post__in'] = $quiz_scope; |
|
| 754 | + |
|
| 755 | + return $args; |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + /** |
|
| 759 | + * It ensures that the author archive shows course by the current user. |
|
| 760 | + * |
|
| 761 | + * This function is hooked into the pre_get_posts filter |
|
| 762 | + * |
|
| 763 | + * @param WP_Query $query |
|
| 764 | + * @return WP_Query $query |
|
| 765 | + */ |
|
| 766 | + public function add_courses_to_author_archive( $query ) { |
|
| 767 | + |
|
| 768 | + if ( is_admin() || ! $query->is_author() ){ |
|
| 769 | + return $query; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + // this should only apply to users with the teacher role |
|
| 773 | + $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | + if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 775 | + |
|
| 776 | + return $query; |
|
| 777 | + |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // Change post types depending on what is set already |
|
| 781 | + $current_post_types = $query->get( 'post_type' ); |
|
| 782 | + if( empty( $current_post_types ) ){ |
|
| 783 | + |
|
| 784 | + // if empty it means post by default, so add post so that it also includes that for now |
|
| 785 | + $new_post_types = array( 'post', 'course' ); |
|
| 786 | + |
|
| 787 | + } elseif( is_array( $current_post_types ) ) { |
|
| 788 | + |
|
| 789 | + // merge the post types instead of overwriting it |
|
| 790 | + $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 791 | + |
|
| 792 | + }else{ |
|
| 793 | + |
|
| 794 | + // in this instance it is probably just one post type in string format |
|
| 795 | + $new_post_types = array( $current_post_types , 'course'); |
|
| 796 | + |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + // change the query before returning it |
|
| 800 | + $query->set('post_type', $new_post_types ); |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * Change the query on the teacher author archive template |
|
| 804 | + * |
|
| 805 | + * @since 1.8.4 |
|
| 806 | + * @param WP_Query $query |
|
| 807 | + */ |
|
| 808 | + return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 809 | + |
|
| 810 | + } |
|
| 811 | + |
|
| 812 | + /** |
|
| 813 | + * Notify teacher when someone assigns a course to their account. |
|
| 814 | + * |
|
| 815 | + * @since 1.8.0 |
|
| 816 | + * |
|
| 817 | + * @param $teacher_id |
|
| 818 | + * @param $course_id |
|
| 819 | + * @return bool |
|
| 820 | + */ |
|
| 821 | + public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 822 | + |
|
| 823 | + if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 824 | + return false; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + // if new user is the same as the current logged user, they don't need an email |
|
| 828 | + if( $teacher_id == get_current_user_id() ){ |
|
| 829 | + return true; |
|
| 830 | + } |
|
| 831 | + |
|
| 832 | + // load the email class |
|
| 833 | + include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
|
| 834 | + $email = new Teacher_New_Course_Assignment(); |
|
| 835 | + $email->trigger( $teacher_id, $course_id ); |
|
| 836 | + |
|
| 837 | + return true; |
|
| 838 | + } // end teacher_course_assigned_notification |
|
| 839 | + |
|
| 840 | + /** |
|
| 841 | + * Email the admin when a teacher creates a new course |
|
| 842 | + * |
|
| 843 | + * This function hooks into wp_insert_post |
|
| 844 | + * |
|
| 845 | + * @since 1.8.0 |
|
| 846 | + * @param int $course_id |
|
| 847 | + * @return bool |
|
| 848 | + */ |
|
| 849 | + public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 850 | + |
|
| 851 | + $course_id = $post->ID; |
|
| 852 | + |
|
| 853 | + if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | + || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 855 | + |
|
| 856 | + return false; |
|
| 857 | + |
|
| 858 | + } |
|
| 859 | + |
|
| 860 | + /** |
|
| 861 | + * Filter the option to send admin notification emails when teachers creation |
|
| 862 | + * course. |
|
| 863 | + * |
|
| 864 | + * @since 1.8.0 |
|
| 865 | + * |
|
| 866 | + * @param bool $on default true |
|
| 867 | + */ |
|
| 868 | + if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 869 | + return false; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + // setting up the data needed by the email template |
|
| 873 | + global $sensei_email_data; |
|
| 874 | + $template = 'admin-teacher-new-course-created'; |
|
| 875 | + $course = get_post( $course_id ); |
|
| 876 | + $teacher = new WP_User( $course->post_author ); |
|
| 877 | + $recipient = get_option('admin_email', true); |
|
| 878 | + |
|
| 879 | + // don't send if the course is created by admin |
|
| 880 | + if( $recipient == $teacher->user_email ){ |
|
| 881 | + return; |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + /** |
|
| 885 | + * Filter the email Header for the admin-teacher-new-course-created template |
|
| 886 | + * |
|
| 887 | + * @since 1.8.0 |
|
| 888 | + * @param string $template |
|
| 889 | + */ |
|
| 890 | + $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 891 | + |
|
| 892 | + /** |
|
| 893 | + * Filter the email subject for the the |
|
| 894 | + * admin-teacher-new-course-created template |
|
| 895 | + * |
|
| 896 | + * @since 1.8.0 |
|
| 897 | + * @param string $subject default New course assigned to you |
|
| 898 | + * @param string $template |
|
| 899 | + */ |
|
| 900 | + $subject = apply_filters('sensei_email_subject', |
|
| 901 | + '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | + $template ); |
|
| 903 | + |
|
| 904 | + //course edit link |
|
| 905 | + $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 906 | + |
|
| 907 | + // Construct data array |
|
| 908 | + $email_data = array( |
|
| 909 | + 'template' => $template, |
|
| 910 | + 'heading' => $heading, |
|
| 911 | + 'teacher' => $teacher, |
|
| 912 | + 'course_id' => $course_id, |
|
| 913 | + 'course_name' => $course->post_title, |
|
| 914 | + 'course_edit_link' => $course_edit_link, |
|
| 915 | + ); |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * Filter the sensei email data for the admin-teacher-new-course-created template |
|
| 919 | + * |
|
| 920 | + * @since 1.8.0 |
|
| 921 | + * @param array $email_data |
|
| 922 | + * @param string $template |
|
| 923 | + */ |
|
| 924 | + $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 925 | + |
|
| 926 | + // Send mail |
|
| 927 | + Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 928 | + |
|
| 929 | + }// end notify admin of course creation |
|
| 930 | + |
|
| 931 | + /** |
|
| 932 | + * Limit the analysis view to only the users taking courses belong to this teacher |
|
| 933 | + * |
|
| 934 | + * Hooked into sensei_analysis_get_learners |
|
| 935 | + * @param array $args WP_User_Query arguments |
|
| 936 | + * @return array $learners_query_results |
|
| 937 | + */ |
|
| 938 | + public function limit_analysis_learners( $args ){ |
|
| 939 | + |
|
| 940 | + // show default for none teachers |
|
| 941 | + if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 942 | + return $args; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + // for teachers all courses only return those which belong to the teacher |
|
| 946 | + // as they don't have access to course belonging to other users |
|
| 947 | + $teacher_courses = Sensei()->course->get_all_courses(); |
|
| 948 | 948 | |
| 949 | - // if the user has no courses they should see no users |
|
| 950 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 951 | - // tell the query to return 0 students |
|
| 952 | - $args[ 'include'] = array( 0 ); |
|
| 953 | - return $args; |
|
| 954 | - |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - $learner_ids_for_teacher_courses = array(); |
|
| 958 | - foreach( $teacher_courses as $course ){ |
|
| 959 | - |
|
| 960 | - $course_learner_ids = array(); |
|
| 961 | - $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 962 | - |
|
| 963 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 964 | - continue; // skip to the next course as there are no users on this course |
|
| 965 | - } |
|
| 966 | - |
|
| 967 | - // it could be an array of comments or a single comment |
|
| 968 | - if( is_array( $activity_comments ) ){ |
|
| 949 | + // if the user has no courses they should see no users |
|
| 950 | + if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 951 | + // tell the query to return 0 students |
|
| 952 | + $args[ 'include'] = array( 0 ); |
|
| 953 | + return $args; |
|
| 954 | + |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + $learner_ids_for_teacher_courses = array(); |
|
| 958 | + foreach( $teacher_courses as $course ){ |
|
| 959 | + |
|
| 960 | + $course_learner_ids = array(); |
|
| 961 | + $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 962 | + |
|
| 963 | + if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 964 | + continue; // skip to the next course as there are no users on this course |
|
| 965 | + } |
|
| 966 | + |
|
| 967 | + // it could be an array of comments or a single comment |
|
| 968 | + if( is_array( $activity_comments ) ){ |
|
| 969 | 969 | |
| 970 | - foreach( $activity_comments as $comment ){ |
|
| 970 | + foreach( $activity_comments as $comment ){ |
|
| 971 | 971 | |
| 972 | - $user = get_userdata( $comment->user_id ); |
|
| 972 | + $user = get_userdata( $comment->user_id ); |
|
| 973 | 973 | |
| 974 | - if( empty( $user ) ){ |
|
| 975 | - // next comment in this array |
|
| 976 | - continue; |
|
| 977 | - } |
|
| 974 | + if( empty( $user ) ){ |
|
| 975 | + // next comment in this array |
|
| 976 | + continue; |
|
| 977 | + } |
|
| 978 | 978 | |
| 979 | - $course_learner_ids[] = $user->ID; |
|
| 980 | - } |
|
| 979 | + $course_learner_ids[] = $user->ID; |
|
| 980 | + } |
|
| 981 | 981 | |
| 982 | - }else{ |
|
| 982 | + }else{ |
|
| 983 | 983 | |
| 984 | - $user = get_userdata( $activity_comments->user_id ); |
|
| 985 | - $course_learner_ids[] = $user->ID; |
|
| 984 | + $user = get_userdata( $activity_comments->user_id ); |
|
| 985 | + $course_learner_ids[] = $user->ID; |
|
| 986 | 986 | |
| 987 | - } |
|
| 987 | + } |
|
| 988 | 988 | |
| 989 | - // add learners on this course to the all courses learner list |
|
| 990 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 989 | + // add learners on this course to the all courses learner list |
|
| 990 | + $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 991 | 991 | |
| 992 | - } |
|
| 992 | + } |
|
| 993 | 993 | |
| 994 | - // if there are no students taking the courses by this teacher don't show them any of the other users |
|
| 995 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 994 | + // if there are no students taking the courses by this teacher don't show them any of the other users |
|
| 995 | + if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 996 | 996 | |
| 997 | - $args[ 'include'] = array( 0 ); |
|
| 997 | + $args[ 'include'] = array( 0 ); |
|
| 998 | 998 | |
| 999 | - }else{ |
|
| 999 | + }else{ |
|
| 1000 | 1000 | |
| 1001 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1001 | + $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1002 | 1002 | |
| 1003 | - } |
|
| 1003 | + } |
|
| 1004 | 1004 | |
| 1005 | - // return the WP_Use_Query arguments |
|
| 1006 | - return $args; |
|
| 1005 | + // return the WP_Use_Query arguments |
|
| 1006 | + return $args; |
|
| 1007 | 1007 | |
| 1008 | - }// end limit_analysis_learners |
|
| 1008 | + }// end limit_analysis_learners |
|
| 1009 | 1009 | |
| 1010 | - /** |
|
| 1011 | - * Give teacher full admin access to the question post type |
|
| 1012 | - * in certain cases. |
|
| 1013 | - * |
|
| 1014 | - * @since 1.8.0 |
|
| 1015 | - * @param $questions |
|
| 1016 | - * @return mixed |
|
| 1017 | - */ |
|
| 1018 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1010 | + /** |
|
| 1011 | + * Give teacher full admin access to the question post type |
|
| 1012 | + * in certain cases. |
|
| 1013 | + * |
|
| 1014 | + * @since 1.8.0 |
|
| 1015 | + * @param $questions |
|
| 1016 | + * @return mixed |
|
| 1017 | + */ |
|
| 1018 | + public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1019 | 1019 | |
| 1020 | - if( ! $this->is_admin_teacher() ){ |
|
| 1021 | - return $questions; |
|
| 1022 | - } |
|
| 1020 | + if( ! $this->is_admin_teacher() ){ |
|
| 1021 | + return $questions; |
|
| 1022 | + } |
|
| 1023 | 1023 | |
| 1024 | - $screen = get_current_screen(); |
|
| 1024 | + $screen = get_current_screen(); |
|
| 1025 | 1025 | |
| 1026 | - // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
| 1027 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1026 | + // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
|
| 1027 | + remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1028 | 1028 | |
| 1029 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1029 | + if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1030 | 1030 | |
| 1031 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1032 | - if( ! empty($admin_user) ){ |
|
| 1031 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1032 | + if( ! empty($admin_user) ){ |
|
| 1033 | 1033 | |
| 1034 | - $current_teacher_id = get_current_user_id(); |
|
| 1034 | + $current_teacher_id = get_current_user_id(); |
|
| 1035 | 1035 | |
| 1036 | - // set current user to admin so teacher can view all questions |
|
| 1037 | - wp_set_current_user( $admin_user->ID ); |
|
| 1038 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1036 | + // set current user to admin so teacher can view all questions |
|
| 1037 | + wp_set_current_user( $admin_user->ID ); |
|
| 1038 | + $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1039 | 1039 | |
| 1040 | - // set the teacher as the current use again |
|
| 1041 | - wp_set_current_user( $current_teacher_id ); |
|
| 1042 | - } |
|
| 1040 | + // set the teacher as the current use again |
|
| 1041 | + wp_set_current_user( $current_teacher_id ); |
|
| 1042 | + } |
|
| 1043 | 1043 | |
| 1044 | - } |
|
| 1045 | - // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
| 1046 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1044 | + } |
|
| 1045 | + // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
|
| 1046 | + add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1047 | 1047 | |
| 1048 | - return $questions; |
|
| 1049 | - } |
|
| 1048 | + return $questions; |
|
| 1049 | + } |
|
| 1050 | 1050 | |
| 1051 | - /** |
|
| 1052 | - * Give the teacher role access to questions from the question bank |
|
| 1053 | - * |
|
| 1054 | - * @since 1.8.0 |
|
| 1055 | - * @param $wp_query |
|
| 1056 | - * @return mixed |
|
| 1057 | - */ |
|
| 1058 | - public function give_access_to_all_questions( $wp_query ){ |
|
| 1051 | + /** |
|
| 1052 | + * Give the teacher role access to questions from the question bank |
|
| 1053 | + * |
|
| 1054 | + * @since 1.8.0 |
|
| 1055 | + * @param $wp_query |
|
| 1056 | + * @return mixed |
|
| 1057 | + */ |
|
| 1058 | + public function give_access_to_all_questions( $wp_query ){ |
|
| 1059 | 1059 | |
| 1060 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1060 | + if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1061 | 1061 | |
| 1062 | - return $wp_query; |
|
| 1063 | - } |
|
| 1062 | + return $wp_query; |
|
| 1063 | + } |
|
| 1064 | 1064 | |
| 1065 | - $screen = get_current_screen(); |
|
| 1066 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1065 | + $screen = get_current_screen(); |
|
| 1066 | + if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | + || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1068 | 1068 | |
| 1069 | - $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1070 | - if( ! empty($admin_user) ){ |
|
| 1069 | + $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
|
| 1070 | + if( ! empty($admin_user) ){ |
|
| 1071 | 1071 | |
| 1072 | - $current_teacher_id = get_current_user_id(); |
|
| 1072 | + $current_teacher_id = get_current_user_id(); |
|
| 1073 | 1073 | |
| 1074 | - // set current user to admin so teacher can view all questions |
|
| 1075 | - wp_set_current_user( $admin_user->ID ); |
|
| 1074 | + // set current user to admin so teacher can view all questions |
|
| 1075 | + wp_set_current_user( $admin_user->ID ); |
|
| 1076 | 1076 | |
| 1077 | - //run new query as admin |
|
| 1078 | - $wp_query = new WP_Query( $wp_query->query ); |
|
| 1077 | + //run new query as admin |
|
| 1078 | + $wp_query = new WP_Query( $wp_query->query ); |
|
| 1079 | 1079 | |
| 1080 | - //set the teache as current use again |
|
| 1081 | - wp_set_current_user( $current_teacher_id ); |
|
| 1080 | + //set the teache as current use again |
|
| 1081 | + wp_set_current_user( $current_teacher_id ); |
|
| 1082 | 1082 | |
| 1083 | - } |
|
| 1084 | - } |
|
| 1083 | + } |
|
| 1084 | + } |
|
| 1085 | 1085 | |
| 1086 | - return $wp_query; |
|
| 1087 | - }// end give_access_to_all_questions |
|
| 1086 | + return $wp_query; |
|
| 1087 | + }// end give_access_to_all_questions |
|
| 1088 | 1088 | |
| 1089 | - /** |
|
| 1090 | - * Add new column heading to the course admin edit list |
|
| 1091 | - * |
|
| 1092 | - * @since 1.8.0 |
|
| 1093 | - * @param $columns |
|
| 1094 | - * @return array |
|
| 1095 | - */ |
|
| 1096 | - public function course_column_heading($columns) { |
|
| 1089 | + /** |
|
| 1090 | + * Add new column heading to the course admin edit list |
|
| 1091 | + * |
|
| 1092 | + * @since 1.8.0 |
|
| 1093 | + * @param $columns |
|
| 1094 | + * @return array |
|
| 1095 | + */ |
|
| 1096 | + public function course_column_heading($columns) { |
|
| 1097 | 1097 | |
| 1098 | - if( $this->is_admin_teacher() ){ |
|
| 1099 | - return $columns; |
|
| 1100 | - } |
|
| 1101 | - $new_columns = array( |
|
| 1102 | - 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1103 | - ); |
|
| 1104 | - return array_merge($columns, $new_columns); |
|
| 1098 | + if( $this->is_admin_teacher() ){ |
|
| 1099 | + return $columns; |
|
| 1100 | + } |
|
| 1101 | + $new_columns = array( |
|
| 1102 | + 'teacher' => __('Teacher', 'woothemes-sensei'), |
|
| 1103 | + ); |
|
| 1104 | + return array_merge($columns, $new_columns); |
|
| 1105 | 1105 | |
| 1106 | - }// end teacher column add |
|
| 1106 | + }// end teacher column add |
|
| 1107 | 1107 | |
| 1108 | - /** |
|
| 1109 | - * Print out teacher column data |
|
| 1110 | - * |
|
| 1111 | - * @since 1.8.0 |
|
| 1112 | - * @param $column |
|
| 1113 | - * @param $course_id |
|
| 1114 | - */ |
|
| 1115 | - public function course_column_data( $column, $course_id ){ |
|
| 1108 | + /** |
|
| 1109 | + * Print out teacher column data |
|
| 1110 | + * |
|
| 1111 | + * @since 1.8.0 |
|
| 1112 | + * @param $column |
|
| 1113 | + * @param $course_id |
|
| 1114 | + */ |
|
| 1115 | + public function course_column_data( $column, $course_id ){ |
|
| 1116 | 1116 | |
| 1117 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1118 | - return; |
|
| 1119 | - } |
|
| 1117 | + if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1118 | + return; |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | - $course = get_post( $course_id ); |
|
| 1122 | - $teacher = get_userdata( $course->post_author ); |
|
| 1121 | + $course = get_post( $course_id ); |
|
| 1122 | + $teacher = get_userdata( $course->post_author ); |
|
| 1123 | 1123 | |
| 1124 | - if( !$teacher ){ |
|
| 1125 | - return; |
|
| 1126 | - } |
|
| 1124 | + if( !$teacher ){ |
|
| 1125 | + return; |
|
| 1126 | + } |
|
| 1127 | 1127 | |
| 1128 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1128 | + echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1129 | 1129 | |
| 1130 | - }// end course_column_ data |
|
| 1130 | + }// end course_column_ data |
|
| 1131 | 1131 | |
| 1132 | - /** |
|
| 1133 | - * Return only courses belonging to the given teacher. |
|
| 1134 | - * |
|
| 1135 | - * |
|
| 1136 | - * @since 1.8.0 |
|
| 1137 | - * |
|
| 1138 | - * @param int $teacher_id |
|
| 1139 | - * @param bool $return_ids_only |
|
| 1140 | - * |
|
| 1141 | - * @return array $teachers_courses |
|
| 1142 | - */ |
|
| 1143 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1132 | + /** |
|
| 1133 | + * Return only courses belonging to the given teacher. |
|
| 1134 | + * |
|
| 1135 | + * |
|
| 1136 | + * @since 1.8.0 |
|
| 1137 | + * |
|
| 1138 | + * @param int $teacher_id |
|
| 1139 | + * @param bool $return_ids_only |
|
| 1140 | + * |
|
| 1141 | + * @return array $teachers_courses |
|
| 1142 | + */ |
|
| 1143 | + public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1144 | 1144 | |
| 1145 | - $teachers_courses = array(); |
|
| 1145 | + $teachers_courses = array(); |
|
| 1146 | 1146 | |
| 1147 | - if( empty( $teacher_id ) ){ |
|
| 1148 | - $teacher_id = get_current_user_id(); |
|
| 1149 | - } |
|
| 1147 | + if( empty( $teacher_id ) ){ |
|
| 1148 | + $teacher_id = get_current_user_id(); |
|
| 1149 | + } |
|
| 1150 | 1150 | |
| 1151 | - $all_courses = Sensei()->course->get_all_courses(); |
|
| 1151 | + $all_courses = Sensei()->course->get_all_courses(); |
|
| 1152 | 1152 | |
| 1153 | - if( empty( $all_courses ) ){ |
|
| 1154 | - return $all_courses; |
|
| 1155 | - } |
|
| 1153 | + if( empty( $all_courses ) ){ |
|
| 1154 | + return $all_courses; |
|
| 1155 | + } |
|
| 1156 | 1156 | |
| 1157 | - foreach( $all_courses as $course ){ |
|
| 1157 | + foreach( $all_courses as $course ){ |
|
| 1158 | 1158 | |
| 1159 | - if( $course->post_author != $teacher_id ){ |
|
| 1160 | - continue; |
|
| 1161 | - } |
|
| 1159 | + if( $course->post_author != $teacher_id ){ |
|
| 1160 | + continue; |
|
| 1161 | + } |
|
| 1162 | 1162 | |
| 1163 | - if( $return_ids_only ){ |
|
| 1163 | + if( $return_ids_only ){ |
|
| 1164 | 1164 | |
| 1165 | - $teachers_courses[] = $course->ID; |
|
| 1165 | + $teachers_courses[] = $course->ID; |
|
| 1166 | 1166 | |
| 1167 | - }else{ |
|
| 1167 | + }else{ |
|
| 1168 | 1168 | |
| 1169 | - $teachers_courses[] = $course; |
|
| 1169 | + $teachers_courses[] = $course; |
|
| 1170 | 1170 | |
| 1171 | - } |
|
| 1171 | + } |
|
| 1172 | 1172 | |
| 1173 | - } |
|
| 1173 | + } |
|
| 1174 | 1174 | |
| 1175 | - return $teachers_courses; |
|
| 1175 | + return $teachers_courses; |
|
| 1176 | 1176 | |
| 1177 | - } |
|
| 1177 | + } |
|
| 1178 | 1178 | |
| 1179 | - /** |
|
| 1180 | - * Limit the message display to only those sent to the current teacher |
|
| 1181 | - * |
|
| 1182 | - * @since 1.8.0 |
|
| 1183 | - * |
|
| 1184 | - * @param $query |
|
| 1185 | - * @return mixed |
|
| 1186 | - */ |
|
| 1187 | - public function limit_edit_messages_query( $query ){ |
|
| 1188 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1189 | - return $query; |
|
| 1190 | - } |
|
| 1191 | - |
|
| 1192 | - $teacher = wp_get_current_user(); |
|
| 1193 | - |
|
| 1194 | - $query->set( 'meta_key', '_receiver' ); |
|
| 1195 | - $meta_query_args = array( |
|
| 1196 | - 'key' => '_receiver', |
|
| 1197 | - 'value' => $teacher->get('user_login') , |
|
| 1198 | - 'compare' => '=' |
|
| 1199 | - ); |
|
| 1179 | + /** |
|
| 1180 | + * Limit the message display to only those sent to the current teacher |
|
| 1181 | + * |
|
| 1182 | + * @since 1.8.0 |
|
| 1183 | + * |
|
| 1184 | + * @param $query |
|
| 1185 | + * @return mixed |
|
| 1186 | + */ |
|
| 1187 | + public function limit_edit_messages_query( $query ){ |
|
| 1188 | + if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1189 | + return $query; |
|
| 1190 | + } |
|
| 1191 | + |
|
| 1192 | + $teacher = wp_get_current_user(); |
|
| 1193 | + |
|
| 1194 | + $query->set( 'meta_key', '_receiver' ); |
|
| 1195 | + $meta_query_args = array( |
|
| 1196 | + 'key' => '_receiver', |
|
| 1197 | + 'value' => $teacher->get('user_login') , |
|
| 1198 | + 'compare' => '=' |
|
| 1199 | + ); |
|
| 1200 | 1200 | |
| 1201 | - $query->set('meta_query', $meta_query_args ); |
|
| 1201 | + $query->set('meta_query', $meta_query_args ); |
|
| 1202 | 1202 | |
| 1203 | - return $query; |
|
| 1204 | - } |
|
| 1203 | + return $query; |
|
| 1204 | + } |
|
| 1205 | 1205 | |
| 1206 | 1206 | |
| 1207 | - /** |
|
| 1208 | - * Add options to filter courses by teacher |
|
| 1209 | - * |
|
| 1210 | - * @since 1.8.0 |
|
| 1211 | - * |
|
| 1212 | - * @return void |
|
| 1213 | - */ |
|
| 1214 | - public function course_teacher_filter_options() { |
|
| 1215 | - global $typenow; |
|
| 1207 | + /** |
|
| 1208 | + * Add options to filter courses by teacher |
|
| 1209 | + * |
|
| 1210 | + * @since 1.8.0 |
|
| 1211 | + * |
|
| 1212 | + * @return void |
|
| 1213 | + */ |
|
| 1214 | + public function course_teacher_filter_options() { |
|
| 1215 | + global $typenow; |
|
| 1216 | 1216 | |
| 1217 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1218 | - return; |
|
| 1219 | - } |
|
| 1217 | + if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1218 | + return; |
|
| 1219 | + } |
|
| 1220 | 1220 | |
| 1221 | - // get all roles |
|
| 1222 | - $roles = get_editable_roles(); |
|
| 1221 | + // get all roles |
|
| 1222 | + $roles = get_editable_roles(); |
|
| 1223 | 1223 | |
| 1224 | - // get roles with the course edit capability |
|
| 1225 | - // and then get the users with those roles |
|
| 1226 | - $users_who_can_edit_courses = array(); |
|
| 1227 | - foreach( $roles as $role_item ){ |
|
| 1224 | + // get roles with the course edit capability |
|
| 1225 | + // and then get the users with those roles |
|
| 1226 | + $users_who_can_edit_courses = array(); |
|
| 1227 | + foreach( $roles as $role_item ){ |
|
| 1228 | 1228 | |
| 1229 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1229 | + $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1230 | 1230 | |
| 1231 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1231 | + if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1232 | 1232 | |
| 1233 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1233 | + $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | + $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1235 | 1235 | |
| 1236 | - // add user from the current $user_role to all users |
|
| 1237 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1236 | + // add user from the current $user_role to all users |
|
| 1237 | + $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1238 | 1238 | |
| 1239 | - } |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | - } |
|
| 1241 | + } |
|
| 1242 | 1242 | |
| 1243 | - // Create the select element with the given users who can edit course |
|
| 1244 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1245 | - $course_options = ''; |
|
| 1246 | - foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1248 | - } |
|
| 1243 | + // Create the select element with the given users who can edit course |
|
| 1244 | + $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1245 | + $course_options = ''; |
|
| 1246 | + foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | + $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1248 | + } |
|
| 1249 | 1249 | |
| 1250 | - $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1251 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1252 | - $output .= $course_options; |
|
| 1253 | - $output .= '</select>'; |
|
| 1250 | + $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
|
| 1251 | + $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1252 | + $output .= $course_options; |
|
| 1253 | + $output .= '</select>'; |
|
| 1254 | 1254 | |
| 1255 | - echo $output; |
|
| 1256 | - } |
|
| 1255 | + echo $output; |
|
| 1256 | + } |
|
| 1257 | 1257 | |
| 1258 | - /** |
|
| 1259 | - * Modify the main query on the admin course list screen |
|
| 1260 | - * |
|
| 1261 | - * @since 1.8.0 |
|
| 1262 | - * |
|
| 1263 | - * @param $query |
|
| 1264 | - * @return $query |
|
| 1265 | - */ |
|
| 1266 | - public function teacher_filter_query_modify( $query ){ |
|
| 1267 | - global $typenow; |
|
| 1258 | + /** |
|
| 1259 | + * Modify the main query on the admin course list screen |
|
| 1260 | + * |
|
| 1261 | + * @since 1.8.0 |
|
| 1262 | + * |
|
| 1263 | + * @param $query |
|
| 1264 | + * @return $query |
|
| 1265 | + */ |
|
| 1266 | + public function teacher_filter_query_modify( $query ){ |
|
| 1267 | + global $typenow; |
|
| 1268 | 1268 | |
| 1269 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1270 | - return $query; |
|
| 1271 | - } |
|
| 1272 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1273 | - |
|
| 1274 | - if( empty( $course_teacher ) ) { |
|
| 1275 | - return $query; |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - $query['author'] = $course_teacher; |
|
| 1279 | - return $query; |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * Only show current teacher's media in the media library |
|
| 1284 | - * @param array $request Default request arguments |
|
| 1285 | - * @return array Modified request arguments |
|
| 1286 | - */ |
|
| 1287 | - public function restrict_media_library( $request = array() ) { |
|
| 1288 | - |
|
| 1289 | - if( ! is_admin() ) { |
|
| 1290 | - return $request; |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - if( ! $this->is_admin_teacher() ) { |
|
| 1294 | - return $request; |
|
| 1295 | - } |
|
| 1296 | - |
|
| 1297 | - $screen = get_current_screen(); |
|
| 1298 | - |
|
| 1299 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | - $teacher = intval( get_current_user_id() ); |
|
| 1301 | - |
|
| 1302 | - if( $teacher ) { |
|
| 1303 | - $request['author__in'] = array( $teacher ); |
|
| 1304 | - } |
|
| 1305 | - } |
|
| 1306 | - |
|
| 1307 | - return $request; |
|
| 1308 | - } // End restrict_media_library() |
|
| 1309 | - |
|
| 1310 | - /** |
|
| 1311 | - * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1312 | - * @param array $query Default query arguments |
|
| 1313 | - * @return array Modified query arguments |
|
| 1314 | - */ |
|
| 1315 | - public function restrict_media_library_modal( $query = array() ) { |
|
| 1316 | - |
|
| 1317 | - if( ! is_admin() ) { |
|
| 1318 | - return $query; |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - if( ! $this->is_admin_teacher() ) { |
|
| 1322 | - return $query; |
|
| 1323 | - } |
|
| 1324 | - |
|
| 1325 | - $teacher = intval( get_current_user_id() ); |
|
| 1326 | - |
|
| 1327 | - if( $teacher ) { |
|
| 1328 | - $query['author__in'] = array( $teacher ); |
|
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - return $query; |
|
| 1332 | - } // End restrict_media_library_modal() |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1336 | - * |
|
| 1337 | - * @since 1.8.0 |
|
| 1338 | - * |
|
| 1339 | - * @param int $lesson_id |
|
| 1340 | - */ |
|
| 1341 | - public function update_lesson_teacher( $lesson_id ){ |
|
| 1342 | - |
|
| 1343 | - if( 'lesson'!= get_post_type() ){ |
|
| 1344 | - return; |
|
| 1345 | - } |
|
| 1269 | + if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1270 | + return $query; |
|
| 1271 | + } |
|
| 1272 | + $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1273 | + |
|
| 1274 | + if( empty( $course_teacher ) ) { |
|
| 1275 | + return $query; |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + $query['author'] = $course_teacher; |
|
| 1279 | + return $query; |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * Only show current teacher's media in the media library |
|
| 1284 | + * @param array $request Default request arguments |
|
| 1285 | + * @return array Modified request arguments |
|
| 1286 | + */ |
|
| 1287 | + public function restrict_media_library( $request = array() ) { |
|
| 1288 | + |
|
| 1289 | + if( ! is_admin() ) { |
|
| 1290 | + return $request; |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + if( ! $this->is_admin_teacher() ) { |
|
| 1294 | + return $request; |
|
| 1295 | + } |
|
| 1296 | + |
|
| 1297 | + $screen = get_current_screen(); |
|
| 1298 | + |
|
| 1299 | + if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | + $teacher = intval( get_current_user_id() ); |
|
| 1301 | + |
|
| 1302 | + if( $teacher ) { |
|
| 1303 | + $request['author__in'] = array( $teacher ); |
|
| 1304 | + } |
|
| 1305 | + } |
|
| 1306 | + |
|
| 1307 | + return $request; |
|
| 1308 | + } // End restrict_media_library() |
|
| 1309 | + |
|
| 1310 | + /** |
|
| 1311 | + * Only show current teacher's media in the media library modal on the course/lesson/quesion edit screen |
|
| 1312 | + * @param array $query Default query arguments |
|
| 1313 | + * @return array Modified query arguments |
|
| 1314 | + */ |
|
| 1315 | + public function restrict_media_library_modal( $query = array() ) { |
|
| 1316 | + |
|
| 1317 | + if( ! is_admin() ) { |
|
| 1318 | + return $query; |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + if( ! $this->is_admin_teacher() ) { |
|
| 1322 | + return $query; |
|
| 1323 | + } |
|
| 1324 | + |
|
| 1325 | + $teacher = intval( get_current_user_id() ); |
|
| 1326 | + |
|
| 1327 | + if( $teacher ) { |
|
| 1328 | + $query['author__in'] = array( $teacher ); |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + return $query; |
|
| 1332 | + } // End restrict_media_library_modal() |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * When saving the lesson, update the teacher if the lesson belongs to a course |
|
| 1336 | + * |
|
| 1337 | + * @since 1.8.0 |
|
| 1338 | + * |
|
| 1339 | + * @param int $lesson_id |
|
| 1340 | + */ |
|
| 1341 | + public function update_lesson_teacher( $lesson_id ){ |
|
| 1342 | + |
|
| 1343 | + if( 'lesson'!= get_post_type() ){ |
|
| 1344 | + return; |
|
| 1345 | + } |
|
| 1346 | 1346 | |
| 1347 | - // this should only run once per request cycle |
|
| 1348 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1347 | + // this should only run once per request cycle |
|
| 1348 | + remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1349 | 1349 | |
| 1350 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1350 | + $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1351 | 1351 | |
| 1352 | - if( empty( $course_id ) || ! $course_id ){ |
|
| 1353 | - return; |
|
| 1354 | - } |
|
| 1352 | + if( empty( $course_id ) || ! $course_id ){ |
|
| 1353 | + return; |
|
| 1354 | + } |
|
| 1355 | 1355 | |
| 1356 | - $course = get_post( $course_id ); |
|
| 1356 | + $course = get_post( $course_id ); |
|
| 1357 | 1357 | |
| 1358 | - $lesson_update_args= array( |
|
| 1359 | - 'ID' => $lesson_id , |
|
| 1360 | - 'post_author' => $course->post_author |
|
| 1361 | - ); |
|
| 1362 | - wp_update_post( $lesson_update_args ); |
|
| 1358 | + $lesson_update_args= array( |
|
| 1359 | + 'ID' => $lesson_id , |
|
| 1360 | + 'post_author' => $course->post_author |
|
| 1361 | + ); |
|
| 1362 | + wp_update_post( $lesson_update_args ); |
|
| 1363 | 1363 | |
| 1364 | - } // end update_lesson_teacher |
|
| 1364 | + } // end update_lesson_teacher |
|
| 1365 | 1365 | |
| 1366 | - /** |
|
| 1367 | - * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1368 | - * |
|
| 1369 | - * Limit teachers to only see their courses, lessons and questions |
|
| 1370 | - * |
|
| 1371 | - * @since 1.8.0 |
|
| 1372 | - * @access public |
|
| 1373 | - * @parameters array $wp_query |
|
| 1374 | - * @return WP_Query $wp_query |
|
| 1375 | - */ |
|
| 1376 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1377 | - global $current_user; |
|
| 1366 | + /** |
|
| 1367 | + * Sensei_Teacher::limit_teacher_edit_screen_post_types |
|
| 1368 | + * |
|
| 1369 | + * Limit teachers to only see their courses, lessons and questions |
|
| 1370 | + * |
|
| 1371 | + * @since 1.8.0 |
|
| 1372 | + * @access public |
|
| 1373 | + * @parameters array $wp_query |
|
| 1374 | + * @return WP_Query $wp_query |
|
| 1375 | + */ |
|
| 1376 | + public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1377 | + global $current_user; |
|
| 1378 | 1378 | |
| 1379 | - //exit early |
|
| 1380 | - if( ! $this->is_admin_teacher() ){ |
|
| 1381 | - return $wp_query; |
|
| 1382 | - } |
|
| 1379 | + //exit early |
|
| 1380 | + if( ! $this->is_admin_teacher() ){ |
|
| 1381 | + return $wp_query; |
|
| 1382 | + } |
|
| 1383 | 1383 | |
| 1384 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1385 | - return $wp_query; |
|
| 1386 | - } |
|
| 1384 | + if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1385 | + return $wp_query; |
|
| 1386 | + } |
|
| 1387 | 1387 | |
| 1388 | - $screen = get_current_screen(); |
|
| 1388 | + $screen = get_current_screen(); |
|
| 1389 | 1389 | |
| 1390 | - if( empty( $screen ) ){ |
|
| 1391 | - return $wp_query; |
|
| 1392 | - } |
|
| 1390 | + if( empty( $screen ) ){ |
|
| 1391 | + return $wp_query; |
|
| 1392 | + } |
|
| 1393 | 1393 | |
| 1394 | - // for any of these conditions limit what the teacher will see |
|
| 1395 | - $limit_screens = array( |
|
| 1396 | - 'edit-lesson', |
|
| 1397 | - 'edit-course', |
|
| 1398 | - 'edit-question', |
|
| 1399 | - 'course_page_course-order', |
|
| 1400 | - 'lesson_page_lesson-order', |
|
| 1401 | - ); |
|
| 1394 | + // for any of these conditions limit what the teacher will see |
|
| 1395 | + $limit_screens = array( |
|
| 1396 | + 'edit-lesson', |
|
| 1397 | + 'edit-course', |
|
| 1398 | + 'edit-question', |
|
| 1399 | + 'course_page_course-order', |
|
| 1400 | + 'lesson_page_lesson-order', |
|
| 1401 | + ); |
|
| 1402 | 1402 | |
| 1403 | - if( in_array($screen->id , $limit_screens ) ) { |
|
| 1403 | + if( in_array($screen->id , $limit_screens ) ) { |
|
| 1404 | 1404 | |
| 1405 | - // set the query author to the current user to only show those those posts |
|
| 1406 | - $wp_query->set( 'author', $current_user->ID ); |
|
| 1407 | - } |
|
| 1405 | + // set the query author to the current user to only show those those posts |
|
| 1406 | + $wp_query->set( 'author', $current_user->ID ); |
|
| 1407 | + } |
|
| 1408 | 1408 | |
| 1409 | - return $wp_query; |
|
| 1409 | + return $wp_query; |
|
| 1410 | 1410 | |
| 1411 | - } // end limit_teacher_edit_screen_post_types() |
|
| 1411 | + } // end limit_teacher_edit_screen_post_types() |
|
| 1412 | 1412 | |
| 1413 | 1413 | |
| 1414 | - /** |
|
| 1415 | - * Sensei_Teacher::teacher_login_redirect |
|
| 1416 | - * |
|
| 1417 | - * Redirect teachers to /wp-admin/ after login |
|
| 1418 | - * |
|
| 1419 | - * @since 1.8.7 |
|
| 1420 | - * @access public |
|
| 1421 | - * @param string $user_login |
|
| 1422 | - * @param object $user |
|
| 1423 | - * @return void |
|
| 1424 | - */ |
|
| 1414 | + /** |
|
| 1415 | + * Sensei_Teacher::teacher_login_redirect |
|
| 1416 | + * |
|
| 1417 | + * Redirect teachers to /wp-admin/ after login |
|
| 1418 | + * |
|
| 1419 | + * @since 1.8.7 |
|
| 1420 | + * @access public |
|
| 1421 | + * @param string $user_login |
|
| 1422 | + * @param object $user |
|
| 1423 | + * @return void |
|
| 1424 | + */ |
|
| 1425 | 1425 | |
| 1426 | - public function teacher_login_redirect( $user_login, $user ) { |
|
| 1426 | + public function teacher_login_redirect( $user_login, $user ) { |
|
| 1427 | 1427 | |
| 1428 | - if (user_can($user, 'edit_courses')) { |
|
| 1428 | + if (user_can($user, 'edit_courses')) { |
|
| 1429 | 1429 | |
| 1430 | - if (isset($_POST['redirect_to'])) { |
|
| 1430 | + if (isset($_POST['redirect_to'])) { |
|
| 1431 | 1431 | |
| 1432 | - wp_redirect($_POST['redirect_to'], 303); |
|
| 1432 | + wp_redirect($_POST['redirect_to'], 303); |
|
| 1433 | 1433 | |
| 1434 | - exit; |
|
| 1434 | + exit; |
|
| 1435 | 1435 | |
| 1436 | - } else { |
|
| 1436 | + } else { |
|
| 1437 | 1437 | |
| 1438 | - wp_redirect(admin_url(), 303); |
|
| 1438 | + wp_redirect(admin_url(), 303); |
|
| 1439 | 1439 | |
| 1440 | - exit; |
|
| 1440 | + exit; |
|
| 1441 | 1441 | |
| 1442 | - } |
|
| 1443 | - } |
|
| 1442 | + } |
|
| 1443 | + } |
|
| 1444 | 1444 | |
| 1445 | - } // end teacher_login_redirect() |
|
| 1445 | + } // end teacher_login_redirect() |
|
| 1446 | 1446 | |
| 1447 | 1447 | |
| 1448 | 1448 | |
| 1449 | - /** |
|
| 1450 | - * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1451 | - * |
|
| 1452 | - * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1453 | - * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1454 | - * so they can 'moderate_comments' as well. |
|
| 1455 | - * |
|
| 1456 | - * @since 1.8.7 |
|
| 1457 | - * @access public |
|
| 1458 | - * @parameters void |
|
| 1459 | - * @return void |
|
| 1460 | - */ |
|
| 1449 | + /** |
|
| 1450 | + * Sensei_Teacher::restrict_posts_menu_page() |
|
| 1451 | + * |
|
| 1452 | + * Remove the Posts menu page for teachers and restrict access to it. |
|
| 1453 | + * We have to do this because we give teachers the 'edit_posts' cap |
|
| 1454 | + * so they can 'moderate_comments' as well. |
|
| 1455 | + * |
|
| 1456 | + * @since 1.8.7 |
|
| 1457 | + * @access public |
|
| 1458 | + * @parameters void |
|
| 1459 | + * @return void |
|
| 1460 | + */ |
|
| 1461 | 1461 | |
| 1462 | - public function restrict_posts_menu_page() { |
|
| 1462 | + public function restrict_posts_menu_page() { |
|
| 1463 | 1463 | |
| 1464 | - global $pagenow, $typenow; |
|
| 1464 | + global $pagenow, $typenow; |
|
| 1465 | 1465 | |
| 1466 | - $user = wp_get_current_user(); |
|
| 1466 | + $user = wp_get_current_user(); |
|
| 1467 | 1467 | |
| 1468 | - /** |
|
| 1469 | - * Filter the option to hide the Posts menu page. |
|
| 1470 | - * |
|
| 1471 | - * @since 1.8.7 |
|
| 1472 | - * |
|
| 1473 | - * @param bool $restrict default true |
|
| 1474 | - */ |
|
| 1468 | + /** |
|
| 1469 | + * Filter the option to hide the Posts menu page. |
|
| 1470 | + * |
|
| 1471 | + * @since 1.8.7 |
|
| 1472 | + * |
|
| 1473 | + * @param bool $restrict default true |
|
| 1474 | + */ |
|
| 1475 | 1475 | |
| 1476 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1476 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1477 | 1477 | |
| 1478 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1478 | + if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1479 | 1479 | |
| 1480 | - remove_menu_page('edit.php'); |
|
| 1480 | + remove_menu_page('edit.php'); |
|
| 1481 | 1481 | |
| 1482 | - if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1482 | + if ($pagenow == "edit.php" || $pagenow == "post-new.php") { |
|
| 1483 | 1483 | |
| 1484 | - if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1484 | + if ($typenow == '' || $typenow == 'post' || $typenow == 'page') { |
|
| 1485 | 1485 | |
| 1486 | - wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1486 | + wp_die('You do not have sufficient permissions to access this page.'); |
|
| 1487 | 1487 | |
| 1488 | - } |
|
| 1488 | + } |
|
| 1489 | 1489 | |
| 1490 | - } |
|
| 1490 | + } |
|
| 1491 | 1491 | |
| 1492 | - } |
|
| 1492 | + } |
|
| 1493 | 1493 | |
| 1494 | - } // end restrict_posts_menu_page() |
|
| 1494 | + } // end restrict_posts_menu_page() |
|
| 1495 | 1495 | |
| 1496 | - /** |
|
| 1497 | - * Sensei_Teacher::restrict_comment_moderation() |
|
| 1498 | - * |
|
| 1499 | - * Restrict commendation moderation for teachers |
|
| 1500 | - * so they can only moderate comments made to posts they own. |
|
| 1501 | - * |
|
| 1502 | - * @since 1.8.7 |
|
| 1503 | - * @access public |
|
| 1504 | - * @parameters obj $clauses |
|
| 1505 | - * @return obj $clauses |
|
| 1506 | - */ |
|
| 1496 | + /** |
|
| 1497 | + * Sensei_Teacher::restrict_comment_moderation() |
|
| 1498 | + * |
|
| 1499 | + * Restrict commendation moderation for teachers |
|
| 1500 | + * so they can only moderate comments made to posts they own. |
|
| 1501 | + * |
|
| 1502 | + * @since 1.8.7 |
|
| 1503 | + * @access public |
|
| 1504 | + * @parameters obj $clauses |
|
| 1505 | + * @return obj $clauses |
|
| 1506 | + */ |
|
| 1507 | 1507 | |
| 1508 | - public function restrict_comment_moderation($clauses) { |
|
| 1508 | + public function restrict_comment_moderation($clauses) { |
|
| 1509 | 1509 | |
| 1510 | - global $pagenow; |
|
| 1510 | + global $pagenow; |
|
| 1511 | 1511 | |
| 1512 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1512 | + if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1513 | 1513 | |
| 1514 | - $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1514 | + $clauses->query_vars['post_author'] = get_current_user_id(); |
|
| 1515 | 1515 | |
| 1516 | - } |
|
| 1516 | + } |
|
| 1517 | 1517 | |
| 1518 | - return $clauses; |
|
| 1518 | + return $clauses; |
|
| 1519 | 1519 | |
| 1520 | - } // end restrict_comment_moderation() |
|
| 1520 | + } // end restrict_comment_moderation() |
|
| 1521 | 1521 | |
| 1522 | - /** |
|
| 1523 | - * Determine if a user is a teacher by ID |
|
| 1524 | - * |
|
| 1525 | - * @param int $user_id |
|
| 1526 | - * |
|
| 1527 | - * @return bool |
|
| 1528 | - */ |
|
| 1529 | - public static function is_a_teacher( $user_id ){ |
|
| 1522 | + /** |
|
| 1523 | + * Determine if a user is a teacher by ID |
|
| 1524 | + * |
|
| 1525 | + * @param int $user_id |
|
| 1526 | + * |
|
| 1527 | + * @return bool |
|
| 1528 | + */ |
|
| 1529 | + public static function is_a_teacher( $user_id ){ |
|
| 1530 | 1530 | |
| 1531 | - $user = get_user_by('id', $user_id); |
|
| 1531 | + $user = get_user_by('id', $user_id); |
|
| 1532 | 1532 | |
| 1533 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1533 | + if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1534 | 1534 | |
| 1535 | - return true; |
|
| 1535 | + return true; |
|
| 1536 | 1536 | |
| 1537 | - }else{ |
|
| 1537 | + }else{ |
|
| 1538 | 1538 | |
| 1539 | - return false; |
|
| 1539 | + return false; |
|
| 1540 | 1540 | |
| 1541 | - } |
|
| 1541 | + } |
|
| 1542 | 1542 | |
| 1543 | - }// end is_a_teacher |
|
| 1543 | + }// end is_a_teacher |
|
| 1544 | 1544 | |
| 1545 | - /** |
|
| 1546 | - * The archive title on the teacher archive filter |
|
| 1547 | - * |
|
| 1548 | - * @since 1.9.0 |
|
| 1549 | - */ |
|
| 1550 | - public static function archive_title(){ |
|
| 1545 | + /** |
|
| 1546 | + * The archive title on the teacher archive filter |
|
| 1547 | + * |
|
| 1548 | + * @since 1.9.0 |
|
| 1549 | + */ |
|
| 1550 | + public static function archive_title(){ |
|
| 1551 | 1551 | |
| 1552 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1553 | - $author_name = $author->display_name; |
|
| 1554 | - ?> |
|
| 1552 | + $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1553 | + $author_name = $author->display_name; |
|
| 1554 | + ?> |
|
| 1555 | 1555 | <h2 class="teacher-archive-title"> |
| 1556 | 1556 | |
| 1557 | 1557 | <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
@@ -1559,17 +1559,17 @@ discard block |
||
| 1559 | 1559 | </h2> |
| 1560 | 1560 | <?php |
| 1561 | 1561 | |
| 1562 | - }// archive title |
|
| 1562 | + }// archive title |
|
| 1563 | 1563 | |
| 1564 | - /** |
|
| 1565 | - * Removing course meta on the teacher archive page |
|
| 1566 | - * |
|
| 1567 | - * @since 1.9.0 |
|
| 1568 | - */ |
|
| 1569 | - public static function remove_course_meta_on_teacher_archive(){ |
|
| 1564 | + /** |
|
| 1565 | + * Removing course meta on the teacher archive page |
|
| 1566 | + * |
|
| 1567 | + * @since 1.9.0 |
|
| 1568 | + */ |
|
| 1569 | + public static function remove_course_meta_on_teacher_archive(){ |
|
| 1570 | 1570 | |
| 1571 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1571 | + remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1572 | 1572 | |
| 1573 | - } |
|
| 1573 | + } |
|
| 1574 | 1574 | |
| 1575 | 1575 | } // End Class |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Teacher class |
@@ -42,58 +42,58 @@ discard block |
||
| 42 | 42 | * @since 1.8.0 |
| 43 | 43 | * @access public |
| 44 | 44 | */ |
| 45 | - public function __construct ( ) { |
|
| 45 | + public function __construct( ) { |
|
| 46 | 46 | |
| 47 | - add_action( 'add_meta_boxes', array( $this , 'add_teacher_meta_boxes' ) , 10, 2 ); |
|
| 48 | - add_action( 'save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 49 | - add_filter( 'parse_query', array( $this, 'limit_teacher_edit_screen_post_types' )); |
|
| 50 | - add_filter( 'pre_get_posts', array( $this, 'course_analysis_teacher_access_limit' ) ); |
|
| 51 | - add_filter( 'wp_count_posts', array( $this, 'list_table_counts' ), 10, 3 ); |
|
| 47 | + add_action('add_meta_boxes', array($this, 'add_teacher_meta_boxes'), 10, 2); |
|
| 48 | + add_action('save_post', array($this, 'save_teacher_meta_box')); |
|
| 49 | + add_filter('parse_query', array($this, 'limit_teacher_edit_screen_post_types')); |
|
| 50 | + add_filter('pre_get_posts', array($this, 'course_analysis_teacher_access_limit')); |
|
| 51 | + add_filter('wp_count_posts', array($this, 'list_table_counts'), 10, 3); |
|
| 52 | 52 | |
| 53 | - add_action( 'pre_get_posts', array( $this, 'filter_queries' ) ); |
|
| 53 | + add_action('pre_get_posts', array($this, 'filter_queries')); |
|
| 54 | 54 | |
| 55 | 55 | //filter the quiz submissions |
| 56 | - add_filter( 'sensei_check_for_activity' , array( $this, 'filter_grading_activity_queries') ); |
|
| 56 | + add_filter('sensei_check_for_activity', array($this, 'filter_grading_activity_queries')); |
|
| 57 | 57 | |
| 58 | 58 | //grading totals count only those belonging to the teacher |
| 59 | - add_filter('sensei_count_statuses_args', array( $this, 'limit_grading_totals' ) ); |
|
| 59 | + add_filter('sensei_count_statuses_args', array($this, 'limit_grading_totals')); |
|
| 60 | 60 | |
| 61 | 61 | // show the courses owned by a user on his author archive page |
| 62 | - add_filter( 'pre_get_posts', array( $this, 'add_courses_to_author_archive' ) ); |
|
| 62 | + add_filter('pre_get_posts', array($this, 'add_courses_to_author_archive')); |
|
| 63 | 63 | |
| 64 | 64 | // notify admin when a teacher creates a course |
| 65 | - add_action( 'transition_post_status',array( $this, 'notify_admin_teacher_course_creation' ), 10, 3 ); |
|
| 65 | + add_action('transition_post_status', array($this, 'notify_admin_teacher_course_creation'), 10, 3); |
|
| 66 | 66 | |
| 67 | 67 | // limit the analysis view to only the users taking courses belong to this teacher |
| 68 | - add_filter( 'sensei_analysis_overview_filter_users',array( $this, 'limit_analysis_learners' ) , 5, 1 ); |
|
| 68 | + add_filter('sensei_analysis_overview_filter_users', array($this, 'limit_analysis_learners'), 5, 1); |
|
| 69 | 69 | |
| 70 | 70 | // give teacher access to question post type |
| 71 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20, 2 ); |
|
| 71 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
| 72 | 72 | |
| 73 | 73 | // Teacher column on the courses list on the admin edit screen |
| 74 | - add_filter('manage_edit-course_columns' , array( $this, 'course_column_heading'), 10,1 ); |
|
| 75 | - add_filter('manage_course_posts_custom_column' , array( $this, 'course_column_data'), 10,2 ); |
|
| 74 | + add_filter('manage_edit-course_columns', array($this, 'course_column_heading'), 10, 1); |
|
| 75 | + add_filter('manage_course_posts_custom_column', array($this, 'course_column_data'), 10, 2); |
|
| 76 | 76 | |
| 77 | 77 | //admin edit messages query limit teacher |
| 78 | - add_filter( 'pre_get_posts', array( $this, 'limit_edit_messages_query' ) ); |
|
| 78 | + add_filter('pre_get_posts', array($this, 'limit_edit_messages_query')); |
|
| 79 | 79 | |
| 80 | 80 | //add filter by teacher on courses list |
| 81 | - add_action( 'restrict_manage_posts', array( $this, 'course_teacher_filter_options' ) ); |
|
| 82 | - add_filter( 'request', array( $this, 'teacher_filter_query_modify' ) ); |
|
| 81 | + add_action('restrict_manage_posts', array($this, 'course_teacher_filter_options')); |
|
| 82 | + add_filter('request', array($this, 'teacher_filter_query_modify')); |
|
| 83 | 83 | |
| 84 | 84 | // Handle media library restrictions |
| 85 | - add_filter( 'request', array( $this, 'restrict_media_library' ), 10, 1 ); |
|
| 86 | - add_filter( 'ajax_query_attachments_args', array( $this, 'restrict_media_library_modal' ), 10, 1 ); |
|
| 85 | + add_filter('request', array($this, 'restrict_media_library'), 10, 1); |
|
| 86 | + add_filter('ajax_query_attachments_args', array($this, 'restrict_media_library_modal'), 10, 1); |
|
| 87 | 87 | |
| 88 | 88 | // update lesson owner to course teacher when saved |
| 89 | - add_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 89 | + add_action('save_post', array($this, 'update_lesson_teacher')); |
|
| 90 | 90 | |
| 91 | 91 | // If a Teacher logs in, redirect to /wp-admin/ |
| 92 | - add_filter( 'wp_login', array( $this, 'teacher_login_redirect') , 10, 2 ); |
|
| 92 | + add_filter('wp_login', array($this, 'teacher_login_redirect'), 10, 2); |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | - add_action( 'admin_menu', array( $this, 'restrict_posts_menu_page'), 10); |
|
| 96 | - add_filter('pre_get_comments', array ($this, 'restrict_comment_moderation'), 10, 1); |
|
| 95 | + add_action('admin_menu', array($this, 'restrict_posts_menu_page'), 10); |
|
| 96 | + add_filter('pre_get_comments', array($this, 'restrict_comment_moderation'), 10, 1); |
|
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | } // end __constructor() |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | * @access public |
| 109 | 109 | * @return void |
| 110 | 110 | */ |
| 111 | - public function create_role ( ) { |
|
| 111 | + public function create_role( ) { |
|
| 112 | 112 | |
| 113 | 113 | // check if the role exists |
| 114 | - $this->teacher_role = get_role( 'teacher' ); |
|
| 114 | + $this->teacher_role = get_role('teacher'); |
|
| 115 | 115 | |
| 116 | 116 | // if the the teacher is not a valid WordPress role create it |
| 117 | - if ( ! is_a( $this->teacher_role, 'WP_Role' ) ) { |
|
| 117 | + if ( ! is_a($this->teacher_role, 'WP_Role')) { |
|
| 118 | 118 | // create the role |
| 119 | - $this->teacher_role = add_role( 'teacher', __( 'Teacher', 'woothemes-sensei' ) ); |
|
| 119 | + $this->teacher_role = add_role('teacher', __('Teacher', 'woothemes-sensei')); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // add the capabilities before returning |
@@ -130,10 +130,10 @@ discard block |
||
| 130 | 130 | * @since 1.8.0 |
| 131 | 131 | * @access protected |
| 132 | 132 | */ |
| 133 | - protected function add_capabilities ( ) { |
|
| 133 | + protected function add_capabilities( ) { |
|
| 134 | 134 | |
| 135 | 135 | // if this is not a valid WP_Role object exit without adding anything |
| 136 | - if( ! is_a( $this->teacher_role, 'WP_Role' ) || empty( $this->teacher_role ) ) { |
|
| 136 | + if ( ! is_a($this->teacher_role, 'WP_Role') || empty($this->teacher_role)) { |
|
| 137 | 137 | return; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param array $capabilities |
| 145 | 145 | * keys: (string) $cap_name => (bool) $grant |
| 146 | 146 | */ |
| 147 | - $caps = apply_filters( 'sensei_teacher_role_capabilities', array( |
|
| 147 | + $caps = apply_filters('sensei_teacher_role_capabilities', array( |
|
| 148 | 148 | // General access rules |
| 149 | 149 | 'read' => true, |
| 150 | 150 | 'manage_sensei_grades' => true, |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | )); |
| 203 | 203 | |
| 204 | - foreach ( $caps as $cap => $grant ) { |
|
| 204 | + foreach ($caps as $cap => $grant) { |
|
| 205 | 205 | |
| 206 | 206 | // load the capability on to the teacher role |
| 207 | 207 | $this->teacher_role->add_cap($cap, $grant); |
@@ -221,12 +221,12 @@ discard block |
||
| 221 | 221 | * @parameter WP_Post $post |
| 222 | 222 | * @return void |
| 223 | 223 | */ |
| 224 | - public function add_teacher_meta_boxes ( $post ) { |
|
| 224 | + public function add_teacher_meta_boxes($post) { |
|
| 225 | 225 | |
| 226 | - if( !current_user_can('manage_options') ){ |
|
| 226 | + if ( ! current_user_can('manage_options')) { |
|
| 227 | 227 | return; |
| 228 | 228 | } |
| 229 | - add_meta_box( 'sensei-teacher', __( 'Teacher' , 'woothemes-sensei'), array( $this , 'teacher_meta_box_content' ), |
|
| 229 | + add_meta_box('sensei-teacher', __('Teacher', 'woothemes-sensei'), array($this, 'teacher_meta_box_content'), |
|
| 230 | 230 | 'course', |
| 231 | 231 | 'side', |
| 232 | 232 | 'core' |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * @access public |
| 244 | 244 | * @parameters |
| 245 | 245 | */ |
| 246 | - public function teacher_meta_box_content ( $post ) { |
|
| 246 | + public function teacher_meta_box_content($post) { |
|
| 247 | 247 | |
| 248 | 248 | // get the current author |
| 249 | 249 | $current_author = $post->post_author; |
@@ -254,12 +254,12 @@ discard block |
||
| 254 | 254 | ?> |
| 255 | 255 | <select name="sensei-course-teacher-author" class="sensei course teacher"> |
| 256 | 256 | |
| 257 | - <?php foreach ( $users as $user_id ) { ?> |
|
| 257 | + <?php foreach ($users as $user_id) { ?> |
|
| 258 | 258 | |
| 259 | 259 | <?php |
| 260 | 260 | $user = get_user_by('id', $user_id); |
| 261 | 261 | ?> |
| 262 | - <option <?php selected( $current_author , $user_id , true ); ?> value="<?php echo $user_id; ?>" > |
|
| 262 | + <option <?php selected($current_author, $user_id, true); ?> value="<?php echo $user_id; ?>" > |
|
| 263 | 263 | <?php echo $user->display_name; ?> |
| 264 | 264 | </option> |
| 265 | 265 | |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @parameters |
| 282 | 282 | * @return array $users user id array |
| 283 | 283 | */ |
| 284 | - public function get_teachers_and_authors ( ){ |
|
| 284 | + public function get_teachers_and_authors( ) { |
|
| 285 | 285 | |
| 286 | 286 | $author_query_args = array( |
| 287 | 287 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | 'who' => 'authors' |
| 290 | 290 | ); |
| 291 | 291 | |
| 292 | - $authors = get_users( $author_query_args ); |
|
| 292 | + $authors = get_users($author_query_args); |
|
| 293 | 293 | |
| 294 | 294 | $teacher_query_args = array( |
| 295 | 295 | 'blog_id' => $GLOBALS['blog_id'], |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | 'role' => 'teacher', |
| 298 | 298 | ); |
| 299 | 299 | |
| 300 | - $teachers = get_users( $teacher_query_args ); |
|
| 300 | + $teachers = get_users($teacher_query_args); |
|
| 301 | 301 | |
| 302 | - return array_unique( array_merge( $teachers, $authors ) ); |
|
| 302 | + return array_unique(array_merge($teachers, $authors)); |
|
| 303 | 303 | |
| 304 | 304 | }// end get_teachers_and_authors |
| 305 | 305 | |
@@ -315,43 +315,43 @@ discard block |
||
| 315 | 315 | * @parameters |
| 316 | 316 | * @return array $users user id array |
| 317 | 317 | */ |
| 318 | - public function save_teacher_meta_box ( $course_id ){ |
|
| 318 | + public function save_teacher_meta_box($course_id) { |
|
| 319 | 319 | |
| 320 | 320 | // check if this is a post from saving the teacher, if not exit early |
| 321 | - if(! isset( $_POST[ 'sensei-course-teacher-author' ] ) || ! isset( $_POST['post_ID'] ) ){ |
|
| 321 | + if ( ! isset($_POST['sensei-course-teacher-author']) || ! isset($_POST['post_ID'])) { |
|
| 322 | 322 | return; |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | //don't fire this hook again |
| 326 | - remove_action('save_post', array( $this, 'save_teacher_meta_box' ) ); |
|
| 326 | + remove_action('save_post', array($this, 'save_teacher_meta_box')); |
|
| 327 | 327 | |
| 328 | 328 | // get the current post object |
| 329 | - $post = get_post( $course_id ); |
|
| 329 | + $post = get_post($course_id); |
|
| 330 | 330 | |
| 331 | 331 | // get the current teacher/author |
| 332 | - $current_author = absint( $post->post_author ); |
|
| 333 | - $new_author = absint( $_POST[ 'sensei-course-teacher-author' ] ); |
|
| 332 | + $current_author = absint($post->post_author); |
|
| 333 | + $new_author = absint($_POST['sensei-course-teacher-author']); |
|
| 334 | 334 | |
| 335 | 335 | // loop through all post lessons to update their authors as well |
| 336 | - $this->update_course_lessons_author( $course_id , $new_author ); |
|
| 336 | + $this->update_course_lessons_author($course_id, $new_author); |
|
| 337 | 337 | |
| 338 | 338 | // do not do any processing if the selected author is the same as the current author |
| 339 | - if( $current_author == $new_author ){ |
|
| 339 | + if ($current_author == $new_author) { |
|
| 340 | 340 | return; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | // save the course author |
| 344 | 344 | $post_updates = array( |
| 345 | - 'ID' => $post->ID , |
|
| 345 | + 'ID' => $post->ID, |
|
| 346 | 346 | 'post_author' => $new_author |
| 347 | 347 | ); |
| 348 | - wp_update_post( $post_updates ); |
|
| 348 | + wp_update_post($post_updates); |
|
| 349 | 349 | |
| 350 | 350 | // ensure the the modules are update so that then new teacher has access to them |
| 351 | - Sensei_Teacher::update_course_modules_author( $course_id, $new_author ); |
|
| 351 | + Sensei_Teacher::update_course_modules_author($course_id, $new_author); |
|
| 352 | 352 | |
| 353 | 353 | // notify the new teacher |
| 354 | - $this->teacher_course_assigned_notification( $new_author, $course_id ); |
|
| 354 | + $this->teacher_course_assigned_notification($new_author, $course_id); |
|
| 355 | 355 | |
| 356 | 356 | } // end save_teacher_meta_box |
| 357 | 357 | |
@@ -365,56 +365,56 @@ discard block |
||
| 365 | 365 | * @param $new_teacher_id |
| 366 | 366 | * @return void |
| 367 | 367 | */ |
| 368 | - public static function update_course_modules_author( $course_id ,$new_teacher_id ){ |
|
| 368 | + public static function update_course_modules_author($course_id, $new_teacher_id) { |
|
| 369 | 369 | |
| 370 | - if( empty( $course_id ) || empty( $new_teacher_id ) ){ |
|
| 370 | + if (empty($course_id) || empty($new_teacher_id)) { |
|
| 371 | 371 | return false; |
| 372 | 372 | } |
| 373 | 373 | |
| 374 | - $terms_selected_on_course = wp_get_object_terms( $course_id, 'module' ); |
|
| 374 | + $terms_selected_on_course = wp_get_object_terms($course_id, 'module'); |
|
| 375 | 375 | |
| 376 | - if( empty( $terms_selected_on_course ) ){ |
|
| 376 | + if (empty($terms_selected_on_course)) { |
|
| 377 | 377 | return; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - foreach( $terms_selected_on_course as $term ){ |
|
| 380 | + foreach ($terms_selected_on_course as $term) { |
|
| 381 | 381 | |
| 382 | - $term_author = Sensei_Core_Modules::get_term_author( $term->slug ); |
|
| 383 | - if( $new_teacher_id != $term_author->ID ){ |
|
| 382 | + $term_author = Sensei_Core_Modules::get_term_author($term->slug); |
|
| 383 | + if ($new_teacher_id != $term_author->ID) { |
|
| 384 | 384 | |
| 385 | 385 | $new_term = ''; |
| 386 | 386 | |
| 387 | 387 | //if the new teacher is admin first check to see if the term with this name already exists |
| 388 | - if( user_can( $new_teacher_id, 'manage_options' ) ){ |
|
| 388 | + if (user_can($new_teacher_id, 'manage_options')) { |
|
| 389 | 389 | |
| 390 | - $slug_without_teacher_id = str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 391 | - $term_args = array( 'slug'=> $slug_without_teacher_id, 'hide_empty' => false, ); |
|
| 392 | - $existing_admin_terms = get_terms( 'module', $term_args ); |
|
| 393 | - if( !empty( $existing_admin_terms ) ){ |
|
| 390 | + $slug_without_teacher_id = str_ireplace(' ', '-', trim($term->name)); |
|
| 391 | + $term_args = array('slug'=> $slug_without_teacher_id, 'hide_empty' => false,); |
|
| 392 | + $existing_admin_terms = get_terms('module', $term_args); |
|
| 393 | + if ( ! empty($existing_admin_terms)) { |
|
| 394 | 394 | // insert it even if it exists |
| 395 | - $new_term = get_term( $existing_admin_terms[0]->term_id, 'module', ARRAY_A ); |
|
| 395 | + $new_term = get_term($existing_admin_terms[0]->term_id, 'module', ARRAY_A); |
|
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - if( empty ( $new_term ) ){ |
|
| 399 | + if (empty ($new_term)) { |
|
| 400 | 400 | |
| 401 | 401 | //setup the new slug |
| 402 | - $new_author_term_slug = $new_teacher_id . '-' . str_ireplace(' ', '-', trim( $term->name ) ); |
|
| 402 | + $new_author_term_slug = $new_teacher_id.'-'.str_ireplace(' ', '-', trim($term->name)); |
|
| 403 | 403 | |
| 404 | 404 | // create new term and set it |
| 405 | - $new_term = wp_insert_term( $term->name,'module', array('slug'=> $new_author_term_slug ) ); |
|
| 405 | + $new_term = wp_insert_term($term->name, 'module', array('slug'=> $new_author_term_slug)); |
|
| 406 | 406 | |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
| 410 | 410 | |
| 411 | 411 | // if term exists |
| 412 | - if( is_wp_error( $new_term ) && isset( $new_term->errors['term_exists'] ) ){ |
|
| 412 | + if (is_wp_error($new_term) && isset($new_term->errors['term_exists'])) { |
|
| 413 | 413 | |
| 414 | - $existing_term = get_term_by( 'slug', $new_author_term_slug, 'module'); |
|
| 414 | + $existing_term = get_term_by('slug', $new_author_term_slug, 'module'); |
|
| 415 | 415 | $term_id = $existing_term->term_id; |
| 416 | 416 | |
| 417 | - }else{ |
|
| 417 | + } else { |
|
| 418 | 418 | |
| 419 | 419 | // for a new term simply get the term from the returned value |
| 420 | 420 | $term_id = $new_term['term_id']; |
@@ -422,21 +422,21 @@ discard block |
||
| 422 | 422 | } // end if term exist |
| 423 | 423 | |
| 424 | 424 | // set the terms selected on the course |
| 425 | - wp_set_object_terms( $course_id, $term_id , 'module', true ); |
|
| 425 | + wp_set_object_terms($course_id, $term_id, 'module', true); |
|
| 426 | 426 | |
| 427 | 427 | // remove old term |
| 428 | - wp_remove_object_terms( $course_id, $term->term_id, 'module' ); |
|
| 428 | + wp_remove_object_terms($course_id, $term->term_id, 'module'); |
|
| 429 | 429 | |
| 430 | 430 | // update the lessons within the current module term |
| 431 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 432 | - foreach( $lessons as $lesson ){ |
|
| 431 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 432 | + foreach ($lessons as $lesson) { |
|
| 433 | 433 | |
| 434 | - if( has_term( $term->slug, 'module', $lesson ) ){ |
|
| 434 | + if (has_term($term->slug, 'module', $lesson)) { |
|
| 435 | 435 | |
| 436 | 436 | // add the new term, the false at the end says to replace all terms on this module |
| 437 | 437 | // with the new term. |
| 438 | - wp_set_object_terms( $lesson->ID, $term_id , 'module', false ); |
|
| 439 | - update_post_meta( $lesson->ID, '_order_module_' . intval( $term_id ), 0 ); |
|
| 438 | + wp_set_object_terms($lesson->ID, $term_id, 'module', false); |
|
| 439 | + update_post_meta($lesson->ID, '_order_module_'.intval($term_id), 0); |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | }// end for each |
@@ -456,50 +456,50 @@ discard block |
||
| 456 | 456 | * @parameters |
| 457 | 457 | * @return array $users user id array |
| 458 | 458 | */ |
| 459 | - public function update_course_lessons_author ( $course_id, $new_author ){ |
|
| 459 | + public function update_course_lessons_author($course_id, $new_author) { |
|
| 460 | 460 | |
| 461 | 461 | |
| 462 | - if( empty( $course_id ) || empty( $new_author ) ){ |
|
| 462 | + if (empty($course_id) || empty($new_author)) { |
|
| 463 | 463 | return false; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | //get a list of course lessons |
| 467 | - $lessons = Sensei()->course->course_lessons( $course_id ); |
|
| 467 | + $lessons = Sensei()->course->course_lessons($course_id); |
|
| 468 | 468 | |
| 469 | - if( empty( $lessons ) || ! is_array( $lessons ) ){ |
|
| 469 | + if (empty($lessons) || ! is_array($lessons)) { |
|
| 470 | 470 | return false; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // update each lesson and quiz author |
| 474 | - foreach( $lessons as $lesson ){ |
|
| 474 | + foreach ($lessons as $lesson) { |
|
| 475 | 475 | |
| 476 | 476 | // don't update if the author is tha same as the new author |
| 477 | - if( $new_author == $lesson->post_author ){ |
|
| 477 | + if ($new_author == $lesson->post_author) { |
|
| 478 | 478 | continue; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | // update lesson author |
| 482 | - wp_update_post( array( |
|
| 482 | + wp_update_post(array( |
|
| 483 | 483 | 'ID'=> $lesson->ID, |
| 484 | 484 | 'post_author' => $new_author |
| 485 | - ) ); |
|
| 485 | + )); |
|
| 486 | 486 | |
| 487 | 487 | // update quiz author |
| 488 | 488 | //get the lessons quiz |
| 489 | - $lesson_quizzes = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 490 | - if( is_array( $lesson_quizzes ) ){ |
|
| 491 | - foreach ( $lesson_quizzes as $quiz_id ) { |
|
| 489 | + $lesson_quizzes = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 490 | + if (is_array($lesson_quizzes)) { |
|
| 491 | + foreach ($lesson_quizzes as $quiz_id) { |
|
| 492 | 492 | // update quiz with new author |
| 493 | - wp_update_post( array( |
|
| 493 | + wp_update_post(array( |
|
| 494 | 494 | 'ID' => $quiz_id, |
| 495 | 495 | 'post_author' => $new_author |
| 496 | - ) ); |
|
| 496 | + )); |
|
| 497 | 497 | } |
| 498 | - }else{ |
|
| 499 | - wp_update_post( array( |
|
| 498 | + } else { |
|
| 499 | + wp_update_post(array( |
|
| 500 | 500 | 'ID' => $lesson_quizzes, |
| 501 | 501 | 'post_author' => $new_author |
| 502 | - ) ); |
|
| 502 | + )); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | } // end for each lessons |
@@ -520,30 +520,30 @@ discard block |
||
| 520 | 520 | * @parameters $query |
| 521 | 521 | * @return array $users user id array |
| 522 | 522 | */ |
| 523 | - public function course_analysis_teacher_access_limit ( $query ) { |
|
| 523 | + public function course_analysis_teacher_access_limit($query) { |
|
| 524 | 524 | |
| 525 | - if( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { |
|
| 525 | + if ( ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 526 | 526 | return $query; |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 529 | + if ( ! function_exists('get_current_screen')) { |
|
| 530 | 530 | return $query; |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | $screen = get_current_screen(); |
| 534 | - $sensei_post_types = array('course', 'lesson', 'question' ); |
|
| 534 | + $sensei_post_types = array('course', 'lesson', 'question'); |
|
| 535 | 535 | |
| 536 | 536 | // exit early for the following conditions |
| 537 | - $limit_screen_ids = array( 'sensei_page_sensei_analysis', 'course_page_module-order' ); |
|
| 537 | + $limit_screen_ids = array('sensei_page_sensei_analysis', 'course_page_module-order'); |
|
| 538 | 538 | |
| 539 | - if( ! $this->is_admin_teacher() || empty( $screen ) || ! in_array( $screen->id ,$limit_screen_ids ) |
|
| 540 | - || ! in_array( $query->query['post_type'], $sensei_post_types ) ){ |
|
| 539 | + if ( ! $this->is_admin_teacher() || empty($screen) || ! in_array($screen->id, $limit_screen_ids) |
|
| 540 | + || ! in_array($query->query['post_type'], $sensei_post_types)) { |
|
| 541 | 541 | return $query; |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | global $current_user; |
| 545 | 545 | // set the query author to the current user to only show those those posts |
| 546 | - $query->set( 'author', $current_user->ID ); |
|
| 546 | + $query->set('author', $current_user->ID); |
|
| 547 | 547 | return $query; |
| 548 | 548 | |
| 549 | 549 | }// end course_analysis_teacher_access_limit |
@@ -559,14 +559,14 @@ discard block |
||
| 559 | 559 | * @parameters array $wp_query |
| 560 | 560 | * @return bool $is_admin_teacher |
| 561 | 561 | */ |
| 562 | - public function is_admin_teacher ( ){ |
|
| 562 | + public function is_admin_teacher( ) { |
|
| 563 | 563 | |
| 564 | - if( ! is_user_logged_in()){ |
|
| 564 | + if ( ! is_user_logged_in()) { |
|
| 565 | 565 | return false; |
| 566 | 566 | } |
| 567 | 567 | $is_admin_teacher = false; |
| 568 | 568 | |
| 569 | - if( is_admin() && Sensei_Teacher::is_a_teacher( get_current_user_id() ) ){ |
|
| 569 | + if (is_admin() && Sensei_Teacher::is_a_teacher(get_current_user_id())) { |
|
| 570 | 570 | |
| 571 | 571 | $is_admin_teacher = true; |
| 572 | 572 | |
@@ -586,14 +586,14 @@ discard block |
||
| 586 | 586 | * @param string $perm User permission level |
| 587 | 587 | * @return object Modified status counts |
| 588 | 588 | */ |
| 589 | - public function list_table_counts( $counts, $type, $perm ) { |
|
| 589 | + public function list_table_counts($counts, $type, $perm) { |
|
| 590 | 590 | global $current_user; |
| 591 | 591 | |
| 592 | - if( ! in_array( $type, array( 'course', 'lesson', 'question' ) ) ) { |
|
| 592 | + if ( ! in_array($type, array('course', 'lesson', 'question'))) { |
|
| 593 | 593 | return $counts; |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - if( ! $this->is_admin_teacher() ) { |
|
| 596 | + if ( ! $this->is_admin_teacher()) { |
|
| 597 | 597 | return $counts; |
| 598 | 598 | } |
| 599 | 599 | |
@@ -607,10 +607,10 @@ discard block |
||
| 607 | 607 | $stati = get_post_stati(); |
| 608 | 608 | |
| 609 | 609 | // Update count object |
| 610 | - foreach( $stati as $status ) { |
|
| 610 | + foreach ($stati as $status) { |
|
| 611 | 611 | $args['post_status'] = $status; |
| 612 | - $posts = get_posts( $args ); |
|
| 613 | - $counts->$status = count( $posts ); |
|
| 612 | + $posts = get_posts($args); |
|
| 613 | + $counts->$status = count($posts); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | return $counts; |
@@ -624,22 +624,22 @@ discard block |
||
| 624 | 624 | * @since 1.8.0 |
| 625 | 625 | * |
| 626 | 626 | */ |
| 627 | - public function filter_queries ( $query ) { |
|
| 627 | + public function filter_queries($query) { |
|
| 628 | 628 | global $current_user; |
| 629 | 629 | |
| 630 | - if( ! $this->is_admin_teacher() ) { |
|
| 630 | + if ( ! $this->is_admin_teacher()) { |
|
| 631 | 631 | return; |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 634 | + if ( ! function_exists('get_current_screen')) { |
|
| 635 | 635 | return; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | $screen = get_current_screen(); |
| 639 | - if( empty( $screen ) ) { |
|
| 639 | + if (empty($screen)) { |
|
| 640 | 640 | return $query; |
| 641 | 641 | } |
| 642 | - switch( $screen->id ) { |
|
| 642 | + switch ($screen->id) { |
|
| 643 | 643 | case 'sensei_page_sensei_grading': |
| 644 | 644 | case 'sensei_page_sensei_analysis': |
| 645 | 645 | case 'sensei_page_sensei_learners': |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | * @param string $screen_id |
| 659 | 659 | * |
| 660 | 660 | */ |
| 661 | - $query->set( 'author', apply_filters( 'sensei_filter_queries_set_author', $current_user->ID, $screen->id ) ); |
|
| 661 | + $query->set('author', apply_filters('sensei_filter_queries_set_author', $current_user->ID, $screen->id)); |
|
| 662 | 662 | break; |
| 663 | 663 | } |
| 664 | 664 | } |
@@ -673,31 +673,31 @@ discard block |
||
| 673 | 673 | * |
| 674 | 674 | * @return array $comments |
| 675 | 675 | */ |
| 676 | - public function filter_grading_activity_queries( $comments ){ |
|
| 676 | + public function filter_grading_activity_queries($comments) { |
|
| 677 | 677 | |
| 678 | - if( !is_admin() || ! $this->is_admin_teacher() || is_numeric( $comments ) || ! is_array( $comments ) ){ |
|
| 679 | - return $comments ; |
|
| 678 | + if ( ! is_admin() || ! $this->is_admin_teacher() || is_numeric($comments) || ! is_array($comments)) { |
|
| 679 | + return $comments; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | //check if we're on the grading screen |
| 683 | 683 | $screen = get_current_screen(); |
| 684 | 684 | |
| 685 | - if( empty( $screen ) || 'sensei_page_sensei_grading' != $screen->id ){ |
|
| 685 | + if (empty($screen) || 'sensei_page_sensei_grading' != $screen->id) { |
|
| 686 | 686 | return $comments; |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | // get the course and determine if the current teacher is the owner |
| 690 | 690 | // if not remove it from the list of comments to be returned |
| 691 | - foreach( $comments as $key => $comment){ |
|
| 692 | - $lesson = get_post( $comment->comment_post_ID ); |
|
| 693 | - $course_id = Sensei()->lesson->get_course_id( $lesson->ID ); |
|
| 694 | - $course = get_post( $course_id ); |
|
| 695 | - if( ! isset( $course->post_author ) || intval( $course->post_author) != intval( get_current_user_id() ) ){ |
|
| 691 | + foreach ($comments as $key => $comment) { |
|
| 692 | + $lesson = get_post($comment->comment_post_ID); |
|
| 693 | + $course_id = Sensei()->lesson->get_course_id($lesson->ID); |
|
| 694 | + $course = get_post($course_id); |
|
| 695 | + if ( ! isset($course->post_author) || intval($course->post_author) != intval(get_current_user_id())) { |
|
| 696 | 696 | //remove this as the teacher should see this. |
| 697 | - unset( $comments[ $key ] ); |
|
| 697 | + unset($comments[$key]); |
|
| 698 | 698 | } |
| 699 | 699 | } |
| 700 | - return $comments ; |
|
| 700 | + return $comments; |
|
| 701 | 701 | |
| 702 | 702 | }// end function filter grading |
| 703 | 703 | |
@@ -713,34 +713,34 @@ discard block |
||
| 713 | 713 | * |
| 714 | 714 | * @return array $args |
| 715 | 715 | */ |
| 716 | - public function limit_grading_totals( $args ){ |
|
| 716 | + public function limit_grading_totals($args) { |
|
| 717 | 717 | |
| 718 | - if( !is_admin() || ! $this->is_admin_teacher() || ! is_array( $args ) ){ |
|
| 719 | - return $args ; |
|
| 718 | + if ( ! is_admin() || ! $this->is_admin_teacher() || ! is_array($args)) { |
|
| 719 | + return $args; |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | //get the teachers courses |
| 723 | 723 | // the query is already filtered to only the teacher |
| 724 | - $courses = Sensei()->course->get_all_courses(); |
|
| 724 | + $courses = Sensei()->course->get_all_courses(); |
|
| 725 | 725 | |
| 726 | - if( empty( $courses ) || ! is_array( $courses ) ){ |
|
| 726 | + if (empty($courses) || ! is_array($courses)) { |
|
| 727 | 727 | return $args; |
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | //setup the lessons quizzes to limit the grading totals to |
| 731 | 731 | $quiz_scope = array(); |
| 732 | - foreach( $courses as $course ){ |
|
| 732 | + foreach ($courses as $course) { |
|
| 733 | 733 | |
| 734 | - $course_lessons = Sensei()->course->course_lessons( $course->ID ); |
|
| 734 | + $course_lessons = Sensei()->course->course_lessons($course->ID); |
|
| 735 | 735 | |
| 736 | - if( ! empty( $course_lessons ) && is_array( $course_lessons ) ){ |
|
| 736 | + if ( ! empty($course_lessons) && is_array($course_lessons)) { |
|
| 737 | 737 | |
| 738 | - foreach( $course_lessons as $lesson ){ |
|
| 738 | + foreach ($course_lessons as $lesson) { |
|
| 739 | 739 | |
| 740 | - $quiz_id = Sensei()->lesson->lesson_quizzes( $lesson->ID ); |
|
| 741 | - if( !empty( $quiz_id ) ) { |
|
| 740 | + $quiz_id = Sensei()->lesson->lesson_quizzes($lesson->ID); |
|
| 741 | + if ( ! empty($quiz_id)) { |
|
| 742 | 742 | |
| 743 | - array_push( $quiz_scope, $quiz_id ); |
|
| 743 | + array_push($quiz_scope, $quiz_id); |
|
| 744 | 744 | |
| 745 | 745 | } |
| 746 | 746 | |
@@ -763,41 +763,41 @@ discard block |
||
| 763 | 763 | * @param WP_Query $query |
| 764 | 764 | * @return WP_Query $query |
| 765 | 765 | */ |
| 766 | - public function add_courses_to_author_archive( $query ) { |
|
| 766 | + public function add_courses_to_author_archive($query) { |
|
| 767 | 767 | |
| 768 | - if ( is_admin() || ! $query->is_author() ){ |
|
| 768 | + if (is_admin() || ! $query->is_author()) { |
|
| 769 | 769 | return $query; |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | // this should only apply to users with the teacher role |
| 773 | - $current_page_user = get_user_by('login', $query->get('author_name') ); |
|
| 774 | - if( ! $current_page_user || ! in_array('teacher', $current_page_user->roles ) ) { |
|
| 773 | + $current_page_user = get_user_by('login', $query->get('author_name')); |
|
| 774 | + if ( ! $current_page_user || ! in_array('teacher', $current_page_user->roles)) { |
|
| 775 | 775 | |
| 776 | 776 | return $query; |
| 777 | 777 | |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | 780 | // Change post types depending on what is set already |
| 781 | - $current_post_types = $query->get( 'post_type' ); |
|
| 782 | - if( empty( $current_post_types ) ){ |
|
| 781 | + $current_post_types = $query->get('post_type'); |
|
| 782 | + if (empty($current_post_types)) { |
|
| 783 | 783 | |
| 784 | 784 | // if empty it means post by default, so add post so that it also includes that for now |
| 785 | - $new_post_types = array( 'post', 'course' ); |
|
| 785 | + $new_post_types = array('post', 'course'); |
|
| 786 | 786 | |
| 787 | - } elseif( is_array( $current_post_types ) ) { |
|
| 787 | + } elseif (is_array($current_post_types)) { |
|
| 788 | 788 | |
| 789 | 789 | // merge the post types instead of overwriting it |
| 790 | - $new_post_types = array_merge( $current_post_types, array( 'course' ) ); |
|
| 790 | + $new_post_types = array_merge($current_post_types, array('course')); |
|
| 791 | 791 | |
| 792 | - }else{ |
|
| 792 | + } else { |
|
| 793 | 793 | |
| 794 | 794 | // in this instance it is probably just one post type in string format |
| 795 | - $new_post_types = array( $current_post_types , 'course'); |
|
| 795 | + $new_post_types = array($current_post_types, 'course'); |
|
| 796 | 796 | |
| 797 | 797 | } |
| 798 | 798 | |
| 799 | 799 | // change the query before returning it |
| 800 | - $query->set('post_type', $new_post_types ); |
|
| 800 | + $query->set('post_type', $new_post_types); |
|
| 801 | 801 | |
| 802 | 802 | /** |
| 803 | 803 | * Change the query on the teacher author archive template |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | * @since 1.8.4 |
| 806 | 806 | * @param WP_Query $query |
| 807 | 807 | */ |
| 808 | - return apply_filters( 'sensei_teacher_archive_query', $query ); |
|
| 808 | + return apply_filters('sensei_teacher_archive_query', $query); |
|
| 809 | 809 | |
| 810 | 810 | } |
| 811 | 811 | |
@@ -818,21 +818,21 @@ discard block |
||
| 818 | 818 | * @param $course_id |
| 819 | 819 | * @return bool |
| 820 | 820 | */ |
| 821 | - public function teacher_course_assigned_notification( $teacher_id, $course_id ){ |
|
| 821 | + public function teacher_course_assigned_notification($teacher_id, $course_id) { |
|
| 822 | 822 | |
| 823 | - if( 'course' != get_post_type( $course_id ) || ! get_userdata( $teacher_id ) ){ |
|
| 823 | + if ('course' != get_post_type($course_id) || ! get_userdata($teacher_id)) { |
|
| 824 | 824 | return false; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | // if new user is the same as the current logged user, they don't need an email |
| 828 | - if( $teacher_id == get_current_user_id() ){ |
|
| 828 | + if ($teacher_id == get_current_user_id()) { |
|
| 829 | 829 | return true; |
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | // load the email class |
| 833 | 833 | include('emails/class-woothemes-sensei-teacher-new-course-assignment.php'); |
| 834 | 834 | $email = new Teacher_New_Course_Assignment(); |
| 835 | - $email->trigger( $teacher_id, $course_id ); |
|
| 835 | + $email->trigger($teacher_id, $course_id); |
|
| 836 | 836 | |
| 837 | 837 | return true; |
| 838 | 838 | } // end teacher_course_assigned_notification |
@@ -846,12 +846,12 @@ discard block |
||
| 846 | 846 | * @param int $course_id |
| 847 | 847 | * @return bool |
| 848 | 848 | */ |
| 849 | - public function notify_admin_teacher_course_creation( $new_status, $old_status, $post ){ |
|
| 849 | + public function notify_admin_teacher_course_creation($new_status, $old_status, $post) { |
|
| 850 | 850 | |
| 851 | 851 | $course_id = $post->ID; |
| 852 | 852 | |
| 853 | - if( 'course' != get_post_type( $course_id ) || 'auto-draft' == get_post_status( $course_id ) |
|
| 854 | - || 'trash' == get_post_status( $course_id ) || 'draft' == get_post_status( $course_id ) ) { |
|
| 853 | + if ('course' != get_post_type($course_id) || 'auto-draft' == get_post_status($course_id) |
|
| 854 | + || 'trash' == get_post_status($course_id) || 'draft' == get_post_status($course_id)) { |
|
| 855 | 855 | |
| 856 | 856 | return false; |
| 857 | 857 | |
@@ -865,19 +865,19 @@ discard block |
||
| 865 | 865 | * |
| 866 | 866 | * @param bool $on default true |
| 867 | 867 | */ |
| 868 | - if( ! apply_filters('sensei_notify_admin_new_course_creation', true ) ){ |
|
| 868 | + if ( ! apply_filters('sensei_notify_admin_new_course_creation', true)) { |
|
| 869 | 869 | return false; |
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | // setting up the data needed by the email template |
| 873 | 873 | global $sensei_email_data; |
| 874 | 874 | $template = 'admin-teacher-new-course-created'; |
| 875 | - $course = get_post( $course_id ); |
|
| 876 | - $teacher = new WP_User( $course->post_author ); |
|
| 875 | + $course = get_post($course_id); |
|
| 876 | + $teacher = new WP_User($course->post_author); |
|
| 877 | 877 | $recipient = get_option('admin_email', true); |
| 878 | 878 | |
| 879 | 879 | // don't send if the course is created by admin |
| 880 | - if( $recipient == $teacher->user_email ){ |
|
| 880 | + if ($recipient == $teacher->user_email) { |
|
| 881 | 881 | return; |
| 882 | 882 | } |
| 883 | 883 | |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | * @since 1.8.0 |
| 888 | 888 | * @param string $template |
| 889 | 889 | */ |
| 890 | - $heading = apply_filters( 'sensei_email_heading', __( 'New course created.', 'woothemes-sensei' ), $template ); |
|
| 890 | + $heading = apply_filters('sensei_email_heading', __('New course created.', 'woothemes-sensei'), $template); |
|
| 891 | 891 | |
| 892 | 892 | /** |
| 893 | 893 | * Filter the email subject for the the |
@@ -898,11 +898,11 @@ discard block |
||
| 898 | 898 | * @param string $template |
| 899 | 899 | */ |
| 900 | 900 | $subject = apply_filters('sensei_email_subject', |
| 901 | - '['. get_bloginfo( 'name', 'display' ) .'] '. __( 'New course created by', 'woothemes-sensei' ) . ' ' . $teacher->display_name , |
|
| 902 | - $template ); |
|
| 901 | + '['.get_bloginfo('name', 'display').'] '.__('New course created by', 'woothemes-sensei').' '.$teacher->display_name, |
|
| 902 | + $template); |
|
| 903 | 903 | |
| 904 | 904 | //course edit link |
| 905 | - $course_edit_link = admin_url('post.php?post=' . $course_id . '&action=edit' ); |
|
| 905 | + $course_edit_link = admin_url('post.php?post='.$course_id.'&action=edit'); |
|
| 906 | 906 | |
| 907 | 907 | // Construct data array |
| 908 | 908 | $email_data = array( |
@@ -921,10 +921,10 @@ discard block |
||
| 921 | 921 | * @param array $email_data |
| 922 | 922 | * @param string $template |
| 923 | 923 | */ |
| 924 | - $sensei_email_data = apply_filters( 'sensei_email_data', $email_data , $template ); |
|
| 924 | + $sensei_email_data = apply_filters('sensei_email_data', $email_data, $template); |
|
| 925 | 925 | |
| 926 | 926 | // Send mail |
| 927 | - Sensei()->emails->send( $recipient, $subject , Sensei()->emails->get_content( $template ) ); |
|
| 927 | + Sensei()->emails->send($recipient, $subject, Sensei()->emails->get_content($template)); |
|
| 928 | 928 | |
| 929 | 929 | }// end notify admin of course creation |
| 930 | 930 | |
@@ -935,10 +935,10 @@ discard block |
||
| 935 | 935 | * @param array $args WP_User_Query arguments |
| 936 | 936 | * @return array $learners_query_results |
| 937 | 937 | */ |
| 938 | - public function limit_analysis_learners( $args ){ |
|
| 938 | + public function limit_analysis_learners($args) { |
|
| 939 | 939 | |
| 940 | 940 | // show default for none teachers |
| 941 | - if( ! Sensei()->teacher->is_admin_teacher() ) { |
|
| 941 | + if ( ! Sensei()->teacher->is_admin_teacher()) { |
|
| 942 | 942 | return $args; |
| 943 | 943 | } |
| 944 | 944 | |
@@ -947,31 +947,31 @@ discard block |
||
| 947 | 947 | $teacher_courses = Sensei()->course->get_all_courses(); |
| 948 | 948 | |
| 949 | 949 | // if the user has no courses they should see no users |
| 950 | - if( empty( $teacher_courses ) || ! is_array( $teacher_courses ) ){ |
|
| 950 | + if (empty($teacher_courses) || ! is_array($teacher_courses)) { |
|
| 951 | 951 | // tell the query to return 0 students |
| 952 | - $args[ 'include'] = array( 0 ); |
|
| 952 | + $args['include'] = array(0); |
|
| 953 | 953 | return $args; |
| 954 | 954 | |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | $learner_ids_for_teacher_courses = array(); |
| 958 | - foreach( $teacher_courses as $course ){ |
|
| 958 | + foreach ($teacher_courses as $course) { |
|
| 959 | 959 | |
| 960 | 960 | $course_learner_ids = array(); |
| 961 | - $activity_comments = Sensei_Utils::sensei_check_for_activity( array( 'post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id' ), true ); |
|
| 961 | + $activity_comments = Sensei_Utils::sensei_check_for_activity(array('post_id' => $course->ID, 'type' => 'sensei_course_status', 'field' => 'user_id'), true); |
|
| 962 | 962 | |
| 963 | - if( empty( $activity_comments ) || ( is_array( $activity_comments ) && ! ( count( $activity_comments ) > 0 ) ) ){ |
|
| 963 | + if (empty($activity_comments) || (is_array($activity_comments) && ! (count($activity_comments) > 0))) { |
|
| 964 | 964 | continue; // skip to the next course as there are no users on this course |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | // it could be an array of comments or a single comment |
| 968 | - if( is_array( $activity_comments ) ){ |
|
| 968 | + if (is_array($activity_comments)) { |
|
| 969 | 969 | |
| 970 | - foreach( $activity_comments as $comment ){ |
|
| 970 | + foreach ($activity_comments as $comment) { |
|
| 971 | 971 | |
| 972 | - $user = get_userdata( $comment->user_id ); |
|
| 972 | + $user = get_userdata($comment->user_id); |
|
| 973 | 973 | |
| 974 | - if( empty( $user ) ){ |
|
| 974 | + if (empty($user)) { |
|
| 975 | 975 | // next comment in this array |
| 976 | 976 | continue; |
| 977 | 977 | } |
@@ -979,26 +979,26 @@ discard block |
||
| 979 | 979 | $course_learner_ids[] = $user->ID; |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - }else{ |
|
| 982 | + } else { |
|
| 983 | 983 | |
| 984 | - $user = get_userdata( $activity_comments->user_id ); |
|
| 984 | + $user = get_userdata($activity_comments->user_id); |
|
| 985 | 985 | $course_learner_ids[] = $user->ID; |
| 986 | 986 | |
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | // add learners on this course to the all courses learner list |
| 990 | - $learner_ids_for_teacher_courses = array_merge( $learner_ids_for_teacher_courses, $course_learner_ids ); |
|
| 990 | + $learner_ids_for_teacher_courses = array_merge($learner_ids_for_teacher_courses, $course_learner_ids); |
|
| 991 | 991 | |
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | // if there are no students taking the courses by this teacher don't show them any of the other users |
| 995 | - if( empty( $learner_ids_for_teacher_courses ) ){ |
|
| 995 | + if (empty($learner_ids_for_teacher_courses)) { |
|
| 996 | 996 | |
| 997 | - $args[ 'include'] = array( 0 ); |
|
| 997 | + $args['include'] = array(0); |
|
| 998 | 998 | |
| 999 | - }else{ |
|
| 999 | + } else { |
|
| 1000 | 1000 | |
| 1001 | - $args[ 'include'] = $learner_ids_for_teacher_courses; |
|
| 1001 | + $args['include'] = $learner_ids_for_teacher_courses; |
|
| 1002 | 1002 | |
| 1003 | 1003 | } |
| 1004 | 1004 | |
@@ -1015,35 +1015,35 @@ discard block |
||
| 1015 | 1015 | * @param $questions |
| 1016 | 1016 | * @return mixed |
| 1017 | 1017 | */ |
| 1018 | - public function allow_teacher_access_to_questions( $questions, $quiz_id ){ |
|
| 1018 | + public function allow_teacher_access_to_questions($questions, $quiz_id) { |
|
| 1019 | 1019 | |
| 1020 | - if( ! $this->is_admin_teacher() ){ |
|
| 1020 | + if ( ! $this->is_admin_teacher()) { |
|
| 1021 | 1021 | return $questions; |
| 1022 | 1022 | } |
| 1023 | 1023 | |
| 1024 | 1024 | $screen = get_current_screen(); |
| 1025 | 1025 | |
| 1026 | 1026 | // don't run this filter within this functions call to Sensei()->lesson->lesson_quiz_questions |
| 1027 | - remove_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20 ); |
|
| 1027 | + remove_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20); |
|
| 1028 | 1028 | |
| 1029 | - if( ! empty( $screen ) && 'lesson'== $screen->post_type ){ |
|
| 1029 | + if ( ! empty($screen) && 'lesson' == $screen->post_type) { |
|
| 1030 | 1030 | |
| 1031 | 1031 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
| 1032 | - if( ! empty($admin_user) ){ |
|
| 1032 | + if ( ! empty($admin_user)) { |
|
| 1033 | 1033 | |
| 1034 | 1034 | $current_teacher_id = get_current_user_id(); |
| 1035 | 1035 | |
| 1036 | 1036 | // set current user to admin so teacher can view all questions |
| 1037 | - wp_set_current_user( $admin_user->ID ); |
|
| 1038 | - $questions = Sensei()->lesson->lesson_quiz_questions( $quiz_id ); |
|
| 1037 | + wp_set_current_user($admin_user->ID); |
|
| 1038 | + $questions = Sensei()->lesson->lesson_quiz_questions($quiz_id); |
|
| 1039 | 1039 | |
| 1040 | 1040 | // set the teacher as the current use again |
| 1041 | - wp_set_current_user( $current_teacher_id ); |
|
| 1041 | + wp_set_current_user($current_teacher_id); |
|
| 1042 | 1042 | } |
| 1043 | 1043 | |
| 1044 | 1044 | } |
| 1045 | 1045 | // attach the filter again for other funtion calls to Sensei()->lesson->lesson_quiz_questions |
| 1046 | - add_filter( 'sensei_lesson_quiz_questions', array( $this, 'allow_teacher_access_to_questions' ), 20,2 ); |
|
| 1046 | + add_filter('sensei_lesson_quiz_questions', array($this, 'allow_teacher_access_to_questions'), 20, 2); |
|
| 1047 | 1047 | |
| 1048 | 1048 | return $questions; |
| 1049 | 1049 | } |
@@ -1055,30 +1055,30 @@ discard block |
||
| 1055 | 1055 | * @param $wp_query |
| 1056 | 1056 | * @return mixed |
| 1057 | 1057 | */ |
| 1058 | - public function give_access_to_all_questions( $wp_query ){ |
|
| 1058 | + public function give_access_to_all_questions($wp_query) { |
|
| 1059 | 1059 | |
| 1060 | - if( ! $this->is_admin_teacher() || !function_exists( 'get_current_screen') || 'question' != $wp_query->get('post_type') ){ |
|
| 1060 | + if ( ! $this->is_admin_teacher() || ! function_exists('get_current_screen') || 'question' != $wp_query->get('post_type')) { |
|
| 1061 | 1061 | |
| 1062 | 1062 | return $wp_query; |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | $screen = get_current_screen(); |
| 1066 | - if( ( isset($screen->id) && 'lesson' == $screen->id ) |
|
| 1067 | - || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ){ |
|
| 1066 | + if ((isset($screen->id) && 'lesson' == $screen->id) |
|
| 1067 | + || (defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 1068 | 1068 | |
| 1069 | 1069 | $admin_user = get_user_by('email', get_bloginfo('admin_email')); |
| 1070 | - if( ! empty($admin_user) ){ |
|
| 1070 | + if ( ! empty($admin_user)) { |
|
| 1071 | 1071 | |
| 1072 | 1072 | $current_teacher_id = get_current_user_id(); |
| 1073 | 1073 | |
| 1074 | 1074 | // set current user to admin so teacher can view all questions |
| 1075 | - wp_set_current_user( $admin_user->ID ); |
|
| 1075 | + wp_set_current_user($admin_user->ID); |
|
| 1076 | 1076 | |
| 1077 | 1077 | //run new query as admin |
| 1078 | - $wp_query = new WP_Query( $wp_query->query ); |
|
| 1078 | + $wp_query = new WP_Query($wp_query->query); |
|
| 1079 | 1079 | |
| 1080 | 1080 | //set the teache as current use again |
| 1081 | - wp_set_current_user( $current_teacher_id ); |
|
| 1081 | + wp_set_current_user($current_teacher_id); |
|
| 1082 | 1082 | |
| 1083 | 1083 | } |
| 1084 | 1084 | } |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | */ |
| 1096 | 1096 | public function course_column_heading($columns) { |
| 1097 | 1097 | |
| 1098 | - if( $this->is_admin_teacher() ){ |
|
| 1098 | + if ($this->is_admin_teacher()) { |
|
| 1099 | 1099 | return $columns; |
| 1100 | 1100 | } |
| 1101 | 1101 | $new_columns = array( |
@@ -1112,20 +1112,20 @@ discard block |
||
| 1112 | 1112 | * @param $column |
| 1113 | 1113 | * @param $course_id |
| 1114 | 1114 | */ |
| 1115 | - public function course_column_data( $column, $course_id ){ |
|
| 1115 | + public function course_column_data($column, $course_id) { |
|
| 1116 | 1116 | |
| 1117 | - if( $this->is_admin_teacher() || 'teacher' != $column ){ |
|
| 1117 | + if ($this->is_admin_teacher() || 'teacher' != $column) { |
|
| 1118 | 1118 | return; |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - $course = get_post( $course_id ); |
|
| 1122 | - $teacher = get_userdata( $course->post_author ); |
|
| 1121 | + $course = get_post($course_id); |
|
| 1122 | + $teacher = get_userdata($course->post_author); |
|
| 1123 | 1123 | |
| 1124 | - if( !$teacher ){ |
|
| 1124 | + if ( ! $teacher) { |
|
| 1125 | 1125 | return; |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | - echo '<a href="'. get_edit_user_link( $teacher->ID ) .'" >'. $teacher->display_name.'</a>'; |
|
| 1128 | + echo '<a href="'.get_edit_user_link($teacher->ID).'" >'.$teacher->display_name.'</a>'; |
|
| 1129 | 1129 | |
| 1130 | 1130 | }// end course_column_ data |
| 1131 | 1131 | |
@@ -1140,31 +1140,31 @@ discard block |
||
| 1140 | 1140 | * |
| 1141 | 1141 | * @return array $teachers_courses |
| 1142 | 1142 | */ |
| 1143 | - public function get_teacher_courses( $teacher_id, $return_ids_only= false){ |
|
| 1143 | + public function get_teacher_courses($teacher_id, $return_ids_only = false) { |
|
| 1144 | 1144 | |
| 1145 | 1145 | $teachers_courses = array(); |
| 1146 | 1146 | |
| 1147 | - if( empty( $teacher_id ) ){ |
|
| 1147 | + if (empty($teacher_id)) { |
|
| 1148 | 1148 | $teacher_id = get_current_user_id(); |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | $all_courses = Sensei()->course->get_all_courses(); |
| 1152 | 1152 | |
| 1153 | - if( empty( $all_courses ) ){ |
|
| 1153 | + if (empty($all_courses)) { |
|
| 1154 | 1154 | return $all_courses; |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - foreach( $all_courses as $course ){ |
|
| 1157 | + foreach ($all_courses as $course) { |
|
| 1158 | 1158 | |
| 1159 | - if( $course->post_author != $teacher_id ){ |
|
| 1159 | + if ($course->post_author != $teacher_id) { |
|
| 1160 | 1160 | continue; |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | - if( $return_ids_only ){ |
|
| 1163 | + if ($return_ids_only) { |
|
| 1164 | 1164 | |
| 1165 | 1165 | $teachers_courses[] = $course->ID; |
| 1166 | 1166 | |
| 1167 | - }else{ |
|
| 1167 | + } else { |
|
| 1168 | 1168 | |
| 1169 | 1169 | $teachers_courses[] = $course; |
| 1170 | 1170 | |
@@ -1184,21 +1184,21 @@ discard block |
||
| 1184 | 1184 | * @param $query |
| 1185 | 1185 | * @return mixed |
| 1186 | 1186 | */ |
| 1187 | - public function limit_edit_messages_query( $query ){ |
|
| 1188 | - if( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type') ){ |
|
| 1187 | + public function limit_edit_messages_query($query) { |
|
| 1188 | + if ( ! $this->is_admin_teacher() || 'sensei_message' != $query->get('post_type')) { |
|
| 1189 | 1189 | return $query; |
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | $teacher = wp_get_current_user(); |
| 1193 | 1193 | |
| 1194 | - $query->set( 'meta_key', '_receiver' ); |
|
| 1194 | + $query->set('meta_key', '_receiver'); |
|
| 1195 | 1195 | $meta_query_args = array( |
| 1196 | 1196 | 'key' => '_receiver', |
| 1197 | - 'value' => $teacher->get('user_login') , |
|
| 1197 | + 'value' => $teacher->get('user_login'), |
|
| 1198 | 1198 | 'compare' => '=' |
| 1199 | 1199 | ); |
| 1200 | 1200 | |
| 1201 | - $query->set('meta_query', $meta_query_args ); |
|
| 1201 | + $query->set('meta_query', $meta_query_args); |
|
| 1202 | 1202 | |
| 1203 | 1203 | return $query; |
| 1204 | 1204 | } |
@@ -1214,7 +1214,7 @@ discard block |
||
| 1214 | 1214 | public function course_teacher_filter_options() { |
| 1215 | 1215 | global $typenow; |
| 1216 | 1216 | |
| 1217 | - if( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1217 | + if ( ! is_admin() || 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
| 1218 | 1218 | return; |
| 1219 | 1219 | } |
| 1220 | 1220 | |
@@ -1224,31 +1224,31 @@ discard block |
||
| 1224 | 1224 | // get roles with the course edit capability |
| 1225 | 1225 | // and then get the users with those roles |
| 1226 | 1226 | $users_who_can_edit_courses = array(); |
| 1227 | - foreach( $roles as $role_item ){ |
|
| 1227 | + foreach ($roles as $role_item) { |
|
| 1228 | 1228 | |
| 1229 | - $role = get_role( strtolower( $role_item['name'] ) ); |
|
| 1229 | + $role = get_role(strtolower($role_item['name'])); |
|
| 1230 | 1230 | |
| 1231 | - if( is_a( $role, 'WP_Role' ) && $role->has_cap('edit_courses') ){ |
|
| 1231 | + if (is_a($role, 'WP_Role') && $role->has_cap('edit_courses')) { |
|
| 1232 | 1232 | |
| 1233 | - $user_query_args = array( 'role' => $role->name, 'fields' => array( 'ID', 'display_name' ) ); |
|
| 1234 | - $role_users_who_can_edit_courses = get_users( $user_query_args ); |
|
| 1233 | + $user_query_args = array('role' => $role->name, 'fields' => array('ID', 'display_name')); |
|
| 1234 | + $role_users_who_can_edit_courses = get_users($user_query_args); |
|
| 1235 | 1235 | |
| 1236 | 1236 | // add user from the current $user_role to all users |
| 1237 | - $users_who_can_edit_courses = array_merge( $users_who_can_edit_courses, $role_users_who_can_edit_courses ); |
|
| 1237 | + $users_who_can_edit_courses = array_merge($users_who_can_edit_courses, $role_users_who_can_edit_courses); |
|
| 1238 | 1238 | |
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | // Create the select element with the given users who can edit course |
| 1244 | - $selected = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1244 | + $selected = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
| 1245 | 1245 | $course_options = ''; |
| 1246 | - foreach( $users_who_can_edit_courses as $user ) { |
|
| 1247 | - $course_options .= '<option value="' . esc_attr( $user->ID ) . '" ' . selected( $selected, $user->ID, false ) . '>' . $user->display_name . '</option>'; |
|
| 1246 | + foreach ($users_who_can_edit_courses as $user) { |
|
| 1247 | + $course_options .= '<option value="'.esc_attr($user->ID).'" '.selected($selected, $user->ID, false).'>'.$user->display_name.'</option>'; |
|
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | $output = '<select name="course_teacher" id="dropdown_course_teachers">'; |
| 1251 | - $output .= '<option value="">'.__( 'Show all teachers', 'woothemes-sensei' ).'</option>'; |
|
| 1251 | + $output .= '<option value="">'.__('Show all teachers', 'woothemes-sensei').'</option>'; |
|
| 1252 | 1252 | $output .= $course_options; |
| 1253 | 1253 | $output .= '</select>'; |
| 1254 | 1254 | |
@@ -1263,15 +1263,15 @@ discard block |
||
| 1263 | 1263 | * @param $query |
| 1264 | 1264 | * @return $query |
| 1265 | 1265 | */ |
| 1266 | - public function teacher_filter_query_modify( $query ){ |
|
| 1266 | + public function teacher_filter_query_modify($query) { |
|
| 1267 | 1267 | global $typenow; |
| 1268 | 1268 | |
| 1269 | - if( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei') ) { |
|
| 1269 | + if ( ! is_admin() && 'course' != $typenow || ! current_user_can('manage_sensei')) { |
|
| 1270 | 1270 | return $query; |
| 1271 | 1271 | } |
| 1272 | - $course_teacher = isset( $_GET['course_teacher'] ) ? $_GET['course_teacher'] : ''; |
|
| 1272 | + $course_teacher = isset($_GET['course_teacher']) ? $_GET['course_teacher'] : ''; |
|
| 1273 | 1273 | |
| 1274 | - if( empty( $course_teacher ) ) { |
|
| 1274 | + if (empty($course_teacher)) { |
|
| 1275 | 1275 | return $query; |
| 1276 | 1276 | } |
| 1277 | 1277 | |
@@ -1284,23 +1284,23 @@ discard block |
||
| 1284 | 1284 | * @param array $request Default request arguments |
| 1285 | 1285 | * @return array Modified request arguments |
| 1286 | 1286 | */ |
| 1287 | - public function restrict_media_library( $request = array() ) { |
|
| 1287 | + public function restrict_media_library($request = array()) { |
|
| 1288 | 1288 | |
| 1289 | - if( ! is_admin() ) { |
|
| 1289 | + if ( ! is_admin()) { |
|
| 1290 | 1290 | return $request; |
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | - if( ! $this->is_admin_teacher() ) { |
|
| 1293 | + if ( ! $this->is_admin_teacher()) { |
|
| 1294 | 1294 | return $request; |
| 1295 | 1295 | } |
| 1296 | 1296 | |
| 1297 | 1297 | $screen = get_current_screen(); |
| 1298 | 1298 | |
| 1299 | - if( in_array( $screen->id, array( 'upload', 'course', 'lesson', 'question' ) ) ) { |
|
| 1300 | - $teacher = intval( get_current_user_id() ); |
|
| 1299 | + if (in_array($screen->id, array('upload', 'course', 'lesson', 'question'))) { |
|
| 1300 | + $teacher = intval(get_current_user_id()); |
|
| 1301 | 1301 | |
| 1302 | - if( $teacher ) { |
|
| 1303 | - $request['author__in'] = array( $teacher ); |
|
| 1302 | + if ($teacher) { |
|
| 1303 | + $request['author__in'] = array($teacher); |
|
| 1304 | 1304 | } |
| 1305 | 1305 | } |
| 1306 | 1306 | |
@@ -1312,20 +1312,20 @@ discard block |
||
| 1312 | 1312 | * @param array $query Default query arguments |
| 1313 | 1313 | * @return array Modified query arguments |
| 1314 | 1314 | */ |
| 1315 | - public function restrict_media_library_modal( $query = array() ) { |
|
| 1315 | + public function restrict_media_library_modal($query = array()) { |
|
| 1316 | 1316 | |
| 1317 | - if( ! is_admin() ) { |
|
| 1317 | + if ( ! is_admin()) { |
|
| 1318 | 1318 | return $query; |
| 1319 | 1319 | } |
| 1320 | 1320 | |
| 1321 | - if( ! $this->is_admin_teacher() ) { |
|
| 1321 | + if ( ! $this->is_admin_teacher()) { |
|
| 1322 | 1322 | return $query; |
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | - $teacher = intval( get_current_user_id() ); |
|
| 1325 | + $teacher = intval(get_current_user_id()); |
|
| 1326 | 1326 | |
| 1327 | - if( $teacher ) { |
|
| 1328 | - $query['author__in'] = array( $teacher ); |
|
| 1327 | + if ($teacher) { |
|
| 1328 | + $query['author__in'] = array($teacher); |
|
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | 1331 | return $query; |
@@ -1338,28 +1338,28 @@ discard block |
||
| 1338 | 1338 | * |
| 1339 | 1339 | * @param int $lesson_id |
| 1340 | 1340 | */ |
| 1341 | - public function update_lesson_teacher( $lesson_id ){ |
|
| 1341 | + public function update_lesson_teacher($lesson_id) { |
|
| 1342 | 1342 | |
| 1343 | - if( 'lesson'!= get_post_type() ){ |
|
| 1343 | + if ('lesson' != get_post_type()) { |
|
| 1344 | 1344 | return; |
| 1345 | 1345 | } |
| 1346 | 1346 | |
| 1347 | 1347 | // this should only run once per request cycle |
| 1348 | - remove_action( 'save_post', array( $this, 'update_lesson_teacher' ) ); |
|
| 1348 | + remove_action('save_post', array($this, 'update_lesson_teacher')); |
|
| 1349 | 1349 | |
| 1350 | - $course_id = Sensei()->lesson->get_course_id( $lesson_id ); |
|
| 1350 | + $course_id = Sensei()->lesson->get_course_id($lesson_id); |
|
| 1351 | 1351 | |
| 1352 | - if( empty( $course_id ) || ! $course_id ){ |
|
| 1352 | + if (empty($course_id) || ! $course_id) { |
|
| 1353 | 1353 | return; |
| 1354 | 1354 | } |
| 1355 | 1355 | |
| 1356 | - $course = get_post( $course_id ); |
|
| 1356 | + $course = get_post($course_id); |
|
| 1357 | 1357 | |
| 1358 | - $lesson_update_args= array( |
|
| 1359 | - 'ID' => $lesson_id , |
|
| 1358 | + $lesson_update_args = array( |
|
| 1359 | + 'ID' => $lesson_id, |
|
| 1360 | 1360 | 'post_author' => $course->post_author |
| 1361 | 1361 | ); |
| 1362 | - wp_update_post( $lesson_update_args ); |
|
| 1362 | + wp_update_post($lesson_update_args); |
|
| 1363 | 1363 | |
| 1364 | 1364 | } // end update_lesson_teacher |
| 1365 | 1365 | |
@@ -1373,21 +1373,21 @@ discard block |
||
| 1373 | 1373 | * @parameters array $wp_query |
| 1374 | 1374 | * @return WP_Query $wp_query |
| 1375 | 1375 | */ |
| 1376 | - public function limit_teacher_edit_screen_post_types( $wp_query ) { |
|
| 1376 | + public function limit_teacher_edit_screen_post_types($wp_query) { |
|
| 1377 | 1377 | global $current_user; |
| 1378 | 1378 | |
| 1379 | 1379 | //exit early |
| 1380 | - if( ! $this->is_admin_teacher() ){ |
|
| 1380 | + if ( ! $this->is_admin_teacher()) { |
|
| 1381 | 1381 | return $wp_query; |
| 1382 | 1382 | } |
| 1383 | 1383 | |
| 1384 | - if ( ! function_exists( 'get_current_screen' ) ) { |
|
| 1384 | + if ( ! function_exists('get_current_screen')) { |
|
| 1385 | 1385 | return $wp_query; |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | 1388 | $screen = get_current_screen(); |
| 1389 | 1389 | |
| 1390 | - if( empty( $screen ) ){ |
|
| 1390 | + if (empty($screen)) { |
|
| 1391 | 1391 | return $wp_query; |
| 1392 | 1392 | } |
| 1393 | 1393 | |
@@ -1400,10 +1400,10 @@ discard block |
||
| 1400 | 1400 | 'lesson_page_lesson-order', |
| 1401 | 1401 | ); |
| 1402 | 1402 | |
| 1403 | - if( in_array($screen->id , $limit_screens ) ) { |
|
| 1403 | + if (in_array($screen->id, $limit_screens)) { |
|
| 1404 | 1404 | |
| 1405 | 1405 | // set the query author to the current user to only show those those posts |
| 1406 | - $wp_query->set( 'author', $current_user->ID ); |
|
| 1406 | + $wp_query->set('author', $current_user->ID); |
|
| 1407 | 1407 | } |
| 1408 | 1408 | |
| 1409 | 1409 | return $wp_query; |
@@ -1423,7 +1423,7 @@ discard block |
||
| 1423 | 1423 | * @return void |
| 1424 | 1424 | */ |
| 1425 | 1425 | |
| 1426 | - public function teacher_login_redirect( $user_login, $user ) { |
|
| 1426 | + public function teacher_login_redirect($user_login, $user) { |
|
| 1427 | 1427 | |
| 1428 | 1428 | if (user_can($user, 'edit_courses')) { |
| 1429 | 1429 | |
@@ -1473,9 +1473,9 @@ discard block |
||
| 1473 | 1473 | * @param bool $restrict default true |
| 1474 | 1474 | */ |
| 1475 | 1475 | |
| 1476 | - $restrict = apply_filters('sensei_restrict_posts_menu_page', true ); |
|
| 1476 | + $restrict = apply_filters('sensei_restrict_posts_menu_page', true); |
|
| 1477 | 1477 | |
| 1478 | - if ( in_array( 'teacher', (array) $user->roles ) && !current_user_can('delete_posts') && $restrict) { |
|
| 1478 | + if (in_array('teacher', (array) $user->roles) && ! current_user_can('delete_posts') && $restrict) { |
|
| 1479 | 1479 | |
| 1480 | 1480 | remove_menu_page('edit.php'); |
| 1481 | 1481 | |
@@ -1509,7 +1509,7 @@ discard block |
||
| 1509 | 1509 | |
| 1510 | 1510 | global $pagenow; |
| 1511 | 1511 | |
| 1512 | - if( self::is_a_teacher( get_current_user_id() ) && $pagenow == "edit-comments.php") { |
|
| 1512 | + if (self::is_a_teacher(get_current_user_id()) && $pagenow == "edit-comments.php") { |
|
| 1513 | 1513 | |
| 1514 | 1514 | $clauses->query_vars['post_author'] = get_current_user_id(); |
| 1515 | 1515 | |
@@ -1526,15 +1526,15 @@ discard block |
||
| 1526 | 1526 | * |
| 1527 | 1527 | * @return bool |
| 1528 | 1528 | */ |
| 1529 | - public static function is_a_teacher( $user_id ){ |
|
| 1529 | + public static function is_a_teacher($user_id) { |
|
| 1530 | 1530 | |
| 1531 | 1531 | $user = get_user_by('id', $user_id); |
| 1532 | 1532 | |
| 1533 | - if( isset( $user->roles ) && in_array( 'teacher', $user->roles ) ){ |
|
| 1533 | + if (isset($user->roles) && in_array('teacher', $user->roles)) { |
|
| 1534 | 1534 | |
| 1535 | 1535 | return true; |
| 1536 | 1536 | |
| 1537 | - }else{ |
|
| 1537 | + } else { |
|
| 1538 | 1538 | |
| 1539 | 1539 | return false; |
| 1540 | 1540 | |
@@ -1547,14 +1547,14 @@ discard block |
||
| 1547 | 1547 | * |
| 1548 | 1548 | * @since 1.9.0 |
| 1549 | 1549 | */ |
| 1550 | - public static function archive_title(){ |
|
| 1550 | + public static function archive_title() { |
|
| 1551 | 1551 | |
| 1552 | - $author = get_user_by( 'id', get_query_var( 'author' ) ); |
|
| 1552 | + $author = get_user_by('id', get_query_var('author')); |
|
| 1553 | 1553 | $author_name = $author->display_name; |
| 1554 | 1554 | ?> |
| 1555 | 1555 | <h2 class="teacher-archive-title"> |
| 1556 | 1556 | |
| 1557 | - <?php echo sprintf( __( 'All courses by %s', 'woothemes-sensei') , $author_name ); ?> |
|
| 1557 | + <?php echo sprintf(__('All courses by %s', 'woothemes-sensei'), $author_name); ?> |
|
| 1558 | 1558 | |
| 1559 | 1559 | </h2> |
| 1560 | 1560 | <?php |
@@ -1566,9 +1566,9 @@ discard block |
||
| 1566 | 1566 | * |
| 1567 | 1567 | * @since 1.9.0 |
| 1568 | 1568 | */ |
| 1569 | - public static function remove_course_meta_on_teacher_archive(){ |
|
| 1569 | + public static function remove_course_meta_on_teacher_archive() { |
|
| 1570 | 1570 | |
| 1571 | - remove_action('sensei_course_content_inside_before', array( Sensei()->course, 'the_course_meta' ) ); |
|
| 1571 | + remove_action('sensei_course_content_inside_before', array(Sensei()->course, 'the_course_meta')); |
|
| 1572 | 1572 | |
| 1573 | 1573 | } |
| 1574 | 1574 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | $grade = __( 'N/A', 'woothemes-sensei' ); |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - $title = Sensei_Student::get_full_name( $item->user_id ); |
|
| 256 | + $title = Sensei_Student::get_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,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_Student::get_full_name( $item->user_id ); |
|
| 256 | + $title = Sensei_Student::get_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 {} |
|
@@ -13,124 +13,124 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Sensei_Autoloader { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var path to the includes directory within Sensei. |
|
| 18 | - */ |
|
| 19 | - private $include_path = 'includes'; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var array $class_file_map. List of classes mapped to their files |
|
| 23 | - */ |
|
| 24 | - private $class_file_map = array(); |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Constructor |
|
| 28 | - * @since 1.9.0 |
|
| 29 | - */ |
|
| 30 | - public function __construct(){ |
|
| 31 | - |
|
| 32 | - // make sure we do not override an existing autoload function |
|
| 33 | - if( function_exists('__autoload') ){ |
|
| 34 | - spl_autoload_register( '__autoload' ); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // setup a relative path for the current autoload instance |
|
| 38 | - $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) ); |
|
| 39 | - |
|
| 40 | - //setup the class file map |
|
| 41 | - $this->initialize_class_file_map(); |
|
| 42 | - |
|
| 43 | - // add Sensei custom auto loader |
|
| 44 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 45 | - |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Generate a list of Sensei class and map them the their respective |
|
| 50 | - * files within the includes directory |
|
| 51 | - * |
|
| 52 | - * @since 1.9.0 |
|
| 53 | - */ |
|
| 54 | - public function initialize_class_file_map(){ |
|
| 55 | - |
|
| 56 | - $this->class_file_map = array( |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Main Sensei class |
|
| 60 | - */ |
|
| 61 | - 'Sensei_Main' => 'class-sensei.php', |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Admin |
|
| 65 | - */ |
|
| 66 | - 'Sensei_Welcome' => 'admin/class-sensei-welcome.php' , |
|
| 67 | - 'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' , |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Shortcodes |
|
| 71 | - */ |
|
| 72 | - 'Sensei_Shortcode_Loader' => 'shortcodes/class-sensei-shortcode-loader.php', |
|
| 73 | - 'Sensei_Shortcode_Interface' => 'shortcodes/interface-sensei-shortcode.php', |
|
| 74 | - 'Sensei_Shortcode_Featured_Courses' => 'shortcodes/class-sensei-shortcode-featured-courses.php', |
|
| 75 | - 'Sensei_Shortcode_User_Courses' => 'shortcodes/class-sensei-shortcode-user-courses.php', |
|
| 76 | - 'Sensei_Shortcode_Courses' => 'shortcodes/class-sensei-shortcode-courses.php', |
|
| 77 | - 'Sensei_Shortcode_Teachers' => 'shortcodes/class-sensei-shortcode-teachers.php', |
|
| 78 | - 'Sensei_Shortcode_User_Messages' => 'shortcodes/class-sensei-shortcode-user-messages.php', |
|
| 79 | - 'Sensei_Shortcode_Course_Page' => 'shortcodes/class-sensei-shortcode-course-page.php', |
|
| 80 | - 'Sensei_Shortcode_Lesson_Page' => 'shortcodes/class-sensei-shortcode-lesson-page.php', |
|
| 81 | - 'Sensei_Shortcode_Course_Categories' => 'shortcodes/class-sensei-shortcode-course-categories.php', |
|
| 82 | - 'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php', |
|
| 83 | - 'Sensei_Legacy_Shortcodes' => 'shortcodes/class-sensei-legacy-shortcodes.php', |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * WooCommerce |
|
| 87 | - */ |
|
| 88 | - 'Sensei_WC' => 'class-sensei-wc.php', |
|
| 89 | - |
|
| 90 | - ); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Autoload all sensei files as the class names are used. |
|
| 95 | - */ |
|
| 96 | - public function autoload( $class ){ |
|
| 97 | - |
|
| 98 | - // only handle classes with the word `sensei` in it |
|
| 99 | - if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){ |
|
| 100 | - |
|
| 101 | - return; |
|
| 102 | - |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // exit if we didn't provide mapping for this class |
|
| 106 | - if( isset( $this->class_file_map[ $class ] ) ){ |
|
| 107 | - |
|
| 108 | - $file_location = $this->include_path . $this->class_file_map[ $class ]; |
|
| 109 | - require_once( $file_location); |
|
| 110 | - return; |
|
| 111 | - |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // check for file in the main includes directory |
|
| 115 | - $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php'; |
|
| 116 | - if( file_exists( $class_file_path ) ){ |
|
| 117 | - |
|
| 118 | - require_once( $class_file_path ); |
|
| 119 | - return; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // lastly check legacy types |
|
| 123 | - $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes |
|
| 124 | - $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php'; |
|
| 125 | - if( file_exists( $legacy_class_file_path ) ){ |
|
| 126 | - |
|
| 127 | - require_once( $legacy_class_file_path ); |
|
| 128 | - return; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return; |
|
| 132 | - |
|
| 133 | - }// end autoload |
|
| 16 | + /** |
|
| 17 | + * @var path to the includes directory within Sensei. |
|
| 18 | + */ |
|
| 19 | + private $include_path = 'includes'; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var array $class_file_map. List of classes mapped to their files |
|
| 23 | + */ |
|
| 24 | + private $class_file_map = array(); |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Constructor |
|
| 28 | + * @since 1.9.0 |
|
| 29 | + */ |
|
| 30 | + public function __construct(){ |
|
| 31 | + |
|
| 32 | + // make sure we do not override an existing autoload function |
|
| 33 | + if( function_exists('__autoload') ){ |
|
| 34 | + spl_autoload_register( '__autoload' ); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // setup a relative path for the current autoload instance |
|
| 38 | + $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) ); |
|
| 39 | + |
|
| 40 | + //setup the class file map |
|
| 41 | + $this->initialize_class_file_map(); |
|
| 42 | + |
|
| 43 | + // add Sensei custom auto loader |
|
| 44 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Generate a list of Sensei class and map them the their respective |
|
| 50 | + * files within the includes directory |
|
| 51 | + * |
|
| 52 | + * @since 1.9.0 |
|
| 53 | + */ |
|
| 54 | + public function initialize_class_file_map(){ |
|
| 55 | + |
|
| 56 | + $this->class_file_map = array( |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Main Sensei class |
|
| 60 | + */ |
|
| 61 | + 'Sensei_Main' => 'class-sensei.php', |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Admin |
|
| 65 | + */ |
|
| 66 | + 'Sensei_Welcome' => 'admin/class-sensei-welcome.php' , |
|
| 67 | + 'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' , |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Shortcodes |
|
| 71 | + */ |
|
| 72 | + 'Sensei_Shortcode_Loader' => 'shortcodes/class-sensei-shortcode-loader.php', |
|
| 73 | + 'Sensei_Shortcode_Interface' => 'shortcodes/interface-sensei-shortcode.php', |
|
| 74 | + 'Sensei_Shortcode_Featured_Courses' => 'shortcodes/class-sensei-shortcode-featured-courses.php', |
|
| 75 | + 'Sensei_Shortcode_User_Courses' => 'shortcodes/class-sensei-shortcode-user-courses.php', |
|
| 76 | + 'Sensei_Shortcode_Courses' => 'shortcodes/class-sensei-shortcode-courses.php', |
|
| 77 | + 'Sensei_Shortcode_Teachers' => 'shortcodes/class-sensei-shortcode-teachers.php', |
|
| 78 | + 'Sensei_Shortcode_User_Messages' => 'shortcodes/class-sensei-shortcode-user-messages.php', |
|
| 79 | + 'Sensei_Shortcode_Course_Page' => 'shortcodes/class-sensei-shortcode-course-page.php', |
|
| 80 | + 'Sensei_Shortcode_Lesson_Page' => 'shortcodes/class-sensei-shortcode-lesson-page.php', |
|
| 81 | + 'Sensei_Shortcode_Course_Categories' => 'shortcodes/class-sensei-shortcode-course-categories.php', |
|
| 82 | + 'Sensei_Shortcode_Unpurchased_Courses' => 'shortcodes/class-sensei-shortcode-unpurchased-courses.php', |
|
| 83 | + 'Sensei_Legacy_Shortcodes' => 'shortcodes/class-sensei-legacy-shortcodes.php', |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * WooCommerce |
|
| 87 | + */ |
|
| 88 | + 'Sensei_WC' => 'class-sensei-wc.php', |
|
| 89 | + |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Autoload all sensei files as the class names are used. |
|
| 95 | + */ |
|
| 96 | + public function autoload( $class ){ |
|
| 97 | + |
|
| 98 | + // only handle classes with the word `sensei` in it |
|
| 99 | + if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){ |
|
| 100 | + |
|
| 101 | + return; |
|
| 102 | + |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // exit if we didn't provide mapping for this class |
|
| 106 | + if( isset( $this->class_file_map[ $class ] ) ){ |
|
| 107 | + |
|
| 108 | + $file_location = $this->include_path . $this->class_file_map[ $class ]; |
|
| 109 | + require_once( $file_location); |
|
| 110 | + return; |
|
| 111 | + |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // check for file in the main includes directory |
|
| 115 | + $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php'; |
|
| 116 | + if( file_exists( $class_file_path ) ){ |
|
| 117 | + |
|
| 118 | + require_once( $class_file_path ); |
|
| 119 | + return; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // lastly check legacy types |
|
| 123 | + $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes |
|
| 124 | + $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php'; |
|
| 125 | + if( file_exists( $legacy_class_file_path ) ){ |
|
| 126 | + |
|
| 127 | + require_once( $legacy_class_file_path ); |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return; |
|
| 132 | + |
|
| 133 | + }// end autoload |
|
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | new Sensei_Autoloader(); |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // security check, don't load file outside WP |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // security check, don't load file outside WP |
|
| 3 | 3 | /** |
| 4 | 4 | * Sensei Autoloader Class |
| 5 | 5 | * |
@@ -27,21 +27,21 @@ discard block |
||
| 27 | 27 | * Constructor |
| 28 | 28 | * @since 1.9.0 |
| 29 | 29 | */ |
| 30 | - public function __construct(){ |
|
| 30 | + public function __construct() { |
|
| 31 | 31 | |
| 32 | 32 | // make sure we do not override an existing autoload function |
| 33 | - if( function_exists('__autoload') ){ |
|
| 34 | - spl_autoload_register( '__autoload' ); |
|
| 33 | + if (function_exists('__autoload')) { |
|
| 34 | + spl_autoload_register('__autoload'); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // setup a relative path for the current autoload instance |
| 38 | - $this->include_path = trailingslashit( untrailingslashit( dirname( __FILE__ ) ) ); |
|
| 38 | + $this->include_path = trailingslashit(untrailingslashit(dirname(__FILE__))); |
|
| 39 | 39 | |
| 40 | 40 | //setup the class file map |
| 41 | 41 | $this->initialize_class_file_map(); |
| 42 | 42 | |
| 43 | 43 | // add Sensei custom auto loader |
| 44 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 44 | + spl_autoload_register(array($this, 'autoload')); |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * |
| 52 | 52 | * @since 1.9.0 |
| 53 | 53 | */ |
| 54 | - public function initialize_class_file_map(){ |
|
| 54 | + public function initialize_class_file_map() { |
|
| 55 | 55 | |
| 56 | 56 | $this->class_file_map = array( |
| 57 | 57 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | /** |
| 64 | 64 | * Admin |
| 65 | 65 | */ |
| 66 | - 'Sensei_Welcome' => 'admin/class-sensei-welcome.php' , |
|
| 67 | - 'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php' , |
|
| 66 | + 'Sensei_Welcome' => 'admin/class-sensei-welcome.php', |
|
| 67 | + 'Sensei_Learner_Management' => 'admin/class-sensei-learner-management.php', |
|
| 68 | 68 | |
| 69 | 69 | /** |
| 70 | 70 | * Shortcodes |
@@ -93,38 +93,38 @@ discard block |
||
| 93 | 93 | /** |
| 94 | 94 | * Autoload all sensei files as the class names are used. |
| 95 | 95 | */ |
| 96 | - public function autoload( $class ){ |
|
| 96 | + public function autoload($class) { |
|
| 97 | 97 | |
| 98 | 98 | // only handle classes with the word `sensei` in it |
| 99 | - if( ! is_numeric( strpos ( strtolower( $class ), 'sensei') ) ){ |
|
| 99 | + if ( ! is_numeric(strpos(strtolower($class), 'sensei'))) { |
|
| 100 | 100 | |
| 101 | 101 | return; |
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | // exit if we didn't provide mapping for this class |
| 106 | - if( isset( $this->class_file_map[ $class ] ) ){ |
|
| 106 | + if (isset($this->class_file_map[$class])) { |
|
| 107 | 107 | |
| 108 | - $file_location = $this->include_path . $this->class_file_map[ $class ]; |
|
| 109 | - require_once( $file_location); |
|
| 108 | + $file_location = $this->include_path.$this->class_file_map[$class]; |
|
| 109 | + require_once($file_location); |
|
| 110 | 110 | return; |
| 111 | 111 | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | // check for file in the main includes directory |
| 115 | - $class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $class ) ) . '.php'; |
|
| 116 | - if( file_exists( $class_file_path ) ){ |
|
| 115 | + $class_file_path = $this->include_path.'class-'.str_replace('_', '-', strtolower($class)).'.php'; |
|
| 116 | + if (file_exists($class_file_path)) { |
|
| 117 | 117 | |
| 118 | - require_once( $class_file_path ); |
|
| 118 | + require_once($class_file_path); |
|
| 119 | 119 | return; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | // lastly check legacy types |
| 123 | - $stripped_woothemes_from_class = str_replace( 'woothemes_','', strtolower( $class ) ); // remove woothemes |
|
| 124 | - $legacy_class_file_path = $this->include_path . 'class-'.str_replace( '_','-', strtolower( $stripped_woothemes_from_class ) ) . '.php'; |
|
| 125 | - if( file_exists( $legacy_class_file_path ) ){ |
|
| 123 | + $stripped_woothemes_from_class = str_replace('woothemes_', '', strtolower($class)); // remove woothemes |
|
| 124 | + $legacy_class_file_path = $this->include_path.'class-'.str_replace('_', '-', strtolower($stripped_woothemes_from_class)).'.php'; |
|
| 125 | + if (file_exists($legacy_class_file_path)) { |
|
| 126 | 126 | |
| 127 | - require_once( $legacy_class_file_path ); |
|
| 127 | + require_once($legacy_class_file_path); |
|
| 128 | 128 | return; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -17,25 +17,25 @@ discard block |
||
| 17 | 17 | public $slider_labels; |
| 18 | 18 | public $role_caps; |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var Sensei_Course |
|
| 22 | - */ |
|
| 23 | - public $course; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var Sensei_Lesson |
|
| 27 | - */ |
|
| 28 | - public $lesson; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var Sensei_Question |
|
| 32 | - */ |
|
| 33 | - public $question; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var Sensei_Quiz |
|
| 37 | - */ |
|
| 38 | - public $quiz; |
|
| 20 | + /** |
|
| 21 | + * @var Sensei_Course |
|
| 22 | + */ |
|
| 23 | + public $course; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var Sensei_Lesson |
|
| 27 | + */ |
|
| 28 | + public $lesson; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var Sensei_Question |
|
| 32 | + */ |
|
| 33 | + public $question; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var Sensei_Quiz |
|
| 37 | + */ |
|
| 38 | + public $quiz; |
|
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | 41 | * Constructor |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | // Setup Post Types |
| 47 | 47 | $this->labels = array(); |
| 48 | - $this->token = 'woothemes-sensei-posttypes'; |
|
| 48 | + $this->token = 'woothemes-sensei-posttypes'; |
|
| 49 | 49 | |
| 50 | 50 | $this->setup_post_type_labels_base(); |
| 51 | 51 | add_action( 'init', array( $this, 'setup_course_post_type' ), 100 ); |
@@ -104,94 +104,94 @@ discard block |
||
| 104 | 104 | /** |
| 105 | 105 | * Setup the "course" post type, it's admin menu item and the appropriate labels and permissions. |
| 106 | 106 | * @since 1.0.0 |
| 107 | - * @uses Sensei() |
|
| 107 | + * @uses Sensei() |
|
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | 110 | public function setup_course_post_type () { |
| 111 | 111 | |
| 112 | 112 | $args = array( |
| 113 | - 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
| 114 | - 'public' => true, |
|
| 115 | - 'publicly_queryable' => true, |
|
| 116 | - 'show_ui' => true, |
|
| 117 | - 'show_in_menu' => true, |
|
| 118 | - 'show_in_admin_bar' => true, |
|
| 119 | - 'query_var' => true, |
|
| 120 | - 'rewrite' => array( |
|
| 121 | - 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
| 122 | - 'with_front' => true, |
|
| 123 | - 'feeds' => true, |
|
| 124 | - 'pages' => true |
|
| 125 | - ), |
|
| 126 | - 'map_meta_cap' => true, |
|
| 127 | - 'capability_type' => 'course', |
|
| 128 | - 'has_archive' => $this->get_course_post_type_archive_slug(), |
|
| 129 | - 'hierarchical' => false, |
|
| 130 | - 'menu_position' => 51, |
|
| 131 | - 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
| 113 | + 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
| 114 | + 'public' => true, |
|
| 115 | + 'publicly_queryable' => true, |
|
| 116 | + 'show_ui' => true, |
|
| 117 | + 'show_in_menu' => true, |
|
| 118 | + 'show_in_admin_bar' => true, |
|
| 119 | + 'query_var' => true, |
|
| 120 | + 'rewrite' => array( |
|
| 121 | + 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
| 122 | + 'with_front' => true, |
|
| 123 | + 'feeds' => true, |
|
| 124 | + 'pages' => true |
|
| 125 | + ), |
|
| 126 | + 'map_meta_cap' => true, |
|
| 127 | + 'capability_type' => 'course', |
|
| 128 | + 'has_archive' => $this->get_course_post_type_archive_slug(), |
|
| 129 | + 'hierarchical' => false, |
|
| 130 | + 'menu_position' => 51, |
|
| 131 | + 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
| 132 | 132 | ); |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Filter the arguments passed in when registering the Sensei Course post type. |
|
| 136 | - * |
|
| 137 | - * @since 1.9.0 |
|
| 138 | - * @param array $args |
|
| 139 | - */ |
|
| 134 | + /** |
|
| 135 | + * Filter the arguments passed in when registering the Sensei Course post type. |
|
| 136 | + * |
|
| 137 | + * @since 1.9.0 |
|
| 138 | + * @param array $args |
|
| 139 | + */ |
|
| 140 | 140 | register_post_type( 'course', apply_filters( 'sensei_register_post_type_course', $args ) ); |
| 141 | 141 | |
| 142 | 142 | } // End setup_course_post_type() |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Figure out of the course post type has an archive and what it should be. |
|
| 146 | - * |
|
| 147 | - * This function should return 'courses' or the page_uri for the course page setting. |
|
| 148 | - * |
|
| 149 | - * For backward compatibility sake ( pre 1.9 )If the course page set in settings |
|
| 150 | - * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the |
|
| 151 | - * page slug will not be returned. For any other pages without it the page URI will be returned. |
|
| 152 | - * |
|
| 153 | - * |
|
| 154 | - * @sine 1.9.0 |
|
| 155 | - * |
|
| 156 | - * |
|
| 157 | - * @return false|string |
|
| 158 | - */ |
|
| 159 | - public function get_course_post_type_archive_slug(){ |
|
| 144 | + /** |
|
| 145 | + * Figure out of the course post type has an archive and what it should be. |
|
| 146 | + * |
|
| 147 | + * This function should return 'courses' or the page_uri for the course page setting. |
|
| 148 | + * |
|
| 149 | + * For backward compatibility sake ( pre 1.9 )If the course page set in settings |
|
| 150 | + * still has any of the old shortcodes: [newcourses][featuredcourses][freecourses][paidcourses] the |
|
| 151 | + * page slug will not be returned. For any other pages without it the page URI will be returned. |
|
| 152 | + * |
|
| 153 | + * |
|
| 154 | + * @sine 1.9.0 |
|
| 155 | + * |
|
| 156 | + * |
|
| 157 | + * @return false|string |
|
| 158 | + */ |
|
| 159 | + public function get_course_post_type_archive_slug(){ |
|
| 160 | 160 | |
| 161 | - $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
| 161 | + $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
| 162 | 162 | |
| 163 | - // for a valid post that doesn't have any of the old short codes set the archive the same |
|
| 164 | - // as the page URI |
|
| 165 | - if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
| 163 | + // for a valid post that doesn't have any of the old short codes set the archive the same |
|
| 164 | + // as the page URI |
|
| 165 | + if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
| 166 | 166 | |
| 167 | - return get_page_uri( $settings_course_page->ID ); |
|
| 167 | + return get_page_uri( $settings_course_page->ID ); |
|
| 168 | 168 | |
| 169 | - }else{ |
|
| 169 | + }else{ |
|
| 170 | 170 | |
| 171 | - return 'courses'; |
|
| 171 | + return 'courses'; |
|
| 172 | 172 | |
| 173 | - } |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - }// end course_post_type_determine_archive |
|
| 175 | + }// end course_post_type_determine_archive |
|
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Check if given content has any of these old shortcodes: |
|
| 179 | - * [newcourses][featuredcourses][freecourses][paidcourses] |
|
| 180 | - * |
|
| 181 | - * @since 1.9.0 |
|
| 182 | - * |
|
| 183 | - * @param string $content |
|
| 184 | - * |
|
| 185 | - * @return bool |
|
| 186 | - */ |
|
| 187 | - public function has_old_shortcodes( $content ){ |
|
| 177 | + /** |
|
| 178 | + * Check if given content has any of these old shortcodes: |
|
| 179 | + * [newcourses][featuredcourses][freecourses][paidcourses] |
|
| 180 | + * |
|
| 181 | + * @since 1.9.0 |
|
| 182 | + * |
|
| 183 | + * @param string $content |
|
| 184 | + * |
|
| 185 | + * @return bool |
|
| 186 | + */ |
|
| 187 | + public function has_old_shortcodes( $content ){ |
|
| 188 | 188 | |
| 189 | - return ( has_shortcode( $content, 'newcourses') |
|
| 190 | - || has_shortcode( $content, 'featuredcourses') |
|
| 191 | - || has_shortcode( $content, 'freecourses') |
|
| 192 | - || has_shortcode( $content, 'paidcourses') ); |
|
| 189 | + return ( has_shortcode( $content, 'newcourses') |
|
| 190 | + || has_shortcode( $content, 'featuredcourses') |
|
| 191 | + || has_shortcode( $content, 'freecourses') |
|
| 192 | + || has_shortcode( $content, 'paidcourses') ); |
|
| 193 | 193 | |
| 194 | - }// end has old shortcodes |
|
| 194 | + }// end has old shortcodes |
|
| 195 | 195 | |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -213,32 +213,32 @@ discard block |
||
| 213 | 213 | } // End If Statement |
| 214 | 214 | |
| 215 | 215 | $args = array( |
| 216 | - 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
| 217 | - 'public' => true, |
|
| 218 | - 'publicly_queryable' => true, |
|
| 219 | - 'show_ui' => true, |
|
| 220 | - 'show_in_menu' => true, |
|
| 221 | - 'query_var' => true, |
|
| 222 | - 'rewrite' => array( |
|
| 223 | - 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 224 | - 'with_front' => true, |
|
| 225 | - 'feeds' => true, |
|
| 226 | - 'pages' => true |
|
| 227 | - ), |
|
| 228 | - 'map_meta_cap' => true, |
|
| 229 | - 'capability_type' => 'lesson', |
|
| 230 | - 'has_archive' => true, |
|
| 231 | - 'hierarchical' => false, |
|
| 232 | - 'menu_position' => 52, |
|
| 233 | - 'supports' => $supports_array |
|
| 216 | + 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
| 217 | + 'public' => true, |
|
| 218 | + 'publicly_queryable' => true, |
|
| 219 | + 'show_ui' => true, |
|
| 220 | + 'show_in_menu' => true, |
|
| 221 | + 'query_var' => true, |
|
| 222 | + 'rewrite' => array( |
|
| 223 | + 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 224 | + 'with_front' => true, |
|
| 225 | + 'feeds' => true, |
|
| 226 | + 'pages' => true |
|
| 227 | + ), |
|
| 228 | + 'map_meta_cap' => true, |
|
| 229 | + 'capability_type' => 'lesson', |
|
| 230 | + 'has_archive' => true, |
|
| 231 | + 'hierarchical' => false, |
|
| 232 | + 'menu_position' => 52, |
|
| 233 | + 'supports' => $supports_array |
|
| 234 | 234 | ); |
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Filter the arguments passed in when registering the Sensei Lesson post type. |
|
| 238 | - * |
|
| 239 | - * @since 1.9.0 |
|
| 240 | - * @param array $args |
|
| 241 | - */ |
|
| 236 | + /** |
|
| 237 | + * Filter the arguments passed in when registering the Sensei Lesson post type. |
|
| 238 | + * |
|
| 239 | + * @since 1.9.0 |
|
| 240 | + * @param array $args |
|
| 241 | + */ |
|
| 242 | 242 | register_post_type( 'lesson', apply_filters( 'sensei_register_post_type_lesson', $args ) ); |
| 243 | 243 | |
| 244 | 244 | } // End setup_lesson_post_type() |
@@ -246,45 +246,45 @@ discard block |
||
| 246 | 246 | /** |
| 247 | 247 | * Setup the "quiz" post type, it's admin menu item and the appropriate labels and permissions. |
| 248 | 248 | * @since 1.0.0 |
| 249 | - * @uses Sensei() |
|
| 249 | + * @uses Sensei() |
|
| 250 | 250 | * @return void |
| 251 | 251 | */ |
| 252 | 252 | public function setup_quiz_post_type () { |
| 253 | 253 | |
| 254 | 254 | |
| 255 | 255 | $args = array( |
| 256 | - 'labels' => $this->create_post_type_labels( |
|
| 257 | - $this->labels['quiz']['singular'], |
|
| 258 | - $this->labels['quiz']['plural'], |
|
| 259 | - $this->labels['quiz']['menu'] |
|
| 260 | - ), |
|
| 261 | - 'public' => true, |
|
| 262 | - 'publicly_queryable' => true, |
|
| 263 | - 'show_ui' => true, |
|
| 264 | - 'show_in_menu' => false, |
|
| 265 | - 'show_in_nav_menus' => false, |
|
| 266 | - 'query_var' => true, |
|
| 267 | - 'exclude_from_search' => true, |
|
| 268 | - 'rewrite' => array( |
|
| 269 | - 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 270 | - 'with_front' => true, |
|
| 271 | - 'feeds' => true, |
|
| 272 | - 'pages' => true |
|
| 273 | - ), |
|
| 274 | - 'map_meta_cap' => true, |
|
| 275 | - 'capability_type' => 'quiz', |
|
| 276 | - 'has_archive' => false, |
|
| 277 | - 'hierarchical' => false, |
|
| 278 | - 'menu_position' => 20, // Below "Pages" |
|
| 279 | - 'supports' => array( '' ) |
|
| 256 | + 'labels' => $this->create_post_type_labels( |
|
| 257 | + $this->labels['quiz']['singular'], |
|
| 258 | + $this->labels['quiz']['plural'], |
|
| 259 | + $this->labels['quiz']['menu'] |
|
| 260 | + ), |
|
| 261 | + 'public' => true, |
|
| 262 | + 'publicly_queryable' => true, |
|
| 263 | + 'show_ui' => true, |
|
| 264 | + 'show_in_menu' => false, |
|
| 265 | + 'show_in_nav_menus' => false, |
|
| 266 | + 'query_var' => true, |
|
| 267 | + 'exclude_from_search' => true, |
|
| 268 | + 'rewrite' => array( |
|
| 269 | + 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 270 | + 'with_front' => true, |
|
| 271 | + 'feeds' => true, |
|
| 272 | + 'pages' => true |
|
| 273 | + ), |
|
| 274 | + 'map_meta_cap' => true, |
|
| 275 | + 'capability_type' => 'quiz', |
|
| 276 | + 'has_archive' => false, |
|
| 277 | + 'hierarchical' => false, |
|
| 278 | + 'menu_position' => 20, // Below "Pages" |
|
| 279 | + 'supports' => array( '' ) |
|
| 280 | 280 | ); |
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Filter the arguments passed in when registering the Sensei Quiz post type. |
|
| 284 | - * |
|
| 285 | - * @since 1.9.0 |
|
| 286 | - * @param array $args |
|
| 287 | - */ |
|
| 282 | + /** |
|
| 283 | + * Filter the arguments passed in when registering the Sensei Quiz post type. |
|
| 284 | + * |
|
| 285 | + * @since 1.9.0 |
|
| 286 | + * @param array $args |
|
| 287 | + */ |
|
| 288 | 288 | register_post_type( 'quiz', apply_filters( 'sensei_register_post_type_quiz', $args ) ); |
| 289 | 289 | |
| 290 | 290 | } // End setup_quiz_post_type() |
@@ -298,34 +298,34 @@ discard block |
||
| 298 | 298 | public function setup_question_post_type () { |
| 299 | 299 | |
| 300 | 300 | $args = array( |
| 301 | - 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
| 302 | - 'public' => false, |
|
| 303 | - 'publicly_queryable' => true, |
|
| 304 | - 'show_ui' => true, |
|
| 305 | - 'show_in_menu' => true, |
|
| 306 | - 'show_in_nav_menus' => false, |
|
| 307 | - 'query_var' => true, |
|
| 308 | - 'exclude_from_search' => true, |
|
| 309 | - 'rewrite' => array( |
|
| 310 | - 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 311 | - 'with_front' => true, |
|
| 312 | - 'feeds' => true, |
|
| 313 | - 'pages' => true |
|
| 314 | - ), |
|
| 315 | - 'map_meta_cap' => true, |
|
| 316 | - 'capability_type' => 'question', |
|
| 317 | - 'has_archive' => true, |
|
| 318 | - 'hierarchical' => false, |
|
| 319 | - 'menu_position' => 51, |
|
| 320 | - 'supports' => array( 'title' ) |
|
| 301 | + 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
| 302 | + 'public' => false, |
|
| 303 | + 'publicly_queryable' => true, |
|
| 304 | + 'show_ui' => true, |
|
| 305 | + 'show_in_menu' => true, |
|
| 306 | + 'show_in_nav_menus' => false, |
|
| 307 | + 'query_var' => true, |
|
| 308 | + 'exclude_from_search' => true, |
|
| 309 | + 'rewrite' => array( |
|
| 310 | + 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 311 | + 'with_front' => true, |
|
| 312 | + 'feeds' => true, |
|
| 313 | + 'pages' => true |
|
| 314 | + ), |
|
| 315 | + 'map_meta_cap' => true, |
|
| 316 | + 'capability_type' => 'question', |
|
| 317 | + 'has_archive' => true, |
|
| 318 | + 'hierarchical' => false, |
|
| 319 | + 'menu_position' => 51, |
|
| 320 | + 'supports' => array( 'title' ) |
|
| 321 | 321 | ); |
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * Filter the arguments passed in when registering the Sensei Question post type. |
|
| 325 | - * |
|
| 326 | - * @since 1.9.0 |
|
| 327 | - * @param array $args |
|
| 328 | - */ |
|
| 323 | + /** |
|
| 324 | + * Filter the arguments passed in when registering the Sensei Question post type. |
|
| 325 | + * |
|
| 326 | + * @since 1.9.0 |
|
| 327 | + * @param array $args |
|
| 328 | + */ |
|
| 329 | 329 | register_post_type( 'question', apply_filters('sensei_register_post_type_question', $args ) ); |
| 330 | 330 | |
| 331 | 331 | } // End setup_question_post_type() |
@@ -338,26 +338,26 @@ discard block |
||
| 338 | 338 | public function setup_multiple_question_post_type () { |
| 339 | 339 | |
| 340 | 340 | $args = array( |
| 341 | - 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
| 342 | - 'public' => false, |
|
| 343 | - 'publicly_queryable' => false, |
|
| 344 | - 'show_ui' => false, |
|
| 345 | - 'show_in_menu' => false, |
|
| 346 | - 'show_in_nav_menus' => false, |
|
| 347 | - 'query_var' => false, |
|
| 348 | - 'exclude_from_search' => true, |
|
| 349 | - 'rewrite' => array( |
|
| 350 | - 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 351 | - 'with_front' => false, |
|
| 352 | - 'feeds' => false, |
|
| 353 | - 'pages' => false |
|
| 354 | - ), |
|
| 355 | - 'map_meta_cap' => true, |
|
| 356 | - 'capability_type' => 'question', |
|
| 357 | - 'has_archive' => false, |
|
| 358 | - 'hierarchical' => false, |
|
| 359 | - 'menu_position' => 51, |
|
| 360 | - 'supports' => array( 'title', 'custom-fields' ) |
|
| 341 | + 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
| 342 | + 'public' => false, |
|
| 343 | + 'publicly_queryable' => false, |
|
| 344 | + 'show_ui' => false, |
|
| 345 | + 'show_in_menu' => false, |
|
| 346 | + 'show_in_nav_menus' => false, |
|
| 347 | + 'query_var' => false, |
|
| 348 | + 'exclude_from_search' => true, |
|
| 349 | + 'rewrite' => array( |
|
| 350 | + 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 351 | + 'with_front' => false, |
|
| 352 | + 'feeds' => false, |
|
| 353 | + 'pages' => false |
|
| 354 | + ), |
|
| 355 | + 'map_meta_cap' => true, |
|
| 356 | + 'capability_type' => 'question', |
|
| 357 | + 'has_archive' => false, |
|
| 358 | + 'hierarchical' => false, |
|
| 359 | + 'menu_position' => 51, |
|
| 360 | + 'supports' => array( 'title', 'custom-fields' ) |
|
| 361 | 361 | ); |
| 362 | 362 | |
| 363 | 363 | register_post_type( 'multiple_question', $args ); |
@@ -374,34 +374,34 @@ discard block |
||
| 374 | 374 | if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
| 375 | 375 | |
| 376 | 376 | $args = array( |
| 377 | - 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
| 378 | - 'public' => true, |
|
| 379 | - 'publicly_queryable' => true, |
|
| 380 | - 'show_ui' => true, |
|
| 381 | - 'show_in_menu' => 'sensei', |
|
| 382 | - 'show_in_nav_menus' => true, |
|
| 383 | - 'query_var' => true, |
|
| 384 | - 'exclude_from_search' => true, |
|
| 385 | - 'rewrite' => array( |
|
| 386 | - 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 387 | - 'with_front' => false, |
|
| 388 | - 'feeds' => false, |
|
| 389 | - 'pages' => true |
|
| 390 | - ), |
|
| 391 | - 'map_meta_cap' => true, |
|
| 392 | - 'capability_type' => 'question', |
|
| 393 | - 'has_archive' => true, |
|
| 394 | - 'hierarchical' => false, |
|
| 395 | - 'menu_position' => 50, |
|
| 396 | - 'supports' => array( 'title', 'editor', 'comments' ), |
|
| 377 | + 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
| 378 | + 'public' => true, |
|
| 379 | + 'publicly_queryable' => true, |
|
| 380 | + 'show_ui' => true, |
|
| 381 | + 'show_in_menu' => 'sensei', |
|
| 382 | + 'show_in_nav_menus' => true, |
|
| 383 | + 'query_var' => true, |
|
| 384 | + 'exclude_from_search' => true, |
|
| 385 | + 'rewrite' => array( |
|
| 386 | + 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 387 | + 'with_front' => false, |
|
| 388 | + 'feeds' => false, |
|
| 389 | + 'pages' => true |
|
| 390 | + ), |
|
| 391 | + 'map_meta_cap' => true, |
|
| 392 | + 'capability_type' => 'question', |
|
| 393 | + 'has_archive' => true, |
|
| 394 | + 'hierarchical' => false, |
|
| 395 | + 'menu_position' => 50, |
|
| 396 | + 'supports' => array( 'title', 'editor', 'comments' ), |
|
| 397 | 397 | ); |
| 398 | 398 | |
| 399 | - /** |
|
| 400 | - * Filter the arguments passed in when registering the Sensei sensei_message post type. |
|
| 401 | - * |
|
| 402 | - * @since 1.9.0 |
|
| 403 | - * @param array $args |
|
| 404 | - */ |
|
| 399 | + /** |
|
| 400 | + * Filter the arguments passed in when registering the Sensei sensei_message post type. |
|
| 401 | + * |
|
| 402 | + * @since 1.9.0 |
|
| 403 | + * @param array $args |
|
| 404 | + */ |
|
| 405 | 405 | register_post_type( 'sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args ) ); |
| 406 | 406 | } |
| 407 | 407 | } // End setup_sensei_message_post_type() |
@@ -434,11 +434,11 @@ discard block |
||
| 434 | 434 | 'show_ui' => true, |
| 435 | 435 | 'query_var' => true, |
| 436 | 436 | 'show_in_nav_menus' => true, |
| 437 | - 'capabilities' => array( |
|
| 438 | - 'manage_terms' => 'manage_categories', |
|
| 439 | - 'edit_terms' => 'edit_courses', |
|
| 440 | - 'delete_terms' => 'manage_categories', |
|
| 441 | - 'assign_terms' => 'edit_courses',), |
|
| 437 | + 'capabilities' => array( |
|
| 438 | + 'manage_terms' => 'manage_categories', |
|
| 439 | + 'edit_terms' => 'edit_courses', |
|
| 440 | + 'delete_terms' => 'manage_categories', |
|
| 441 | + 'assign_terms' => 'edit_courses',), |
|
| 442 | 442 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_course_category_slug', _x( 'course-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
| 443 | 443 | ); |
| 444 | 444 | |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | 'show_ui' => true, /* TO DO - future releases */ |
| 475 | 475 | 'query_var' => true, |
| 476 | 476 | 'show_in_nav_menus' => false, |
| 477 | - 'public' => false, |
|
| 477 | + 'public' => false, |
|
| 478 | 478 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_quiz_type_slug', _x( 'quiz-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
| 479 | 479 | ); |
| 480 | 480 | |
@@ -546,11 +546,11 @@ discard block |
||
| 546 | 546 | 'query_var' => false, |
| 547 | 547 | 'show_in_nav_menus' => false, |
| 548 | 548 | 'show_admin_column' => true, |
| 549 | - 'capabilities' => array( |
|
| 550 | - 'manage_terms' => 'manage_categories', |
|
| 551 | - 'edit_terms' => 'edit_questions', |
|
| 552 | - 'delete_terms' => 'manage_categories', |
|
| 553 | - 'assign_terms' => 'edit_questions',), |
|
| 549 | + 'capabilities' => array( |
|
| 550 | + 'manage_terms' => 'manage_categories', |
|
| 551 | + 'edit_terms' => 'edit_questions', |
|
| 552 | + 'delete_terms' => 'manage_categories', |
|
| 553 | + 'assign_terms' => 'edit_questions',), |
|
| 554 | 554 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_category_slug', _x( 'question-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
| 555 | 555 | ); |
| 556 | 556 | |
@@ -584,11 +584,11 @@ discard block |
||
| 584 | 584 | 'show_ui' => true, |
| 585 | 585 | 'query_var' => true, |
| 586 | 586 | 'show_in_nav_menus' => true, |
| 587 | - 'capabilities' => array( |
|
| 588 | - 'manage_terms' => 'manage_categories', |
|
| 589 | - 'edit_terms' => 'edit_lessons', |
|
| 590 | - 'delete_terms' => 'manage_categories', |
|
| 591 | - 'assign_terms' => 'edit_lessons',), |
|
| 587 | + 'capabilities' => array( |
|
| 588 | + 'manage_terms' => 'manage_categories', |
|
| 589 | + 'edit_terms' => 'edit_lessons', |
|
| 590 | + 'delete_terms' => 'manage_categories', |
|
| 591 | + 'assign_terms' => 'edit_lessons',), |
|
| 592 | 592 | 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_lesson_tag_slug', _x( 'lesson-tag', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
| 593 | 593 | ); |
| 594 | 594 | |
@@ -622,19 +622,19 @@ discard block |
||
| 622 | 622 | */ |
| 623 | 623 | private function create_post_type_labels ( $singular, $plural, $menu ) { |
| 624 | 624 | $labels = array( |
| 625 | - 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
| 626 | - 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
| 627 | - 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
| 628 | - 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
| 629 | - 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
| 630 | - 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
| 631 | - 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
| 632 | - 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
| 633 | - 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
| 634 | - 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
| 635 | - 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
| 636 | - 'parent_item_colon' => '', |
|
| 637 | - 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
| 625 | + 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
| 626 | + 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
| 627 | + 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
| 628 | + 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
| 629 | + 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
| 630 | + 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
| 631 | + 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
| 632 | + 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
| 633 | + 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
| 634 | + 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
| 635 | + 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
| 636 | + 'parent_item_colon' => '', |
|
| 637 | + 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
| 638 | 638 | ); |
| 639 | 639 | |
| 640 | 640 | return $labels; |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | * Assigns the defaults for each user role capabilities. |
| 708 | 708 | * |
| 709 | 709 | * @since 1.1.0 |
| 710 | - * |
|
| 710 | + * |
|
| 711 | 711 | * @param array $post_types |
| 712 | 712 | * @return void |
| 713 | 713 | */ |
@@ -775,7 +775,7 @@ discard block |
||
| 775 | 775 | * Adds a 'Edit Quiz' link to the admin bar when viewing a Quiz linked to a corresponding Lesson |
| 776 | 776 | * |
| 777 | 777 | * @since 1.7.0 |
| 778 | - * @param WP_Admin_Bar $bar |
|
| 778 | + * @param WP_Admin_Bar $bar |
|
| 779 | 779 | * @return void |
| 780 | 780 | */ |
| 781 | 781 | public function quiz_admin_bar_menu( $bar ) { |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
|
| 2 | +if ( ! defined('ABSPATH')) exit; // Exit if accessed directly |
|
| 3 | 3 | |
| 4 | 4 | /** |
| 5 | 5 | * Sensei Post Types Class |
@@ -41,43 +41,43 @@ discard block |
||
| 41 | 41 | * Constructor |
| 42 | 42 | * @since 1.0.0 |
| 43 | 43 | */ |
| 44 | - public function __construct () { |
|
| 44 | + public function __construct() { |
|
| 45 | 45 | |
| 46 | 46 | // Setup Post Types |
| 47 | 47 | $this->labels = array(); |
| 48 | 48 | $this->token = 'woothemes-sensei-posttypes'; |
| 49 | 49 | |
| 50 | 50 | $this->setup_post_type_labels_base(); |
| 51 | - add_action( 'init', array( $this, 'setup_course_post_type' ), 100 ); |
|
| 52 | - add_action( 'init', array( $this, 'setup_lesson_post_type' ), 100 ); |
|
| 53 | - add_action( 'init', array( $this, 'setup_quiz_post_type' ), 100 ); |
|
| 54 | - add_action( 'init', array( $this, 'setup_question_post_type' ), 100 ); |
|
| 55 | - add_action( 'init', array( $this, 'setup_multiple_question_post_type' ), 100 ); |
|
| 56 | - add_action( 'init', array( $this, 'setup_sensei_message_post_type' ), 100 ); |
|
| 51 | + add_action('init', array($this, 'setup_course_post_type'), 100); |
|
| 52 | + add_action('init', array($this, 'setup_lesson_post_type'), 100); |
|
| 53 | + add_action('init', array($this, 'setup_quiz_post_type'), 100); |
|
| 54 | + add_action('init', array($this, 'setup_question_post_type'), 100); |
|
| 55 | + add_action('init', array($this, 'setup_multiple_question_post_type'), 100); |
|
| 56 | + add_action('init', array($this, 'setup_sensei_message_post_type'), 100); |
|
| 57 | 57 | |
| 58 | 58 | // Setup Taxonomies |
| 59 | - add_action( 'init', array( $this, 'setup_course_category_taxonomy' ), 100 ); |
|
| 60 | - add_action( 'init', array( $this, 'setup_quiz_type_taxonomy' ), 100 ); |
|
| 61 | - add_action( 'init', array( $this, 'setup_question_type_taxonomy' ), 100 ); |
|
| 62 | - add_action( 'init', array( $this, 'setup_question_category_taxonomy' ), 100 ); |
|
| 63 | - add_action( 'init', array( $this, 'setup_lesson_tag_taxonomy' ), 100 ); |
|
| 59 | + add_action('init', array($this, 'setup_course_category_taxonomy'), 100); |
|
| 60 | + add_action('init', array($this, 'setup_quiz_type_taxonomy'), 100); |
|
| 61 | + add_action('init', array($this, 'setup_question_type_taxonomy'), 100); |
|
| 62 | + add_action('init', array($this, 'setup_question_category_taxonomy'), 100); |
|
| 63 | + add_action('init', array($this, 'setup_lesson_tag_taxonomy'), 100); |
|
| 64 | 64 | |
| 65 | 65 | // Load Post Type Objects |
| 66 | - $default_post_types = array( 'course' => 'Course', 'lesson' => 'Lesson', 'quiz' => 'Quiz', 'question' => 'Question', 'messages' => 'Messages' ) ; |
|
| 67 | - $this->load_posttype_objects( $default_post_types ); |
|
| 66 | + $default_post_types = array('course' => 'Course', 'lesson' => 'Lesson', 'quiz' => 'Quiz', 'question' => 'Question', 'messages' => 'Messages'); |
|
| 67 | + $this->load_posttype_objects($default_post_types); |
|
| 68 | 68 | |
| 69 | 69 | // Admin functions |
| 70 | - if ( is_admin() ) { |
|
| 71 | - $this->set_role_cap_defaults( $default_post_types ); |
|
| 70 | + if (is_admin()) { |
|
| 71 | + $this->set_role_cap_defaults($default_post_types); |
|
| 72 | 72 | global $pagenow; |
| 73 | - if ( ( $pagenow == 'post.php' || $pagenow == 'post-new.php' ) ) { |
|
| 74 | - add_filter( 'enter_title_here', array( $this, 'enter_title_here' ), 10 ); |
|
| 75 | - add_filter( 'post_updated_messages', array( $this, 'setup_post_type_messages' ) ); |
|
| 73 | + if (($pagenow == 'post.php' || $pagenow == 'post-new.php')) { |
|
| 74 | + add_filter('enter_title_here', array($this, 'enter_title_here'), 10); |
|
| 75 | + add_filter('post_updated_messages', array($this, 'setup_post_type_messages')); |
|
| 76 | 76 | } // End If Statement |
| 77 | 77 | } // End If Statement |
| 78 | 78 | |
| 79 | 79 | // Add 'Edit Quiz' link to admin bar |
| 80 | - add_action( 'admin_bar_menu', array( $this, 'quiz_admin_bar_menu' ), 81 ); |
|
| 80 | + add_action('admin_bar_menu', array($this, 'quiz_admin_bar_menu'), 81); |
|
| 81 | 81 | |
| 82 | 82 | } // End __construct() |
| 83 | 83 | |
@@ -88,12 +88,12 @@ discard block |
||
| 88 | 88 | * @param array $posttypes (default: array()) |
| 89 | 89 | * @return void |
| 90 | 90 | */ |
| 91 | - public function load_posttype_objects( $posttypes = array() ) { |
|
| 91 | + public function load_posttype_objects($posttypes = array()) { |
|
| 92 | 92 | |
| 93 | - foreach ( $posttypes as $posttype_token => $posttype_name ) { |
|
| 93 | + foreach ($posttypes as $posttype_token => $posttype_name) { |
|
| 94 | 94 | |
| 95 | 95 | // Load the files |
| 96 | - $class_name = 'WooThemes_Sensei_' . $posttype_name; |
|
| 96 | + $class_name = 'WooThemes_Sensei_'.$posttype_name; |
|
| 97 | 97 | $this->$posttype_token = new $class_name(); |
| 98 | 98 | $this->$posttype_token->token = $posttype_token; |
| 99 | 99 | |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | * @uses Sensei() |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - public function setup_course_post_type () { |
|
| 110 | + public function setup_course_post_type() { |
|
| 111 | 111 | |
| 112 | 112 | $args = array( |
| 113 | - 'labels' => $this->create_post_type_labels( $this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu'] ), |
|
| 113 | + 'labels' => $this->create_post_type_labels($this->labels['course']['singular'], $this->labels['course']['plural'], $this->labels['course']['menu']), |
|
| 114 | 114 | 'public' => true, |
| 115 | 115 | 'publicly_queryable' => true, |
| 116 | 116 | 'show_ui' => true, |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | 'show_in_admin_bar' => true, |
| 119 | 119 | 'query_var' => true, |
| 120 | 120 | 'rewrite' => array( |
| 121 | - 'slug' => esc_attr( apply_filters( 'sensei_course_slug', _x( 'course', 'post type single url base', 'woothemes-sensei' ) ) ) , |
|
| 121 | + 'slug' => esc_attr(apply_filters('sensei_course_slug', _x('course', 'post type single url base', 'woothemes-sensei'))), |
|
| 122 | 122 | 'with_front' => true, |
| 123 | 123 | 'feeds' => true, |
| 124 | 124 | 'pages' => true |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | 'has_archive' => $this->get_course_post_type_archive_slug(), |
| 129 | 129 | 'hierarchical' => false, |
| 130 | 130 | 'menu_position' => 51, |
| 131 | - 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ) |
|
| 131 | + 'supports' => array('title', 'editor', 'excerpt', 'thumbnail') |
|
| 132 | 132 | ); |
| 133 | 133 | |
| 134 | 134 | /** |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @since 1.9.0 |
| 138 | 138 | * @param array $args |
| 139 | 139 | */ |
| 140 | - register_post_type( 'course', apply_filters( 'sensei_register_post_type_course', $args ) ); |
|
| 140 | + register_post_type('course', apply_filters('sensei_register_post_type_course', $args)); |
|
| 141 | 141 | |
| 142 | 142 | } // End setup_course_post_type() |
| 143 | 143 | |
@@ -156,17 +156,17 @@ discard block |
||
| 156 | 156 | * |
| 157 | 157 | * @return false|string |
| 158 | 158 | */ |
| 159 | - public function get_course_post_type_archive_slug(){ |
|
| 159 | + public function get_course_post_type_archive_slug() { |
|
| 160 | 160 | |
| 161 | - $settings_course_page = get_post( Sensei()->settings->get( 'course_page' ) ); |
|
| 161 | + $settings_course_page = get_post(Sensei()->settings->get('course_page')); |
|
| 162 | 162 | |
| 163 | 163 | // for a valid post that doesn't have any of the old short codes set the archive the same |
| 164 | 164 | // as the page URI |
| 165 | - if( is_a( $settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes( $settings_course_page->post_content ) ){ |
|
| 165 | + if (is_a($settings_course_page, 'WP_Post') && ! $this->has_old_shortcodes($settings_course_page->post_content)) { |
|
| 166 | 166 | |
| 167 | - return get_page_uri( $settings_course_page->ID ); |
|
| 167 | + return get_page_uri($settings_course_page->ID); |
|
| 168 | 168 | |
| 169 | - }else{ |
|
| 169 | + } else { |
|
| 170 | 170 | |
| 171 | 171 | return 'courses'; |
| 172 | 172 | |
@@ -184,12 +184,12 @@ discard block |
||
| 184 | 184 | * |
| 185 | 185 | * @return bool |
| 186 | 186 | */ |
| 187 | - public function has_old_shortcodes( $content ){ |
|
| 187 | + public function has_old_shortcodes($content) { |
|
| 188 | 188 | |
| 189 | - return ( has_shortcode( $content, 'newcourses') |
|
| 190 | - || has_shortcode( $content, 'featuredcourses') |
|
| 191 | - || has_shortcode( $content, 'freecourses') |
|
| 192 | - || has_shortcode( $content, 'paidcourses') ); |
|
| 189 | + return (has_shortcode($content, 'newcourses') |
|
| 190 | + || has_shortcode($content, 'featuredcourses') |
|
| 191 | + || has_shortcode($content, 'freecourses') |
|
| 192 | + || has_shortcode($content, 'paidcourses')); |
|
| 193 | 193 | |
| 194 | 194 | }// end has old shortcodes |
| 195 | 195 | |
@@ -200,27 +200,27 @@ discard block |
||
| 200 | 200 | * @uses Sensei() |
| 201 | 201 | * @return void |
| 202 | 202 | */ |
| 203 | - public function setup_lesson_post_type () { |
|
| 203 | + public function setup_lesson_post_type() { |
|
| 204 | 204 | |
| 205 | 205 | |
| 206 | - $supports_array = array( 'title', 'editor', 'excerpt', 'thumbnail', 'page-attributes' ); |
|
| 206 | + $supports_array = array('title', 'editor', 'excerpt', 'thumbnail', 'page-attributes'); |
|
| 207 | 207 | $allow_comments = false; |
| 208 | - if ( isset( Sensei()->settings->settings[ 'lesson_comments' ] ) ) { |
|
| 209 | - $allow_comments = Sensei()->settings->settings[ 'lesson_comments' ]; |
|
| 208 | + if (isset(Sensei()->settings->settings['lesson_comments'])) { |
|
| 209 | + $allow_comments = Sensei()->settings->settings['lesson_comments']; |
|
| 210 | 210 | } // End If Statement |
| 211 | - if ( $allow_comments ) { |
|
| 212 | - array_push( $supports_array, 'comments' ); |
|
| 211 | + if ($allow_comments) { |
|
| 212 | + array_push($supports_array, 'comments'); |
|
| 213 | 213 | } // End If Statement |
| 214 | 214 | |
| 215 | 215 | $args = array( |
| 216 | - 'labels' => $this->create_post_type_labels( $this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu'] ), |
|
| 216 | + 'labels' => $this->create_post_type_labels($this->labels['lesson']['singular'], $this->labels['lesson']['plural'], $this->labels['lesson']['menu']), |
|
| 217 | 217 | 'public' => true, |
| 218 | 218 | 'publicly_queryable' => true, |
| 219 | 219 | 'show_ui' => true, |
| 220 | 220 | 'show_in_menu' => true, |
| 221 | 221 | 'query_var' => true, |
| 222 | 222 | 'rewrite' => array( |
| 223 | - 'slug' => esc_attr( apply_filters( 'sensei_lesson_slug', _x( 'lesson', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 223 | + 'slug' => esc_attr(apply_filters('sensei_lesson_slug', _x('lesson', 'post type single slug', 'woothemes-sensei'))), |
|
| 224 | 224 | 'with_front' => true, |
| 225 | 225 | 'feeds' => true, |
| 226 | 226 | 'pages' => true |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | * @since 1.9.0 |
| 240 | 240 | * @param array $args |
| 241 | 241 | */ |
| 242 | - register_post_type( 'lesson', apply_filters( 'sensei_register_post_type_lesson', $args ) ); |
|
| 242 | + register_post_type('lesson', apply_filters('sensei_register_post_type_lesson', $args)); |
|
| 243 | 243 | |
| 244 | 244 | } // End setup_lesson_post_type() |
| 245 | 245 | |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * @uses Sensei() |
| 250 | 250 | * @return void |
| 251 | 251 | */ |
| 252 | - public function setup_quiz_post_type () { |
|
| 252 | + public function setup_quiz_post_type() { |
|
| 253 | 253 | |
| 254 | 254 | |
| 255 | 255 | $args = array( |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | 'query_var' => true, |
| 267 | 267 | 'exclude_from_search' => true, |
| 268 | 268 | 'rewrite' => array( |
| 269 | - 'slug' => esc_attr( apply_filters( 'sensei_quiz_slug', _x( 'quiz', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 269 | + 'slug' => esc_attr(apply_filters('sensei_quiz_slug', _x('quiz', 'post type single slug', 'woothemes-sensei'))), |
|
| 270 | 270 | 'with_front' => true, |
| 271 | 271 | 'feeds' => true, |
| 272 | 272 | 'pages' => true |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | 'has_archive' => false, |
| 277 | 277 | 'hierarchical' => false, |
| 278 | 278 | 'menu_position' => 20, // Below "Pages" |
| 279 | - 'supports' => array( '' ) |
|
| 279 | + 'supports' => array('') |
|
| 280 | 280 | ); |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * @since 1.9.0 |
| 286 | 286 | * @param array $args |
| 287 | 287 | */ |
| 288 | - register_post_type( 'quiz', apply_filters( 'sensei_register_post_type_quiz', $args ) ); |
|
| 288 | + register_post_type('quiz', apply_filters('sensei_register_post_type_quiz', $args)); |
|
| 289 | 289 | |
| 290 | 290 | } // End setup_quiz_post_type() |
| 291 | 291 | |
@@ -295,10 +295,10 @@ discard block |
||
| 295 | 295 | * @since 1.0.0 |
| 296 | 296 | * @return void |
| 297 | 297 | */ |
| 298 | - public function setup_question_post_type () { |
|
| 298 | + public function setup_question_post_type() { |
|
| 299 | 299 | |
| 300 | 300 | $args = array( |
| 301 | - 'labels' => $this->create_post_type_labels( $this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu'] ), |
|
| 301 | + 'labels' => $this->create_post_type_labels($this->labels['question']['singular'], $this->labels['question']['plural'], $this->labels['question']['menu']), |
|
| 302 | 302 | 'public' => false, |
| 303 | 303 | 'publicly_queryable' => true, |
| 304 | 304 | 'show_ui' => true, |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | 'query_var' => true, |
| 308 | 308 | 'exclude_from_search' => true, |
| 309 | 309 | 'rewrite' => array( |
| 310 | - 'slug' => esc_attr( apply_filters( 'sensei_question_slug', _x( 'question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 310 | + 'slug' => esc_attr(apply_filters('sensei_question_slug', _x('question', 'post type single slug', 'woothemes-sensei'))), |
|
| 311 | 311 | 'with_front' => true, |
| 312 | 312 | 'feeds' => true, |
| 313 | 313 | 'pages' => true |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | 'has_archive' => true, |
| 318 | 318 | 'hierarchical' => false, |
| 319 | 319 | 'menu_position' => 51, |
| 320 | - 'supports' => array( 'title' ) |
|
| 320 | + 'supports' => array('title') |
|
| 321 | 321 | ); |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * @since 1.9.0 |
| 327 | 327 | * @param array $args |
| 328 | 328 | */ |
| 329 | - register_post_type( 'question', apply_filters('sensei_register_post_type_question', $args ) ); |
|
| 329 | + register_post_type('question', apply_filters('sensei_register_post_type_question', $args)); |
|
| 330 | 330 | |
| 331 | 331 | } // End setup_question_post_type() |
| 332 | 332 | |
@@ -335,10 +335,10 @@ discard block |
||
| 335 | 335 | * @since 1.6.0 |
| 336 | 336 | * @return void |
| 337 | 337 | */ |
| 338 | - public function setup_multiple_question_post_type () { |
|
| 338 | + public function setup_multiple_question_post_type() { |
|
| 339 | 339 | |
| 340 | 340 | $args = array( |
| 341 | - 'labels' => $this->create_post_type_labels( $this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu'] ), |
|
| 341 | + 'labels' => $this->create_post_type_labels($this->labels['multiple_question']['singular'], $this->labels['multiple_question']['plural'], $this->labels['multiple_question']['menu']), |
|
| 342 | 342 | 'public' => false, |
| 343 | 343 | 'publicly_queryable' => false, |
| 344 | 344 | 'show_ui' => false, |
@@ -347,7 +347,7 @@ discard block |
||
| 347 | 347 | 'query_var' => false, |
| 348 | 348 | 'exclude_from_search' => true, |
| 349 | 349 | 'rewrite' => array( |
| 350 | - 'slug' => esc_attr( apply_filters( 'sensei_multiple_question_slug', _x( 'multiple_question', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 350 | + 'slug' => esc_attr(apply_filters('sensei_multiple_question_slug', _x('multiple_question', 'post type single slug', 'woothemes-sensei'))), |
|
| 351 | 351 | 'with_front' => false, |
| 352 | 352 | 'feeds' => false, |
| 353 | 353 | 'pages' => false |
@@ -357,10 +357,10 @@ discard block |
||
| 357 | 357 | 'has_archive' => false, |
| 358 | 358 | 'hierarchical' => false, |
| 359 | 359 | 'menu_position' => 51, |
| 360 | - 'supports' => array( 'title', 'custom-fields' ) |
|
| 360 | + 'supports' => array('title', 'custom-fields') |
|
| 361 | 361 | ); |
| 362 | 362 | |
| 363 | - register_post_type( 'multiple_question', $args ); |
|
| 363 | + register_post_type('multiple_question', $args); |
|
| 364 | 364 | } // End setup_multiple_question_post_type() |
| 365 | 365 | |
| 366 | 366 | /** |
@@ -368,13 +368,13 @@ discard block |
||
| 368 | 368 | * @since 1.6.0 |
| 369 | 369 | * @return void |
| 370 | 370 | */ |
| 371 | - public function setup_sensei_message_post_type () { |
|
| 371 | + public function setup_sensei_message_post_type() { |
|
| 372 | 372 | |
| 373 | 373 | |
| 374 | - if( ! isset( Sensei()->settings->settings['messages_disable'] ) || ! Sensei()->settings->settings['messages_disable'] ) { |
|
| 374 | + if ( ! isset(Sensei()->settings->settings['messages_disable']) || ! Sensei()->settings->settings['messages_disable']) { |
|
| 375 | 375 | |
| 376 | 376 | $args = array( |
| 377 | - 'labels' => $this->create_post_type_labels( $this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu'] ), |
|
| 377 | + 'labels' => $this->create_post_type_labels($this->labels['sensei_message']['singular'], $this->labels['sensei_message']['plural'], $this->labels['sensei_message']['menu']), |
|
| 378 | 378 | 'public' => true, |
| 379 | 379 | 'publicly_queryable' => true, |
| 380 | 380 | 'show_ui' => true, |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | 'query_var' => true, |
| 384 | 384 | 'exclude_from_search' => true, |
| 385 | 385 | 'rewrite' => array( |
| 386 | - 'slug' => esc_attr( apply_filters( 'sensei_messages_slug', _x( 'messages', 'post type single slug', 'woothemes-sensei' ) ) ) , |
|
| 386 | + 'slug' => esc_attr(apply_filters('sensei_messages_slug', _x('messages', 'post type single slug', 'woothemes-sensei'))), |
|
| 387 | 387 | 'with_front' => false, |
| 388 | 388 | 'feeds' => false, |
| 389 | 389 | 'pages' => true |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | 'has_archive' => true, |
| 394 | 394 | 'hierarchical' => false, |
| 395 | 395 | 'menu_position' => 50, |
| 396 | - 'supports' => array( 'title', 'editor', 'comments' ), |
|
| 396 | + 'supports' => array('title', 'editor', 'comments'), |
|
| 397 | 397 | ); |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | * @since 1.9.0 |
| 403 | 403 | * @param array $args |
| 404 | 404 | */ |
| 405 | - register_post_type( 'sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args ) ); |
|
| 405 | + register_post_type('sensei_message', apply_filters('sensei_register_post_type_sensei_message', $args)); |
|
| 406 | 406 | } |
| 407 | 407 | } // End setup_sensei_message_post_type() |
| 408 | 408 | |
@@ -411,20 +411,20 @@ discard block |
||
| 411 | 411 | * @since 1.1.0 |
| 412 | 412 | * @return void |
| 413 | 413 | */ |
| 414 | - public function setup_course_category_taxonomy () { |
|
| 414 | + public function setup_course_category_taxonomy() { |
|
| 415 | 415 | // "Course Categories" Custom Taxonomy |
| 416 | 416 | $labels = array( |
| 417 | - 'name' => _x( 'Course Categories', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 418 | - 'singular_name' => _x( 'Course Category', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 419 | - 'search_items' => __( 'Search Course Categories', 'woothemes-sensei' ), |
|
| 420 | - 'all_items' => __( 'All Course Categories', 'woothemes-sensei' ), |
|
| 421 | - 'parent_item' => __( 'Parent Course Category', 'woothemes-sensei' ), |
|
| 422 | - 'parent_item_colon' => __( 'Parent Course Category:', 'woothemes-sensei' ), |
|
| 423 | - 'edit_item' => __( 'Edit Course Category', 'woothemes-sensei' ), |
|
| 424 | - 'update_item' => __( 'Update Course Category', 'woothemes-sensei' ), |
|
| 425 | - 'add_new_item' => __( 'Add New Course Category', 'woothemes-sensei' ), |
|
| 426 | - 'new_item_name' => __( 'New Course Category Name', 'woothemes-sensei' ), |
|
| 427 | - 'menu_name' => __( 'Course Categories', 'woothemes-sensei' ), |
|
| 417 | + 'name' => _x('Course Categories', 'taxonomy general name', 'woothemes-sensei'), |
|
| 418 | + 'singular_name' => _x('Course Category', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 419 | + 'search_items' => __('Search Course Categories', 'woothemes-sensei'), |
|
| 420 | + 'all_items' => __('All Course Categories', 'woothemes-sensei'), |
|
| 421 | + 'parent_item' => __('Parent Course Category', 'woothemes-sensei'), |
|
| 422 | + 'parent_item_colon' => __('Parent Course Category:', 'woothemes-sensei'), |
|
| 423 | + 'edit_item' => __('Edit Course Category', 'woothemes-sensei'), |
|
| 424 | + 'update_item' => __('Update Course Category', 'woothemes-sensei'), |
|
| 425 | + 'add_new_item' => __('Add New Course Category', 'woothemes-sensei'), |
|
| 426 | + 'new_item_name' => __('New Course Category Name', 'woothemes-sensei'), |
|
| 427 | + 'menu_name' => __('Course Categories', 'woothemes-sensei'), |
|
| 428 | 428 | 'popular_items' => null // Hides the "Popular" section above the "add" form in the admin. |
| 429 | 429 | ); |
| 430 | 430 | |
@@ -439,10 +439,10 @@ discard block |
||
| 439 | 439 | 'edit_terms' => 'edit_courses', |
| 440 | 440 | 'delete_terms' => 'manage_categories', |
| 441 | 441 | 'assign_terms' => 'edit_courses',), |
| 442 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_course_category_slug', _x( 'course-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 442 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_course_category_slug', _x('course-category', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 443 | 443 | ); |
| 444 | 444 | |
| 445 | - register_taxonomy( 'course-category', array( 'course' ), $args ); |
|
| 445 | + register_taxonomy('course-category', array('course'), $args); |
|
| 446 | 446 | |
| 447 | 447 | } // End setup_course_category_taxonomy() |
| 448 | 448 | |
@@ -451,20 +451,20 @@ discard block |
||
| 451 | 451 | * @since 1.0.0 |
| 452 | 452 | * @return void |
| 453 | 453 | */ |
| 454 | - public function setup_quiz_type_taxonomy () { |
|
| 454 | + public function setup_quiz_type_taxonomy() { |
|
| 455 | 455 | // "Quiz Types" Custom Taxonomy |
| 456 | 456 | $labels = array( |
| 457 | - 'name' => _x( 'Quiz Types', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 458 | - 'singular_name' => _x( 'Quiz Type', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 459 | - 'search_items' => __( 'Search Quiz Types', 'woothemes-sensei' ), |
|
| 460 | - 'all_items' => __( 'All Quiz Types', 'woothemes-sensei' ), |
|
| 461 | - 'parent_item' => __( 'Parent Quiz Type', 'woothemes-sensei' ), |
|
| 462 | - 'parent_item_colon' => __( 'Parent Quiz Type:', 'woothemes-sensei' ), |
|
| 463 | - 'edit_item' => __( 'Edit Quiz Type', 'woothemes-sensei' ), |
|
| 464 | - 'update_item' => __( 'Update Quiz Type', 'woothemes-sensei' ), |
|
| 465 | - 'add_new_item' => __( 'Add New Quiz Type', 'woothemes-sensei' ), |
|
| 466 | - 'new_item_name' => __( 'New Quiz Type Name', 'woothemes-sensei' ), |
|
| 467 | - 'menu_name' => __( 'Quiz Types', 'woothemes-sensei' ), |
|
| 457 | + 'name' => _x('Quiz Types', 'taxonomy general name', 'woothemes-sensei'), |
|
| 458 | + 'singular_name' => _x('Quiz Type', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 459 | + 'search_items' => __('Search Quiz Types', 'woothemes-sensei'), |
|
| 460 | + 'all_items' => __('All Quiz Types', 'woothemes-sensei'), |
|
| 461 | + 'parent_item' => __('Parent Quiz Type', 'woothemes-sensei'), |
|
| 462 | + 'parent_item_colon' => __('Parent Quiz Type:', 'woothemes-sensei'), |
|
| 463 | + 'edit_item' => __('Edit Quiz Type', 'woothemes-sensei'), |
|
| 464 | + 'update_item' => __('Update Quiz Type', 'woothemes-sensei'), |
|
| 465 | + 'add_new_item' => __('Add New Quiz Type', 'woothemes-sensei'), |
|
| 466 | + 'new_item_name' => __('New Quiz Type Name', 'woothemes-sensei'), |
|
| 467 | + 'menu_name' => __('Quiz Types', 'woothemes-sensei'), |
|
| 468 | 468 | 'popular_items' => null // Hides the "Popular" section above the "add" form in the admin. |
| 469 | 469 | ); |
| 470 | 470 | |
@@ -475,10 +475,10 @@ discard block |
||
| 475 | 475 | 'query_var' => true, |
| 476 | 476 | 'show_in_nav_menus' => false, |
| 477 | 477 | 'public' => false, |
| 478 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_quiz_type_slug', _x( 'quiz-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 478 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_quiz_type_slug', _x('quiz-type', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 479 | 479 | ); |
| 480 | 480 | |
| 481 | - register_taxonomy( 'quiz-type', array( 'quiz' ), $args ); |
|
| 481 | + register_taxonomy('quiz-type', array('quiz'), $args); |
|
| 482 | 482 | } // End setup_quiz_type_taxonomy() |
| 483 | 483 | |
| 484 | 484 | /** |
@@ -486,20 +486,20 @@ discard block |
||
| 486 | 486 | * @since 1.3.0 |
| 487 | 487 | * @return void |
| 488 | 488 | */ |
| 489 | - public function setup_question_type_taxonomy () { |
|
| 489 | + public function setup_question_type_taxonomy() { |
|
| 490 | 490 | // "Question Types" Custom Taxonomy |
| 491 | 491 | $labels = array( |
| 492 | - 'name' => _x( 'Question Types', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 493 | - 'singular_name' => _x( 'Question Type', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 494 | - 'search_items' => __( 'Search Question Types', 'woothemes-sensei' ), |
|
| 495 | - 'all_items' => __( 'All Question Types', 'woothemes-sensei' ), |
|
| 496 | - 'parent_item' => __( 'Parent Question Type', 'woothemes-sensei' ), |
|
| 497 | - 'parent_item_colon' => __( 'Parent Question Type:', 'woothemes-sensei' ), |
|
| 498 | - 'edit_item' => __( 'Edit Question Type', 'woothemes-sensei' ), |
|
| 499 | - 'update_item' => __( 'Update Question Type', 'woothemes-sensei' ), |
|
| 500 | - 'add_new_item' => __( 'Add New Question Type', 'woothemes-sensei' ), |
|
| 501 | - 'new_item_name' => __( 'New Question Type Name', 'woothemes-sensei' ), |
|
| 502 | - 'menu_name' => __( 'Question Types', 'woothemes-sensei' ), |
|
| 492 | + 'name' => _x('Question Types', 'taxonomy general name', 'woothemes-sensei'), |
|
| 493 | + 'singular_name' => _x('Question Type', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 494 | + 'search_items' => __('Search Question Types', 'woothemes-sensei'), |
|
| 495 | + 'all_items' => __('All Question Types', 'woothemes-sensei'), |
|
| 496 | + 'parent_item' => __('Parent Question Type', 'woothemes-sensei'), |
|
| 497 | + 'parent_item_colon' => __('Parent Question Type:', 'woothemes-sensei'), |
|
| 498 | + 'edit_item' => __('Edit Question Type', 'woothemes-sensei'), |
|
| 499 | + 'update_item' => __('Update Question Type', 'woothemes-sensei'), |
|
| 500 | + 'add_new_item' => __('Add New Question Type', 'woothemes-sensei'), |
|
| 501 | + 'new_item_name' => __('New Question Type Name', 'woothemes-sensei'), |
|
| 502 | + 'menu_name' => __('Question Types', 'woothemes-sensei'), |
|
| 503 | 503 | 'popular_items' => null // Hides the "Popular" section above the "add" form in the admin. |
| 504 | 504 | ); |
| 505 | 505 | |
@@ -511,10 +511,10 @@ discard block |
||
| 511 | 511 | 'query_var' => false, |
| 512 | 512 | 'show_in_nav_menus' => false, |
| 513 | 513 | 'show_admin_column' => true, |
| 514 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_type_slug', _x( 'question-type', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 514 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_question_type_slug', _x('question-type', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 515 | 515 | ); |
| 516 | 516 | |
| 517 | - register_taxonomy( 'question-type', array( 'question' ), $args ); |
|
| 517 | + register_taxonomy('question-type', array('question'), $args); |
|
| 518 | 518 | } // End setup_question_type_taxonomy() |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -522,20 +522,20 @@ discard block |
||
| 522 | 522 | * @since 1.3.0 |
| 523 | 523 | * @return void |
| 524 | 524 | */ |
| 525 | - public function setup_question_category_taxonomy () { |
|
| 525 | + public function setup_question_category_taxonomy() { |
|
| 526 | 526 | // "Question Categories" Custom Taxonomy |
| 527 | 527 | $labels = array( |
| 528 | - 'name' => _x( 'Question Categories', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 529 | - 'singular_name' => _x( 'Question Category', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 530 | - 'search_items' => __( 'Search Question Categories', 'woothemes-sensei' ), |
|
| 531 | - 'all_items' => __( 'All Question Categories', 'woothemes-sensei' ), |
|
| 532 | - 'parent_item' => __( 'Parent Question Category', 'woothemes-sensei' ), |
|
| 533 | - 'parent_item_colon' => __( 'Parent Question Category:', 'woothemes-sensei' ), |
|
| 534 | - 'edit_item' => __( 'Edit Question Category', 'woothemes-sensei' ), |
|
| 535 | - 'update_item' => __( 'Update Question Category', 'woothemes-sensei' ), |
|
| 536 | - 'add_new_item' => __( 'Add New Question Category', 'woothemes-sensei' ), |
|
| 537 | - 'new_item_name' => __( 'New Question Category Name', 'woothemes-sensei' ), |
|
| 538 | - 'menu_name' => __( 'Categories', 'woothemes-sensei' ), |
|
| 528 | + 'name' => _x('Question Categories', 'taxonomy general name', 'woothemes-sensei'), |
|
| 529 | + 'singular_name' => _x('Question Category', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 530 | + 'search_items' => __('Search Question Categories', 'woothemes-sensei'), |
|
| 531 | + 'all_items' => __('All Question Categories', 'woothemes-sensei'), |
|
| 532 | + 'parent_item' => __('Parent Question Category', 'woothemes-sensei'), |
|
| 533 | + 'parent_item_colon' => __('Parent Question Category:', 'woothemes-sensei'), |
|
| 534 | + 'edit_item' => __('Edit Question Category', 'woothemes-sensei'), |
|
| 535 | + 'update_item' => __('Update Question Category', 'woothemes-sensei'), |
|
| 536 | + 'add_new_item' => __('Add New Question Category', 'woothemes-sensei'), |
|
| 537 | + 'new_item_name' => __('New Question Category Name', 'woothemes-sensei'), |
|
| 538 | + 'menu_name' => __('Categories', 'woothemes-sensei'), |
|
| 539 | 539 | ); |
| 540 | 540 | |
| 541 | 541 | $args = array( |
@@ -551,10 +551,10 @@ discard block |
||
| 551 | 551 | 'edit_terms' => 'edit_questions', |
| 552 | 552 | 'delete_terms' => 'manage_categories', |
| 553 | 553 | 'assign_terms' => 'edit_questions',), |
| 554 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_question_category_slug', _x( 'question-category', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 554 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_question_category_slug', _x('question-category', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 555 | 555 | ); |
| 556 | 556 | |
| 557 | - register_taxonomy( 'question-category', array( 'question' ), $args ); |
|
| 557 | + register_taxonomy('question-category', array('question'), $args); |
|
| 558 | 558 | } // End setup_question_type_taxonomy() |
| 559 | 559 | |
| 560 | 560 | /** |
@@ -562,20 +562,20 @@ discard block |
||
| 562 | 562 | * @since 1.5.0 |
| 563 | 563 | * @return void |
| 564 | 564 | */ |
| 565 | - public function setup_lesson_tag_taxonomy () { |
|
| 565 | + public function setup_lesson_tag_taxonomy() { |
|
| 566 | 566 | // "Lesson Tags" Custom Taxonomy |
| 567 | 567 | $labels = array( |
| 568 | - 'name' => _x( 'Lesson Tags', 'taxonomy general name', 'woothemes-sensei' ), |
|
| 569 | - 'singular_name' => _x( 'Lesson Tag', 'taxonomy singular name', 'woothemes-sensei' ), |
|
| 570 | - 'search_items' => __( 'Search Lesson Tags', 'woothemes-sensei' ), |
|
| 571 | - 'all_items' => __( 'All Lesson Tags', 'woothemes-sensei' ), |
|
| 572 | - 'parent_item' => __( 'Parent Tag', 'woothemes-sensei' ), |
|
| 573 | - 'parent_item_colon' => __( 'Parent Tag:', 'woothemes-sensei' ), |
|
| 574 | - 'edit_item' => __( 'Edit Lesson Tag', 'woothemes-sensei' ), |
|
| 575 | - 'update_item' => __( 'Update Lesson Tag', 'woothemes-sensei' ), |
|
| 576 | - 'add_new_item' => __( 'Add New Lesson Tag', 'woothemes-sensei' ), |
|
| 577 | - 'new_item_name' => __( 'New Tag Name', 'woothemes-sensei' ), |
|
| 578 | - 'menu_name' => __( 'Lesson Tags', 'woothemes-sensei' ) |
|
| 568 | + 'name' => _x('Lesson Tags', 'taxonomy general name', 'woothemes-sensei'), |
|
| 569 | + 'singular_name' => _x('Lesson Tag', 'taxonomy singular name', 'woothemes-sensei'), |
|
| 570 | + 'search_items' => __('Search Lesson Tags', 'woothemes-sensei'), |
|
| 571 | + 'all_items' => __('All Lesson Tags', 'woothemes-sensei'), |
|
| 572 | + 'parent_item' => __('Parent Tag', 'woothemes-sensei'), |
|
| 573 | + 'parent_item_colon' => __('Parent Tag:', 'woothemes-sensei'), |
|
| 574 | + 'edit_item' => __('Edit Lesson Tag', 'woothemes-sensei'), |
|
| 575 | + 'update_item' => __('Update Lesson Tag', 'woothemes-sensei'), |
|
| 576 | + 'add_new_item' => __('Add New Lesson Tag', 'woothemes-sensei'), |
|
| 577 | + 'new_item_name' => __('New Tag Name', 'woothemes-sensei'), |
|
| 578 | + 'menu_name' => __('Lesson Tags', 'woothemes-sensei') |
|
| 579 | 579 | ); |
| 580 | 580 | |
| 581 | 581 | $args = array( |
@@ -589,10 +589,10 @@ discard block |
||
| 589 | 589 | 'edit_terms' => 'edit_lessons', |
| 590 | 590 | 'delete_terms' => 'manage_categories', |
| 591 | 591 | 'assign_terms' => 'edit_lessons',), |
| 592 | - 'rewrite' => array( 'slug' => esc_attr( apply_filters( 'sensei_lesson_tag_slug', _x( 'lesson-tag', 'taxonomy archive slug', 'woothemes-sensei' ) ) ) ) |
|
| 592 | + 'rewrite' => array('slug' => esc_attr(apply_filters('sensei_lesson_tag_slug', _x('lesson-tag', 'taxonomy archive slug', 'woothemes-sensei')))) |
|
| 593 | 593 | ); |
| 594 | 594 | |
| 595 | - register_taxonomy( 'lesson-tag', array( 'lesson' ), $args ); |
|
| 595 | + register_taxonomy('lesson-tag', array('lesson'), $args); |
|
| 596 | 596 | } // End setup_lesson_tag_taxonomy() |
| 597 | 597 | |
| 598 | 598 | /** |
@@ -600,15 +600,15 @@ discard block |
||
| 600 | 600 | * @since 1.0.0 |
| 601 | 601 | * @return void |
| 602 | 602 | */ |
| 603 | - private function setup_post_type_labels_base () { |
|
| 604 | - $this->labels = array( 'course' => array(), 'lesson' => array(), 'quiz' => array(), 'question' => array() ); |
|
| 603 | + private function setup_post_type_labels_base() { |
|
| 604 | + $this->labels = array('course' => array(), 'lesson' => array(), 'quiz' => array(), 'question' => array()); |
|
| 605 | 605 | |
| 606 | - $this->labels['course'] = array( 'singular' => __( 'Course', 'woothemes-sensei' ), 'plural' => __( 'Courses', 'woothemes-sensei' ), 'menu' => __( 'Courses', 'woothemes-sensei' ) ); |
|
| 607 | - $this->labels['lesson'] = array( 'singular' => __( 'Lesson', 'woothemes-sensei' ), 'plural' => __( 'Lessons', 'woothemes-sensei' ), 'menu' => __( 'Lessons', 'woothemes-sensei' ) ); |
|
| 608 | - $this->labels['quiz'] = array( 'singular' => __( 'Quiz', 'woothemes-sensei' ), 'plural' => __( 'Quizzes', 'woothemes-sensei' ), 'menu' => __( 'Quizzes', 'woothemes-sensei' ) ); |
|
| 609 | - $this->labels['question'] = array( 'singular' => __( 'Question', 'woothemes-sensei' ), 'plural' => __( 'Questions', 'woothemes-sensei' ), 'menu' => __( 'Questions', 'woothemes-sensei' ) ); |
|
| 610 | - $this->labels['multiple_question'] = array( 'singular' => __( 'Multiple Question', 'woothemes-sensei' ), 'plural' => __( 'Multiple Questions', 'woothemes-sensei' ), 'menu' => __( 'Multiple Questions', 'woothemes-sensei' ) ); |
|
| 611 | - $this->labels['sensei_message'] = array( 'singular' => __( 'Message', 'woothemes-sensei' ), 'plural' => __( 'Messages', 'woothemes-sensei' ), 'menu' => __( 'Messages', 'woothemes-sensei' ) ); |
|
| 606 | + $this->labels['course'] = array('singular' => __('Course', 'woothemes-sensei'), 'plural' => __('Courses', 'woothemes-sensei'), 'menu' => __('Courses', 'woothemes-sensei')); |
|
| 607 | + $this->labels['lesson'] = array('singular' => __('Lesson', 'woothemes-sensei'), 'plural' => __('Lessons', 'woothemes-sensei'), 'menu' => __('Lessons', 'woothemes-sensei')); |
|
| 608 | + $this->labels['quiz'] = array('singular' => __('Quiz', 'woothemes-sensei'), 'plural' => __('Quizzes', 'woothemes-sensei'), 'menu' => __('Quizzes', 'woothemes-sensei')); |
|
| 609 | + $this->labels['question'] = array('singular' => __('Question', 'woothemes-sensei'), 'plural' => __('Questions', 'woothemes-sensei'), 'menu' => __('Questions', 'woothemes-sensei')); |
|
| 610 | + $this->labels['multiple_question'] = array('singular' => __('Multiple Question', 'woothemes-sensei'), 'plural' => __('Multiple Questions', 'woothemes-sensei'), 'menu' => __('Multiple Questions', 'woothemes-sensei')); |
|
| 611 | + $this->labels['sensei_message'] = array('singular' => __('Message', 'woothemes-sensei'), 'plural' => __('Messages', 'woothemes-sensei'), 'menu' => __('Messages', 'woothemes-sensei')); |
|
| 612 | 612 | |
| 613 | 613 | } // End setup_post_type_labels_base() |
| 614 | 614 | |
@@ -620,21 +620,21 @@ discard block |
||
| 620 | 620 | * @param string $menu The menu item label |
| 621 | 621 | * @return array An array of the labels to be used |
| 622 | 622 | */ |
| 623 | - private function create_post_type_labels ( $singular, $plural, $menu ) { |
|
| 623 | + private function create_post_type_labels($singular, $plural, $menu) { |
|
| 624 | 624 | $labels = array( |
| 625 | - 'name' => sprintf( _x( '%s', 'post type general name', 'woothemes-sensei' ), $plural ), |
|
| 626 | - 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'woothemes-sensei' ), $singular ), |
|
| 627 | - 'add_new' => __( 'Add New', 'woothemes-sensei' ), |
|
| 628 | - 'add_new_item' => sprintf( __( 'Add New %s', 'woothemes-sensei' ), $singular ), |
|
| 629 | - 'edit_item' => sprintf( __( 'Edit %s', 'woothemes-sensei' ), $singular ), |
|
| 630 | - 'new_item' => sprintf( __( 'New %s', 'woothemes-sensei' ), $singular ), |
|
| 631 | - 'all_items' => sprintf( __( 'All %s', 'woothemes-sensei' ), $plural ), |
|
| 632 | - 'view_item' => sprintf( __( 'View %s', 'woothemes-sensei' ), $singular ), |
|
| 633 | - 'search_items' => sprintf( __( 'Search %s', 'woothemes-sensei' ), $plural ), |
|
| 634 | - 'not_found' => sprintf( __( 'No %s found', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
| 635 | - 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'woothemes-sensei' ), mb_strtolower( $plural, 'UTF-8') ), |
|
| 625 | + 'name' => sprintf(_x('%s', 'post type general name', 'woothemes-sensei'), $plural), |
|
| 626 | + 'singular_name' => sprintf(_x('%s', 'post type singular name', 'woothemes-sensei'), $singular), |
|
| 627 | + 'add_new' => __('Add New', 'woothemes-sensei'), |
|
| 628 | + 'add_new_item' => sprintf(__('Add New %s', 'woothemes-sensei'), $singular), |
|
| 629 | + 'edit_item' => sprintf(__('Edit %s', 'woothemes-sensei'), $singular), |
|
| 630 | + 'new_item' => sprintf(__('New %s', 'woothemes-sensei'), $singular), |
|
| 631 | + 'all_items' => sprintf(__('All %s', 'woothemes-sensei'), $plural), |
|
| 632 | + 'view_item' => sprintf(__('View %s', 'woothemes-sensei'), $singular), |
|
| 633 | + 'search_items' => sprintf(__('Search %s', 'woothemes-sensei'), $plural), |
|
| 634 | + 'not_found' => sprintf(__('No %s found', 'woothemes-sensei'), mb_strtolower($plural, 'UTF-8')), |
|
| 635 | + 'not_found_in_trash' => sprintf(__('No %s found in Trash', 'woothemes-sensei'), mb_strtolower($plural, 'UTF-8')), |
|
| 636 | 636 | 'parent_item_colon' => '', |
| 637 | - 'menu_name' => sprintf( __( '%s', 'woothemes-sensei' ), $menu ) |
|
| 637 | + 'menu_name' => sprintf(__('%s', 'woothemes-sensei'), $menu) |
|
| 638 | 638 | ); |
| 639 | 639 | |
| 640 | 640 | return $labels; |
@@ -646,14 +646,14 @@ discard block |
||
| 646 | 646 | * @param array $messages The existing array of messages for post types. |
| 647 | 647 | * @return array The modified array of messages for post types. |
| 648 | 648 | */ |
| 649 | - public function setup_post_type_messages ( $messages ) { |
|
| 649 | + public function setup_post_type_messages($messages) { |
|
| 650 | 650 | global $post, $post_ID; |
| 651 | 651 | |
| 652 | - $messages['course'] = $this->create_post_type_messages( 'course' ); |
|
| 653 | - $messages['lesson'] = $this->create_post_type_messages( 'lesson' ); |
|
| 654 | - $messages['quiz'] = $this->create_post_type_messages( 'quiz' ); |
|
| 655 | - $messages['question'] = $this->create_post_type_messages( 'question' ); |
|
| 656 | - $messages['multiple_question'] = $this->create_post_type_messages( 'multiple_question' ); |
|
| 652 | + $messages['course'] = $this->create_post_type_messages('course'); |
|
| 653 | + $messages['lesson'] = $this->create_post_type_messages('lesson'); |
|
| 654 | + $messages['quiz'] = $this->create_post_type_messages('quiz'); |
|
| 655 | + $messages['question'] = $this->create_post_type_messages('question'); |
|
| 656 | + $messages['multiple_question'] = $this->create_post_type_messages('multiple_question'); |
|
| 657 | 657 | |
| 658 | 658 | return $messages; |
| 659 | 659 | } // End setup_post_type_messages() |
@@ -664,23 +664,23 @@ discard block |
||
| 664 | 664 | * @param string $post_type The post type for which to create messages. |
| 665 | 665 | * @return array An array of messages (empty array if the post type isn't one we're looking to work with). |
| 666 | 666 | */ |
| 667 | - private function create_post_type_messages ( $post_type ) { |
|
| 667 | + private function create_post_type_messages($post_type) { |
|
| 668 | 668 | global $post, $post_ID; |
| 669 | 669 | |
| 670 | - if ( ! isset( $this->labels[$post_type] ) ) { return array(); } |
|
| 670 | + if ( ! isset($this->labels[$post_type])) { return array(); } |
|
| 671 | 671 | |
| 672 | 672 | $messages = array( |
| 673 | 673 | 0 => '', |
| 674 | - 1 => sprintf( __( '%1$s updated. %2$sView %1$s%3$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>' ), |
|
| 675 | - 2 => __( 'Custom field updated.' , 'woothemes-sensei' ), |
|
| 676 | - 3 => __( 'Custom field deleted.' , 'woothemes-sensei' ), |
|
| 677 | - 4 => sprintf( __( '%1$s updated.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'] ), |
|
| 678 | - 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 679 | - 6 => sprintf( __( '%1$s published. %2$sView %1$s%3$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a href="' . esc_url( get_permalink( $post_ID ) ) . '">', '</a>' ), |
|
| 680 | - 7 => sprintf( __( '%1$s saved.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'] ), |
|
| 681 | - 8 => sprintf( __( '%1$s submitted. %2$sPreview %1$s%3$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', '</a>' ), |
|
| 682 | - 9 => sprintf( __( '%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<strong>' . date_i18n( __( 'M j, Y @ G:i' , 'woothemes-sensei' ), strtotime( $post->post_date ) ) . '</strong>', '<a target="_blank" href="' . esc_url( get_permalink( $post_ID ) ) . '">', $this->labels[$post_type]['singular'], '</a>' ), |
|
| 683 | - 10 => sprintf( __( '%1$s draft updated. %2$sPreview %3$s%4$s.' , 'woothemes-sensei' ), $this->labels[$post_type]['singular'], '<a target="_blank" href="' . esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) . '">', $this->labels[$post_type]['singular'], '</a>' ), |
|
| 674 | + 1 => sprintf(__('%1$s updated. %2$sView %1$s%3$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a href="'.esc_url(get_permalink($post_ID)).'">', '</a>'), |
|
| 675 | + 2 => __('Custom field updated.', 'woothemes-sensei'), |
|
| 676 | + 3 => __('Custom field deleted.', 'woothemes-sensei'), |
|
| 677 | + 4 => sprintf(__('%1$s updated.', 'woothemes-sensei'), $this->labels[$post_type]['singular']), |
|
| 678 | + 5 => isset($_GET['revision']) ? sprintf(__('%1$s restored to revision from %2$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
| 679 | + 6 => sprintf(__('%1$s published. %2$sView %1$s%3$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a href="'.esc_url(get_permalink($post_ID)).'">', '</a>'), |
|
| 680 | + 7 => sprintf(__('%1$s saved.', 'woothemes-sensei'), $this->labels[$post_type]['singular']), |
|
| 681 | + 8 => sprintf(__('%1$s submitted. %2$sPreview %1$s%3$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))).'">', '</a>'), |
|
| 682 | + 9 => sprintf(__('%1$s scheduled for: %2$s. %3$sPreview %4$s%5$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<strong>'.date_i18n(__('M j, Y @ G:i', 'woothemes-sensei'), strtotime($post->post_date)).'</strong>', '<a target="_blank" href="'.esc_url(get_permalink($post_ID)).'">', $this->labels[$post_type]['singular'], '</a>'), |
|
| 683 | + 10 => sprintf(__('%1$s draft updated. %2$sPreview %3$s%4$s.', 'woothemes-sensei'), $this->labels[$post_type]['singular'], '<a target="_blank" href="'.esc_url(add_query_arg('preview', 'true', get_permalink($post_ID))).'">', $this->labels[$post_type]['singular'], '</a>'), |
|
| 684 | 684 | ); |
| 685 | 685 | |
| 686 | 686 | return $messages; |
@@ -693,11 +693,11 @@ discard block |
||
| 693 | 693 | * @param string $title |
| 694 | 694 | * @return string $title |
| 695 | 695 | */ |
| 696 | - public function enter_title_here ( $title ) { |
|
| 697 | - if ( get_post_type() == 'course' ) { |
|
| 698 | - $title = __( 'Enter a title for this course here', 'woothemes-sensei' ); |
|
| 699 | - } elseif ( get_post_type() == 'lesson' ) { |
|
| 700 | - $title = __( 'Enter a title for this lesson here', 'woothemes-sensei' ); |
|
| 696 | + public function enter_title_here($title) { |
|
| 697 | + if (get_post_type() == 'course') { |
|
| 698 | + $title = __('Enter a title for this course here', 'woothemes-sensei'); |
|
| 699 | + } elseif (get_post_type() == 'lesson') { |
|
| 700 | + $title = __('Enter a title for this lesson here', 'woothemes-sensei'); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | return $title; |
@@ -711,60 +711,60 @@ discard block |
||
| 711 | 711 | * @param array $post_types |
| 712 | 712 | * @return void |
| 713 | 713 | */ |
| 714 | - public function set_role_cap_defaults( $post_types = array() ) { |
|
| 714 | + public function set_role_cap_defaults($post_types = array()) { |
|
| 715 | 715 | |
| 716 | - foreach ( $post_types as $post_type_item => $post_type_name ) { |
|
| 716 | + foreach ($post_types as $post_type_item => $post_type_name) { |
|
| 717 | 717 | // Super Admin |
| 718 | - $this->role_caps[] = array( 'administrator' => array( 'edit_' . $post_type_item, |
|
| 719 | - 'read_' . $post_type_item, |
|
| 720 | - 'delete_' . $post_type_item, |
|
| 721 | - 'create_' . $post_type_item . 's', |
|
| 722 | - 'edit_' . $post_type_item . 's', |
|
| 723 | - 'edit_others_' . $post_type_item . 's', |
|
| 724 | - 'publish_' . $post_type_item . 's', |
|
| 725 | - 'read_private_' . $post_type_item . 's', |
|
| 718 | + $this->role_caps[] = array('administrator' => array('edit_'.$post_type_item, |
|
| 719 | + 'read_'.$post_type_item, |
|
| 720 | + 'delete_'.$post_type_item, |
|
| 721 | + 'create_'.$post_type_item.'s', |
|
| 722 | + 'edit_'.$post_type_item.'s', |
|
| 723 | + 'edit_others_'.$post_type_item.'s', |
|
| 724 | + 'publish_'.$post_type_item.'s', |
|
| 725 | + 'read_private_'.$post_type_item.'s', |
|
| 726 | 726 | 'read', |
| 727 | - 'delete_' . $post_type_item . 's', |
|
| 728 | - 'delete_private_' . $post_type_item . 's', |
|
| 729 | - 'delete_published_' . $post_type_item . 's', |
|
| 730 | - 'delete_others_' . $post_type_item . 's', |
|
| 731 | - 'edit_private_' . $post_type_item . 's', |
|
| 732 | - 'edit_published_' . $post_type_item . 's', |
|
| 727 | + 'delete_'.$post_type_item.'s', |
|
| 728 | + 'delete_private_'.$post_type_item.'s', |
|
| 729 | + 'delete_published_'.$post_type_item.'s', |
|
| 730 | + 'delete_others_'.$post_type_item.'s', |
|
| 731 | + 'edit_private_'.$post_type_item.'s', |
|
| 732 | + 'edit_published_'.$post_type_item.'s', |
|
| 733 | 733 | 'manage_sensei', |
| 734 | - 'manage_sensei_grades' ), |
|
| 735 | - 'editor' => array( 'edit_' . $post_type_item, |
|
| 736 | - 'read_' . $post_type_item, |
|
| 737 | - 'delete_' . $post_type_item, |
|
| 738 | - 'create_' . $post_type_item . 's', |
|
| 739 | - 'edit_' . $post_type_item . 's', |
|
| 740 | - 'edit_others_' . $post_type_item . 's', |
|
| 741 | - 'publish_' . $post_type_item . 's', |
|
| 742 | - 'read_private_' . $post_type_item . 's', |
|
| 734 | + 'manage_sensei_grades'), |
|
| 735 | + 'editor' => array('edit_'.$post_type_item, |
|
| 736 | + 'read_'.$post_type_item, |
|
| 737 | + 'delete_'.$post_type_item, |
|
| 738 | + 'create_'.$post_type_item.'s', |
|
| 739 | + 'edit_'.$post_type_item.'s', |
|
| 740 | + 'edit_others_'.$post_type_item.'s', |
|
| 741 | + 'publish_'.$post_type_item.'s', |
|
| 742 | + 'read_private_'.$post_type_item.'s', |
|
| 743 | 743 | 'read', |
| 744 | - 'delete_' . $post_type_item . 's', |
|
| 745 | - 'delete_private_' . $post_type_item . 's', |
|
| 746 | - 'delete_published_' . $post_type_item . 's', |
|
| 747 | - 'delete_others_' . $post_type_item . 's', |
|
| 748 | - 'edit_private_' . $post_type_item . 's', |
|
| 749 | - 'edit_published_' . $post_type_item . 's' ), |
|
| 750 | - 'author' => array( 'edit_' . $post_type_item, |
|
| 751 | - 'read_' . $post_type_item, |
|
| 752 | - 'delete_' . $post_type_item, |
|
| 753 | - 'create_' . $post_type_item . 's', |
|
| 754 | - 'edit_' . $post_type_item . 's', |
|
| 755 | - 'publish_' . $post_type_item . 's', |
|
| 744 | + 'delete_'.$post_type_item.'s', |
|
| 745 | + 'delete_private_'.$post_type_item.'s', |
|
| 746 | + 'delete_published_'.$post_type_item.'s', |
|
| 747 | + 'delete_others_'.$post_type_item.'s', |
|
| 748 | + 'edit_private_'.$post_type_item.'s', |
|
| 749 | + 'edit_published_'.$post_type_item.'s'), |
|
| 750 | + 'author' => array('edit_'.$post_type_item, |
|
| 751 | + 'read_'.$post_type_item, |
|
| 752 | + 'delete_'.$post_type_item, |
|
| 753 | + 'create_'.$post_type_item.'s', |
|
| 754 | + 'edit_'.$post_type_item.'s', |
|
| 755 | + 'publish_'.$post_type_item.'s', |
|
| 756 | 756 | 'read', |
| 757 | - 'delete_' . $post_type_item . 's', |
|
| 758 | - 'delete_published_' . $post_type_item . 's', |
|
| 759 | - 'edit_published_' . $post_type_item . 's' ), |
|
| 760 | - 'contributor' => array( 'edit_' . $post_type_item, |
|
| 761 | - 'read_' . $post_type_item, |
|
| 762 | - 'delete_' . $post_type_item, |
|
| 763 | - 'create_' . $post_type_item . 's', |
|
| 764 | - 'edit_' . $post_type_item . 's', |
|
| 757 | + 'delete_'.$post_type_item.'s', |
|
| 758 | + 'delete_published_'.$post_type_item.'s', |
|
| 759 | + 'edit_published_'.$post_type_item.'s'), |
|
| 760 | + 'contributor' => array('edit_'.$post_type_item, |
|
| 761 | + 'read_'.$post_type_item, |
|
| 762 | + 'delete_'.$post_type_item, |
|
| 763 | + 'create_'.$post_type_item.'s', |
|
| 764 | + 'edit_'.$post_type_item.'s', |
|
| 765 | 765 | 'read', |
| 766 | - 'delete_' . $post_type_item . 's' ), |
|
| 767 | - 'subscriber' => array( 'read' ) |
|
| 766 | + 'delete_'.$post_type_item.'s'), |
|
| 767 | + 'subscriber' => array('read') |
|
| 768 | 768 | |
| 769 | 769 | ); |
| 770 | 770 | } // End For Loop |
@@ -778,16 +778,16 @@ discard block |
||
| 778 | 778 | * @param WP_Admin_Bar $bar |
| 779 | 779 | * @return void |
| 780 | 780 | */ |
| 781 | - public function quiz_admin_bar_menu( $bar ) { |
|
| 782 | - if ( is_single() && 'quiz' == get_queried_object()->post_type ) { |
|
| 783 | - $lesson_id = get_post_meta( get_queried_object()->ID, '_quiz_lesson', true ); |
|
| 784 | - if ( $lesson_id ) { |
|
| 781 | + public function quiz_admin_bar_menu($bar) { |
|
| 782 | + if (is_single() && 'quiz' == get_queried_object()->post_type) { |
|
| 783 | + $lesson_id = get_post_meta(get_queried_object()->ID, '_quiz_lesson', true); |
|
| 784 | + if ($lesson_id) { |
|
| 785 | 785 | $object_type = get_post_type_object('quiz'); |
| 786 | - $bar->add_menu( array( |
|
| 786 | + $bar->add_menu(array( |
|
| 787 | 787 | 'id' => 'edit', |
| 788 | 788 | 'title' => $object_type->labels->edit_item, |
| 789 | - 'href' => get_edit_post_link( $lesson_id ), |
|
| 790 | - ) ); |
|
| 789 | + 'href' => get_edit_post_link($lesson_id), |
|
| 790 | + )); |
|
| 791 | 791 | } |
| 792 | 792 | } |
| 793 | 793 | } |
@@ -799,4 +799,4 @@ discard block |
||
| 799 | 799 | * for backward compatibility |
| 800 | 800 | * @since 1.9.0 |
| 801 | 801 | */ |
| 802 | -class WooThemes_Sensei_PostTypes extends Sensei_PostTypes{} |
|
| 802 | +class WooThemes_Sensei_PostTypes extends Sensei_PostTypes {} |
|